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 17C73606A322 for ; Fri, 4 Dec 2026 11:22:41 +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=luCcedgr; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=wvaKR8vq; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=T/YgNE4g; dkim=neutral header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=wvaKR8vq; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=T/YgNE4g DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Unsubscribe-Post: List-Owner; bh=HWJ5CpDo89ZWX9/iWlwieEbtAcD9h65xGMJ/tIAWNoQ=; b=luCcedgra+Wxof Nnrkrgqnic/6y7oVXFRKjnfsKEeVf7PzsDSST6IcRKgubN3qN+omY1qhS18Fo641zRiCNBisuU1e8 iMVJa4Y2vFgtIdP8EaHiWqDdunpv47FXhF61FsnlBTBIgDE3wQoT5v1/jUZDueiUKyhQGFzBau4yc tpQHgFal3TwEvy/fiz3+4MLZSD2AHDLI9/n5MnAsnZ5l0fZoXdBksaXg62aTnPmeZ+DLtwientpKt Uk+g/EBDc5tZ1MVa8074hIfbpfcn9c4LZmIHDAq6RIzus3QC9sPzuEiorRhMflh4xdger/9E/loR0 mHch8XwuNPi67rdkiBAg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZRN9-000000008Zd-1dXR; Fri, 04 Dec 2026 11:22:39 +0000 Received: from smtp-out2.suse.de ([2a07:de40:b251:101:10:150:64:2]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xZRN6-000000008YR-1fRF for linux-nvme@lists.infradead.org; Fri, 04 Dec 2026 11:22:37 +0000 Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 212495D3AB; Fri, 4 Dec 2026 11:22:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1796383351; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HWJ5CpDo89ZWX9/iWlwieEbtAcD9h65xGMJ/tIAWNoQ=; b=wvaKR8vqUqxgFzjXZqAAkHFjrFsXA9xFQnZiNFv4DOeUydQGPQo54VNnLZC8Jas2YO3jNi LDXAPF+ZLckITCOwArL1F0fG+TeyL18b9xd6Nky2YYOMVYH6Q/AodHZk8Bz+wfLC3jAQbQ 93XuTLWtyBTjx1rS6SNzUsILjsBPqFc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1796383351; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HWJ5CpDo89ZWX9/iWlwieEbtAcD9h65xGMJ/tIAWNoQ=; b=T/YgNE4g3JCvwh10lahmNuv0cHYDUS10D1HI/rm7dKL+/LX40k0CBM9GtOLwJnvomDp7Ic wPOiSUEVK3vJbKDA== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1796383351; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HWJ5CpDo89ZWX9/iWlwieEbtAcD9h65xGMJ/tIAWNoQ=; b=wvaKR8vqUqxgFzjXZqAAkHFjrFsXA9xFQnZiNFv4DOeUydQGPQo54VNnLZC8Jas2YO3jNi LDXAPF+ZLckITCOwArL1F0fG+TeyL18b9xd6Nky2YYOMVYH6Q/AodHZk8Bz+wfLC3jAQbQ 93XuTLWtyBTjx1rS6SNzUsILjsBPqFc= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1796383351; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HWJ5CpDo89ZWX9/iWlwieEbtAcD9h65xGMJ/tIAWNoQ=; b=T/YgNE4g3JCvwh10lahmNuv0cHYDUS10D1HI/rm7dKL+/LX40k0CBM9GtOLwJnvomDp7Ic wPOiSUEVK3vJbKDA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7E67A1352B; Fri, 4 Dec 2026 11:22:30 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id l4vdBnaiEmtsCQAAD6G6ig (envelope-from ); Fri, 04 Dec 2026 11:22:30 +0000 Message-ID: <66592372-af49-4c74-a384-da3f86296fdd@suse.de> Date: Fri, 4 Dec 2026 12:22:29 +0100 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v5] nvme-multipath: serialize ana_log_buf lifecycle with ana_lock To: Guixin Liu , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Nilay Shroff , Daniel Wagner Cc: linux-nvme@lists.infradead.org References: <20261204070041.3602839-1-kanie@linux.alibaba.com> Content-Language: en-US From: Hannes Reinecke In-Reply-To: <20261204070041.3602839-1-kanie@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Level: X-Spamd-Result: default: False [-13.29 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-0.998]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; XM_UA_NO_VERSION(0.01)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; RCPT_COUNT_SEVEN(0.00)[8]; RCVD_VIA_SMTP_AUTH(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,suse.de:email] X-Spam-Score: -13.29 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261204_032236_583230_C3B97226 X-CRM114-Status: GOOD ( 20.89 ) X-Spam-Score: -2.1 (--) 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: , Sender: "Linux-nvme" X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 On 12/4/26 8:00 AM, Guixin Liu wrote: > nvme_parse_ana_log() reads ana_log_buf and ana_log_size under ana_lock, > but the buffer is freed in nvme_mpath_uninit() and reallocated in > nvme_mpath_init_identify() outside the lock. A concurrent parser in > nvme_mpath_add_disk() can then use freed memory, dereference a NULL > buffer, read a freshly allocated buffer before nvme_read_ana_log() > populates it, or validate stale descriptors against shrunk limits > (WARN_ON_ONCE). Once the buffer is NULL, nvme_read_ana_log() calls > nvme_get_log() with size 0, where nvme_bytes_to_numd(0) underflows to > 0xffffffff, and the NULL-buffer bail in nvme_parse_ana_log() leaves > desc.state == 0 so the namespace is stuck NVME_NS_ANA_PENDING and never > goes live. > > Take ana_lock around the buffer release and reallocation, updating > ana_log_buf, ana_log_size and anagrpmax together. Allocate the new > buffer outside the lock and zero it, and clear ngrps on the shrink path, > so an early parser sees ngrps == 0. nvme_read_ana_log() bails on a NULL > buffer and nvme_parse_ana_log() returns -ENOENT in that case. > nvme_mpath_add_disk() keeps the lockless nvme_ctrl_use_ana() feature test > and, on -ENOENT, clears any pending bit and falls back to the non-ANA > path so the namespace goes live even if ANA was disabled while it > parsed. The ana_work drain stays outside the lock since ana_work itself > takes ana_lock. > > Fixes: 0d0b660f214d ("nvme: add ANA support") > Cc: stable@vger.kernel.org > Signed-off-by: Guixin Liu > --- > Originally reported by Sashiko AI review as pre-existing issues, > confirmed by source analysis and reproduced in a KASAN guest. > > Tested on 7.4.0-rc1 (KASAN, nvmet-tcp loopback, ANA enabled). A test-only > parameter clears ana_log_buf before nvme_mpath_add_disk() takes ana_lock: > without the fix the namespace stays NVME_NS_ANA_PENDING and /dev/nvme0n2 > never appears; with the fix it goes optimized and live and 4K reads pass. > Normal ANA path, multipath fio (err=0) and controller reset are clean. > > The ns->ana_grpid/ana_state publication stays outside ana_lock on > purpose: nvme_mpath_set_live() runs synchronous report-zones I/O for > zoned namespaces, and holding ana_lock across it deadlocks scan_work > against reset_work (reset takes ana_lock in nvme_mpath_init_identify() > without flushing scan_work). The stale-snapshot race this leaves is > pre-existing and recoverable via failover. An already-pending namespace > stranded when ANA is disabled (nvme_mpath_update() returns early on a > NULL buffer) is a separate pre-existing gap left for a follow-up. > > Changes since v4: > - revert the under-lock nvme_ctrl_use_ana() test, keep it lockless; > nvme_parse_ana_log() returns -ENOENT for a NULL buffer and add_disk > falls back to the non-ANA path (clearing pending) on that error > (Nilay Shroff) > > Changes since v3: > - move the nvme_ctrl_use_ana() test under ana_lock so add_disk takes > the non-ANA path if ANA was disabled while it waited (Sashiko) > > Changes since v2: > - bail out of nvme_read_ana_log() on a NULL buffer (numd underflow); > update anagrpmax under ana_lock and clear ngrps on shrink (Sashiko) > > Changes since v1: > - serialize the realloc swap under ana_lock, allocate/zero outside the > lock, bail out of nvme_parse_ana_log() on a NULL buffer (Sashiko) > > v4: https://lore.kernel.org/all/20261202085124.1252825-1-kanie@linux.alibaba.com/ > v3: https://lore.kernel.org/all/20261201074919.1051448-1-kanie@linux.alibaba.com/ > v2: https://lore.kernel.org/all/20261125122446.1122253-1-kanie@linux.alibaba.com/ > v1: https://lore.kernel.org/all/20261125060153.206699-1-kanie@linux.alibaba.com/ > Reviewed-by: Hannes Reinecke Cheers, Hannes -- Dr. Hannes Reinecke Kernel Storage Architect hare@suse.de +49 911 74053 688 SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich