From nobody Thu Oct 2 10:49:36 2025 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (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 4E7091E32D6 for ; Wed, 17 Sep 2025 13:41:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116498; cv=none; b=RdFD+OObWLLKzUgDzQ8jYbsG11FMK4Iya/FLBEKw+asLHY0Ldwctg5UDDn6wjsYkhApRUDvPnbch8oy+M7wBbu0lPQ/RpnN/z5hJzEypCwOEa/Qx5nCavbRZX8T/yJUC6jVGhLXDwU9nfznzVqxgXme/5OQ9Hzkvqv0VHiW4kJQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116498; c=relaxed/simple; bh=IHPKBKUHBCQv+vf6QHv35uUvAqo5mXtMFlwSA2YvK5c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=eCe27KkihQUsn5ITbJbYQQCQrqGNUa7WBGAH7LT5k35uB71K1UidAvNBa5T8v/eYZSaXeGuybcVCRicJ78UFtBjfNwY/yip8rDigmnUeSXd4WJN/u0VNswzvY1xbKjym2CDXU2Fo5z7AEg5YlzvLIQRMH28v5r1YixPdQRKwSWU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=XcEIw/xp; arc=none smtp.client-ip=203.254.224.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="XcEIw/xp" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20250917134134epoutp04d97380616eae2ea554f5b84a01bb8da3~mFaL5vUAP0413504135epoutp04y for ; Wed, 17 Sep 2025 13:41:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20250917134134epoutp04d97380616eae2ea554f5b84a01bb8da3~mFaL5vUAP0413504135epoutp04y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116494; bh=jc8FD7JXvWhCV/EAXTp2IPOjNKOfDlPIfA8NoFMX5Pc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XcEIw/xp0oyMbnimScQPpuRsjeA03GfwqkK+LH9ZBhuo1XIfIuyO/a2Lm7FK9Ngfr 75p+ttccMnbjfjP9nAbumZLu/D/TIspVDNUDwYAF+fIqQddm4uAxGk4U+9gfTkDslc XhedDrS2zIPFUIul/uhpapapigLYK4oOz2s/YM2U= Received: from epsnrtp02.localdomain (unknown [182.195.42.154]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPS id 20250917134132epcas5p31b585c9eaf4dd2455d4deebaa8374b08~mFaKLqISg0180401804epcas5p3c; Wed, 17 Sep 2025 13:41:32 +0000 (GMT) Received: from epcas5p2.samsung.com (unknown [182.195.38.93]) by epsnrtp02.localdomain (Postfix) with ESMTP id 4cRg0W3N6sz2SSKY; Wed, 17 Sep 2025 13:41:31 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20250917134130epcas5p417d7c26bc564d64d1bcea6e04d55704d~mFaIm5Pk92411724117epcas5p49; Wed, 17 Sep 2025 13:41:30 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134129epsmtip29579ab0689edfb63670e6fd4f4a1c525~mFaHUVYzZ0862908629epsmtip2-; Wed, 17 Sep 2025 13:41:29 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 01/20] nvdimm/label: Introduce NDD_REGION_LABELING flag to set region label Date: Wed, 17 Sep 2025 19:10:57 +0530 Message-Id: <20250917134116.1623730-2-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134130epcas5p417d7c26bc564d64d1bcea6e04d55704d X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134130epcas5p417d7c26bc564d64d1bcea6e04d55704d References: <20250917134116.1623730-1-s.neeraj@samsung.com> Prior to LSA 2.1 version, LSA contain only namespace labels. LSA 2.1 introduced in CXL 2.0 Spec, which contain region label along with namespace label. NDD_LABELING flag is used for namespace. Introduced NDD_REGION_LABELING flag for region label. Based on these flags nvdimm driver performs operation on namespace label or region label. NDD_REGION_LABELING will be utilized by cxl driver to enable LSA 2.1 region label support Accordingly updated label index version Signed-off-by: Neeraj Kumar Reviewed-by: Dave Jiang --- drivers/nvdimm/dimm.c | 1 + drivers/nvdimm/dimm_devs.c | 7 +++++++ drivers/nvdimm/label.c | 21 +++++++++++++++++---- drivers/nvdimm/nd.h | 1 + include/linux/libnvdimm.h | 3 +++ 5 files changed, 29 insertions(+), 4 deletions(-) diff --git a/drivers/nvdimm/dimm.c b/drivers/nvdimm/dimm.c index 91d9163ee303..bda22cb94e5b 100644 --- a/drivers/nvdimm/dimm.c +++ b/drivers/nvdimm/dimm.c @@ -62,6 +62,7 @@ static int nvdimm_probe(struct device *dev) if (rc < 0) dev_dbg(dev, "failed to unlock dimm: %d\n", rc); =20 + ndd->cxl =3D nvdimm_check_region_label_format(ndd->dev); =20 /* * EACCES failures reading the namespace label-area-properties diff --git a/drivers/nvdimm/dimm_devs.c b/drivers/nvdimm/dimm_devs.c index 21498d461fde..918c3db93195 100644 --- a/drivers/nvdimm/dimm_devs.c +++ b/drivers/nvdimm/dimm_devs.c @@ -18,6 +18,13 @@ =20 static DEFINE_IDA(dimm_ida); =20 +bool nvdimm_check_region_label_format(struct device *dev) +{ + struct nvdimm *nvdimm =3D to_nvdimm(dev); + + return test_bit(NDD_REGION_LABELING, &nvdimm->flags); +} + /* * Retrieve bus and dimm handle and return if this bus supports * get_config_data commands diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index 04f4a049599a..0a9b6c5cb2c3 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -688,11 +688,24 @@ static int nd_label_write_index(struct nvdimm_drvdata= *ndd, int index, u32 seq, - (unsigned long) to_namespace_index(ndd, 0); nsindex->labeloff =3D __cpu_to_le64(offset); nsindex->nslot =3D __cpu_to_le32(nslot); - nsindex->major =3D __cpu_to_le16(1); - if (sizeof_namespace_label(ndd) < 256) + + /* Set LSA Label Index Version */ + if (ndd->cxl) { + /* CXL r3.2: Table 9-9 Label Index Block Layout */ + nsindex->major =3D __cpu_to_le16(2); nsindex->minor =3D __cpu_to_le16(1); - else - nsindex->minor =3D __cpu_to_le16(2); + } else { + nsindex->major =3D __cpu_to_le16(1); + /* + * NVDIMM Namespace Specification + * Table 2: Namespace Label Index Block Fields + */ + if (sizeof_namespace_label(ndd) < 256) + nsindex->minor =3D __cpu_to_le16(1); + else /* UEFI 2.7: Label Index Block Definitions */ + nsindex->minor =3D __cpu_to_le16(2); + } + nsindex->checksum =3D __cpu_to_le64(0); if (flags & ND_NSINDEX_INIT) { unsigned long *free =3D (unsigned long *) nsindex->free; diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h index cc5c8f3f81e8..158809c2be9e 100644 --- a/drivers/nvdimm/nd.h +++ b/drivers/nvdimm/nd.h @@ -522,6 +522,7 @@ void nvdimm_set_labeling(struct device *dev); void nvdimm_set_locked(struct device *dev); void nvdimm_clear_locked(struct device *dev); int nvdimm_security_setup_events(struct device *dev); +bool nvdimm_check_region_label_format(struct device *dev); #if IS_ENABLED(CONFIG_NVDIMM_KEYS) int nvdimm_security_unlock(struct device *dev); #else diff --git a/include/linux/libnvdimm.h b/include/linux/libnvdimm.h index 28f086c4a187..5696715c33bb 100644 --- a/include/linux/libnvdimm.h +++ b/include/linux/libnvdimm.h @@ -44,6 +44,9 @@ enum { /* dimm provider wants synchronous registration by __nvdimm_create() */ NDD_REGISTER_SYNC =3D 8, =20 + /* dimm supports region labels (LSA Format 2.1) */ + NDD_REGION_LABELING =3D 9, + /* need to set a limit somewhere, but yes, this is likely overkill */ ND_IOCTL_MAX_BUFLEN =3D SZ_4M, ND_CMD_MAX_ELEM =3D 5, --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (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 4F189258CE2 for ; Thu, 18 Sep 2025 04:28:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758169687; cv=none; b=iRbHsSC2ATOT+GaicjnN+EXRyJQ//Cqt5rvDM0GahTPtclXsWkEwVPAF9CDNU33g5mfa2TzyuNTd6YZiJo9/3muE+FWucs0aafCYY3R1NO8yKpDT4gxwhKpIAbiz75LC8OTb1FwL23New5rgReUhd3+Gj84GQts8ciyiik06UPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758169687; c=relaxed/simple; bh=huzLLkBs3Vk5ryeeSJ5VZUBZGOCp4kS3cFAiVMmu5JQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=n656SRmNECSz72IGrP0XFXsM/NpPIsIiedVv0hAE9Oib2AHtmfU+QFEb2/tKIFTYwktoyNS4Tp5dajPSGvq8lo14FhunPAPTACye8JXbbjNwKNzk8LIvbb/Hh3+Hl3lLIqoePmRRL886d6q00gkPEnqBQHl85K7TNqA8A995fjE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=YQbA0kRA; arc=none smtp.client-ip=203.254.224.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="YQbA0kRA" Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20250918042803epoutp04c9cbd0ac77ecf9e5007579d83165bd4e~mRgMIGmrI2274622746epoutp04Q for ; Thu, 18 Sep 2025 04:28:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20250918042803epoutp04c9cbd0ac77ecf9e5007579d83165bd4e~mRgMIGmrI2274622746epoutp04Q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758169683; bh=VfTKt+9cya/Xi6xKXtJ2s6w+UyV0o12N66zYmXYF2Bw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YQbA0kRABPa4qazJNmP0w0ncK1iF3Ho0j+8cn/pFxfHuwfpUP5GydFeH4Pnas5fhJ UOF7IaB6Ry8XYdV49c/d8ZJBqKoyFrEBOPc23bTC2k7BwHK7uziZaMIe7JeMCQe8c8 tyxpNJAf2oVJ/kOLr9nqPivFviuhLYJyi17XXucU= Received: from epsnrtp02.localdomain (unknown [182.195.42.154]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPS id 20250918042802epcas5p395734330ce89f122c2e1396d1fbb2f29~mRgLfUQX02834428344epcas5p3J; Thu, 18 Sep 2025 04:28:02 +0000 (GMT) Received: from epcpadp2new (unknown [182.195.40.142]) by epsnrtp02.localdomain (Postfix) with ESMTP id 4cS2gQ4dgJz2SSKd; Thu, 18 Sep 2025 04:28:02 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20250917134132epcas5p192c031691ab4cbb905f2b2313bb79dee~mFaKh1Xvt1744617446epcas5p1D; Wed, 17 Sep 2025 13:41:32 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134131epsmtip2b3ec6fcf599b4b2f199f60c0dc1c8878~mFaI_cDaX0779307793epsmtip2_; Wed, 17 Sep 2025 13:41:30 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar , Jonathan Cameron , Ira Weiny Subject: [PATCH V3 02/20] nvdimm/label: CXL labels skip the need for 'interleave-set cookie' Date: Wed, 17 Sep 2025 19:10:58 +0530 Message-Id: <1891546521.01758169682623.JavaMail.epsvc@epcpadp2new> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134132epcas5p192c031691ab4cbb905f2b2313bb79dee X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y X-Hop-Count: 3 X-CMS-RootMailID: 20250917134132epcas5p192c031691ab4cbb905f2b2313bb79dee References: <20250917134116.1623730-1-s.neeraj@samsung.com> CXL LSA v2.1 utilizes the region labels stored in the LSA for interleave set configuration instead of interleave-set cookie used in previous LSA versions. As interleave-set cookie is not required for CXL LSA v2.1 format so skip its usage for CXL LSA 2.1 format Signed-off-by: Neeraj Kumar Reviewed-by: Jonathan Cameron Acked-by: Ira Weiny Reviewed-by: Dave Jiang --- drivers/nvdimm/namespace_devs.c | 8 +++++++- drivers/nvdimm/region_devs.c | 10 ++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_dev= s.c index 55cfbf1e0a95..3271b1c8569a 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -1684,7 +1684,13 @@ static struct device *create_namespace_pmem(struct n= d_region *nd_region, int rc =3D 0; u16 i; =20 - if (cookie =3D=3D 0) { + /* + * CXL LSA v2.1 utilizes the region label stored in the LSA for + * interleave set configuration. Whereas EFI LSA v1.1 & v1.2 + * utilizes interleave-set cookie. i.e, CXL labels skip the + * need for 'interleave-set cookie' + */ + if (!ndd->cxl && cookie =3D=3D 0) { dev_dbg(&nd_region->dev, "invalid interleave-set-cookie\n"); return ERR_PTR(-ENXIO); } diff --git a/drivers/nvdimm/region_devs.c b/drivers/nvdimm/region_devs.c index de1ee5ebc851..88275f352240 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c @@ -858,6 +858,16 @@ u64 nd_region_interleave_set_cookie(struct nd_region *= nd_region, if (!nd_set) return 0; =20 + /* + * CXL LSA v2.1 utilizes the region label stored in the LSA for + * interleave set configuration. Whereas EFI LSA v1.1 & v1.2 + * utilizes interleave-set cookie. i.e, CXL labels skip the + * need for 'interleave-set cookie' + */ + if (nsindex && __le16_to_cpu(nsindex->major) =3D=3D 2 + && __le16_to_cpu(nsindex->minor) =3D=3D 1) + return 0; + if (nsindex && __le16_to_cpu(nsindex->major) =3D=3D 1 && __le16_to_cpu(nsindex->minor) =3D=3D 1) return nd_set->cookie1; --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (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 0FED431BC93 for ; Wed, 17 Sep 2025 13:41:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.24 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116500; cv=none; b=HxObnhqAh1hEmzwBLNJX1ZrmgM77K7+8xeY8L52cI0jCrHPNpXv4YUSAoe8HWV4/UIYgBffSwtgNwhmXbqIItyB3dcdFVCWcXxlmoajlEu59Rf4kjm0cBwyMvoWQBkxXIFs7wQaoHNK4ffHcaimN7/tTYoFe8JJWK+w7W91rFDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116500; c=relaxed/simple; bh=jE8XefBKHoH4o8xanFWc0C2cpGJEqVbjQVeCi5HEx6c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=bjcbe4HcKVAD891iVaXEInUHPP/AeUhqm79RyIK2aTLe40OMYYt3edza0pBxJaKDRFaep0vzksmAFDtIgFyXcoHMhFd5wqI0JfygzKRMQXYf6Wl+EgVp5x/FjwGyRQyKDnmso9f71p9k4EKeHsBNx4H7Lj6A/x1on5PxJX+DDBM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=mmmtrZNz; arc=none smtp.client-ip=203.254.224.24 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="mmmtrZNz" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20250917134136epoutp01de3964db3d25d4d149585be484e39d36~mFaNtna9t2841328413epoutp01U for ; Wed, 17 Sep 2025 13:41:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20250917134136epoutp01de3964db3d25d4d149585be484e39d36~mFaNtna9t2841328413epoutp01U DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116496; bh=rqMArwoFuPVor1N9q2bx2CVy1q2vuGySReKFqLZxQOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mmmtrZNznvpHqa9mO1L1J6KGaTJ8/b/ibrGL5cMRoGvfbUDxCCLX0yq8Y9yGZ9v8K KvYnAwwogvXLQVPqibsfHWFBqoh5cZJGfR5irrjDS1aphgkFEpnFCwG+SjDUdcZN4+ x4A5eurzbGOC7Rlzy2TCHMUaCnjJKHGEnwrOTSYU= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPS id 20250917134135epcas5p1dee91eade89746c8ca55765f8878774a~mFaNXNgaQ3219532195epcas5p1t; Wed, 17 Sep 2025 13:41:35 +0000 (GMT) Received: from epcas5p2.samsung.com (unknown [182.195.38.89]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4cRg0Z5XhWz6B9m6; Wed, 17 Sep 2025 13:41:34 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20250917134134epcas5p3f64af9556015ed9dfb881f852ea854c4~mFaMBBK7T0180501805epcas5p3f; Wed, 17 Sep 2025 13:41:34 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134133epsmtip21c7d66b792f81a407055c318a9552687~mFaKzBvZV0833108331epsmtip2h; Wed, 17 Sep 2025 13:41:32 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 03/20] nvdimm/label: Modify nd_label_base() signature Date: Wed, 17 Sep 2025 19:10:59 +0530 Message-Id: <20250917134116.1623730-4-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134134epcas5p3f64af9556015ed9dfb881f852ea854c4 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134134epcas5p3f64af9556015ed9dfb881f852ea854c4 References: <20250917134116.1623730-1-s.neeraj@samsung.com> nd_label_base() was being used after typecasting with 'unsigned long'. Thus modified nd_label_base() to return 'unsigned long' instead of 'struct nd_namespace_label *' Signed-off-by: Neeraj Kumar Acked-by: Ira Weiny Reviewed-by: Dave Jiang --- drivers/nvdimm/label.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index 0a9b6c5cb2c3..668e1e146229 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -271,11 +271,11 @@ static void nd_label_copy(struct nvdimm_drvdata *ndd, memcpy(dst, src, sizeof_namespace_index(ndd)); } =20 -static struct nd_namespace_label *nd_label_base(struct nvdimm_drvdata *ndd) +static unsigned long nd_label_base(struct nvdimm_drvdata *ndd) { void *base =3D to_namespace_index(ndd, 0); =20 - return base + 2 * sizeof_namespace_index(ndd); + return (unsigned long) (base + 2 * sizeof_namespace_index(ndd)); } =20 static int to_slot(struct nvdimm_drvdata *ndd, @@ -284,7 +284,7 @@ static int to_slot(struct nvdimm_drvdata *ndd, unsigned long label, base; =20 label =3D (unsigned long) nd_label; - base =3D (unsigned long) nd_label_base(ndd); + base =3D nd_label_base(ndd); =20 return (label - base) / sizeof_namespace_label(ndd); } @@ -293,7 +293,7 @@ static struct nd_namespace_label *to_label(struct nvdim= m_drvdata *ndd, int slot) { unsigned long label, base; =20 - base =3D (unsigned long) nd_label_base(ndd); + base =3D nd_label_base(ndd); label =3D base + sizeof_namespace_label(ndd) * slot; =20 return (struct nd_namespace_label *) label; @@ -684,7 +684,7 @@ static int nd_label_write_index(struct nvdimm_drvdata *= ndd, int index, u32 seq, nd_label_next_nsindex(index)) - (unsigned long) to_namespace_index(ndd, 0); nsindex->otheroff =3D __cpu_to_le64(offset); - offset =3D (unsigned long) nd_label_base(ndd) + offset =3D nd_label_base(ndd) - (unsigned long) to_namespace_index(ndd, 0); nsindex->labeloff =3D __cpu_to_le64(offset); nsindex->nslot =3D __cpu_to_le32(nslot); --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (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 B0CA3328965 for ; Wed, 17 Sep 2025 13:41:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116503; cv=none; b=lcdj5RPZPvjUP3cnG0P/i8hNfhkLsccuZp4D44HzcxnePS9LEinHcPfy8c3AOx0mf0E7Y2AbrOoUfJzOVPYtG+o/W6yUv/GrMuDEVjd3qOa2JTUXnYXr6FvckurCP7bMgN9eElo61wGvhTqw/jZ0R2UYdBrKr7NLsJlRle7x0QU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116503; c=relaxed/simple; bh=zf5v0P2isE0qmAmZVojJgSZzamCbh8gBkuc7+76jBBk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=O/To4pqKsx4DuqR+GSDeOLyt5LZePI3xnYynY4IFm8KdFM2Ndw1JymXTRrqAjlgYzeeuJypSmmnSiHBYCC1gG/4lIEz15HI0Gt4J72PWBF/FzI0MSAxM6uXBNCvJt7w0tQEqu++rUgZpIDRBeYPO7KXHbtEmTsQKMEw1b6s90qk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=Qp8jWngo; arc=none smtp.client-ip=203.254.224.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="Qp8jWngo" Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20250917134138epoutp04e189089924669baec4420aa5da02cfb3~mFaQUR69Y0546205462epoutp04C for ; Wed, 17 Sep 2025 13:41:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20250917134138epoutp04e189089924669baec4420aa5da02cfb3~mFaQUR69Y0546205462epoutp04C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116499; bh=VbBlpRaiPk+6zIQaFNB8aIo/sNFkPAmn9Rc+w20AuEo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Qp8jWngofSNaoHrzB7uGUrxugT+CavkwPbk+LiwYbqLHlzJJjv5YschagVuOpxrm5 b3/YqhaqPJsoeA0fAqs9RZ4/9mAA9+PDBrFdWG5KJjpCtHLrz7dloVjEEXJl2sqebe BGPJud82J00kZphQws7UzRiVsVsB1S1JByksDc2w= Received: from epsnrtp03.localdomain (unknown [182.195.42.155]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20250917134138epcas5p2be817d11fd58f21c7c873dad49881e95~mFaP4hlBN0928509285epcas5p2F; Wed, 17 Sep 2025 13:41:38 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.94]) by epsnrtp03.localdomain (Postfix) with ESMTP id 4cRg0d3H72z3hhT4; Wed, 17 Sep 2025 13:41:37 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20250917134136epcas5p118f18ce5139d489d90ac608e3887c1fc~mFaN5iUaH3225232252epcas5p14; Wed, 17 Sep 2025 13:41:36 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134134epsmtip29428fbe4650670d0dee40f007158e69b~mFaMQBR6-0833808338epsmtip2E; Wed, 17 Sep 2025 13:41:34 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 04/20] nvdimm/label: Update mutex_lock() with guard(mutex)() Date: Wed, 17 Sep 2025 19:11:00 +0530 Message-Id: <20250917134116.1623730-5-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134136epcas5p118f18ce5139d489d90ac608e3887c1fc X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134136epcas5p118f18ce5139d489d90ac608e3887c1fc References: <20250917134116.1623730-1-s.neeraj@samsung.com> Updated mutex_lock() with guard(mutex)() Signed-off-by: Neeraj Kumar --- drivers/nvdimm/label.c | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index 668e1e146229..3235562d0e1c 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -948,7 +948,7 @@ static int __pmem_label_update(struct nd_region *nd_reg= ion, return rc; =20 /* Garbage collect the previous label */ - mutex_lock(&nd_mapping->lock); + guard(mutex)(&nd_mapping->lock); list_for_each_entry(label_ent, &nd_mapping->labels, list) { if (!label_ent->label) continue; @@ -960,20 +960,20 @@ static int __pmem_label_update(struct nd_region *nd_r= egion, /* update index */ rc =3D nd_label_write_index(ndd, ndd->ns_next, nd_inc_seq(__le32_to_cpu(nsindex->seq)), 0); - if (rc =3D=3D 0) { - list_for_each_entry(label_ent, &nd_mapping->labels, list) - if (!label_ent->label) { - label_ent->label =3D nd_label; - nd_label =3D NULL; - break; - } - dev_WARN_ONCE(&nspm->nsio.common.dev, nd_label, - "failed to track label: %d\n", - to_slot(ndd, nd_label)); - if (nd_label) - rc =3D -ENXIO; - } - mutex_unlock(&nd_mapping->lock); + if (rc) + return rc; + + list_for_each_entry(label_ent, &nd_mapping->labels, list) + if (!label_ent->label) { + label_ent->label =3D nd_label; + nd_label =3D NULL; + break; + } + dev_WARN_ONCE(&nspm->nsio.common.dev, nd_label, + "failed to track label: %d\n", + to_slot(ndd, nd_label)); + if (nd_label) + rc =3D -ENXIO; =20 return rc; } @@ -998,9 +998,8 @@ static int init_labels(struct nd_mapping *nd_mapping, i= nt num_labels) label_ent =3D kzalloc(sizeof(*label_ent), GFP_KERNEL); if (!label_ent) return -ENOMEM; - mutex_lock(&nd_mapping->lock); + guard(mutex)(&nd_mapping->lock); list_add_tail(&label_ent->list, &nd_mapping->labels); - mutex_unlock(&nd_mapping->lock); } =20 if (ndd->ns_current =3D=3D -1 || ndd->ns_next =3D=3D -1) @@ -1039,7 +1038,7 @@ static int del_labels(struct nd_mapping *nd_mapping, = uuid_t *uuid) if (!preamble_next(ndd, &nsindex, &free, &nslot)) return 0; =20 - mutex_lock(&nd_mapping->lock); + guard(mutex)(&nd_mapping->lock); list_for_each_entry_safe(label_ent, e, &nd_mapping->labels, list) { struct nd_namespace_label *nd_label =3D label_ent->label; =20 @@ -1061,7 +1060,6 @@ static int del_labels(struct nd_mapping *nd_mapping, = uuid_t *uuid) nd_mapping_free_labels(nd_mapping); dev_dbg(ndd->dev, "no more active labels\n"); } - mutex_unlock(&nd_mapping->lock); =20 return nd_label_write_index(ndd, ndd->ns_next, nd_inc_seq(__le32_to_cpu(nsindex->seq)), 0); --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (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 CBBBD328995 for ; Wed, 17 Sep 2025 13:41:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116504; cv=none; b=uyFnDqBwMGGClghJZ2w3wLREiU2CSWrq+HAJvxhY9RfZvrzMW3sVz+qQgfp/8DZZOPsN8dI3EXmGPls+7mKK+fc9ca8cXj25RFe2MptnwEh6EihJukEH48eyfHdaj488BAIJ3aCroMrBe4Zah3cMqXUOODxFX301l7ORYpo9OWI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116504; c=relaxed/simple; bh=RkAsuDKxc8445mRlXvsnxqnd4Yo1V+gjETT/kjelF7E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=VM7wBZc0fPqm8cGgE6KK0f7maTZRubJBzOnBlPfY9kJwaR/LdbB1oT5t17nTnmxhTSrTLl1m3yiRrQ40xeqszL3pdjaGtxRISCf//33sg7Pzi25N+tv9LZpeXBvN9KpR4VrhCru/QzbON7z6cqEBuogVuos/cqKYcM7rtCUVMwc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=fTs5Jtxs; arc=none smtp.client-ip=203.254.224.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="fTs5Jtxs" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20250917134140epoutp0462df9ffe061f2047af20d3755ff2553d~mFaRbA6rw0413504135epoutp042 for ; Wed, 17 Sep 2025 13:41:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20250917134140epoutp0462df9ffe061f2047af20d3755ff2553d~mFaRbA6rw0413504135epoutp042 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116500; bh=L8I4pczPLL+3fGYbV4VkM8e4qH7d3Y7IhMKieoHkqSY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=fTs5JtxsiQRaFXydTJiV4zst3ukA041MWmAvs+0zMxGqNVzul1nrZhfFtq0ChexiV Y1u5ta6nD0WXipTFpwXJpmDFkATx3lEoSEKQ6de1rViBZBO0Sp9+F7Mr8c5ZBeUMY/ 0EO9hCN1oTieZ5sNfuG7PUYBF9FTIU8Rgx5zC4p0= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPS id 20250917134139epcas5p17de75f6f34fd82c902ad860ef9d803e0~mFaQ6us6f1744017440epcas5p1J; Wed, 17 Sep 2025 13:41:39 +0000 (GMT) Received: from epdlp11prp10 (unknown [182.195.38.95]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4cRg0f4z8Gz6B9m8; Wed, 17 Sep 2025 13:41:38 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20250917134138epcas5p2b02390404681df79c26f7a1a0f0262b8~mFaPqep2X1122211222epcas5p2B; Wed, 17 Sep 2025 13:41:38 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134136epsmtip2937729757e7b83a96e66fb422f807226~mFaOH1cRi0779307793epsmtip2-; Wed, 17 Sep 2025 13:41:36 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 05/20] nvdimm/namespace_label: Add namespace label changes as per CXL LSA v2.1 Date: Wed, 17 Sep 2025 19:11:01 +0530 Message-Id: <20250917134116.1623730-6-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134138epcas5p2b02390404681df79c26f7a1a0f0262b8 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134138epcas5p2b02390404681df79c26f7a1a0f0262b8 References: <20250917134116.1623730-1-s.neeraj@samsung.com> CXL 3.2 Spec mentions CXL LSA 2.1 Namespace Labels at section 9.13.2.5 Modified __pmem_label_update function using setter functions to update namespace label as per CXL LSA 2.1 Signed-off-by: Neeraj Kumar Reviewed-by: Jonathan Cameron --- drivers/nvdimm/label.c | 3 +++ drivers/nvdimm/nd.h | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index 3235562d0e1c..182f8c9a01bf 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -924,6 +924,7 @@ static int __pmem_label_update(struct nd_region *nd_reg= ion, =20 nd_label =3D to_label(ndd, slot); memset(nd_label, 0, sizeof_namespace_label(ndd)); + nsl_set_type(ndd, nd_label); nsl_set_uuid(ndd, nd_label, nspm->uuid); nsl_set_name(ndd, nd_label, nspm->alt_name); nsl_set_flags(ndd, nd_label, flags); @@ -935,7 +936,9 @@ static int __pmem_label_update(struct nd_region *nd_reg= ion, nsl_set_lbasize(ndd, nd_label, nspm->lbasize); nsl_set_dpa(ndd, nd_label, res->start); nsl_set_slot(ndd, nd_label, slot); + nsl_set_alignment(ndd, nd_label, 0); nsl_set_type_guid(ndd, nd_label, &nd_set->type_guid); + nsl_set_region_uuid(ndd, nd_label, NULL); nsl_set_claim_class(ndd, nd_label, ndns->claim_class); nsl_calculate_checksum(ndd, nd_label); nd_dbg_dpa(nd_region, ndd, res, "\n"); diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h index 158809c2be9e..e362611d82cc 100644 --- a/drivers/nvdimm/nd.h +++ b/drivers/nvdimm/nd.h @@ -295,6 +295,29 @@ static inline const u8 *nsl_uuid_raw(struct nvdimm_drv= data *ndd, return nd_label->efi.uuid; } =20 +static inline void nsl_set_type(struct nvdimm_drvdata *ndd, + struct nd_namespace_label *ns_label) +{ + if (ndd->cxl && ns_label) + uuid_parse(CXL_NAMESPACE_UUID, (uuid_t *) ns_label->cxl.type); +} + +static inline void nsl_set_alignment(struct nvdimm_drvdata *ndd, + struct nd_namespace_label *ns_label, + u32 align) +{ + if (ndd->cxl) + ns_label->cxl.align =3D __cpu_to_le32(align); +} + +static inline void nsl_set_region_uuid(struct nvdimm_drvdata *ndd, + struct nd_namespace_label *ns_label, + const uuid_t *uuid) +{ + if (ndd->cxl && uuid) + export_uuid(ns_label->cxl.region_uuid, uuid); +} + bool nsl_validate_type_guid(struct nvdimm_drvdata *ndd, struct nd_namespace_label *nd_label, guid_t *guid); enum nvdimm_claim_class nsl_get_claim_class(struct nvdimm_drvdata *ndd, --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (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 136CF330D4B for ; Wed, 17 Sep 2025 13:41:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116507; cv=none; b=OYnrzpiouFoxphWy91/ZgtXNAsn45k9wpiR+K+h7cwWUtI4+Uml/8ZA/HLrjIS535ByqXbZg4K7Rnz5ffkRtZWjTj+RgoBRYHjtP2XyakBsl9LjICqPMRT4G0ROJTWFxP7mPG66NHbYkZvXuUPgqiOm2VWOKX7O615O40vDweJ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116507; c=relaxed/simple; bh=m+dlx95K5oRBB1Fo9JSKiyM7af1qhH+KR82XAaI2sP4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=Sgm/k6j6CyL0iv/KmsgrFj/HeYpP6ifi+zRk3Kee3cEC08cISZcBP2dA1ab06wv6NxTR9/iN4V302Ge0QB5rRmuAiT/gVz1oAPepWfr1BxX+efcfBxBa0mxtfwhWxeJaL4V6GbrKjP1W3c5nKDRqh0QeOA8WsNaX3mgV/H9xT64= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=s1y+3q2V; arc=none smtp.client-ip=203.254.224.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="s1y+3q2V" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20250917134143epoutp036303d21871577d6fb81e81b990bb1513~mFaULDdR_0922309223epoutp03K for ; Wed, 17 Sep 2025 13:41:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20250917134143epoutp036303d21871577d6fb81e81b990bb1513~mFaULDdR_0922309223epoutp03K DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116503; bh=ki1A0a36em7y8BY/guzR0gdUavTJy8xMVS6+k0q4n3Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s1y+3q2VwT9Z7kMpb3zFmP/Bun3XsblArMas/VOGUmneXkx3jWW/OUUphGBxtm+EZ 0dPJA9poEH2NPeTPv0SxbMOPtG2z6bLcKzBDaAlbE7lLg1ek2naIizwMpUrEbXlf5I R46uNzxiRUChhN+jedT1Dh0mGT0mTdKvII6K0EAU= Received: from epsnrtp02.localdomain (unknown [182.195.42.154]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPS id 20250917134142epcas5p11e82afebc343919d1c74d1668e6a9ef4~mFaTtp0J52209822098epcas5p1B; Wed, 17 Sep 2025 13:41:42 +0000 (GMT) Received: from epcas5p3.samsung.com (unknown [182.195.38.92]) by epsnrtp02.localdomain (Postfix) with ESMTP id 4cRg0j49mRz2SSKX; Wed, 17 Sep 2025 13:41:41 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20250917134140epcas5p23c007dab49ed7e98726b0dd9a2ce077a~mFaSEEw_61139711397epcas5p2H; Wed, 17 Sep 2025 13:41:40 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134138epsmtip2d721f83bd321153b910f3c898f1a0be7~mFaQOerRM0779307793epsmtip2A; Wed, 17 Sep 2025 13:41:38 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 06/20] nvdimm/region_label: Add region label update support Date: Wed, 17 Sep 2025 19:11:02 +0530 Message-Id: <20250917134116.1623730-7-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134140epcas5p23c007dab49ed7e98726b0dd9a2ce077a X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134140epcas5p23c007dab49ed7e98726b0dd9a2ce077a References: <20250917134116.1623730-1-s.neeraj@samsung.com> Modified __pmem_label_update() to update region labels into LSA Signed-off-by: Neeraj Kumar --- drivers/nvdimm/label.c | 269 ++++++++++++++++++++++++++------ drivers/nvdimm/label.h | 15 ++ drivers/nvdimm/namespace_devs.c | 12 ++ drivers/nvdimm/nd.h | 38 ++++- include/linux/libnvdimm.h | 8 + 5 files changed, 289 insertions(+), 53 deletions(-) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index 182f8c9a01bf..209c73f6b7e7 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -381,6 +381,16 @@ static void nsl_calculate_checksum(struct nvdimm_drvda= ta *ndd, nsl_set_checksum(ndd, nd_label, sum); } =20 +static void region_label_calculate_checksum(struct nvdimm_drvdata *ndd, + struct cxl_region_label *region_label) +{ + u64 sum; + + region_label_set_checksum(region_label, 0); + sum =3D nd_fletcher64(region_label, sizeof_namespace_label(ndd), 1); + region_label_set_checksum(region_label, sum); +} + static bool slot_valid(struct nvdimm_drvdata *ndd, struct nd_namespace_label *nd_label, u32 slot) { @@ -884,26 +894,20 @@ enum nvdimm_claim_class nsl_get_claim_class(struct nv= dimm_drvdata *ndd, return guid_to_nvdimm_cclass(&nd_label->efi.abstraction_guid); } =20 -static int __pmem_label_update(struct nd_region *nd_region, - struct nd_mapping *nd_mapping, struct nd_namespace_pmem *nspm, - int pos, unsigned long flags) +static int namespace_label_update(struct nd_region *nd_region, + struct nd_mapping *nd_mapping, + struct nd_namespace_pmem *nspm, + int pos, u64 flags, + struct nd_namespace_label *ns_label, + struct nd_namespace_index *nsindex, + u32 slot) { struct nd_namespace_common *ndns =3D &nspm->nsio.common; struct nd_interleave_set *nd_set =3D nd_region->nd_set; struct nvdimm_drvdata *ndd =3D to_ndd(nd_mapping); - struct nd_namespace_label *nd_label; - struct nd_namespace_index *nsindex; - struct nd_label_ent *label_ent; struct nd_label_id label_id; struct resource *res; - unsigned long *free; - u32 nslot, slot; - size_t offset; u64 cookie; - int rc; - - if (!preamble_next(ndd, &nsindex, &free, &nslot)) - return -ENXIO; =20 cookie =3D nd_region_interleave_set_cookie(nd_region, nsindex); nd_label_gen_id(&label_id, nspm->uuid, 0); @@ -916,36 +920,131 @@ static int __pmem_label_update(struct nd_region *nd_= region, return -ENXIO; } =20 + nsl_set_type(ndd, ns_label); + nsl_set_uuid(ndd, ns_label, nspm->uuid); + nsl_set_name(ndd, ns_label, nspm->alt_name); + nsl_set_flags(ndd, ns_label, flags); + nsl_set_nlabel(ndd, ns_label, nd_region->ndr_mappings); + nsl_set_nrange(ndd, ns_label, 1); + nsl_set_position(ndd, ns_label, pos); + nsl_set_isetcookie(ndd, ns_label, cookie); + nsl_set_rawsize(ndd, ns_label, resource_size(res)); + nsl_set_lbasize(ndd, ns_label, nspm->lbasize); + nsl_set_dpa(ndd, ns_label, res->start); + nsl_set_slot(ndd, ns_label, slot); + nsl_set_alignment(ndd, ns_label, 0); + nsl_set_type_guid(ndd, ns_label, &nd_set->type_guid); + nsl_set_region_uuid(ndd, ns_label, &nd_set->uuid); + nsl_set_claim_class(ndd, ns_label, ndns->claim_class); + nsl_calculate_checksum(ndd, ns_label); + nd_dbg_dpa(nd_region, ndd, res, "\n"); + + return 0; +} + +static void region_label_update(struct nd_region *nd_region, + struct cxl_region_label *region_label, + struct nd_mapping *nd_mapping, + int pos, u64 flags, u32 slot) +{ + struct nd_interleave_set *nd_set =3D nd_region->nd_set; + struct nvdimm_drvdata *ndd =3D to_ndd(nd_mapping); + + /* Set Region Label Format identification UUID */ + uuid_parse(CXL_REGION_UUID, (uuid_t *) region_label->type); + + /* Set Current Region Label UUID */ + export_uuid(region_label->uuid, &nd_set->uuid); + + region_label->flags =3D __cpu_to_le32(flags); + region_label->nlabel =3D __cpu_to_le16(nd_region->ndr_mappings); + region_label->position =3D __cpu_to_le16(pos); + region_label->dpa =3D __cpu_to_le64(nd_mapping->start); + region_label->rawsize =3D __cpu_to_le64(nd_mapping->size); + region_label->hpa =3D __cpu_to_le64(nd_set->res->start); + region_label->slot =3D __cpu_to_le32(slot); + region_label->ig =3D __cpu_to_le32(nd_set->interleave_granularity); + region_label->align =3D __cpu_to_le32(0); + + /* Update fletcher64 Checksum */ + region_label_calculate_checksum(ndd, region_label); +} + +static bool is_label_reapable(struct nd_interleave_set *nd_set, + struct nd_namespace_pmem *nspm, + struct nvdimm_drvdata *ndd, + union nd_lsa_label *label, + enum label_type ltype, + unsigned long *flags) +{ + switch (ltype) { + case NS_LABEL_TYPE: + if (test_and_clear_bit(ND_LABEL_REAP, flags) || + nsl_uuid_equal(ndd, &label->ns_label, nspm->uuid)) + return true; + + break; + case RG_LABEL_TYPE: + if (region_label_uuid_equal(&label->region_label, + &nd_set->uuid)) + return true; + + break; + } + + return false; +} + +static int __pmem_label_update(struct nd_region *nd_region, + struct nd_mapping *nd_mapping, + struct nd_namespace_pmem *nspm, + int pos, unsigned long flags, + enum label_type ltype) +{ + struct nd_interleave_set *nd_set =3D nd_region->nd_set; + struct nvdimm_drvdata *ndd =3D to_ndd(nd_mapping); + struct nd_namespace_index *nsindex; + struct nd_label_ent *label_ent; + union nd_lsa_label *lsa_label; + unsigned long *free; + struct device *dev; + u32 nslot, slot; + size_t offset; + int rc; + + if (!preamble_next(ndd, &nsindex, &free, &nslot)) + return -ENXIO; + /* allocate and write the label to the staging (next) index */ slot =3D nd_label_alloc_slot(ndd); if (slot =3D=3D UINT_MAX) return -ENXIO; dev_dbg(ndd->dev, "allocated: %d\n", slot); =20 - nd_label =3D to_label(ndd, slot); - memset(nd_label, 0, sizeof_namespace_label(ndd)); - nsl_set_type(ndd, nd_label); - nsl_set_uuid(ndd, nd_label, nspm->uuid); - nsl_set_name(ndd, nd_label, nspm->alt_name); - nsl_set_flags(ndd, nd_label, flags); - nsl_set_nlabel(ndd, nd_label, nd_region->ndr_mappings); - nsl_set_nrange(ndd, nd_label, 1); - nsl_set_position(ndd, nd_label, pos); - nsl_set_isetcookie(ndd, nd_label, cookie); - nsl_set_rawsize(ndd, nd_label, resource_size(res)); - nsl_set_lbasize(ndd, nd_label, nspm->lbasize); - nsl_set_dpa(ndd, nd_label, res->start); - nsl_set_slot(ndd, nd_label, slot); - nsl_set_alignment(ndd, nd_label, 0); - nsl_set_type_guid(ndd, nd_label, &nd_set->type_guid); - nsl_set_region_uuid(ndd, nd_label, NULL); - nsl_set_claim_class(ndd, nd_label, ndns->claim_class); - nsl_calculate_checksum(ndd, nd_label); - nd_dbg_dpa(nd_region, ndd, res, "\n"); + lsa_label =3D (union nd_lsa_label *) to_label(ndd, slot); + memset(lsa_label, 0, sizeof_namespace_label(ndd)); + + switch (ltype) { + case NS_LABEL_TYPE: + dev =3D &nspm->nsio.common.dev; + rc =3D namespace_label_update(nd_region, nd_mapping, + nspm, pos, flags, &lsa_label->ns_label, + nsindex, slot); + if (rc) + return rc; + + break; + case RG_LABEL_TYPE: + dev =3D &nd_region->dev; + region_label_update(nd_region, &lsa_label->region_label, + nd_mapping, pos, flags, slot); + + break; + } =20 /* update label */ - offset =3D nd_label_offset(ndd, nd_label); - rc =3D nvdimm_set_config_data(ndd, offset, nd_label, + offset =3D nd_label_offset(ndd, &lsa_label->ns_label); + rc =3D nvdimm_set_config_data(ndd, offset, lsa_label, sizeof_namespace_label(ndd)); if (rc < 0) return rc; @@ -955,8 +1054,10 @@ static int __pmem_label_update(struct nd_region *nd_r= egion, list_for_each_entry(label_ent, &nd_mapping->labels, list) { if (!label_ent->label) continue; - if (test_and_clear_bit(ND_LABEL_REAP, &label_ent->flags) || - nsl_uuid_equal(ndd, label_ent->label, nspm->uuid)) + + if (is_label_reapable(nd_set, nspm, ndd, + (union nd_lsa_label *) label_ent->label, + ltype, &label_ent->flags)) reap_victim(nd_mapping, label_ent); } =20 @@ -966,19 +1067,20 @@ static int __pmem_label_update(struct nd_region *nd_= region, if (rc) return rc; =20 - list_for_each_entry(label_ent, &nd_mapping->labels, list) - if (!label_ent->label) { - label_ent->label =3D nd_label; - nd_label =3D NULL; - break; - } - dev_WARN_ONCE(&nspm->nsio.common.dev, nd_label, - "failed to track label: %d\n", - to_slot(ndd, nd_label)); - if (nd_label) - rc =3D -ENXIO; + list_for_each_entry(label_ent, &nd_mapping->labels, list) { + if (label_ent->label) + continue; =20 - return rc; + label_ent->label =3D &lsa_label->ns_label; + lsa_label =3D NULL; + break; + } + dev_WARN_ONCE(dev, lsa_label, "failed to track label: %d\n", + to_slot(ndd, &lsa_label->ns_label)); + if (lsa_label) + return -ENXIO; + + return 0; } =20 static int init_labels(struct nd_mapping *nd_mapping, int num_labels) @@ -1068,6 +1170,21 @@ static int del_labels(struct nd_mapping *nd_mapping,= uuid_t *uuid) nd_inc_seq(__le32_to_cpu(nsindex->seq)), 0); } =20 +static int find_region_label_count(struct nvdimm_drvdata *ndd, + struct nd_mapping *nd_mapping) +{ + struct nd_label_ent *label_ent; + int region_label_cnt =3D 0; + + guard(mutex)(&nd_mapping->lock); + list_for_each_entry(label_ent, &nd_mapping->labels, list) + if (is_region_label(ndd, + (union nd_lsa_label *) label_ent->label)) + region_label_cnt++; + + return region_label_cnt; +} + int nd_pmem_namespace_label_update(struct nd_region *nd_region, struct nd_namespace_pmem *nspm, resource_size_t size) { @@ -1076,6 +1193,7 @@ int nd_pmem_namespace_label_update(struct nd_region *= nd_region, for (i =3D 0; i < nd_region->ndr_mappings; i++) { struct nd_mapping *nd_mapping =3D &nd_region->mapping[i]; struct nvdimm_drvdata *ndd =3D to_ndd(nd_mapping); + int region_label_cnt =3D 0; struct resource *res; int count =3D 0; =20 @@ -1091,12 +1209,19 @@ int nd_pmem_namespace_label_update(struct nd_region= *nd_region, count++; WARN_ON_ONCE(!count); =20 - rc =3D init_labels(nd_mapping, count); + region_label_cnt =3D find_region_label_count(ndd, nd_mapping); + /* + * init_labels() scan labels and allocate new label based + * on its second parameter (num_labels). Therefore to + * allocate new namespace label also include previously + * added region label + */ + rc =3D init_labels(nd_mapping, count + region_label_cnt); if (rc < 0) return rc; =20 rc =3D __pmem_label_update(nd_region, nd_mapping, nspm, i, - NSLABEL_FLAG_UPDATING); + NSLABEL_FLAG_UPDATING, NS_LABEL_TYPE); if (rc) return rc; } @@ -1108,7 +1233,47 @@ int nd_pmem_namespace_label_update(struct nd_region = *nd_region, for (i =3D 0; i < nd_region->ndr_mappings; i++) { struct nd_mapping *nd_mapping =3D &nd_region->mapping[i]; =20 - rc =3D __pmem_label_update(nd_region, nd_mapping, nspm, i, 0); + rc =3D __pmem_label_update(nd_region, nd_mapping, nspm, i, 0, + NS_LABEL_TYPE); + if (rc) + return rc; + } + + return 0; +} + +int nd_pmem_region_label_update(struct nd_region *nd_region) +{ + int i, rc; + + for (i =3D 0; i < nd_region->ndr_mappings; i++) { + struct nd_mapping *nd_mapping =3D &nd_region->mapping[i]; + struct nvdimm_drvdata *ndd =3D to_ndd(nd_mapping); + int region_label_cnt =3D 0; + + /* No need to update region label for non cxl format */ + if (!ndd->cxl) + return 0; + + region_label_cnt =3D find_region_label_count(ndd, nd_mapping); + rc =3D init_labels(nd_mapping, region_label_cnt + 1); + if (rc < 0) + return rc; + + rc =3D __pmem_label_update(nd_region, nd_mapping, NULL, i, + NSLABEL_FLAG_UPDATING, RG_LABEL_TYPE); + if (rc) + return rc; + } + + /* Clear the UPDATING flag per UEFI 2.7 expectations */ + for (i =3D 0; i < nd_region->ndr_mappings; i++) { + struct nd_mapping *nd_mapping =3D &nd_region->mapping[i]; + struct nvdimm_drvdata *ndd =3D to_ndd(nd_mapping); + + WARN_ON_ONCE(!ndd->cxl); + rc =3D __pmem_label_update(nd_region, nd_mapping, NULL, i, 0, + RG_LABEL_TYPE); if (rc) return rc; } diff --git a/drivers/nvdimm/label.h b/drivers/nvdimm/label.h index 0650fb4b9821..284e2a763b49 100644 --- a/drivers/nvdimm/label.h +++ b/drivers/nvdimm/label.h @@ -30,6 +30,11 @@ enum { ND_NSINDEX_INIT =3D 0x1, }; =20 +enum label_type { + RG_LABEL_TYPE, + NS_LABEL_TYPE, +}; + /** * struct nd_namespace_index - label set superblock * @sig: NAMESPACE_INDEX\0 @@ -183,6 +188,15 @@ struct nd_namespace_label { }; }; =20 +/* + * LSA 2.1 format introduces region label, which can also reside + * into LSA along with only namespace label as per v1.1 and v1.2 + */ +union nd_lsa_label { + struct nd_namespace_label ns_label; + struct cxl_region_label region_label; +}; + #define NVDIMM_BTT_GUID "8aed63a2-29a2-4c66-8b12-f05d15d3922a" #define NVDIMM_BTT2_GUID "18633bfc-1735-4217-8ac9-17239282d3f8" #define NVDIMM_PFN_GUID "266400ba-fb9f-4677-bcb0-968f11d0d225" @@ -223,4 +237,5 @@ struct nd_region; struct nd_namespace_pmem; int nd_pmem_namespace_label_update(struct nd_region *nd_region, struct nd_namespace_pmem *nspm, resource_size_t size); +int nd_pmem_region_label_update(struct nd_region *nd_region); #endif /* __LABEL_H__ */ diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_dev= s.c index 3271b1c8569a..559f822ef24f 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -232,6 +232,18 @@ static ssize_t __alt_name_store(struct device *dev, co= nst char *buf, return rc; } =20 +int nd_region_label_update(struct nd_region *nd_region) +{ + int rc; + + nvdimm_bus_lock(&nd_region->dev); + rc =3D nd_pmem_region_label_update(nd_region); + nvdimm_bus_unlock(&nd_region->dev); + + return rc; +} +EXPORT_SYMBOL_GPL(nd_region_label_update); + static int nd_namespace_label_update(struct nd_region *nd_region, struct device *dev) { diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h index e362611d82cc..f04c042dcfa9 100644 --- a/drivers/nvdimm/nd.h +++ b/drivers/nvdimm/nd.h @@ -318,6 +318,39 @@ static inline void nsl_set_region_uuid(struct nvdimm_d= rvdata *ndd, export_uuid(ns_label->cxl.region_uuid, uuid); } =20 +static inline bool is_region_label(struct nvdimm_drvdata *ndd, + union nd_lsa_label *nd_label) +{ + uuid_t region_type, *ns_type; + + if (!ndd->cxl || !nd_label) + return false; + + uuid_parse(CXL_REGION_UUID, ®ion_type); + ns_type =3D (uuid_t *) nd_label->ns_label.cxl.type; + return uuid_equal(®ion_type, ns_type); +} + +static inline bool +region_label_uuid_equal(struct cxl_region_label *region_label, + const uuid_t *uuid) +{ + return uuid_equal((uuid_t *) region_label->uuid, uuid); +} + +static inline u64 +region_label_get_checksum(struct cxl_region_label *region_label) +{ + return __le64_to_cpu(region_label->checksum); +} + +static inline void +region_label_set_checksum(struct cxl_region_label *region_label, + u64 checksum) +{ + region_label->checksum =3D __cpu_to_le64(checksum); +} + bool nsl_validate_type_guid(struct nvdimm_drvdata *ndd, struct nd_namespace_label *nd_label, guid_t *guid); enum nvdimm_claim_class nsl_get_claim_class(struct nvdimm_drvdata *ndd, @@ -399,7 +432,10 @@ enum nd_label_flags { struct nd_label_ent { struct list_head list; unsigned long flags; - struct nd_namespace_label *label; + union { + struct nd_namespace_label *label; + struct cxl_region_label *region_label; + }; }; =20 enum nd_mapping_lock_class { diff --git a/include/linux/libnvdimm.h b/include/linux/libnvdimm.h index 5696715c33bb..2c213b9dac66 100644 --- a/include/linux/libnvdimm.h +++ b/include/linux/libnvdimm.h @@ -117,6 +117,13 @@ struct nd_interleave_set { u64 altcookie; =20 guid_t type_guid; + + /* v2.1 region label info */ + uuid_t uuid; + int interleave_ways; + int interleave_granularity; + struct resource *res; + int nr_targets; }; =20 struct nd_mapping_desc { @@ -307,6 +314,7 @@ int nvdimm_has_flush(struct nd_region *nd_region); int nvdimm_has_cache(struct nd_region *nd_region); int nvdimm_in_overwrite(struct nvdimm *nvdimm); bool is_nvdimm_sync(struct nd_region *nd_region); +int nd_region_label_update(struct nd_region *nd_region); =20 static inline int nvdimm_ctl(struct nvdimm *nvdimm, unsigned int cmd, void= *buf, unsigned int buf_len, int *cmd_rc) --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) (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 20B89330D5E for ; Wed, 17 Sep 2025 13:41:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.25 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116508; cv=none; b=sBXYkRSQ4Rr9fjevFh59Qnbg17tyONZIoDa0XZdOogXWAmqvaajFBTgdYh7KgJHSwEx8/P/3pSbQJ7lmMg1p+fWXumAEEm543OfyjvySWDbItCNcRuoQR/dycFm6Klwy+iov/3WsxCBuWOOqvrj9q7XEwEAH1sxEjixnyXwDAfs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116508; c=relaxed/simple; bh=ObxFNjY3CDqZKiFtjzWuhPhDg4JW+Aar2f8yMQjHZoU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=OZ9qc3rvsJahELy4pFQEYrInALScuixwzaTK7HFWWjY9pIz/kLmY/iQ1QYYLhIpeM7ELfiLfOWeoG0beJkyhw92sN2x4JTCnhi1XX0riMdsCGHMv90W6QBbw4ZMQiyv+rz8gSFMVqnaIpG97HRZjz6yQvmrr3MCqMzRVNpm2cVw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=pJTYRhQp; arc=none smtp.client-ip=203.254.224.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="pJTYRhQp" Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20250917134144epoutp02cbc71effb307a8d78c1658e0e8128ac9~mFaVZVNkh1573115731epoutp02O for ; Wed, 17 Sep 2025 13:41:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20250917134144epoutp02cbc71effb307a8d78c1658e0e8128ac9~mFaVZVNkh1573115731epoutp02O DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116504; bh=UJ9hFCDX6oRFE5yO/OJ6tbFOtoiVij+t/C+pJ0pqnUk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pJTYRhQpNP+3GVB4KXwav19kjQ88rkiKfF7R1bJ+2BAexl6JfxfHV0/GqBpnfS8nd wjyEKNz1E2dl+haD5mBudyoYKCYMGVFTzTrCZ3BrBU7WNtItOTQWcC05J3MBU2pWKr 30//9mZlP9IY3n+7L3lG9p/WCdI21/sNLWFMS2r0= Received: from epsnrtp02.localdomain (unknown [182.195.42.154]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPS id 20250917134144epcas5p39965d3dd0da5249034d52607471ef6f6~mFaU-DBT30180401804epcas5p30; Wed, 17 Sep 2025 13:41:44 +0000 (GMT) Received: from epcas5p3.samsung.com (unknown [182.195.38.95]) by epsnrtp02.localdomain (Postfix) with ESMTP id 4cRg0l0TMhz2SSKX; Wed, 17 Sep 2025 13:41:43 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20250917134142epcas5p49d85873cf3ea5f3166c63381ab668fc7~mFaTm8opi2411624116epcas5p4c; Wed, 17 Sep 2025 13:41:42 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134141epsmtip27a4a7bd0a74dacbc35e662da756e84ea~mFaSTAfEd0911709117epsmtip2T; Wed, 17 Sep 2025 13:41:40 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 07/20] nvdimm/region_label: Add region label delete support Date: Wed, 17 Sep 2025 19:11:03 +0530 Message-Id: <20250917134116.1623730-8-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134142epcas5p49d85873cf3ea5f3166c63381ab668fc7 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134142epcas5p49d85873cf3ea5f3166c63381ab668fc7 References: <20250917134116.1623730-1-s.neeraj@samsung.com> Added LSA v2.1 format region label deletion routine. This function is used to delete region label from LSA Signed-off-by: Neeraj Kumar --- drivers/nvdimm/label.c | 79 ++++++++++++++++++++++++++++++--- drivers/nvdimm/label.h | 1 + drivers/nvdimm/namespace_devs.c | 12 +++++ drivers/nvdimm/nd.h | 6 +++ include/linux/libnvdimm.h | 1 + 5 files changed, 92 insertions(+), 7 deletions(-) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index 209c73f6b7e7..d33db96ba8ba 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -1126,11 +1126,13 @@ static int init_labels(struct nd_mapping *nd_mappin= g, int num_labels) return max(num_labels, old_num_labels); } =20 -static int del_labels(struct nd_mapping *nd_mapping, uuid_t *uuid) +static int del_labels(struct nd_mapping *nd_mapping, uuid_t *uuid, + enum label_type ltype) { struct nvdimm_drvdata *ndd =3D to_ndd(nd_mapping); struct nd_label_ent *label_ent, *e; struct nd_namespace_index *nsindex; + union nd_lsa_label *nd_label; unsigned long *free; LIST_HEAD(list); u32 nslot, slot; @@ -1145,15 +1147,28 @@ static int del_labels(struct nd_mapping *nd_mapping= , uuid_t *uuid) =20 guard(mutex)(&nd_mapping->lock); list_for_each_entry_safe(label_ent, e, &nd_mapping->labels, list) { - struct nd_namespace_label *nd_label =3D label_ent->label; + nd_label =3D (union nd_lsa_label *) label_ent->label; =20 if (!nd_label) continue; active++; - if (!nsl_uuid_equal(ndd, nd_label, uuid)) - continue; + + switch (ltype) { + case NS_LABEL_TYPE: + if (!nsl_uuid_equal(ndd, &nd_label->ns_label, uuid)) + continue; + + break; + case RG_LABEL_TYPE: + if (!region_label_uuid_equal(&nd_label->region_label, + uuid)) + continue; + + break; + } + active--; - slot =3D to_slot(ndd, nd_label); + slot =3D to_slot(ndd, &nd_label->ns_label); nd_label_free_slot(ndd, slot); dev_dbg(ndd->dev, "free: %d\n", slot); list_move_tail(&label_ent->list, &list); @@ -1161,7 +1176,7 @@ static int del_labels(struct nd_mapping *nd_mapping, = uuid_t *uuid) } list_splice_tail_init(&list, &nd_mapping->labels); =20 - if (active =3D=3D 0) { + if ((ltype =3D=3D NS_LABEL_TYPE) && (active =3D=3D 0)) { nd_mapping_free_labels(nd_mapping); dev_dbg(ndd->dev, "no more active labels\n"); } @@ -1198,7 +1213,8 @@ int nd_pmem_namespace_label_update(struct nd_region *= nd_region, int count =3D 0; =20 if (size =3D=3D 0) { - rc =3D del_labels(nd_mapping, nspm->uuid); + rc =3D del_labels(nd_mapping, nspm->uuid, + NS_LABEL_TYPE); if (rc) return rc; continue; @@ -1281,6 +1297,55 @@ int nd_pmem_region_label_update(struct nd_region *nd= _region) return 0; } =20 +int nd_pmem_region_label_delete(struct nd_region *nd_region) +{ + struct nd_interleave_set *nd_set =3D nd_region->nd_set; + struct nd_label_ent *label_ent; + int ns_region_cnt =3D 0; + int i, rc; + + for (i =3D 0; i < nd_region->ndr_mappings; i++) { + struct nd_mapping *nd_mapping =3D &nd_region->mapping[i]; + struct nvdimm_drvdata *ndd =3D to_ndd(nd_mapping); + + /* Find non cxl format supported ndr_mappings */ + if (!ndd->cxl) { + dev_info(&nd_region->dev, "Unsupported region label\n"); + return -EINVAL; + } + + /* Find if any NS label using this region */ + guard(mutex)(&nd_mapping->lock); + list_for_each_entry(label_ent, &nd_mapping->labels, list) { + if (!label_ent->label) + continue; + + /* + * Check if any available NS labels has same + * region_uuid in LSA + */ + if (nsl_region_uuid_equal(label_ent->label, + &nd_set->uuid)) + ns_region_cnt++; + } + } + + if (ns_region_cnt) { + dev_dbg(&nd_region->dev, "Region/Namespace label in use\n"); + return -EBUSY; + } + + for (i =3D 0; i < nd_region->ndr_mappings; i++) { + struct nd_mapping *nd_mapping =3D &nd_region->mapping[i]; + + rc =3D del_labels(nd_mapping, &nd_set->uuid, RG_LABEL_TYPE); + if (rc) + return rc; + } + + return 0; +} + int __init nd_label_init(void) { WARN_ON(guid_parse(NVDIMM_BTT_GUID, &nvdimm_btt_guid)); diff --git a/drivers/nvdimm/label.h b/drivers/nvdimm/label.h index 284e2a763b49..276dd822e142 100644 --- a/drivers/nvdimm/label.h +++ b/drivers/nvdimm/label.h @@ -238,4 +238,5 @@ struct nd_namespace_pmem; int nd_pmem_namespace_label_update(struct nd_region *nd_region, struct nd_namespace_pmem *nspm, resource_size_t size); int nd_pmem_region_label_update(struct nd_region *nd_region); +int nd_pmem_region_label_delete(struct nd_region *nd_region); #endif /* __LABEL_H__ */ diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_dev= s.c index 559f822ef24f..564a73b1da41 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -244,6 +244,18 @@ int nd_region_label_update(struct nd_region *nd_region) } EXPORT_SYMBOL_GPL(nd_region_label_update); =20 +int nd_region_label_delete(struct nd_region *nd_region) +{ + int rc; + + nvdimm_bus_lock(&nd_region->dev); + rc =3D nd_pmem_region_label_delete(nd_region); + nvdimm_bus_unlock(&nd_region->dev); + + return rc; +} +EXPORT_SYMBOL_GPL(nd_region_label_delete); + static int nd_namespace_label_update(struct nd_region *nd_region, struct device *dev) { diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h index f04c042dcfa9..046063ea08b6 100644 --- a/drivers/nvdimm/nd.h +++ b/drivers/nvdimm/nd.h @@ -331,6 +331,12 @@ static inline bool is_region_label(struct nvdimm_drvda= ta *ndd, return uuid_equal(®ion_type, ns_type); } =20 +static inline bool nsl_region_uuid_equal(struct nd_namespace_label *ns_lab= el, + const uuid_t *uuid) +{ + return uuid_equal((uuid_t *) ns_label->cxl.region_uuid, uuid); +} + static inline bool region_label_uuid_equal(struct cxl_region_label *region_label, const uuid_t *uuid) diff --git a/include/linux/libnvdimm.h b/include/linux/libnvdimm.h index 2c213b9dac66..bbf14a260c93 100644 --- a/include/linux/libnvdimm.h +++ b/include/linux/libnvdimm.h @@ -315,6 +315,7 @@ int nvdimm_has_cache(struct nd_region *nd_region); int nvdimm_in_overwrite(struct nvdimm *nvdimm); bool is_nvdimm_sync(struct nd_region *nd_region); int nd_region_label_update(struct nd_region *nd_region); +int nd_region_label_delete(struct nd_region *nd_region); =20 static inline int nvdimm_ctl(struct nvdimm *nvdimm, unsigned int cmd, void= *buf, unsigned int buf_len, int *cmd_rc) --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (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 25374330D58 for ; Wed, 17 Sep 2025 13:41:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.24 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116511; cv=none; b=uDhbjtVPW3HHp3Upwdv3n8kN5ZLstmuVtPcohALGLwZAsvGTsMN3PJDJrEp8FMnAh6cHLfBCvPtRp68XeUh88Hg/mc0asXbrKbBUwU6ikyBRnFDtF7dsRwfpwKm8evqojjpG/hTvrr+IhSTo/V4iGB/COk1TvaNj+WpI65gXCUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116511; c=relaxed/simple; bh=vHuAadVlS3FOglAGf+BTtp47I18dR2Liu7MyC/Wl1sk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=robfeyTIIChXYcxknd4BT3gR/O0O1KibGELFcwjPvkKZEHXpJ1WpLzoF/8ZQtAli0fQkV5mhttsQrmdAAh/gKbDCIsuUlj8pU8eafJ59pGXDP1Q/r+gjtgb/6/Nnb785ZnQOArcChEB+H15j0qtg7ZrfoXhTrZKuVaqK92Gs5ws= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=s/2U3K6s; arc=none smtp.client-ip=203.254.224.24 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="s/2U3K6s" Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20250917134147epoutp01fe75baed46f871351e5ac95c6f378c56~mFaX9lWS-2840728407epoutp01H for ; Wed, 17 Sep 2025 13:41:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20250917134147epoutp01fe75baed46f871351e5ac95c6f378c56~mFaX9lWS-2840728407epoutp01H DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116507; bh=EEuNV6QTBvuCr9tgJGSp5/94eDUJ6AJpAamfaAzmqdA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s/2U3K6siid4Fn6rISDPVml6jPlEBsmuXpK6912gJnuPZIzYNc2YzX0cNmo7f0p/a G/Ift52BaV9bg12VdNEr3CngKrwNt9puaIvvhhEODG3pzwuQFoY2/9cyQvHGlA4Lit xL72efsT+v2OZ6wUmMWkuPPC2QtUbjd6LBVG69pg= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20250917134146epcas5p2041885921056859cc482db8a63dca955~mFaXeI2zm1141811418epcas5p2L; Wed, 17 Sep 2025 13:41:46 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.87]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4cRg0n4bhtz6B9m6; Wed, 17 Sep 2025 13:41:45 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20250917134144epcas5p498fb4b005516fca56e68533ce017fba0~mFaVxGMat2679026790epcas5p4U; Wed, 17 Sep 2025 13:41:44 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134142epsmtip2c2cff03d8d4f3aed14eeab47426ba8cd~mFaT7qXR70862908629epsmtip2C; Wed, 17 Sep 2025 13:41:42 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar , Jonathan Cameron Subject: [PATCH V3 08/20] nvdimm/label: Include region label in slot validation Date: Wed, 17 Sep 2025 19:11:04 +0530 Message-Id: <20250917134116.1623730-9-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134144epcas5p498fb4b005516fca56e68533ce017fba0 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134144epcas5p498fb4b005516fca56e68533ce017fba0 References: <20250917134116.1623730-1-s.neeraj@samsung.com> Slot validation routine validates label slot by calculating label checksum. It was only validating namespace label. This changeset also validates region label if present. Signed-off-by: Neeraj Kumar Reviewed-by: Jonathan Cameron --- drivers/nvdimm/label.c | 72 ++++++++++++++++++++++++++++++++---------- drivers/nvdimm/nd.h | 5 +++ 2 files changed, 60 insertions(+), 17 deletions(-) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index d33db96ba8ba..5e476154cf81 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -359,7 +359,7 @@ static bool nsl_validate_checksum(struct nvdimm_drvdata= *ndd, { u64 sum, sum_save; =20 - if (!ndd->cxl && !efi_namespace_label_has(ndd, checksum)) + if (!efi_namespace_label_has(ndd, checksum)) return true; =20 sum_save =3D nsl_get_checksum(ndd, nd_label); @@ -374,13 +374,25 @@ static void nsl_calculate_checksum(struct nvdimm_drvd= ata *ndd, { u64 sum; =20 - if (!ndd->cxl && !efi_namespace_label_has(ndd, checksum)) + if (!efi_namespace_label_has(ndd, checksum)) return; nsl_set_checksum(ndd, nd_label, 0); sum =3D nd_fletcher64(nd_label, sizeof_namespace_label(ndd), 1); nsl_set_checksum(ndd, nd_label, sum); } =20 +static bool region_label_validate_checksum(struct nvdimm_drvdata *ndd, + struct cxl_region_label *region_label) +{ + u64 sum, sum_save; + + sum_save =3D region_label_get_checksum(region_label); + region_label_set_checksum(region_label, 0); + sum =3D nd_fletcher64(region_label, sizeof_namespace_label(ndd), 1); + region_label_set_checksum(region_label, sum_save); + return sum =3D=3D sum_save; +} + static void region_label_calculate_checksum(struct nvdimm_drvdata *ndd, struct cxl_region_label *region_label) { @@ -392,16 +404,30 @@ static void region_label_calculate_checksum(struct nv= dimm_drvdata *ndd, } =20 static bool slot_valid(struct nvdimm_drvdata *ndd, - struct nd_namespace_label *nd_label, u32 slot) + union nd_lsa_label *lsa_label, u32 slot) { + struct cxl_region_label *region_label =3D &lsa_label->region_label; + struct nd_namespace_label *nd_label =3D &lsa_label->ns_label; + char *label_name; bool valid; =20 /* check that we are written where we expect to be written */ - if (slot !=3D nsl_get_slot(ndd, nd_label)) - return false; - valid =3D nsl_validate_checksum(ndd, nd_label); + if (is_region_label(ndd, lsa_label)) { + label_name =3D "rg"; + if (slot !=3D region_label_get_slot(region_label)) + return false; + valid =3D region_label_validate_checksum(ndd, region_label); + } else { + label_name =3D "ns"; + if (slot !=3D nsl_get_slot(ndd, nd_label)) + return false; + valid =3D nsl_validate_checksum(ndd, nd_label); + } + if (!valid) - dev_dbg(ndd->dev, "fail checksum. slot: %d\n", slot); + dev_dbg(ndd->dev, "%s label checksum fail. slot: %d\n", + label_name, slot); + return valid; } =20 @@ -424,7 +450,7 @@ int nd_label_reserve_dpa(struct nvdimm_drvdata *ndd) =20 nd_label =3D to_label(ndd, slot); =20 - if (!slot_valid(ndd, nd_label, slot)) + if (!slot_valid(ndd, (union nd_lsa_label *) nd_label, slot)) continue; =20 nsl_get_uuid(ndd, nd_label, &label_uuid); @@ -575,18 +601,30 @@ int nd_label_active_count(struct nvdimm_drvdata *ndd) return 0; =20 for_each_clear_bit_le(slot, free, nslot) { + struct cxl_region_label *region_label; struct nd_namespace_label *nd_label; - - nd_label =3D to_label(ndd, slot); - - if (!slot_valid(ndd, nd_label, slot)) { - u32 label_slot =3D nsl_get_slot(ndd, nd_label); - u64 size =3D nsl_get_rawsize(ndd, nd_label); - u64 dpa =3D nsl_get_dpa(ndd, nd_label); + union nd_lsa_label *lsa_label; + u32 lslot; + u64 size, dpa; + + lsa_label =3D (union nd_lsa_label *) to_label(ndd, slot); + nd_label =3D &lsa_label->ns_label; + region_label =3D &lsa_label->region_label; + + if (!slot_valid(ndd, lsa_label, slot)) { + if (is_region_label(ndd, lsa_label)) { + lslot =3D __le32_to_cpu(region_label->slot); + size =3D __le64_to_cpu(region_label->rawsize); + dpa =3D __le64_to_cpu(region_label->dpa); + } else { + lslot =3D nsl_get_slot(ndd, nd_label); + size =3D nsl_get_rawsize(ndd, nd_label); + dpa =3D nsl_get_dpa(ndd, nd_label); + } =20 dev_dbg(ndd->dev, "slot%d invalid slot: %d dpa: %llx size: %llx\n", - slot, label_slot, dpa, size); + slot, lslot, dpa, size); continue; } count++; @@ -607,7 +645,7 @@ struct nd_namespace_label *nd_label_active(struct nvdim= m_drvdata *ndd, int n) struct nd_namespace_label *nd_label; =20 nd_label =3D to_label(ndd, slot); - if (!slot_valid(ndd, nd_label, slot)) + if (!slot_valid(ndd, (union nd_lsa_label *) nd_label, slot)) continue; =20 if (n-- =3D=3D 0) diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h index 046063ea08b6..c985f91728dd 100644 --- a/drivers/nvdimm/nd.h +++ b/drivers/nvdimm/nd.h @@ -344,6 +344,11 @@ region_label_uuid_equal(struct cxl_region_label *regio= n_label, return uuid_equal((uuid_t *) region_label->uuid, uuid); } =20 +static inline u32 region_label_get_slot(struct cxl_region_label *region_la= bel) +{ + return __le32_to_cpu(region_label->slot); +} + static inline u64 region_label_get_checksum(struct cxl_region_label *region_label) { --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (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 229EB332A50 for ; Wed, 17 Sep 2025 13:41:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.24 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116514; cv=none; b=Km/xEB1DiySL/cVJOppaidriwk3kAPLbANXnmyaY8zY6AFy0Gqm3A1o7megvuoT++/ea+Dsa9KQALrsjD9IgPcBXQ3kFKyZDY1uZf9khYiGWJXTINi/UwtY0xYQrdHBxUIEYts8TAxiI7qIRgc5H/DskhIFX7CtMfi9oQ1/ShF4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116514; c=relaxed/simple; bh=RcHk8WZ2UuIHppAX6L+eQPaLFn6Vtz8ivz7q2719PHk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=OX8CICqAaVT/RleLrx3y5QF/8gqvCDBs67Mix1DSngon83SgSlJmfHP6U5ZjvL+63xTuhGOrSSPILOcu1rqDfxw3XI/U5iCHR/lFH7flF5kr4Kf6TrUgXsAgplfLwZW2YG+ivnB+yRjTIuWGPmPNJGF634tztWTKMqtP6SXkstQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=MyjYkBUs; arc=none smtp.client-ip=203.254.224.24 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="MyjYkBUs" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20250917134149epoutp010863a7f7b407d81c38ee23be7f428f44~mFaaAnW7T3165931659epoutp01I for ; Wed, 17 Sep 2025 13:41:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20250917134149epoutp010863a7f7b407d81c38ee23be7f428f44~mFaaAnW7T3165931659epoutp01I DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116509; bh=ifsQ5LfCM0vfQYRmAKPl7bTVrf062dIvEHubp+A3f7o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MyjYkBUsenyY8VcRmySXyWyF3nOCrXOxzkaYEuX3Scidh4zFV3flrOVpjcfD5dq7O U8SvF4+8MsuFVxl1MNpzy1Tu6OsIcu9WwKSIpjrNJQpnz/YTysAmZR22lvVjg+ozhl Qeylky+++cZYJA6I/qEI6hj6To7kVr9hgST1p02k= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPS id 20250917134148epcas5p132403067cee9e356d233ccae11a47c72~mFaY-CywK1744617446epcas5p1f; Wed, 17 Sep 2025 13:41:48 +0000 (GMT) Received: from epcas5p2.samsung.com (unknown [182.195.38.88]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4cRg0q2h11z6B9m4; Wed, 17 Sep 2025 13:41:47 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20250917134146epcas5p2a1f3eb1ece0c000eedd06c3201cb8132~mFaXnoKdr0912409124epcas5p2T; Wed, 17 Sep 2025 13:41:46 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134145epsmtip2d81b34392bfe8c03acd7631a83afc3be~mFaWM06bE0911709117epsmtip2U; Wed, 17 Sep 2025 13:41:44 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 09/20] nvdimm/namespace_label: Skip region label during ns label DPA reservation Date: Wed, 17 Sep 2025 19:11:05 +0530 Message-Id: <20250917134116.1623730-10-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134146epcas5p2a1f3eb1ece0c000eedd06c3201cb8132 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134146epcas5p2a1f3eb1ece0c000eedd06c3201cb8132 References: <20250917134116.1623730-1-s.neeraj@samsung.com> If Namespace label is present in LSA during nvdimm_probe() then DPA reservation is required. But this reservation is not required by region label. Therefore if LSA scanning finds any region label, skip it. Signed-off-by: Neeraj Kumar --- drivers/nvdimm/label.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index 5e476154cf81..935a0df5b47e 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -441,6 +441,7 @@ int nd_label_reserve_dpa(struct nvdimm_drvdata *ndd) return 0; /* no label, nothing to reserve */ =20 for_each_clear_bit_le(slot, free, nslot) { + union nd_lsa_label *lsa_label; struct nd_namespace_label *nd_label; struct nd_region *nd_region =3D NULL; struct nd_label_id label_id; @@ -448,9 +449,14 @@ int nd_label_reserve_dpa(struct nvdimm_drvdata *ndd) uuid_t label_uuid; u32 flags; =20 - nd_label =3D to_label(ndd, slot); + lsa_label =3D (union nd_lsa_label *) to_label(ndd, slot); + nd_label =3D &lsa_label->ns_label; =20 - if (!slot_valid(ndd, (union nd_lsa_label *) nd_label, slot)) + /* Skip region label. DPA reservation is for NS label only */ + if (is_region_label(ndd, lsa_label)) + continue; + + if (!slot_valid(ndd, lsa_label, slot)) continue; =20 nsl_get_uuid(ndd, nd_label, &label_uuid); --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (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 214CB333A97 for ; Wed, 17 Sep 2025 13:41:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116515; cv=none; b=NVyhSyTU1sTV/7LaCi8elAYlPWhssDhdhVDTDEXOq/+peDUtowWDD08jq2NCdguMdnbACDSEz9Q1NdJkdXys5J7jHD0m6nsvrV6KHI6bAOegVTpySpyP2/f6DmWY1x5wCugcm+XxY0yxPaRd3lM0wjV7OjLw7E59wsO+w8I+l5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116515; c=relaxed/simple; bh=dOUtKhv+1IrsvgPjYg1RhVFluP4pKZptnByxb9JFqYA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=lpC4GZWeZpFqWF6tNzQcBxp+ODjOf7eUZzqfhIsxNYssrKcii3LFbYgFWQJxV8DP0rltGTJ/PaGlznyfcIrCuFdvUukt9t3ejaAf898xfj+fA0LjV4Cwy669DPeov+pe3cQxaZ+Y02bdkAoLD8ghBkX+pv3P8LZ4qrVvPVm8RnE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=QTUJ3py3; arc=none smtp.client-ip=203.254.224.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="QTUJ3py3" Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20250917134151epoutp04093ade83c78c55a0e213c2e2bc3f9864~mFaby8znQ0413504135epoutp045 for ; Wed, 17 Sep 2025 13:41:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20250917134151epoutp04093ade83c78c55a0e213c2e2bc3f9864~mFaby8znQ0413504135epoutp045 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116511; bh=1JPrkmrI8goW5KEl6T+7MfqJMEk7a0KIJYoQ6H1XOC0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QTUJ3py3mkNKyLhp32mJXSg/ni4b3yHZ+UsIovjyT5BlgRZ8raMw0CzUQWbegloaj gxz/5jlq1ks9+tFs2MBioPNjRKzKE6SRNHxbcM919QOE6CWgJcS/QsEnISbIvE2JVf sPynBH3/OHZkdHSBdc223P+xBHWDWZ9o3pX720QQ= Received: from epsnrtp02.localdomain (unknown [182.195.42.154]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20250917134150epcas5p2a52b870fe40d7b8dc0178c5a4636088d~mFaatw9nt2257722577epcas5p29; Wed, 17 Sep 2025 13:41:50 +0000 (GMT) Received: from epcas5p1.samsung.com (unknown [182.195.38.93]) by epsnrtp02.localdomain (Postfix) with ESMTP id 4cRg0s1W6hz2SSKX; Wed, 17 Sep 2025 13:41:49 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20250917134148epcas5p1062c53d38d36040a3e65429543099f6d~mFaZb4YIG3219032190epcas5p1H; Wed, 17 Sep 2025 13:41:48 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134147epsmtip2469fb38d92cab39f0c31782114a3cbd5~mFaX2fAt40862908629epsmtip2D; Wed, 17 Sep 2025 13:41:46 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 10/20] nvdimm/namespace_label: Skip region label during namespace creation Date: Wed, 17 Sep 2025 19:11:06 +0530 Message-Id: <20250917134116.1623730-11-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134148epcas5p1062c53d38d36040a3e65429543099f6d X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134148epcas5p1062c53d38d36040a3e65429543099f6d References: <20250917134116.1623730-1-s.neeraj@samsung.com> During namespace creation, skip any region labels found. And Preserve region label into labels list if present. Signed-off-by: Neeraj Kumar --- drivers/nvdimm/namespace_devs.c | 52 +++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 5 deletions(-) diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_dev= s.c index 564a73b1da41..735310e6fc11 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -1979,6 +1979,10 @@ static struct device **scan_labels(struct nd_region = *nd_region) if (!nd_label) continue; =20 + /* Skip region labels if present */ + if (is_region_label(ndd, (union nd_lsa_label *) nd_label)) + continue; + /* skip labels that describe extents outside of the region */ if (nsl_get_dpa(ndd, nd_label) < nd_mapping->start || nsl_get_dpa(ndd, nd_label) > map_end) @@ -2017,9 +2021,31 @@ static struct device **scan_labels(struct nd_region = *nd_region) =20 if (count =3D=3D 0) { struct nd_namespace_pmem *nspm; + for (i =3D 0; i < nd_region->ndr_mappings; i++) { + union nd_lsa_label *nd_label; + struct nd_label_ent *le, *e; + LIST_HEAD(list); =20 - /* Publish a zero-sized namespace for userspace to configure. */ - nd_mapping_free_labels(nd_mapping); + nd_mapping =3D &nd_region->mapping[i]; + if (list_empty(&nd_mapping->labels)) + continue; + + list_for_each_entry_safe(le, e, &nd_mapping->labels, + list) { + nd_label =3D (union nd_lsa_label *) le->label; + + /* Preserve region labels if present */ + if (is_region_label(ndd, nd_label)) + list_move_tail(&le->list, &list); + } + + /* + * Publish a zero-sized namespace for userspace + * to configure. + */ + nd_mapping_free_labels(nd_mapping); + list_splice_init(&list, &nd_mapping->labels); + } nspm =3D kzalloc(sizeof(*nspm), GFP_KERNEL); if (!nspm) goto err; @@ -2031,7 +2057,8 @@ static struct device **scan_labels(struct nd_region *= nd_region) } else if (is_memory(&nd_region->dev)) { /* clean unselected labels */ for (i =3D 0; i < nd_region->ndr_mappings; i++) { - struct list_head *l, *e; + union nd_lsa_label *nd_label; + struct nd_label_ent *le, *e; LIST_HEAD(list); int j; =20 @@ -2042,10 +2069,25 @@ static struct device **scan_labels(struct nd_region= *nd_region) } =20 j =3D count; - list_for_each_safe(l, e, &nd_mapping->labels) { + list_for_each_entry_safe(le, e, &nd_mapping->labels, + list) { + nd_label =3D (union nd_lsa_label *) le->label; + + /* Preserve region labels */ + if (is_region_label(ndd, nd_label)) { + list_move_tail(&le->list, &list); + continue; + } + + /* + * Once preserving selected ns label done + * break out of loop + */ if (!j--) break; - list_move_tail(l, &list); + + /* Preserve selected ns label */ + list_move_tail(&le->list, &list); } nd_mapping_free_labels(nd_mapping); list_splice_init(&list, &nd_mapping->labels); --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) (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 061E9333ABA for ; Wed, 17 Sep 2025 13:41:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.25 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116517; cv=none; b=JZ9mE0Yu8eXJ60Mgr3y3p+EVCbI54kY97rUTJkm612iGW9U22TEzNY2nZVDCaoHhywFSYuHchYChh9pHFBOON4rxS9YnRA4NQt6oi3QUtC6rEMXzyyBz8HTvSJH2VYe6jnAVlxDtxpcXfnMEVpNIqE8tBVQmIiR+jzKiZxD1lwg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116517; c=relaxed/simple; bh=WBnAmooK9dbHr1obbST6yNo1GwSVNRQTXn1AF3hPqHo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=RVx+/LHrtlWwSRE5ic9dL1x1DDbWGnW3CcjISHWnp8csG7AtdE2y/TaKIk3u7u9qMESlDGI2W2urw8dWGhS8SDmiSHhs+eYdImB64I2HvoIFfvqAIViHSXMqStyMiIfx4E6sP86LLGISul/SplbFvoQb7e8wXmb1Y8ufn05zMx4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=kM/u0lGn; arc=none smtp.client-ip=203.254.224.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="kM/u0lGn" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20250917134153epoutp0278c49c4affbe6ef6990aa50d83c95417~mFadhmg-I1573715737epoutp02Q for ; Wed, 17 Sep 2025 13:41:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20250917134153epoutp0278c49c4affbe6ef6990aa50d83c95417~mFadhmg-I1573715737epoutp02Q DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116513; bh=jKNEAlEwR61MDjdL+446RjbQx5LOJGoeYbxBJtUMFuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kM/u0lGnQ94Kc1+T364iZabQ3BRwviHFqv/clhJ5RfBmz1J05j+GHnJ2cARirz1Wh EhaIYTDuPgEfxV261QHKlYHDEaO4Unv7ckjeqMdTZ2hzhknG7ekfXCfRVimYVy21yl L1QvijWuIu2QuoYloD3ujpSDdBOJ5WQ1qm4WOuOE= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPS id 20250917134152epcas5p15ebd60bdbcae9d6f4a9b786c50d08773~mFacyfTGW3219532195epcas5p1L; Wed, 17 Sep 2025 13:41:52 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.91]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4cRg0v32RTz6B9m4; Wed, 17 Sep 2025 13:41:51 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20250917134150epcas5p4d5cbd55f1ac51ac23736e855ff2725dc~mFabGQ7kc2411624116epcas5p4o; Wed, 17 Sep 2025 13:41:50 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134148epsmtip25ccf93854c8d9e0d18f4e6b37a0937e7~mFaZj5htj0833808338epsmtip2N; Wed, 17 Sep 2025 13:41:48 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 11/20] nvdimm/region_label: Preserve cxl region information from region label Date: Wed, 17 Sep 2025 19:11:07 +0530 Message-Id: <20250917134116.1623730-12-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134150epcas5p4d5cbd55f1ac51ac23736e855ff2725dc X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134150epcas5p4d5cbd55f1ac51ac23736e855ff2725dc References: <20250917134116.1623730-1-s.neeraj@samsung.com> Preserve region information from region label during nvdimm_probe. This preserved region information is used for creating cxl region to achieve region persistency across reboot. Signed-off-by: Neeraj Kumar --- drivers/nvdimm/dimm.c | 4 ++++ drivers/nvdimm/label.c | 41 +++++++++++++++++++++++++++++++++++++++ drivers/nvdimm/nd-core.h | 2 ++ drivers/nvdimm/nd.h | 1 + include/linux/libnvdimm.h | 14 +++++++++++++ 5 files changed, 62 insertions(+) diff --git a/drivers/nvdimm/dimm.c b/drivers/nvdimm/dimm.c index bda22cb94e5b..30fc90591093 100644 --- a/drivers/nvdimm/dimm.c +++ b/drivers/nvdimm/dimm.c @@ -107,6 +107,10 @@ static int nvdimm_probe(struct device *dev) if (rc) goto err; =20 + /* Preserve cxl region info if available */ + if (ndd->cxl) + nvdimm_cxl_region_preserve(ndd); + return 0; =20 err: diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index 935a0df5b47e..3250e3ecd973 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -473,6 +473,47 @@ int nd_label_reserve_dpa(struct nvdimm_drvdata *ndd) return 0; } =20 +int nvdimm_cxl_region_preserve(struct nvdimm_drvdata *ndd) +{ + struct nvdimm *nvdimm =3D to_nvdimm(ndd->dev); + struct cxl_pmem_region_params *p =3D &nvdimm->cxl_region_params; + struct nd_namespace_index *nsindex; + unsigned long *free; + u32 nslot, slot; + + if (!preamble_current(ndd, &nsindex, &free, &nslot)) + return 0; /* no label, nothing to preserve */ + + for_each_clear_bit_le(slot, free, nslot) { + union nd_lsa_label *nd_label; + struct cxl_region_label *region_label; + uuid_t rg_type, region_type; + + nd_label =3D (union nd_lsa_label *) to_label(ndd, slot); + region_label =3D &nd_label->region_label; + uuid_parse(CXL_REGION_UUID, ®ion_type); + import_uuid(&rg_type, nd_label->region_label.type); + + /* TODO: Currently preserving only one region */ + if (uuid_equal(®ion_type, &rg_type)) { + nvdimm->is_region_label =3D true; + import_uuid(&p->uuid, region_label->uuid); + p->flags =3D __le32_to_cpu(region_label->flags); + p->nlabel =3D __le16_to_cpu(region_label->nlabel); + p->position =3D __le16_to_cpu(region_label->position); + p->dpa =3D __le64_to_cpu(region_label->dpa); + p->rawsize =3D __le64_to_cpu(region_label->rawsize); + p->hpa =3D __le64_to_cpu(region_label->hpa); + p->slot =3D __le32_to_cpu(region_label->slot); + p->ig =3D __le32_to_cpu(region_label->ig); + p->align =3D __le32_to_cpu(region_label->align); + break; + } + } + + return 0; +} + int nd_label_data_init(struct nvdimm_drvdata *ndd) { size_t config_size, read_size, max_xfer, offset; diff --git a/drivers/nvdimm/nd-core.h b/drivers/nvdimm/nd-core.h index bfc6bfeb6e24..a73fac81531e 100644 --- a/drivers/nvdimm/nd-core.h +++ b/drivers/nvdimm/nd-core.h @@ -46,6 +46,8 @@ struct nvdimm { } sec; struct delayed_work dwork; const struct nvdimm_fw_ops *fw_ops; + bool is_region_label; + struct cxl_pmem_region_params cxl_region_params; }; =20 static inline unsigned long nvdimm_security_flags( diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h index c985f91728dd..2d0f6dd64c52 100644 --- a/drivers/nvdimm/nd.h +++ b/drivers/nvdimm/nd.h @@ -593,6 +593,7 @@ void nvdimm_set_locked(struct device *dev); void nvdimm_clear_locked(struct device *dev); int nvdimm_security_setup_events(struct device *dev); bool nvdimm_check_region_label_format(struct device *dev); +int nvdimm_cxl_region_preserve(struct nvdimm_drvdata *ndd); #if IS_ENABLED(CONFIG_NVDIMM_KEYS) int nvdimm_security_unlock(struct device *dev); #else diff --git a/include/linux/libnvdimm.h b/include/linux/libnvdimm.h index bbf14a260c93..07ea2e3f821a 100644 --- a/include/linux/libnvdimm.h +++ b/include/linux/libnvdimm.h @@ -108,6 +108,20 @@ struct nd_cmd_desc { int out_sizes[ND_CMD_MAX_ELEM]; }; =20 +struct cxl_pmem_region_params { + uuid_t uuid; + u32 flags; + u16 nlabel; + u16 position; + u64 dpa; + u64 rawsize; + u64 hpa; + u32 slot; + u32 ig; + u32 align; + int nr_targets; +}; + struct nd_interleave_set { /* v1.1 definition of the interleave-set-cookie algorithm */ u64 cookie1; --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (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 E2E3533594D for ; Wed, 17 Sep 2025 13:41:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116519; cv=none; b=gkLK6N5vb4CWW6WBSKKMdY1FUKpXTK15t4lM8PqzkrZSoeTXO37782J5xVDEgJTOHgtC8DTNDeEACns7xo10IJBtbNX53PnWnUHzhb2Ly2lelfE5g+a1/i77R/9TjL2ooIZ6+BFao+V+cSxQ1jm5P0bN7TvUtGveg2s3jWuOeGA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116519; c=relaxed/simple; bh=aAT36OD6sazighOfpzQSmftqbC9DnJOQdrbUq9T0Bvk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=d2SgAJwWudkkwBGQvtDMpsLd4X9KCG65FxLp86fbQ21lJNCoxnxL/8JvfQYnvsLvuU1QPwBiuS0rStG0uBVAUXopr2f5F7fluJzTCu3LdRjE+GyafIM1biIxTf2j0/0YuFtoi0WALec1aSYgku3MuHsQhRxtBLJbssEqgnuubw0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=hsgJL7Gz; arc=none smtp.client-ip=203.254.224.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="hsgJL7Gz" Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20250917134155epoutp03aa0149d62a7291b63e0b3a8441f21398~mFafiX2y00946809468epoutp03F for ; Wed, 17 Sep 2025 13:41:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20250917134155epoutp03aa0149d62a7291b63e0b3a8441f21398~mFafiX2y00946809468epoutp03F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116515; bh=EvHiPrSCwDV9YFoLErNp7XwahEpYXRahMYHe/BeQwrI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hsgJL7Gz0dW0OSYplh1klVc5wB1LfJQMFRSZ6UgvRDAHvnR5VInploAo1/16d6QW7 6V2v+QoICh2Y40oWr7dMkHb53vUpg6RVytkI0pLb4QXfM9Z5iNl6bjk0P4tZLRgJZR uO4uktnFXShsES/jpem08drtRCbfoPpHJJAw1tY4= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20250917134154epcas5p20d3515258023be49296af30e22b27630~mFae6SDpf0912409124epcas5p2c; Wed, 17 Sep 2025 13:41:54 +0000 (GMT) Received: from epcas5p1.samsung.com (unknown [182.195.38.92]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4cRg0x52Qwz6B9m4; Wed, 17 Sep 2025 13:41:53 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20250917134153epcas5p1e1f7a7a19fb41d12b9397c3e6265f823~mFadm6i5E2209422094epcas5p1R; Wed, 17 Sep 2025 13:41:53 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134151epsmtip27d672a0b6f0f07066cde9dc3c3ba8a26~mFabrhxfP0833808338epsmtip2O; Wed, 17 Sep 2025 13:41:50 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 12/20] nvdimm/region_label: Export routine to fetch region information Date: Wed, 17 Sep 2025 19:11:08 +0530 Message-Id: <20250917134116.1623730-13-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134153epcas5p1e1f7a7a19fb41d12b9397c3e6265f823 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134153epcas5p1e1f7a7a19fb41d12b9397c3e6265f823 References: <20250917134116.1623730-1-s.neeraj@samsung.com> CXL region information preserved from the LSA needs to be exported for use by the CXL driver for CXL region re-creation. Signed-off-by: Neeraj Kumar --- drivers/nvdimm/dimm_devs.c | 18 ++++++++++++++++++ include/linux/libnvdimm.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/drivers/nvdimm/dimm_devs.c b/drivers/nvdimm/dimm_devs.c index 918c3db93195..619c8ce56dce 100644 --- a/drivers/nvdimm/dimm_devs.c +++ b/drivers/nvdimm/dimm_devs.c @@ -280,6 +280,24 @@ void *nvdimm_provider_data(struct nvdimm *nvdimm) } EXPORT_SYMBOL_GPL(nvdimm_provider_data); =20 +bool nvdimm_has_cxl_region(struct nvdimm *nvdimm) +{ + if (nvdimm) + return nvdimm->is_region_label; + + return false; +} +EXPORT_SYMBOL_GPL(nvdimm_has_cxl_region); + +void *nvdimm_get_cxl_region_param(struct nvdimm *nvdimm) +{ + if (nvdimm) + return &nvdimm->cxl_region_params; + + return NULL; +} +EXPORT_SYMBOL_GPL(nvdimm_get_cxl_region_param); + static ssize_t commands_show(struct device *dev, struct device_attribute *attr, char *buf) { diff --git a/include/linux/libnvdimm.h b/include/linux/libnvdimm.h index 07ea2e3f821a..3ffd50ab6ac4 100644 --- a/include/linux/libnvdimm.h +++ b/include/linux/libnvdimm.h @@ -330,6 +330,8 @@ int nvdimm_in_overwrite(struct nvdimm *nvdimm); bool is_nvdimm_sync(struct nd_region *nd_region); int nd_region_label_update(struct nd_region *nd_region); int nd_region_label_delete(struct nd_region *nd_region); +bool nvdimm_has_cxl_region(struct nvdimm *nvdimm); +void *nvdimm_get_cxl_region_param(struct nvdimm *nvdimm); =20 static inline int nvdimm_ctl(struct nvdimm *nvdimm, unsigned int cmd, void= *buf, unsigned int buf_len, int *cmd_rc) --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (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 D9E8633AE91 for ; Wed, 17 Sep 2025 13:42:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.24 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116522; cv=none; b=OfKhEyl63MTmvqYcqLhR0FNOF59i6Nb6UJlalzSdq4KdX5fqa1FzhKn5ZJzNf6RYQLW/2D9JukbOkjxt/80rcOq7BWAjmewcO4pk5S1B59Ynjcbznro/CyqmqBO7S9XukDpIy+r0jHI0ASnqdbRzkuLNoPBhVO5jm9TfuSakHlo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116522; c=relaxed/simple; bh=sc2EE0+QmIXZUojuXWuZnjKPlj10YMGnzKhst0JuMJI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=k+IHK9JLjb5+aZ5LhZHXW77tZ+8IxlrMSJ7wVzIHmsP7fOEfxYXR4NdqFuf4jFjanqBNz+z4rxVkkpsNPtnt7U/7+wx7fZ+/VTUG3y2yfh0jcAHhSO+6D/3mIZZ3RyP/KDWghNT5eCOiTxEsSS+36MRrVDaeKk2k7pcpkk6Hnhc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=Ls7IsCUC; arc=none smtp.client-ip=203.254.224.24 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="Ls7IsCUC" Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20250917134159epoutp01d5963820266b7274371c1e12865e1573~mFajMfxxH3165931659epoutp01O for ; Wed, 17 Sep 2025 13:41:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20250917134159epoutp01d5963820266b7274371c1e12865e1573~mFajMfxxH3165931659epoutp01O DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116519; bh=Tzf++Z8J1+T9kRGY8CZ5Q8sYrCDb44hcVDm2fad7IJs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ls7IsCUCxCKgLKZ6kd6Wlo7gQZp6dIKdpQdF+VaD/GQ7XoQN9A5QSral3Ruyqb0Ii 8neNgoOYNR0weCphsqQBHzI/EGDFGqBIEOtqHNus0ATwO+ENNfQl/faG0JDhImLE2S Ti8kojvD7xsIxwIX3/ZHXb+ppb6zVP0JLg5//qNE= Received: from epsnrtp03.localdomain (unknown [182.195.42.155]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPS id 20250917134158epcas5p1dfdd9e3ed8b4c8f0333d187410752668~mFai7YbI81745017450epcas5p1t; Wed, 17 Sep 2025 13:41:58 +0000 (GMT) Received: from epcas5p2.samsung.com (unknown [182.195.38.90]) by epsnrtp03.localdomain (Postfix) with ESMTP id 4cRg12056zz3hhT7; Wed, 17 Sep 2025 13:41:58 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20250917134157epcas5p1b30306bc8596b7b50548ddf3683c3b97~mFahKzsrt1745017450epcas5p1s; Wed, 17 Sep 2025 13:41:57 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134153epsmtip28edea1ecdda435c600db431d7eb17abd~mFaeLhxXC0833808338epsmtip2P; Wed, 17 Sep 2025 13:41:53 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 13/20] cxl/mem: Refactor cxl pmem region auto-assembling Date: Wed, 17 Sep 2025 19:11:09 +0530 Message-Id: <20250917134116.1623730-14-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134157epcas5p1b30306bc8596b7b50548ddf3683c3b97 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134157epcas5p1b30306bc8596b7b50548ddf3683c3b97 References: <20250917134116.1623730-1-s.neeraj@samsung.com> In 84ec985944ef3, devm_cxl_add_nvdimm() sequence was changed and called before devm_cxl_add_endpoint(). It's because cxl pmem region auto-assembly used to get called at last in cxl_endpoint_port_probe(), which requires cxl_nvd presence. For cxl region persistency, region creation happens during nvdimm_probe which need the completion of endpoint probe. In order to accommodate both cxl pmem region auto-assembly and cxl region persistency, refactored following 1. Re-Sequence devm_cxl_add_nvdimm() after devm_cxl_add_endpoint(). This will be called only after successful completion of endpoint probe. 2. Moved cxl pmem region auto-assembly from cxl_endpoint_port_probe() to cxl_mem_probe() after devm_cxl_add_nvdimm(). It gurantees both the completion of endpoint probe and cxl_nvd presence before its call. Signed-off-by: Neeraj Kumar --- drivers/cxl/core/region.c | 33 +++++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 4 ++++ drivers/cxl/mem.c | 24 +++++++++++++++--------- drivers/cxl/port.c | 39 +-------------------------------------- 4 files changed, 53 insertions(+), 47 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 7a0cead24490..c325aa827992 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3606,6 +3606,39 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *c= xled) } EXPORT_SYMBOL_NS_GPL(cxl_add_to_region, "CXL"); =20 +static int discover_region(struct device *dev, void *unused) +{ + struct cxl_endpoint_decoder *cxled; + int rc; + + if (!is_endpoint_decoder(dev)) + return 0; + + cxled =3D to_cxl_endpoint_decoder(dev); + if ((cxled->cxld.flags & CXL_DECODER_F_ENABLE) =3D=3D 0) + return 0; + + if (cxled->state !=3D CXL_DECODER_STATE_AUTO) + return 0; + + /* + * Region enumeration is opportunistic, if this add-event fails, + * continue to the next endpoint decoder. + */ + rc =3D cxl_add_to_region(cxled); + if (rc) + dev_dbg(dev, "failed to add to region: %#llx-%#llx\n", + cxled->cxld.hpa_range.start, cxled->cxld.hpa_range.end); + + return 0; +} + +void cxl_region_discovery(struct cxl_port *port) +{ + device_for_each_child(&port->dev, NULL, discover_region); +} +EXPORT_SYMBOL_NS_GPL(cxl_region_discovery, "CXL"); + u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, u64 spa) { struct cxl_region_ref *iter; diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 4fe3df06f57a..b57597e55f7e 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -873,6 +873,7 @@ struct cxl_pmem_region *to_cxl_pmem_region(struct devic= e *dev); int cxl_add_to_region(struct cxl_endpoint_decoder *cxled); struct cxl_dax_region *to_cxl_dax_region(struct device *dev); u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, u64 spa); +void cxl_region_discovery(struct cxl_port *port); #else static inline bool is_cxl_pmem_region(struct device *dev) { @@ -895,6 +896,9 @@ static inline u64 cxl_port_get_spa_cache_alias(struct c= xl_port *endpoint, { return 0; } +static inline void cxl_region_discovery(struct cxl_port *port) +{ +} #endif =20 void cxl_endpoint_parse_cdat(struct cxl_port *port); diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c index 6e6777b7bafb..54501616ff09 100644 --- a/drivers/cxl/mem.c +++ b/drivers/cxl/mem.c @@ -152,15 +152,6 @@ static int cxl_mem_probe(struct device *dev) return -ENXIO; } =20 - if (cxl_pmem_size(cxlds) && IS_ENABLED(CONFIG_CXL_PMEM)) { - rc =3D devm_cxl_add_nvdimm(parent_port, cxlmd); - if (rc) { - if (rc =3D=3D -ENODEV) - dev_info(dev, "PMEM disabled by platform\n"); - return rc; - } - } - if (dport->rch) endpoint_parent =3D parent_port->uport_dev; else @@ -184,6 +175,21 @@ static int cxl_mem_probe(struct device *dev) if (rc) dev_dbg(dev, "CXL memdev EDAC registration failed rc=3D%d\n", rc); =20 + if (cxl_pmem_size(cxlds) && IS_ENABLED(CONFIG_CXL_PMEM)) { + rc =3D devm_cxl_add_nvdimm(parent_port, cxlmd); + if (rc) { + if (rc =3D=3D -ENODEV) + dev_info(dev, "PMEM disabled by platform\n"); + return rc; + } + } + + /* + * Now that all endpoint decoders are successfully enumerated, try to + * assemble region autodiscovery from committed decoders. + */ + cxl_region_discovery(cxlmd->endpoint); + /* * The kernel may be operating out of CXL memory on this device, * there is no spec defined way to determine whether this device diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c index cf32dc50b7a6..07bb909b7d2e 100644 --- a/drivers/cxl/port.c +++ b/drivers/cxl/port.c @@ -30,33 +30,6 @@ static void schedule_detach(void *cxlmd) schedule_cxl_memdev_detach(cxlmd); } =20 -static int discover_region(struct device *dev, void *unused) -{ - struct cxl_endpoint_decoder *cxled; - int rc; - - if (!is_endpoint_decoder(dev)) - return 0; - - cxled =3D to_cxl_endpoint_decoder(dev); - if ((cxled->cxld.flags & CXL_DECODER_F_ENABLE) =3D=3D 0) - return 0; - - if (cxled->state !=3D CXL_DECODER_STATE_AUTO) - return 0; - - /* - * Region enumeration is opportunistic, if this add-event fails, - * continue to the next endpoint decoder. - */ - rc =3D cxl_add_to_region(cxled); - if (rc) - dev_dbg(dev, "failed to add to region: %#llx-%#llx\n", - cxled->cxld.hpa_range.start, cxled->cxld.hpa_range.end); - - return 0; -} - static int cxl_switch_port_probe(struct cxl_port *port) { struct cxl_hdm *cxlhdm; @@ -121,17 +94,7 @@ static int cxl_endpoint_port_probe(struct cxl_port *por= t) if (rc) return rc; =20 - rc =3D devm_cxl_enumerate_decoders(cxlhdm, &info); - if (rc) - return rc; - - /* - * Now that all endpoint decoders are successfully enumerated, try to - * assemble regions from committed decoders - */ - device_for_each_child(&port->dev, NULL, discover_region); - - return 0; + return devm_cxl_enumerate_decoders(cxlhdm, &info); } =20 static int cxl_port_probe(struct device *dev) --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) (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 D26C333AEB6 for ; Wed, 17 Sep 2025 13:42:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.25 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116525; cv=none; b=s+dt/1TvBXT/x7wJ6hkidVbtYspaDY4hdhSame9iVaCgtp/Nqvl/XUC+NdZ/zj7tqy3C+mLlhtOfiDCzyQS6w6OnlRaSq/Tcoy7O2AgK9TifuWT5QXti+PSU+aB4r2XJSZLS431H1lMB6pell/WQQZgOxV22oNHWoCFr+6k93Po= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116525; c=relaxed/simple; bh=6wBoep2iJJ3gbOo/sNXpIeAC6OyR+6x9/eGgpld/Vds=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=S/vK14z6hg2aGHn9K1bn2HBOaKlQJEQmU7JNOQAGjMSWH098BUolld3PFiOaN+7++FSoCl4qBEuiFa6Z/KPHO9zVtCBI7Ms5tGx/54CxvK6utg1HPisiMGCCJvDREGMwNpEOmqE3xsEn78v8qlcnSJDJHJ5fV5uqopbETiBLRNg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=II7q4qSO; arc=none smtp.client-ip=203.254.224.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="II7q4qSO" Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20250917134202epoutp0233c5e529c8456a5f93989cb9caad9126~mFalwUmow1572615726epoutp02L for ; Wed, 17 Sep 2025 13:42:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20250917134202epoutp0233c5e529c8456a5f93989cb9caad9126~mFalwUmow1572615726epoutp02L DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116522; bh=ZcTfZKgynno2dRGhPfNpKZtAAtwys9IWfg2QaYJnRDc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=II7q4qSO+s+IYak0r9AOh79ZO1Xwsl1szbTw4dCL6Ah79/bK2U03IegwzS9qgUidA p4GIvUnF+tE6fqlj5OaOmUFdLlwM0aA+aoLaHcZ7CVcSkprfB7hX0m3gMediEr7oZF 9zW75khmAYcr7MkdnNIOzdLhlnBJkya0VVSor0/4= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPS id 20250917134201epcas5p35769cb951694b153333ad6e0dee7ce6c~mFalZGfen2642526425epcas5p3e; Wed, 17 Sep 2025 13:42:01 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.88]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4cRg144tmqz6B9m6; Wed, 17 Sep 2025 13:42:00 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20250917134159epcas5p37716c48d36c07aaffe70dafca2fa207b~mFaj2HfAX2692726927epcas5p3V; Wed, 17 Sep 2025 13:41:59 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134157epsmtip29938e9c7f2a4c8566aa2580e37d8f7db~mFahj8IOz0862908629epsmtip2N; Wed, 17 Sep 2025 13:41:57 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 14/20] cxl/region: Add devm_cxl_pmem_add_region() for pmem region creation Date: Wed, 17 Sep 2025 19:11:10 +0530 Message-Id: <20250917134116.1623730-15-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134159epcas5p37716c48d36c07aaffe70dafca2fa207b X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134159epcas5p37716c48d36c07aaffe70dafca2fa207b References: <20250917134116.1623730-1-s.neeraj@samsung.com> devm_cxl_pmem_add_region() is used to create cxl region based on region information scanned from LSA. devm_cxl_add_region() is used to just allocate cxlr and its fields are filled later by userspace tool using device attributes (*_store()). Inspiration for devm_cxl_pmem_add_region() is taken from these device attributes (_store*) calls. It allocates cxlr and fills information parsed from LSA and calls device_add(&cxlr->dev) to initiate further region creation porbes Renamed __create_region() to cxl_create_region() and make it an exported routine. This will be used in later patch to create cxl region after fetching region information from LSA. Signed-off-by: Neeraj Kumar --- drivers/cxl/core/region.c | 127 ++++++++++++++++++++++++++++++++++++-- drivers/cxl/cxl.h | 12 ++++ 2 files changed, 134 insertions(+), 5 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index c325aa827992..d5c227ce7b09 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2573,6 +2573,116 @@ static struct cxl_region *devm_cxl_add_region(struc= t cxl_root_decoder *cxlrd, return ERR_PTR(rc); } =20 +static ssize_t alloc_region_hpa(struct cxl_region *cxlr, u64 size) +{ + int rc; + + ACQUIRE(rwsem_write_kill, rwsem)(&cxl_rwsem.region); + rc =3D ACQUIRE_ERR(rwsem_write_kill, &rwsem); + if (rc) + return rc; + + if (!size) + return -EINVAL; + + return alloc_hpa(cxlr, size); +} + +static ssize_t alloc_region_dpa(struct cxl_endpoint_decoder *cxled, u64 si= ze) +{ + int rc; + + if (!size) + return -EINVAL; + + if (!IS_ALIGNED(size, SZ_256M)) + return -EINVAL; + + rc =3D cxl_dpa_free(cxled); + if (rc) + return rc; + + return cxl_dpa_alloc(cxled, size); +} + +static struct cxl_region * +devm_cxl_pmem_add_region(struct cxl_root_decoder *cxlrd, int id, + enum cxl_partition_mode mode, + enum cxl_decoder_type type, + struct cxl_pmem_region_params *params, + struct cxl_decoder *cxld) +{ + struct cxl_endpoint_decoder *cxled; + struct cxl_region_params *p; + struct cxl_port *root_port; + struct device *dev; + int rc; + + struct cxl_region *cxlr __free(put_cxl_region) =3D + cxl_region_alloc(cxlrd, id); + if (IS_ERR(cxlr)) + return cxlr; + + cxlr->mode =3D mode; + cxlr->type =3D type; + + dev =3D &cxlr->dev; + rc =3D dev_set_name(dev, "region%d", id); + if (rc) + return ERR_PTR(rc); + + p =3D &cxlr->params; + p->uuid =3D params->uuid; + p->interleave_ways =3D params->nlabel; + p->interleave_granularity =3D params->ig; + + rc =3D alloc_region_hpa(cxlr, params->rawsize); + if (rc) + return ERR_PTR(rc); + + cxled =3D to_cxl_endpoint_decoder(&cxld->dev); + + rc =3D cxl_dpa_set_part(cxled, CXL_PARTMODE_PMEM); + if (rc) + return ERR_PTR(rc); + + rc =3D alloc_region_dpa(cxled, params->rawsize); + if (rc) + return ERR_PTR(rc); + + /* + * TODO: Currently we have support of interleave_way =3D=3D 1, where + * we can only have one region per mem device. It means mem device + * position (params->position) will always be 0. It is therefore + * attaching only one target at params->position + */ + if (params->position) + return ERR_PTR(-EINVAL); + + rc =3D attach_target(cxlr, cxled, params->position, TASK_INTERRUPTIBLE); + if (rc) + return ERR_PTR(rc); + + rc =3D __commit(cxlr); + if (rc) + return ERR_PTR(rc); + + rc =3D device_add(dev); + if (rc) + return ERR_PTR(rc); + + root_port =3D to_cxl_port(cxlrd->cxlsd.cxld.dev.parent); + rc =3D devm_add_action_or_reset(root_port->uport_dev, + unregister_region, cxlr); + if (rc) + return ERR_PTR(rc); + + dev_dbg(root_port->uport_dev, "%s: created %s\n", + dev_name(&cxlrd->cxlsd.cxld.dev), dev_name(dev)); + + return no_free_ptr(cxlr); +} + static ssize_t __create_region_show(struct cxl_root_decoder *cxlrd, char *= buf) { return sysfs_emit(buf, "region%u\n", atomic_read(&cxlrd->region_id)); @@ -2590,8 +2700,10 @@ static ssize_t create_ram_region_show(struct device = *dev, return __create_region_show(to_cxl_root_decoder(dev), buf); } =20 -static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd, - enum cxl_partition_mode mode, int id) +struct cxl_region *cxl_create_region(struct cxl_root_decoder *cxlrd, + enum cxl_partition_mode mode, int id, + struct cxl_pmem_region_params *pmem_params, + struct cxl_decoder *cxld) { int rc; =20 @@ -2613,8 +2725,12 @@ static struct cxl_region *__create_region(struct cxl= _root_decoder *cxlrd, return ERR_PTR(-EBUSY); } =20 + if (pmem_params) + return devm_cxl_pmem_add_region(cxlrd, id, mode, + CXL_DECODER_HOSTONLYMEM, pmem_params, cxld); return devm_cxl_add_region(cxlrd, id, mode, CXL_DECODER_HOSTONLYMEM); } +EXPORT_SYMBOL_NS_GPL(cxl_create_region, "CXL"); =20 static ssize_t create_region_store(struct device *dev, const char *buf, size_t len, enum cxl_partition_mode mode) @@ -2627,7 +2743,7 @@ static ssize_t create_region_store(struct device *dev= , const char *buf, if (rc !=3D 1) return -EINVAL; =20 - cxlr =3D __create_region(cxlrd, mode, id); + cxlr =3D cxl_create_region(cxlrd, mode, id, NULL, NULL); if (IS_ERR(cxlr)) return PTR_ERR(cxlr); =20 @@ -3523,8 +3639,9 @@ static struct cxl_region *construct_region(struct cxl= _root_decoder *cxlrd, struct cxl_region *cxlr; =20 do { - cxlr =3D __create_region(cxlrd, cxlds->part[part].mode, - atomic_read(&cxlrd->region_id)); + cxlr =3D cxl_create_region(cxlrd, cxlds->part[part].mode, + atomic_read(&cxlrd->region_id), + NULL, NULL); } while (IS_ERR(cxlr) && PTR_ERR(cxlr) =3D=3D -EBUSY); =20 if (IS_ERR(cxlr)) { diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index b57597e55f7e..3abadc3dc82e 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -874,6 +874,10 @@ int cxl_add_to_region(struct cxl_endpoint_decoder *cxl= ed); struct cxl_dax_region *to_cxl_dax_region(struct device *dev); u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, u64 spa); void cxl_region_discovery(struct cxl_port *port); +struct cxl_region *cxl_create_region(struct cxl_root_decoder *cxlrd, + enum cxl_partition_mode mode, int id, + struct cxl_pmem_region_params *params, + struct cxl_decoder *cxld); #else static inline bool is_cxl_pmem_region(struct device *dev) { @@ -899,6 +903,14 @@ static inline u64 cxl_port_get_spa_cache_alias(struct = cxl_port *endpoint, static inline void cxl_region_discovery(struct cxl_port *port) { } +static inline struct cxl_region * +cxl_create_region(struct cxl_root_decoder *cxlrd, + enum cxl_partition_mode mode, int id, + struct cxl_pmem_region_params *params, + struct cxl_decoder *cxld) +{ + return ERR_PTR(-EOPNOTSUPP); +} #endif =20 void cxl_endpoint_parse_cdat(struct cxl_port *port); --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (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 0674F33B47C for ; Wed, 17 Sep 2025 13:42:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116527; cv=none; b=Y79JA52VLtLQ9O+JEaNnzcHtvv+C0q9A82BnUf7gjHF0II+YVY7bTtepr154UyZ5u44EPOQKfcOpTSA2qYzcHHzpvY31hF3SjyJRI2iolXfce9xK59weUfLvI5RApxzVELlAtGkhmJHOq6DPQQjShEygZWp/QYOsYBXWiJEa55M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116527; c=relaxed/simple; bh=QxgrxiYPyfgIgdcckKir9l5MmECb0kuUk85QadtiF30=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=DYlBJQtFBfz7cTkO3xo3+qZ5MLIHZIDRfDYska+we7WtbyJTu0Cvm92Xf7t3qMW0bcwU1PBAMCZY0u8DtyxXKTrRS2eNXCo3uYk2rHI0aN1vcXlHeiH5VwBO6q5DT4gZ/Y38DpD9485/aEEdW6j+njVtIbGz7tCRUSTOK3EM65E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=eCPREgEG; arc=none smtp.client-ip=203.254.224.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="eCPREgEG" Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20250917134204epoutp049daea3829788c6d76ccc2366aa05f9ec~mFan-LRnI0545805458epoutp04R for ; Wed, 17 Sep 2025 13:42:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20250917134204epoutp049daea3829788c6d76ccc2366aa05f9ec~mFan-LRnI0545805458epoutp04R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116524; bh=J/7DkBNdXlSoe7d+7pBkn1ckZK936GrNoSihihPioVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eCPREgEG9MNIE5S6U3YSJ1PEZhVOKU7Ifv+2OosPMbBv1KSGK3WK4IHzDky/7wzyr m9VvNMMBEuBRjEiYA4k+oXVHRKxd2kgTL9HKQZFlgzTLn3KLPXqUqLdsB0dhtFrYqf OkJEGwWA4zde/TbtMx4KjwSNLTk4ax1yksT7QH9Y= Received: from epsnrtp03.localdomain (unknown [182.195.42.155]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20250917134204epcas5p2f4e766e991133c0decc2c8cea61fefab~mFanpbwR61141811418epcas5p2k; Wed, 17 Sep 2025 13:42:04 +0000 (GMT) Received: from epcas5p3.samsung.com (unknown [182.195.38.89]) by epsnrtp03.localdomain (Postfix) with ESMTP id 4cRg170hM8z3hhT4; Wed, 17 Sep 2025 13:42:03 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20250917134202epcas5p23f718742c74c5b519ecbbc1e04840c03~mFamD8tYo0912409124epcas5p2i; Wed, 17 Sep 2025 13:42:02 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134200epsmtip268b889eb80e785df75d3437e164a087e~mFakFR9C60862908629epsmtip2P; Wed, 17 Sep 2025 13:42:00 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 15/20] cxl: Add a routine to find cxl root decoder on cxl bus using cxl port Date: Wed, 17 Sep 2025 19:11:11 +0530 Message-Id: <20250917134116.1623730-16-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134202epcas5p23f718742c74c5b519ecbbc1e04840c03 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134202epcas5p23f718742c74c5b519ecbbc1e04840c03 References: <20250917134116.1623730-1-s.neeraj@samsung.com> Add cxl_find_root_decoder_by_port() to find root decoder on cxl bus. It is used to find root decoder using cxl port. Signed-off-by: Neeraj Kumar --- drivers/cxl/core/port.c | 27 +++++++++++++++++++++++++++ drivers/cxl/cxl.h | 1 + 2 files changed, 28 insertions(+) diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index 8f36ff413f5d..647d9ce32b64 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -518,6 +518,33 @@ struct cxl_switch_decoder *to_cxl_switch_decoder(struc= t device *dev) } EXPORT_SYMBOL_NS_GPL(to_cxl_switch_decoder, "CXL"); =20 +static int match_root_decoder(struct device *dev, const void *data) +{ + return is_root_decoder(dev); +} + +/** + * cxl_find_root_decoder_by_port() - find a cxl root decoder on cxl bus + * @port: any descendant port in CXL port topology + */ +struct cxl_root_decoder *cxl_find_root_decoder_by_port(struct cxl_port *po= rt) +{ + struct cxl_root *cxl_root __free(put_cxl_root) =3D find_cxl_root(port); + struct device *dev; + + if (!cxl_root) + return NULL; + + dev =3D device_find_child(&cxl_root->port.dev, NULL, match_root_decoder); + if (!dev) + return NULL; + + /* Release device ref taken via device_find_child() */ + put_device(dev); + return to_cxl_root_decoder(dev); +} +EXPORT_SYMBOL_NS_GPL(cxl_find_root_decoder_by_port, "CXL"); + static void cxl_ep_release(struct cxl_ep *ep) { put_device(ep->ep); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 3abadc3dc82e..1eb1aca7c69f 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -866,6 +866,7 @@ struct cxl_nvdimm *to_cxl_nvdimm(struct device *dev); bool is_cxl_nvdimm(struct device *dev); int devm_cxl_add_nvdimm(struct cxl_port *parent_port, struct cxl_memdev *c= xlmd); struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_port *port); +struct cxl_root_decoder *cxl_find_root_decoder_by_port(struct cxl_port *po= rt); =20 #ifdef CONFIG_CXL_REGION bool is_cxl_pmem_region(struct device *dev); --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (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 D2A5233B48C for ; Wed, 17 Sep 2025 13:42:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.24 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116529; cv=none; b=IO3x1VK+qW9LHcK8Rd2yJZKz4iaMpiZq4babf1FbGCQcuRCPK9VCU3Pa6gKSrkq25LgSmrx7vjgTO3WIIPdHyu/NXH20voJt3lDcv4GPO5x9APeNHzx9/1mJ2IpTbGBZGDgXXiM0SLBtQnU4O94D7zJfjUpPaN5zvjxVqFdkoo8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116529; c=relaxed/simple; bh=KFoRj9mZvTUE6PPXaSVUQhJJ9OCKEsjumD8QM6HYavM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=LJMKpfOGcYHlOo3G+NmOlpZMXbme8fRIyUj+WRmMYlYG/+UmImP66kemBMGw6XbwkCAihC3ty9mVVyTJu+l/Jat9vYoDRB7w6fTlgeGn/pRBuokfLU+ZC1HLsSY7AghOfiBrfy3/vYAHynJ+ccx2ij9ApeKuf6TKl+6k3qdZ0Vw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=RcZfuKjJ; arc=none smtp.client-ip=203.254.224.24 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="RcZfuKjJ" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20250917134206epoutp01789a394c7bcec4ebcf8a5c5623833506~mFapomHJA2841328413epoutp01e for ; Wed, 17 Sep 2025 13:42:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20250917134206epoutp01789a394c7bcec4ebcf8a5c5623833506~mFapomHJA2841328413epoutp01e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116526; bh=ruMW/DmvKo1W3pEP4KsORZ6lIfMB2xwID5AWAJCvEL0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RcZfuKjJm4RBuGQ6J7sXvTW2S4akw7wQqEGGD4os2lCOqfoszZzBd/EVie0M99tQZ MpwBKBqxxD8put3nD3Jia4GXti38/5gLvJIczRO3ddfwHMAthLBfZJYu9hhAKGmrG3 7MVvO9AU5XmPmOMz0mmwGt3G7RXNSb2o2Om8SURw= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20250917134205epcas5p25b79e0aa6a59b88e4543f5ab86f85bcd~mFapKanKK0928509285epcas5p2q; Wed, 17 Sep 2025 13:42:05 +0000 (GMT) Received: from epcas5p3.samsung.com (unknown [182.195.38.90]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4cRg184rsSz6B9m6; Wed, 17 Sep 2025 13:42:04 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20250917134203epcas5p3819aee1deecdeaed95bd92d19d3b1910~mFanhE-OD2659126591epcas5p3i; Wed, 17 Sep 2025 13:42:03 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134202epsmtip282c537362371aad97c61d5f3447d005f~mFamSz2Aa0911709117epsmtip2W; Wed, 17 Sep 2025 13:42:02 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 16/20] cxl/mem: Preserve cxl root decoder during mem probe Date: Wed, 17 Sep 2025 19:11:12 +0530 Message-Id: <20250917134116.1623730-17-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134203epcas5p3819aee1deecdeaed95bd92d19d3b1910 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134203epcas5p3819aee1deecdeaed95bd92d19d3b1910 References: <20250917134116.1623730-1-s.neeraj@samsung.com> Saved root decoder info is required for cxl region persistency Signed-off-by: Neeraj Kumar --- drivers/cxl/cxlmem.h | 1 + drivers/cxl/mem.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h index 434031a0c1f7..25cb115b72bd 100644 --- a/drivers/cxl/cxlmem.h +++ b/drivers/cxl/cxlmem.h @@ -59,6 +59,7 @@ struct cxl_memdev { struct cxl_nvdimm_bridge *cxl_nvb; struct cxl_nvdimm *cxl_nvd; struct cxl_port *endpoint; + struct cxl_root_decoder *cxlrd; int id; int depth; u8 scrub_cycle; diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c index 54501616ff09..1a0da7253a24 100644 --- a/drivers/cxl/mem.c +++ b/drivers/cxl/mem.c @@ -152,6 +152,8 @@ static int cxl_mem_probe(struct device *dev) return -ENXIO; } =20 + cxlmd->cxlrd =3D cxl_find_root_decoder_by_port(parent_port); + if (dport->rch) endpoint_parent =3D parent_port->uport_dev; else --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (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 07EBA34F492 for ; Wed, 17 Sep 2025 13:42:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.24 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116531; cv=none; b=gKcm8/z+3z3VHmpXEOx2CO5VSgHPaGzQ42/E5iBd8n7DPNFFGsNfz6ZwT62Wd7NCHTzuzCsaGgGUTUrE84nzDsA1UYwhwXkQFEFlcjyY4cRKZzY+WtlBCJx2e5GUPVzjX84Zws10F2mrOI9jANeIjlCq7Cqad5KnY5HLtwUMw4o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116531; c=relaxed/simple; bh=8QH1l6WhkxI25RXDqtdyvnQAdOa9RFZNwZRhHLcA25w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=ecUJsErsacJF1gD+l4UZSkqOHIsrllKFUjbFoDuYJjFCY6f7vZHdC4+U2NlSTn+ROR0m+XnrVk9oN0sodbRx8Xzh5n1gCGakvdkewAfZbpM2IbO/kL3DSs4GJdLq8gKVmrsGA64x+L0wONZCUST7zK2HxDy8qYqlFG67yAmOAYY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=bQG+sR/9; arc=none smtp.client-ip=203.254.224.24 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="bQG+sR/9" Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20250917134208epoutp012c27446e8e22fa0ca1a844422e28d6c0~mFarq_oHV2840728407epoutp01R for ; Wed, 17 Sep 2025 13:42:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20250917134208epoutp012c27446e8e22fa0ca1a844422e28d6c0~mFarq_oHV2840728407epoutp01R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116528; bh=Lrv2ikBf3O5NwJGep2hXkTk6Ovkh45U+lUMsg7E/HGM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bQG+sR/9ClRpTq9IGaBEdH4eW56kzxqVeSvkd4QLAhK5fPb05Cn3scKKH+LgKCqWH M/ICJxlOu2VQWmTtrzGfYHZwvLbLbZk4Gd98glQcHR4+o8jczNS5myVMlNsyVzQ6Yz u25zIXRqwb7HPm4sRsu6+iQFbtcQtjIqPCNUik5E= Received: from epsnrtp03.localdomain (unknown [182.195.42.155]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20250917134208epcas5p29ad13559962480c1a5dce18ddb43a182~mFarYiSeu1139711397epcas5p2s; Wed, 17 Sep 2025 13:42:08 +0000 (GMT) Received: from epcas5p1.samsung.com (unknown [182.195.38.88]) by epsnrtp03.localdomain (Postfix) with ESMTP id 4cRg1C0Yn7z3hhT7; Wed, 17 Sep 2025 13:42:07 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20250917134206epcas5p346640447ba36a00e33ec98c4d35f063b~mFap8lNWO2768527685epcas5p3k; Wed, 17 Sep 2025 13:42:06 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134204epsmtip20246a2e57d4cd53b18015193f6fc4e7a~mFaoAf7b20967109671epsmtip2e; Wed, 17 Sep 2025 13:42:04 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 17/20] cxl/pmem: Preserve region information into nd_set Date: Wed, 17 Sep 2025 19:11:13 +0530 Message-Id: <20250917134116.1623730-18-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134206epcas5p346640447ba36a00e33ec98c4d35f063b X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134206epcas5p346640447ba36a00e33ec98c4d35f063b References: <20250917134116.1623730-1-s.neeraj@samsung.com> Save region information stored in cxlr to nd_set during cxl_pmem_region_probe in nd_set. This saved region information is being stored into LSA, which will be used for cxl region persistence Signed-off-by: Neeraj Kumar --- drivers/cxl/pmem.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/cxl/pmem.c b/drivers/cxl/pmem.c index e197883690ef..38a5bcdc68ce 100644 --- a/drivers/cxl/pmem.c +++ b/drivers/cxl/pmem.c @@ -377,6 +377,7 @@ static int cxl_pmem_region_probe(struct device *dev) struct nd_mapping_desc mappings[CXL_DECODER_MAX_INTERLEAVE]; struct cxl_pmem_region *cxlr_pmem =3D to_cxl_pmem_region(dev); struct cxl_region *cxlr =3D cxlr_pmem->cxlr; + struct cxl_region_params *p =3D &cxlr->params; struct cxl_nvdimm_bridge *cxl_nvb =3D cxlr->cxl_nvb; struct cxl_pmem_region_info *info =3D NULL; struct nd_interleave_set *nd_set; @@ -465,12 +466,12 @@ static int cxl_pmem_region_probe(struct device *dev) ndr_desc.num_mappings =3D cxlr_pmem->nr_mappings; ndr_desc.mapping =3D mappings; =20 - /* - * TODO enable CXL labels which skip the need for 'interleave-set cookie' - */ - nd_set->cookie1 =3D - nd_fletcher64(info, sizeof(*info) * cxlr_pmem->nr_mappings, 0); - nd_set->cookie2 =3D nd_set->cookie1; + nd_set->uuid =3D p->uuid; + nd_set->interleave_ways =3D p->interleave_ways; + nd_set->interleave_granularity =3D p->interleave_granularity; + nd_set->res =3D p->res; + nd_set->nr_targets =3D p->nr_targets; + ndr_desc.nd_set =3D nd_set; =20 cxlr_pmem->nd_region =3D --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) (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 D2B2836C068 for ; Wed, 17 Sep 2025 13:42:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.25 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116535; cv=none; b=L24uTgn5VCGuXfz9wRTrTMTKeTtpP+qiMXWDeGeIoCCX12wH4hNrAr7/H9aoYb4ViA5xDm3VloXtDOa8Tg+z9E87ev0+aPgrUjU2t2EZ2n6vrdbEzubknAkMMDCzrUy3nCsVAiKYpS41RnCI/3mjxpTdXF3VPxLhsb/oMuF+wL4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116535; c=relaxed/simple; bh=8nsFmYVBjU4yibJYKPdj/k/Nv5TJAe45Muu6Fy5zh+k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=H5owWk57iHnwM5ASxNQgQ0OT7xwnwH2dkuPuyQRFcg35s1p/C3DT+8qECoI9KaPxcTTwCZqx3I9zNRvDqc6JXPHY4l1sowcWuZhqVpnITOb1L9OkDd4LsrVttisePwJvATDb4OIob8buZXqnlCKJWctS06bIlDAIldv/HwzVIyw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=CvfE08Wg; arc=none smtp.client-ip=203.254.224.25 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="CvfE08Wg" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20250917134211epoutp02079671e78590ef1dcaec9d075e279890~mFauSIUkn1573515735epoutp02N for ; Wed, 17 Sep 2025 13:42:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20250917134211epoutp02079671e78590ef1dcaec9d075e279890~mFauSIUkn1573515735epoutp02N DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116531; bh=FTD1FAvN8ETtjFFAyKiqEdIsNxWFHuIsp6B90QotBH8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CvfE08WgJq9ThRoO9ID6/Jl6IgPQViAu/T3oHrsdAF5xmyEMK7lVa5gJskI7ZF5Dq KhTFXLbf6T8Fv+D7xpgdhuGntmnoTYDDx9fyyow5oV/60+RzvMX9JrftGeFWIMFU1p B01T5yB86XcU/PorwGYzGKXUB8LZEq3J7RuJ1RCQ= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20250917134210epcas5p22abf04b11344506c14e46e30da153ed0~mFat-NZvW1141811418epcas5p22; Wed, 17 Sep 2025 13:42:10 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.95]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4cRg1F6TVDz6B9m4; Wed, 17 Sep 2025 13:42:09 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20250917134209epcas5p1b7f861dbd8299ec874ae44cbf63ce87c~mFaskCqI_1745017450epcas5p11; Wed, 17 Sep 2025 13:42:09 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134206epsmtip2d0e9af7d98cc6a6ab0908554dba7f65f~mFaqLvhkS0952109521epsmtip2D; Wed, 17 Sep 2025 13:42:06 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 18/20] cxl/pmem_region: Prep patch to accommodate pmem_region attributes Date: Wed, 17 Sep 2025 19:11:14 +0530 Message-Id: <20250917134116.1623730-19-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134209epcas5p1b7f861dbd8299ec874ae44cbf63ce87c X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134209epcas5p1b7f861dbd8299ec874ae44cbf63ce87c References: <20250917134116.1623730-1-s.neeraj@samsung.com> Created a separate file core/pmem_region.c along with CONFIG_PMEM_REGION Moved pmem_region related code from core/region.c to core/pmem_region.c For region label update, need to create device attribute, which calls nvdimm exported function thus making pmem_region dependent on libnvdimm. Because of this dependency of pmem region on libnvdimm, segregated pmem region related code from core/region.c Signed-off-by: Neeraj Kumar --- drivers/cxl/Kconfig | 14 +++ drivers/cxl/core/Makefile | 1 + drivers/cxl/core/core.h | 8 +- drivers/cxl/core/pmem_region.c | 203 +++++++++++++++++++++++++++++++++ drivers/cxl/core/port.c | 2 +- drivers/cxl/core/region.c | 191 +------------------------------ drivers/cxl/cxl.h | 30 +++-- tools/testing/cxl/Kbuild | 1 + 8 files changed, 250 insertions(+), 200 deletions(-) create mode 100644 drivers/cxl/core/pmem_region.c diff --git a/drivers/cxl/Kconfig b/drivers/cxl/Kconfig index 48b7314afdb8..532eaa1bbdd6 100644 --- a/drivers/cxl/Kconfig +++ b/drivers/cxl/Kconfig @@ -211,6 +211,20 @@ config CXL_REGION =20 If unsure say 'y' =20 +config CXL_PMEM_REGION + bool "CXL: Pmem Region Support" + default CXL_BUS + depends on CXL_REGION + depends on PHYS_ADDR_T_64BIT + depends on BLK_DEV + select LIBNVDIMM + help + Enable the CXL core to enumerate and provision CXL pmem regions. + A CXL pmem region need to update region label into LSA. For LSA + updation/deletion libnvdimm is required. + + If unsure say 'y' + config CXL_REGION_INVALIDATION_TEST bool "CXL: Region Cache Management Bypass (TEST)" depends on CXL_REGION diff --git a/drivers/cxl/core/Makefile b/drivers/cxl/core/Makefile index 5ad8fef210b5..399157beb917 100644 --- a/drivers/cxl/core/Makefile +++ b/drivers/cxl/core/Makefile @@ -17,6 +17,7 @@ cxl_core-y +=3D cdat.o cxl_core-y +=3D ras.o cxl_core-$(CONFIG_TRACING) +=3D trace.o cxl_core-$(CONFIG_CXL_REGION) +=3D region.o +cxl_core-$(CONFIG_CXL_PMEM_REGION) +=3D pmem_region.o cxl_core-$(CONFIG_CXL_MCE) +=3D mce.o cxl_core-$(CONFIG_CXL_FEATURES) +=3D features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) +=3D edac.o diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index 5707cd60a8eb..536636a752dc 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -34,7 +34,6 @@ int cxl_decoder_detach(struct cxl_region *cxlr, #define CXL_REGION_ATTR(x) (&dev_attr_##x.attr) #define CXL_REGION_TYPE(x) (&cxl_region_type) #define SET_CXL_REGION_ATTR(x) (&dev_attr_##x.attr), -#define CXL_PMEM_REGION_TYPE(x) (&cxl_pmem_region_type) #define CXL_DAX_REGION_TYPE(x) (&cxl_dax_region_type) int cxl_region_init(void); void cxl_region_exit(void); @@ -74,10 +73,15 @@ static inline void cxl_region_exit(void) #define CXL_REGION_ATTR(x) NULL #define CXL_REGION_TYPE(x) NULL #define SET_CXL_REGION_ATTR(x) -#define CXL_PMEM_REGION_TYPE(x) NULL #define CXL_DAX_REGION_TYPE(x) NULL #endif =20 +#ifdef CONFIG_CXL_PMEM_REGION +#define CXL_PMEM_REGION_TYPE (&cxl_pmem_region_type) +#else +#define CXL_PMEM_REGION_TYPE NULL +#endif + struct cxl_send_command; struct cxl_mem_query_commands; int cxl_query_cmd(struct cxl_mailbox *cxl_mbox, diff --git a/drivers/cxl/core/pmem_region.c b/drivers/cxl/core/pmem_region.c new file mode 100644 index 000000000000..55b80d587403 --- /dev/null +++ b/drivers/cxl/core/pmem_region.c @@ -0,0 +1,203 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright(c) 2020 Intel Corporation. */ +#include +#include +#include +#include +#include "core.h" + +/** + * DOC: cxl pmem region + * + * The core CXL PMEM region infrastructure supports persistent memory + * region creation using LIBNVDIMM subsystem. It has dependency on + * LIBNVDIMM, pmem region need updation of cxl region information into + * LSA. LIBNVDIMM dependency is only for pmem region, it is therefore + * need this separate file. + */ + +bool is_cxl_pmem_region(struct device *dev) +{ + return dev->type =3D=3D &cxl_pmem_region_type; +} +EXPORT_SYMBOL_NS_GPL(is_cxl_pmem_region, "CXL"); + +struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev) +{ + if (dev_WARN_ONCE(dev, !is_cxl_pmem_region(dev), + "not a cxl_pmem_region device\n")) + return NULL; + return container_of(dev, struct cxl_pmem_region, dev); +} +EXPORT_SYMBOL_NS_GPL(to_cxl_pmem_region, "CXL"); + +static void cxl_pmem_region_release(struct device *dev) +{ + struct cxl_pmem_region *cxlr_pmem =3D to_cxl_pmem_region(dev); + int i; + + for (i =3D 0; i < cxlr_pmem->nr_mappings; i++) { + struct cxl_memdev *cxlmd =3D cxlr_pmem->mapping[i].cxlmd; + + put_device(&cxlmd->dev); + } + + kfree(cxlr_pmem); +} + +static const struct attribute_group *cxl_pmem_region_attribute_groups[] = =3D { + &cxl_base_attribute_group, + NULL, +}; + +const struct device_type cxl_pmem_region_type =3D { + .name =3D "cxl_pmem_region", + .release =3D cxl_pmem_region_release, + .groups =3D cxl_pmem_region_attribute_groups, +}; + +static struct lock_class_key cxl_pmem_region_key; + +static int cxl_pmem_region_alloc(struct cxl_region *cxlr) +{ + struct cxl_region_params *p =3D &cxlr->params; + struct cxl_nvdimm_bridge *cxl_nvb; + struct device *dev; + int i; + + guard(rwsem_read)(&cxl_rwsem.region); + if (p->state !=3D CXL_CONFIG_COMMIT) + return -ENXIO; + + struct cxl_pmem_region *cxlr_pmem __free(kfree) =3D + kzalloc(struct_size(cxlr_pmem, mapping, p->nr_targets), + GFP_KERNEL); + if (!cxlr_pmem) + return -ENOMEM; + + cxlr_pmem->hpa_range.start =3D p->res->start; + cxlr_pmem->hpa_range.end =3D p->res->end; + + /* Snapshot the region configuration underneath the cxl_region_rwsem */ + cxlr_pmem->nr_mappings =3D p->nr_targets; + for (i =3D 0; i < p->nr_targets; i++) { + struct cxl_endpoint_decoder *cxled =3D p->targets[i]; + struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); + struct cxl_pmem_region_mapping *m =3D &cxlr_pmem->mapping[i]; + + /* + * Regions never span CXL root devices, so by definition the + * bridge for one device is the same for all. + */ + if (i =3D=3D 0) { + cxl_nvb =3D cxl_find_nvdimm_bridge(cxlmd->endpoint); + if (!cxl_nvb) + return -ENODEV; + cxlr->cxl_nvb =3D cxl_nvb; + } + m->cxlmd =3D cxlmd; + get_device(&cxlmd->dev); + m->start =3D cxled->dpa_res->start; + m->size =3D resource_size(cxled->dpa_res); + m->position =3D i; + } + + dev =3D &cxlr_pmem->dev; + device_initialize(dev); + lockdep_set_class(&dev->mutex, &cxl_pmem_region_key); + device_set_pm_not_required(dev); + dev->parent =3D &cxlr->dev; + dev->bus =3D &cxl_bus_type; + dev->type =3D &cxl_pmem_region_type; + cxlr_pmem->cxlr =3D cxlr; + cxlr->cxlr_pmem =3D no_free_ptr(cxlr_pmem); + + return 0; +} + +static void cxlr_pmem_unregister(void *_cxlr_pmem) +{ + struct cxl_pmem_region *cxlr_pmem =3D _cxlr_pmem; + struct cxl_region *cxlr =3D cxlr_pmem->cxlr; + struct cxl_nvdimm_bridge *cxl_nvb =3D cxlr->cxl_nvb; + + /* + * Either the bridge is in ->remove() context under the device_lock(), + * or cxlr_release_nvdimm() is cancelling the bridge's release action + * for @cxlr_pmem and doing it itself (while manually holding the bridge + * lock). + */ + device_lock_assert(&cxl_nvb->dev); + cxlr->cxlr_pmem =3D NULL; + cxlr_pmem->cxlr =3D NULL; + device_unregister(&cxlr_pmem->dev); +} + +static void cxlr_release_nvdimm(void *_cxlr) +{ + struct cxl_region *cxlr =3D _cxlr; + struct cxl_nvdimm_bridge *cxl_nvb =3D cxlr->cxl_nvb; + + scoped_guard(device, &cxl_nvb->dev) { + if (cxlr->cxlr_pmem) + devm_release_action(&cxl_nvb->dev, cxlr_pmem_unregister, + cxlr->cxlr_pmem); + } + cxlr->cxl_nvb =3D NULL; + put_device(&cxl_nvb->dev); +} + +/** + * devm_cxl_add_pmem_region() - add a cxl_region-to-nd_region bridge + * @cxlr: parent CXL region for this pmem region bridge device + * + * Return: 0 on success negative error code on failure. + */ +int devm_cxl_add_pmem_region(struct cxl_region *cxlr) +{ + struct cxl_pmem_region *cxlr_pmem; + struct cxl_nvdimm_bridge *cxl_nvb; + struct device *dev; + int rc; + + rc =3D cxl_pmem_region_alloc(cxlr); + if (rc) + return rc; + cxlr_pmem =3D cxlr->cxlr_pmem; + cxl_nvb =3D cxlr->cxl_nvb; + + dev =3D &cxlr_pmem->dev; + rc =3D dev_set_name(dev, "pmem_region%d", cxlr->id); + if (rc) + goto err; + + rc =3D device_add(dev); + if (rc) + goto err; + + dev_dbg(&cxlr->dev, "%s: register %s\n", dev_name(dev->parent), + dev_name(dev)); + + scoped_guard(device, &cxl_nvb->dev) { + if (cxl_nvb->dev.driver) + rc =3D devm_add_action_or_reset(&cxl_nvb->dev, + cxlr_pmem_unregister, + cxlr_pmem); + else + rc =3D -ENXIO; + } + + if (rc) + goto err_bridge; + + /* @cxlr carries a reference on @cxl_nvb until cxlr_release_nvdimm */ + return devm_add_action_or_reset(&cxlr->dev, cxlr_release_nvdimm, cxlr); + +err: + put_device(dev); +err_bridge: + put_device(&cxl_nvb->dev); + cxlr->cxl_nvb =3D NULL; + return rc; +} +EXPORT_SYMBOL_NS_GPL(devm_cxl_add_pmem_region, "CXL"); diff --git a/drivers/cxl/core/port.c b/drivers/cxl/core/port.c index 647d9ce32b64..717de1d3f70e 100644 --- a/drivers/cxl/core/port.c +++ b/drivers/cxl/core/port.c @@ -53,7 +53,7 @@ static int cxl_device_id(const struct device *dev) return CXL_DEVICE_NVDIMM_BRIDGE; if (dev->type =3D=3D &cxl_nvdimm_type) return CXL_DEVICE_NVDIMM; - if (dev->type =3D=3D CXL_PMEM_REGION_TYPE()) + if (dev->type =3D=3D CXL_PMEM_REGION_TYPE) return CXL_DEVICE_PMEM_REGION; if (dev->type =3D=3D CXL_DAX_REGION_TYPE()) return CXL_DEVICE_DAX_REGION; diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index d5c227ce7b09..d2ef7fcc19fe 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -38,8 +38,6 @@ */ static nodemask_t nodemask_region_seen =3D NODE_MASK_NONE; =20 -static struct cxl_region *to_cxl_region(struct device *dev); - #define __ACCESS_ATTR_RO(_level, _name) { \ .attr =3D { .name =3D __stringify(_name), .mode =3D 0444 }, \ .show =3D _name##_access##_level##_show, \ @@ -2382,7 +2380,7 @@ bool is_cxl_region(struct device *dev) } EXPORT_SYMBOL_NS_GPL(is_cxl_region, "CXL"); =20 -static struct cxl_region *to_cxl_region(struct device *dev) +struct cxl_region *to_cxl_region(struct device *dev) { if (dev_WARN_ONCE(dev, dev->type !=3D &cxl_region_type, "not a cxl_region device\n")) @@ -2390,6 +2388,7 @@ static struct cxl_region *to_cxl_region(struct device= *dev) =20 return container_of(dev, struct cxl_region, dev); } +EXPORT_SYMBOL_NS_GPL(to_cxl_region, "CXL"); =20 static void unregister_region(void *_cxlr) { @@ -2814,46 +2813,6 @@ static ssize_t delete_region_store(struct device *de= v, } DEVICE_ATTR_WO(delete_region); =20 -static void cxl_pmem_region_release(struct device *dev) -{ - struct cxl_pmem_region *cxlr_pmem =3D to_cxl_pmem_region(dev); - int i; - - for (i =3D 0; i < cxlr_pmem->nr_mappings; i++) { - struct cxl_memdev *cxlmd =3D cxlr_pmem->mapping[i].cxlmd; - - put_device(&cxlmd->dev); - } - - kfree(cxlr_pmem); -} - -static const struct attribute_group *cxl_pmem_region_attribute_groups[] = =3D { - &cxl_base_attribute_group, - NULL, -}; - -const struct device_type cxl_pmem_region_type =3D { - .name =3D "cxl_pmem_region", - .release =3D cxl_pmem_region_release, - .groups =3D cxl_pmem_region_attribute_groups, -}; - -bool is_cxl_pmem_region(struct device *dev) -{ - return dev->type =3D=3D &cxl_pmem_region_type; -} -EXPORT_SYMBOL_NS_GPL(is_cxl_pmem_region, "CXL"); - -struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev) -{ - if (dev_WARN_ONCE(dev, !is_cxl_pmem_region(dev), - "not a cxl_pmem_region device\n")) - return NULL; - return container_of(dev, struct cxl_pmem_region, dev); -} -EXPORT_SYMBOL_NS_GPL(to_cxl_pmem_region, "CXL"); - struct cxl_poison_context { struct cxl_port *port; int part; @@ -3213,64 +3172,6 @@ static int region_offset_to_dpa_result(struct cxl_re= gion *cxlr, u64 offset, return -ENXIO; } =20 -static struct lock_class_key cxl_pmem_region_key; - -static int cxl_pmem_region_alloc(struct cxl_region *cxlr) -{ - struct cxl_region_params *p =3D &cxlr->params; - struct cxl_nvdimm_bridge *cxl_nvb; - struct device *dev; - int i; - - guard(rwsem_read)(&cxl_rwsem.region); - if (p->state !=3D CXL_CONFIG_COMMIT) - return -ENXIO; - - struct cxl_pmem_region *cxlr_pmem __free(kfree) =3D - kzalloc(struct_size(cxlr_pmem, mapping, p->nr_targets), GFP_KERNEL); - if (!cxlr_pmem) - return -ENOMEM; - - cxlr_pmem->hpa_range.start =3D p->res->start; - cxlr_pmem->hpa_range.end =3D p->res->end; - - /* Snapshot the region configuration underneath the cxl_rwsem.region */ - cxlr_pmem->nr_mappings =3D p->nr_targets; - for (i =3D 0; i < p->nr_targets; i++) { - struct cxl_endpoint_decoder *cxled =3D p->targets[i]; - struct cxl_memdev *cxlmd =3D cxled_to_memdev(cxled); - struct cxl_pmem_region_mapping *m =3D &cxlr_pmem->mapping[i]; - - /* - * Regions never span CXL root devices, so by definition the - * bridge for one device is the same for all. - */ - if (i =3D=3D 0) { - cxl_nvb =3D cxl_find_nvdimm_bridge(cxlmd->endpoint); - if (!cxl_nvb) - return -ENODEV; - cxlr->cxl_nvb =3D cxl_nvb; - } - m->cxlmd =3D cxlmd; - get_device(&cxlmd->dev); - m->start =3D cxled->dpa_res->start; - m->size =3D resource_size(cxled->dpa_res); - m->position =3D i; - } - - dev =3D &cxlr_pmem->dev; - device_initialize(dev); - lockdep_set_class(&dev->mutex, &cxl_pmem_region_key); - device_set_pm_not_required(dev); - dev->parent =3D &cxlr->dev; - dev->bus =3D &cxl_bus_type; - dev->type =3D &cxl_pmem_region_type; - cxlr_pmem->cxlr =3D cxlr; - cxlr->cxlr_pmem =3D no_free_ptr(cxlr_pmem); - - return 0; -} - static void cxl_dax_region_release(struct device *dev) { struct cxl_dax_region *cxlr_dax =3D to_cxl_dax_region(dev); @@ -3334,92 +3235,6 @@ static struct cxl_dax_region *cxl_dax_region_alloc(s= truct cxl_region *cxlr) return cxlr_dax; } =20 -static void cxlr_pmem_unregister(void *_cxlr_pmem) -{ - struct cxl_pmem_region *cxlr_pmem =3D _cxlr_pmem; - struct cxl_region *cxlr =3D cxlr_pmem->cxlr; - struct cxl_nvdimm_bridge *cxl_nvb =3D cxlr->cxl_nvb; - - /* - * Either the bridge is in ->remove() context under the device_lock(), - * or cxlr_release_nvdimm() is cancelling the bridge's release action - * for @cxlr_pmem and doing it itself (while manually holding the bridge - * lock). - */ - device_lock_assert(&cxl_nvb->dev); - cxlr->cxlr_pmem =3D NULL; - cxlr_pmem->cxlr =3D NULL; - device_unregister(&cxlr_pmem->dev); -} - -static void cxlr_release_nvdimm(void *_cxlr) -{ - struct cxl_region *cxlr =3D _cxlr; - struct cxl_nvdimm_bridge *cxl_nvb =3D cxlr->cxl_nvb; - - scoped_guard(device, &cxl_nvb->dev) { - if (cxlr->cxlr_pmem) - devm_release_action(&cxl_nvb->dev, cxlr_pmem_unregister, - cxlr->cxlr_pmem); - } - cxlr->cxl_nvb =3D NULL; - put_device(&cxl_nvb->dev); -} - -/** - * devm_cxl_add_pmem_region() - add a cxl_region-to-nd_region bridge - * @cxlr: parent CXL region for this pmem region bridge device - * - * Return: 0 on success negative error code on failure. - */ -static int devm_cxl_add_pmem_region(struct cxl_region *cxlr) -{ - struct cxl_pmem_region *cxlr_pmem; - struct cxl_nvdimm_bridge *cxl_nvb; - struct device *dev; - int rc; - - rc =3D cxl_pmem_region_alloc(cxlr); - if (rc) - return rc; - cxlr_pmem =3D cxlr->cxlr_pmem; - cxl_nvb =3D cxlr->cxl_nvb; - - dev =3D &cxlr_pmem->dev; - rc =3D dev_set_name(dev, "pmem_region%d", cxlr->id); - if (rc) - goto err; - - rc =3D device_add(dev); - if (rc) - goto err; - - dev_dbg(&cxlr->dev, "%s: register %s\n", dev_name(dev->parent), - dev_name(dev)); - - scoped_guard(device, &cxl_nvb->dev) { - if (cxl_nvb->dev.driver) - rc =3D devm_add_action_or_reset(&cxl_nvb->dev, - cxlr_pmem_unregister, - cxlr_pmem); - else - rc =3D -ENXIO; - } - - if (rc) - goto err_bridge; - - /* @cxlr carries a reference on @cxl_nvb until cxlr_release_nvdimm */ - return devm_add_action_or_reset(&cxlr->dev, cxlr_release_nvdimm, cxlr); - -err: - put_device(dev); -err_bridge: - put_device(&cxl_nvb->dev); - cxlr->cxl_nvb =3D NULL; - return rc; -} - static void cxlr_dax_unregister(void *_cxlr_dax) { struct cxl_dax_region *cxlr_dax =3D _cxlr_dax; @@ -3985,6 +3800,8 @@ static int cxl_region_probe(struct device *dev) dev_dbg(&cxlr->dev, "CXL EDAC registration for region_id=3D%d failed\n", cxlr->id); =20 + if (!IS_ENABLED(CONFIG_CXL_PMEM_REGION)) + return -EINVAL; return devm_cxl_add_pmem_region(cxlr); case CXL_PARTMODE_RAM: rc =3D devm_cxl_region_edac_register(cxlr); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 1eb1aca7c69f..0d576b359de6 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -825,6 +825,7 @@ int cxl_dvsec_rr_decode(struct cxl_dev_state *cxlds, struct cxl_endpoint_dvsec_info *info); =20 bool is_cxl_region(struct device *dev); +struct cxl_region *to_cxl_region(struct device *dev); =20 extern const struct bus_type cxl_bus_type; =20 @@ -869,8 +870,6 @@ struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct= cxl_port *port); struct cxl_root_decoder *cxl_find_root_decoder_by_port(struct cxl_port *po= rt); =20 #ifdef CONFIG_CXL_REGION -bool is_cxl_pmem_region(struct device *dev); -struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev); int cxl_add_to_region(struct cxl_endpoint_decoder *cxled); struct cxl_dax_region *to_cxl_dax_region(struct device *dev); u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, u64 spa); @@ -880,14 +879,6 @@ struct cxl_region *cxl_create_region(struct cxl_root_d= ecoder *cxlrd, struct cxl_pmem_region_params *params, struct cxl_decoder *cxld); #else -static inline bool is_cxl_pmem_region(struct device *dev) -{ - return false; -} -static inline struct cxl_pmem_region *to_cxl_pmem_region(struct device *de= v) -{ - return NULL; -} static inline int cxl_add_to_region(struct cxl_endpoint_decoder *cxled) { return 0; @@ -914,6 +905,25 @@ cxl_create_region(struct cxl_root_decoder *cxlrd, } #endif =20 +#ifdef CONFIG_CXL_PMEM_REGION +bool is_cxl_pmem_region(struct device *dev); +struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev); +int devm_cxl_add_pmem_region(struct cxl_region *cxlr); +#else +static inline bool is_cxl_pmem_region(struct device *dev) +{ + return false; +} +static inline struct cxl_pmem_region *to_cxl_pmem_region(struct device *de= v) +{ + return NULL; +} +static inline int devm_cxl_add_pmem_region(struct cxl_region *cxlr) +{ + return 0; +} +#endif + void cxl_endpoint_parse_cdat(struct cxl_port *port); void cxl_switch_parse_cdat(struct cxl_port *port); =20 diff --git a/tools/testing/cxl/Kbuild b/tools/testing/cxl/Kbuild index d07f14cb7aa4..cf58ada337b7 100644 --- a/tools/testing/cxl/Kbuild +++ b/tools/testing/cxl/Kbuild @@ -64,6 +64,7 @@ cxl_core-y +=3D $(CXL_CORE_SRC)/cdat.o cxl_core-y +=3D $(CXL_CORE_SRC)/ras.o cxl_core-$(CONFIG_TRACING) +=3D $(CXL_CORE_SRC)/trace.o cxl_core-$(CONFIG_CXL_REGION) +=3D $(CXL_CORE_SRC)/region.o +cxl_core-$(CONFIG_CXL_PMEM_REGION) +=3D $(CXL_CORE_SRC)/pmem_region.o cxl_core-$(CONFIG_CXL_MCE) +=3D $(CXL_CORE_SRC)/mce.o cxl_core-$(CONFIG_CXL_FEATURES) +=3D $(CXL_CORE_SRC)/features.o cxl_core-$(CONFIG_CXL_EDAC_MEM_FEATURES) +=3D $(CXL_CORE_SRC)/edac.o --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (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 E09643705AC for ; Wed, 17 Sep 2025 13:42:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116538; cv=none; b=Oet5RD4QtfnBzrGaneDf1YOQ8U/11zuPfCkSEULBnnvi0Iq1V0AnSk7eVRBV1BQtB3VjCJa/mlYqNdM2+qvJTc3+RQQ46+60Is46NTtf3JUoapfhJvLvuOlBOwRJCeS1A3Br4dpHobhRhS3b+4EHve2/iWxbzpSftiG3RD6w3fw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116538; c=relaxed/simple; bh=9bTEk28p+1EQHHun823XzXhDf9Y8hPVkAkMuj47iOl4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=qhFrT+WYyTRwuyXCUuAWYqAGb+NR4OvwO1unPABMUpOJ3uBOWegvsEKCIZ85tN7P2GBibTyY+PVYd/wwgpF7qbQ4AKUBsAojxpdMsU6SpSHjlBxiCua232SHCfQVEHLPm8Vj4KPJe4Kk4ZYhuKgAbPN2ZrN4mHsyqo4Xmx+1MLw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=tMdEPQ74; arc=none smtp.client-ip=203.254.224.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="tMdEPQ74" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20250917134214epoutp03abe120475dfe7eda96b1b22fb59f1984~mFaxJnZj_0947909479epoutp03P for ; Wed, 17 Sep 2025 13:42:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20250917134214epoutp03abe120475dfe7eda96b1b22fb59f1984~mFaxJnZj_0947909479epoutp03P DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116534; bh=Gis+7Gmlr9qMCEkpYG8GWuuPF2egOaPPu7OYRJgJuIc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tMdEPQ74dYBYVHjKFckasnAK4cm+DFBtCEx0+YR9YqIlGe3QNkeue8fvq+z7a5hIO V0ZrvokjTMllWYdac4JwNa79eHHD8I8zq3lYb8CcBIgLd7AB7J3+SEVGxMeLc/3di7 A+W9bjAlrr80rlC7gbcQhSqVY8MloAZ71Sngg91Q= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPS id 20250917134213epcas5p3b005d2627fd878856aa9bbbf118b8c66~mFawOasd72659126591epcas5p31; Wed, 17 Sep 2025 13:42:13 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.92]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4cRg1J1whNz6B9m6; Wed, 17 Sep 2025 13:42:12 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20250917134211epcas5p17cf5e4052df126a67b27be971be82fe1~mFauehKXU2209822098epcas5p1u; Wed, 17 Sep 2025 13:42:11 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134209epsmtip2f7c92cf264b8112a07dae1cd96a09253~mFaszAMbH0970709707epsmtip2E; Wed, 17 Sep 2025 13:42:09 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 19/20] cxl/pmem_region: Add sysfs attribute cxl region label updation/deletion Date: Wed, 17 Sep 2025 19:11:15 +0530 Message-Id: <20250917134116.1623730-20-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134211epcas5p17cf5e4052df126a67b27be971be82fe1 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134211epcas5p17cf5e4052df126a67b27be971be82fe1 References: <20250917134116.1623730-1-s.neeraj@samsung.com> Using these attributes region label is added/deleted into LSA. These attributes are called from userspace (ndctl) after region creation. Signed-off-by: Neeraj Kumar --- Documentation/ABI/testing/sysfs-bus-cxl | 22 ++++++ drivers/cxl/core/pmem_region.c | 91 ++++++++++++++++++++++++- drivers/cxl/cxl.h | 1 + 3 files changed, 113 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/te= sting/sysfs-bus-cxl index 6b4e8c7a963d..d6080fcf843a 100644 --- a/Documentation/ABI/testing/sysfs-bus-cxl +++ b/Documentation/ABI/testing/sysfs-bus-cxl @@ -615,3 +615,25 @@ Description: The count is persistent across power loss and wraps back to 0 upon overflow. If this file is not present, the device does not have the necessary support for dirty tracking. + + +What: /sys/bus/cxl/devices/regionZ/pmem_regionZ/region_label_update +Date: Sept, 2025 +KernelVersion: v6.17 +Contact: linux-cxl@vger.kernel.org +Description: + (RW) Write a boolean 'true' string value to this attribute to + update cxl region information into LSA as region label. It + uses nvdimm nd_region_label_update() to update cxl region + information saved during cxl region creation into LSA. This + attribute must be called at last during cxl region creation. + + +What: /sys/bus/cxl/devices/regionZ/pmem_regionZ/region_label_delete +Date: Sept, 2025 +KernelVersion: v6.17 +Contact: linux-cxl@vger.kernel.org +Description: + (WO) When a boolean 'true' is written to this attribute then + pmem_region driver deletes cxl region label from LSA using + nvdimm nd_region_label_delete() diff --git a/drivers/cxl/core/pmem_region.c b/drivers/cxl/core/pmem_region.c index 55b80d587403..665b603c907b 100644 --- a/drivers/cxl/core/pmem_region.c +++ b/drivers/cxl/core/pmem_region.c @@ -45,9 +45,98 @@ static void cxl_pmem_region_release(struct device *dev) kfree(cxlr_pmem); } =20 +static ssize_t region_label_update_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct cxl_pmem_region *cxlr_pmem =3D to_cxl_pmem_region(dev); + struct cxl_region *cxlr =3D cxlr_pmem->cxlr; + ssize_t rc; + bool update; + + rc =3D kstrtobool(buf, &update); + if (rc) + return rc; + + ACQUIRE(rwsem_write_kill, rwsem)(&cxl_rwsem.region); + rc =3D ACQUIRE_ERR(rwsem_write_kill, &rwsem); + if (rc) + return rc; + + /* Region not yet committed */ + if (update && cxlr && cxlr->params.state !=3D CXL_CONFIG_COMMIT) { + dev_dbg(dev, "region not committed, can't update into LSA\n"); + return -ENXIO; + } + + if (cxlr && cxlr->cxlr_pmem && cxlr->cxlr_pmem->nd_region) { + rc =3D nd_region_label_update(cxlr->cxlr_pmem->nd_region); + if (!rc) + cxlr->params.region_label_state =3D 1; + } + + if (rc) + return rc; + + return len; +} + +static ssize_t region_label_update_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct cxl_pmem_region *cxlr_pmem =3D to_cxl_pmem_region(dev); + struct cxl_region *cxlr =3D cxlr_pmem->cxlr; + struct cxl_region_params *p =3D &cxlr->params; + ssize_t rc; + + ACQUIRE(rwsem_read_intr, rwsem)(&cxl_rwsem.region); + rc =3D ACQUIRE_ERR(rwsem_read_intr, &rwsem); + if (rc) + return rc; + + return sysfs_emit(buf, "%d\n", p->region_label_state); +} +static DEVICE_ATTR_RW(region_label_update); + +static ssize_t region_label_delete_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct cxl_pmem_region *cxlr_pmem =3D to_cxl_pmem_region(dev); + struct cxl_region *cxlr =3D cxlr_pmem->cxlr; + ssize_t rc; + + ACQUIRE(rwsem_write_kill, rwsem)(&cxl_rwsem.region); + rc =3D ACQUIRE_ERR(rwsem_write_kill, &rwsem); + if (rc) + return rc; + + if (cxlr && cxlr->cxlr_pmem && cxlr->cxlr_pmem->nd_region) { + rc =3D nd_region_label_delete(cxlr->cxlr_pmem->nd_region); + if (rc) + return rc; + cxlr->params.region_label_state =3D 0; + } + + return len; +} +static DEVICE_ATTR_WO(region_label_delete); + +static struct attribute *cxl_pmem_region_attrs[] =3D { + &dev_attr_region_label_update.attr, + &dev_attr_region_label_delete.attr, + NULL +}; + +static struct attribute_group cxl_pmem_region_group =3D { + .attrs =3D cxl_pmem_region_attrs, +}; + static const struct attribute_group *cxl_pmem_region_attribute_groups[] = =3D { &cxl_base_attribute_group, - NULL, + &cxl_pmem_region_group, + NULL }; =20 const struct device_type cxl_pmem_region_type =3D { diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 0d576b359de6..f01f8c942fdf 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -484,6 +484,7 @@ enum cxl_config_state { */ struct cxl_region_params { enum cxl_config_state state; + int region_label_state; uuid_t uuid; int interleave_ways; int interleave_granularity; --=20 2.34.1 From nobody Thu Oct 2 10:49:36 2025 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (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 CC23E3705A2 for ; Wed, 17 Sep 2025 13:42:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.33 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116538; cv=none; b=qifZ6OvL0jqUTuop/0XWzx0XW9OdzxQbjs4aWQjXr2PemJiEh0Mw2dxTp8P9TgQG2FtY6X7F2BvgGNIwTLMMgQa2x50Ms7EwxLTmiclvHdZ8YH3hPIz7CUIgQxzxuw4+bTUmZHXbvdQ9REbHk+jbEBf5tNDG5GinjY8FFVs9+4s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1758116538; c=relaxed/simple; bh=bBNRVqm0xNP2bUegYaeeW1aFmcjZpJaGNmJt5fBNr4k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=a6giaSCS0znmHAQWtz0tbVQl+vcJjcR3Cm/FgOkMcYIrmZo+hMDVxiW2sCllKEZNsg2TkGfhV/GKh55nzFlwjQjFuXw5YJo/qrTfWW2BTJzXKwREtEcuBzdbJfDsrazkrG7sE9uPcTjblpR1osfQPT2c5QI8vz5YS4lpM4eufdA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com; spf=pass smtp.mailfrom=samsung.com; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b=NjJfTOyw; arc=none smtp.client-ip=203.254.224.33 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=samsung.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="NjJfTOyw" Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20250917134215epoutp03d177504657ac660a33541616fa8a9c85~mFayJkiST0929209292epoutp03Y for ; Wed, 17 Sep 2025 13:42:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20250917134215epoutp03d177504657ac660a33541616fa8a9c85~mFayJkiST0929209292epoutp03Y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1758116535; bh=47MZ+V0NL7IUSooPzfSTYCMJEyy6bhIfvUpbYlXE654=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NjJfTOywhvVtgdV3eRZnWqlx3a+J3GUZGZI+F9sUu/ahIk/LcRVbQFzX4yXtGa/Qy E2l2xa6ooK9aUyQ2iec4JkHb6bta5sTUfdfous+i4DY8L3fZehX6FLsYl4dttOEQRe bxEqPUR2KRXcn7kmwxjtMgrk6FruWS30Ne3Z0JZs= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPS id 20250917134214epcas5p102f95878dcffde6551eff24b69ddeb95~mFaxy6AHd1744017440epcas5p16; Wed, 17 Sep 2025 13:42:14 +0000 (GMT) Received: from epcas5p2.samsung.com (unknown [182.195.38.89]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4cRg1K75dHz6B9m6; Wed, 17 Sep 2025 13:42:13 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20250917134213epcas5p139ba10deb2f4361f9bbab8e8490c4720~mFawftC-y3219032190epcas5p1o; Wed, 17 Sep 2025 13:42:13 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20250917134211epsmtip219794a6baeaefdd01da7969c3905321b~mFautZlRJ0952109521epsmtip2F; Wed, 17 Sep 2025 13:42:11 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, cpgs@samsung.com, Neeraj Kumar Subject: [PATCH V3 20/20] cxl/pmem: Add CXL LSA 2.1 support in cxl pmem Date: Wed, 17 Sep 2025 19:11:16 +0530 Message-Id: <20250917134116.1623730-21-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250917134116.1623730-1-s.neeraj@samsung.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-CMS-MailID: 20250917134213epcas5p139ba10deb2f4361f9bbab8e8490c4720 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P X-CPGSPASS: Y cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20250917134213epcas5p139ba10deb2f4361f9bbab8e8490c4720 References: <20250917134116.1623730-1-s.neeraj@samsung.com> Add support of CXL LSA 2.1 using NDD_REGION_LABELING flag. It creates cxl region based on region information parsed from LSA. Signed-off-by: Neeraj Kumar --- drivers/cxl/core/pmem_region.c | 53 ++++++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 4 +++ drivers/cxl/pmem.c | 2 ++ 3 files changed, 59 insertions(+) diff --git a/drivers/cxl/core/pmem_region.c b/drivers/cxl/core/pmem_region.c index 665b603c907b..3ef9c7d15041 100644 --- a/drivers/cxl/core/pmem_region.c +++ b/drivers/cxl/core/pmem_region.c @@ -290,3 +290,56 @@ int devm_cxl_add_pmem_region(struct cxl_region *cxlr) return rc; } EXPORT_SYMBOL_NS_GPL(devm_cxl_add_pmem_region, "CXL"); + +static int match_free_ep_decoder(struct device *dev, const void *data) +{ + struct cxl_decoder *cxld =3D to_cxl_decoder(dev); + + return !cxld->region; +} + +static struct cxl_decoder *cxl_find_free_ep_decoder(struct cxl_port *port) +{ + struct device *dev; + + dev =3D device_find_child(&port->dev, NULL, match_free_ep_decoder); + if (!dev) + return NULL; + + /* Release device ref taken via device_find_child() */ + put_device(dev); + return to_cxl_decoder(dev); +} + +void create_pmem_region(struct nvdimm *nvdimm) +{ + struct cxl_nvdimm *cxl_nvd; + struct cxl_memdev *cxlmd; + struct cxl_pmem_region_params *params; + struct cxl_root_decoder *cxlrd; + struct cxl_decoder *cxld; + struct cxl_region *cxlr; + + if (!nvdimm_has_cxl_region(nvdimm)) + return; + + lockdep_assert_held(&cxl_rwsem.region); + cxl_nvd =3D nvdimm_provider_data(nvdimm); + params =3D nvdimm_get_cxl_region_param(nvdimm); + cxlmd =3D cxl_nvd->cxlmd; + cxlrd =3D cxlmd->cxlrd; + + /* TODO: Region creation support only for interleave way =3D=3D 1 */ + if (!(params->nlabel =3D=3D 1)) + dev_info(&cxlmd->dev, + "Region Creation is not supported with iw > 1\n"); + else { + cxld =3D cxl_find_free_ep_decoder(cxlmd->endpoint); + cxlr =3D cxl_create_region(cxlrd, CXL_PARTMODE_PMEM, + atomic_read(&cxlrd->region_id), + params, cxld); + if (IS_ERR(cxlr)) + dev_info(&cxlmd->dev, "Region Creation failed\n"); + } +} +EXPORT_SYMBOL_NS_GPL(create_pmem_region, "CXL"); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index f01f8c942fdf..0a87ea79742a 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -910,6 +910,7 @@ cxl_create_region(struct cxl_root_decoder *cxlrd, bool is_cxl_pmem_region(struct device *dev); struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev); int devm_cxl_add_pmem_region(struct cxl_region *cxlr); +void create_pmem_region(struct nvdimm *nvdimm); #else static inline bool is_cxl_pmem_region(struct device *dev) { @@ -923,6 +924,9 @@ static inline int devm_cxl_add_pmem_region(struct cxl_r= egion *cxlr) { return 0; } +static inline void create_pmem_region(struct nvdimm *nvdimm) +{ +} #endif =20 void cxl_endpoint_parse_cdat(struct cxl_port *port); diff --git a/drivers/cxl/pmem.c b/drivers/cxl/pmem.c index 38a5bcdc68ce..0cdef01dbc68 100644 --- a/drivers/cxl/pmem.c +++ b/drivers/cxl/pmem.c @@ -135,6 +135,7 @@ static int cxl_nvdimm_probe(struct device *dev) return rc; =20 set_bit(NDD_LABELING, &flags); + set_bit(NDD_REGION_LABELING, &flags); set_bit(NDD_REGISTER_SYNC, &flags); set_bit(ND_CMD_GET_CONFIG_SIZE, &cmd_mask); set_bit(ND_CMD_GET_CONFIG_DATA, &cmd_mask); @@ -155,6 +156,7 @@ static int cxl_nvdimm_probe(struct device *dev) return -ENOMEM; =20 dev_set_drvdata(dev, nvdimm); + create_pmem_region(nvdimm); return devm_add_action_or_reset(dev, unregister_nvdimm, nvdimm); } =20 --=20 2.34.1