From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796382692; b=MxNDzoIrGYWDig0AlgbpkSAI/Hz2F9rbxxIO7Yp/4zcpNRAnKxpyX0hxL20vjL+tcstE zmZWX2EWppBm7Wcg1qP65xba+2oQy6ijayyOB62PLHgGhXaC+SJauspphBR6932JQbUsd izZzgLR58WSqzTW+DcLseSPC6IoOo+qFCwAJy0EWx4JnMmHc5SewuHnYp1aV8dZUl9EEj drni0yyHGKnaF04m/XMpUMBSiq28Wz84EWAonZ2Qn/NoLtqMJQJmA6RVTI7p2XUI1DPrp zF1DdWwMW/oL3TVgTZP0qxVvaq6czqokUJ42yq0osBTvC8pH/t7NU1mxDjssluDXgUQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796382692; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=eXfRLgKCGHJMxOPwm5DkxXN8349G27fDEjqpB8ea8o4=; b=AchuUuTkXymZSP/YtCZuuDtJoeue8LXEb6Qmhv0yau593nGJ3v8r+V8H8QTt9x3jnIOY NMEtKDNIFoqOlN+gJLGoxgV39/l2hH5tfWI2kIx9AthPZqgtCkL3j/d48TjrsN8vMEV/l wJkhma4rASA03MvRZTAU5+Y/XEEEPOpNqESfhOpB8hXbug9LMD2F5sUnRiwIn6Fr2brgT FC37TRllTEd5l9X2yFJIl8v8WM8G/nHfpzcbuMqSQFhvkTZkQjBH9m3UhaqUhquBHi0em dHRohmEeunYAuPSlWoolaR7P0AzjLOWC7PmTskkTy1KHq8zm1Hxtn7mI6NPw0UOUtiA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=BmJqPbTn; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 29FD4606A322; Fri, 4 Dec 2026 11:11:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=BmJqPbTn Received: by smtp.kernel.org (Postfix) with ESMTPSA id 97A7C1F000CE; Fri, 4 Dec 2026 11:11:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796382692; bh=eXfRLgKCGHJMxOPwm5DkxXN8349G27fDEjqpB8ea8o4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=BmJqPbTnXQdJlnpTuK8OCrIcVA2yTb3jVKuBNWyzT9PnxLxWaeikmk/H6EFinKbon NXxs8luoUKvBjJ8ajThonx8NfVScwkzIoDqab6Y3pm02Y/0960PGdVB50MRF5DGze9 6NdVwKAftCoMT18BOSy37PdJRHeI8pYbQf8mrywY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Yingjie Wang <1075151112@qq.com>, Christoph Hellwig , Keith Busch Subject: [PATCH 6.18 563/703] nvme: avoid wrapping admin_timeout and io_timeout Date: Fri, 4 Dec 2026 19:07:42 +0900 Message-ID: <20261204100642.752463275@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100627.522266145@linuxfoundation.org> References: <20261204100627.522266145@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Yingjie Wang <1075151112@qq.com> commit 4a5aeebf1a00360bcc53c9e29fcd8d47aefa4c1d upstream. 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 Signed-off-by: Keith Busch Signed-off-by: Greg Kroah-Hartman --- drivers/nvme/host/core.c | 2 +- drivers/nvme/host/nvme.h | 13 +++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -4765,7 +4765,7 @@ static void nvme_fw_act_work(struct work if (ctrl->mtfa) fw_act_timeout = jiffies + msecs_to_jiffies(ctrl->mtfa * 100); else - fw_act_timeout = jiffies + secs_to_jiffies(admin_timeout); + fw_act_timeout = jiffies + NVME_ADMIN_TIMEOUT; nvme_quiesce_io_queues(ctrl); while (nvme_ctrl_pp_status(ctrl)) { --- a/drivers/nvme/host/nvme.h +++ b/drivers/nvme/host/nvme.h @@ -22,11 +22,20 @@ extern const struct pr_ops nvme_pr_ops; +/* 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