From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Yingjie Wang <1075151112@qq.com>, Christoph Hellwig <hch@lst.de>,
Keith Busch <kbusch@kernel.org>, Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.1.y] nvme: avoid wrapping admin_timeout and io_timeout
Date: Fri, 4 Dec 2026 00:21:41 -0500 [thread overview]
Message-ID: <20261204052122.2755846-1-sashal@kernel.org> (raw)
In-Reply-To: <2026120225-periscope-abruptly-bdb6@gregkh>
From: Yingjie Wang <1075151112@qq.com>
[ Upstream commit 4a5aeebf1a00360bcc53c9e29fcd8d47aefa4c1d ]
NVME_ADMIN_TIMEOUT and NVME_IO_TIMEOUT multiply the admin_timeout and
io_timeout module parameters by HZ in unsigned int arithmetic, and
nvme_fw_act_work() does the same through secs_to_jiffies(). The parameters
accept any unsigned int, so values above UINT_MAX / HZ wrap. With HZ=1000,
io_timeout=4294968 becomes 704 jiffies, and a controller created afterwards
times out I/O after 0.7 seconds instead of about 49.7 days. On 32-bit
systems, results above MAX_JIFFY_OFFSET are also unsafe relative delays and
can be treated as already expired.
These large values are used in practice. AWS documents
nvme_core.io_timeout=4294967295 for EBS volumes and says Amazon Linux uses
it by default. With HZ=1000, the current code happens to wrap this setting
to 4294966296 jiffies, which still behaves as a long timeout on 64-bit
systems.
Add nvme_timeout_to_jiffies(), which caps the seconds value so that the
result fits the u32 timeout fields and stays within MAX_JIFFY_OFFSET for
32-bit timers, and use it for both macros and for the firmware
activation wait. On 64-bit kernels every timeout that did not wrap is
unchanged. Larger values saturate instead of being rejected so that the
documented setting keeps a long timeout.
Fixes: 8ae4e4477d8f ("nvme: update timeout module parameter type")
Cc: stable@vger.kernel.org
Signed-off-by: Yingjie Wang <1075151112@qq.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
[ sashal: Replaced upstream's secs_to_jiffies(admin_timeout) in nvme_fw_act_work() with NVME_ADMIN_TIMEOUT, since this tree has msecs_to_jiffies(admin_timeout * 1000) and no secs_to_jiffies(). ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/nvme/host/core.c | 3 +--
drivers/nvme/host/nvme.h | 13 +++++++++++--
2 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
index f35165aa0bb7b..db3057647a28a 100644
--- a/drivers/nvme/host/core.c
+++ b/drivers/nvme/host/core.c
@@ -4885,8 +4885,7 @@ static void nvme_fw_act_work(struct work_struct *work)
fw_act_timeout = jiffies +
msecs_to_jiffies(ctrl->mtfa * 100);
else
- fw_act_timeout = jiffies +
- msecs_to_jiffies(admin_timeout * 1000);
+ fw_act_timeout = jiffies + NVME_ADMIN_TIMEOUT;
nvme_stop_queues(ctrl);
while (nvme_ctrl_pp_status(ctrl)) {
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 338f98b45c893..06d0d587194ae 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -19,11 +19,20 @@
#include <trace/events/block.h>
+/* Seconds to jiffies, capped for the u32 timeouts and timer delays */
+static inline unsigned int nvme_timeout_to_jiffies(unsigned int timeout)
+{
+ unsigned long max_secs;
+
+ max_secs = min_t(unsigned long, UINT_MAX, MAX_JIFFY_OFFSET) / HZ;
+ return min_t(unsigned long, timeout, max_secs) * HZ;
+}
+
extern unsigned int nvme_io_timeout;
-#define NVME_IO_TIMEOUT (nvme_io_timeout * HZ)
+#define NVME_IO_TIMEOUT nvme_timeout_to_jiffies(nvme_io_timeout)
extern unsigned int admin_timeout;
-#define NVME_ADMIN_TIMEOUT (admin_timeout * HZ)
+#define NVME_ADMIN_TIMEOUT nvme_timeout_to_jiffies(admin_timeout)
#define NVME_DEFAULT_KATO 5
--
2.53.0
prev parent reply other threads:[~2026-12-04 5:21 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 13:51 FAILED: patch "[PATCH] nvme: avoid wrapping admin_timeout and io_timeout" failed to apply to 6.1-stable tree gregkh
2026-12-04 5:21 ` Sasha Levin [this message]
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=20261204052122.2755846-1-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=1075151112@qq.com \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=stable@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.