* [dm-devel] [PATCH v2] dm-crypt: fix softlockup in dmcrypt_write
@ 2023-03-06 11:56 yangerkun
2023-03-06 16:15 ` Mikulas Patocka
0 siblings, 1 reply; 2+ messages in thread
From: yangerkun @ 2023-03-06 11:56 UTC (permalink / raw)
To: agk, snitzer, mpatocka, dm-devel; +Cc: yangerkun, yangerkun
From: yangerkun <yangerkun@huawei.com>
We meet a softlockup:
localhost login: [ 3391.153255][ C12] watchdog: BUG: soft lockup - CPU#12 stuck for 23s! [dmcrypt_write/2:2897]
...
[ 3391.258372][ C12] CPU: 12 PID: 2897 Comm: dmcrypt_write/2 Tainted: G L 5.10.0+ #8
[ 3391.267288][ C12] Hardware name: Huawei TaiShan 2280 V2/BC82AMDDA, BIOS 1.75 04/26/2021
[ 3391.275428][ C12] pstate: 80400009 (Nzcv daif +PAN -UAO -TCO BTYPE=--)
[ 3391.282102][ C12] pc : blk_attempt_bio_merge.part.6+0x38/0x158
[ 3391.288080][ C12] lr : blk_attempt_plug_merge+0xc0/0x1b0
[ 3391.293540][ C12] sp : ffff8000718abc30
[ 3391.297530][ C12] x29: ffff8000718abc30 x28: 0000000000000000
[ 3391.303509][ C12] x27: ffff2020361d9ac0 x26: 0000000000000001
[ 3391.309488][ C12] x25: 0000000000000001 x24: ffff8000718abd08
[ 3391.315467][ C12] x23: ffff0020a10dbb00 x22: 0000000000000001
[ 3391.321445][ C12] x21: ffff8000718abe20 x20: ffff0020a10dbb00
[ 3391.327424][ C12] x19: ffff0020aed7b040 x18: 0000000000000000
[ 3391.333402][ C12] x17: 0000000000000000 x16: fffffdffffe00000
[ 3391.339381][ C12] x15: 0000000000001000 x14: 0000000000000000
[ 3391.345359][ C12] x13: 0000000000002000 x12: ffff2060011f9070
[ 3391.351338][ C12] x11: 0000000000000001 x10: 0000000000000002
[ 3391.357316][ C12] x9 : ffff800010586c38 x8 : ffff202009a7f200
[ 3391.363294][ C12] x7 : ffff8000718abd00 x6 : ffff20200df33750
[ 3391.369274][ C12] x5 : 0000000000000001 x4 : 0000000000000000
[ 3391.375252][ C12] x3 : 0000000000000001 x2 : ffff0020a10dbb00
[ 3391.381230][ C12] x1 : ffff0020aed7b040 x0 : 0000000000001000
[ 3391.387210][ C12] Call trace:
[ 3391.390338][ C12] blk_attempt_bio_merge.part.6+0x38/0x158
[ 3391.395970][ C12] blk_attempt_plug_merge+0xc0/0x1b0
[ 3391.401085][ C12] blk_mq_submit_bio+0x398/0x550
[ 3391.405856][ C12] submit_bio_noacct+0x308/0x380
[ 3391.410630][ C12] dmcrypt_write+0x1e4/0x208 [dm_crypt]
[ 3391.416005][ C12] kthread+0x130/0x138
[ 3391.419911][ C12] ret_from_fork+0x10/0x18
dmcrypt_write will be wakeup once there is a not empty write_tree, and
before really submit_bio, the old write_tree will be peeled, so there
may not so much bio, but every time we check RB_EMPTY_ROOT, it may be
false since the heavy load write, so the softlockup can trigger.
We can add cond_resched every time before or after kcryptd_io_write, but
dmcrypt_write seems performance sensitive since it will submit all
pending write, so we choose cond_resched after 1s before the 'while'
submit bio.
Fixes: dc2676210c42 ("dm crypt: offload writes to thread")
Signed-off-by: yangerkun <yangerkun@huawei.com>
---
drivers/md/dm-crypt.c | 6 ++++++
1 file changed, 6 insertions(+)
v1->v2:
change schedule() to cond_resched()
diff --git a/drivers/md/dm-crypt.c b/drivers/md/dm-crypt.c
index 40cb1719ae4d..6a675257e00e 100644
--- a/drivers/md/dm-crypt.c
+++ b/drivers/md/dm-crypt.c
@@ -1894,6 +1894,7 @@ static int dmcrypt_write(void *data)
{
struct crypt_config *cc = data;
struct dm_crypt_io *io;
+ unsigned long start_time = jiffies;
while (1) {
struct rb_root write_tree;
@@ -1916,6 +1917,7 @@ static int dmcrypt_write(void *data)
schedule();
+ start_time = jiffies;
set_current_state(TASK_RUNNING);
spin_lock_irq(&cc->write_thread_lock);
goto continue_locked;
@@ -1927,6 +1929,10 @@ static int dmcrypt_write(void *data)
BUG_ON(rb_parent(write_tree.rb_node));
+ if (time_is_before_jiffies(start_time + HZ)) {
+ cond_resched();
+ start_time = jiffies;
+ }
/*
* Note: we cannot walk the tree here with rb_next because
* the structures may be freed when kcryptd_io_write is called.
--
2.31.1
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [dm-devel] [PATCH v2] dm-crypt: fix softlockup in dmcrypt_write
2023-03-06 11:56 [dm-devel] [PATCH v2] dm-crypt: fix softlockup in dmcrypt_write yangerkun
@ 2023-03-06 16:15 ` Mikulas Patocka
0 siblings, 0 replies; 2+ messages in thread
From: Mikulas Patocka @ 2023-03-06 16:15 UTC (permalink / raw)
To: yangerkun; +Cc: dm-devel, snitzer, yangerkun, agk
On Mon, 6 Mar 2023, yangerkun wrote:
> From: yangerkun <yangerkun@huawei.com>
>
> We meet a softlockup:
>
> localhost login: [ 3391.153255][ C12] watchdog: BUG: soft lockup - CPU#12 stuck for 23s! [dmcrypt_write/2:2897]
> ...
> [ 3391.258372][ C12] CPU: 12 PID: 2897 Comm: dmcrypt_write/2 Tainted: G L 5.10.0+ #8
> [ 3391.267288][ C12] Hardware name: Huawei TaiShan 2280 V2/BC82AMDDA, BIOS 1.75 04/26/2021
> [ 3391.275428][ C12] pstate: 80400009 (Nzcv daif +PAN -UAO -TCO BTYPE=--)
> [ 3391.282102][ C12] pc : blk_attempt_bio_merge.part.6+0x38/0x158
> [ 3391.288080][ C12] lr : blk_attempt_plug_merge+0xc0/0x1b0
> [ 3391.293540][ C12] sp : ffff8000718abc30
> [ 3391.297530][ C12] x29: ffff8000718abc30 x28: 0000000000000000
> [ 3391.303509][ C12] x27: ffff2020361d9ac0 x26: 0000000000000001
> [ 3391.309488][ C12] x25: 0000000000000001 x24: ffff8000718abd08
> [ 3391.315467][ C12] x23: ffff0020a10dbb00 x22: 0000000000000001
> [ 3391.321445][ C12] x21: ffff8000718abe20 x20: ffff0020a10dbb00
> [ 3391.327424][ C12] x19: ffff0020aed7b040 x18: 0000000000000000
> [ 3391.333402][ C12] x17: 0000000000000000 x16: fffffdffffe00000
> [ 3391.339381][ C12] x15: 0000000000001000 x14: 0000000000000000
> [ 3391.345359][ C12] x13: 0000000000002000 x12: ffff2060011f9070
> [ 3391.351338][ C12] x11: 0000000000000001 x10: 0000000000000002
> [ 3391.357316][ C12] x9 : ffff800010586c38 x8 : ffff202009a7f200
> [ 3391.363294][ C12] x7 : ffff8000718abd00 x6 : ffff20200df33750
> [ 3391.369274][ C12] x5 : 0000000000000001 x4 : 0000000000000000
> [ 3391.375252][ C12] x3 : 0000000000000001 x2 : ffff0020a10dbb00
> [ 3391.381230][ C12] x1 : ffff0020aed7b040 x0 : 0000000000001000
> [ 3391.387210][ C12] Call trace:
> [ 3391.390338][ C12] blk_attempt_bio_merge.part.6+0x38/0x158
> [ 3391.395970][ C12] blk_attempt_plug_merge+0xc0/0x1b0
> [ 3391.401085][ C12] blk_mq_submit_bio+0x398/0x550
> [ 3391.405856][ C12] submit_bio_noacct+0x308/0x380
> [ 3391.410630][ C12] dmcrypt_write+0x1e4/0x208 [dm_crypt]
> [ 3391.416005][ C12] kthread+0x130/0x138
> [ 3391.419911][ C12] ret_from_fork+0x10/0x18
>
> dmcrypt_write will be wakeup once there is a not empty write_tree, and
> before really submit_bio, the old write_tree will be peeled, so there
> may not so much bio, but every time we check RB_EMPTY_ROOT, it may be
> false since the heavy load write, so the softlockup can trigger.
>
> We can add cond_resched every time before or after kcryptd_io_write, but
> dmcrypt_write seems performance sensitive since it will submit all
> pending write, so we choose cond_resched after 1s before the 'while'
> submit bio.
>
> Fixes: dc2676210c42 ("dm crypt: offload writes to thread")
> Signed-off-by: yangerkun <yangerkun@huawei.com>
Hi
Thanks for the bug report.
I think that we don't have to count time and call cond_resched() only
after being stuck for one second, we should call it always. There is no
performance problem when calling cond_resched() - it does nothing if the
scheduler hasn't decided that scheduling is needed.
cond_resched() should be called in the do-while loop because this loop can
run for unbounded amount of time too.
Mikulas
--
dm-devel mailing list
dm-devel@redhat.com
https://listman.redhat.com/mailman/listinfo/dm-devel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-06 16:29 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-06 11:56 [dm-devel] [PATCH v2] dm-crypt: fix softlockup in dmcrypt_write yangerkun
2023-03-06 16:15 ` Mikulas Patocka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).