linux-stable/block
Ming Lei 20cb1c2fb7 blk-cgroup: Flush stats before releasing blkcg_gq
As noted by Michal, the blkg_iostat_set's in the lockless list hold
reference to blkg's to protect against their removal. Those blkg's
hold reference to blkcg. When a cgroup is being destroyed,
cgroup_rstat_flush() is only called at css_release_work_fn() which
is called when the blkcg reference count reaches 0. This circular
dependency will prevent blkcg and some blkgs from being freed after
they are made offline.

It is less a problem if the cgroup to be destroyed also has other
controllers like memory that will call cgroup_rstat_flush() which will
clean up the reference count. If block is the only controller that uses
rstat, these offline blkcg and blkgs may never be freed leaking more
and more memory over time.

To prevent this potential memory leak:

- flush blkcg per-cpu stats list in __blkg_release(), when no new stat
can be added

- add global blkg_stat_lock for covering concurrent parent blkg stat
update

- don't grab bio->bi_blkg reference when adding the stats into blkcg's
per-cpu stat list since all stats are guaranteed to be consumed before
releasing blkg instance, and grabbing blkg reference for stats was the
most fragile part of original patch

Based on Waiman's patch:

https://lore.kernel.org/linux-block/20221215033132.230023-3-longman@redhat.com/

