提交 37fe5913 编写于 作者: Y Yu Kuai 提交者: Yang Yingliang

blk-cgroup: prevent rcu_sched detected stalls warnings in blkg_destroy_all()

hulk inclusion
category: bugfix
bugzilla: 46357
CVE: NA

---------------------------

test procedures:

a. create 20000 cgroups, and echo "8:0 10000" to
   blkio.throttle.write_bps_device
b. echo 1 > /sys/blocd/sda/device/delete

test result:

rcu: INFO: rcu_sched detected stalls on CPUs/tasks:                                                                                                                     [5/1143]
rcu:     0-...0: (0 ticks this GP) idle=0f2/1/0x4000000000000000 softirq=15507/15507 fq
rcu:     (detected by 6, t=60012 jiffies, g=119977, q=27153)
NMI backtrace for cpu 0
CPU: 0 PID: 443 Comm: bash Not tainted 4.19.95-00061-g0bcc83b30eec #63
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS ?-20190727_073836-buildvm-p4
RIP: 0010:blk_throtl_update_limit_valid.isra.0+0x116/0x2a0
Code: 01 00 00 e8 7c dd 74 ff 48 83 bb 78 01 00 00 00 0f 85 54 01 00 00 48 8d bb 88 01 1
RSP: 0018:ffff8881030bf9f0 EFLAGS: 00000046
RAX: 0000000000000000 RBX: ffff8880b4f37080 RCX: ffffffff95da0afe
RDX: dffffc0000000000 RSI: ffff888100373980 RDI: ffff8880b4f37208
RBP: ffff888100deca00 R08: ffffffff9528f951 R09: 0000000000000001
R10: ffffed10159dbf56 R11: ffff8880acedfab3 R12: ffff8880b9fda498
R13: ffff8880b9fda4f4 R14: 0000000000000050 R15: ffffffff98b622c0
FS:  00007feb51c51700(0000) GS:ffff888106200000(0000) knlGS:0000000000000000
CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000561619547080 CR3: 0000000102bc9000 CR4: 00000000000006f0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000fffe0ff0 DR7: 0000000000000400
Call Trace:
 throtl_pd_offline+0x98/0x100
 blkg_destroy+0x133/0x630
 ? blkcg_deactivate_policy+0x2c0/0x2c0
 ? lock_timer_base+0x65/0x110
 blkg_destroy_all+0x7f/0x100
 blkcg_exit_queue+0x3f/0xa5
 blk_exit_queue+0x69/0xa0
 blk_cleanup_queue+0x226/0x360
 __scsi_remove_device+0xb4/0x3c0
 scsi_remove_device+0x38/0x60
 sdev_store_delete+0x74/0x100
 ? dev_driver_string+0xb0/0xb0
 dev_attr_store+0x41/0x70
 sysfs_kf_write+0x89/0xc0
 kernfs_fop_write+0x1b6/0x2e0
 ? sysfs_kf_bin_read+0x130/0x130
 __vfs_write+0xca/0x420
 ? kernel_read+0xc0/0xc0
 ? __alloc_fd+0x16f/0x2d0
 ? __fd_install+0x95/0x1a0
 ? handle_mm_fault+0x3e0/0x560
 vfs_write+0x11a/0x2f0
 ksys_write+0xb9/0x1e0
 ? __x64_sys_read+0x60/0x60
 ? kasan_check_write+0x20/0x30
 ? filp_close+0xb5/0xf0
 __x64_sys_write+0x46/0x60
 do_syscall_64+0xd9/0x1f0
 entry_SYSCALL_64_after_hwframe+0x44/0xa9

The usage of so many blkg is very rare, however, such problem do exist
in theory. In order to avoid such warnings, release 'q->queue_lock' for
a while when a batch of blkg were destroyed.
Signed-off-by: NYu Kuai <yukuai3@huawei.com>
Reviewed-by: NTao Hou <houtao1@huawei.com>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
Signed-off-by: NCheng Jian <cj.chengjian@huawei.com>
上级 29607aaa
...@@ -364,16 +364,31 @@ static void blkg_destroy(struct blkcg_gq *blkg) ...@@ -364,16 +364,31 @@ static void blkg_destroy(struct blkcg_gq *blkg)
*/ */
static void blkg_destroy_all(struct request_queue *q) static void blkg_destroy_all(struct request_queue *q)
{ {
#define BLKG_DESTROY_BATCH 4096
struct blkcg_gq *blkg, *n; struct blkcg_gq *blkg, *n;
int count;
lockdep_assert_held(q->queue_lock); lockdep_assert_held(q->queue_lock);
again:
count = BLKG_DESTROY_BATCH;
list_for_each_entry_safe(blkg, n, &q->blkg_list, q_node) { list_for_each_entry_safe(blkg, n, &q->blkg_list, q_node) {
struct blkcg *blkcg = blkg->blkcg; struct blkcg *blkcg = blkg->blkcg;
spin_lock(&blkcg->lock); spin_lock(&blkcg->lock);
blkg_destroy(blkg); blkg_destroy(blkg);
spin_unlock(&blkcg->lock); spin_unlock(&blkcg->lock);
/*
* If the list is too long, the loop can took a long time,
* thus relese the lock for a while when a batch of blkg
* were destroyed.
*/
if (!--count) {
spin_unlock_irq(q->queue_lock);
cond_resched();
spin_lock_irq(q->queue_lock);
goto again;
}
} }
q->root_blkg = NULL; q->root_blkg = NULL;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册