lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251209165019.2643142-6-mhonap@nvidia.com>
Date: Tue, 9 Dec 2025 22:20:09 +0530
From: <mhonap@...dia.com>
To: <aniketa@...dia.com>, <ankita@...dia.com>, <alwilliamson@...dia.com>,
	<vsethi@...dia.com>, <jgg@...dia.com>, <mochs@...dia.com>,
	<skolothumtho@...dia.com>, <alejandro.lucero-palau@....com>,
	<dave@...olabs.net>, <jonathan.cameron@...wei.com>, <dave.jiang@...el.com>,
	<alison.schofield@...el.com>, <vishal.l.verma@...el.com>,
	<ira.weiny@...el.com>, <dan.j.williams@...el.com>, <jgg@...pe.ca>,
	<yishaih@...dia.com>, <kevin.tian@...el.com>
CC: <cjia@...dia.com>, <kwankhede@...dia.com>, <targupta@...dia.com>,
	<zhiw@...dia.com>, <kjaju@...dia.com>, <linux-kernel@...r.kernel.org>,
	<linux-cxl@...r.kernel.org>, <kvm@...r.kernel.org>, <mhonap@...dia.com>
Subject: [RFC v2 05/15] cxl: introduce cxl_get_committed_regions()

From: Zhi Wang <zhiw@...dia.com>

The kernel CXL core can discover the configured and committed CXL regions
from BIOS or firmware, respect its configuration and create the related
kernel CXL core data structures without configuring and committing the CXL
region.

However, those information are kept within the kernel CXL core. A type-2
device can have the same usage and a type-2 driver would like to know
about it before creating the CXL regions.

Introduce cxl_get_committed_regions() for a type-2 driver to discover the
committed regions.

Signed-off-by: Zhi Wang <zhiw@...dia.com>
Signed-off-by: Manish Honap <mhonap@...dia.com>
---
 drivers/cxl/core/region.c | 73 +++++++++++++++++++++++++++++++++++++++
 include/cxl/cxl.h         |  1 +
 2 files changed, 74 insertions(+)

diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index e89a98780e76..6c368b4641f1 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -2785,6 +2785,79 @@ int cxl_get_region_range(struct cxl_region *region, struct range *range)
 }
 EXPORT_SYMBOL_NS_GPL(cxl_get_region_range, "CXL");
 
+struct match_region_info {
+	struct cxl_memdev *cxlmd;
+	struct cxl_region **cxlrs;
+	int nr_regions;
+};
+
+static int match_region_by_device(struct device *match, void *data)
+{
+	struct match_region_info *info = data;
+	struct cxl_endpoint_decoder *cxled;
+	struct cxl_memdev *cxlmd;
+	struct cxl_region_params *p;
+	struct cxl_region *cxlr;
+	int i;
+
+	if (!is_cxl_region(match))
+		return 0;
+
+	lockdep_assert_held(&cxl_rwsem.region);
+	cxlr = to_cxl_region(match);
+	p = &cxlr->params;
+
+	if (p->state != CXL_CONFIG_COMMIT)
+		return 0;
+
+	for (i = 0; i < p->nr_targets; i++) {
+		void *cxlrs;
+
+		cxled = p->targets[i];
+		cxlmd = cxled_to_memdev(cxled);
+
+		if (info->cxlmd != cxlmd)
+			continue;
+
+		cxlrs = krealloc(info->cxlrs, sizeof(cxlr) * (info->nr_regions + 1),
+				 GFP_KERNEL);
+		if (!cxlrs) {
+			kfree(info->cxlrs);
+			return -ENOMEM;
+		}
+		info->cxlrs = cxlrs;
+
+		info->cxlrs[info->nr_regions++] = cxlr;
+	}
+
+	return 0;
+}
+
+int cxl_get_committed_regions(struct cxl_memdev *cxlmd, struct cxl_region ***cxlrs, int *num)
+{
+	struct match_region_info info = {0};
+	int ret = 0;
+
+	ret = down_write_killable(&cxl_rwsem.region);
+	if (ret)
+		return ret;
+
+	info.cxlmd = cxlmd;
+
+	ret = bus_for_each_dev(&cxl_bus_type, NULL, &info, match_region_by_device);
+	if (ret) {
+		kfree(info.cxlrs);
+	} else {
+		*cxlrs = info.cxlrs;
+		*num = info.nr_regions;
+	}
+
+	up_write(&cxl_rwsem.region);
+
+	return ret;
+}
+EXPORT_SYMBOL_NS_GPL(cxl_get_committed_regions, "CXL");
+
 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));
diff --git a/include/cxl/cxl.h b/include/cxl/cxl.h
index e3bf8cf0b6d6..0a1f245557f4 100644
--- a/include/cxl/cxl.h
+++ b/include/cxl/cxl.h
@@ -295,5 +295,6 @@ int cxl_get_region_range(struct cxl_region *region, struct range *range);
 int cxl_get_hdm_reg_info(struct cxl_dev_state *cxlds, u64 *count, u64 *offset,
 			 u64 *size);
 int cxl_find_comp_regblock_offset(struct pci_dev *pdev, u64 *offset);
+int cxl_get_committed_regions(struct cxl_memdev *cxlmd, struct cxl_region ***cxlrs, int *num);
 
 #endif /* __CXL_CXL_H__ */
-- 
2.25.1


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