Fixes: 3b8cc62987 ("blk-cgroup: Optimize blkcg_rstat_flush()")
Cc: stable@vger.kernel.org
Reported-by: Jay Shin <jaeshin@redhat.com>
Acked-by: Tejun Heo <tj@kernel.org>
Cc: Waiman Long <longman@redhat.com>
Cc: mkoutny@suse.com
Cc: Yosry Ahmed <yosryahmed@google.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Link: https://lore.kernel.org/r/20230609234249.1412858-1-ming.lei@redhat.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
2023-06-11 19:49:29 -06:00
..
partitions block: Cleanup set_capacity()/bdev_set_nr_sectors() 2023-04-24 08:48:09 -06:00
badblocks.c
bdev.c block: sync part's ->bd_has_submit_bio with disk's 2023-04-25 07:36:02 -06:00
bfq-cgroup.c blkcg: Restructure blkg_conf_prep() and friends 2023-04-13 06:46:49 -06:00
bfq-iosched.c block, bfq: Fix division by zero error on zero wsum 2023-04-16 13:01:43 -06:00
bfq-iosched.h block, bfq: remove BFQ_WEIGHT_LEGACY_DFL 2023-04-06 16:17:32 -06:00
bfq-wf2q.c
bio-integrity.c
bio.c ext4: Convert ext4_bio_write_page() to use a folio 2023-04-06 13:39:50 -04:00
blk-cgroup-fc-appid.c
blk-cgroup-rwstat.c
blk-cgroup-rwstat.h
blk-cgroup.c blk-cgroup: Flush stats before releasing blkcg_gq 2023-06-11 19:49:29 -06:00
blk-cgroup.h for-6.4/block-2023-04-21 2023-04-26 12:52:58 -07:00
blk-core.c block: make bio_check_eod work for zero sized devices 2023-05-24 08:19:26 -06:00
blk-crypto-fallback.c
blk-crypto-internal.h
blk-crypto-profile.c
blk-crypto-sysfs.c
blk-crypto.c
blk-flush.c blk-mq: fix the blk_mq_add_to_requeue_list call in blk_kick_flush 2023-04-16 13:01:43 -06:00
blk-ia-ranges.c
blk-integrity.c blk-integrity: register sysfs attributes on struct device 2023-04-26 18:22:50 -06:00
blk-ioc.c
blk-iocost.c blkcg: Restructure blkg_conf_prep() and friends 2023-04-13 06:46:49 -06:00
blk-iolatency.c blk-iolatency: Make initialization lazy 2023-04-13 06:46:49 -06:00
blk-ioprio.c
blk-ioprio.h
blk-lib.c
blk-map.c block: fix bio-cache for passthru IO 2023-05-23 11:11:29 -06:00
blk-merge.c
blk-mq-cpumap.c blk-mq: include <linux/blk-mq.h> in block/blk-mq.h 2023-04-13 06:52:29 -06:00
blk-mq-debugfs-zoned.c
blk-mq-debugfs.c blk-mq: include <linux/blk-mq.h> in block/blk-mq.h 2023-04-13 06:52:29 -06:00
blk-mq-debugfs.h
blk-mq-pci.c blk-mq: include <linux/blk-mq.h> in block/blk-mq.h 2023-04-13 06:52:29 -06:00
blk-mq-sched.c blk-mq: cleanup __blk_mq_sched_dispatch_requests 2023-04-13 06:57:18 -06:00
blk-mq-sched.h blk-mq: move blk_mq_sched_insert_request to blk-mq.c 2023-04-13 06:52:29 -06:00
blk-mq-sysfs.c blk-mq: include <linux/blk-mq.h> in block/blk-mq.h 2023-04-13 06:52:29 -06:00
blk-mq-tag.c blk-mq: fix race condition in active queue accounting 2023-05-23 11:10:16 -06:00
blk-mq-virtio.c blk-mq: include <linux/blk-mq.h> in block/blk-mq.h 2023-04-13 06:52:29 -06:00
blk-mq.c blk-mq: fix blk_mq_hw_ctx active request accounting 2023-06-03 17:20:00 -06:00
blk-mq.h for-6.4/block-2023-04-21 2023-04-26 12:52:58 -07:00
blk-pm.c blk-mq: include <linux/blk-mq.h> in block/blk-mq.h 2023-04-13 06:52:29 -06:00
blk-pm.h
blk-rq-qos.c
blk-rq-qos.h blk-iolatency: s/blkcg_rq_qos/iolat_rq_qos/ 2023-04-13 06:46:49 -06:00
blk-settings.c block: fix revalidate performance regression 2023-05-29 08:40:32 -06:00
blk-stat.c blk-mq: include <linux/blk-mq.h> in block/blk-mq.h 2023-04-13 06:52:29 -06:00
blk-stat.h
blk-sysfs.c blk-mq: include <linux/blk-mq.h> in block/blk-mq.h 2023-04-13 06:52:29 -06:00
blk-throttle.c blk-throttle: only enable blk-stat when BLK_DEV_THROTTLING_LOW 2023-04-13 06:48:11 -06:00
blk-throttle.h
blk-timeout.c
blk-wbt.c blk-wbt: fix that wbt can't be disabled by default 2023-05-23 11:08:53 -06:00
blk-wbt.h
blk-zoned.c
blk.h blk-integrity: register sysfs attributes on struct device 2023-04-26 18:22:50 -06:00
bounce.c
bsg-lib.c
bsg.c
disk-events.c
elevator.c
elevator.h blk-mq: pass a flags argument to elevator_type->insert_requests 2023-04-13 06:52:30 -06:00
fops.c block: Deny writable memory mapping if block is read-only 2023-05-19 20:17:10 -06:00
genhd.c for-6.4/block-2023-05-06 2023-05-06 08:28:58 -07:00
holder.c
ioctl.c
ioprio.c
Kconfig for-6.4/block-2023-04-21 2023-04-26 12:52:58 -07:00
Kconfig.iosched
kyber-iosched.c blk-mq: pass a flags argument to elevator_type->insert_requests 2023-04-13 06:52:30 -06:00
Makefile blk-mq-rdma: remove queue mapping helper for rdma devices 2023-04-13 08:59:05 +02:00
mq-deadline.c blk-mq: pass a flags argument to elevator_type->insert_requests 2023-04-13 06:52:30 -06:00
opal_proto.h sed-opal: allow user authority to get locking range attributes. 2023-04-05 07:46:25 -06:00
sed-opal.c sed-opal: geometry feature reporting command 2023-04-19 14:07:13 -06:00
t10-pi.c