mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Qiliang Yuan <qiliang.yuan@linux.dev>
To: Keith Busch <kbusch@kernel.org>, Jens Axboe <axboe@kernel.dk>,
	 Christoph Hellwig <hch@lst.de>, Sagi Grimberg <sagi@grimberg.me>,
	 Nilay Shroff <nilay@linux.ibm.com>,
	Hannes Reinecke <hare@suse.de>
Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org,
	 Qiliang Yuan <qiliang.yuan@linux.dev>
Subject: [PATCH v6 1/3] nvme-multipath: keep a large delayed_removal_secs from wrapping around
Date: Thu, 19 Nov 2026 20:25:01 -0500	[thread overview]
Message-ID: <20261119-bug-nvme-mpath-set-live-srcu-v6-1-da85b18b274b@linux.dev> (raw)
In-Reply-To: <20261119-bug-nvme-mpath-set-live-srcu-v6-0-da85b18b274b@linux.dev>

nvme_mpath_remove_disk() delays the removal of a namespace head that
lost its last path by delayed_removal_secs, which it converts to
jiffies as delayed_removal_secs * HZ.

delayed_removal_secs is an unsigned int, so the product is computed in
32 bits and wraps around for values above UINT_MAX / HZ. With HZ=1000,
4294968 seconds turns into a delay of 704 jiffies, and the head goes
away in under a second instead of after about 50 days.

Compute the delay in 64 bits and cap it at MAX_JIFFY_OFFSET.

With delayed_removal_secs set to 4294968 at HZ=1000, removing the last
path deletes the head after (mean of two runs, min-max in parentheses;
"> 10000" means it was still there 10 s later):

  before (ms)     after (ms)
  858 (856-860)   > 10000

Fixes: 62188639ec160 ("nvme-multipath: introduce delayed removal of the multipath head node")
Signed-off-by: Qiliang Yuan <qiliang.yuan@linux.dev>
---
 drivers/nvme/host/multipath.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index ae8059366b57d..9958d08cd3829 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -724,6 +724,15 @@ static void nvme_requeue_work(struct work_struct *work)
 	}
 }
 
+/*
+ * Convert delayed_removal_secs to jiffies, capped at MAX_JIFFY_OFFSET so
+ * that a large value doesn't wrap around into a short delay.
+ */
+static unsigned long nvme_delayed_removal_jiffies(unsigned int secs)
+{
+	return min_t(u64, (u64)secs * HZ, MAX_JIFFY_OFFSET);
+}
+
 static void nvme_remove_head(struct nvme_ns_head *head)
 {
 	if (test_and_clear_bit(NVME_NSHEAD_DISK_LIVE, &head->flags)) {
@@ -1523,7 +1532,7 @@ void nvme_mpath_remove_disk(struct nvme_ns_head *head)
 	 */
 	if (head->delayed_removal_secs && try_module_get(THIS_MODULE)) {
 		mod_delayed_work(nvme_wq, &head->remove_work,
-				head->delayed_removal_secs * HZ);
+			nvme_delayed_removal_jiffies(head->delayed_removal_secs));
 	} else {
 		list_del_init(&head->entry);
 		remove = true;

-- 
2.43.0


  reply	other threads:[~2026-11-20  1:25 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20  1:25 [PATCH v6 0/3] nvme-multipath: requeue work fixes Qiliang Yuan
2026-11-20  1:25 ` Qiliang Yuan [this message]
2026-11-20  1:25 ` [PATCH v6 2/3] nvme-multipath: apply delayed_removal_secs changes to a pending removal Qiliang Yuan
2026-11-20  1:25 ` [PATCH v6 3/3] nvme-multipath: don't wait for a grace period in nvme_mpath_set_live() Qiliang Yuan

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=20261119-bug-nvme-mpath-set-live-srcu-v6-1-da85b18b274b@linux.dev \
    --to=qiliang.yuan@linux.dev \
    --cc=axboe@kernel.dk \
    --cc=hare@suse.de \
    --cc=hch@lst.de \
    --cc=kbusch@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=nilay@linux.ibm.com \
    --cc=sagi@grimberg.me \
    /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®