mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Daniel Wagner <wagi@kernel.org>
To: Christoph Hellwig <hch@lst.de>, Keith Busch <kbusch@kernel.org>,
	 Jens Axboe <axboe@kernel.dk>, Ming Lei <ming.lei@redhat.com>
Cc: Guangwu Zhang <guazhang@redhat.com>,
	 Chengming Zhou <zhouchengming@bytedance.com>,
	 Thomas Gleixner <tglx@kernel.org>,
	linux-nvme@lists.infradead.org,  linux-kernel@vger.kernel.org,
	linux-block@vger.kernel.org,  Daniel Wagner <wagi@kernel.org>
Subject: [PATCH 0/3] block: revert avoid acquiring cpu hotplug lock in group_cpus_evenly
Date: Thu, 26 Feb 2026 14:40:34 +0100	[thread overview]
Message-ID: <20260226-revert-cpu-read-lock-v1-0-eb005072566e@kernel.org> (raw)

The 0263f92fadbb ("lib/group_cpus.c: avoid acquiring cpu hotplug lock in
group_cpus_evenly") commit removed the CPU read lock.

The lock was removed because the nvme-pci driver reset handler attempted to
acquire the CPU read lock during CPU hotplug offlining (holds the write lock).
As a result, the block layer offline callback could not make progress because
in-flight requests were detected.

	static bool blk_mq_has_request(struct request *rq, void *data)
	{
		struct rq_iter_data *iter_data = data;
	
		if (rq->mq_hctx != iter_data->hctx)
			return true;
	
		iter_data->has_rq = true;
		return false;
	}

In order to bring back the CPU read lock, introduce an explicit handshake
protocol between the driver and the block layer. This allows the driver to
signal when it is safe to ignore any remaining pending requests.

I've tried several different approaches, like looking at the request_queue state
in blk_mq_has_request or at the request state but I could not convienced myself
that this works.

For example, when a requests is right before nvme_prep_rq in nvme_queue_rq, the
request is not yet marked as in flight nor are there any queue state checks left
in the remaining path:

	static blk_status_t nvme_queue_rq(struct blk_mq_hw_ctx *hctx,
				 const struct blk_mq_queue_data *bd)
	{
		[...]
	
		if (unlikely(!nvme_check_ready(&dev->ctrl, req, true)))
			return nvme_fail_nonready_command(&dev->ctrl, req);
	
		ret = nvme_prep_rq(req);
		if (unlikely(ret))
			return ret;
		spin_lock(&nvmeq->sq_lock);
		nvme_sq_copy_cmd(nvmeq, &iod->cmd);
		nvme_write_sq_db(nvmeq, bd->last);
		spin_unlock(&nvmeq->sq_lock);
		return BLK_STS_OK;
	}
	
Thus a check like

	 if (!blk_mq_request_started(rq) && blk_queue_quiesced(rq->q))

in blk_mq_has_request is not enough.

I've tested this by a hammering the system with PCI resets and CPU
onlining/offlining while generating load with fio. The original problem was
fairly simple to reproduce (wihtin a minute or so) and with this patches it
survived a whole night.

This unblocks my isolcpu work which touches group_cpus_evenly.

https://lore.kernel.org/linux-nvme/87cy7vrbc4.ffs@tglx/

Signed-off-by: Daniel Wagner <wagi@kernel.org>
---
Daniel Wagner (3):
      nvme: failover requests for inactive hctx
      blk-mq: add handshake for offlinig hw queues
      Revert "lib/group_cpus.c: avoid acquiring cpu hotplug lock in group_cpus_evenly"

 block/blk-mq-debugfs.c        |  1 +
 block/blk-mq.c                | 36 +++++++++++++++++++
 drivers/nvme/host/core.c      | 83 ++++++++++++++++++++++++++++++++++++++++++-
 drivers/nvme/host/multipath.c | 43 ----------------------
 drivers/nvme/host/nvme.h      |  3 +-
 drivers/nvme/host/pci.c       |  3 ++
 include/linux/blk-mq.h        |  3 ++
 lib/group_cpus.c              | 21 +++--------
 8 files changed, 132 insertions(+), 61 deletions(-)
---
base-commit: 6de23f81a5e08be8fbf5e8d7e9febc72a5b5f27f
change-id: 20260226-revert-cpu-read-lock-94685007080a

Best regards,
-- 
Daniel Wagner <wagi@kernel.org>


             reply	other threads:[~2026-02-26 13:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-26 13:40 Daniel Wagner [this message]
2026-02-26 13:40 ` [PATCH 1/3] nvme: failover requests for inactive hctx Daniel Wagner
2026-02-26 19:09   ` kernel test robot
2026-02-26 23:55   ` kernel test robot
2026-02-26 13:40 ` [PATCH 2/3] blk-mq: add handshake for offlinig hw queues Daniel Wagner
2026-02-26 13:40 ` [PATCH 3/3] Revert "lib/group_cpus.c: avoid acquiring cpu hotplug lock in group_cpus_evenly" Daniel Wagner
2026-02-26 14:04   ` Ming Lei
2026-03-02 14:04     ` Daniel Wagner
2026-03-02 14:12       ` Ming Lei
2026-03-02 14:27         ` Daniel Wagner

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=20260226-revert-cpu-read-lock-v1-0-eb005072566e@kernel.org \
    --to=wagi@kernel.org \
    --cc=axboe@kernel.dk \
    --cc=guazhang@redhat.com \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=ming.lei@redhat.com \
    --cc=tglx@kernel.org \
    --cc=zhouchengming@bytedance.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®