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 CD0B7606A320 for ; Tue, 1 Dec 2026 12:55:28 +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=Tn6/AYqD; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=KcO93ZwT 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=qM4HZZmnnA87dtbz1C6PI/IUG8K54lYZuyhhIzAM6G4=; b=Tn6/AYqDBQRNsi eW678FyTEDm0bdhB8ZjAIGksLcNLWPWUcGcGxy7XLy1XoX+wIupoGZnJO4FeySly4edwKZLm6ajhL A0QPJtNXy2xJm697kg0H7G6tTGhKx0yDFm75t9V6ktVu0YxDdmruTw09374a/otuN+9Uye/yMrBb8 WW3qo2Zchcsnpa7Zo0QgKHuP0IZiNJ248VbvpOsg+pwoaWPWsN6Y4FcW77BqTsSrsccndVR/OKMPL jS6ieCrZPD+s4BplrflmnKT8svC5GQoMboL0UN8l/O2kVUj1ZCSW5AnsGdf4Fhj1t3KYmQsTnSn6c KNWhqYGRX9shMtE93u8A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYNOI-00000007qll-4AVG; Tue, 01 Dec 2026 12:55:26 +0000 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYNOF-00000007qkm-2a2E for linux-nvme@lists.infradead.org; Tue, 01 Dec 2026 12:55:25 +0000 Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6B1AYkG91577471; Tue, 1 Dec 2026 12:55:02 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=pp1; bh=qM4HZZ mnnA87dtbz1C6PI/IUG8K54lYZuyhhIzAM6G4=; b=KcO93ZwTAzjUpDJOc8UJpz zfte2BVWLcp8uLy96Pi7S6NVkURz3MQcp8CbQjbjatJstV+oCbRRTrOIBHBeSZMJ EMl5Y2VCNfx+m+wcosFTz6zpuorbNvcykw7GyNqH0OfvyOEPNA37G7IdhNxA1G4x JlCTLbtz754/i7Qi4LV6P5zfwYEk3spxoJjr3ebCoi1TzXwp3D9MUaCN52Q0dRBO pw8cwwlENywu5Te1VtYpSoH7oeWA2RB6qNYp0XjmYXtdRaBhR8RJYj6gN9d4oLBS jm9yC0dyJhMd0o/7N5qCLP21hW3vhUTj7rPYKfw/QH6Gtbs3v/j12MLh+v5Ghrww == Received: from ppma11.dal12v.mail.ibm.com (db.9e.1632.ip4.static.sl-reverse.com [50.22.158.219]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7pku42sy-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 01 Dec 2026 12:55:01 +0000 (GMT) Received: from pps.filterd (ppma11.dal12v.mail.ibm.com [127.0.0.1]) by ppma11.dal12v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6B1AYL7A1470634; Tue, 1 Dec 2026 12:55:01 GMT Received: from smtprelay06.wdc07v.mail.ibm.com ([172.16.1.73]) by ppma11.dal12v.mail.ibm.com (PPS) with ESMTPS id 4j9v5w0fku-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 01 Dec 2026 12:55:00 +0000 (GMT) Received: from smtpav06.wdc07v.mail.ibm.com (smtpav06.wdc07v.mail.ibm.com [10.39.53.233]) by smtprelay06.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6B1Ct0kh13632178 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 1 Dec 2026 12:55:00 GMT Received: from smtpav06.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 369E658054; Tue, 1 Dec 2026 12:55:00 +0000 (GMT) Received: from smtpav06.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 80B8F5804E; Tue, 1 Dec 2026 12:54:57 +0000 (GMT) Received: from [9.61.17.248] (unknown [9.61.17.248]) by smtpav06.wdc07v.mail.ibm.com (Postfix) with ESMTP; Tue, 1 Dec 2026 12:54:57 +0000 (GMT) Message-ID: <7e50ed7f-3f4f-48cd-9bd2-517b6402b0f5@linux.ibm.com> Date: Tue, 1 Dec 2026 18:24:55 +0530 X-Archived-By: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] nvme-multipath: serialize ana_log_buf lifecycle with ana_lock To: Guixin Liu , Keith Busch , Jens Axboe , Christoph Hellwig , Sagi Grimberg , Daniel Wagner , Hannes Reinecke Cc: linux-nvme@lists.infradead.org References: <20261201074919.1051448-1-kanie@linux.alibaba.com> Content-Language: en-US From: Nilay Shroff In-Reply-To: <20261201074919.1051448-1-kanie@linux.alibaba.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-TM-AS-GCONF: 00 X-Proofpoint-Reinject: loops=2 maxloops=12 X-Authority-Analysis: v=2.4 cv=KZZHIgYD c=1 sm=1 tr=0 ts=6b0ec3a6 cx=c_pps a=aDMHemPKRhS1OARIsFnwRA==:117 a=aDMHemPKRhS1OARIsFnwRA==:17 a=IkcTkHD0fZMA:10 a=pUM-KoujPXoA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=RzCfie-kr_QcCd8fBx8p:22 a=91mSN3xrS9PvjIdtmHMA:9 a=QEXdDO2ut3YA:10 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMjAxMDA1MCBTYWx0ZWRfXzNi7fFnfrA10 tYNiu69DjFjLhEzoWx1iN1lgoMw+Grh9VT4fflCxLylkDB/249nRIwmayo8bANHhxtmN40oJLLA YcAq+Vf2qWZ5cFWISW3P2TC4c5ydGpT+rYIDindD63GcBKP9YLHMmQ8jwccAWKIjvT5Rk5Ha0bC IuVETMQb2fcrLKmShNGtH17zaHRaqo50dMkpWJZR5BJ2bp6bqZ6xillaxm+Qj8UitLOJSfYDJ10 Hk3nq5pSsl7s3RmGiihKiLivaHwKHnciwLZgPsivG8i47ZK5cOSsHblHfvwX3vrzEtLp5gRbTlM bYEEXvxHZ89jYorZmbbHv7pzv1vW2nGfVuEElFTsLw+RUyVrOXNyTHkmVPkrbVAZ7+CNVm9WNV2 2sYxrY5qyW5Xtj+FX2BS6HLhvM76OtkQ46WeVfwkS9LtjWHa9W0r25lSZohWUo5KOs1abN+YuDW 9Dz60a0GjanhsbxSmxw== X-Proofpoint-Spam-Info: AW1haW4tMjYxMjAxMDA1MCBTYWx0ZWRfX5cFwshLrZ3gy hEl4jbmAe/sJBcCEdKcuK5zvTVfFL1dDmBkcRuQFQ8u0jjDMM7YNHW/8Al/QW0xx8nZ5Tb3jEFk x3Yi6B7fXbCygct58oh2j+733M4gprQ= X-Proofpoint-ORIG-GUID: aN1g0U3qL-3A1AyH6sTJhtBsrFi4hybl X-Proofpoint-GUID: 03_UjwTR9nBBhtAX01CpwyPeL1LXFkvu X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-12-01_02,2026-11-30_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 bulkscore=0 malwarescore=0 adultscore=0 spamscore=0 suspectscore=0 lowpriorityscore=0 priorityscore=1501 clxscore=1015 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2612010050 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.9.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20261201_045523_783763_E800F963 X-CRM114-Status: GOOD ( 18.92 ) X-Spam-Score: -2.6 (--) 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=-5.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=no 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/1/26 1:19 PM, Guixin Liu wrote: > nvme_parse_ana_log() reads ctrl->ana_log_buf and ctrl->ana_log_size > under ctrl->ana_lock, but the buffer lifecycle is not fully serialized > against it: > > - nvme_mpath_uninit() frees the buffer without ana_lock, so a > concurrent parser in nvme_mpath_add_disk() can use freed memory. > - nvme_mpath_init_identify() reallocates the buffer and updates > ana_log_size outside ana_lock. nvme_mpath_add_disk() tests > nvme_ctrl_use_ana() before taking the lock, so it can pass the check > and then dereference a NULL buffer after nvme_mpath_uninit() cleared > it; and the freshly allocated buffer can be parsed before > nvme_read_ana_log() populates it, reading uninitialized memory. > - The shrink path leaves the old log in place while shrinking > ana_log_size, and anagrpmax is updated outside ana_lock, so a > concurrent parser validates stale descriptors against the new > limits and trips WARN_ON_ONCE(). > - After nvme_mpath_uninit() clears the buffer, nvme_mpath_add_disk() > can still queue ana_work; nvme_read_ana_log() then calls > nvme_get_log() with a NULL buffer and size 0, and > nvme_bytes_to_numd(0) underflows to 0xffffffff. > > Take ana_lock around the buffer release in nvme_mpath_uninit() and > around the reallocation in nvme_mpath_init_identify(), updating > ana_log_buf, ana_log_size and anagrpmax together so a parser never > observes a freed or NULL buffer or stale limits. Allocate the new > buffer outside the lock and zero it, and clear ngrps on the shrink > path, so a parser running before nvme_read_ana_log() populates the log > sees ngrps == 0. nvme_parse_ana_log() and nvme_read_ana_log() bail out > when the buffer is NULL. Keep the ana_work drain outside the lock: > ana_work itself takes ana_lock, so cancelling it under the lock would > deadlock. > Along with this change, can we also annotate relevant ANA fields in struct nvme_ctrl using ctrl->ana_lock? That would help document all fields protected with ana_lock as well as all references to those fields would be also analyzed by thread-safety context analyzer when compiled with clang. Thanks, --Nilay