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 C9E02606A31A for ; Tue, 1 Dec 2026 08:08:16 +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=0AmVSAaX; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=aZJk+L4C 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=l7rkQgTTcgqS6tfa1wwgzPrIpCQlVOkuQoiMUgYdF9I=; b=0AmVSAaXhRAXKi/yOzb8PIIh8z bHkrFM2EBoRbtqsjx20JKImaeGGVNricfbUb/trZ7YmNFCIKjp/xUsoPzNETv18Bs0x9bUaIqw45+ TcWybufH1rLvHzcCOjxjNmZl5BD6kxrfpZuvN6iM5dsLaikPnwpXnETXA7ZhIbdRPYWhffnAkXFfG 0YwdMxaD4RYfuTLrpvLtToKZhU4yDj60AdHz8B9d4iWV4YX0fseyttKYtxHcbuobanjw/Yix3D/Ou DBtyLGqQhhyjQwQwjwSnKd8JIbHZo7caH28WTPwIX5ppxR/58tLA4Kijzzrbz+7fgG83hiADll/gT u+VvNlQQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYIuO-00000006y4L-2E1g; Tue, 01 Dec 2026 08:08:16 +0000 Received: from sea.source.kernel.org ([2600:3c0a:e001:78e:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYIuN-00000006y41-2Vms for linux-nvme@lists.infradead.org; Tue, 01 Dec 2026 08:08:15 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id D87DB40BF9; Tue, 1 Dec 2026 08:08:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3F4D1F00893; Tue, 1 Dec 2026 08:08:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796112493; bh=l7rkQgTTcgqS6tfa1wwgzPrIpCQlVOkuQoiMUgYdF9I=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=aZJk+L4C2KhPVmxl+F3XJuAFW8eLKxzRRFkkg6M6lkJDxVVsku7scFMkp+nUxMDMq AIIYOf2MJ99Uu+TdR8uUyAjYKqAKphrVkBruSROn3rAcUpn3VQAWHzTSKMf+6MmSQj LGQPrLNhaOIQOfSk//mMoQibO6m6Eu7s/3rEnSTKmb96un+sZCrJPE6OP+6madNfAg hgbBcouabnjwyJ93/tHrjXu5DDL7eJo7wukBwSE6oLv7dW+KLoChI/4lVXXcFSTFl0 DEFfL5j6JwVamcnmTKCNVHHSAlyonCDECl6/80rTOj74QIkMfxQhugl48BhWs278Fn WASVSdJmA2tlA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH v3] nvme-multipath: serialize ana_log_buf lifecycle with ana_lock To: "Guixin Liu" Cc: linux-nvme@lists.infradead.org In-Reply-To: <20261201074919.1051448-1-kanie@linux.alibaba.com> References: <20261201074919.1051448-1-kanie@linux.alibaba.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 08:08:13 +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 1 potential issue to consider: - [Medium] nvme-multipath: TOCTOU race on ana_log_buf in nvme_mpath_add_disk() -- commit f8acdff41f6798914e6883d82fb65ecaaa130b49 Author: Guixin Liu nvme-multipath: serialize ana_log_buf lifecycle with ana_lock This commit serializes ctrl->ana_log_buf freeing and reallocation with ctrl->ana_lock and makes nvme_parse_ana_log() and nvme_read_ana_log() bail out when ctrl->ana_log_buf is NULL. > diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c > index 27facdbb3d4c0..e0476af20f3e8 100644 > --- a/drivers/nvme/host/multipath.c > +++ b/drivers/nvme/host/multipath.c > @@ -867,6 +867,9 @@ static int nvme_parse_ana_log(struct nvme_ctrl *ctrl,= void *data, > =20 > lockdep_assert_held(&ctrl->ana_lock); > =20 > + if (!ctrl->ana_log_buf) > + return 0; [Severity: Medium] Can returning 0 here cause nvme_mpath_add_disk() to mistake a freed ana_log_buf for a missing ANA group descriptor when racing with nvme_mpath_uninit()? drivers/nvme/host/multipath.c:nvme_mpath_add_disk() { if (nvme_ctrl_use_ana(ns->ctrl)) { struct nvme_ana_group_desc desc =3D { .grpid =3D anagrpid, .state =3D 0, }; mutex_lock(&ns->ctrl->ana_lock); ns->ana_grpid =3D le32_to_cpu(anagrpid); nvme_parse_ana_log(ns->ctrl, &desc, nvme_lookup_ana_group_desc); mutex_unlock(&ns->ctrl->ana_lock); if (desc.state) { /* found the group desc: update */ nvme_update_ns_ana_state(&desc, ns); } else { /* group desc not found: trigger a re-read */ set_bit(NVME_NS_ANA_PENDING, &ns->flags); queue_work(nvme_wq, &ns->ctrl->ana_work); } } else { ns->ana_state =3D NVME_ANA_OPTIMIZED; nvme_mpath_set_live(ns); } } Because nvme_mpath_add_disk() checks nvme_ctrl_use_ana() outside ana_lock, a concurrent nvme_mpath_uninit() can clear ana_log_buf before ana_lock is acquired: CPU0 CPU1 nvme_mpath_add_disk() nvme_mpath_init_identify() nvme_ctrl_use_ana() -> true /* ana_log_size > max_transfer_size= */ nvme_mpath_uninit() cancel_work_sync(&ctrl->ana_work) mutex_lock(&ctrl->ana_lock) ctrl->ana_log_buf =3D NULL mutex_unlock(&ctrl->ana_lock) mutex_lock(&ctrl->ana_lock) nvme_parse_ana_log() -> 0 mutex_unlock(&ctrl->ana_lock) /* desc.state =3D=3D 0 */ set_bit(NVME_NS_ANA_PENDING, ...) queue_work(..., &ctrl->ana_work) <-- queued after ANA teardown When nvme_mpath_init_identify() disables ANA because ana_log_size exceeds max_transfer_size, it returns 0 and the controller proceeds without ANA. CPU0 sets NVME_NS_ANA_PENDING instead of taking the non-ANA branch to mark the namespace live, and nvme_read_ana_log() now bails out on the NULL ana_log_buf, leaving the path stuck in NVME_PATH_DISABLED_ANA_PENDING. Also, once ana_log_buf is NULL, nvme_mpath_stop() returns early because nvme_ctrl_use_ana() is false, so it will not cancel the newly queued ana_work. Would rechecking nvme_ctrl_use_ana() under ana_lock in nvme_mpath_add_disk() (or having nvme_parse_ana_log() return an error such as -ENOENT when ana_log_buf is NULL) allow nvme_mpath_add_disk() to fall back to the non-ANA path? --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201074919.1051= 448-1-kanie@linux.alibaba.com?part=3D1