From nobody Tue Dec 2 02:32:22 2025 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8E288322DA8 for ; Wed, 19 Nov 2025 07:53:17 +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=1763538800; cv=none; b=i0WBdMFrT2riH2mp3OabadIB87RFv/20t2VjLNy1eOPJKHmpOGdcYAY8frwYOts+ORxzKMGFXfzaqobWE3K6yau6CZXGtJcYMACUqGkNOMk9k4I8QZ/DGg1so8MBh6wM5pvE2gEPjANIPx5GjhAFxHJ0kHojA1mtJHGNg9eOzD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538800; c=relaxed/simple; bh=Nrh3LJeASNPcmlmYLto8vp7K7VofCjI17u7FYsOih7U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=dEzU8KDYXqgVQGrKyT/RU10evUxmqxjDMfLdjsYjiT34qGZXEM22sYAloAeFN+ZucAbpCecb8z83qK4/SHqDViYPeOKNWRrNRvc9eSX883g69r7/vqVORXxz+eBG5K+8yauZVtTL9yQJQBVBY7GC8VWFns3/AcW3l1nafM3XB94= 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=JmhbqC1V; 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="JmhbqC1V" Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20251119075309epoutp0125b3ff23c67c5c63652e4edce892a8f1~5WS9_--Jt0084400844epoutp01J for ; Wed, 19 Nov 2025 07:53:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20251119075309epoutp0125b3ff23c67c5c63652e4edce892a8f1~5WS9_--Jt0084400844epoutp01J DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538789; bh=5xmz/B9yMfpkRTzrVcJYqxwlY+cbVHk6E47L8xjO2O4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JmhbqC1VW2TeOmgGeFzFKBwQATHmGPaiHcZYb/8JNEPw15iGSSGvxyoKGRCsim5v/ CwhUTW7qWGjxcmP4Di3A/OhfH0NgFmcj6/1ls/g3sktwrileyze1dbRxeNww/EfjM9 1CKMA26mPHRr0z3qAzmo6NCyqKKLTWtViEm21Wsk= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPS id 20251119075309epcas5p10e66cd25a992f314cefde9c28ad930d5~5WS9ssSmC2205722057epcas5p1j; Wed, 19 Nov 2025 07:53:09 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.87]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4dBDHS258Qz6B9m6; Wed, 19 Nov 2025 07:53:08 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20251119075307epcas5p3007a9cb341efc3fa57b763e74caa35c4~5WS8RlJk31255112551epcas5p3_; Wed, 19 Nov 2025 07:53:07 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075306epsmtip1a4c04623af5019f52b81ea3bf23b14c9~5WS7LURsR2604526045epsmtip1G; Wed, 19 Nov 2025 07:53:06 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, Neeraj Kumar Subject: [PATCH V4 01/17] nvdimm/label: Introduce NDD_REGION_LABELING flag to set region label Date: Wed, 19 Nov 2025 13:22:39 +0530 Message-Id: <20251119075255.2637388-2-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075307epcas5p3007a9cb341efc3fa57b763e74caa35c4 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: 20251119075307epcas5p3007a9cb341efc3fa57b763e74caa35c4 References: <20251119075255.2637388-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: 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 Tue Dec 2 02:32:22 2025 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E548A2F692A for ; Wed, 19 Nov 2025 08:03:11 +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=1763539395; cv=none; b=PFRBFEfG2aoLlbIP4XB1pOr3M144FoykE/5KoO4pXqlNtEXh5R0ViqozTN5ibOtYHJ/9JRpg4CKEDK2PGwCnRU9OmPc2Y2c23gYNV65v3wQipuKSlQtQt3d+xz8piOERP2n/5QNgf6y28mc3ZUHjqEzu5Kn6gtmfdPpGACz7LzQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763539395; c=relaxed/simple; bh=ShADinf0ceFNInXUC1/9ovwqsK/dzkjpi29FBCB4wyk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=ilIrYW7a087Db7yvOnsUCcXmqk7qDf3xoNoGCrqAqI8rYfEBbcjCx+wXJWbrt4z5brkyqf6n7GehbVglDztN9NSZbdMRblGtOmQXrSitg6PrK05djmT4uVinb1SsWmTPUtpJShQJsbAlURxzbHikn3c2eEtEgKQ0ObiWlpfPH+I= 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=cpq6rKn7; 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="cpq6rKn7" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20251119075311epoutp025b87cbc953f28115718fc28803d0b1dd~5WS-Y2We-2565225652epoutp023 for ; Wed, 19 Nov 2025 07:53:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20251119075311epoutp025b87cbc953f28115718fc28803d0b1dd~5WS-Y2We-2565225652epoutp023 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538791; bh=rPhEj1OYydDtYbq1YtLA0Z1jyn4oKHdktpA/8d10QHk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cpq6rKn79nP/3K3BB/N3v5hfKurEBNtxfvu55Bo4OPaz9QjK9ywf+Ue8cHsqn+xNh XIiroigY9ax5V0CsxM4rbTno4YPJuQhLi+MIZPilp3B2vL/b7QhRYfdT5hkDszWPTh uU8o7VCjoKmo9OWykTggrRNTDyDbbEKPIKULYjjs= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPS id 20251119075310epcas5p3e885d2478bbe2f44ed78876c8d06d948~5WS_-xyMd3101731017epcas5p3t; Wed, 19 Nov 2025 07:53:10 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.91]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4dBDHT5K6jz6B9mD; Wed, 19 Nov 2025 07:53:09 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20251119075309epcas5p204a699babdf635f11f4b97d3ab8e8a13~5WS9ueb7x0870808708epcas5p2x; Wed, 19 Nov 2025 07:53:09 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075308epsmtip1d5375b1ba801c57f79c7fc64d1c55939~5WS8gtAhz2605226052epsmtip1J; Wed, 19 Nov 2025 07:53:07 +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 V4 02/17] nvdimm/label: CXL labels skip the need for 'interleave-set cookie' Date: Wed, 19 Nov 2025 13:22:40 +0530 Message-Id: <20251119075255.2637388-3-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075309epcas5p204a699babdf635f11f4b97d3ab8e8a13 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: 20251119075309epcas5p204a699babdf635f11f4b97d3ab8e8a13 References: <20251119075255.2637388-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 a5ceaf5db595..269595e6321e 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 Tue Dec 2 02:32:22 2025 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A7743277B4 for ; Wed, 19 Nov 2025 07:53:21 +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=1763538805; cv=none; b=bLZk73o32LhCKRQ8+Wcz0CqcDOdYvpK/JdPDSNN+PNdcdEsSbItsv8ntJLlFLG5gyBLXmJVlAc0jbzSwSWWGS84clbVc76jylYMzpf62obtTXWgSASXN8Q87TYZbcxqmhKENR9Mc6V+q3tB+moX9RNbkFnfe+98/Uhf5h9wSMS0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538805; c=relaxed/simple; bh=fljmTRcrPwyCRxBUrfkV3a7vXAxFW8thJBz/EBDNK2M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=AfGtazTUgJ14o2jZUrgGuiifPdUhVWboDfyu61PdXVgq2+L9eCaQiBGOBbnsz1IS5XquehEIm1JjxaeMtakV8+Meu5bKn58Sul5dxQwsoJ2oPEU2R1p/1rbh6khIfK0tZPeWWCfu1Or2h4NRGjBHe09vFx7X42GNA8Qqh8ylp9E= 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=u4txUZtU; 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="u4txUZtU" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20251119075313epoutp048cadd4c2d2ee0d27bf6ee7ef28404f85~5WTBnCX9x1369413694epoutp04j for ; Wed, 19 Nov 2025 07:53:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20251119075313epoutp048cadd4c2d2ee0d27bf6ee7ef28404f85~5WTBnCX9x1369413694epoutp04j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538793; bh=WsBTiypWECecOfnMGFc+3wSFBkG6XUMQfj1GvbwkftA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=u4txUZtUl792A4GcP92DRQ8Zu9QxgEs8+d8oB71dHiHgeOTvtlC5YdGvEKQ9L6hd8 c7Ldy2aWDkG3PxJtWhrbwmG6eW8U48wNdwGccDplwfKGYhRi/16ukF3bwn5lWArTkA I06TfbCIvdOgIvfdC6h9CRLVmJ5XDyHOGdwNHDEc= Received: from epsnrtp03.localdomain (unknown [182.195.42.155]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20251119075312epcas5p2fc463f3767aeaccd97cce053530dd955~5WTA8MPss0912909129epcas5p2q; Wed, 19 Nov 2025 07:53:12 +0000 (GMT) Received: from epcas5p3.samsung.com (unknown [182.195.38.90]) by epsnrtp03.localdomain (Postfix) with ESMTP id 4dBDHW59Cgz3hhT4; Wed, 19 Nov 2025 07:53:11 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20251119075311epcas5p1af6f86ca65fd4a8452979e861b87a841~5WS-eR5Br1599915999epcas5p1N; Wed, 19 Nov 2025 07:53:11 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075309epsmtip170bd564a375b01a9533016ef774c97f6~5WS9_QIjC2566025660epsmtip1A; Wed, 19 Nov 2025 07:53:09 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, Neeraj Kumar Subject: [PATCH V4 03/17] nvdimm/label: Add namespace/region label support as per LSA 2.1 Date: Wed, 19 Nov 2025 13:22:41 +0530 Message-Id: <20251119075255.2637388-4-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075311epcas5p1af6f86ca65fd4a8452979e861b87a841 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: 20251119075311epcas5p1af6f86ca65fd4a8452979e861b87a841 References: <20251119075255.2637388-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 Signed-off-by: Neeraj Kumar Reviewed-by: Dave Jiang --- drivers/nvdimm/label.c | 360 ++++++++++++++++++++++++++------ drivers/nvdimm/label.h | 17 +- drivers/nvdimm/namespace_devs.c | 25 ++- drivers/nvdimm/nd.h | 66 ++++++ include/linux/libnvdimm.h | 8 + 5 files changed, 406 insertions(+), 70 deletions(-) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index 0a9b6c5cb2c3..0d587a5b9f7e 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_set_checksum(region_label, 0); + sum =3D nd_fletcher64(region_label, sizeof_namespace_label(ndd), 1); + region_label_set_checksum(region_label, sum); +} + static bool slot_valid(struct nvdimm_drvdata *ndd, struct nd_namespace_label *nd_label, u32 slot) { @@ -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 */ + uuid_copy((uuid_t *)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 =3D 0; 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 =3D 0; + + /* No need to update region label for non cxl format */ + if (!ndd->cxl) + return 0; + + region_label_cnt =3D find_region_label_count(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..b1abbe602a5e 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -232,6 +232,18 @@ static ssize_t __alt_name_store(struct device *dev, co= nst char *buf, return rc; } =20 +int nd_region_label_update(struct nd_region *nd_region) +{ + int rc; + + nvdimm_bus_lock(&nd_region->dev); + rc =3D nd_pmem_region_label_update(nd_region); + nvdimm_bus_unlock(&nd_region->dev); + + return rc; +} +EXPORT_SYMBOL_GPL(nd_region_label_update); + static int nd_namespace_label_update(struct nd_region *nd_region, struct device *dev) { @@ -2122,13 +2134,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..5fd69c28ffe7 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,67 @@ 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; + + uuid_copy((uuid_t *)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 *region_type; + + if (!ndd->cxl) + return false; + + region_type =3D (uuid_t *) lsa_label->region_label.type; + return uuid_equal(&cxl_region_uuid, region_type); +} + +static inline bool +region_label_uuid_equal(struct cxl_region_label *region_label, + const uuid_t *uuid) +{ + return uuid_equal((uuid_t *) region_label->uuid, uuid); +} + +static inline u64 +region_label_get_checksum(struct cxl_region_label *region_label) +{ + return __le64_to_cpu(region_label->checksum); +} + +static inline void +region_label_set_checksum(struct cxl_region_label *region_label, + u64 checksum) +{ + region_label->checksum =3D __cpu_to_le64(checksum); +} + bool nsl_validate_type_guid(struct nvdimm_drvdata *ndd, struct nd_namespace_label *nd_label, guid_t *guid); enum nvdimm_claim_class nsl_get_claim_class(struct nvdimm_drvdata *ndd, @@ -376,7 +440,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 Tue Dec 2 02:32:22 2025 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47676320A30 for ; Wed, 19 Nov 2025 07:53:17 +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=1763538801; cv=none; b=TS3LUeUJuebWOv5eE12n+v0crJWls+02vI17tDIIDp+iHHJxjQVJ8iElD3fZlvJkfNFzrpvCbh+NvN19EZGUj2l751Zz6F7i0C/8iZ7VHqaxE+GR8m/LrPZeqd9ukiYaeGAnDXVC5l9qexi3TO5qY40DpK3cDWikhr62UdDCcwo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538801; c=relaxed/simple; bh=ypMhn0Q0GMQSRpsgJClAhQxdV8HA9KvCwIobkNtECag=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=QJRvKzy7Ga7xz2pARbjB1cPt02EkEoZ8UZ+v8DmRo3Jf6CUr8/Wj0W1gSciUgXyfa2UZIi74MEqAkG89sFp/D+y4SKztNdIRxN+SWJIA7wRb7XmMHkITCNF8U5Y23tHienuLsDQ/nWV1Y6fdsrwRgWiSBtc+550jJ3oy0FwTa7M= 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=QkEYtrig; 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="QkEYtrig" Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20251119075315epoutp04bf64aad19ca704653751d878be9e7a41~5WTDRRsb_1410114101epoutp04k for ; Wed, 19 Nov 2025 07:53:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20251119075315epoutp04bf64aad19ca704653751d878be9e7a41~5WTDRRsb_1410114101epoutp04k DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538795; bh=JoE3B/f5qTuEWVTLKcRVyuWCSq09YuW6AptM39kalGY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QkEYtrighD6kRsK4T6Er2aOQrLxOTnVzmXtWbUo47VtrQpTn1g3VK2YrtB1JDw+bm oS+A7yVsQfpzjqA2IfJ8u7KKOZd4vI/ySIJsIIKSl1uTWc3sxkfqq/rSf8We8hIy8l 5uLdcy9smWC3RzfvNKmccc6+ZqQQc+Anb4TFaaPo= Received: from epsnrtp02.localdomain (unknown [182.195.42.154]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPS id 20251119075314epcas5p4a84690f4df31dee3ede003d5c6209768~5WTC2EUtE0334103341epcas5p4E; Wed, 19 Nov 2025 07:53:14 +0000 (GMT) Received: from epcas5p2.samsung.com (unknown [182.195.38.86]) by epsnrtp02.localdomain (Postfix) with ESMTP id 4dBDHY5M1cz2SSKm; Wed, 19 Nov 2025 07:53:13 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20251119075313epcas5p2db0de2ac270e4676b12730e10281ef83~5WTBXxxkl0175501755epcas5p2A; Wed, 19 Nov 2025 07:53:13 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075311epsmtip11482b0fd17a1d14c79056d2ee5a4ff1f~5WS-thM6e2605226052epsmtip1Q; Wed, 19 Nov 2025 07:53:11 +0000 (GMT) From: Neeraj Kumar To: linux-cxl@vger.kernel.org, nvdimm@lists.linux.dev, linux-kernel@vger.kernel.org, gost.dev@samsung.com Cc: a.manzanares@samsung.com, vishak.g@samsung.com, neeraj.kernel@gmail.com, Neeraj Kumar Subject: [PATCH V4 04/17] nvdimm/label: Include region label in slot validation Date: Wed, 19 Nov 2025 13:22:42 +0530 Message-Id: <20251119075255.2637388-5-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075313epcas5p2db0de2ac270e4676b12730e10281ef83 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: 20251119075313epcas5p2db0de2ac270e4676b12730e10281ef83 References: <20251119075255.2637388-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* In this patch We have converted all usage of to_label() to to_lsa_label() Reviewed-by: Jonathan Cameron Signed-off-by: Neeraj Kumar Reviewed-by: Dave Jiang --- drivers/nvdimm/label.c | 94 ++++++++++++++++++++++++++++-------------- drivers/nvdimm/nd.h | 5 +++ 2 files changed, 69 insertions(+), 30 deletions(-) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index 0d587a5b9f7e..6ccc51552822 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 region_label_get_checksum(region_label); + region_label_set_checksum(region_label, 0); + sum =3D nd_fletcher64(region_label, sizeof_namespace_label(ndd), 1); + region_label_set_checksum(region_label, sum_save); + return sum =3D=3D sum_save; +} + static void region_label_calculate_checksum(struct nvdimm_drvdata *ndd, struct cxl_region_label *region_label) { @@ -415,16 +417,34 @@ static void region_label_calculate_checksum(struct nv= dimm_drvdata *ndd, } =20 static bool slot_valid(struct nvdimm_drvdata *ndd, - struct nd_namespace_label *nd_label, u32 slot) + union nd_lsa_label *lsa_label, u32 slot) { + struct cxl_region_label *region_label =3D &lsa_label->region_label; + struct nd_namespace_label *nd_label =3D &lsa_label->ns_label; + 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)) { + type =3D RG_LABEL_TYPE; + if (slot !=3D region_label_get_slot(region_label)) + return false; + valid =3D region_label_validate_checksum(ndd, region_label); + } else { + 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 +460,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,18 +620,30 @@ int nd_label_active_count(struct nvdimm_drvdata *ndd) return 0; =20 for_each_clear_bit_le(slot, free, nslot) { + struct cxl_region_label *region_label; struct nd_namespace_label *nd_label; - - nd_label =3D to_label(ndd, slot); - - if (!slot_valid(ndd, nd_label, slot)) { - u32 label_slot =3D nsl_get_slot(ndd, nd_label); - u64 size =3D nsl_get_rawsize(ndd, nd_label); - u64 dpa =3D nsl_get_dpa(ndd, nd_label); + union nd_lsa_label *lsa_label; + u32 lslot; + u64 size, dpa; + + lsa_label =3D to_lsa_label(ndd, slot); + nd_label =3D &lsa_label->ns_label; + region_label =3D &lsa_label->region_label; + + if (!slot_valid(ndd, lsa_label, slot)) { + if (is_region_label(ndd, lsa_label)) { + lslot =3D __le32_to_cpu(region_label->slot); + size =3D __le64_to_cpu(region_label->rawsize); + dpa =3D __le64_to_cpu(region_label->dpa); + } else { + lslot =3D nsl_get_slot(ndd, nd_label); + size =3D nsl_get_rawsize(ndd, nd_label); + dpa =3D nsl_get_dpa(ndd, nd_label); + } =20 dev_dbg(ndd->dev, "slot%d invalid slot: %d dpa: %llx size: %llx\n", - slot, label_slot, dpa, size); + slot, lslot, dpa, size); continue; } count++; @@ -627,10 +661,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) diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h index 5fd69c28ffe7..30c7262d8a26 100644 --- a/drivers/nvdimm/nd.h +++ b/drivers/nvdimm/nd.h @@ -346,6 +346,11 @@ region_label_uuid_equal(struct cxl_region_label *regio= n_label, return uuid_equal((uuid_t *) region_label->uuid, uuid); } =20 +static inline u32 region_label_get_slot(struct cxl_region_label *region_la= bel) +{ + return __le32_to_cpu(region_label->slot); +} + static inline u64 region_label_get_checksum(struct cxl_region_label *region_label) { --=20 2.34.1 From nobody Tue Dec 2 02:32:22 2025 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66B612D7801 for ; Wed, 19 Nov 2025 07:53:19 +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=1763538801; cv=none; b=u5VqM9LJbIudpbonrSlSYf7QfNOLfxhUlWs47X9l+KH55FbzVjBR1ERVWEzdRPyZ73XrBKHDOqdzSGs8bCU//GOWRmNV+ZbLcZ/fudSOhV8gGfAxFiYLs8cCdI6vZL5WhnMA7o49Q65zITH8d2TFLNXJ0c022LBxpYKFpHDhVT0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538801; c=relaxed/simple; bh=smiYMCJ3GpxAWMiqb+arblnaWcl4SogFr6+11VFacFA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=Ao8ufZNKxk9pIRSYuiSKsW4X2wfp/PmqVRIxN31OSYn0HrOGJI/KpK0EjVcuW+gme4GXfAofpipYD8YtlUGqzp/3mI0bObdbhdkX3OOnKkXT2V7zFsu2o+VCgGAlRHVrDWnPcoVJrQhsSNBpvexiDWg/SsgymbChnbA995fB8vg= 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=KlQDvjTt; 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="KlQDvjTt" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20251119075317epoutp023cb7da7ebc08699de38d7186c81c8cc5~5WTFRHeG82683826838epoutp02D for ; Wed, 19 Nov 2025 07:53:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20251119075317epoutp023cb7da7ebc08699de38d7186c81c8cc5~5WTFRHeG82683826838epoutp02D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538797; bh=Kg+JhK8ZnwwhPgJ82TO8KyWjNuZjCa1lJq/zsnBHHVU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KlQDvjTt5VEL+w+NpV41Yp7tGzipOuElnPKR6F235YLuZr6BdIEACwzPevl7+oZvX BNE/h2b1lrGn9zRSWsIhldj3L3qHzdl91de+aYJ1HnrSk8iQq1TluqHvFG9fK9wHAZ Ok42tZDDYO0u/6s9vvZe/vJF5mkCGaNqzxsQa/PI= Received: from epsnrtp02.localdomain (unknown [182.195.42.154]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPS id 20251119075317epcas5p4c77b246971ef67641eaf9dddca9a75cc~5WTFCBjny2373623736epcas5p4x; Wed, 19 Nov 2025 07:53:17 +0000 (GMT) Received: from epcas5p1.samsung.com (unknown [182.195.38.91]) by epsnrtp02.localdomain (Postfix) with ESMTP id 4dBDHc1nQNz2SSKp; Wed, 19 Nov 2025 07:53:16 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20251119075315epcas5p2be6f51993152492f0dd64366863d70e2~5WTDzEfti1867518675epcas5p2F; Wed, 19 Nov 2025 07:53:15 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075313epsmtip1ee62d704c02f9eff2695f7ea412c25e8~5WTBnEPqp2565625656epsmtip1U; Wed, 19 Nov 2025 07:53:13 +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 V4 05/17] nvdimm/label: Skip region label during ns label DPA reservation Date: Wed, 19 Nov 2025 13:22:43 +0530 Message-Id: <20251119075255.2637388-6-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075315epcas5p2be6f51993152492f0dd64366863d70e2 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: 20251119075315epcas5p2be6f51993152492f0dd64366863d70e2 References: <20251119075255.2637388-1-s.neeraj@samsung.com> If Namespace label is present in LSA during nvdimm_probe() then DPA reservation is required. But this reservation is not required by region label. Therefore if LSA scanning finds any region label, skip it. Signed-off-by: Neeraj Kumar Reviewed-by: Dave Jiang --- drivers/nvdimm/label.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index 6ccc51552822..e90e48672da3 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -469,6 +469,10 @@ 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 + /* Skip region label. DPA reservation is for NS label only */ + if (is_region_label(ndd, lsa_label)) + continue; + if (!slot_valid(ndd, lsa_label, slot)) continue; =20 --=20 2.34.1 From nobody Tue Dec 2 02:32:22 2025 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31431325716 for ; Wed, 19 Nov 2025 07:53:20 +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=1763538803; cv=none; b=L07jOlNXHoKQPnyHh4MZSevIsvXGbzo54oPTQi9VB37RSH0PnDdtFW0/NGJs5ojw3SfDYUi/ZieGPF9T18YWtJaOhxUAMvSlXWwKzjMlVNdNPvtoXdJSWNNo+crN/0D1FvyNG3xkAuobcSV0eadFFJ6gw3iS6ktncQKJcZ/w2QM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538803; c=relaxed/simple; bh=Yqw1K860oHVedQqAJVS3TE0A6Qg36ZdNGkGWr4rs7qA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=vCGvJDsO8weYON60QDys2p0DqZGxHaJElSS9bm+yFiS2a1hE8s2bzJlzc3OefVW7rD626w/G1AGXsbAtdosuT7BOS4XonuVO9wG1xUbYJJ4BMFOd3O3h+BBEN0MXVaSRg2zrvFfIGUMRLR6ZIxql6aIW1GEo5CiMVjl9u38UqKg= 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=YbJmSbwt; 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="YbJmSbwt" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20251119075319epoutp02af5c4353da731a46626af752e209b8d7~5WTG23hp12680826808epoutp02R for ; Wed, 19 Nov 2025 07:53:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20251119075319epoutp02af5c4353da731a46626af752e209b8d7~5WTG23hp12680826808epoutp02R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538799; bh=4x+K7Cx6L38kqLC/vl+6BzQLovRHHs/YI6/d6xMJlvI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YbJmSbwt6Dh6G8ntsOS6Hyq/kNByY//Xn6T7zH1s3k+f40eLe5pEfj11q3rRGGa9O /z6jaBCetWP0tIBIvYimkE8dm0ko7QOduoBrBLKsTnhQEYCvI8YVASxp8Gkoy72yjm zxJTUFi73VORNVAfIpxp2k5g024f4pGHq2ocycEk= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPS id 20251119075318epcas5p3c97d3948f67f3a25a2ec5ef6fe22be18~5WTGhPi8M0354903549epcas5p3V; Wed, 19 Nov 2025 07:53:18 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.94]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4dBDHd5ptJz6B9mJ; Wed, 19 Nov 2025 07:53:17 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20251119075317epcas5p41468e3c1602d89e634f48a7b67454663~5WTFJWikK0332303323epcas5p4M; Wed, 19 Nov 2025 07:53:17 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075316epsmtip1e04e10307a6a9263f1b79d6ed3a98df6~5WTECN61X2604526045epsmtip1S; Wed, 19 Nov 2025 07:53:15 +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 V4 06/17] nvdimm/label: Preserve region label during namespace creation Date: Wed, 19 Nov 2025 13:22:44 +0530 Message-Id: <20251119075255.2637388-7-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075317epcas5p41468e3c1602d89e634f48a7b67454663 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: 20251119075317epcas5p41468e3c1602d89e634f48a7b67454663 References: <20251119075255.2637388-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 Signed-off-by: Neeraj Kumar Reviewed-by: Dave Jiang --- 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 b1abbe602a5e..9450200b4470 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -1999,9 +1999,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; @@ -2013,7 +2036,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 @@ -2024,10 +2047,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 Tue Dec 2 02:32:22 2025 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 86B3C328B69 for ; Wed, 19 Nov 2025 07:53:23 +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=1763538806; cv=none; b=mFoFnYx7h3eB237r1bRYyyi3cmA4rteC+CKFgiR38R83FAMPNy9tL5axmM9z/h5KpBm6brPEJBItQXWSORI6ZtJKB8Ek0JVJTbMrTQzXmOH9rog4Rzq845DcEyhIPJIK8pCDJmfmHz+l9blULshoLCs27P769giVK+qGRLOhcaE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538806; c=relaxed/simple; bh=l5r1bvh6LDoBeIcHYiJgNcCRv0EOwPTUgben6xc9GAU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=qeGKeguL4bCaYQhTRC3+F7DyUiWUBKkkdgazzLC4WxU90Bs1qHPCbvsKaGUh6pNuv387btmzTMtyAwJ1r+/2vmxoLfdOko7Tu3tcbdRbGv14l/9VCgbU4lb7eLT5eevMs0XpbcWNc0xDzW/QXjPxx5Lw7HqyTetpbMeXNlU67Ps= 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=Ws1NumQx; 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="Ws1NumQx" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20251119075321epoutp01bd73b6ce0d3ff4b879052a6580b55bcc~5WTJFJEiF3155131551epoutp01j for ; Wed, 19 Nov 2025 07:53:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20251119075321epoutp01bd73b6ce0d3ff4b879052a6580b55bcc~5WTJFJEiF3155131551epoutp01j DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538801; bh=w26qsRHcIfkdliipZ7xkb7xoi4LnA7c+2pfJfJorvqo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ws1NumQxILMvrLCIYdFkJX8JHUpCOqXjpF0jr93HIwG3DWfY/h5qiqjou8OrROiBP K6l4bhZlcbjo5aj7UNLbF+WrPKyuGQr+M+2c5pxH+t4qrFMxkkKg0krZ1LaFiJ5OA5 KR2vLutusAwEg3i7zdrNodPOP37WrS8/FsYhkoH0= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPS id 20251119075321epcas5p3017fa4bb2e4751c7604151e7cacbb118~5WTIoeyB73101731017epcas5p3b; Wed, 19 Nov 2025 07:53:21 +0000 (GMT) Received: from epcas5p2.samsung.com (unknown [182.195.38.91]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4dBDHh0NP0z6B9m9; Wed, 19 Nov 2025 07:53:20 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20251119075319epcas5p2374c721a42a68cfb6f2b17b17c51c0ea~5WTHPhK3W0912909129epcas5p29; Wed, 19 Nov 2025 07:53:19 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075317epsmtip13d23869e6dd2400f1a9bb9aa89423cf7~5WTFihqNt2566025660epsmtip1I; Wed, 19 Nov 2025 07:53:17 +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 V4 07/17] nvdimm/label: Add region label delete support Date: Wed, 19 Nov 2025 13:22:45 +0530 Message-Id: <20251119075255.2637388-8-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075319epcas5p2374c721a42a68cfb6f2b17b17c51c0ea 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: 20251119075319epcas5p2374c721a42a68cfb6f2b17b17c51c0ea References: <20251119075255.2637388-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 Signed-off-by: Neeraj Kumar Reviewed-by: Dave Jiang --- drivers/nvdimm/label.c | 76 ++++++++++++++++++++++++++++++--- drivers/nvdimm/label.h | 1 + drivers/nvdimm/namespace_devs.c | 12 ++++++ drivers/nvdimm/nd.h | 6 +++ include/linux/libnvdimm.h | 1 + 5 files changed, 90 insertions(+), 6 deletions(-) diff --git a/drivers/nvdimm/label.c b/drivers/nvdimm/label.c index e90e48672da3..da55ecd95e2f 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -1225,7 +1225,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; @@ -1244,11 +1245,25 @@ 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); @@ -1257,10 +1272,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"); } @@ -1296,7 +1313,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; @@ -1381,6 +1399,52 @@ 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++) { + struct nd_mapping *nd_mapping =3D &nd_region->mapping[i]; + + rc =3D del_labels(nd_mapping, &nd_set->uuid, RG_LABEL_TYPE); + if (rc) + return rc; + } + + return 0; +} + int __init nd_label_init(void) { WARN_ON(guid_parse(NVDIMM_BTT_GUID, &nvdimm_btt_guid)); diff --git a/drivers/nvdimm/label.h b/drivers/nvdimm/label.h index 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 9450200b4470..9299a586bfce 100644 --- a/drivers/nvdimm/namespace_devs.c +++ b/drivers/nvdimm/namespace_devs.c @@ -244,6 +244,18 @@ int nd_region_label_update(struct nd_region *nd_region) } EXPORT_SYMBOL_GPL(nd_region_label_update); =20 +int nd_region_label_delete(struct nd_region *nd_region) +{ + int rc; + + nvdimm_bus_lock(&nd_region->dev); + rc =3D nd_pmem_region_label_delete(nd_region); + nvdimm_bus_unlock(&nd_region->dev); + + return rc; +} +EXPORT_SYMBOL_GPL(nd_region_label_delete); + static int nd_namespace_label_update(struct nd_region *nd_region, struct device *dev) { diff --git a/drivers/nvdimm/nd.h b/drivers/nvdimm/nd.h index 30c7262d8a26..b241a0b2e314 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(&cxl_region_uuid, region_type); } =20 +static inline bool nsl_region_uuid_equal(struct nd_namespace_label *ns_lab= el, + const uuid_t *uuid) +{ + return uuid_equal((uuid_t *) ns_label->cxl.region_uuid, uuid); +} + static inline bool region_label_uuid_equal(struct cxl_region_label *region_label, const uuid_t *uuid) diff --git a/include/linux/libnvdimm.h b/include/linux/libnvdimm.h index 2c213b9dac66..bbf14a260c93 100644 --- a/include/linux/libnvdimm.h +++ b/include/linux/libnvdimm.h @@ -315,6 +315,7 @@ int nvdimm_has_cache(struct nd_region *nd_region); int nvdimm_in_overwrite(struct nvdimm *nvdimm); bool is_nvdimm_sync(struct nd_region *nd_region); int nd_region_label_update(struct nd_region *nd_region); +int nd_region_label_delete(struct nd_region *nd_region); =20 static inline int nvdimm_ctl(struct nvdimm *nvdimm, unsigned int cmd, void= *buf, unsigned int buf_len, int *cmd_rc) --=20 2.34.1 From nobody Tue Dec 2 02:32:22 2025 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ABCA332E131 for ; Wed, 19 Nov 2025 07:53:25 +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=1763538808; cv=none; b=ARNh0YKI78Au8RAUH605Zt+q0JxEwecIrMT2dK6BYqIHg7IcpZE/1fVRtDdyLs5ERekByPaHUzC8rRVbV1l5gZ2xjzeaaiyS2jHDmMNAjM7hJyktH81xFOhHWchy/mMrMuE6fz/DN7hlxT423rjNfsrjrfF3SCfIlQqkPgUmDco= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538808; c=relaxed/simple; bh=oAcaU2hpucQZNGlisFd1k5yBX0F8qMiXFExPoQHvt8E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=Lq0Zv5BmbHxIGgV6YIuV3I23ZxX2KQXQkDv4HV5OJU9lh35h7ag+9x/mHlxc4FeE547JFqWWvnKQrzasZxfozgqF18FjZel/63bPvYZdmqTLaLWiG1Nrzlk5wMRl63Yp04epJIsTaVWY0xDXG04B8wRzyrr6axpVV7RnjKHy/4o= 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=ci1r5zCi; 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="ci1r5zCi" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20251119075323epoutp02dd6da8476b87ebc88199baed08fd9edb~5WTLN5cHj2685926859epoutp02J for ; Wed, 19 Nov 2025 07:53:23 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20251119075323epoutp02dd6da8476b87ebc88199baed08fd9edb~5WTLN5cHj2685926859epoutp02J DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538803; bh=SkwP4HhOpRTbS1pQ24chsgXJFLDk7ZKuo9B0djks+YE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ci1r5zCiA4bFeeNRW1OvNOb3dNUgiCL+eBZRXSzoRpAo1DsBpWEDdh/5sBrJw/adj ygwRX1KFomI/33OdBfZceoEtoAHkjSraGkmfErTkQbV7ra2A631+B4rc4qf2oCc3Rc BwH45h3I9oTdisSnyrdR6WNHzhlLz2UPv+a6SCZg= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPS id 20251119075322epcas5p4c069d89c40b91a90d194960f64210a66~5WTKP5G7M0334103341epcas5p4S; Wed, 19 Nov 2025 07:53:22 +0000 (GMT) Received: from epcas5p2.samsung.com (unknown [182.195.38.93]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4dBDHj56QMz6B9m7; Wed, 19 Nov 2025 07:53:21 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20251119075321epcas5p19665a54028ce13d8c1af3f00c0834fc7~5WTIyWZw-2708227082epcas5p1M; Wed, 19 Nov 2025 07:53:21 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075319epsmtip170c5bc491ea2854fec5450bbbba71ab7~5WTHeoRgi2565625656epsmtip1W; Wed, 19 Nov 2025 07:53:19 +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 V4 08/17] nvdimm/label: Preserve cxl region information from region label Date: Wed, 19 Nov 2025 13:22:46 +0530 Message-Id: <20251119075255.2637388-9-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075321epcas5p19665a54028ce13d8c1af3f00c0834fc7 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: 20251119075321epcas5p19665a54028ce13d8c1af3f00c0834fc7 References: <20251119075255.2637388-1-s.neeraj@samsung.com> Preserve region information from region label during nvdimm_probe. This preserved region information is used for creating cxl region to achieve region persistency across reboot. Signed-off-by: Neeraj Kumar Reviewed-by: Dave Jiang --- drivers/nvdimm/dimm.c | 4 ++++ drivers/nvdimm/label.c | 40 +++++++++++++++++++++++++++++++++++++++ drivers/nvdimm/nd-core.h | 2 ++ drivers/nvdimm/nd.h | 1 + include/linux/libnvdimm.h | 14 ++++++++++++++ 5 files changed, 61 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 da55ecd95e2f..0f8aea61b504 100644 --- a/drivers/nvdimm/label.c +++ b/drivers/nvdimm/label.c @@ -490,6 +490,46 @@ 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; + struct cxl_region_label *region_label; + uuid_t *region_uuid; + + lsa_label =3D to_lsa_label(ndd, slot); + region_label =3D &lsa_label->region_label; + region_uuid =3D (uuid_t *) ®ion_label->type; + + /* TODO: Currently preserving only one region */ + if (uuid_equal(&cxl_region_uuid, region_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 b241a0b2e314..281d30dd9ba0 100644 --- a/drivers/nvdimm/nd.h +++ b/drivers/nvdimm/nd.h @@ -600,6 +600,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 Tue Dec 2 02:32:22 2025 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A719432E6A7 for ; Wed, 19 Nov 2025 07:53:26 +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=1763538808; cv=none; b=qrdzo0lhYq02eyX0lDpj1lXtbRhJqHxSTbiwGCxhl8Ia9rQKX1KmUYMBywX2wuGrhrF9W+/Enf3h8FG2MnryT6T2Q7+oD+wUdHuj7WTYFi0XBUgpAnaUrSAJz/FCvgmYZPdHaabWM088gRqsxoDtHXtox1UJiniK2Xh0z7KBVr0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538808; c=relaxed/simple; bh=i1FI22B+24KIAZ+Y/EUtwTheSp2SKHQG5cukeITglik=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=GiMxoA08vLiXGyFvUhw2DT8inlldIn8aAFME8Fq1N3ftEnYqaV4h8BSZUxoD+ssd4PgtAl+YplKROUtqi9Dio6cJNf4VWQqiW9Ot8824e56VFhFT5I2sy9KdFD5kCU7cL0bgyKAHuWUGsKCTCmcqzEFDXjRoQuBy95u+ca+8Kas= 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=cFjhzVva; 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="cFjhzVva" Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20251119075324epoutp027f0b3216497da2d1f81ee7d9b2ec6654~5WTMMXVDY2685926859epoutp02K for ; Wed, 19 Nov 2025 07:53:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20251119075324epoutp027f0b3216497da2d1f81ee7d9b2ec6654~5WTMMXVDY2685926859epoutp02K DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538804; bh=XgdTodktIe2yEqaotEXyfE/JNHfS6ZzRHo/QULupwQ0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cFjhzVvaRqWaE4tuUMMaHo+Ap6jzGdSTvNK9pwMhmqYoqxbnSnWWrbdfBklOg5hW+ HcEcR1nT9IQchETyBMdoz513nGrsB4XKPouePOHbOBbIqlo4DWQTfWMN5c4xksBSd+ 5GOiLxQFmn/cT62He93ThDD8Smaw83JCgathtNRM= Received: from epsnrtp01.localdomain (unknown [182.195.42.153]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20251119075324epcas5p24b78bc8b647adcda3d94983f04767d88~5WTL9o2mX1868418684epcas5p2c; Wed, 19 Nov 2025 07:53:24 +0000 (GMT) Received: from epcas5p3.samsung.com (unknown [182.195.38.86]) by epsnrtp01.localdomain (Postfix) with ESMTP id 4dBDHl4TGfz6B9m5; Wed, 19 Nov 2025 07:53:23 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20251119075323epcas5p369dea15a390bea0b3690e2a19533f956~5WTKm-Y8O0364303643epcas5p3W; Wed, 19 Nov 2025 07:53:23 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075321epsmtip1ab2e1ccf16e014d177c3485c3cf833f1~5WTI6SQn32573625736epsmtip1l; Wed, 19 Nov 2025 07:53: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 V4 09/17] nvdimm/label: Export routine to fetch region information Date: Wed, 19 Nov 2025 13:22:47 +0530 Message-Id: <20251119075255.2637388-10-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075323epcas5p369dea15a390bea0b3690e2a19533f956 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: 20251119075323epcas5p369dea15a390bea0b3690e2a19533f956 References: <20251119075255.2637388-1-s.neeraj@samsung.com> CXL region information preserved from the LSA needs to be exported for use by the CXL driver for CXL region re-creation. Signed-off-by: Neeraj Kumar Reviewed-by: Dave Jiang --- drivers/nvdimm/dimm_devs.c | 18 ++++++++++++++++++ include/linux/libnvdimm.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/drivers/nvdimm/dimm_devs.c b/drivers/nvdimm/dimm_devs.c index 3363a97cc5b5..1474b4e45fcc 100644 --- a/drivers/nvdimm/dimm_devs.c +++ b/drivers/nvdimm/dimm_devs.c @@ -280,6 +280,24 @@ void *nvdimm_provider_data(struct nvdimm *nvdimm) } EXPORT_SYMBOL_GPL(nvdimm_provider_data); =20 +bool nvdimm_has_cxl_region(struct nvdimm *nvdimm) +{ + if (!nvdimm) + return false; + + return nvdimm->is_region_label; +} +EXPORT_SYMBOL_GPL(nvdimm_has_cxl_region); + +void *nvdimm_get_cxl_region_param(struct nvdimm *nvdimm) +{ + if (!nvdimm) + return NULL; + + 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 Tue Dec 2 02:32:22 2025 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99E9832E75F for ; Wed, 19 Nov 2025 07:53:28 +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=1763538811; cv=none; b=aAx0xItC8TTjQhQXi5jeHzPwspOwsiVtxl5xGUylXkXjG19pct/u5gd0jxLAnlINy/1mJxsf+/TIe2gJE57EDs5Qt4nWan7QFF3WWkwLSZbhGPqBD84jvIgV+2ri1oSmueic1b3AFpvzua/hUIVF3BVBeguV36DrZsmmUyiPfN4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538811; c=relaxed/simple; bh=rCnFs+wTFiUzB8dwDWhtT0JfRAiF5oUhvonJGQ9Bzws=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=kAE6484AhWAmbq4DyrU3PYaSbRUfC+fg6SGCHdqmIqJEB8y1Od9mrBp33w3TCSnMpEUc+3wy2F7UE84l4c/0xEo/lXH2MyCFYDzwrid060ctmrUyfVE/7UZKI9LGD+I5/jeiZi0NhQQwdJZzaS6etnvtPCpuIuePGK3bRYoGxNk= 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=kcxQOhVH; 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="kcxQOhVH" Received: from epcas5p2.samsung.com (unknown [182.195.41.40]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20251119075326epoutp014c2035fd1eee6a40ef85688f05af588f~5WTODJJeo3132231322epoutp01i for ; Wed, 19 Nov 2025 07:53:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20251119075326epoutp014c2035fd1eee6a40ef85688f05af588f~5WTODJJeo3132231322epoutp01i DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538806; bh=g71o0PINWhr1xwvhb/lFkayQCIafgmrL7rI+AkDSi7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kcxQOhVHa47TnJY+YHN7pj27wim8+CxB7jx4XkViN5n9OFmvcb5hbpHuegJ2NaL9E Os3RNWKotjnnD/+Dnw8Ya6zESI4G8x5SZETc0d0fcvt8WKOgWxSg+K34G0EyLvAVOX hvYTfXk50VqkILDocCQ7dwqvJtyJjbJbEZx/O8Oo= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPS id 20251119075326epcas5p3c6a45700cffb798e2a79999acc8b4137~5WTNvkL3a0829208292epcas5p3B; Wed, 19 Nov 2025 07:53:26 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.89]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4dBDHn39xNz6B9m8; Wed, 19 Nov 2025 07:53:25 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p1.samsung.com (KnoxPortal) with ESMTPA id 20251119075324epcas5p1b0a7149ede962491e6be2d72d33f77eb~5WTMOZS7o1599915999epcas5p1a; Wed, 19 Nov 2025 07:53:24 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075323epsmtip1298d30dc1c8595c3634129f813fc0c23~5WTLHh0VD2604526045epsmtip1Y; Wed, 19 Nov 2025 07:53: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 V4 10/17] cxl/mem: Refactor cxl pmem region auto-assembling Date: Wed, 19 Nov 2025 13:22:48 +0530 Message-Id: <20251119075255.2637388-11-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075324epcas5p1b0a7149ede962491e6be2d72d33f77eb 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: 20251119075324epcas5p1b0a7149ede962491e6be2d72d33f77eb References: <20251119075255.2637388-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->ops->probe() calls registered cxl_region_discovery(), so move devm_cxl_add_nvdimm() before cxlmd->ops->probe(). It gurantees both the completion of endpoint probe and cxl_nvd presence before calling cxlmd->ops->probe(). Signed-off-by: Neeraj Kumar Reviewed-by: Dave Jiang --- 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 2cf5b29cefd2..3c868c4de4ec 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3724,6 +3724,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 ba17fa86d249..684a0d1b441a 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -904,6 +904,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) { @@ -926,6 +927,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 13d9e089ecaf..f5e3e2fca86c 100644 --- a/drivers/cxl/mem.c +++ b/drivers/cxl/mem.c @@ -115,15 +115,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 @@ -143,6 +134,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->ops) { rc =3D cxlmd->ops->probe(cxlmd); if (rc) diff --git a/drivers/cxl/pci.c b/drivers/cxl/pci.c index e21051d79b25..d56fdfe4b43b 100644 --- a/drivers/cxl/pci.c +++ b/drivers/cxl/pci.c @@ -907,6 +907,7 @@ static int cxl_pci_probe(struct pci_dev *pdev, const st= ruct pci_device_id *id) struct cxl_memdev_state *mds; struct cxl_dev_state *cxlds; struct cxl_register_map map; + struct cxl_memdev_ops ops; struct cxl_memdev *cxlmd; int rc, pmu_count; unsigned int i; @@ -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(&pdev->dev, cxlds, NULL); + ops.probe =3D cxl_region_discovery; + cxlmd =3D devm_cxl_add_memdev(&pdev->dev, cxlds, &ops); if (IS_ERR(cxlmd)) return PTR_ERR(cxlmd); =20 diff --git a/drivers/cxl/port.c b/drivers/cxl/port.c index d5fd0c5ae49b..ad98b2881fed 100644 --- a/drivers/cxl/port.c +++ b/drivers/cxl/port.c @@ -31,33 +31,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 */ @@ -83,17 +56,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 Tue Dec 2 02:32:22 2025 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1F09E29B79B for ; Wed, 19 Nov 2025 07:53:30 +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=1763538813; cv=none; b=sLbTLlqb0XNobyZHj47IixQIs/7uDTrN5XKQz2w7bsf4Jieug5/ZGfqgaOYbKjr3vRpQq+4sxhAbJxIhC50O+p63laCxVOMD6Lm0rWXcTvph3mo+AoVCbSOyHlL5vJ/eVlmnq2z6z1MNNP5Q7GzM5NvflJzmjRTbz+vquD8XU1Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538813; c=relaxed/simple; bh=ddqsAoildU29bgw12poMrTNGEm2wd9LLl2mU0azwNTg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=QHJRksqV5a/90MGHj7KjAjyj1uUDdcSGaHj5MBdVMVi6qwPNw88vOoBcMNyN5z2bLfPwfq0/Ifbs1no0QyAq+2I9BGkG/oXe4gpbf7hAVbEz3glUfzq+c7NqBY5pRkqaL5C9LK/lNs9HzMfomX9ts+HQAFTRvP/qIi732jNXoWM= 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=CGHgo/Fg; 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="CGHgo/Fg" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20251119075329epoutp04edd6dcd3606bd9af5a2f7de510bf76bb~5WTQYK0-d1680216802epoutp04O for ; Wed, 19 Nov 2025 07:53:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20251119075329epoutp04edd6dcd3606bd9af5a2f7de510bf76bb~5WTQYK0-d1680216802epoutp04O DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538809; bh=TMmzIrOMVYX+K4e/SmF/lOkxVcUq2FEcYqKgyP4Jo8E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CGHgo/FgpbaE4QG4qhRscSo9+EvMBhd9nC9QadmLBlvrd9ncCkXvgfdGNbmNyNt9Z g9hhUdLRNXL2P/O+ZUFR6AIuskkBtx0G0ZwI3sRCV0dO5xSZWxybRL0F3+bKwiIO0w zeV/yLAKlQOMHIZX+H99EMuMQ5oCT2uSKVaQY+ps= Received: from epsnrtp02.localdomain (unknown [182.195.42.154]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPS id 20251119075329epcas5p3c6477e07762f44b8abd3a3f81c007aa9~5WTQHsSXc0364303643epcas5p3n; Wed, 19 Nov 2025 07:53:29 +0000 (GMT) Received: from epcas5p2.samsung.com (unknown [182.195.38.94]) by epsnrtp02.localdomain (Postfix) with ESMTP id 4dBDHr0Cdhz2SSKf; Wed, 19 Nov 2025 07:53:28 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20251119075327epcas5p29991fec95ca8a26503f457a30bb2429a~5WTOgFtar0912909129epcas5p2Q; Wed, 19 Nov 2025 07:53:27 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075325epsmtip11383e765cc6ba195188097c155d01016~5WTMdV8iq2573225732epsmtip16; Wed, 19 Nov 2025 07:53: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 V4 11/17] cxl/region: Add devm_cxl_pmem_add_region() for pmem region creation Date: Wed, 19 Nov 2025 13:22:49 +0530 Message-Id: <20251119075255.2637388-12-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075327epcas5p29991fec95ca8a26503f457a30bb2429a 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: 20251119075327epcas5p29991fec95ca8a26503f457a30bb2429a References: <20251119075255.2637388-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 Rename __create_region() to cxl_create_region(), which will be used in later patch to create cxl region after fetching region information from LSA. Signed-off-by: Neeraj Kumar Reviewed-by: Dave Jiang --- drivers/cxl/core/core.h | 12 ++++ drivers/cxl/core/region.c | 124 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 131 insertions(+), 5 deletions(-) diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index 1fb66132b777..fde96507cb75 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 *params, + struct cxl_decoder *cxld); =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_decoder *cxld) +{ + 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 3c868c4de4ec..06a75f0a8e9b 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -2618,6 +2618,114 @@ static struct cxl_region *devm_cxl_add_region(struc= t cxl_root_decoder *cxlrd, return ERR_PTR(rc); } =20 +static ssize_t alloc_region_hpa(struct cxl_region *cxlr, u64 size) +{ + int rc; + + ACQUIRE(rwsem_write_kill, rwsem)(&cxl_rwsem.region); + if ((rc =3D ACQUIRE_ERR(rwsem_write_kill, &rwsem))) + return rc; + + if (!size) + return -EINVAL; + + return alloc_hpa(cxlr, size); +} + +static ssize_t alloc_region_dpa(struct cxl_endpoint_decoder *cxled, u64 si= ze) +{ + int rc; + + if (!size) + return -EINVAL; + + if (!IS_ALIGNED(size, SZ_256M)) + return -EINVAL; + + rc =3D cxl_dpa_free(cxled); + if (rc) + return rc; + + return cxl_dpa_alloc(cxled, size); +} + +static struct cxl_region * +devm_cxl_pmem_add_region(struct cxl_root_decoder *cxlrd, int id, + struct cxl_pmem_region_params *params, + struct cxl_decoder *cxld, + enum cxl_decoder_type type) +{ + struct cxl_endpoint_decoder *cxled; + struct cxl_region_params *p; + struct cxl_port *root_port; + struct device *dev; + int rc; + + struct cxl_region *cxlr __free(put_cxl_region) =3D + cxl_region_alloc(cxlrd, id); + if (IS_ERR(cxlr)) + return cxlr; + + cxlr->mode =3D CXL_PARTMODE_PMEM; + cxlr->type =3D type; + + dev =3D &cxlr->dev; + rc =3D dev_set_name(dev, "region%d", id); + if (rc) + return ERR_PTR(rc); + + p =3D &cxlr->params; + p->uuid =3D params->uuid; + p->interleave_ways =3D params->nlabel; + p->interleave_granularity =3D params->ig; + + rc =3D alloc_region_hpa(cxlr, params->rawsize); + if (rc) + return ERR_PTR(rc); + + cxled =3D to_cxl_endpoint_decoder(&cxld->dev); + + rc =3D cxl_dpa_set_part(cxled, CXL_PARTMODE_PMEM); + if (rc) + return ERR_PTR(rc); + + rc =3D alloc_region_dpa(cxled, params->rawsize); + if (rc) + return ERR_PTR(rc); + + /* + * TODO: Currently we have support of interleave_way =3D=3D 1, where + * we can only have one region per mem device. It means mem device + * position (params->position) will always be 0. It is therefore + * attaching only one target at params->position + */ + if (params->position) + return ERR_PTR(-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); + + root_port =3D to_cxl_port(cxlrd->cxlsd.cxld.dev.parent); + rc =3D devm_add_action_or_reset(root_port->uport_dev, + unregister_region, cxlr); + if (rc) + return ERR_PTR(rc); + + dev_dbg(root_port->uport_dev, "%s: created %s\n", + dev_name(&cxlrd->cxlsd.cxld.dev), dev_name(dev)); + + return no_free_ptr(cxlr); +} + static ssize_t __create_region_show(struct cxl_root_decoder *cxlrd, char *= buf) { return sysfs_emit(buf, "region%u\n", atomic_read(&cxlrd->region_id)); @@ -2635,8 +2743,10 @@ static ssize_t create_ram_region_show(struct device = *dev, return __create_region_show(to_cxl_root_decoder(dev), buf); } =20 -static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd, - enum cxl_partition_mode mode, int id) +struct cxl_region *cxl_create_region(struct cxl_root_decoder *cxlrd, + enum cxl_partition_mode mode, int id, + struct cxl_pmem_region_params *pmem_params, + struct cxl_decoder *cxld) { int rc; =20 @@ -2658,6 +2768,9 @@ static struct cxl_region *__create_region(struct cxl_= root_decoder *cxlrd, return ERR_PTR(-EBUSY); } =20 + if (pmem_params) + return devm_cxl_pmem_add_region(cxlrd, id, pmem_params, cxld, + CXL_DECODER_HOSTONLYMEM); return devm_cxl_add_region(cxlrd, id, mode, CXL_DECODER_HOSTONLYMEM); } =20 @@ -2672,7 +2785,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 @@ -3641,8 +3754,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 Tue Dec 2 02:32:22 2025 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1001433033C for ; Wed, 19 Nov 2025 07:53:32 +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=1763538815; cv=none; b=b6m8ORfhoI4yueY1NYcluXaXCf5SwXcw/+zpK8fTcoJGc8zwFox6WT2SHQWUpxV3y51d6h0OXwdySAQt3BHXb2f2EsOHR6a5f+MQ+9Tc8P+3hC689mSagfNk8nKbyLNbXfGX/GJti4RART7ujmXzbe71fvJ3UxFzTe1YE8KpN3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538815; c=relaxed/simple; bh=ESls8kczsiy757C1K/kgmyz7R8++FryTKTQjvShztDk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=WyifJXzSNu6XUOFQXi4rTIb1IXKfhyiCE9zDbbM2ovbszeB1Kb83dNG35nv4UG1pGTaxTNzorLS5LRFvVFonE4lwcgJmIUKVtnFl8fp3OptZ6GO3u1qWX5/K/YQKKhvXIbV0Y7m71POp3+5TFBeXyCK9QVp/rKdwPppbogTWvBk= 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=lWNBzxYV; 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="lWNBzxYV" Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20251119075331epoutp0451a24b26bafc95bf7631a0d4145cca81~5WTSTracA1707417074epoutp04E for ; Wed, 19 Nov 2025 07:53:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20251119075331epoutp0451a24b26bafc95bf7631a0d4145cca81~5WTSTracA1707417074epoutp04E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538811; bh=IlJP9oSMjOblSzq1z4N3+ZlVhBcZJv4QELzYajuAbpM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lWNBzxYViYjm+2tIJV/of6TYr00mzciDU5/RBDTvA3HHUOQVjmyUZHYhgsDy/8Dls F5ZhlfJt1jw51Q5g9uJIv7g/N/jGOJhvdeV/G6CAe7324KHEG/7Mi/1ooEwH7p+Vqg kczGtye1Z/1p2outH5KBgo4vN19+FnCH9NMcDQNo= Received: from epsnrtp04.localdomain (unknown [182.195.42.156]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20251119075331epcas5p2818ec9fdfbf39c78bea13810170fc9b9~5WTSDr0Fj0870708707epcas5p2c; Wed, 19 Nov 2025 07:53:31 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.92]) by epsnrtp04.localdomain (Postfix) with ESMTP id 4dBDHt0XSqz6B9mR; Wed, 19 Nov 2025 07:53:30 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20251119075329epcas5p2e59df029313007c9adcf3a09ef0185cf~5WTQppWtC1868418684epcas5p2t; Wed, 19 Nov 2025 07:53:29 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075328epsmtip15b78488122daa96e7f27f1dd016a83c1~5WTPG3_V_2566025660epsmtip1R; Wed, 19 Nov 2025 07:53: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 V4 12/17] cxl/pmem: Preserve region information into nd_set Date: Wed, 19 Nov 2025 13:22:50 +0530 Message-Id: <20251119075255.2637388-13-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075329epcas5p2e59df029313007c9adcf3a09ef0185cf 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: 20251119075329epcas5p2e59df029313007c9adcf3a09ef0185cf References: <20251119075255.2637388-1-s.neeraj@samsung.com> Save region information stored in cxlr to nd_set during cxl_pmem_region_probe in nd_set. This saved region information is being stored into LSA, which will be used for cxl region persistence Signed-off-by: Neeraj Kumar Reviewed-by: Dave Jiang --- 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 Tue Dec 2 02:32:22 2025 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 831D03314B7 for ; Wed, 19 Nov 2025 07:53:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=203.254.224.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538820; cv=none; b=eBCLW3dnvWvvN8O6ODh9lpf+FX0JFaayV95JGRd0n9JSIH14LQ+qUedHs15mBthP9/C+sPyzYOoJSOLHffdtAnoQ1IFVzX9YrqdIQo7GFanfor8/HyeZrJp40Z5des87yutrEKP5AOsTnYXidCgw3puR6S1MJjPT754wK5xWTOc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538820; c=relaxed/simple; bh=03LKIcGIu8CM0DSnpRjzTNy6kSJYDGaqbmVHCFtXeKY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=JMXcOrAqJ5YN37AJfY0k5tPsTuf96OmhDCoZZD9o/eoq0Kn0AXzKNbGXZcCQzNFxLNRO46fGuwggk8Ee4n+yNcaCkkeZkA9Lh6SRsze2N3mpFZPvlXovfIoWstlwMxKu22YYwrtfTCfbRmL/AtrH6DzhWjre401zde34993kWec= 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=kbRyYb5J; 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="kbRyYb5J" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20251119075334epoutp047d82e8f5046a32ac9e50c290805dea24~5WTVUx9yH1680216802epoutp04S for ; Wed, 19 Nov 2025 07:53:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20251119075334epoutp047d82e8f5046a32ac9e50c290805dea24~5WTVUx9yH1680216802epoutp04S DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538814; bh=6KgMWgkzu+WSU0RDSWslHu9/l6dti3z+68L3NRhyXB0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kbRyYb5J7iFdAdBGPuY/unUHUKNCEO30n4aL5ClQqsrJX6j0nqeODIW4JH988hlRy vOt0wuZ5YwDPN77dO9jmeujLRK7uZzo6sLohnjgFF6Rin/vIGUkLhPUqgoYmYl/Etn lR6yS10JsG0HD1zUFYKmldcrS7C3TQyDhO1dvkt0= Received: from epsnrtp03.localdomain (unknown [182.195.42.155]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPS id 20251119075333epcas5p2a6b32faca8bc83beccf8b915e915e2bf~5WTUkcsSl1867518675epcas5p2m; Wed, 19 Nov 2025 07:53:33 +0000 (GMT) Received: from epcas5p1.samsung.com (unknown [182.195.38.87]) by epsnrtp03.localdomain (Postfix) with ESMTP id 4dBDHw5xfPz3hhTD; Wed, 19 Nov 2025 07:53:32 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20251119075332epcas5p2d173f0373aa1ccdfcd4d75c68d5d09fd~5WTTMwhAA0870808708epcas5p2l; Wed, 19 Nov 2025 07:53:32 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075329epsmtip1dd86747585cf71447c60af820eb1a076~5WTQ6DeW72573225732epsmtip18; Wed, 19 Nov 2025 07:53: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 V4 13/17] cxl/pmem_region: Prep patch to accommodate pmem_region attributes Date: Wed, 19 Nov 2025 13:22:51 +0530 Message-Id: <20251119075255.2637388-14-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075332epcas5p2d173f0373aa1ccdfcd4d75c68d5d09fd 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: 20251119075332epcas5p2d173f0373aa1ccdfcd4d75c68d5d09fd References: <20251119075255.2637388-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 Signed-off-by: Neeraj Kumar Reviewed-by: Dave Jiang --- drivers/cxl/core/Makefile | 2 +- drivers/cxl/core/core.h | 10 ++ drivers/cxl/core/pmem_region.c | 202 +++++++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 188 +----------------------------- tools/testing/cxl/Kbuild | 2 +- 5 files changed, 215 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 fde96507cb75..5ebbc3d3dde5 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 *params, struct cxl_decoder *cxld); +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..b45e60f04ff4 --- /dev/null +++ b/drivers/cxl/core/pmem_region.c @@ -0,0 +1,202 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* Copyright(c) 2020 Intel Corporation. */ +#include +#include +#include +#include +#include "core.h" + +/** + * DOC: cxl pmem region + * + * The core CXL PMEM region infrastructure supports persistent memory + * region creation using LIBNVDIMM subsystem. It has dependency on + * LIBNVDIMM, pmem region need updation of cxl region information into + * LSA. LIBNVDIMM dependency is only for pmem region, it is therefore + * need this separate file. + */ + +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 06a75f0a8e9b..9798120b208e 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, \ @@ -2426,7 +2424,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")) @@ -2856,46 +2854,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; @@ -3327,64 +3285,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); @@ -3448,92 +3348,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 Tue Dec 2 02:32:22 2025 Received: from mailout1.samsung.com (mailout1.samsung.com [203.254.224.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C2BBC33123E for ; Wed, 19 Nov 2025 07:53:38 +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=1763538820; cv=none; b=onblX6g7V3yjJKJk7KMRD4uFN3leCdlqpyAKPOCZpSEiCom3uXymXt6jg6hM1rEhhARo15cBBNkFD8aAj3S9aZsMJZuc+fw7YP9p1iJZ9MBoBzZ6BFdQQH1h9cddXWOOhvq1QQaUtSQVq3UbFUuG5NIs9ytHZFStHdHjU2GOAWw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538820; c=relaxed/simple; bh=VQWxKAopaeO60DUBcEMSdVQoa1prMpXpDOwUpLcLDLQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=uL1M+sB+flhTTdeHGXz9jxmrzoNpQwgzTr3Gn1n2eIce+MJd+VkV6+u94M6AlQnOAu7MSOnSmmpW64AJsWZOx2dqugnj1rMnRDBCj5R5C6F5oPeNrOdRfekMiVJNXX8Jx3cZHxur20BjnZRCo8695SMO3l3TfUy3uCF8r10zYK0= 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=VCE+29Yf; 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="VCE+29Yf" Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout1.samsung.com (KnoxPortal) with ESMTP id 20251119075336epoutp01d069f5d78273e4628388dd85c8803d98~5WTXbIuJJ0084400844epoutp01Y for ; Wed, 19 Nov 2025 07:53:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout1.samsung.com 20251119075336epoutp01d069f5d78273e4628388dd85c8803d98~5WTXbIuJJ0084400844epoutp01Y DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538816; bh=nRmk4CyFkpvjGxbn2pi4XQTyhVHs86/ZbxOiVLXLGKU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VCE+29YfJVrqKI6OAO4HBla3faffmq3PbNf7m37Uaz2RcJbx06KKtWd2C2FEEJsbC 2EQpRp1zLNZSph/w5xAWyI/tDIx52m0e8Rx3pbcRx4Qz5Phq8U10QxrKM9zOowF+CD A+p86b4Jsgn+9sHt6AuJKVhIuBSJWX9+pSDqKrbw= Received: from epsnrtp02.localdomain (unknown [182.195.42.154]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPS id 20251119075336epcas5p3bfd918b9cb28d764dd04aacef9f3554f~5WTXGnxia0829208292epcas5p3X; Wed, 19 Nov 2025 07:53:36 +0000 (GMT) Received: from epcas5p2.samsung.com (unknown [182.195.38.90]) by epsnrtp02.localdomain (Postfix) with ESMTP id 4dBDHz33G9z2SSKd; Wed, 19 Nov 2025 07:53:35 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20251119075335epcas5p3a8fdc68301233f899d9041a300309fa2~5WTVpryIm0406004060epcas5p3k; Wed, 19 Nov 2025 07:53:35 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075333epsmtip1ad0c9c9bc13dc254306e6c791530c2f3~5WTTzWIX92573225732epsmtip1-; Wed, 19 Nov 2025 07:53: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 V4 14/17] cxl/pmem_region: Introduce CONFIG_CXL_PMEM_REGION for core/pmem_region.c Date: Wed, 19 Nov 2025 13:22:52 +0530 Message-Id: <20251119075255.2637388-15-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075335epcas5p3a8fdc68301233f899d9041a300309fa2 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: 20251119075335epcas5p3a8fdc68301233f899d9041a300309fa2 References: <20251119075255.2637388-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. Signed-off-by: Neeraj Kumar Reviewed-by: Dave Jiang --- drivers/cxl/Kconfig | 15 +++++++++++++++ drivers/cxl/core/Makefile | 3 ++- drivers/cxl/core/core.h | 17 +++++++++++------ drivers/cxl/core/region.c | 2 ++ drivers/cxl/cxl.h | 24 ++++++++++++++---------- tools/testing/cxl/Kbuild | 3 ++- 6 files changed, 46 insertions(+), 18 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 5ebbc3d3dde5..beeb9b7527b8 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); @@ -89,17 +88,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 0; +} +#endif + struct cxl_send_command; struct cxl_mem_query_commands; int cxl_query_cmd(struct cxl_mailbox *cxl_mbox, diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c index 9798120b208e..408e139718f1 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -3918,6 +3918,8 @@ static int cxl_region_probe(struct device *dev) dev_dbg(&cxlr->dev, "CXL EDAC registration for region_id=3D%d failed\n", cxlr->id); =20 + if (!IS_ENABLED(CONFIG_CXL_PMEM_REGION)) + return -EINVAL; return devm_cxl_add_pmem_region(cxlr); case CXL_PARTMODE_RAM: rc =3D devm_cxl_region_edac_register(cxlr); diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 684a0d1b441a..6ac3b40cb5ff 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -899,21 +899,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; @@ -933,6 +923,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 Tue Dec 2 02:32:22 2025 Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2F534331A44 for ; Wed, 19 Nov 2025 07:53:41 +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=1763538823; cv=none; b=eFxZP2XeI4gDeQ4jx+PghKoZT+MqZaQQ/vwVrlB/YLr7OTo5uIdFtEeGsG1S93Ig90HGWydxa+QbhKlsKZ2D9nrz3nVez6ooPqd8CnSg42z/n8uWlpPJ5wlGv7AloQSy5whewNvQMDgEXQoXvQc1W3s3qdAHh4frTIM3jTiXPgk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538823; c=relaxed/simple; bh=jTMYQUiv8Am1QQGYwohPmbAwti7mjegWK51W92U8wCg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=K8DQhFnnE+9l18X5aFbM4vbBZ4yupv3B3ypsxB5khY5fDLQO3tC0C0RLWu5fbv240+HEb1sdBXJvVo2ciHs0j7WW1pzuIItjUvrfekhURrDGsn9v9ku1Z6pLYg9RhjCImM04jnb1hKZPh918jDc2wqxKCAPC+wp6oQK2y9kOAp0= 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=HiH0zYwT; 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="HiH0zYwT" Received: from epcas5p3.samsung.com (unknown [182.195.41.41]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20251119075339epoutp036f5d733fe1a0a67d167b1352c4c409f9~5WTZ6POOp3072130721epoutp03S for ; Wed, 19 Nov 2025 07:53:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20251119075339epoutp036f5d733fe1a0a67d167b1352c4c409f9~5WTZ6POOp3072130721epoutp03S DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538819; bh=TzalgRoEh+zoqHT1Bybxnd725dsC8LlneSqErpOEjAs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HiH0zYwTmEfp5EJXIxzjUiSBjTMxNRQAhgF7HActWLbY3ghkwGrtkxd70DsTimLNR t8glRd/m0flm9KEpRX25uVE2qaMSr9LkqlbhhtZZEwJ8KgO5OWRDPOrbnuAXuaEPXa lNqQ1uzI/ANKH5rOREBtHX8sLDOhEhtfeV4LWZb8= Received: from epsnrtp03.localdomain (unknown [182.195.42.155]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPS id 20251119075339epcas5p4cadadafe28c6e26a365f912052efe7de~5WTZqV2Lq3148931489epcas5p4h; Wed, 19 Nov 2025 07:53:39 +0000 (GMT) Received: from epcas5p4.samsung.com (unknown [182.195.38.89]) by epsnrtp03.localdomain (Postfix) with ESMTP id 4dBDJ224zFz3hhT7; Wed, 19 Nov 2025 07:53:38 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p2.samsung.com (KnoxPortal) with ESMTPA id 20251119075337epcas5p2cb576137ca33d6304add4e1ba0b2bdc1~5WTYSKkoB1868418684epcas5p2B; Wed, 19 Nov 2025 07:53:37 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075335epsmtip18fb5b180f316c3e498067ad94ae78a22~5WTV48C1j2566025660epsmtip1h; Wed, 19 Nov 2025 07:53: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 V4 15/17] cxl/pmem_region: Add sysfs attribute cxl region label updation/deletion Date: Wed, 19 Nov 2025 13:22:53 +0530 Message-Id: <20251119075255.2637388-16-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075337epcas5p2cb576137ca33d6304add4e1ba0b2bdc1 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: 20251119075337epcas5p2cb576137ca33d6304add4e1ba0b2bdc1 References: <20251119075255.2637388-1-s.neeraj@samsung.com> Using these attributes region label is added/deleted into LSA. These attributes are called from userspace (ndctl) after region creation. Signed-off-by: Neeraj Kumar --- Documentation/ABI/testing/sysfs-bus-cxl | 22 ++++++ drivers/cxl/core/pmem_region.c | 93 ++++++++++++++++++++++++- drivers/cxl/cxl.h | 7 ++ 3 files changed, 121 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-bus-cxl b/Documentation/ABI/te= sting/sysfs-bus-cxl index c80a1b5a03db..76d79c03dde4 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: Nov, 2025 +KernelVersion: v6.19 +Contact: linux-cxl@vger.kernel.org +Description: + (RW) Write a boolean 'true' string value to this attribute to + update cxl region information into LSA as region label. It + uses nvdimm nd_region_label_update() to update cxl region + information saved during cxl region creation into LSA. This + attribute must be called at last during cxl region creation. + + +What: /sys/bus/cxl/devices/regionZ/pmem_regionZ/region_label_delete +Date: Nov, 2025 +KernelVersion: v6.19 +Contact: linux-cxl@vger.kernel.org +Description: + (WO) When a boolean 'true' is written to this attribute then + pmem_region driver deletes cxl region label from LSA using + nvdimm nd_region_label_delete() diff --git a/drivers/cxl/core/pmem_region.c b/drivers/cxl/core/pmem_region.c index b45e60f04ff4..be4feb73aafc 100644 --- a/drivers/cxl/core/pmem_region.c +++ b/drivers/cxl/core/pmem_region.c @@ -30,9 +30,100 @@ static void cxl_pmem_region_release(struct device *dev) kfree(cxlr_pmem); } =20 +static ssize_t region_label_update_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct cxl_pmem_region *cxlr_pmem =3D to_cxl_pmem_region(dev); + struct cxl_region *cxlr =3D cxlr_pmem->cxlr; + ssize_t rc; + bool update; + + rc =3D kstrtobool(buf, &update); + if (rc) + return rc; + + ACQUIRE(rwsem_write_kill, rwsem)(&cxl_rwsem.region); + rc =3D ACQUIRE_ERR(rwsem_write_kill, &rwsem); + if (rc) + return rc; + + /* Region not yet committed */ + if (update && cxlr && cxlr->params.state !=3D CXL_CONFIG_COMMIT) { + dev_dbg(dev, "region not committed, can't update into LSA\n"); + return -ENXIO; + } + + if (!cxlr || !cxlr->cxlr_pmem || !cxlr->cxlr_pmem->nd_region) + 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); + rc =3D ACQUIRE_ERR(rwsem_read_intr, &rwsem); + if (rc) + 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); + rc =3D ACQUIRE_ERR(rwsem_write_kill, &rwsem); + if (rc) + 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, - NULL, + &cxl_pmem_region_group, + NULL }; =20 const struct device_type cxl_pmem_region_type =3D { diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 6ac3b40cb5ff..8c76c4a981bf 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 state * @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 Tue Dec 2 02:32:22 2025 Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CB5463321C0 for ; Wed, 19 Nov 2025 07:53:43 +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=1763538826; cv=none; b=fK00JxfQq1N3wncaK9GODdV631Ndk+8ZrQF7fhCdps7253xtTjZddfqTUHOCz8Tv0/9nZbnv5V3apv6xxMdZDj3lLYKVA94HlYMk5M3jg3iKitDHGKZeIivH0hHmaHhqKnLl3jjIKUMSgCxXUpZCUmVJE/WWm4rYwo9qouWc6W0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538826; c=relaxed/simple; bh=36BUp7N3TJ5x9YM//xTIELhreovBXHMMAZwu22ohaJk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=XFD4m345n2rZuYu0UNWpv1+NnK8et11SaT86rHbpVi65Dgwe4DNG99Ahkg6sf1oOXSosIsP+VZhMpn1GXjhvUX9d3jRVaM6qZQn1kF3NQQT4qK2G/ZCdfh2FJOikx/S4KRyQz9HpYplBG41lrVRd6z009FlIUXJ9RFH7k8OP65k= 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=W7liOqfM; 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="W7liOqfM" Received: from epcas5p4.samsung.com (unknown [182.195.41.42]) by mailout4.samsung.com (KnoxPortal) with ESMTP id 20251119075341epoutp046057f7a42b538824f1871beb4e76cf71~5WTcFFE7R1706817068epoutp04L for ; Wed, 19 Nov 2025 07:53:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout4.samsung.com 20251119075341epoutp046057f7a42b538824f1871beb4e76cf71~5WTcFFE7R1706817068epoutp04L DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538821; bh=QtgKPtRaF+g9hj163fkaFzL+e2IHQeT6w33mvY5sDrc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W7liOqfMrYIYC3zWROdyDhaT59r3hybN3Bm/EdPh2v7WmyXRNzZJ2lgfZrkq0fPGj yjTZe88i2fX/SM3UeqdtdUwX4KkIJnXXEKj7BbcC1tNDsa/Czc7z/MvL98R/LbRG3p 37vgGwy8jTJLbX93FaHxDOKxjfKyNCGmgi0kkZNo= Received: from epsnrtp03.localdomain (unknown [182.195.42.155]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPS id 20251119075340epcas5p393a0ff565080928e3b548b5457b4a8d9~5WTbLE_Nh0354303543epcas5p3J; Wed, 19 Nov 2025 07:53:40 +0000 (GMT) Received: from epcas5p3.samsung.com (unknown [182.195.38.89]) by epsnrtp03.localdomain (Postfix) with ESMTP id 4dBDJ35f3sz3hhTC; Wed, 19 Nov 2025 07:53:39 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p3.samsung.com (KnoxPortal) with ESMTPA id 20251119075339epcas5p3160bfa74362cc974e917fcc9b83ee112~5WTZsFM1m0829308293epcas5p3c; Wed, 19 Nov 2025 07:53:39 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075338epsmtip1f9aadad485c7447031067e3ea16ee03a~5WTYiLO2K2605226052epsmtip1a; Wed, 19 Nov 2025 07:53: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 V4 16/17] cxl/pmem_region: Create pmem region using information parsed from LSA Date: Wed, 19 Nov 2025 13:22:54 +0530 Message-Id: <20251119075255.2637388-17-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075339epcas5p3160bfa74362cc974e917fcc9b83ee112 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: 20251119075339epcas5p3160bfa74362cc974e917fcc9b83ee112 References: <20251119075255.2637388-1-s.neeraj@samsung.com> create_pmem_region() creates cxl region based on region information parsed from LSA. This routine required cxl root decoder and endpoint decoder. Therefore added cxl_find_root_decoder_by_port() and cxl_find_free_ep_decoder(). These routines find cxl root decoder and free endpoint decoder on cxl bus using cxl port Signed-off-by: Neeraj Kumar --- drivers/cxl/core/core.h | 4 ++ drivers/cxl/core/pmem_region.c | 97 ++++++++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 13 +++-- drivers/cxl/cxl.h | 5 ++ 4 files changed, 115 insertions(+), 4 deletions(-) diff --git a/drivers/cxl/core/core.h b/drivers/cxl/core/core.h index beeb9b7527b8..dd2efd3deb5e 100644 --- a/drivers/cxl/core/core.h +++ b/drivers/cxl/core/core.h @@ -35,6 +35,7 @@ int cxl_decoder_detach(struct cxl_region *cxlr, #define CXL_REGION_TYPE(x) (&cxl_region_type) #define SET_CXL_REGION_ATTR(x) (&dev_attr_##x.attr), #define CXL_DAX_REGION_TYPE(x) (&cxl_dax_region_type) +int verify_free_decoder(struct device *dev); int cxl_region_init(void); void cxl_region_exit(void); int cxl_get_poison_by_endpoint(struct cxl_port *port); @@ -88,6 +89,9 @@ static inline struct cxl_region *to_cxl_region(struct dev= ice *dev) { return NULL; } +static inline int verify_free_decoder(struct device *dev) +{ +} #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 be4feb73aafc..06665937c180 100644 --- a/drivers/cxl/core/pmem_region.c +++ b/drivers/cxl/core/pmem_region.c @@ -291,3 +291,100 @@ int devm_cxl_add_pmem_region(struct cxl_region *cxlr) cxlr->cxl_nvb =3D NULL; return rc; } + +static int match_root_decoder(struct device *dev, const void *data) +{ + return is_root_decoder(dev); +} + +/** + * cxl_find_root_decoder_by_port() - find a cxl root decoder on cxl bus + * @port: any descendant port in CXL port topology + * + * 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_p= ort *port) +{ + struct cxl_root *cxl_root __free(put_cxl_root) =3D find_cxl_root(port); + struct device *dev; + + if (!cxl_root) + return NULL; + + dev =3D device_find_child(&cxl_root->port.dev, NULL, match_root_decoder); + if (!dev) + return NULL; + + 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 verify_free_decoder(dev); +} + +/** + * cxl_find_endpoint_decoder_by_port() - find a cxl root decoder on cxl bus + * @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_nvdimm *cxl_nvd; + struct cxl_memdev *cxlmd; + struct cxl_pmem_region_params *params; + 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_root_decoder *cxlrd __free(put_cxl_root_decoder) =3D + cxl_find_root_decoder_by_port(cxlmd->endpoint); + if (!cxlrd) { + dev_err(&cxlmd->dev, "CXL root decoder not found\n"); + return; + } + + struct cxl_decoder *cxld __free(put_cxl_decoder) =3D + cxl_find_free_ep_decoder(cxlmd->endpoint); + if (!cxlrd) { + dev_err(&cxlmd->dev, "CXL endpoint decoder not found\n"); + return; + } + + cxlr =3D cxl_create_region(cxlrd, CXL_PARTMODE_PMEM, + atomic_read(&cxlrd->region_id), + params, cxld); + 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 408e139718f1..96f3cf4143b8 100644 --- a/drivers/cxl/core/region.c +++ b/drivers/cxl/core/region.c @@ -835,15 +835,12 @@ 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) +int verify_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) @@ -867,6 +864,14 @@ static int match_free_decoder(struct device *dev, cons= t void *data) return 1; } =20 +static int match_free_decoder(struct device *dev, const void *data) +{ + if (!is_switch_decoder(dev)) + return 0; + + return verify_free_decoder(dev); +} + static bool spa_maps_hpa(const struct cxl_region_params *p, const struct range *range) { diff --git a/drivers/cxl/cxl.h b/drivers/cxl/cxl.h index 8c76c4a981bf..088841a3e238 100644 --- a/drivers/cxl/cxl.h +++ b/drivers/cxl/cxl.h @@ -792,6 +792,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); @@ -933,6 +934,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) { @@ -942,6 +944,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 Tue Dec 2 02:32:22 2025 Received: from mailout2.samsung.com (mailout2.samsung.com [203.254.224.25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1CA53321D9 for ; Wed, 19 Nov 2025 07:53:44 +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=1763538826; cv=none; b=imR9zJ7VdTvnmYx42WZ4ixteJMsv3mXzYp8aPS1k1IynHq57ob9d/g1W0e/SKfvjHK8Vyo+pKcvWehyYlQOC2qlh0azkve9YbOnpF66BEGuIEapzGkik8z7GBoVt4iQALfJoY4G+xObvzcqeTLhRbjnP7Ue9YgzZzDG3CtbP8Dc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763538826; c=relaxed/simple; bh=AfBioUf1IVGmsSD9OMFKz6qxSlMnB+8ca3YxyO/ofIg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:MIME-Version: Content-Type:References; b=lSyzwI9Vm5TOI7T1iT9pa5Wi8c93LsmplacTvsEnmESAFNoXQR1WpjNY/VHEI+La+c4snydyLEETnJM4SDMhObqBX0zSBDoW8hBt6FlbZDYQj7bDAei6D4SnH+TbaLZ7EIWrj23jwBjBbt3K1qZYyv8zYmlYqs7O7XNZ6UL70Ro= 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=hY77iF0e; 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="hY77iF0e" Received: from epcas5p1.samsung.com (unknown [182.195.41.39]) by mailout2.samsung.com (KnoxPortal) with ESMTP id 20251119075342epoutp02708282835385d38a4c2a8714ae089642~5WTc6oLVi2685926859epoutp02T for ; Wed, 19 Nov 2025 07:53:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.samsung.com 20251119075342epoutp02708282835385d38a4c2a8714ae089642~5WTc6oLVi2685926859epoutp02T DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1763538822; bh=r0m+fwZmxBJRaLlXaZy9HJnLDXtt5ZcCqrXivVZfU+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hY77iF0erohl6xADWuqvn/YGgcnhyaFJrGvaCQM+qqZN7UtJ8bLSPPEw+p4lt1cxX Jo387QyIlHJlt+mMaYKN0zzfsdkgO5HzHID50Vntv9QgGZZuSRQOZEKYFuGrcHdZ6W G7NE7e3Z/Altz1oCp3whEqiIyChJwDaz0DicKjpQ= Received: from epsnrtp03.localdomain (unknown [182.195.42.155]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPS id 20251119075342epcas5p4dd7beb63b638e948d29f40cdf11d0b33~5WTcTUDLS0326403264epcas5p42; Wed, 19 Nov 2025 07:53:42 +0000 (GMT) Received: from epcas5p2.samsung.com (unknown [182.195.38.89]) by epsnrtp03.localdomain (Postfix) with ESMTP id 4dBDJ50yVKz3hhTH; Wed, 19 Nov 2025 07:53:41 +0000 (GMT) Received: from epsmtip1.samsung.com (unknown [182.195.34.30]) by epcas5p4.samsung.com (KnoxPortal) with ESMTPA id 20251119075340epcas5p42d0fa80388af654dff0da088fb3e978c~5WTa9Nc1d1043810438epcas5p4K; Wed, 19 Nov 2025 07:53:40 +0000 (GMT) Received: from test-PowerEdge-R740xd.samsungds.net (unknown [107.99.41.79]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20251119075339epsmtip142b837a41fae8a18ee46218eb6f63495~5WTZ33uH82573225732epsmtip1I; Wed, 19 Nov 2025 07:53: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 V4 17/17] cxl/pmem: Add CXL LSA 2.1 support in cxl pmem Date: Wed, 19 Nov 2025 13:22:55 +0530 Message-Id: <20251119075255.2637388-18-s.neeraj@samsung.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20251119075255.2637388-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: 20251119075340epcas5p42d0fa80388af654dff0da088fb3e978c 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: 20251119075340epcas5p42d0fa80388af654dff0da088fb3e978c References: <20251119075255.2637388-1-s.neeraj@samsung.com> Add support of CXL LSA 2.1 using NDD_REGION_LABELING flag. It creates cxl region based on region information parsed from LSA Signed-off-by: Neeraj Kumar Reviewed-by: Dave Jiang --- 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