<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/git/stable/linux.git/block/blk-cgroup.c, branch master</title>
<subtitle>Linux kernel stable tree</subtitle>
<id>https://git.landau.one/pub/scm/linux/kernel/git/stable/linux.git/atom?h=master</id>
<link rel='self' href='https://git.landau.one/pub/scm/linux/kernel/git/stable/linux.git/atom?h=master'/>
<link rel='alternate' type='text/html' href='https://git.landau.one/pub/scm/linux/kernel/git/stable/linux.git/'/>
<updated>2026-08-15T23:15:08+00:00</updated>
<entry>
<title>block: skip blkcg walk in blk_cgroup_congested() when nothing throttled</title>
<updated>2026-08-15T23:15:08+00:00</updated>
<author>
<name>Usama Arif</name>
<email>usama.arif@linux.dev</email>
</author>
<published>2026-08-14T16:56:39+00:00</published>
<link rel='alternate' type='text/html' href='https://git.landau.one/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=4febfe7d98948bf6693f5c6a0a7e198e8fb4e584'/>
<id>urn:sha1:4febfe7d98948bf6693f5c6a0a7e198e8fb4e584</id>
<content type='text'>
blk_cgroup_congested() walks the current task's blkcg ancestor chain on
every readahead decision and, once swap is in use, on every anonymous and
shmem folio allocation.  The answer is almost always "no", but finding that
out costs two loads per level on two cold cache lines, plus an out-of-line
kthread_blkcg() and an RCU read-side pair.  On a fleet profile of hosts
running containers with 5-10 level hierarchies it costs about as much as
all of mutex_lock(), 99.4% of it under __folio_throttle_swaprate().

Gate the walk on a global count of blkcgs with a non-zero
congestion_count.  The counter only moves on the 0 &lt;-&gt; 1 transitions of
each blkcg's congestion_count, so the extra atomic stays in the throttle
arm/disarm paths and never appears in steady state. When something is
throttled the counter is non-zero and the walk runs as before.

Signed-off-by: Usama Arif &lt;usama.arif@linux.dev&gt;
Acked-by: Tejun Heo &lt;tj@kernel.org&gt;
Link: https://patch.msgid.link/20260814165712.510132-4-usama.arif@linux.dev
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>blk-cgroup: factor policy pd teardown loop into helper</title>
<updated>2026-08-04T02:02:35+00:00</updated>
<author>
<name>Zheng Qixing</name>
<email>zhengqixing@huawei.com</email>
</author>
<published>2026-08-02T11:25:20+00:00</published>
<link rel='alternate' type='text/html' href='https://git.landau.one/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=d3f775718a66e4242b3b344d6b3fc836a390785b'/>
<id>urn:sha1:d3f775718a66e4242b3b344d6b3fc836a390785b</id>
<content type='text'>
Move the teardown sequence which offlines and frees per-policy
blkg_policy_data (pd) into a helper for readability.

No functional change intended.

Signed-off-by: Zheng Qixing &lt;zhengqixing@huawei.com&gt;
Reviewed-by: Christoph Hellwig &lt;hch@lst.de&gt;
Reviewed-by: Tang Yizhou &lt;yizhou.tang@shopee.com&gt;
Signed-off-by: Yu Kuai &lt;yukuai@fygo.io&gt;
Reviewed-by: Nilay Shroff &lt;nilay@linux.ibm.com&gt;
Link: https://patch.msgid.link/20260802112525.3933753-5-yukuai@kernel.org
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>blk-cgroup: skip dying blkg in blkcg_activate_policy()</title>
<updated>2026-08-04T02:02:35+00:00</updated>
<author>
<name>Zheng Qixing</name>
<email>zhengqixing@huawei.com</email>
</author>
<published>2026-08-02T11:25:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.landau.one/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=5e9220389920f33b6a804d50c548cd0cd1b04634'/>
<id>urn:sha1:5e9220389920f33b6a804d50c548cd0cd1b04634</id>
<content type='text'>
When switching IO schedulers on a block device, blkcg_activate_policy()
can race with concurrent blkcg deletion, leading to a use-after-free in
rcu_accelerate_cbs.

