From nobody Fri Sep 25 04:38:25 2026 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 151E8378822 for ; Wed, 16 Sep 2026 15:11:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789571466; cv=none; b=O0RBfcrqh3YH4m1F0Kww7e2OvAKZtcoifywHOA9Gkc3jmXL0tCC6ve2/OCoHVow/TgJfZ1X5Z41u1yef+Cd7uExAyEQ3zZ2yFFc266/ybUBKhcePeXmh8koZz9TBP0Y8elPY35OEpw6lH1Hwrw12RfMJz6ouXFdtUzCeJq7GgOM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789571466; c=relaxed/simple; bh=82Po+MWtnddHsMFzebg79RzSQQLt8vBCjhQTbPXgZLA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=li5Pgaa6/eL6H2WhDZGOv9i7Sl5rbyViCrMJm3LD5YPdllrTxLv7N3EvZd1rVPkTrtVYJdq+wNeQeB976az+BlOiyQHo+69zGHSk1gtoUeiKPUswo4ed5t+8AfHmMmhlnW3YbZbUh3p4v92Yxw8CoGhDabjIjqcOZ0DegZkdecc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=eOiPHdb3; arc=none smtp.client-ip=148.163.156.1 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="eOiPHdb3" Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 68GEVuP44007658; Wed, 16 Sep 2026 15:10:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=FqLDnrcteHK5S/7d6 FBsaAPQcmaAmif37JjMEJUwCSQ=; b=eOiPHdb3lbaDHsR1RVLJdGygZGtD9OfIk hhC0hW+xcG4kW2WvSF/yzdbxBz1GY1w3R8mrScBR7Um9DrizJdF2QW3xYAdhsH5O Uvy2rtJlvV1pV7vtnw2XN9KKavW0pAI9BnU+iezZsFszJs/T5YTT8e6bypFdiTE+ KRVK+HDL3Uj4frRY8bYjAFpD2L1wQ43xNxQtutztyxBy9UlJrsd9bRxke+1JRnso gwBoVW4yK2EGpAr/hHFyVsTSi8BApHrArnRAlFDkWdVwoMRFCnn/YrdsfsbUaXs6 BtNnHqvggSGcVKNYvDjFaGFGbVO74snTC7EZ4y9ItvyojeSyp9ndA== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4gmx83wa2r-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 16 Sep 2026 15:10:39 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 68GEaBXj1585015; Wed, 16 Sep 2026 15:10:38 GMT Received: from smtprelay03.fra02v.mail.ibm.com ([9.218.2.224]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4gq089putb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Sep 2026 15:10:38 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay03.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 68GFAXin41091564 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Sep 2026 15:10:33 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3081020040; Wed, 16 Sep 2026 15:10:33 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CE75020043; Wed, 16 Sep 2026 15:10:28 +0000 (GMT) Received: from li-a84c74cc-2b13-11b2-a85c-acdd023f0674.ibm.com.com (unknown [9.61.52.228]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 16 Sep 2026 15:10:28 +0000 (GMT) From: Nilay Shroff To: hch@lst.de, kbusch@kernel.org, sagi@grimberg.me, kch@nvidia.com Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, gjoyce@linux.ibm.com, Nilay Shroff Subject: [PATCH 1/2] nvmet: defer setting ns->enabled to false in nvmet_ns_disable() Date: Wed, 16 Sep 2026 20:39:59 +0530 Message-ID: <20260916151012.3702896-2-nilay@linux.ibm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260916151012.3702896-1-nilay@linux.ibm.com> References: <20260916151012.3702896-1-nilay@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTE2MDIwNCBTYWx0ZWRfX6dGS980MbI+N E1uazvwmAOosUXR53+sqojk1wQtwy4HaJuwQ+ri6fotqzASbEtxSeEoe6uszcHBpdWI+8G/8uam xxaimdewMd8Uj0ZJlT6T5v1Fk3o/caG8CD22/H6b5bs3qs5UNWvc205DfdBNJiO+/D/ywOs+iJq LzxEe88ZpobH95How3Z5meiB+LdaBRW6vvxUaYsog/Qu6fsNRKmrM04sAGw0ta+7xh+wJaYvXyH RHAjvm2NV6z8iXXJSXbYj0pEG4Lmu3Nug41FO80LcXmt/H9rJAI7p518MVHqdFYnAvS/qQ/KZ6z 7KYmbNgmyIROd5ZmHPUftp9h8ToT3Zd0NaegIMC1x6iX8jeM/L3Ijr5HhOTb9fPwqS+dKx7s5hB FZihB2JzPn2LWBK9yFgctUIOMfOe5fRBgrXSNYaWNItwCH2uXf/bHv+MY2wNiKtxpWqLrkv3Vht vA/rlyLaWc0ZxqAvLKA== X-Proofpoint-ORIG-GUID: NBho84BV1Yc1YOjkmKW_iko5EqwNDbEV X-Proofpoint-GUID: NBho84BV1Yc1YOjkmKW_iko5EqwNDbEV X-Proofpoint-Spam-Info: AW1haW4tMjYwOTE2MDIwNCBTYWx0ZWRfXxLI6g4tw+KuB EQDM3IKNfYidhgyHthDLcZZHFgaj+75EOKsGL2RZiyIdjPh0KeIysjC5vQydWiwkbbWq73qoVCC z+fIVccUmemAhPgUs9n6MX/zYRlysyM= X-Authority-Analysis: v=2.4 cv=cY9HPXDM c=1 sm=1 tr=0 ts=6aaab16f cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=iQ6ETzBq9ecOQQE5vZCe:22 a=VnNF1IyMAAAA:8 a=rmADpZh76WS4eRlhKtcA:9 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-09-16_02,2026-09-16_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 spamscore=0 bulkscore=0 clxscore=1015 suspectscore=0 impostorscore=0 malwarescore=0 phishscore=0 adultscore=0 lowpriorityscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609160204 Content-Type: text/plain; charset="utf-8" nvmet_ns_disable() currently clears ns->enabled before draining in-flight I/O references. This allows namespace configuration to be changed while existing I/O requests can still hold a reference to the namespace. This can race with configuration of namespace attributes such as the device path, UUID, NGUID etc. These attributes can be accessed by I/O requests without holding subsys->lock and must not be modified while such requests are still using the namespace. In nvmet_ns_disable(), keep ns->enabled set while existing namespace references are being drained, so namespace configuration remains blocked until all in-flight I/O has completed. Set ns->enabled to false only after the namespace references have been drained and the namespace device has been disabled. Since setting ns->enabled to false is deferred in nvmet_ns_disable(), use the NVMET_NS_ENABLED XArray mark in nvmet_req_find_ns() to determine whether a namespace can accept new I/O. Similarly, use the NVMET_NS_ENABLED XArray mark in nvmet_ns_disable() to prevent concurrent callers from starting namespace disable. Signed-off-by: Nilay Shroff --- drivers/nvme/target/core.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index 43871a8f56ca..77d113fceced 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -448,7 +448,8 @@ u16 nvmet_req_find_ns(struct nvmet_req *req) struct nvmet_subsys *subsys =3D nvmet_req_subsys(req); =20 req->ns =3D xa_load(&subsys->namespaces, nsid); - if (unlikely(!req->ns || !req->ns->enabled)) { + if (unlikely(!req->ns) || + !xa_get_mark(&subsys->namespaces, nsid, NVMET_NS_ENABLED)) { req->error_loc =3D offsetof(struct nvme_common_command, nsid); if (!req->ns) /* ns doesn't exist! */ return NVME_SC_INVALID_NS | NVME_STATUS_DNR; @@ -644,10 +645,9 @@ void nvmet_ns_disable(struct nvmet_ns *ns) struct nvmet_ctrl *ctrl; =20 mutex_lock(&subsys->lock); - if (!ns->enabled) + if (!xa_get_mark(&subsys->namespaces, ns->nsid, NVMET_NS_ENABLED)) goto out_unlock; =20 - ns->enabled =3D false; xa_clear_mark(&subsys->namespaces, ns->nsid, NVMET_NS_ENABLED); nvmet_debugfs_ns_free(ns); =20 @@ -675,6 +675,7 @@ void nvmet_ns_disable(struct nvmet_ns *ns) mutex_lock(&subsys->lock); nvmet_ns_changed(subsys, ns->nsid); nvmet_ns_dev_disable(ns); + ns->enabled =3D false; out_unlock: mutex_unlock(&subsys->lock); } --=20 2.53.0 From nobody Fri Sep 25 04:38:25 2026 Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB6DE392C42 for ; Wed, 16 Sep 2026 15:10:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789571461; cv=none; b=SsPguKRDxckDRiEML2/adzrxcHYVC9VwvWGqCTgB2H/ViKJsXNwFswgpI52XUb8gEuAFL7u920vqzDra6+BilZpATBaYKUNmSN2GQcYnOJBnvNbjIV6wmvNwcMBreCRkpaGWIA3vGfa31W5Vu4gmYnXrnoIy1cSxL4Obk5l82yE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1789571461; c=relaxed/simple; bh=kcCekCdd0xXogTnLIuCa8Bx6EwG7SCmZNgJ+WGf7HiM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eEcNXAng7UEx+iTCdqNnvYiAQ8nYjVWUGopOZncK9MXpzPF6rJU5BXeNS2nJKC0/pIWr7IhZh7Nx7hH5nvAv2xFHy7JIw7kL20LVcocf9FgbJbTAbeEA/S4ORlYHAVmgl0CDZ1D1cTd6SFxEzDOmoloHnCVbHOCs1iOnAeGXlqQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b=czMpeaFI; arc=none smtp.client-ip=148.163.158.5 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.b="czMpeaFI" Received: from pps.filterd (m0353725.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 68GEVwGQ2848423; Wed, 16 Sep 2026 15:10:42 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=Tyn7p4qMx787NAdSd nxhAQIMdWPHTdHAcg4NY+NhEC0=; b=czMpeaFIzK8XXnuENgrEoGmnJGhhLWE1n y3tw01nKB+cw4dVn04e9CCsoP4Uxlbf+716wXnoy51ZN/+jatzJG6osej0bClFCX yK+a+FztqAk+xMRq9RxqNwkM7t05xHNLZ7Nb/VxjAT+M4Qjbtk6kIvQFH/VQE+60 V8kbXGcYd7V+0AzDQKU04Xnn33Y83tg+mT2jZ4lh2IVcON3+M+gq3ryLbSO18XmT VT51gG6Uofs+bqpuH/IIE0T4Ug7dt4b1Crulky72DD1mMsQps/ObOCdaJ7Yu80wR wdBXINjRP+MBYpoIcq8B2we2y4xYHUrUs+eWXlgjEbJtfE8Fhwmtw== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4gmw5e51qu-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 16 Sep 2026 15:10:42 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 68GEaAL71585010; Wed, 16 Sep 2026 15:10:42 GMT Received: from smtprelay07.fra02v.mail.ibm.com ([9.218.2.229]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4gq089putm-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 16 Sep 2026 15:10:42 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (smtpav05.fra02v.mail.ibm.com [10.20.54.104]) by smtprelay07.fra02v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 68GFAc7h45613390 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 16 Sep 2026 15:10:38 GMT Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1E54620040; Wed, 16 Sep 2026 15:10:38 +0000 (GMT) Received: from smtpav05.fra02v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E89E620043; Wed, 16 Sep 2026 15:10:33 +0000 (GMT) Received: from li-a84c74cc-2b13-11b2-a85c-acdd023f0674.ibm.com.com (unknown [9.61.52.228]) by smtpav05.fra02v.mail.ibm.com (Postfix) with ESMTP; Wed, 16 Sep 2026 15:10:33 +0000 (GMT) From: Nilay Shroff To: hch@lst.de, kbusch@kernel.org, sagi@grimberg.me, kch@nvidia.com Cc: linux-nvme@lists.infradead.org, linux-kernel@vger.kernel.org, gjoyce@linux.ibm.com, Nilay Shroff Subject: [PATCH 2/2] nvmet: don't allow I/O admission after percpu ns reference is killed Date: Wed, 16 Sep 2026 20:40:00 +0530 Message-ID: <20260916151012.3702896-3-nilay@linux.ibm.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260916151012.3702896-1-nilay@linux.ibm.com> References: <20260916151012.3702896-1-nilay@linux.ibm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-TM-AS-GCONF: 00 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYwOTE2MDIwNCBTYWx0ZWRfX9AyQMTC/Sczo aNWfdl02ezkbAk9eRO7cK652SlupP1yzWVE4EVil/ywkWbDAtjnmbmB1zwa67lSngnlUnUYmd5s PrXt9K39hMAuCO018IUTXe4vVPHmYhG/PrFOwOUEU8g3HBSdqh/dHwWOEUxvpdGScZyoTB5D7zS 83tyQJJ7MUUQiLOoSsp/isobco+/iel2HNzQsvP6kWQce5lm6xU+bkbqVUznpnG8iDJOw74No5p 2N7ezkQjHQMDRnGRztk2af4DSKCDcmkbnR4jNNEXlndf5W1gmZfbPUaYMVxvMR6zr5qnoKIZxTJ RHdaX5GMW8OiBoolCatt8opMrCJO4KoQBNveRUiVqFSbjbaGji6x+bmiwwXpYSaIED9219lqDo/ K0sBMmaYxs4XU5BAsBbK4WvkzJ3Mg2ogFTT73hecbzW8dufyNbTI+/a+FSKOAadDTCeMB9Z5CNE J24EnaEh+gy5DyZVjWg== X-Authority-Analysis: v=2.4 cv=E/NYNqdl c=1 sm=1 tr=0 ts=6aaab172 cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=VdqzKS8jKosA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=V8glGbnc2Ofi9Qvn3v5h:22 a=VnNF1IyMAAAA:8 a=uDwynFsZHstSZAYALL0A:9 X-Proofpoint-ORIG-GUID: dZn6IjynXkF34tanayK0rMyapIUqzj9I X-Proofpoint-Spam-Info: AW1haW4tMjYwOTE2MDIwNCBTYWx0ZWRfXx6mlc+Tx3Q9A ubMHMxcWNFUSDmt9MM5IfmRx/bvFl5YuHFz9eyu7Tcp846T5KplXT/wyfgURHbYIOsHrEEI+jnP /f/WcmCbGMdDwx5sfSeFWegaIdttYBQ= X-Proofpoint-GUID: dZn6IjynXkF34tanayK0rMyapIUqzj9I X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.134,FMLib:17.12.100.49 definitions=2026-09-16_02,2026-09-16_01,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 adultscore=0 clxscore=1015 bulkscore=0 malwarescore=0 suspectscore=0 phishscore=0 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2609040000 definitions=main-2609160204 Content-Type: text/plain; charset="utf-8" nvmet_req_find_ns() uses percpu_ref_get() to obtain a reference to the namespace. However, percpu_ref_get() can acquire a reference even after the namespace reference has been killed (or marked DEAD). This is undesirable during namespace disable because nvmet_ns_disable() kills the namespace reference and then waits for all outstanding references to drain. Acquiring a new reference after the reference is killed can therefore extend the namespace drain period. Replace percpu_ref_get() in nvmet_req_find_ns() with percpu_ref_tryget_live_rcu(), which only acquires a reference while the namespace reference is still live. This handles the race where nvmet_req_find_ns() finds ns is enabled but before it acquires the reference to ns, its reference is killed in nvmet_ns_disable(). For instnace check this race: CPU0 CPU1 nvmet_req_find_ns(): nvmet_ns_disable(): xa_load() -> ns mark =3D=3D set xa_clear_mark() percpu_ref_kill() // DEAD percpu_ref_get() synchronize_rcu() | wait_for_completion() +-- succeed Replacing percpu_ref_get() with percpu_ref_tryget_live_rcu() prevents the I/O request from acquiring a namespace reference once the reference has been marked DEAD. Perform the namespace lookup and reference acquisition in nvmet_req_find_ns() within an RCU read-side critical section. nvmet_ns_disable() uses synchronize_rcu() before draining and exiting the namespace reference, ensuring that RCU readers which may be acquiring the namespace reference have completed before the reference is exited. Signed-off-by: Nilay Shroff --- drivers/nvme/target/core.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c index 77d113fceced..81a2ae072909 100644 --- a/drivers/nvme/target/core.c +++ b/drivers/nvme/target/core.c @@ -446,21 +446,27 @@ u16 nvmet_req_find_ns(struct nvmet_req *req) { u32 nsid =3D le32_to_cpu(req->cmd->common.nsid); struct nvmet_subsys *subsys =3D nvmet_req_subsys(req); + u16 status =3D NVME_SC_SUCCESS; =20 + rcu_read_lock(); req->ns =3D xa_load(&subsys->namespaces, nsid); if (unlikely(!req->ns) || - !xa_get_mark(&subsys->namespaces, nsid, NVMET_NS_ENABLED)) { + !xa_get_mark(&subsys->namespaces, nsid, NVMET_NS_ENABLED) || + !percpu_ref_tryget_live_rcu(&req->ns->ref)) { req->error_loc =3D offsetof(struct nvme_common_command, nsid); - if (!req->ns) /* ns doesn't exist! */ - return NVME_SC_INVALID_NS | NVME_STATUS_DNR; + if (!req->ns) { /* ns doesn't exist! */ + status =3D NVME_SC_INVALID_NS | NVME_STATUS_DNR; + goto unlock; + } =20 /* ns exists but it's disabled */ req->ns =3D NULL; - return NVME_SC_INTERNAL_PATH_ERROR; + status =3D NVME_SC_INTERNAL_PATH_ERROR; } +unlock: + rcu_read_unlock(); =20 - percpu_ref_get(&req->ns->ref); - return NVME_SC_SUCCESS; + return status; } =20 static void nvmet_destroy_namespace(struct percpu_ref *ref) --=20 2.53.0