From: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
To: Ming Lei <tom.leiming@gmail.com>
Cc: Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org,
Caleb Sander Mateos <csander@purestorage.com>,
Ming Lei <ming.lei@redhat.com>,
"Liam R. Howlett" <liam.howlett@oracle.com>
Subject: Re: [PATCH] ublk: fix maple tree lockdep warning and unpin under spinlock
Date: Wed, 22 Apr 2026 10:59:31 +0900 [thread overview]
Message-ID: <aegqG_y2VXD_W8y3@shinmob> (raw)
In-Reply-To: <20260422000856.2362220-1-tom.leiming@gmail.com>
On Apr 22, 2026 / 08:08, Ming Lei wrote:
> From: Ming Lei <ming.lei@redhat.com>
>
> Fix two issues in the shmem buffer maple tree usage:
>
> 1) ublk_buf_cleanup() iterates the tree with mas_for_each() without
> holding rcu_read_lock or mas_lock, triggering a lockdep splat on
> CONFIG_PROVE_RCU kernels. Add mas_lock/unlock around the iteration.
>
> 2) __ublk_ctrl_unreg_buf() calls unpin_user_pages() under mas_lock
> (a spinlock). unpin_user_pages can be expensive for large buffers
> and may take additional locks if folio refcount drops to zero.
> Restructure to drop mas_lock before unpinning, re-acquiring it
> to continue iteration.
>
> Both functions now use the same pattern: erase under lock, drop lock,
> unpin and free, re-lock to continue. Extract ublk_unpin_range_pages()
> helper to share the page unpinning loop.
>
> Reported-by: Jens Axboe <axboe@kernel.dk>
> Closes: https://lore.kernel.org/linux-block/0349d72d-dff8-4f9f-b448-919fa5ae96da@kernel.dk/
> Cc: Liam R. Howlett <liam.howlett@oracle.com>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
I observed the same WARN at blktests test cases block/033 and ublk/*. I
confirmed this patch avoids the WARN and makes the test cases pass. Thanks!
Tested-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
I also bisected and confirmed that the commit below is the failure trigger.
Adding a Fixes tag might add a bit of value.
Fixes: 5e864438e285 ("ublk: replace xarray with IDA for shmem buffer index allocation")
prev parent reply other threads:[~2026-04-22 1:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-04-22 0:08 [PATCH] ublk: fix maple tree lockdep warning and unpin under spinlock Ming Lei
2026-04-22 1:59 ` Shin'ichiro Kawasaki [this message]
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=aegqG_y2VXD_W8y3@shinmob \
--to=shinichiro.kawasaki@wdc.com \
--cc=axboe@kernel.dk \
--cc=csander@purestorage.com \
--cc=liam.howlett@oracle.com \
--cc=linux-block@vger.kernel.org \
--cc=ming.lei@redhat.com \
--cc=tom.leiming@gmail.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