T1:                               T2:
                                  blkg_destroy
                                  kill(&amp;blkg-&gt;refcnt) // blkg-&gt;refcnt=1-&gt;0
                                  blkg_release // call_rcu(__blkg_release)
                                  ...
                                  blkg_free_workfn
                                  -&gt;pd_free_fn(pd)
elv_iosched_store
elevator_switch
...
iterate blkg list
blkg_get(blkg) // blkg-&gt;refcnt=0-&gt;1
                                  list_del_init(&amp;blkg-&gt;q_node)
blkg_put(pinned_blkg) // blkg-&gt;refcnt=1-&gt;0
blkg_release // call_rcu again
rcu_accelerate_cbs // uaf

Fix this by checking hlist_unhashed(&amp;blkg-&gt;blkcg_node) before getting
a reference to the blkg. This is the same check used in blkg_destroy()
to detect if a blkg has already been destroyed. If the blkg is already
unhashed, skip processing it since it's being destroyed.

Fixes: f1c006f1c685 ("blk-cgroup: synchronize pd_free_fn() from blkg_free_workfn() and blkcg_deactivate_policy()")
Signed-off-by: Zheng Qixing &lt;zhengqixing@huawei.com&gt;
Reviewed-by: Tang Yizhou &lt;yizhou.tang@shopee.com&gt;
Signed-off-by: Yu Kuai &lt;yukuai@fygo.io&gt;
Reviewed-by: Tao Cui &lt;cuitao@kylinos.cn&gt;
Reviewed-by: Nilay Shroff &lt;nilay@linux.ibm.com&gt;
Link: https://patch.msgid.link/20260802112525.3933753-4-yukuai@kernel.org
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>blk-cgroup: fix race between policy activation and blkg destruction</title>
<updated>2026-08-04T02:02:35+00:00</updated>
<author>
<name>Zheng Qixing</name>
<email>zhengqixing@huawei.com</email>
</author>
<published>2026-08-02T11:25:18+00:00</published>
<link rel='alternate' type='text/html' href='https://git.landau.one/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=5313d4d41739b0cb63000747c97bb1217ac45f3e'/>
<id>urn:sha1:5313d4d41739b0cb63000747c97bb1217ac45f3e</id>
<content type='text'>
When switching an IO scheduler on a block device, blkcg_activate_policy()
allocates blkg_policy_data (pd) for all blkgs attached to the queue.
However, blkcg_activate_policy() may race with concurrent blkcg deletion,
leading to use-after-free and memory leak issues.

The use-after-free occurs in the following race:

T1 (blkcg_activate_policy):
  - Successfully allocates pd for blkg1 (loop0-&gt;queue, blkcgA)
  - Fails to allocate pd for blkg2 (loop0-&gt;queue, blkcgB)
  - Enters the enomem rollback path to release blkg1 resources

T2 (blkcg deletion):
  - blkcgA is deleted concurrently
  - blkg1 is freed via blkg_free_workfn()
  - blkg1-&gt;pd is freed

T1 (continued):
  - Rollback path accesses blkg1-&gt;pd-&gt;online after pd is freed
  - Triggers use-after-free

In addition, blkg_free_workfn() frees pd before removing the blkg from
q-&gt;blkg_list. This allows blkcg_activate_policy() to allocate a new pd
for a blkg that is being destroyed, leaving the newly allocated pd
unreachable when the blkg is finally freed.

Fix these races by extending blkcg_mutex coverage to serialize
blkcg_activate_policy() rollback and blkg destruction, ensuring pd
lifecycle is synchronized with blkg list visibility.

