From: Ming Lei <ming.lei@redhat.com>
To: Jens Axboe <axboe@kernel.dk>, linux-block@vger.kernel.org
Cc: "Valdis Klētnieks" <valdis.kletnieks@vt.edu>,
"Nilay Shroff" <nilay@linux.ibm.com>,
"Christoph Hellwig" <hch@lst.de>
Subject: Re: [PATCH 1/3] block: add blk_mq_enter_no_io() and blk_mq_exit_no_io()
Date: Wed, 2 Apr 2025 15:55:51 +0800 [thread overview]
Message-ID: <Z-zthxEKJg_kZqgg@fedora> (raw)
In-Reply-To: <20250402043851.946498-2-ming.lei@redhat.com>
On Wed, Apr 02, 2025 at 12:38:47PM +0800, Ming Lei wrote:
> Add blk_mq_enter_no_io() and blk_mq_exit_no_io() for preventing queue
> from handling any FS or passthrough IO, meantime the queue is kept in
> non-freeze state.
>
> The added two APIs are for avoiding many potential lock risk related
> with freeze lock.
>
> Also add two variants of memsave version.
>
> Signed-off-by: Ming Lei <ming.lei@redhat.com>
> ---
> block/blk-core.c | 6 ++++--
> block/blk-mq.c | 18 ++++++++++++++++--
> block/blk-mq.h | 19 +++++++++++++++++++
> block/blk.h | 5 +++--
> include/linux/blkdev.h | 8 ++++++++
> 5 files changed, 50 insertions(+), 6 deletions(-)
>
> diff --git a/block/blk-core.c b/block/blk-core.c
> index 4623de79effa..a54a18fada8a 100644
> --- a/block/blk-core.c
> +++ b/block/blk-core.c
> @@ -319,7 +319,8 @@ int blk_queue_enter(struct request_queue *q, blk_mq_req_flags_t flags)
> smp_rmb();
> wait_event(q->mq_freeze_wq,
> (!q->mq_freeze_depth &&
> - blk_pm_resume_queue(pm, q)) ||
> + (blk_pm_resume_queue(pm, q) ||
> + !blk_queue_no_io(q))) ||
> blk_queue_dying(q));
> if (blk_queue_dying(q))
> return -ENODEV;
> @@ -352,7 +353,8 @@ int __bio_queue_enter(struct request_queue *q, struct bio *bio)
> smp_rmb();
> wait_event(q->mq_freeze_wq,
> (!q->mq_freeze_depth &&
> - blk_pm_resume_queue(false, q)) ||
> + (blk_pm_resume_queue(false, q) ||
Here the above '||' should have been '&&'.
> + !blk_queue_no_io(q))) ||
> test_bit(GD_DEAD, &disk->state));
> if (test_bit(GD_DEAD, &disk->state))
> goto dead;
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index ae8494d88897..075ee51066b3 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -222,8 +222,7 @@ bool __blk_mq_unfreeze_queue(struct request_queue *q, bool force_atomic)
> bool unfreeze;
>
> mutex_lock(&q->mq_freeze_lock);
> - if (force_atomic)
> - q->q_usage_counter.data->force_atomic = true;
> + q->q_usage_counter.data->force_atomic = force_atomic;
> q->mq_freeze_depth--;
> WARN_ON_ONCE(q->mq_freeze_depth < 0);
> if (!q->mq_freeze_depth) {
> @@ -278,6 +277,21 @@ void blk_mq_quiesce_queue_nowait(struct request_queue *q)
> }
> EXPORT_SYMBOL_GPL(blk_mq_quiesce_queue_nowait);
>
> +void blk_mq_enter_no_io(struct request_queue *q)
> +{
> + blk_mq_freeze_queue_nomemsave(q);
> + q->no_io = true;
> + if (__blk_mq_unfreeze_queue(q, true))
> + blk_unfreeze_release_lock(q);
> +}
> +
> +void blk_mq_exit_no_io(struct request_queue *q)
> +{
> + blk_mq_freeze_queue_nomemsave(q);
> + q->no_io = false;
> + blk_mq_unfreeze_queue_nomemrestore(q);
> +}
> +
> /**
> * blk_mq_wait_quiesce_done() - wait until in-progress quiesce is done
> * @set: tag_set to wait on
> diff --git a/block/blk-mq.h b/block/blk-mq.h
> index 3011a78cf16a..f49070c8c05f 100644
> --- a/block/blk-mq.h
> +++ b/block/blk-mq.h
> @@ -452,4 +452,23 @@ static inline bool blk_mq_can_poll(struct request_queue *q)
> q->tag_set->map[HCTX_TYPE_POLL].nr_queues;
> }
>
> +void blk_mq_enter_no_io(struct request_queue *q);
> +void blk_mq_exit_no_io(struct request_queue *q);
> +
> +static inline unsigned int __must_check
> +blk_mq_enter_no_io_memsave(struct request_queue *q)
> +{
> + unsigned int memflags = memalloc_noio_save();
> +
> + blk_mq_enter_no_io(q);
> + return memflags;
> +}
> +
> +static inline void
> +blk_mq_exit_no_io_memrestore(struct request_queue *q, unsigned int memflags)
> +{
> + blk_mq_exit_no_io(q);
> + memalloc_noio_restore(memflags);
> +}
> +
> #endif
> diff --git a/block/blk.h b/block/blk.h
> index 006e3be433d2..7d0994c1d3ad 100644
> --- a/block/blk.h
> +++ b/block/blk.h
> @@ -56,8 +56,9 @@ static inline bool blk_try_enter_queue(struct request_queue *q, bool pm)
> * The code that increments the pm_only counter must ensure that the
> * counter is globally visible before the queue is unfrozen.
> */
> - if (blk_queue_pm_only(q) &&
> - (!pm || queue_rpm_status(q) == RPM_SUSPENDED))
> + if ((blk_queue_pm_only(q) &&
> + (!pm || queue_rpm_status(q) == RPM_SUSPENDED)) ||
Same with above.
Thanks,
Ming
next prev parent reply other threads:[~2025-04-02 7:56 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-02 4:38 [PATCH 0/3] block: fix lock dependency between freeze and elevator lock Ming Lei
2025-04-02 4:38 ` [PATCH 1/3] block: add blk_mq_enter_no_io() and blk_mq_exit_no_io() Ming Lei
2025-04-02 7:55 ` Ming Lei [this message]
2025-04-02 13:50 ` Nilay Shroff
2025-04-02 4:38 ` [PATCH 2/3] block: don't call freeze queue in elevator_switch() and elevator_disable() Ming Lei
2025-04-02 13:45 ` Nilay Shroff
2025-04-02 4:38 ` [PATCH 3/3] block: use blk_mq_no_io() for avoiding lock dependency Ming Lei
2025-04-02 13:43 ` Nilay Shroff
2025-04-03 2:54 ` 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=Z-zthxEKJg_kZqgg@fedora \
--to=ming.lei@redhat.com \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=linux-block@vger.kernel.org \
--cc=nilay@linux.ibm.com \
--cc=valdis.kletnieks@vt.edu \
/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