[PATCH v6 1/3] nvme-multipath: keep a large delayed_removal_secs from wrapping around
From: Qiliang Yuan
Date: Thu Nov 19 2026 - 20:25:25 EST
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@xxxxxxxxx>
---
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