From nobody Sun Feb 8 20:58:37 2026 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 DD8EF29E0E6 for ; Fri, 23 Jan 2026 11:31:26 +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=1769167888; cv=none; b=QzZ/+vWRd1oIeVra9hJ2wtxZQjkPyoSaH8HbMUIuIFjIlZ5u7ybFBRpD9R9BlGZ7c4calt+r7uHMM2Pycwd4QLgiohk32neSurna5Om79YgDA3TWF13tIbM8/upbXIcCp/ztdAwE0aTGnpur2N/8ZxCBX7TfMNZthDcuMkiQPAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167888; c=relaxed/simple; bh=4qHt/xDniKwMgIY1YwmQ3xcp6PYkSm9xkRL07p9cspo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=WBU5aDYaqo3qlT1kvdckECkCb9mAfHrUXJfiKyyd/n3/MwEzF++eeTHIMykiO7xGlSaKKwafaqHoW8jYrzLKg6uQYEdqQnJVnDEm/OG8q+KFZvK3MoiSmdWrqn7GQ4eNt6HoYVy7Puh1onQhWArPWFuIQTZrOI3gINLYjyDYoUc= 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=rZ3jx9qw; 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="rZ3jx9qw" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20260123113125epoutp0191b592a1dedf969caa0c02617a0b8d66~NWNFyFtB_1520115201epoutp01X for ; Fri, 23 Jan 2026 11:31:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20260123113125epoutp0191b592a1dedf969caa0c02617a0b8d66~NWNFyFtB_1520115201epoutp01X DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167885; bh=lcO44Gsz1PNJ0v4h4R3IOLaklgF6IhzTyQAvIp2tLAc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rZ3jx9qwiXneEuhmrXK9MU8x/+fF69hIQUqhLO+mKLTvIsPQsnifrDK4L7gTXlH7i jMPBylgky0IMYH+8peBOIj2H8yazsytKpjruRWdbFWMaTyIhXUlkcMy4v8CjtrIKdM NH3uVxskBSFh+Ud9c0KIZVfGMhW5eg2iKh3LQj8M= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20260123113124epcas5p23161e0ff9be78f2df3b8c419cffb3938~NWNFiqJ5v1670216702epcas5p2J; Fri, 23 Jan 2026 11:31:24 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.89]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4dyG3J1rDnz6B9m8; Fri, 23 Jan 2026 11:31:24 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20260123113123epcas5p1cd55b845a358fccd305e655664b4f042~NWNEaF1Rd2762827628epcas5p1e; Fri, 23 Jan 2026 11:31:23 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113122epsmtip2fa77e7e4601f1a7c8bad555be188016d~NWNC1_Xgg2355523555epsmtip2e; Fri, 23 Jan 2026 11:31:21 +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, Neeraj Kumar Subject: [PATCH V6 01/18] nvdimm/label: Introduce NDD_REGION_LABELING flag to set region label Date: Fri, 23 Jan 2026 17:00:55 +0530 Message-Id: <20260123113112.3488381-2-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113123epcas5p1cd55b845a358fccd305e655664b4f042 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113123epcas5p1cd55b845a358fccd305e655664b4f042 References: <20260123113112.3488381-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 Reviewed-by: Ira Weiny Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang Signed-off-by: Neeraj Kumar --- 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 2f6c26cc6a3e..07f5c5d5e537 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_region_label_supported(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 e1349ef5f8fd..3363a97cc5b5 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_region_label_supported(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 b199eea3260e..f631bd84d6f0 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_region_label_supported(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 Sun Feb 8 20:58:37 2026 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 EF8C92EA168 for ; Fri, 23 Jan 2026 11:31:28 +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=1769167890; cv=none; b=l8bcNB9lQtq7M2jQZFtZOeTIz89615gJOIU7ZeOVB9i639fmDCY0crD0z74cS4aTctpjcc5p6wBotrPX5rCJK66CVAVUPb/wUpvybY+KMmg+vWYV46dYBnR4EQVHK0fLuvIx7ZhiY1fNq+zchYUFault7wEbH84rWYBa3WsBVT8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167890; c=relaxed/simple; bh=KM24CjqoMDDe8npGaVVcWzJfF1oRGcGBwVm4lwATVU0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=EOz+rPGc8VXmbtaW/Xi165YpH7EaxNKEHa2wBv2B6o8MSl5yw6aXJXSJJGSJCoCItWjv6K2uyMeMcRGidZWh1WdKS2YXS8rdXy+2gYjz/QaPDybAgyZxR+rpm/olrgKl/y2Hv05dJS+Sd8nDPYbX6sLoysKV67sNcR+LrP5EGiw= 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=sZCszZMv; 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="sZCszZMv" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20260123113127epoutp03e2e0d3e07840ffb378d9496387577026~NWNHgpcfn2123021230epoutp032 for ; Fri, 23 Jan 2026 11:31:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20260123113127epoutp03e2e0d3e07840ffb378d9496387577026~NWNHgpcfn2123021230epoutp032 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167887; bh=XCGgkoYzmHDoS6RA8zyIHNIs3/xy9sGJph2JjO1aG/Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sZCszZMv3csjHpp93359S3O57dmnEPMGAXSYF7fgmnXed54IE8nVRY68LRRm1tdWB Y9JuSSYuk5ofQ2H6lrncFQNexw95URuKC5Q12nC8KsV4Egoafb299TUeS45UKkl/cU 9itL62tNF0T0hQICgD0wRKAGWctTV1XfTHE7mnJU= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPS id 20260123113126epcas5p313cae7f1d85a00b38e87ba641037513a~NWNHJvvno1446414464epcas5p3f; Fri, 23 Jan 2026 11:31:26 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.95]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4dyG3L02S9z6B9m4; Fri, 23 Jan 2026 11:31:26 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20260123113125epcas5p2331d76ce8aee6d594dbdd5b3e75e7d6f~NWNF-I7Dz1670216702epcas5p2L; Fri, 23 Jan 2026 11:31:25 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113124epsmtip26c00a84ba699a3bb67c8331a9a2efb37~NWNExDnPz2685626856epsmtip2C; Fri, 23 Jan 2026 11:31:23 +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, Neeraj Kumar Subject: [PATCH V6 02/18] nvdimm/label: CXL labels skip the need for 'interleave-set cookie' Date: Fri, 23 Jan 2026 17:00:56 +0530 Message-Id: <20260123113112.3488381-3-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113125epcas5p2331d76ce8aee6d594dbdd5b3e75e7d6f X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113125epcas5p2331d76ce8aee6d594dbdd5b3e75e7d6f References: <20260123113112.3488381-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 Reviewed-by: Jonathan Cameron Acked-by: Ira Weiny Reviewed-by: Dave Jiang Signed-off-by: Neeraj Kumar --- 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 a5edcacfe46d..43fdb806532e 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -1678,7 +1678,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 1220530a23b6..77f36a585f13 100644 --- a/drivers/nvdimm/region_devs.c +++ b/drivers/nvdimm/region_devs.c @@ -841,6 +841,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 Sun Feb 8 20:58:37 2026 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 AAA183358D3 for ; Fri, 23 Jan 2026 11:31:30 +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=1769167893; cv=none; b=YXSBKQEiQrFWeGQKiMFPFld3MEqowJX1XGfe09XoxnLq1Dp0t1xAqiB7Ka6xOxbx1Kv8MA6Qw+bxYsVeS7uIiyMCRB3MgaVW7Dq3P/0aXn3TSPvIM5gJcEMdUPnTTU7M3npPFO/Q4DtgovQu5EbyBlzaIOrH9o2iVzbuUANOFuM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167893; c=relaxed/simple; bh=TKkEjxR2DwEAT9rQTEuAf1qpQerdS5gNRbSua4ETWNU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=ntNImXgPUS+AR1nXoTFKpfm/+rPBPlZET6hMqrK+qbgp8iFgp5QLOPSjTT2FPWfJBhzjHSC6Dry8O0/oOIV5ufPDCF5OtZEFoBoZCgxC8jDVs+2qDTDyIBmb+yPHcJIxQ9QOLgg8p8PTQ1nvVxisT23bTQs/ZurcS1u/dVHl5k0= 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=hORDD7jI; 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="hORDD7jI" Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20260123113129epoutp01b038be8b656f6e4b290de132d62fd256~NWNJY7YXn1946719467epoutp01M for ; Fri, 23 Jan 2026 11:31:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20260123113129epoutp01b038be8b656f6e4b290de132d62fd256~NWNJY7YXn1946719467epoutp01M DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167889; bh=8/FuXEmDi1NDYdANSjMVDLBqG+YoZtWtapZA0q0Tt34=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hORDD7jIz8VTgdeDHanRyJtCjjCrmOjxVaKxmUqZSGzSuIfMhItnVF3WrA3SyR1Ry TGTde6NeFwecKETyRYPCwQnoJlQxQ3ih02pUV7N00U4MQ6rk57j+3Bdqt49wdIScsN rjLqXAVcvPDo0zR0wh2C1/yNOj8QvwhCwOVwN+R8= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPS id 20260123113128epcas5p1bb0d8f39a3897733dae403eeed0b5cc6~NWNJHCZS52520225202epcas5p14; Fri, 23 Jan 2026 11:31:28 +0000 (GMT) Received: from epcas5p3.samsung.com (unknown [182.195.38.91]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4dyG3N0WpZz6B9m8; Fri, 23 Jan 2026 11:31:28 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20260123113127epcas5p2c03d8e1749dc7e266870cc55eda31822~NWNH8znlF1735017350epcas5p2L; Fri, 23 Jan 2026 11:31:27 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113125epsmtip2818659cb672dc81e67b2606019e19927~NWNGU2lLe2681126811epsmtip2M; Fri, 23 Jan 2026 11:31:25 +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, Neeraj Kumar Subject: [PATCH V6 03/18] nvdimm/label: Add namespace/region label support as per LSA 2.1 Date: Fri, 23 Jan 2026 17:00:57 +0530 Message-Id: <20260123113112.3488381-4-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113127epcas5p2c03d8e1749dc7e266870cc55eda31822 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113127epcas5p2c03d8e1749dc7e266870cc55eda31822 References: <20260123113112.3488381-1-s.neeraj@samsung.com> Modify __pmem_label_update() to update region labels into LSA CXL 3.2 Spec mentions CXL LSA 2.1 Namespace Labels at section 9.13.2.5 Modified __pmem_label_update() using setter functions to update namespace label as per CXL LSA 2.1 Create export routine nd_region_label_update() used for creating region label into LSA. It will be used later from CXL subsystem Reviewed-by: Ira Weiny Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang Signed-off-by: Neeraj Kumar --- drivers/nvdimm/label.c | 360 ++++++++++++++++++++++++++------ drivers/nvdimm/label.h | 17 +- drivers/nvdimm/namespace_devs.c | 20 +- drivers/nvdimm/nd.h | 56 +++++ include/linux/libnvdimm.h | 8 + 5 files changed, 391 insertions(+), 70 deletions(-) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index 0a9b6c5cb2c3..06c6e23abf4e 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -22,8 +22,8 @@ static uuid_t nvdimm_btt2_uuid; static uuid_t nvdimm_pfn_uuid; static uuid_t nvdimm_dax_uuid; =20 -static uuid_t cxl_region_uuid; -static uuid_t cxl_namespace_uuid; +uuid_t cxl_region_uuid; +uuid_t cxl_namespace_uuid; =20 static const char NSINDEX_SIGNATURE[] =3D "NAMESPACE_INDEX\0"; =20 @@ -278,15 +278,38 @@ static struct nd_namespace_label *nd_label_base(struc= t nvdimm_drvdata *ndd) return base + 2 * sizeof_namespace_index(ndd); } =20 +static unsigned long find_slot(struct nvdimm_drvdata *ndd, + unsigned long label) +{ + unsigned long base; + + base =3D (unsigned long)nd_label_base(ndd); + return (label - base) / sizeof_namespace_label(ndd); +} + +static int to_lsa_slot(struct nvdimm_drvdata *ndd, + union nd_lsa_label *lsa_label) +{ + return find_slot(ndd, (unsigned long) lsa_label); +} + static int to_slot(struct nvdimm_drvdata *ndd, - struct nd_namespace_label *nd_label) + struct nd_label_ent *label_ent) +{ + if (uuid_equal(&cxl_region_uuid, &label_ent->label_uuid)) + return find_slot(ndd, (unsigned long) label_ent->region_label); + else + return find_slot(ndd, (unsigned long) label_ent->label); +} + +static union nd_lsa_label *to_lsa_label(struct nvdimm_drvdata *ndd, int sl= ot) { unsigned long label, base; =20 - label =3D (unsigned long) nd_label; base =3D (unsigned long) nd_label_base(ndd); + label =3D base + sizeof_namespace_label(ndd) * slot; =20 - return (label - base) / sizeof_namespace_label(ndd); + return (union nd_lsa_label *) label; } =20 static struct nd_namespace_label *to_label(struct nvdimm_drvdata *ndd, int= slot) @@ -381,6 +404,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->checksum =3D __cpu_to_le64(0); + sum =3D nd_fletcher64(region_label, sizeof_namespace_label(ndd), 1); + region_label->checksum =3D __cpu_to_le64(sum); +} + static bool slot_valid(struct nvdimm_drvdata *ndd, struct nd_namespace_label *nd_label, u32 slot) { @@ -584,7 +617,7 @@ int nd_label_active_count(struct nvdimm_drvdata *ndd) return count; } =20 -struct nd_namespace_label *nd_label_active(struct nvdimm_drvdata *ndd, int= n) +union nd_lsa_label *nd_label_active(struct nvdimm_drvdata *ndd, int n) { struct nd_namespace_index *nsindex; unsigned long *free; @@ -601,7 +634,7 @@ struct nd_namespace_label *nd_label_active(struct nvdim= m_drvdata *ndd, int n) continue; =20 if (n-- =3D=3D 0) - return to_label(ndd, slot); + return to_lsa_label(ndd, slot); } =20 return NULL; @@ -737,9 +770,9 @@ static int nd_label_write_index(struct nvdimm_drvdata *= ndd, int index, u32 seq, } =20 static unsigned long nd_label_offset(struct nvdimm_drvdata *ndd, - struct nd_namespace_label *nd_label) + union nd_lsa_label *lsa_label) { - return (unsigned long) nd_label + return (unsigned long) lsa_label - (unsigned long) to_namespace_index(ndd, 0); } =20 @@ -823,11 +856,15 @@ static void reap_victim(struct nd_mapping *nd_mapping, struct nd_label_ent *victim) { struct nvdimm_drvdata *ndd =3D to_ndd(nd_mapping); - u32 slot =3D to_slot(ndd, victim->label); + u32 slot =3D to_slot(ndd, victim); =20 dev_dbg(ndd->dev, "free: %d\n", slot); nd_label_free_slot(ndd, slot); - victim->label =3D NULL; + + if (uuid_equal(&cxl_region_uuid, &victim->label_uuid)) + victim->region_label =3D NULL; + else + victim->label =3D NULL; } =20 static void nsl_set_type_guid(struct nvdimm_drvdata *ndd, @@ -884,26 +921,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,33 +947,150 @@ 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 */ + export_uuid(region_label->type, &cxl_region_uuid); + + /* 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, + struct nd_label_ent *label_ent, + 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_ent->label, nspm->uuid)) + return true; + + break; + case RG_LABEL_TYPE: + if (region_label_uuid_equal(label_ent->region_label, + &nd_set->uuid)) + return true; + + break; + } + + return false; +} + +static bool is_label_present(struct nd_label_ent *label_ent, + enum label_type ltype) +{ + switch (ltype) { + case NS_LABEL_TYPE: + if (label_ent->label) + return true; + + break; + case RG_LABEL_TYPE: + if (label_ent->region_label) + 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_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_type_guid(ndd, nd_label, &nd_set->type_guid); - 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 to_lsa_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); + rc =3D nvdimm_set_config_data(ndd, offset, lsa_label, sizeof_namespace_label(ndd)); if (rc < 0) return rc; @@ -950,10 +1098,11 @@ static int __pmem_label_update(struct nd_region *nd_= region, /* Garbage collect the previous label */ mutex_lock(&nd_mapping->lock); list_for_each_entry(label_ent, &nd_mapping->labels, list) { - if (!label_ent->label) + if (!is_label_present(label_ent, ltype)) 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, label_ent, ltype, + &label_ent->flags)) reap_victim(nd_mapping, label_ent); } =20 @@ -961,16 +1110,21 @@ static int __pmem_label_update(struct nd_region *nd_= region, 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) + list_for_each_entry(label_ent, &nd_mapping->labels, list) { + if (is_label_present(label_ent, ltype)) + continue; + + if (ltype =3D=3D NS_LABEL_TYPE) + label_ent->label =3D &lsa_label->ns_label; + else + label_ent->region_label =3D &lsa_label->region_label; + + lsa_label =3D NULL; + break; + } + dev_WARN_ONCE(dev, lsa_label, "failed to track label: %d\n", + to_lsa_slot(ndd, lsa_label)); + if (lsa_label) rc =3D -ENXIO; } mutex_unlock(&nd_mapping->lock); @@ -978,7 +1132,8 @@ static int __pmem_label_update(struct nd_region *nd_re= gion, return rc; } =20 -static int init_labels(struct nd_mapping *nd_mapping, int num_labels) +static int init_labels(struct nd_mapping *nd_mapping, int num_labels, + enum label_type ltype) { int i, old_num_labels =3D 0; struct nd_label_ent *label_ent; @@ -998,6 +1153,16 @@ static int init_labels(struct nd_mapping *nd_mapping,= int num_labels) label_ent =3D kzalloc(sizeof(*label_ent), GFP_KERNEL); if (!label_ent) return -ENOMEM; + + switch (ltype) { + case NS_LABEL_TYPE: + uuid_copy(&label_ent->label_uuid, &cxl_namespace_uuid); + break; + case RG_LABEL_TYPE: + uuid_copy(&label_ent->label_uuid, &cxl_region_uuid); + break; + } + mutex_lock(&nd_mapping->lock); list_add_tail(&label_ent->list, &nd_mapping->labels); mutex_unlock(&nd_mapping->lock); @@ -1041,19 +1206,19 @@ static int del_labels(struct nd_mapping *nd_mapping= , uuid_t *uuid) =20 mutex_lock(&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; - - if (!nd_label) + if (label_ent->label) continue; active++; - if (!nsl_uuid_equal(ndd, nd_label, uuid)) + if (!nsl_uuid_equal(ndd, label_ent->label, uuid)) continue; active--; - slot =3D to_slot(ndd, nd_label); + slot =3D to_slot(ndd, label_ent); nd_label_free_slot(ndd, slot); dev_dbg(ndd->dev, "free: %d\n", slot); list_move_tail(&label_ent->list, &list); - label_ent->label =3D NULL; + + if (uuid_equal(&cxl_namespace_uuid, &label_ent->label_uuid)) + label_ent->label =3D NULL; } list_splice_tail_init(&list, &nd_mapping->labels); =20 @@ -1067,6 +1232,19 @@ 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 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 (uuid_equal(&cxl_region_uuid, &label_ent->label_uuid)) + 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) { @@ -1075,6 +1253,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; struct resource *res; int count =3D 0; =20 @@ -1090,12 +1269,20 @@ 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(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, + NS_LABEL_TYPE); 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; } @@ -1107,7 +1294,48 @@ 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; + + /* No need to update region label for non cxl format */ + if (!ndd->cxl) + return 0; + + region_label_cnt =3D find_region_label_count(nd_mapping); + rc =3D init_labels(nd_mapping, region_label_cnt + 1, + RG_LABEL_TYPE); + 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..f11f54056353 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" @@ -215,7 +229,7 @@ struct nvdimm_drvdata; int nd_label_data_init(struct nvdimm_drvdata *ndd); size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd); int nd_label_active_count(struct nvdimm_drvdata *ndd); -struct nd_namespace_label *nd_label_active(struct nvdimm_drvdata *ndd, int= n); +union nd_lsa_label *nd_label_active(struct nvdimm_drvdata *ndd, int n); u32 nd_label_alloc_slot(struct nvdimm_drvdata *ndd); bool nd_label_free_slot(struct nvdimm_drvdata *ndd, u32 slot); u32 nd_label_nfree(struct nvdimm_drvdata *ndd); @@ -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 43fdb806532e..657004021c95 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -232,6 +232,13 @@ 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) +{ + guard(nvdimm_bus)(&nd_region->dev); + return nd_pmem_region_label_update(nd_region); +} +EXPORT_SYMBOL_GPL(nd_region_label_update); + static int nd_namespace_label_update(struct nd_region *nd_region, struct device *dev) { @@ -2122,13 +2129,20 @@ static int init_active_labels(struct nd_region *nd_= region) if (!count) continue; for (j =3D 0; j < count; j++) { - struct nd_namespace_label *label; + union nd_lsa_label *lsa_label; =20 label_ent =3D kzalloc(sizeof(*label_ent), GFP_KERNEL); if (!label_ent) break; - label =3D nd_label_active(ndd, j); - label_ent->label =3D label; + + lsa_label =3D nd_label_active(ndd, j); + if (is_region_label(ndd, lsa_label)) { + label_ent->region_label =3D &lsa_label->region_label; + uuid_copy(&label_ent->label_uuid, &cxl_region_uuid); + } else { + label_ent->label =3D &lsa_label->ns_label; + uuid_copy(&label_ent->label_uuid, &cxl_namespace_uuid); + } =20 mutex_lock(&nd_mapping->lock); list_add_tail(&label_ent->list, &nd_mapping->labels); diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h index f631bd84d6f0..14cdc3e927b4 100644 --- a/drivers/nvdimm/nd.h +++ b/drivers/nvdimm/nd.h @@ -14,6 +14,9 @@ #include #include "label.h" =20 +extern uuid_t cxl_namespace_uuid; +extern uuid_t cxl_region_uuid; + enum { /* * Limits the maximum number of block apertures a dimm can @@ -295,6 +298,57 @@ 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)) + return; + + export_uuid(ns_label->cxl.type, &cxl_namespace_uuid); +} + +static inline void nsl_set_alignment(struct nvdimm_drvdata *ndd, + struct nd_namespace_label *ns_label, + u32 align) +{ + if (!ndd->cxl) + return; + + 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)) + return; + + export_uuid(ns_label->cxl.region_uuid, uuid); +} + +static inline bool is_region_label(struct nvdimm_drvdata *ndd, + union nd_lsa_label *lsa_label) +{ + uuid_t tmp; + + if (!ndd->cxl) + return false; + + import_uuid(&tmp, lsa_label->region_label.type); + return uuid_equal(&tmp, &cxl_region_uuid); +} + +static inline bool +region_label_uuid_equal(struct cxl_region_label *region_label, + const uuid_t *uuid) +{ + uuid_t tmp; + + import_uuid(&tmp, region_label->uuid); + return uuid_equal(&tmp, 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, @@ -376,7 +430,9 @@ enum nd_label_flags { struct nd_label_ent { struct list_head list; unsigned long flags; + uuid_t label_uuid; 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 Sun Feb 8 20:58:37 2026 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 D504934CFD9 for ; Fri, 23 Jan 2026 11:31:32 +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=1769167895; cv=none; b=NuxOMAnuqfmLAz4QS9wrRLYd+BrlXSiCuU/G1lQoX9lvxqKrJNoVut9fmVULR+3Xr1JNZG/GBGxgp4FbwYkUfuy9aSIhnvXLa4RvOABOWbLeZz+A4RZsCNoWAF+bKwIp5Pc5xwQ1qrBSK+t6JIqCdeiMWpBHpLhx89WG1TKxyiE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167895; c=relaxed/simple; bh=PYZkwLELAugEwacQUtSNEErxPE1uGggbBLL1aLVqmgM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=kqFWKKgnizb48ith1NRrYfKvuvyx4h1uMdT6YwxC9DUd2heD9dLYlYxgNWETIpFH2dO/5WaMLyTkYFH61velJ22Cr0wWImRGQ2ZHCk54QrbcM4ptwAIsMFcqDy5iJvWihOy2K5RLiq0rzA83dGJIi6441aNdCL+Mz5fvtBHHJKo= 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=XCv/vx3z; 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="XCv/vx3z" Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20260123113131epoutp02f9ae99e4d29b985cf885789478f7de55~NWNLa-nB20069400694epoutp02Y for ; Fri, 23 Jan 2026 11:31:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20260123113131epoutp02f9ae99e4d29b985cf885789478f7de55~NWNLa-nB20069400694epoutp02Y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167891; bh=tI9VZASa/xswWxnMaIHEtR5FaxfRWnY49pqQx0aGKSw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XCv/vx3zFLOVkaj4dSf+RUENIu8k/sTD2qfFQTYDKQTZtcBlFxrIcfYREhRHP+BWs 16xmg6NKps1cYD3ZupsXIa/t8axP4HX5aI9ieuDx5c0Os7liispYlNewTubEVz0bl/ jZ79QUMwDWzHCFzT0uS99dK3K4upT5grQNtkBPf0= Received: from epsnrtp03.localdomain (unknown [182.195.42.155]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPS id 20260123113130epcas5p45491161bec49e9a1cf1737f0bf34cdb5~NWNKy8ZIw1497514975epcas5p4L; Fri, 23 Jan 2026 11:31:30 +0000 (GMT) Received: from epcas5p1.samsung.com (unknown [182.195.38.93]) by epsnrtp03.localdomain (Postfix) with ESMTP id 4dyG3P6Ryyz3hhT8; Fri, 23 Jan 2026 11:31:29 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20260123113129epcas5p26bb834be2b841296ca1b3fff1a44ab76~NWNJd4ipz1735017350epcas5p2P; Fri, 23 Jan 2026 11:31:29 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113127epsmtip2d0d404ae6749aca5ebc88a93278017a7~NWNINOwsx2355523555epsmtip2j; Fri, 23 Jan 2026 11:31:27 +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, Neeraj Kumar Subject: [PATCH V6 04/18] nvdimm/label: Include region label in slot validation Date: Fri, 23 Jan 2026 17:00:58 +0530 Message-Id: <20260123113112.3488381-5-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113129epcas5p26bb834be2b841296ca1b3fff1a44ab76 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113129epcas5p26bb834be2b841296ca1b3fff1a44ab76 References: <20260123113112.3488381-1-s.neeraj@samsung.com> Prior to LSA 2.1 Support, label in slot means only namespace label. But with LSA 2.1 a label can be either namespace or region label. Slot validation routine validates label slot by calculating label checksum. It was only validating namespace label. This changeset also validates region label if present. In previous patch to_lsa_label() was introduced along with to_label(). to_label() returns only namespace label whereas to_lsa_label() returns union nd_lsa_label* Convert all usage of to_label() to to_lsa_label() Reviewed-by: Ira Weiny Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang Signed-off-by: Neeraj Kumar --- drivers/nvdimm/label.c | 94 +++++++++++++++++++++++++++++------------- 1 file changed, 65 insertions(+), 29 deletions(-) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index 06c6e23abf4e..5a4599c5e5a8 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -312,16 +312,6 @@ static union nd_lsa_label *to_lsa_label(struct nvdimm_= drvdata *ndd, int slot) return (union nd_lsa_label *) label; } =20 -static struct nd_namespace_label *to_label(struct nvdimm_drvdata *ndd, int= slot) -{ - unsigned long label, base; - - base =3D (unsigned long) nd_label_base(ndd); - label =3D base + sizeof_namespace_label(ndd) * slot; - - return (struct nd_namespace_label *) label; -} - #define for_each_clear_bit_le(bit, addr, size) \ for ((bit) =3D find_next_zero_bit_le((addr), (size), 0); \ (bit) < (size); \ @@ -382,7 +372,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); @@ -397,13 +387,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 __le64_to_cpu(region_label->checksum); + region_label->checksum =3D __cpu_to_le64(0); + sum =3D nd_fletcher64(region_label, sizeof_namespace_label(ndd), 1); + region_label->checksum =3D __cpu_to_le64(sum_save); + return sum =3D=3D sum_save; +} + static void region_label_calculate_checksum(struct nvdimm_drvdata *ndd, struct cxl_region_label *region_label) { @@ -415,16 +417,36 @@ 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; + struct nd_namespace_label *nd_label; + enum label_type type; bool valid; + static const char * const label_name[] =3D { + [RG_LABEL_TYPE] =3D "region", + [NS_LABEL_TYPE] =3D "namespace", + }; =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)) { + region_label =3D &lsa_label->region_label; + type =3D RG_LABEL_TYPE; + if (slot !=3D __le32_to_cpu(region_label->slot)) + return false; + valid =3D region_label_validate_checksum(ndd, region_label); + } else { + nd_label =3D &lsa_label->ns_label; + type =3D NS_LABEL_TYPE; + 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[type], slot); + return valid; } =20 @@ -440,14 +462,16 @@ int nd_label_reserve_dpa(struct nvdimm_drvdata *ndd) for_each_clear_bit_le(slot, free, nslot) { struct nd_namespace_label *nd_label; struct nd_region *nd_region =3D NULL; + union nd_lsa_label *lsa_label; struct nd_label_id label_id; struct resource *res; uuid_t label_uuid; u32 flags; =20 - nd_label =3D to_label(ndd, slot); + lsa_label =3D to_lsa_label(ndd, slot); + nd_label =3D &lsa_label->ns_label; =20 - if (!slot_valid(ndd, nd_label, slot)) + if (!slot_valid(ndd, lsa_label, slot)) continue; =20 nsl_get_uuid(ndd, nd_label, &label_uuid); @@ -598,14 +622,26 @@ 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 label_slot; + u64 size, dpa; + + lsa_label =3D to_lsa_label(ndd, slot); + + if (!slot_valid(ndd, lsa_label, slot)) { + if (is_region_label(ndd, lsa_label)) { + region_label =3D &lsa_label->region_label; + label_slot =3D __le32_to_cpu(region_label->slot); + size =3D __le64_to_cpu(region_label->rawsize); + dpa =3D __le64_to_cpu(region_label->dpa); + } else { + nd_label =3D &lsa_label->ns_label; + label_slot =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", @@ -627,10 +663,10 @@ union nd_lsa_label *nd_label_active(struct nvdimm_drv= data *ndd, int n) return NULL; =20 for_each_clear_bit_le(slot, free, nslot) { - struct nd_namespace_label *nd_label; + union nd_lsa_label *lsa_label; =20 - nd_label =3D to_label(ndd, slot); - if (!slot_valid(ndd, nd_label, slot)) + lsa_label =3D to_lsa_label(ndd, slot); + if (!slot_valid(ndd, lsa_label, slot)) continue; =20 if (n-- =3D=3D 0) --=20 2.34.1 From nobody Sun Feb 8 20:58:37 2026 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 92F7A361DA1 for ; Fri, 23 Jan 2026 11:31:34 +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=1769167897; cv=none; b=Olgef7GvM/rmU9UVYrbnBnJ70cQzFjJAPPH5q6TU/5fZQ+iHcvJ0nNoPfY4WkMYmAk00ZBqIKGhlnoyiI5r6zqJ/iz4DUgyyjsgcwaJjZhqItGBmGqQFrr0HNj3g/mUrL1n8+JGThGpbZ7mXSo6uWXIe1BPBvIwCEjmgROXcyb0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167897; c=relaxed/simple; bh=Hc/LE7S7ygoxfL1UA2Iyub7zUbzQXaayt+Tz65QkZn8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=stkrs0+M4b/QYBI/nLl4L5x8+6/h1BDt+1OXwJzjQUgptTrfKCk4EW7d0AALMSdPwPM80lLoRzrmVWuSRgw+LoJy/YahQhYIDw7SlRTE64HEhUgBCLenfm3Srj1vJJD7Si0bXQ2gVyg9pqFE8JiFDa0mLgsCIE6EdxazRoSIbxk= 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=qVk48t7r; 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="qVk48t7r" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20260123113132epoutp0300fbe65e7fd3997dd16cf645a5bd9a67~NWNMhRhCA2123021230epoutp035 for ; Fri, 23 Jan 2026 11:31:32 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20260123113132epoutp0300fbe65e7fd3997dd16cf645a5bd9a67~NWNMhRhCA2123021230epoutp035 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167892; bh=Je8+tDbOogLpQy7XjpQXu4atLQSWU6GOTBA3BV7GROo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qVk48t7rNumOt8D0O9yoskYMiaceW+RmkLVQrS4jMP8nRuJ8Jay9MZ1LsY+ClSZsq ote5Nc+XWjKV11kRD4sxTuHlfNr7K41W7hEY32rhE8otFemV7F8Eo47q4QQJsQlApa FDP6WHxMx8WHVLrg3UWrhT/cl77701GhJrnxYweo= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPS id 20260123113132epcas5p41fd35b87847b41fdbf7a52442830c77a~NWNMSjANm1464914649epcas5p4Q; Fri, 23 Jan 2026 11:31:32 +0000 (GMT) Received: from epcas5p2.samsung.com (unknown [182.195.38.91]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4dyG3R3jTyz6B9mB; Fri, 23 Jan 2026 11:31:31 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20260123113130epcas5p4af26a172d155a1c8b78d33945f495452~NWNKynEhY1479614796epcas5p4M; Fri, 23 Jan 2026 11:31:30 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113129epsmtip25f735015777e2fb8aa9661dc713ff0e3~NWNJs7vBO2355523555epsmtip2k; Fri, 23 Jan 2026 11:31: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, Neeraj Kumar Subject: [PATCH V6 05/18] nvdimm/label: Skip region label during ns label DPA reservation Date: Fri, 23 Jan 2026 17:00:59 +0530 Message-Id: <20260123113112.3488381-6-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113130epcas5p4af26a172d155a1c8b78d33945f495452 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113130epcas5p4af26a172d155a1c8b78d33945f495452 References: <20260123113112.3488381-1-s.neeraj@samsung.com> CXL 3.2 Spec mentions CXL LSA 2.1 Namespace Labels at section 9.13.2.5. If Namespace label is present in LSA during nvdimm_probe() then dimm-physical-address(DPA) reservation is required. But this reservation is not required by cxl region label. Therefore if LSA scanning finds any region label, skip it. Reviewed-by: Ira Weiny Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang Signed-off-by: Neeraj Kumar --- drivers/nvdimm/label.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index 5a4599c5e5a8..f18b04f63dcc 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -471,6 +471,13 @@ int nd_label_reserve_dpa(struct nvdimm_drvdata *ndd) lsa_label =3D to_lsa_label(ndd, slot); nd_label =3D &lsa_label->ns_label; =20 + /* + * If the LSA label is a region label then it doesn't + * require a dimm-physical-address(DPA) reservation. + */ + if (is_region_label(ndd, lsa_label)) + continue; + if (!slot_valid(ndd, lsa_label, slot)) continue; =20 --=20 2.34.1 From nobody Sun Feb 8 20:58:37 2026 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 863FA366053 for ; Fri, 23 Jan 2026 11:31:35 +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=1769167898; cv=none; b=RCOFPbNQ53kcxaxLotWEGorIR9Q59cUWek1YUGIww8H7fdFShEJczozrWUI1oVqcoX+zBtX76swl8l+9vpBRUq6eIuIzpme1CrMK8UppJd3eN1KFSa6cAMYXtGlL6/vsHF+nHQPdd2y7Ap+MFmCUPTdGsQuqRrT0AOUPiLnBeOw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167898; c=relaxed/simple; bh=cQ74lHFeHeEdE+a1RS3IKKo9RhHGG1MmhaDslbqhTl0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=JURB/5OiEOiTNzxulhxN86LFhuI84pHs2lNd0baOEqaSY1QF6FavirQKo9dTb29B1LkIfIW5o7Fn1z486Y/2NUIn5NskqOW9IRYa6zPl3IqhQD9OEx/JniuuFgPvv8qD4u68bDRThAUzdsAeikPyv6Hs67qmCQ6ZMPqhegFHegc= 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=E1td/0yE; 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="E1td/0yE" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20260123113133epoutp043dc4317f21fa64a9cc16e0a706d02288~NWNNqH-2K0116501165epoutp04m for ; Fri, 23 Jan 2026 11:31:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20260123113133epoutp043dc4317f21fa64a9cc16e0a706d02288~NWNNqH-2K0116501165epoutp04m DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167893; bh=vEaz7qTizm8glHr7yEMSFLmH7n6xVHbo0062LSuKaUg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E1td/0yEwiLuRz85zCKwQ+EPI7K+r15QiLzFT+47u65fO4i+FFhtR5Xodx5HxZZfq AvSrqFI5mCJFekFLwtjFvj9JVQ4yN83rwpdLUKXjrtqiALlBHpiJ6/5r8X3UdHyLvT shQStNEVCH2woTdSFYVYHcx1qZUf4RXM1Ylkt+no= Received: from epsnrtp02.localdomain (unknown [182.195.42.154]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20260123113133epcas5p29d0a743f45f5612bc1c8071ed3b96437~NWNNTudRV1735017350epcas5p2V; Fri, 23 Jan 2026 11:31:33 +0000 (GMT) Received: from epcas5p1.samsung.com (unknown [182.195.38.93]) by epsnrtp02.localdomain (Postfix) with ESMTP id 4dyG3S42yDz2SSKb; Fri, 23 Jan 2026 11:31:32 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20260123113132epcas5p368496769470a9163183a1d5a967442e2~NWNMJKtns1446414464epcas5p3q; Fri, 23 Jan 2026 11:31:32 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113130epsmtip2a702a8ef6f1cbb4b8e13ea6e7525e173~NWNLB7Ii12621526215epsmtip20; Fri, 23 Jan 2026 11:31: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, Neeraj Kumar Subject: [PATCH V6 06/18] nvdimm/label: Preserve region label during namespace creation Date: Fri, 23 Jan 2026 17:01:00 +0530 Message-Id: <20260123113112.3488381-7-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113132epcas5p368496769470a9163183a1d5a967442e2 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113132epcas5p368496769470a9163183a1d5a967442e2 References: <20260123113112.3488381-1-s.neeraj@samsung.com> During namespace creation we scan labels present in LSA using scan_labels(). Currently scan_labels() is only preserving namespace labels into label_ent list. In this patch we also preserve region label into label_ent list Reviewed-by: Ira Weiny Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang Signed-off-by: Neeraj Kumar --- drivers/nvdimm/namespace_devs.c | 47 +++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/drivers/nvdimm/namespace_devs.c b/drivers/nvdimm/namespace_dev= s.c index 657004021c95..8411f4152319 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -1994,9 +1994,32 @@ 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++) { + struct cxl_region_label *region_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) { + region_label =3D le->region_label; + if (!region_label) + continue; + + /* Preserve region labels if present */ + 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; @@ -2008,7 +2031,7 @@ 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; + struct nd_label_ent *le, *e; LIST_HEAD(list); int j; =20 @@ -2019,10 +2042,24 @@ 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) { + /* Preserve region labels */ + if (uuid_equal(&le->label_uuid, + &cxl_region_uuid)) { + 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 Sun Feb 8 20:58:37 2026 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 7CED936F436 for ; Fri, 23 Jan 2026 11:31:37 +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=1769167899; cv=none; b=H9gzFk+DK1X7CIqA2n+WAh1LSxmi+wiEuf+iCPC//G0nxDZvTN1dB6gnkghH3WUTPEkkV+Rf+eskHN8i3PRPQ++zhjG993AqTsbSa9LOvjp1t4n1z/RFVE6V6VBnCoEXpBgZEgqJkKnr+BY5dWus3bLmZBMV878m0rVooE8jW3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167899; c=relaxed/simple; bh=EgMNhzC7a2IW9P1C/1Z2fXCMpTWugBXn80XMjtR5JqQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=E6HylSkl2ytFcfUZjOVk8s6BBbD8TDyH91rr7PbkXwkcDesfnRyXp/RYuXCM7CdMf8FB19VapTF1guLOL5Si8yOoLe6F6Kti3nP/+ZLSIBfgpKfP+4A3lTU5GcYA9JaxLVdnQZovbYQkRhOvrNt2CT7iQ3879URqGI45a07+kvY= 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=MInHJBuK; 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="MInHJBuK" Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20260123113135epoutp03b540fca9aea6b9396e843ac9e1111b50~NWNPZkqc92133521335epoutp039 for ; Fri, 23 Jan 2026 11:31:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20260123113135epoutp03b540fca9aea6b9396e843ac9e1111b50~NWNPZkqc92133521335epoutp039 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167895; bh=HlHjWUX/NwX1kOa8NWAPwT8k2Y+IDbU92VMZ2fTe4rc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MInHJBuKfKzP5oDhsQJ0yVHwotdr6wrA2cTds5ee5gTKzTjlRrcvaY05sdn2qum2H cgCeM5gzuYD2tQlTYu++5ZT8NkuJOO6i90tsL+61WVkv6e2UpnZc99wwTS1kJ61Mgv m0dIeAU2Grs/4xn2ylPrz7chaB5VQxGJqiaUteRA= Received: from epsnrtp02.localdomain (unknown [182.195.42.154]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPS id 20260123113134epcas5p1b3914dce86dc87a6257fb05ed881b932~NWNO3IdKc2520225202epcas5p1F; Fri, 23 Jan 2026 11:31:34 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.91]) by epsnrtp02.localdomain (Postfix) with ESMTP id 4dyG3V1X7bz2SSKd; Fri, 23 Jan 2026 11:31:34 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20260123113133epcas5p4989af8ca6a75569b2b47d80514e62c57~NWNNuYA202258722587epcas5p40; Fri, 23 Jan 2026 11:31:33 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113132epsmtip2f2132afbe5e1d32a42d5d46c47f1a237~NWNMatGI82685726857epsmtip2T; Fri, 23 Jan 2026 11:31: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, Neeraj Kumar Subject: [PATCH V6 07/18] nvdimm/label: Add region label delete support Date: Fri, 23 Jan 2026 17:01:01 +0530 Message-Id: <20260123113112.3488381-8-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113133epcas5p4989af8ca6a75569b2b47d80514e62c57 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113133epcas5p4989af8ca6a75569b2b47d80514e62c57 References: <20260123113112.3488381-1-s.neeraj@samsung.com> Create export routine nd_region_label_delete() used for deleting region label from LSA. It will be used later from CXL subsystem Reviewed-by: Ira Weiny Reviewed-by: Dave Jiang Reviewed-by: Jonathan Cameron Signed-off-by: Neeraj Kumar --- drivers/nvdimm/label.c | 74 ++++++++++++++++++++++++++++++--- drivers/nvdimm/label.h | 1 + drivers/nvdimm/namespace_devs.c | 7 ++++ drivers/nvdimm/nd.h | 6 +++ include/linux/libnvdimm.h | 1 + 5 files changed, 83 insertions(+), 6 deletions(-) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index f18b04f63dcc..014af60d68a1 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -1230,7 +1230,8 @@ static int init_labels(struct nd_mapping *nd_mapping,= 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; @@ -1249,11 +1250,24 @@ static int del_labels(struct nd_mapping *nd_mapping= , uuid_t *uuid) =20 mutex_lock(&nd_mapping->lock); list_for_each_entry_safe(label_ent, e, &nd_mapping->labels, list) { - if (label_ent->label) + if ((ltype =3D=3D NS_LABEL_TYPE && !label_ent->label) || + (ltype =3D=3D RG_LABEL_TYPE && !label_ent->region_label)) continue; active++; - if (!nsl_uuid_equal(ndd, label_ent->label, uuid)) - continue; + + switch (ltype) { + case NS_LABEL_TYPE: + if (!nsl_uuid_equal(ndd, label_ent->label, uuid)) + continue; + + break; + case RG_LABEL_TYPE: + if (!region_label_uuid_equal(label_ent->region_label, uuid)) + continue; + + break; + } + active--; slot =3D to_slot(ndd, label_ent); nd_label_free_slot(ndd, slot); @@ -1262,10 +1276,12 @@ static int del_labels(struct nd_mapping *nd_mapping= , uuid_t *uuid) =20 if (uuid_equal(&cxl_namespace_uuid, &label_ent->label_uuid)) label_ent->label =3D NULL; + else + label_ent->region_label =3D NULL; } 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"); } @@ -1301,7 +1317,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; @@ -1386,6 +1403,51 @@ 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 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)) { + dev_dbg(&nd_region->dev, + "Region/Namespace label in use\n"); + return -EBUSY; + } + } + } + + for (i =3D 0; i < nd_region->ndr_mappings; i++) { + rc =3D del_labels(&nd_region->mapping[i], &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 f11f54056353..80a7f7dd8ba7 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 8411f4152319..9047826138be 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -239,6 +239,13 @@ 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) +{ + guard(nvdimm_bus)(&nd_region->dev); + return nd_pmem_region_label_delete(nd_region); +} +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 14cdc3e927b4..ec856601fda0 100644 --- a/drivers/nvdimm/nd.h +++ b/drivers/nvdimm/nd.h @@ -339,6 +339,12 @@ static inline bool is_region_label(struct nvdimm_drvda= ta *ndd, return uuid_equal(&tmp, &cxl_region_uuid); } =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 Sun Feb 8 20:58:37 2026 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 568E63385AE for ; Fri, 23 Jan 2026 11:31:38 +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=1769167900; cv=none; b=PUF2U8VWxgCIhOqfiL0LVdqg/g+pHFSSXBc2z98wHM0YksVMn94zE66jdc+rMhY0NJlm/J0zWfgaMufDmGz/+trxvuwFLODBMhSnsn7zAXZOFtvbOV35ajSlONShPVLh/7rbeyVkPABjw2MxQ6Yt2a4DnwFEOfBJljUwcbeDfJU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167900; c=relaxed/simple; bh=bGIq3h9f5253GBcVTY5bbahGD6vngr120G7OmmB81Rs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=euq8jZtw3w+wBlPacT6vViMJcCHqi/Zg7OSEI/PWwSz2nvVEgS8OdUzMcDOdzS3uALvjY9+ZxAbJlt0MJRGBfJg8nM9CzB2KaaUB2QdfrhiQZXRo0bQ5kDqKM4xgjh7H/BXzfzH6d01QAx5Ngw0tmA+kyFSecaHYDmoX9uXBEKs= 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=KJ07aa0T; 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="KJ07aa0T" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20260123113136epoutp040deb49b2fe53269f3fb8a7604aced5d2~NWNQoEGHQ0297002970epoutp04b for ; Fri, 23 Jan 2026 11:31:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20260123113136epoutp040deb49b2fe53269f3fb8a7604aced5d2~NWNQoEGHQ0297002970epoutp04b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167896; bh=ibDapUD922yChN15VjqbeuJ35JsJCtKJGDjUDOa1EuE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KJ07aa0TZiJqjfA3GAgb/Aa9Gp+WplTwZB/FDnQmCdF7UN91OfjO3P2L2PDNrB6tB exMR1sIqsTEsZ+3SdQXKgb8WMaePqxBmEndOET0DRst2s/B+uxrZLgs8yjR0s3+OT/ g09iFZ75jaaPydxsIZkXaY9i41Cpf4PnV0VKdm/E= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPS id 20260123113136epcas5p196907cb2ba431ed5e4b1b719343e1a8b~NWNQQ_UKu0266702667epcas5p1W; Fri, 23 Jan 2026 11:31:36 +0000 (GMT) Received: from epcas5p3.samsung.com (unknown [182.195.38.93]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4dyG3W5bsHz6B9m6; Fri, 23 Jan 2026 11:31:35 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20260123113135epcas5p2b0e7d9651a5a78b5451daeb6b1e018d8~NWNPK4t-p1670216702epcas5p2f; Fri, 23 Jan 2026 11:31:35 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113133epsmtip242c314dc055e67241beefe4fa519e91a~NWNN3H5Z42621526215epsmtip22; Fri, 23 Jan 2026 11:31:33 +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, Neeraj Kumar Subject: [PATCH V6 08/18] nvdimm/label: Preserve cxl region information from region label Date: Fri, 23 Jan 2026 17:01:02 +0530 Message-Id: <20260123113112.3488381-9-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113135epcas5p2b0e7d9651a5a78b5451daeb6b1e018d8 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113135epcas5p2b0e7d9651a5a78b5451daeb6b1e018d8 References: <20260123113112.3488381-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. This patch supports interleave way =3D=3D 1, it is therefore it preserves only one region into LSA Reviewed-by: Ira Weiny Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang Signed-off-by: Neeraj Kumar --- drivers/nvdimm/dimm.c | 4 ++++ drivers/nvdimm/label.c | 38 ++++++++++++++++++++++++++++++++++++++ drivers/nvdimm/nd-core.h | 2 ++ drivers/nvdimm/nd.h | 1 + include/linux/libnvdimm.h | 14 ++++++++++++++ 5 files changed, 59 insertions(+) diff --git a/drivers/nvdimm/dimm.c b/drivers/nvdimm/dimm.c index 07f5c5d5e537..590ec883903d 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 014af60d68a1..054dd4e47ab4 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -495,6 +495,44 @@ 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 *lsa_label =3D to_lsa_label(ndd, slot); + struct cxl_region_label *region_label =3D &lsa_label->region_label; + uuid_t region_type_uuid; + + import_uuid(®ion_type_uuid, region_label->type); + + /* TODO: Currently preserving only one region */ + if (uuid_equal(&cxl_region_uuid, ®ion_type_uuid)) { + 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 ec856601fda0..578a828be918 100644 --- a/drivers/nvdimm/nd.h +++ b/drivers/nvdimm/nd.h @@ -585,6 +585,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_region_label_supported(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 Sun Feb 8 20:58:37 2026 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 B8A8437D100 for ; Fri, 23 Jan 2026 11:31:40 +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=1769167902; cv=none; b=JB0c8tYGDblxefWQPrrIwhFtGD70lbJ5LZD0TBp54rm5zmq6N/QHOTyh2svSYNP4pDJwium9a8EDKdL6Spsfa69mYFW0BitfYU1BP8yRrFC4WG579iUxIWZA2aprP8Yb8YFIp+2WKfS/AXjorxZii1tOGuYcw2+TPncCclpLYio= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167902; c=relaxed/simple; bh=Tj2av5RqoLJvlZWfZOdgCwzuwvbjOh/yCFSztEmuyGM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=Y7fzSQFgK0erzpZezybt0SpByq1cLzAUpYeB8kHh/09dUlnT47hvXrFuMRvDfoYABQfuSCaoupUt7xVf8iF0TeT3UvWZiDp3QNaMRAi00R5XmYaB6sLffzF2NXmZGCfnx7o6fOU7r6aam/LpWJlYR5S+PvsGmP7L7ZbA/HQ37Qw= 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=X0iAxVpW; 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="X0iAxVpW" Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20260123113138epoutp02928f02b14b8e9ca6e9a0b101a8076918~NWNSkq3NG0069700697epoutp02f for ; Fri, 23 Jan 2026 11:31:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20260123113138epoutp02928f02b14b8e9ca6e9a0b101a8076918~NWNSkq3NG0069700697epoutp02f DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167898; bh=/tl3ZBvPbTkm53eHYFgRfz0iSfaYWcp8OPuMCg1TaVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X0iAxVpWCKsLXVk+4EnOwvi/eBWcme/RRyeqKKcUd+MEJ+O8mvsTZGLKn6e3+VhmF I5XrLiBxgi0F8HFGEdl2m6TIYdtxBr35WiwVE48ggdSTxGzthMWA+kmQFVe0rWtWkp a16/MG4KHqadxQajaL1uV9OS+DbHXfq9v6RnXQec= Received: from epsnrtp02.localdomain (unknown [182.195.42.154]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPS id 20260123113138epcas5p46133b97bb5fb3be9930f55c863283797~NWNSEG1C-1497514975epcas5p4e; Fri, 23 Jan 2026 11:31:38 +0000 (GMT) Received: from epcas5p1.samsung.com (unknown [182.195.38.92]) by epsnrtp02.localdomain (Postfix) with ESMTP id 4dyG3X6QGvz2SSKZ; Fri, 23 Jan 2026 11:31:36 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20260123113136epcas5p22683ce5ef04a3da50fbb319a43e331a6~NWNQSzbEa3116331163epcas5p2P; Fri, 23 Jan 2026 11:31:36 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113135epsmtip2535b1e68e0aad62fe2bc41eb73a4271e~NWNPL7vue2685626856epsmtip2Q; Fri, 23 Jan 2026 11:31:35 +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, Neeraj Kumar Subject: [PATCH V6 09/18] nvdimm/label: Export routine to fetch region information Date: Fri, 23 Jan 2026 17:01:03 +0530 Message-Id: <20260123113112.3488381-10-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113136epcas5p22683ce5ef04a3da50fbb319a43e331a6 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113136epcas5p22683ce5ef04a3da50fbb319a43e331a6 References: <20260123113112.3488381-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. Reviewed-by: Ira Weiny Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang Signed-off-by: Neeraj Kumar --- drivers/nvdimm/dimm_devs.c | 12 ++++++++++++ include/linux/libnvdimm.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/drivers/nvdimm/dimm_devs.c b/drivers/nvdimm/dimm_devs.c index 3363a97cc5b5..e1c95da92fbf 100644 --- a/drivers/nvdimm/dimm_devs.c +++ b/drivers/nvdimm/dimm_devs.c @@ -280,6 +280,18 @@ void *nvdimm_provider_data(struct nvdimm *nvdimm) } EXPORT_SYMBOL_GPL(nvdimm_provider_data); =20 +bool nvdimm_has_cxl_region(struct nvdimm *nvdimm) +{ + return nvdimm->is_region_label; +} +EXPORT_SYMBOL_GPL(nvdimm_has_cxl_region); + +void *nvdimm_get_cxl_region_param(struct nvdimm *nvdimm) +{ + return &nvdimm->cxl_region_params; +} +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 Sun Feb 8 20:58:37 2026 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 954CF37D122 for ; Fri, 23 Jan 2026 11:31:41 +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=1769167904; cv=none; b=BVdttfsZ0zbQqFwPCOEhY+QQfdy+iHgOZtSG2VcncLdY99VzrbIY4sP4A3R3jliOtzEjE1U7cS8lSq4LGoui220bncoun6oeDv1LvwzMVRknhoBluMXy3mAfAAqU4/2V5P1KOH2carPZ0lZFAFdoWpdgtbC5iWnmEzZImQ3dFlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167904; c=relaxed/simple; bh=HMONvmV7Y1bknVkpYYOr9kqrOZElT5JD2Ggj4UUk5Us=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=cg3dDK3UABq5b6CNetdvhO6IoBJHh5vzbUAFx91A5vPIlJGiQkzmAiCgXySCa4RKIg9S+YcwwB7f4DPLrSZac8BTLctZBJjAegUHJFSYn+lZG+985rtDOY5CdFSEPUEgA+6IDUlltHMWbEMaOShD1pA/+GbwwxSvpfvmjO/PFGc= 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=O/Hir2ae; 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="O/Hir2ae" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20260123113139epoutp01883ac474545c62d24a365a792c299132~NWNTSRJMB1498214982epoutp01g for ; Fri, 23 Jan 2026 11:31:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20260123113139epoutp01883ac474545c62d24a365a792c299132~NWNTSRJMB1498214982epoutp01g DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167899; bh=KJnVVuFcZ2jV9iJ1V/KWC/G0+lhbD6YEhwRdoEULiMY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=O/Hir2aev+Sya8O7vriHbscwNKUO1QZw5N0t7UwVqXVE8AY3AoAQuF9SiUxdpMTjE YmTrnIzo/RiSADcRPaAYUwGWfz3zdruvRMOuh30diApUADChqPx2YREi3py/PI54t7 qog0s/TWxo92lsRK6ez6SnjloJJ0sU2IqAMrJvNM= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPS id 20260123113139epcas5p134c15e58d816330aace7b939253c70f2~NWNS933Wm0724607246epcas5p1B; Fri, 23 Jan 2026 11:31:39 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.95]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4dyG3Z4mCtz6B9m7; Fri, 23 Jan 2026 11:31:38 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20260123113138epcas5p4bc54ae41192dbc9c958c43ad8a80b5c6~NWNR7mAIy2258322583epcas5p4A; Fri, 23 Jan 2026 11:31:38 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113136epsmtip2c71518c1755ce62511b0fb888218ae44~NWNQmn8OZ2685726857epsmtip2V; Fri, 23 Jan 2026 11:31: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, Neeraj Kumar Subject: [PATCH V6 10/18] cxl/mem: Refactor cxl pmem region auto-assembling Date: Fri, 23 Jan 2026 17:01:04 +0530 Message-Id: <20260123113112.3488381-11-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113138epcas5p4bc54ae41192dbc9c958c43ad8a80b5c6 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113138epcas5p4bc54ae41192dbc9c958c43ad8a80b5c6 References: <20260123113112.3488381-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. Create cxl_region_discovery() which performs pmem region auto-assembly and remove cxl pmem region auto-assembly from cxl_endpoint_port_probe() 3. Register cxl_region_discovery() with devm_cxl_add_memdev() which gets called during cxl_pci_probe() in context of cxl_mem_probe() 4. As cxlmd->attach->probe() calls registered cxl_region_discovery(), so move devm_cxl_add_nvdimm() before cxlmd->attach->probe(). It guarantees both the completion of endpoint probe and cxl_nvd presence before calling cxlmd->attach->probe(). Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang Signed-off-by: Neeraj Kumar --- drivers/cxl/core/region.c | 37 +++++++++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 5 +++++ drivers/cxl/mem.c | 18 +++++++++--------- drivers/cxl/pci.c | 4 +++- drivers/cxl/port.c | 39 +-------------------------------------- 5 files changed, 55 insertions(+), 48 deletions(-) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index ae899f68551f..26238fb5e8cf 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3727,6 +3727,43 @@ 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; +} + +int cxl_region_discovery(struct cxl_memdev *cxlmd) +{ + struct cxl_port *port =3D cxlmd->endpoint; + + device_for_each_child(&port->dev, NULL, discover_region); + + return 0; +} +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 c796c3db36e0..86efcc4fb963 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -906,6 +906,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); +int cxl_region_discovery(struct cxl_memdev *cxlmd); #else static inline bool is_cxl_pmem_region(struct device *dev) { @@ -928,6 +929,10 @@ static inline u64 cxl_port_get_spa_cache_alias(struct = cxl_port *endpoint, { return 0; } +static inline int cxl_region_discovery(struct cxl_memdev *cxlmd) +{ + return 0; +} #endif =20 void cxl_endpoint_parse_cdat(struct cxl_port *port); diff --git a/drivers/cxl/mem.c b/drivers/cxl/mem.c index 333c366b69e7..7d19528d9b55 100644 --- a/drivers/cxl/mem.c +++ b/drivers/cxl/mem.c @@ -114,15 +114,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 @@ -142,6 +133,15 @@ static int cxl_mem_probe(struct device *dev) return 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; + } + } + if (cxlmd->attach) { rc =3D cxlmd->attach->probe(cxlmd); if (rc) diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index 549368a9c868..70b40a10be7a 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -903,6 +903,7 @@ __ATTRIBUTE_GROUPS(cxl_rcd); static int cxl_pci_probe(struct pci_dev *pdev, const struct pci_device_id = *id) { struct pci_host_bridge *host_bridge =3D pci_find_host_bridge(pdev->bus); + struct cxl_memdev_attach memdev_attach =3D { 0 }; struct cxl_dpa_info range_info =3D { 0 }; struct cxl_memdev_state *mds; struct cxl_dev_state *cxlds; @@ -1006,7 +1007,8 @@ static int cxl_pci_probe(struct pci_dev *pdev, const = struct pci_device_id *id) if (rc) dev_dbg(&pdev->dev, "No CXL Features discovered\n"); =20 - cxlmd =3D devm_cxl_add_memdev(cxlds, NULL); + memdev_attach.probe =3D cxl_region_discovery; + cxlmd =3D devm_cxl_add_memdev(cxlds, &memdev_attach); if (IS_ERR(cxlmd)) return PTR_ERR(cxlmd); =20 diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c index 7937e7e53797..fbeff1978bfb 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) { /* Reset nr_dports for rebind of driver */ @@ -82,17 +55,7 @@ static int cxl_endpoint_port_probe(struct cxl_port *port) if (rc) return rc; =20 - rc =3D devm_cxl_endpoint_decoders_setup(port); - 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_endpoint_decoders_setup(port); } =20 static int cxl_port_probe(struct device *dev) --=20 2.34.1 From nobody Sun Feb 8 20:58:37 2026 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 5FF5937FF4E for ; Fri, 23 Jan 2026 11:31:43 +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=1769167905; cv=none; b=NqHIGkH3Bf190g50uj/aQqGJ7kTYR0WtZ4GwfccbTuVlvHU6M6Ew6ys/jIp7iU+ZdFWwNtWQ2PNsyV4ooOWs8QkSH+NzoLEMPb9obyezIxYi2VCMIy3yvUNte9so7mh67UDiH2Nnnud5xXTnLMeSgb/FfoY8vj3FDs78wE8oAq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167905; c=relaxed/simple; bh=12SjqgG/2au2W2dkYs+WPLEpvuaVcGNq0Yr5ctgp+TY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=l3+cApe2oJu1MJ/Y/ZtT2XkJqHVVS+oKh/hdAL4XmyGY3hNEkNAv2YBKnrvqDQw+SPRX+yAuElY0La3AOSUu1XoUWhPaKEzBC54ktLod1CpD5tLlCGBB1RncVDRdxQqlTboiUvyAnAcBMPVEGJ/64h1Nzx0tnc4coLrTqLRQ6kI= 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=MWKrpT51; 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="MWKrpT51" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20260123113141epoutp029bbe99cc85f0d584c39e7c621f19c06d~NWNVFdqDH0146201462epoutp02O for ; Fri, 23 Jan 2026 11:31:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20260123113141epoutp029bbe99cc85f0d584c39e7c621f19c06d~NWNVFdqDH0146201462epoutp02O DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167901; bh=h42lregPaaxWlPA3ZNxkhidw5R9qr+oDNtum6fVurAQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=MWKrpT51B1KDcShGw7UEC1hhwLEvpM2uWIvwr+vCc19RpFSTyA77OINHL/BoDDjUw fLq5WGzvdiYll78nOaP48xw+kmehz9c+9gda2c7Vpz9vo+2tFspYSTxmAtNWSEg5NZ pujBxEMFPxPTSv0DdJqTcZzDhfGkpb+CR4lfg4TY= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPS id 20260123113141epcas5p45a1c656d0625186910879ca0781cab78~NWNUzAdLz1479614796epcas5p4o; Fri, 23 Jan 2026 11:31:41 +0000 (GMT) Received: from epcas5p3.samsung.com (unknown [182.195.38.94]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4dyG3c48c2z6B9m9; Fri, 23 Jan 2026 11:31:40 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20260123113140epcas5p4bc7a864d4a717b96afcb863e3200b3a2~NWNTue00c1464914649epcas5p4m; Fri, 23 Jan 2026 11:31:40 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113138epsmtip2c8f269e388fc1d8648b4c40766119bac~NWNSKvlTm2681126811epsmtip2g; Fri, 23 Jan 2026 11:31: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, Neeraj Kumar Subject: [PATCH V6 11/18] cxl/region: Rename __create_region() to cxl_create_region() Date: Fri, 23 Jan 2026 17:01:05 +0530 Message-Id: <20260123113112.3488381-12-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113140epcas5p4bc7a864d4a717b96afcb863e3200b3a2 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113140epcas5p4bc7a864d4a717b96afcb863e3200b3a2 References: <20260123113112.3488381-1-s.neeraj@samsung.com> Currently __create_region() is a static routine used within region.c So to use it from another file rename it to cxl_create_region(). Later patch will create cxl region after fetching region information from LSA using cxl_create_region() along with two extra function parameters. Signed-off-by: Neeraj Kumar Reviewed-by: Jonathan Cameron --- drivers/cxl/core/core.h | 12 ++++++++++++ drivers/cxl/core/region.c | 13 ++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index 1fb66132b777..268f6d19ab9d 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -42,6 +42,10 @@ int cxl_get_poison_by_endpoint(struct cxl_port *port); struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 d= pa); u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd, u64 dpa); +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_endpoint_decoder *cxled); =20 #else static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, @@ -71,6 +75,14 @@ static inline int cxl_region_init(void) static inline void cxl_region_exit(void) { } +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_endpoint_decoder *cxled) +{ + return ERR_PTR(-EOPNOTSUPP); +} #define CXL_REGION_ATTR(x) NULL #define CXL_REGION_TYPE(x) NULL #define SET_CXL_REGION_ATTR(x) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 26238fb5e8cf..2e60e5e72551 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2638,8 +2638,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_endpoint_decoder *cxled) { int rc; =20 @@ -2675,7 +2677,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 @@ -3644,8 +3646,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)) { --=20 2.34.1 From nobody Sun Feb 8 20:58:37 2026 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 53D6B27FD5A for ; Fri, 23 Jan 2026 11:31: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=1769167908; cv=none; b=nhsQPaRxBGY4Ny/XxXYlcIK2tLVVjFs2lPPedCyu3zD+J/rXtn3jvlVDG4ylMPCdB65WUMw5JLQrjqncOs3USQHS+T4S56eBnO/qguEHYADLNe1OtKR5r7aUNLRlKG8/mP+5Io1OVPLRbftTpvlBdwHJZePN4I13OVt1PAH7fZ4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167908; c=relaxed/simple; bh=oHBj1cPJz8cQ+pkC2U1P21/5vYsZOUJH1jFiM4pjtnk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=DrbeZ8lJDwuAzmJHplXCzCuvBnCwXZLU2YEgXRm8LK1I9o39Ce2FWffOXXD6hngOg4/7ARajDyJJ20eIYgi7dObCz6/dSBVtdk7mE7SCwt5px9gxV45dmmi1xpVZF2+DrEEOgLlvjU3KTt3jr3Xymkt8B+WhMqoKWqdau8Hmg0g= 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=N6dphHs7; 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="N6dphHs7" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20260123113143epoutp026a13ca58bddf68668fb506f189ee6128~NWNW2rNhZ0069300693epoutp02h for ; Fri, 23 Jan 2026 11:31:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20260123113143epoutp026a13ca58bddf68668fb506f189ee6128~NWNW2rNhZ0069300693epoutp02h DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167903; bh=P48pOT0TYblMck0fUkubQe5/ucz9763CSDBG1sAPzuA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N6dphHs7QO27SwEgkG1aosTB2ZGbtIPRLgvVAFr/4Li9dBewH0tQikH4TQ+Rf7x/c 4mXU9s+tZ30piQ+n79VEQyRYHJsgaoLLD8fvGdXp/h3zst8rOGhFEkpgwh+5i9uRyI I5VHWQoCwvO8o7mVznnwe4VHfN8cgI3bHQ9lcNho= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPS id 20260123113142epcas5p309a54180492f21217e4204c39ca39272~NWNWBVxvY2653226532epcas5p3n; Fri, 23 Jan 2026 11:31:42 +0000 (GMT) Received: from epcas5p2.samsung.com (unknown [182.195.38.91]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4dyG3d6m6Cz6B9m5; Fri, 23 Jan 2026 11:31:41 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20260123113141epcas5p49a1eebff4401a7fc98381358162fde2b~NWNU7bEbS1479614796epcas5p4q; Fri, 23 Jan 2026 11:31:41 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113140epsmtip2aa6180409cc0d8dfaeced5e29aca429e~NWNTp7mcc2685626856epsmtip2U; Fri, 23 Jan 2026 11:31:39 +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, Neeraj Kumar Subject: [PATCH V6 12/18] cxl/region: Add devm_cxl_pmem_add_region() for pmem region creation Date: Fri, 23 Jan 2026 17:01:06 +0530 Message-Id: <20260123113112.3488381-13-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113141epcas5p49a1eebff4401a7fc98381358162fde2b X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113141epcas5p49a1eebff4401a7fc98381358162fde2b References: <20260123113112.3488381-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 Reviewed-by: Dave Jiang Signed-off-by: Neeraj Kumar Reviewed-by: Jonathan Cameron --- drivers/cxl/core/region.c | 118 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 2e60e5e72551..e384eacc46ae 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2621,6 +2621,121 @@ 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; + + if (!size) + return -EINVAL; + + ACQUIRE(rwsem_write_kill, rwsem)(&cxl_rwsem.region); + if ((rc =3D ACQUIRE_ERR(rwsem_write_kill, &rwsem))) + return rc; + + return alloc_hpa(cxlr, size); +} + +static ssize_t alloc_region_dpa(struct cxl_endpoint_decoder *cxled, u64 si= ze) +{ + if (!size) + return -EINVAL; + + if (!IS_ALIGNED(size, SZ_256M)) + return -EINVAL; + + return cxl_dpa_alloc(cxled, size); +} + +static struct cxl_region * +cxl_pmem_region_prep(struct cxl_root_decoder *cxlrd, int id, + struct cxl_pmem_region_params *params, + struct cxl_endpoint_decoder *cxled, + enum cxl_decoder_type type) +{ + struct cxl_region_params *p; + 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; + + dev =3D &cxlr->dev; + rc =3D dev_set_name(dev, "region%d", id); + if (rc) + return ERR_PTR(rc); + + cxlr->mode =3D CXL_PARTMODE_PMEM; + cxlr->type =3D type; + + 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); + + 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(-EOPNOTSUPP); + + 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); + + return no_free_ptr(cxlr); +} + +static struct cxl_region * +devm_cxl_pmem_add_region(struct cxl_root_decoder *cxlrd, int id, + struct cxl_pmem_region_params *params, + struct cxl_endpoint_decoder *cxled, + enum cxl_decoder_type type) +{ + struct cxl_port *root_port; + struct cxl_region *cxlr; + int rc; + + cxlr =3D cxl_pmem_region_prep(cxlrd, id, params, cxled, type); + if (IS_ERR(cxlr)) + return cxlr; + + 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(&cxlr->dev)); + + return 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)); @@ -2663,6 +2778,9 @@ struct cxl_region *cxl_create_region(struct cxl_root_= decoder *cxlrd, return ERR_PTR(-EBUSY); } =20 + if (pmem_params) + return devm_cxl_pmem_add_region(cxlrd, id, pmem_params, cxled, + CXL_DECODER_HOSTONLYMEM); return devm_cxl_add_region(cxlrd, id, mode, CXL_DECODER_HOSTONLYMEM); } =20 --=20 2.34.1 From nobody Sun Feb 8 20:58:37 2026 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 7553F3815EE for ; Fri, 23 Jan 2026 11:31:47 +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=1769167911; cv=none; b=RjgMMszslKnv94FjQU4XnMrqs0COtSpFqb16Je7DjhxOeqjnmMykKxxPk9KM2x+q/aN8tMvIpu+JA6y6Y8qiimdJfAg6B8VOrMVjVM3amQ/CK3iIgBkyI9Iya3RWqFXOMOC/7JfxLwGjpgs7EAJ33GpAP1n7O9Q5xv1fYYgqbsI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167911; c=relaxed/simple; bh=ACjr2okpiFzwOb4tqPK7mla9DKYQFdfGvBOMtuUJ9s8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=F1ykgT40qHrlSsyZQfxhN/0XNn9vqoA9oVZ1d7KowiwxP9SrlV5nM8CfHna5K+dZOOW7lFII5WttSxCo0NtrOQmVwwUxsotziuJalbdOvhYzNU3w5RfkaV4qNlhyu1LDaeYFVA1lpALOB3Tn/5mwVI7F/g3BR3Nx7tFJKZ7AwWc= 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=c6AP/Fp5; 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="c6AP/Fp5" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20260123113145epoutp020a8e3f95bc8d1c3a262e939c5435cf88~NWNYfIfgm0069300693epoutp02i for ; Fri, 23 Jan 2026 11:31:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20260123113145epoutp020a8e3f95bc8d1c3a262e939c5435cf88~NWNYfIfgm0069300693epoutp02i DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167905; bh=4SmBPbCv6RQLjMURvQxmA1uVIrUH8weGaJhrbxLOigc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c6AP/Fp5JoVzaCRLcr3xzL7nTdy0n9ZZxEAZzrlqtbMDN4P//1ko1HlMuPnkVhOko 7FiAS9JRhLD8j4aJlLOgX2yc92QwexeRYwl7om/Gyu6Xrow4qZktCshJwc0fpw4DUX Vg7DUihxLLXDJ4a+u7ZHAGVif70ey4+yY7TS88Pg= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPS id 20260123113144epcas5p1cb548210263df17c4109796db61e8291~NWNXn_byA0266802668epcas5p1p; Fri, 23 Jan 2026 11:31:44 +0000 (GMT) Received: from epcas5p1.samsung.com (unknown [182.195.38.86]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4dyG3g4rclz6B9m7; Fri, 23 Jan 2026 11:31:43 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20260123113143epcas5p1f056205feaa11092be91be6f74ccc0be~NWNWhUEH72762827628epcas5p1F; Fri, 23 Jan 2026 11:31:43 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113141epsmtip24c4b7c5badb0981613dfb74aa1bfc660~NWNVO2xE32685626856epsmtip2V; Fri, 23 Jan 2026 11:31:41 +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, Neeraj Kumar Subject: [PATCH V6 13/18] cxl/pmem: Preserve region information into nd_set Date: Fri, 23 Jan 2026 17:01:07 +0530 Message-Id: <20260123113112.3488381-14-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113143epcas5p1f056205feaa11092be91be6f74ccc0be X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113143epcas5p1f056205feaa11092be91be6f74ccc0be References: <20260123113112.3488381-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 Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang 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..a6eba3572090 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 Sun Feb 8 20:58:37 2026 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 B5818350D51 for ; Fri, 23 Jan 2026 11:31:50 +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=1769167913; cv=none; b=nRiQHGI76jUYha8adAxVWYQrmgMNu23Ft/QUWlYo1kdpXPcxdx5eDiM3qYQCRwKNRiOqdlX45RdFkL9e4IUboTPYxq2uQ4tnE3nY6XvJNAdEdvef2CIehkvaB/YfnGweO40hiNLKSvrgV9S7UCP/MokQRkSQDmyJvzC3DUFNKg4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167913; c=relaxed/simple; bh=5tAtMy4WfvhEstME0Y+aQ2zHX5jFXZ6f7SDfuW8BbLg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=e7UAI6aylpLrR2GFIe1uzPH8nCGVx9ltl2D5vB0UG9DJo/p9AmEQ+sQPH/lNXFH0GXueHOwxAxHyR0dVvjbuiF8vuKfkGx/ZhxkFEeuNQrkdStHB+sjR83OOlS04oTfYtsoy/t7GcebEHpkcs5yLehLDzjZYnNBjPKOW7JpNUlk= 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=bosZZADq; 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="bosZZADq" Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20260123113147epoutp0383c1ae2436e8afa3b1e15c3a34ed4caf~NWNa7x_8a2126021260epoutp03N for ; Fri, 23 Jan 2026 11:31:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20260123113147epoutp0383c1ae2436e8afa3b1e15c3a34ed4caf~NWNa7x_8a2126021260epoutp03N DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167907; bh=x3MHNOcogxwkLb4okjjYI9s7EwXA49nWVIp97O0VH3c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bosZZADqVV4EGQu5vQDchSjVAdt+xyqlh/id5X2OXYxFsKSHaqb9vJliZkiK3Pjr6 lLqRWE0o85OC57/ttM0S6Ia5Cgj2thHUxtJZI/JQGqvDfQPHMzaGsVc72CrdY5fwYt q25jzTPW11sZJImxOe/j2z/xoc+UZT20xCZnctlk= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPS id 20260123113147epcas5p131ff346215f8925b2aa0c81a53b3cee0~NWNasnvCz0962609626epcas5p1H; Fri, 23 Jan 2026 11:31:47 +0000 (GMT) Received: from epcas5p3.samsung.com (unknown [182.195.38.92]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4dyG3j0w4lz6B9mB; Fri, 23 Jan 2026 11:31:45 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20260123113144epcas5p18477c68ede07c17a6c8461cf034eb3d1~NWNX90uV40266802668epcas5p1r; Fri, 23 Jan 2026 11:31:44 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113143epsmtip2b0cdf0fc901eb6c7757ec22782273dd6~NWNWyfCit2685626856epsmtip2W; Fri, 23 Jan 2026 11:31:43 +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, Neeraj Kumar Subject: [PATCH V6 14/18] cxl/pmem_region: Prep patch to accommodate pmem_region attributes Date: Fri, 23 Jan 2026 17:01:08 +0530 Message-Id: <20260123113112.3488381-15-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113144epcas5p18477c68ede07c17a6c8461cf034eb3d1 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113144epcas5p18477c68ede07c17a6c8461cf034eb3d1 References: <20260123113112.3488381-1-s.neeraj@samsung.com> For region label update, need to create device attribute, which calls nvdimm exported routine thus making pmem_region dependent on libnvdimm. Because of this dependency of pmem region on libnvdimm, segregate pmem region related code from core/region.c to core/pmem_region.c This patch has no functionality change. Its just code movement from core/region.c to core/pmem_region.c Reviewed-by: Dave Jiang Reviewed-by: Jonathan Cameron Signed-off-by: Neeraj Kumar --- drivers/cxl/core/Makefile | 2 +- drivers/cxl/core/core.h | 10 ++ drivers/cxl/core/pmem_region.c | 201 +++++++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 188 +----------------------------- tools/testing/cxl/Kbuild | 2 +- 5 files changed, 214 insertions(+), 189 deletions(-) create mode 100644 drivers/cxl/core/pmem_region.c diff --git a/drivers/cxl/core/Makefile b/drivers/cxl/core/Makefile index 5ad8fef210b5..fe0fcab6d730 100644 --- a/drivers/cxl/core/Makefile +++ b/drivers/cxl/core/Makefile @@ -16,7 +16,7 @@ cxl_core-y +=3D pmu.o 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_REGION) +=3D region.o 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 268f6d19ab9d..4eed243c0d7d 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -46,6 +46,8 @@ struct cxl_region *cxl_create_region(struct cxl_root_deco= der *cxlrd, enum cxl_partition_mode mode, int id, struct cxl_pmem_region_params *pmem_params, struct cxl_endpoint_decoder *cxled); +struct cxl_region *to_cxl_region(struct device *dev); +int devm_cxl_add_pmem_region(struct cxl_region *cxlr); =20 #else static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, @@ -83,6 +85,14 @@ cxl_create_region(struct cxl_root_decoder *cxlrd, { return ERR_PTR(-EOPNOTSUPP); } +static inline struct cxl_region *to_cxl_region(struct device *dev) +{ + return NULL; +} +static inline int devm_cxl_add_pmem_region(struct cxl_region *cxlr) +{ + return 0; +} #define CXL_REGION_ATTR(x) NULL #define CXL_REGION_TYPE(x) NULL #define SET_CXL_REGION_ATTR(x) diff --git a/drivers/cxl/core/pmem_region.c b/drivers/cxl/core/pmem_region.c new file mode 100644 index 000000000000..dcaab59108fd --- /dev/null +++ b/drivers/cxl/core/pmem_region.c @@ -0,0 +1,201 @@ +// 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 needs to update the cxl region information + * in the LSA. + */ + +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"); + +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; +} diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index e384eacc46ae..f9b3dd6cee50 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, \ @@ -2429,7 +2427,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")) @@ -2866,46 +2864,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; @@ -3337,64 +3295,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); @@ -3458,92 +3358,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; diff --git a/tools/testing/cxl/Kbuild b/tools/testing/cxl/Kbuild index 0e151d0572d1..ad2496b38fdd 100644 --- a/tools/testing/cxl/Kbuild +++ b/tools/testing/cxl/Kbuild @@ -59,7 +59,7 @@ cxl_core-y +=3D $(CXL_CORE_SRC)/pmu.o 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_REGION) +=3D $(CXL_CORE_SRC)/region.o $(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 Sun Feb 8 20:58:37 2026 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 84726318EF9 for ; Fri, 23 Jan 2026 11:31:50 +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=1769167913; cv=none; b=X0heG9rJ6PbPiNGsc5uc3VW51kf3rNKywz0sz7r7fAL9Lsd6PWxiRdHArKXAQX3BAyMO5Gy9WGkheClvsOH7ULR4dPRgnMYOnW0/g2STSIou/Mc4UawbpghdnvaRs6Csuamy5cAKnDztpB3FNHZ4wD+hYhaRmZDccUTLQieOZ0o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167913; c=relaxed/simple; bh=T6Le4Sw56pSLJy+oCkhg4Y5NnmDD7d0n7ueM5l1OuLU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=Lmp7ys2c/cvmeL3eGeFkAW1PAYTA9Asp/4drmeLF2+Qmv89yMZ9orbZxIz8g6+91lVDnGnmaLP2QIj9oku7Y9SPP2MY+syxjWyNGQBRFTCz+e5JMXxGRvwwc86KcZVqD2L52jvGG1K3H7sN+YlPeGDmpSqTmvJrd0+qxFCigMuw= 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=AtVGXnbe; 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="AtVGXnbe" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20260123113147epoutp03e4fe66b15a586b0528a6e289a4acfded~NWNawMEId2133521335epoutp03B for ; Fri, 23 Jan 2026 11:31:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20260123113147epoutp03e4fe66b15a586b0528a6e289a4acfded~NWNawMEId2133521335epoutp03B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167907; bh=3BcurE+TS4eJN7ewQ/AnjErQapQmb8iQp1p6oIuMtMA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AtVGXnbeVDKbT3nPNHQ+UmohoQgyz8AKre7vCgUh1Gv7hjvvidGuwa1KRKkZDn2g1 zx7XoO5PusvmPbUqsXpv6ZtpgOibtLHb0yP+hWiB5WS+MCISOfLmKV7J69OaRKSDiT L1tbdtBM0gPTQDyFUd1oHj/zrLH5nWmi4VkQfMZM= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPS id 20260123113147epcas5p3ab7e0a04394763a32228728a13817aa9~NWNaZGXiK2902429024epcas5p3V; Fri, 23 Jan 2026 11:31:47 +0000 (GMT) Received: from epcas5p1.samsung.com (unknown [182.195.38.93]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4dyG3k4cWNz6B9mB; Fri, 23 Jan 2026 11:31:46 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20260123113146epcas5p3d267b8d1aed388debac761ebf5f143d4~NWNZX_jzu2168121681epcas5p3U; Fri, 23 Jan 2026 11:31:46 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113145epsmtip20e51ca817a199039faf62ef5e8132738~NWNYNqhXE2685626856epsmtip2X; Fri, 23 Jan 2026 11:31: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, Neeraj Kumar Subject: [PATCH V6 15/18] cxl/pmem_region: Introduce CONFIG_CXL_PMEM_REGION for core/pmem_region.c Date: Fri, 23 Jan 2026 17:01:09 +0530 Message-Id: <20260123113112.3488381-16-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113146epcas5p3d267b8d1aed388debac761ebf5f143d4 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113146epcas5p3d267b8d1aed388debac761ebf5f143d4 References: <20260123113112.3488381-1-s.neeraj@samsung.com> As pmem region label update/delete has hard dependency on libnvdimm. It is therefore put core/pmem_region.c under CONFIG_CXL_PMEM_REGION control. It handles the dependency by selecting CONFIG_LIBNVDIMM if not enabled. Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang Signed-off-by: Neeraj Kumar --- drivers/cxl/Kconfig | 15 +++++++++++++++ drivers/cxl/core/Makefile | 3 ++- drivers/cxl/core/core.h | 18 +++++++++++------- drivers/cxl/cxl.h | 24 ++++++++++++++---------- tools/testing/cxl/Kbuild | 3 ++- 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/drivers/cxl/Kconfig b/drivers/cxl/Kconfig index f1361ed6a0d4..307fed8f1f56 100644 --- a/drivers/cxl/Kconfig +++ b/drivers/cxl/Kconfig @@ -211,6 +211,21 @@ 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 ARCH_HAS_PMEM_API + 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 + update/delete 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 fe0fcab6d730..399157beb917 100644 --- a/drivers/cxl/core/Makefile +++ b/drivers/cxl/core/Makefile @@ -16,7 +16,8 @@ cxl_core-y +=3D pmu.o 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 pmem_region.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 4eed243c0d7d..5ae693269771 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); @@ -47,7 +46,6 @@ struct cxl_region *cxl_create_region(struct cxl_root_deco= der *cxlrd, struct cxl_pmem_region_params *pmem_params, struct cxl_endpoint_decoder *cxled); struct cxl_region *to_cxl_region(struct device *dev); -int devm_cxl_add_pmem_region(struct cxl_region *cxlr); =20 #else static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, @@ -89,17 +87,23 @@ static inline struct cxl_region *to_cxl_region(struct d= evice *dev) { return NULL; } -static inline int devm_cxl_add_pmem_region(struct cxl_region *cxlr) -{ - return 0; -} #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(x) (&cxl_pmem_region_type) +int devm_cxl_add_pmem_region(struct cxl_region *cxlr); +#else +#define CXL_PMEM_REGION_TYPE(x) NULL +static inline int devm_cxl_add_pmem_region(struct cxl_region *cxlr) +{ + return -EINVAL; +} +#endif + struct cxl_send_command; struct cxl_mem_query_commands; int cxl_query_cmd(struct cxl_mailbox *cxl_mbox, diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 86efcc4fb963..296411be1c36 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -901,21 +901,11 @@ int devm_cxl_add_nvdimm(struct cxl_port *parent_port,= struct cxl_memdev *cxlmd); struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_port *port); =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); int cxl_region_discovery(struct cxl_memdev *cxlmd); #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; @@ -935,6 +925,20 @@ static inline int cxl_region_discovery(struct cxl_memd= ev *cxlmd) } #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); +#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; +} +#endif + void cxl_endpoint_parse_cdat(struct cxl_port *port); void cxl_switch_parse_cdat(struct cxl_dport *dport); =20 diff --git a/tools/testing/cxl/Kbuild b/tools/testing/cxl/Kbuild index ad2496b38fdd..024922326a6b 100644 --- a/tools/testing/cxl/Kbuild +++ b/tools/testing/cxl/Kbuild @@ -59,7 +59,8 @@ cxl_core-y +=3D $(CXL_CORE_SRC)/pmu.o 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_SRC= )/pmem_region.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 Sun Feb 8 20:58:37 2026 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 7AE02385502 for ; Fri, 23 Jan 2026 11:31:52 +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=1769167915; cv=none; b=VFliGw4+Aqu4ny2J3JV/1VsAOm01a/BRtt3n3E5xJy0qDXSCmBPU6swcDMKNrYqN/AdOOgwiTJFXM5SEYqp1XrnFnA8C3BT5o8JgNy8ctIj+22ZmlUNooJ7lr3PlapnFsMZoAUPFiHTPYFzY0cQSvt9r8Lp2h5Q62PS3IvGd7JU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167915; c=relaxed/simple; bh=+2siN0dvDCPFtNbIgNZBKQyzkTRL5yXcRjVlmdA43c0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=Pj5eZLqa+Vkb72yqfJOSKd8uex62hnPLeKY1vnQXPbUs5LI2NazS7UeUYOSWTlCbMYBuVAQbjNtZxLJEjyt/GNzwiMz7nlcfZxJlBiFXm9f9RSc72PBC2E8494j60Oo59cD5BMYTDPtfy3ztq9LLb/oe/aFVObAmN2Y6PBLyxGA= 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=B1BbQbEE; 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="B1BbQbEE" Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20260123113150epoutp01baf43fef98619298f018d58de8f609a8~NWNdEWh_n1946719467epoutp01a for ; Fri, 23 Jan 2026 11:31:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20260123113150epoutp01baf43fef98619298f018d58de8f609a8~NWNdEWh_n1946719467epoutp01a DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167910; bh=2nCu0F8Ca6ps/usVx8k0KaFrFchNzhmkBjKX5T8KSmY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=B1BbQbEEoFmThB7+FrzRHkahWh3GH40kmaoR20HYCpUnRSKaxGjVheM2U/6kPlZPk C9j5kS99uQlq8SjLhxi6dzlm0ls3zpkrV12JnlxjfGAlpmxFAil/Ka/eZYxs3tO3Uh an5zQphmkzZZALOvwQBUz7MrxKs0DAKQiOs+lqN0= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPS id 20260123113149epcas5p1a63df62daa60bc997338a40cfd33ac1b~NWNcvMVoz2764227642epcas5p1W; Fri, 23 Jan 2026 11:31:49 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.87]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4dyG3n1D2lz6B9m7; Fri, 23 Jan 2026 11:31:49 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20260123113147epcas5p39e1e5e148faaf7e47b40516cfef3de61~NWNa2W5_E2902429024epcas5p3X; Fri, 23 Jan 2026 11:31:47 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113146epsmtip23168efe14701d25905f4744d91f4d715~NWNZoJbaA2681126811epsmtip2n; Fri, 23 Jan 2026 11:31: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, Neeraj Kumar Subject: [PATCH V6 16/18] cxl/pmem_region: Add sysfs attribute cxl region label updation/deletion Date: Fri, 23 Jan 2026 17:01:10 +0530 Message-Id: <20260123113112.3488381-17-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113147epcas5p39e1e5e148faaf7e47b40516cfef3de61 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113147epcas5p39e1e5e148faaf7e47b40516cfef3de61 References: <20260123113112.3488381-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. Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang Signed-off-by: Neeraj Kumar --- Documentation/ABI/testing/sysfs-bus-cxl | 22 +++++++ drivers/cxl/core/pmem_region.c | 88 +++++++++++++++++++++++++ drivers/cxl/cxl.h | 7 ++ 3 files changed, 117 insertions(+) diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/te= sting/sysfs-bus-cxl index c80a1b5a03db..e42213c9b030 100644 --- a/Documentation/ABI/testing/sysfs-bus-cxl +++ b/Documentation/ABI/testing/sysfs-bus-cxl @@ -624,3 +624,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: Jan, 2026 +KernelVersion: v7.0 +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 is + used to update cxl region information saved during cxl region + creation into LSA. This attribute must be written last during + cxl region creation. Reading this attribute indicates whether + the region label is active or not. + + +What: /sys/bus/cxl/devices/regionZ/pmem_regionZ/region_label_delete +Date: Jan, 2026 +KernelVersion: v7.0 +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. diff --git a/drivers/cxl/core/pmem_region.c b/drivers/cxl/core/pmem_region.c index dcaab59108fd..53d3d81e9676 100644 --- a/drivers/cxl/core/pmem_region.c +++ b/drivers/cxl/core/pmem_region.c @@ -29,8 +29,96 @@ 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); + if ((rc =3D ACQUIRE_ERR(rwsem_write_kill, &rwsem))) + 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) + return 0; + + rc =3D nd_region_label_update(cxlr->cxlr_pmem->nd_region); + if (rc) + return rc; + + cxlr->params.state_region_label =3D CXL_REGION_LABEL_ACTIVE; + + 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); + if ((rc =3D ACQUIRE_ERR(rwsem_read_intr, &rwsem))) + return rc; + + return sysfs_emit(buf, "%d\n", p->state_region_label); +} +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); + if ((rc =3D ACQUIRE_ERR(rwsem_write_kill, &rwsem))) + return rc; + + if (!cxlr && !cxlr->cxlr_pmem && !cxlr->cxlr_pmem->nd_region) + return 0; + + rc =3D nd_region_label_delete(cxlr->cxlr_pmem->nd_region); + if (rc) + return rc; + + cxlr->params.state_region_label =3D CXL_REGION_LABEL_INACTIVE; + + 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, + &cxl_pmem_region_group, NULL }; =20 diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 296411be1c36..32a8296a833a 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -473,9 +473,15 @@ enum cxl_config_state { CXL_CONFIG_COMMIT, }; =20 +enum region_label_state { + CXL_REGION_LABEL_INACTIVE, + CXL_REGION_LABEL_ACTIVE, +}; + /** * struct cxl_region_params - region settings * @state: allow the driver to lockdown further parameter changes + * @state_region_label: region label state information * @uuid: unique id for persistent regions * @interleave_ways: number of endpoints in the region * @interleave_granularity: capacity each endpoint contributes to a stripe @@ -488,6 +494,7 @@ enum cxl_config_state { */ struct cxl_region_params { enum cxl_config_state state; + enum region_label_state state_region_label; uuid_t uuid; int interleave_ways; int interleave_granularity; --=20 2.34.1 From nobody Sun Feb 8 20:58:37 2026 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 86E7B352955 for ; Fri, 23 Jan 2026 11:31:52 +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=1769167917; cv=none; b=beFJGQtVujsS7NlPRzS1I4hYe9Wov8viUvk6srn0aqsvelWcqF59LMAzeXkRdpX5f6zE558BC4TG68xmagkPQqWmoE8596fwNbfr5/rkI6itTQ2v+W4gj9wtTMDpKkevKuV/5qtNVlTCRIfiJWCDx14TZokhZgnpS6hO/sVDTFQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167917; c=relaxed/simple; bh=EWyTHIXRjnxuz5bMEmopbPulR+K5y7vgs2pkq5uFWKU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=R57iVqd79fXAbtaT7teAJhE8e+oaXlRzAwFetbPF2hY3FWMNXQ5YVQV2zcHogO6XWHSnX+KUwglwLTLkj0wRMw3XrELdCQM3ROhe4ToM9PMjudOv2Mu/chbPRmq/Mc3bAmAzCYbcZ/iMdR+9eQGGdgc50gecNMNw3640LzjOXLI= 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=b3/2YtWV; 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="b3/2YtWV" Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20260123113150epoutp01499b6feadbf69161f582e560392d6281~NWNdzHNwK1471314713epoutp01i for ; Fri, 23 Jan 2026 11:31:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20260123113150epoutp01499b6feadbf69161f582e560392d6281~NWNdzHNwK1471314713epoutp01i DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167911; bh=oYoasi3H98eaABmP5XK/+MqgF3n0XTF/ldFpMP/hfUw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=b3/2YtWVbesOxUIXkzF8HvWOvjN5lZvkvkW/boUOn+xVx37LXkJcGK4trYZX1X4Dr PojEGPe8qZlEhorvWPMbRZ6rXwgQMVAtIDpnKRKJzMaD9no6EvFEQeopGpdblV65mP cXM4yTpLzw87VUs2uUumOElgY9LWtoPEm29ldQro= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20260123113150epcas5p26fb3bfbd2b99e86dcfa93b37d1da6c46~NWNdiK0PV2197121971epcas5p2f; Fri, 23 Jan 2026 11:31:50 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.86]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4dyG3p08N7z6B9m5; Fri, 23 Jan 2026 11:31:50 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20260123113149epcas5p1884531875d9676391e7ccc66a0f314d4~NWNcWmWly2520225202epcas5p1l; Fri, 23 Jan 2026 11:31:49 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113148epsmtip2d45ba503047a434d45d85eb073c9865a~NWNbI8bRF2681126811epsmtip2o; Fri, 23 Jan 2026 11:31: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, Neeraj Kumar Subject: [PATCH V6 17/18] cxl/pmem_region: Create pmem region using information parsed from LSA Date: Fri, 23 Jan 2026 17:01:11 +0530 Message-Id: <20260123113112.3488381-18-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113149epcas5p1884531875d9676391e7ccc66a0f314d4 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113149epcas5p1884531875d9676391e7ccc66a0f314d4 References: <20260123113112.3488381-1-s.neeraj@samsung.com> create_pmem_region() creates CXL region based on region information parsed from the Label Storage Area (LSA). This routine requires cxl endpoint decoder and root decoder. Add cxl_find_root_decoder_by_port() and cxl_find_free_ep_decoder() to find the root decoder and a free endpoint decoder respectively. Signed-off-by: Neeraj Kumar Reviewed-by: Jonathan Cameron --- drivers/cxl/core/core.h | 5 ++ drivers/cxl/core/pmem_region.c | 133 +++++++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 21 ++++-- drivers/cxl/cxl.h | 5 ++ 4 files changed, 156 insertions(+), 8 deletions(-) diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index 5ae693269771..8421ea0ef834 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -46,6 +46,7 @@ struct cxl_region *cxl_create_region(struct cxl_root_deco= der *cxlrd, struct cxl_pmem_region_params *pmem_params, struct cxl_endpoint_decoder *cxled); struct cxl_region *to_cxl_region(struct device *dev); +bool is_free_decoder(struct device *dev); =20 #else static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, @@ -87,6 +88,10 @@ static inline struct cxl_region *to_cxl_region(struct de= vice *dev) { return NULL; } +static inline bool is_free_decoder(struct device *dev) +{ + return false; +} #define CXL_REGION_ATTR(x) NULL #define CXL_REGION_TYPE(x) NULL #define SET_CXL_REGION_ATTR(x) diff --git a/drivers/cxl/core/pmem_region.c b/drivers/cxl/core/pmem_region.c index 53d3d81e9676..cdee2788fad8 100644 --- a/drivers/cxl/core/pmem_region.c +++ b/drivers/cxl/core/pmem_region.c @@ -287,3 +287,136 @@ int devm_cxl_add_pmem_region(struct cxl_region *cxlr) cxlr->cxl_nvb =3D NULL; return rc; } + +static int match_root_decoder_by_dport(struct device *dev, const void *dat= a) +{ + const struct cxl_port *ep_port =3D data; + struct cxl_root_decoder *cxlrd; + struct cxl_port *root_port; + struct cxl_decoder *cxld; + struct cxl_dport *dport; + int i; + + if (!is_root_decoder(dev)) + return 0; + + cxld =3D to_cxl_decoder(dev); + if (!(cxld->flags & CXL_DECODER_F_PMEM)) + return 0; + + cxlrd =3D to_cxl_root_decoder(dev); + + root_port =3D cxlrd_to_port(cxlrd); + dport =3D cxl_find_dport_by_dev(root_port, ep_port->host_bridge); + if (!dport) + return 0; + + for (i =3D 0; i < cxlrd->cxlsd.nr_targets; i++) + if (dport =3D=3D cxlrd->cxlsd.target[i]) + break; + + if (i =3D=3D cxlrd->cxlsd.nr_targets) + return 0; + + 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 + * @cxled: endpoint decoder + * + * Caller of this function must call put_device() when done as a device ref + * is taken via device_find_child() + */ +static struct cxl_root_decoder * +cxl_find_root_decoder_by_port(struct cxl_port *port, + struct cxl_endpoint_decoder *cxled) +{ + struct cxl_root *cxl_root __free(put_cxl_root) =3D find_cxl_root(port); + struct cxl_port *ep_port =3D cxled_to_port(cxled); + struct device *dev; + + if (!cxl_root) + return NULL; + + dev =3D device_find_child(&cxl_root->port.dev, ep_port, + match_root_decoder_by_dport); + if (!dev) + return NULL; + + return to_cxl_root_decoder(dev); +} + +static int match_free_ep_decoder(struct device *dev, const void *data) +{ + if (!is_endpoint_decoder(dev)) + return 0; + + return is_free_decoder(dev); +} + +/** + * cxl_find_free_ep_decoder() - find a cxl endpoint decoder using cxl port + * @port: any descendant port in CXL port topology + * + * Caller of this function must call put_device() when done as a device ref + * is taken via device_find_child() + */ +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; + + return to_cxl_decoder(dev); +} + +void create_pmem_region(struct nvdimm *nvdimm) +{ + struct cxl_pmem_region_params *params; + struct cxl_endpoint_decoder *cxled; + struct cxl_nvdimm *cxl_nvd; + struct cxl_memdev *cxlmd; + 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; + + /* TODO: Region creation support only for interleave way =3D=3D 1 */ + if (!(params->nlabel =3D=3D 1)) { + dev_dbg(&cxlmd->dev, + "Region Creation is not supported with iw > 1\n"); + return; + } + + struct cxl_decoder *cxld __free(put_cxl_decoder) =3D + cxl_find_free_ep_decoder(cxlmd->endpoint); + if (!cxld) { + dev_err(&cxlmd->dev, "CXL endpoint decoder not found\n"); + return; + } + + cxled =3D to_cxl_endpoint_decoder(&cxld->dev); + + struct cxl_root_decoder *cxlrd __free(put_cxl_root_decoder) =3D + cxl_find_root_decoder_by_port(cxlmd->endpoint, cxled); + if (!cxlrd) { + dev_err(&cxlmd->dev, "CXL root decoder not found\n"); + return; + } + + cxlr =3D cxl_create_region(cxlrd, CXL_PARTMODE_PMEM, + atomic_read(&cxlrd->region_id), + params, cxled); + if (IS_ERR(cxlr)) + dev_warn(&cxlmd->dev, "Region Creation failed\n"); +} +EXPORT_SYMBOL_NS_GPL(create_pmem_region, "CXL"); diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index f9b3dd6cee50..37b88641b818 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -838,25 +838,22 @@ static int check_commit_order(struct device *dev, voi= d *data) return 0; } =20 -static int match_free_decoder(struct device *dev, const void *data) +bool is_free_decoder(struct device *dev) { struct cxl_port *port =3D to_cxl_port(dev->parent); struct cxl_decoder *cxld; int rc; =20 - if (!is_switch_decoder(dev)) - return 0; - cxld =3D to_cxl_decoder(dev); =20 if (cxld->id !=3D port->commit_end + 1) - return 0; + return false; =20 if (cxld->region) { dev_dbg(dev->parent, "next decoder to commit (%s) is already reserved (%s)\n", dev_name(dev), dev_name(&cxld->region->dev)); - return 0; + return false; } =20 rc =3D device_for_each_child_reverse_from(dev->parent, dev, NULL, @@ -865,9 +862,17 @@ static int match_free_decoder(struct device *dev, cons= t void *data) dev_dbg(dev->parent, "unable to allocate %s due to out of order shutdown\n", dev_name(dev)); - return 0; + return false; } - return 1; + return true; +} + +static int match_free_decoder(struct device *dev, const void *data) +{ + if (!is_switch_decoder(dev)) + return 0; + + return is_free_decoder(dev); } =20 static bool spa_maps_hpa(const struct cxl_region_params *p, diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 32a8296a833a..1fc3e6260a00 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -794,6 +794,7 @@ struct cxl_root *find_cxl_root(struct cxl_port *port); DEFINE_FREE(put_cxl_root, struct cxl_root *, if (_T) put_device(&_T->port.= dev)) DEFINE_FREE(put_cxl_port, struct cxl_port *, if (!IS_ERR_OR_NULL(_T)) put_= device(&_T->dev)) DEFINE_FREE(put_cxl_root_decoder, struct cxl_root_decoder *, if (!IS_ERR_O= R_NULL(_T)) put_device(&_T->cxlsd.cxld.dev)) +DEFINE_FREE(put_cxl_decoder, struct cxl_decoder *, if (!IS_ERR_OR_NULL(_T)= ) put_device(&_T->dev)) DEFINE_FREE(put_cxl_region, struct cxl_region *, if (!IS_ERR_OR_NULL(_T)) = put_device(&_T->dev)) =20 int devm_cxl_enumerate_ports(struct cxl_memdev *cxlmd); @@ -935,6 +936,7 @@ static inline int cxl_region_discovery(struct cxl_memde= v *cxlmd) #ifdef CONFIG_CXL_PMEM_REGION bool is_cxl_pmem_region(struct device *dev); struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev); +void create_pmem_region(struct nvdimm *nvdimm); #else static inline bool is_cxl_pmem_region(struct device *dev) { @@ -944,6 +946,9 @@ static inline struct cxl_pmem_region *to_cxl_pmem_regio= n(struct device *dev) { return NULL; } +static inline void create_pmem_region(struct nvdimm *nvdimm) +{ +} #endif =20 void cxl_endpoint_parse_cdat(struct cxl_port *port); --=20 2.34.1 From nobody Sun Feb 8 20:58:37 2026 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 B83783815E7 for ; Fri, 23 Jan 2026 11:31:54 +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=1769167919; cv=none; b=gOzciZA/4HRY6QyfGlHze4Kr9MT1TNMVqMJbK8uFmWSQPM1jfoMnrMgyFUPn009J01suRJUpjANhFUzlkCUHEb9M0+wTMmC/NhSHyjGQxpiz+ybmqtTEDK5IAYLQGfN10H2hi/UFO/L31S8SoQEx4AGiERWb4dPO6dY3oM1Zk+Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769167919; c=relaxed/simple; bh=qzPar7obw36NTmPt2/9vP+Zkp3egPZG/7olE6tY06Eg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=WbkTZ1tqnMcnhUtyF2l6eMCRhLdSynoTqdOh1IdW+YFcG/uZlFht1HFHrHVRiiv5PdKz43JDdHzTstZqBkBkwgquYVmlAsO458315mWoLmk+Mtt7Z0CtAxkVjxnZT3P/dTAbU/z07LfKbH4Da6lLV+fmJ1ZP0pPLxjiZIRYJIHg= 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=gl+VzFkD; 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="gl+VzFkD" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20260123113152epoutp030dde509c7429f1662bce3c0a1de927a7~NWNfCaD4e2126021260epoutp03R for ; Fri, 23 Jan 2026 11:31:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20260123113152epoutp030dde509c7429f1662bce3c0a1de927a7~NWNfCaD4e2126021260epoutp03R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1769167912; bh=6p1qnXqZOG7pC4bLUPqhPGqIpYVzEFMexCDooS72Qbs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gl+VzFkDrt8BbR6DDIkYeizehDF9OFZcBLnMLfprs2HShWIfKqAry8R7V4sS8siE+ TDLAxppRzv/c6/Ua1nBZ/SjnYBtL5AwDBwmkkhy8tooIDzVeHf0r/oZfa/rcJX1wkC 5erao1LihU0My/Fk4VDF3UIMYRmHREe1DlKd/p2c= Received: from epsnrtp02.localdomain (unknown [182.195.42.154]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPS id 20260123113152epcas5p1beb310d63acb5de9d41c9c3e3b880733~NWNevH52J2762827628epcas5p1V; Fri, 23 Jan 2026 11:31:52 +0000 (GMT) Received: from epcas5p1.samsung.com (unknown [182.195.38.91]) by epsnrtp02.localdomain (Postfix) with ESMTP id 4dyG3q2Fdhz2SSKY; Fri, 23 Jan 2026 11:31:51 +0000 (GMT) Received: from epsmtip2.samsung.com (unknown [182.195.34.31]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20260123113150epcas5p14974b694807b93b27319c33f3003dcba~NWNdrP8M70266802668epcas5p10; Fri, 23 Jan 2026 11:31:50 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20260123113149epsmtip2ad1a52fe6cbea5b2b91db1b2d727fbf6~NWNcmanMK2685626856epsmtip2m; Fri, 23 Jan 2026 11:31:49 +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, Neeraj Kumar Subject: [PATCH V6 18/18] cxl/pmem: Add CXL LSA 2.1 support in cxl pmem Date: Fri, 23 Jan 2026 17:01:12 +0530 Message-Id: <20260123113112.3488381-19-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260123113112.3488381-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: 20260123113150epcas5p14974b694807b93b27319c33f3003dcba X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" CMS-TYPE: 105P cpgsPolicy: CPGSC10-542,Y X-CFilter-Loop: Reflected X-CMS-RootMailID: 20260123113150epcas5p14974b694807b93b27319c33f3003dcba References: <20260123113112.3488381-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 Reviewed-by: Jonathan Cameron Reviewed-by: Dave Jiang Signed-off-by: Neeraj Kumar --- drivers/cxl/pmem.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/cxl/pmem.c b/drivers/cxl/pmem.c index a6eba3572090..5970d1792be8 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