Fixes: f1c006f1c685 ("blk-cgroup: synchronize pd_free_fn() from blkg_free_workfn() and blkcg_deactivate_policy()")
Signed-off-by: Zheng Qixing &lt;zhengqixing@huawei.com&gt;
Reviewed-by: Tang Yizhou &lt;yizhou.tang@shopee.com&gt;
Signed-off-by: Yu Kuai &lt;yukuai@fygo.io&gt;
Reviewed-by: Tao Cui &lt;cuitao@kylinos.cn&gt;
Reviewed-by: Nilay Shroff &lt;nilay@linux.ibm.com&gt;
Link: https://patch.msgid.link/20260802112525.3933753-3-yukuai@kernel.org
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>blk-cgroup: protect q-&gt;blkg_list iteration in blkg_destroy_all() with blkcg_mutex</title>
<updated>2026-08-04T02:02:34+00:00</updated>
<author>
<name>Yu Kuai</name>
<email>yukuai@fygo.io</email>
</author>
<published>2026-08-02T11:25:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.landau.one/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=9a916798946e5107472cdc714079c0167b8cd251'/>
<id>urn:sha1:9a916798946e5107472cdc714079c0167b8cd251</id>
<content type='text'>
blkg_destroy_all() iterates q-&gt;blkg_list without holding blkcg_mutex,
which can race with blkg_free_workfn() that removes blkgs from the list
while holding blkcg_mutex.

Add blkcg_mutex protection around the q-&gt;blkg_list iteration to prevent
potential list corruption or use-after-free issues.

Reviewed-by: Tang Yizhou &lt;yizhou.tang@shopee.com&gt;
Signed-off-by: Yu Kuai &lt;yukuai@fygo.io&gt;
Reviewed-by: Tao Cui &lt;cuitao@kylinos.cn&gt;
Reviewed-by: Nilay Shroff &lt;nilay@linux.ibm.com&gt;
Link: https://patch.msgid.link/20260802112525.3933753-2-yukuai@kernel.org
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>blk-cgroup: fix leaks and online flag on radix_tree_insert failure</title>
<updated>2026-07-15T22:31:43+00:00</updated>
<author>
<name>Tao Cui</name>
<email>cuitao@kylinos.cn</email>
</author>
<published>2026-07-15T13:24:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.landau.one/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=dbbca20764382b4d411ec2918f4e278ffe547acc'/>
<id>urn:sha1:dbbca20764382b4d411ec2918f4e278ffe547acc</id>
<content type='text'>
When radix_tree_insert() fails in blkg_create(), the error path has two
issues:

1. blkg-&gt;online is set to true unconditionally, even when the blkg was
   never fully inserted.  Move the assignment inside the success block.

2. The error path calls blkg_put() without first calling
   percpu_ref_kill().  Because the refcount is still in percpu mode,
   percpu_ref_put() only does this_cpu_sub() without checking for zero,
   so blkg_release() is never triggered.  This permanently leaks the
   blkg memory, its percpu iostat, policy data, the parent blkg
   reference, and the cgroup css reference — the latter preventing the
   cgroup from ever being destroyed.

Fix by replacing blkg_put() with percpu_ref_kill(), matching the pattern
used in blkg_destroy().

Acked-by: Tejun Heo &lt;tj@kernel.org&gt;
Signed-off-by: Tao Cui &lt;cuitao@kylinos.cn&gt;
Link: https://patch.msgid.link/20260715132407.1469777-1-cui.tao@linux.dev
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>blk-cgroup: don't nest queue_lock under blkcg-&gt;lock in blkcg_destroy_blkgs()</title>
<updated>2026-06-24T12:42:31+00:00</updated>
<author>
<name>Yu Kuai</name>
<email>yukuai@fygo.io</email>
</author>
<published>2026-06-08T03:42:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.landau.one/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=4cfd7c1cff8f4c863b99d420cdbe0563802a9e80'/>
<id>urn:sha1:4cfd7c1cff8f4c863b99d420cdbe0563802a9e80</id>
<content type='text'>
The correct lock order is q-&gt;queue_lock before blkcg-&gt;lock, and in order
to prevent deadlock from blkcg_destroy_blkgs(), trylock is used for
q-&gt;queue_lock while blkcg-&gt;lock is already held, this is hacky.

Refactor blkcg_destroy_blkgs() to hold blkcg-&gt;lock only long enough to
get the first blkg and then release it. Then take q-&gt;queue_lock and
blkcg-&gt;lock in the correct order to destroy the blkg. This is a very cold
path, so the extra lock/unlock cycles are acceptable.

