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=1796381283; b=io3W6LQH6/t+GI366E6oDWQvfhe3jWQY97dakmGHz2urPg2xgkw1gpWlefIg2CCogRDg XUQrXv6dXsaIZQeX7YEv9oWaYE9spD37AHty7LtAdk4wcXck3/Kj4bdt2tR4KCBWe2Ul+ lJMv6ih5g+k2tYo09qPf2/yTkrnnTJNUnIkvmhGOSAiNFYRpcSp/Afo58hlu1813JTI+y Aw6BrCO0VSLNVf6AO3htYLWYROIIoc6d/HqIv/KLOLQNxhFtRXbq2LS7reFPFYloiQJt8 VOTkFAJBIo96N+yxhe7XlwfU+OJMvM+mHVcouvhZPrNr0wHDyiltDQcocqeHQ4voKGg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381283; 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=XqGK29YfXZ2DHc63wBsaLL/qowtr36IbJd4A3nhDAJ8=; b=w9NeO6TzLjtjEYlq2QHhty/ZZLjRJociujEBFIf5jYR/A19xxcUll6mBFwt+UarsBuf2 JGA0v2RdP07r49EogqR0U5YAZbmG0ebQxssdK3Af5vcwRmCmNY3TK569+rdx93cULoD44 6Lap88Fc1cHVyREs5ge4Gw5QpADE7i/ML5JYNyoE6ZFgJIzJ6Xorx6cMwU26vWKK84K39 lGKBADj9IdKc8z6LJ6sl7L3Viy08EpGiZcGZ7mPxCKAv6r03lfxE3BjMKyF3EtnWi6ze7 HZdJUFulQsj3e4VpjqqX5EtbMF1oEe2gHI7kwppCEYrQypIiaiMZ6DrHnKWgXENlrZg== 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=XcurApfR; 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 4DC89606A689; Fri, 4 Dec 2026 10:48:03 +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=XcurApfR Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE63E1F0092C; Fri, 4 Dec 2026 10:48:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381283; bh=XqGK29YfXZ2DHc63wBsaLL/qowtr36IbJd4A3nhDAJ8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XcurApfR8Nrlr9we4K59diA6CsjTJfBtAO7ZOz9lCPmclU+vfdo/bFvw8xL6RPqQT ZgGgDweM+lruELq9AUEGFPaUDgy9VZ/g5v18/bHoUEWg0sUFvaffOpCY0TAPfXeWfp QjisB6YluLKqoZpTbakUaeYBkjfMYvESV+3BLJMI= 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 7.3 638/742] nvme: avoid wrapping admin_timeout and io_timeout Date: Fri, 4 Dec 2026 19:08:22 +0900 Message-ID: <20261204100652.041111953@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore 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 7.3-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 @@ -4893,7 +4893,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