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=1796361703; b=W3ipM0YoieCg+63bhylBT9WclVjk5FiQ6mmR5fc60uLmWOr1T8M58JOZl1HBCveOHi37 cG5fJtFCVc8sW3ApLDarRevIpZuFurMPnTFgttH60SbkIhjbRwMPhihjSBa/YbVPYKt5d eI58v0jYyQtVEZ09dCZMXy3bj5Zp10E3EhGZ3fsaAbI+USHgXVmDLe3QwNaEvc2TrEzQH 0zxIFQWUSBvP8KtZ3pdER8w/LiBJeMnaWiEfWaCT+MoeH+BGeGVtojZ5wyb53ZVGKbTK5 haee0bkY5JTtGxbE8seoG9xF0Eh4u3FPtxx7fykeZM3WXNi7QhwmJcTim2PGLiXG4RQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796361703; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:MIME-Version:Content-Transfer-Encoding; bh=xCeCEo60MTnLBEBzgpvAkTw2Kc3LP+7dlGEeuCw2dZM=; b=QySlAM4y+4POP9hMm2Ul5z5GSu96AcyqMtXSOoTPNxAtkjf6Fub2vvCoDhHQMlrM2w0T pOe3j8oZDU/RM08neZgJpB9m1PVh6VAbM20blAU+bcIktJhS2jRM6t7BJoRh0FWyDyz3Z vunyqmGvxq39wPDRofBoG+26NqrOR3MG78c5B5tGV4E3UJB161qzA27M1KgfOlU8NgMCG VJPrWEdleo6Chwq0OegYiUM6X+/DN++WcmhqVh6zybvA6T56xM/PX0lfyZ5hoAA4/VIk3 M4QxxmOkVr7pIqJAnnhlBTlQbB/hFN8o4AdPgT3d2iVUbhbvOKzvM9YueL/E9uvQtOQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bUolIIxf; 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 D7A55606A322 for ; Fri, 4 Dec 2026 05:21:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=bUolIIxf Received: by smtp.kernel.org (Postfix) with ESMTPSA id 170681F000C2; Fri, 4 Dec 2026 05:21:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796361703; bh=xCeCEo60MTnLBEBzgpvAkTw2Kc3LP+7dlGEeuCw2dZM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=bUolIIxfqwXtWfwgSDeFXYNVUcCvNewdnz1Wm4so36884MBqYs5Cw1rYElVaoH6gS z/SDIVLqA9nYj5UTcg4W2nnmli6TRQ9hA3F0ema6uhPcf7JYSiGjIUo2jf1JY+6QJb 2bZxLDEx388M0iDRsSKjlPLCyDu4JAiRbE5L3jrVA6iBsbphuUzkFo1b0f7E6l6Yyx 0nL0VlLCIQRWVdOFHqNzfvnkDnj5oiZ+WvgnNcnENW6vx/8x3i7eWkoHBaZ9ZXaaaz v4UP0LBBbZ7YFjJN0hEFYsWreeqYKUSS7rc+djUmTNq0vf2N2JdA+GHcNFghvME33u 50PNj37oqoQIw== From: Sasha Levin To: stable@vger.kernel.org Cc: Yingjie Wang <1075151112@qq.com>, Christoph Hellwig , Keith Busch , Sasha Levin Subject: [PATCH 6.1.y] nvme: avoid wrapping admin_timeout and io_timeout Date: Fri, 4 Dec 2026 00:21:41 -0500 Message-ID: <20261204052122.2755846-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026120225-periscope-abruptly-bdb6@gregkh> References: <2026120225-periscope-abruptly-bdb6@gregkh> X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Keith Busch [ 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 --- 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 +/* 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