Also prepare to convert protecting blkcg with blkcg_mutex instead of
queue_lock.

Signed-off-by: Yu Kuai &lt;yukuai@fygo.io&gt;
Link: https://patch.msgid.link/00b03cf74a9937cb4d6dd67a189ddc00a3de0451.1780621988.git.yukuai@fygo.io
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>blk-cgroup: don't nest queue_lock under rcu in bio_associate_blkg()</title>
<updated>2026-06-24T12:42:31+00:00</updated>
<author>
<name>Yu Kuai</name>
<email>yukuai@fygo.io</email>
</author>
<published>2026-06-08T03:42:46+00:00</published>
<link rel='alternate' type='text/html' href='https://git.landau.one/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=457d3c4f0fdd6cf8a4bd8115bf470809984a9f02'/>
<id>urn:sha1:457d3c4f0fdd6cf8a4bd8115bf470809984a9f02</id>
<content type='text'>
If a bio is already associated with a blkg, the blkcg is already pinned
until the bio is done, so there is no need for RCU protection. Otherwise,
protect blkcg_css() with RCU independently. Prepare to protect blkcg with
blkcg_mutex instead of queue_lock.

Signed-off-by: Yu Kuai &lt;yukuai@fygo.io&gt;
Link: https://patch.msgid.link/8496fa234b21d4b31b7f068766906d0bffcac8e6.1780621988.git.yukuai@fygo.io
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>blk-cgroup: don't nest queue_lock under rcu in blkg_lookup_create()</title>
<updated>2026-06-24T12:42:31+00:00</updated>
<author>
<name>Yu Kuai</name>
<email>yukuai@fygo.io</email>
</author>
<published>2026-06-08T03:42:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.landau.one/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=9327a865e395a53f67dffac4710beb1d4730495e'/>
<id>urn:sha1:9327a865e395a53f67dffac4710beb1d4730495e</id>
<content type='text'>
Change this in two steps:

1) hold rcu lock and do blkg_lookup() from fast path;
2) hold queue_lock directly from slow path, and don't nest it under rcu
   lock;

Prepare to convert protecting blkcg with blkcg_mutex instead of
queue_lock.

Signed-off-by: Yu Kuai &lt;yukuai@fygo.io&gt;
Link: https://patch.msgid.link/93f33cc9e5a39dddb78dcd934d0c1d04b564fb00.1780621988.git.yukuai@fygo.io
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
<entry>
<title>blk-cgroup: don't nest queue_lock under rcu in blkcg_print_blkgs()</title>
<updated>2026-06-24T12:42:19+00:00</updated>
<author>
<name>Yu Kuai</name>
<email>yukuai@fygo.io</email>
</author>
<published>2026-06-08T03:42:44+00:00</published>
<link rel='alternate' type='text/html' href='https://git.landau.one/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=56cc24f59c145ce6938959f792df04b8a4f5a4d8'/>
<id>urn:sha1:56cc24f59c145ce6938959f792df04b8a4f5a4d8</id>
<content type='text'>
With previous modification to delay freeing policy data after an RCU grace
period, prfill() can run under RCU instead of taking queue_lock. However,
policy teardown can still clear blkg-&gt;pd[plid] after blkcg_print_blkgs()
observes the policy enabled bit.

Load policy data once with READ_ONCE() and skip the blkg if teardown
already cleared it. Do the same in recursive stat walks for descendant
blkgs. Remove the stale BFQ debug queue_lock assertion because
blkcg_print_blkgs() no longer calls prfill() with queue_lock held. This
also lets ioc_qos_prfill() and ioc_cost_model_prfill() use IRQ-safe
ioc-&gt;lock locking without re-enabling IRQs while queue_lock is still held.

Signed-off-by: Yu Kuai &lt;yukuai@fygo.io&gt;
Link: https://patch.msgid.link/db7633d5e263dd1c2bf9b901762545a84b7d714e.1780621988.git.yukuai@fygo.io
Signed-off-by: Jens Axboe &lt;axboe@kernel.dk&gt;
</content>
</entry>
</feed>
