From: Mikulas Patocka <mpatocka@redhat.com>
To: Sheng Yong <shengyong2021@gmail.com>
Cc: agk@redhat.com, snitzer@kernel.org, nhuck@google.com,
dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org,
Sheng Yong <shengyong1@xiaomi.com>,
Wang Shuai <wangshuai12@xiaomi.com>
Subject: Re: [PATCH] dm-bufio: fix sched in atomic context
Date: Mon, 14 Jul 2025 19:17:00 +0200 (CEST) [thread overview]
Message-ID: <673ddfed-d874-9ffe-c2fe-a741e8fc69f1@redhat.com> (raw)
In-Reply-To: <20250710064855.239572-1-shengyong1@xiaomi.com>
On Thu, 10 Jul 2025, Sheng Yong wrote:
> From: Sheng Yong <shengyong1@xiaomi.com>
>
> If "try_verify_in_tasklet" is set for dm-verity, DM_BUFIO_CLIENT_NO_SLEEP
> is enabled for dm-bufio. However, when bufio tries to evict buffers, there
> is a chance to trigger scheduling in spin_lock_bh, the following warning
> is hit:
>
> BUG: sleeping function called from invalid context at drivers/md/dm-bufio.c:2745
> in_atomic(): 1, irqs_disabled(): 0, non_block: 0, pid: 123, name: kworker/2:2
> preempt_count: 201, expected: 0
> RCU nest depth: 0, expected: 0
> 4 locks held by kworker/2:2/123:
> #0: ffff88800a2d1548 ((wq_completion)dm_bufio_cache){....}-{0:0}, at: process_one_work+0xe46/0x1970
> #1: ffffc90000d97d20 ((work_completion)(&dm_bufio_replacement_work)){....}-{0:0}, at: process_one_work+0x763/0x1970
> #2: ffffffff8555b528 (dm_bufio_clients_lock){....}-{3:3}, at: do_global_cleanup+0x1ce/0x710
> #3: ffff88801d5820b8 (&c->spinlock){....}-{2:2}, at: do_global_cleanup+0x2a5/0x710
> Preemption disabled at:
> [<0000000000000000>] 0x0
> CPU: 2 UID: 0 PID: 123 Comm: kworker/2:2 Not tainted 6.16.0-rc3-g90548c634bd0 #305 PREEMPT(voluntary)
> Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.16.3-0-ga6ed6b701f0a-prebuilt.qemu.org 04/01/2014
> Workqueue: dm_bufio_cache do_global_cleanup
> Call Trace:
> <TASK>
> dump_stack_lvl+0x53/0x70
> __might_resched+0x360/0x4e0
> do_global_cleanup+0x2f5/0x710
> process_one_work+0x7db/0x1970
> worker_thread+0x518/0xea0
> kthread+0x359/0x690
> ret_from_fork+0xf3/0x1b0
> ret_from_fork_asm+0x1a/0x30
> </TASK>
>
> That can be reproduced by:
>
> veritysetup format --data-block-size=4096 --hash-block-size=4096 /dev/vda /dev/vdb
> SIZE=$(blockdev --getsz /dev/vda)
> dmsetup create myverity -r --table "0 $SIZE verity 1 /dev/vda /dev/vdb 4096 4096 <data_blocks> 1 sha256 <root_hash> <salt> 1 try_verify_in_tasklet"
> mount /dev/dm-0 /mnt -o ro
> echo 102400 > /sys/module/dm_bufio/parameters/max_cache_size_bytes
> [read files in /mnt]
>
> Fixes: 5721d4e5a9cd ("dm verity: Add optional "try_verify_in_tasklet" feature")
> Signed-off-by: Wang Shuai <wangshuai12@xiaomi.com>
> Signed-off-by: Sheng Yong <shengyong1@xiaomi.com>
> ---
> drivers/md/dm-bufio.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c
> index ec84ba5e93e5..caf6ae9a8b52 100644
> --- a/drivers/md/dm-bufio.c
> +++ b/drivers/md/dm-bufio.c
> @@ -2742,7 +2742,9 @@ static unsigned long __evict_a_few(unsigned long nr_buffers)
> __make_buffer_clean(b);
> __free_buffer_wake(b);
>
> + dm_bufio_unlock(c);
> cond_resched();
> + dm_bufio_lock(c);
> }
>
> dm_bufio_unlock(c);
> --
> 2.43.0
Hi
I accepted this patch. I changed it to:
- cond_resched();
+ if (need_resched()) {
+ dm_bufio_unlock(c);
+ cond_resched();
+ dm_bufio_lock(c);
+ }
}
dm_bufio_unlock(c);
so that we are not hammering on the dm bufio lock when scheduling is not
needed.
Mikulas
next prev parent reply other threads:[~2025-07-14 17:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-10 6:48 Sheng Yong
2025-07-14 17:17 ` Mikulas Patocka [this message]
2025-07-15 1:35 ` Sheng Yong
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=673ddfed-d874-9ffe-c2fe-a741e8fc69f1@redhat.com \
--to=mpatocka@redhat.com \
--cc=agk@redhat.com \
--cc=dm-devel@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=nhuck@google.com \
--cc=shengyong1@xiaomi.com \
--cc=shengyong2021@gmail.com \
--cc=snitzer@kernel.org \
--cc=wangshuai12@xiaomi.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®