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 1F580606A329 for ; Wed, 2 Dec 2026 17:04:19 +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=sRNsnctE; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=R7JsCsjX 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=eVMK//c3Xu4sZQBF7PYuf64ovrK5XCdwBfCQEuxDaac=; b=sRNsnctEe2B0tdM+zD2qjlVqtj rWDQjgRmj+P4MiKk3Dycx/ANo+yQy+kWkyn+EEYfLebsk2T6mjbcyhRWQ9szJ9frOeMTXAhkTjKwM SeIUYf9Kk6zJC1NTaoewbrtokpCLHcD2L/5gvesMSJR+F03rNY7pxF4od8lPhi+FyUlEmM8Aum1an UjJpZoZ930xufZ759ZjChfU1JQD7iwr5PBRo5K754i//U9EFXhlgFkD96RoS8vm3TtISiq1ymOr3A kXH91CZxOphHP7rZvHSFdTJaEKE+TjC4dOZypnBLUJiNOwRQSF6OyBOqaPOoWkzZz0zkRN4aXU7Si xMNZYMBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYnkf-0000000CJI1-0kit; Wed, 02 Dec 2026 17:04:17 +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 1xYnke-0000000CJHp-0vMJ for linux-nvme@lists.infradead.org; Wed, 02 Dec 2026 17:04:16 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id B04C341FC8; Wed, 2 Dec 2026 17:04:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1E7051F00897; Wed, 2 Dec 2026 17:04:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796231055; bh=eVMK//c3Xu4sZQBF7PYuf64ovrK5XCdwBfCQEuxDaac=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=R7JsCsjXmkRxdVUR0XGjI1GouzkUi2PFPluSbdlSPdlrEhXZuIDWB5HLM7nshoiPc 8z8KGk0xBoQLUGEA6Fpt6h0QJX71600DnUWDlAbK78lpCo5zTXWARN/plcTDWNMCP9 7h2PbgJyUFlVD4ZlmAxlS6u97SL2hFF5IkVvvM/7OtZcQdvr4nBpTQlz7mkyutvWUc jCSjm8E+SczKYr529VN1DJGOHsYl+4gXAtcLTl1bjvXVAKGtZyKX1gGGiABzRjTkXc tv+ueAnQIPS7eY0MF+R0AjCh2NfMosx+8q7WHdXm7T2DM0vOW+JbTVK/TLJprmr9qH dXZhyJmnsE/+Q== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] nvme: requeue keep-alive work when a Keep Alive fails To: "Andrew Stellman" Cc: linux-nvme@lists.infradead.org In-Reply-To: <20261202163728.48705-1-bugs@stellman-greene.com> References: <20261202163728.48705-1-bugs@stellman-greene.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 17:04:14 +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 4 potential issues to consider: - [High] nvme: nvme_keep_alive_end_io() re-arms ka_work after nvme_stop_keep_alive() - [High] nvme: 0-delay ka_work loop in nvme_keep_alive_end_io() on unstarted rq - [High] nvme: TOCTOU race and early blk_mq_free_request() in nvme_keep_alive_end_io() - [Medium] nvme: nvme_keep_alive_end_io() leaves comp_seen set on Keep Alive error -- commit d4772f222149ed81b6c4ebef2863f8b28557e653 Author: Andrew Stellman nvme: requeue keep-alive work when a Keep Alive fails This commit requeues ctrl->ka_work in nvme_keep_alive_end_io() when a Keep Alive command completes with an error while the controller is in NVME_CTRL_LIVE or NVME_CTRL_CONNECTING. > diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c > index f43582e5f6c4a..ca04ff0f437d6 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 || state =3D=3D NVME_CTRL_CONNECTING) > + queue_delayed_work(nvme_wq, &ctrl->ka_work, delay); > return RQ_END_IO_NONE; > } > =20 [Severity: High] Can this re-arm ctrl->ka_work after nvme_stop_keep_alive() has already returned during admin queue teardown in NVME_CTRL_CONNECTING? nvme_init_ctrl_finish() starts keep-alive while ctrl->state is still NVME_CTRL_CONNECTING. When nvme_keep_alive_work() runs, it submits the Keep Alive request on ctrl->admin_q via blk_execute_rq_nowait(), so ctrl->ka_work is not pending while the request is in flight. If controller setup subsequently tears down or restarts the admin queue in NVME_CTRL_CONNECTING (such as the destroy_admin and secure-concatenation paths in nvme_tcp_setup_ctrl()), it calls nvme_stop_keep_alive() and then nvme_tcp_teardown_admin_queue() -> nvme_cancel_admin_tagset(): drivers/nvme/host/tcp.c:nvme_tcp_setup_ctrl() { ... destroy_admin: nvme_stop_keep_alive(ctrl); nvme_tcp_teardown_admin_queue(ctrl, new); ... } Because nvme_stop_keep_alive() only calls cancel_delayed_work_sync(&ctrl->ka_work), it does not wait for the in-flight Keep Alive request. nvme_cancel_admin_tagset() then cancels that request via nvme_cancel_request() with NVME_SC_HOST_ABORTED_CMD and NVME_REQ_CANCELLED while ctrl->state is still NVME_CTRL_CONNECTING, and nvme_keep_alive_end_io() now queues ctrl->ka_work again after keep-alive was stopped and while the transport admin queue is being torn down. [Severity: High] Does this enter a zero-delay workqueue loop on nvme_wq when a Keep Alive request fails before blk_mq_start_request() sets rq->deadline? blk_mq_rq_ctx_init() initializes rq->deadline to 0, and rq->deadline is only populated when the transport ->queue_rq() callback calls nvme_start_request(). If the transport admin queue is not live while ctrl->admin_q is unquiesced in NVME_CTRL_CONNECTING (for example, after nvme_tcp_complete_timed_out() stops queue 0 on a Keep Alive timeout in NVME_CTRL_CONNECTING, or after nvme_fc_delete_association() unquiesces ctrl->admin_q), ->queue_rq() calls nvme_fail_nonready_command() before starting the request. Because nvme_init_request() sets REQ_FAILFAST_DRIVER on Keep Alive requests, nvme_fail_nonready_command() immediately completes rq via nvme_host_path_error() with rq->deadline still 0. At the top of nvme_keep_alive_end_io(), rtt =3D jiffies - (rq->deadline - rq->timeout) evaluates to jiffies + rq->timeout > delay, logs a spurious long keepalive RTT warning, sets delay =3D 0, and now requeues ctrl->ka_work with a delay = of 0 in a tight loop. [Severity: High] Can a concurrent controller reset or teardown finish stopping keep-alive between blk_mq_free_request(rq) and queue_delayed_work()? CPU0 CPU1 nvme_keep_alive_end_io() state =3D nvme_ctrl_state(ctrl) /* state =3D=3D NVME_CTRL_LIVE */ nvme_change_ctrl_state(..., NVME_CTRL_RESETTING) nvme_stop_keep_alive(ctrl) nvme_cancel_admin_tagset(ctrl) blk_mq_free_request(rq) /* tagset wait / queue destroy completes once rq is freed */ dev_err(...) if (state =3D=3D NVME_CTRL_LIVE ...) queue_delayed_work(..., &ctrl->ka_work, ...) <-- re-armed after stop nvme_keep_alive_end_io() snapshots ctrl->state at entry and calls blk_mq_free_request(rq) before dev_err() and queue_delayed_work(). Freeing rq drops the admin_tagset tag and admin_q usage reference that nvme_cancel_admin_tagset() and nvme_remove_admin_tag_set() wait on, so a concurrent reset or deletion can complete teardown while CPU0 is in dev_err(), after which CPU0 tests the stale state snapshot and re-queues ctrl->ka_work on a stopped or uninitialized controller. [Severity: Medium] Does returning before clearing ctrl->comp_seen cause the next nvme_keep_alive_work() run to skip sending a Keep Alive on controllers with Traffic-Based Keep Alive (NVME_CTRL_ATTR_TBKAS)? When the failed Keep Alive request completes through __nvme_complete_rq(), it sets ctrl->comp_seen =3D true: drivers/nvme/host/core.c:__nvme_complete_rq() { ... if (ctrl->kas && req->deadline - req->timeout >=3D ctrl->ka_last_check_time) ctrl->comp_seen =3D true; ... } The success path in nvme_keep_alive_end_io() resets ctrl->comp_seen =3D fal= se and updates ctrl->ka_last_check_time =3D jiffies, but the error path returns early with comp_seen still set. On the next run of nvme_keep_alive_work(), (ctrl->ctratt & NVME_CTRL_ATTR_TBKAS) && comp_seen is true, so it treats the failed Keep Alive itself as I/O traffic and defers the retry by another keep-alive work period, which can still let the target's KATO timer expire. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202163728.4870= 5-1-bugs@stellman-greene.com?part=3D1