[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251209165019.2643142-9-mhonap@nvidia.com>
Date: Tue, 9 Dec 2025 22:20:12 +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 08/15] vfio/cxl: discover precommitted CXL region
From: Zhi Wang <zhiw@...dia.com>
A type-2 device can have precommitted CXL region that is configured by
BIOS. Before letting a VFIO CXL variant driver create a new CXL region,
the VFIO CXL core first needs to discover the precommited CXL region.
Discover the precommited CXL region when enabling CXL devices.
Signed-off-by: Zhi Wang <zhiw@...dia.com>
Signed-off-by: Manish Honap <mhonap@...dia.com>
---
drivers/vfio/pci/vfio_cxl_core.c | 29 +++++++++++++++++++++++++++--
include/linux/vfio_pci_core.h | 1 +
2 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/drivers/vfio/pci/vfio_cxl_core.c b/drivers/vfio/pci/vfio_cxl_core.c
index 35d95de47fa8..099d35866a39 100644
--- a/drivers/vfio/pci/vfio_cxl_core.c
+++ b/drivers/vfio/pci/vfio_cxl_core.c
@@ -82,11 +82,16 @@ static void disable_cxl(struct vfio_cxl_core_device *cxl)
{
struct vfio_cxl *cxl_core = cxl->cxl_core;
- WARN_ON(cxl_core->region.region);
-
if (!cxl->hdm_count)
return;
+ if (cxl_core->region.precommitted) {
+ kfree(cxl_core->region.region);
+ cxl_core->region.region = NULL;
+ }
+
+ WARN_ON(cxl_core->region.region);
+
if (cxl_core->cxled) {
cxl_decoder_detach(NULL, cxl_core->cxled, 0, DETACH_INVALIDATE);
cxl_dpa_free(cxl_core->cxled);
@@ -96,6 +101,24 @@ static void disable_cxl(struct vfio_cxl_core_device *cxl)
cxl_put_root_decoder(cxl_core->cxlrd);
}
+static void discover_precommitted_region(struct vfio_cxl_core_device *cxl)
+{
+ struct cxl_region **cxlrs = NULL;
+ struct vfio_cxl *cxl_core = cxl->cxl_core;
+ int num, ret;
+
+ ret = cxl_get_committed_regions(cxl_core->cxlmd, &cxlrs, &num);
+ if (ret || !cxlrs) {
+ kfree(cxlrs);
+ return;
+ }
+
+ WARN_ON(num > 1);
+
+ cxl_core->region.region = cxlrs[0];
+ cxl_core->region.precommitted = true;
+}
+
int vfio_cxl_core_enable(struct vfio_cxl_core_device *cxl,
struct vfio_cxl_dev_info *info)
{
@@ -126,6 +149,8 @@ int vfio_cxl_core_enable(struct vfio_cxl_core_device *cxl,
if (ret)
goto err;
+ discover_precommitted_region(cxl);
+
return 0;
err:
diff --git a/include/linux/vfio_pci_core.h b/include/linux/vfio_pci_core.h
index 3474835f5d65..7237fcaecbb6 100644
--- a/include/linux/vfio_pci_core.h
+++ b/include/linux/vfio_pci_core.h
@@ -104,6 +104,7 @@ struct vfio_cxl_region {
u64 addr;
void *vaddr;
bool noncached;
+ bool precommitted;
};
struct vfio_cxl {
--
2.25.1
Powered by blists - more mailing lists