From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5522E606A335 for ; Wed, 2 Dec 2026 19:47:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=yrrxFHZ7; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SPVRr0Fl DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Date: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Cc:To:Subject: From:Message-ID:MIME-Version:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=cGXbFltxSaWcLkYKjluAPVkiXKuPOPqd3KkEUmnT8S4=; b=yrrxFHZ7yMH+GKFuEslpD3RN+O 9oU2oYdEHHK3Pp2609Dx283bxeW8HPoUMVQvhbPLUggwOos/INGgB5bosiCeAo9U7n0gn9bgxLr9e bXn0ckTGqwRUeu5nRMpjHuKEuuu/OQ3Js+wrdpkA6IU51yzNbFRWFXy5P+46RUSwXpSe38sTRu7VN Dc8IktP3rP3krI62inBeC8oOSBQ/bf5EHU5LzjdLjX5jxsWOftt2Ui7k4KU7xsj2F5wx47E3Q8oHK PaY2Kh2bEdDaG8/7iGZq7+Y1BjLbAKW6QFotZH5O52cwVlFBUNl0kBguSgrkASF+xhcEU5uRDN7Gu y7mCetBg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYqI9-0000000CeZP-2UiV; Wed, 02 Dec 2026 19:47:01 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYqI8-0000000CeZJ-1UEU for linux-nvme@lists.infradead.org; Wed, 02 Dec 2026 19:47:00 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id C53DE41B2D; Wed, 2 Dec 2026 19:46:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 998FB1F000C1; Wed, 2 Dec 2026 19:46:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796240819; bh=cGXbFltxSaWcLkYKjluAPVkiXKuPOPqd3KkEUmnT8S4=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=SPVRr0Fl0eltuMUMy3VIo7yfSCiKZ/kjCM5EnuCuGcZvoTHptFhQpEKEWMfCq2oys fh8Y9OB0779OueDO/azeSu+w5pikHkUAWWwcdWQrFsi7cxsnZTeNJC/zKz4FqSByRj AJlgcyx4RTHNl3+bnQoHuMGGuoSDQfj6OUMkr0IUV051ozBpLVrVKhA8adlqkn5y4f G5HH2Pj0/ae1BXxfPi+JK+Khv2gdjyfZv7aKtTnOWVK4g1ejN0To8OxdDwajJQ7MHD zlnZNYMPAeAqbaPMOQoE5zWM0DLy6PLbMHb+KBLUolj53NlCAIXFDkdjLNgVe6UKwm KKM/TsdPX/5Lw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v2] nvme: requeue keep-alive work when a Keep Alive fails To: "Andrew Stellman" Cc: linux-nvme@lists.infradead.org In-Reply-To: <20261202192236.88068-1-bugs@stellman-greene.com> References: <20261202192236.88068-1-bugs@stellman-greene.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 19:46:58 +0000 X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "Linux-nvme" X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] nvme: missing comp_seen reset on error in nvme_keep_alive_end_io() - [Medium] nvme: TOCTOU race and early blk_mq_free_request() in nvme_keep_alive_end_io() -- commit 236de8328119255613d8447e380cbb58332dc209 Author: Andrew Stellman nvme: requeue keep-alive work when a Keep Alive fails This commit requeues ctrl->ka_work via nvme_queue_keep_alive_work() when a Keep Alive command completes with an error while the controller is in NVME_CTRL_LIVE. > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c > index f43582e5f6c4a..58bae0e85a012 100644 > --- a/drivers/nvme/host/core.c > +++ b/drivers/nvme/host/core.c > @@ -1387,6 +1387,8 @@ static enum rq_end_io_ret nvme_keep_alive_end_io(st= ruct request *rq, > dev_err(ctrl->device, > "failed nvme_keep_alive_end_io error=3D%d\n", > status); > + if (state =3D=3D NVME_CTRL_LIVE) > + nvme_queue_keep_alive_work(ctrl); > return RQ_END_IO_NONE; > } [Severity: Medium] Should the error path also reset ctrl->comp_seen =3D false before calling nvme_queue_keep_alive_work(ctrl), as the success path does? __nvme_complete_rq() sets ctrl->comp_seen =3D true for any completing request started at or after ctrl->ka_last_check_time, including a failed Keep Alive request. When NVME_CTRL_ATTR_TBKAS is enabled, the next run of nvme_keep_alive_work() sees ctrl->comp_seen =3D=3D true, treats the fail= ed Keep Alive completion as I/O traffic, and defers sending the retry Keep Alive for another work period, which can still let the target's keep-alive timer expire. [Severity: Medium] Can checking the entry snapshot of state after blk_mq_free_request(rq) requeue ctrl->ka_work on a controller that is already resetting or deleting? nvme_keep_alive_end_io() snapshots state at function entry and frees rq before dev_err() and this check. Once blk_mq_free_request(rq) releases the admin tag and queue reference, a concurrent reset or teardown is no longer blocked in nvme_cancel_admin_tagset() or blk_mq_destroy_queue(): CPU0 CPU1 nvme_keep_alive_end_io() state =3D nvme_ctrl_state(ctrl) // NVME_CTRL_LIVE blk_mq_free_request(rq) nvme_remove_admin_tag_set() nvme_stop_keep_alive(ctrl) blk_mq_destroy_queue(ctrl->admin_= q) dev_err(...) if (state =3D=3D NVME_CTRL_LIVE) nvme_queue_keep_alive_work(ctrl) nvme_keep_alive_work() ... <-- use-after-free on admin_q Re-reading nvme_ctrl_state(ctrl) before requeueing and freeing rq after handling the completion would narrow this window. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202192236.8806= 8-1-bugs@stellman-greene.com?part=3D1