From: Ming Lei <ming.lei@redhat.com>
To: Nilay Shroff <nilay@linux.ibm.com>
Cc: Damien Le Moal <dlemoal@kernel.org>,
Christoph Hellwig <hch@lst.de>, Jens Axboe <axboe@kernel.dk>,
linux-block@vger.kernel.org
Subject: Re: [PATCH 1/2] block: avoid to hold q->limits_lock across APIs for atomic update queue limits
Date: Wed, 18 Dec 2024 21:40:32 +0800 [thread overview]
Message-ID: <Z2LQ0PYmt3DYBCi0@fedora> (raw)
In-Reply-To: <f34f179a-4eaf-4f73-93ff-efb1ff9fe482@linux.ibm.com>
On Wed, Dec 18, 2024 at 05:03:00PM +0530, Nilay Shroff wrote:
>
>
> On 12/18/24 07:39, Ming Lei wrote:
> > On Tue, Dec 17, 2024 at 08:07:06AM -0800, Damien Le Moal wrote:
> >> On 2024/12/16 23:30, Ming Lei wrote:
> >>> On Tue, Dec 17, 2024 at 08:19:28AM +0100, Christoph Hellwig wrote:
> >>>> On Tue, Dec 17, 2024 at 03:05:48PM +0800, Ming Lei wrote:
> >>>>> On Tue, Dec 17, 2024 at 05:40:56AM +0100, Christoph Hellwig wrote:
> >>>>>> On Tue, Dec 17, 2024 at 09:52:51AM +0800, Ming Lei wrote:
> >>>>>>> The local copy can be updated in any way with any data, so does another
> >>>>>>> concurrent update on q->limits really matter?
> >>>>>>
> >>>>>> Yes, because that means one of the updates get lost even if it is
> >>>>>> for entirely separate fields.
> >>>>>
> >>>>> Right, but the limits are still valid anytime.
> >>>>>
> >>>>> Any suggestion for fixing this deadlock?
> >>>>
> >>>> What is "this deadlock"?
> >>>
> >>> The commit log provides two reports:
> >>>
> >>> - lockdep warning
> >>>
> >>> https://lore.kernel.org/linux-block/Z1A8fai9_fQFhs1s@hovoldconsulting.com/
> >>>
> >>> - real deadlock report
> >>>
> >>> https://lore.kernel.org/linux-scsi/ZxG38G9BuFdBpBHZ@fedora/
> >>>
> >>> It is actually one simple ABBA lock:
> >>>
> >>> 1) queue_attr_store()
> >>>
> >>> blk_mq_freeze_queue(q); //queue freeze lock
> >>> res = entry->store(disk, page, length);
> >>> queue_limits_start_update //->limits_lock
> >>> ...
> >>> queue_limits_commit_update
> >>> blk_mq_unfreeze_queue(q);
> >>
> >> The locking + freeze pattern should be:
> >>
> >> lim = queue_limits_start_update(q);
> >> ...
> >> blk_mq_freeze_queue(q);
> >> ret = queue_limits_commit_update(q, &lim);
> >> blk_mq_unfreeze_queue(q);
> >>
> >> This pattern is used in most places and anything that does not use it is likely
> >> susceptible to a similar ABBA deadlock. We should probably look into trying to
> >> integrate the freeze/unfreeze calls directly into queue_limits_commit_update().
> >>
> >> Fixing queue_attr_store() to use this pattern seems simpler than trying to fix
> >> sd_revalidate_disk().
> >
> > This way looks good, just commit af2814149883 ("block: freeze the queue in
> > queue_attr_store") needs to be reverted, and freeze/unfreeze has to be
> > added to each queue attribute .store() handler.
> >
> Wouldn't it be feasible to add blk-mq freeze in queue_limits_start_update()
> and blk-mq unfreeze in queue_limits_commit_update()? If we do this then
> the pattern would be,
>
> queue_limits_start_update(): limit-lock + freeze
> queue_limits_commit_update() : unfreeze + limit-unlock
>
> Then in queue_attr_store() we shall just remove freeze/unfreeze.
>
> We also need to fix few call sites where we've code block,
>
> {
> blk_mq_freeze_queue()
> ...
> queue_limits_start_update()
> ...
> queue_limits_commit_update()
> ...
> blk_mq_unfreeze_queue()
>
> }
>
> In the above code block, we may then replace blk_mq_freeze_queue() with
> queue_limits_commit_update() and similarly replace blk_mq_unfreeze_queue()
> with queue_limits_commit_update().
>
> {
> queue_limits_start_update()
> ...
> ...
> ...
> queue_limits_commit_update()
In sd_revalidate_disk(), blk-mq request is allocated under queue_limits_start_update(),
then ABBA deadlock is triggered since blk_queue_enter() implies same lock(freeze lock)
from blk_mq_freeze_queue().
Thanks,
Ming
next prev parent reply other threads:[~2024-12-18 13:40 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-16 8:02 [PATCH 0/2] block: fix deadlock caused by atomic limits update Ming Lei
2024-12-16 8:02 ` [PATCH 1/2] block: avoid to hold q->limits_lock across APIs for atomic update queue limits Ming Lei
2024-12-16 15:49 ` Christoph Hellwig
2024-12-17 1:52 ` Ming Lei
2024-12-17 4:40 ` Christoph Hellwig
2024-12-17 7:05 ` Ming Lei
2024-12-17 7:19 ` Christoph Hellwig
2024-12-17 7:30 ` Ming Lei
2024-12-17 16:07 ` Damien Le Moal
2024-12-18 2:09 ` Ming Lei
2024-12-18 11:33 ` Nilay Shroff
2024-12-18 13:40 ` Ming Lei [this message]
2024-12-18 14:05 ` Nilay Shroff
2024-12-18 14:57 ` Damien Le Moal
2024-12-19 6:20 ` Christoph Hellwig
2024-12-19 7:16 ` Nilay Shroff
2024-12-21 13:03 ` Nilay Shroff
2024-12-30 9:02 ` Ming Lei
2024-12-30 23:29 ` Damien Le Moal
2025-01-01 11:17 ` Nilay Shroff
2024-12-19 6:17 ` Christoph Hellwig
2024-12-19 6:15 ` Christoph Hellwig
2024-12-16 8:02 ` [PATCH 2/2] block: remove queue_limits_cancel_update() Ming Lei
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=Z2LQ0PYmt3DYBCi0@fedora \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=dlemoal@kernel.org \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=nilay@linux.ibm.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