CXL.mem error isolation support
cover CXL.mem error isolation support
Overview
========
This series adds support for the CXL.mem Timeout & Isolation Capability as defined by the CXL 3.2 spec (section 8.2.4.24), with some extras (explained below). This is an optional capability implemented by CXL-capable PCIe Root Ports to prevent the host system from resetting when the CXL.mem link times out or goes down (i.e. CXL memory device is suprise removed or dies). Without this capability, the system is expected to immediately reset or power off when either of these conditions occurs.
When CXL.mem isolation is triggered, the CXL memory below the port is no longer accessible. Writes to the memory from the host are expected to silently drop, while a synchronous response is expected for reads. This response is implemntation specific, but an example response would be poisoned data.
The specific features enabled by this series are:
- Enabling CXL.mem isolation on link down conditions and transaction timeout
- Setting up, enabling, and handling CXL isolation interrupts
- Preventing onlining/enabling of isolated CXL memory
- Sysfs attributes for system administrators to tune isolation capabilities
The Extras
==========
The last 3 commits provide support for an ECN [1] submitted by AMD that allows platform firmware to modify how the OS enables and handles CXL isolation. The ECN contents are expected to land in revision 4 of the CXL spec. The link at [1] is only accessible to CXL SSWG members, but I've done my best to explain the changes in the relevant commits.
The changes in these commits could probably be moved to earlier commits, but I've opted to leave them tacked on the end just in case anyone has a problem with their inclusion.
Intended Behavior
=================
Due to how CXL memory is currently handled by Linux, this feature isn't all that useful for type 3 cards. The intended behavior for type 3 cards is to panic when isolation is triggered, which defeats the purpose of the feature.
The reason I'm sending this out anyway is twofold:
1) I've seen rumblings that CXL memory will be part of it's own opt-in allocator in the future and the memory may be safely removable at that point.
2) CXL memory provided by a Type 2 card may be safely removable, though it's left up to the type 2 endpoint driver to handle isolation recovery.
I've also not included a flow for isolation recovery. This is because I
a) don't have a system that supports it, and b) it's not applicable to the type 3 driver.
Building the Set
================
This series is based on both Terry's port error handling patch set (v10) and Dave's deferred downstream port probe set (v7). Terry's set was needed since it introduces the uncorrectable CXL error = system panic paradigm, as well as the routines for logging the AER info from the CXL subsystem.
I included Dave's set due to a timing issue I saw where the PCIe portdrv code would run after the CXL ports that have the isolation capability were probed. This caused the isolation set up to fail because the PCIe portdrv provides the information to allocate the CXL isolation interrupt. I tried deferring the probe, but the deferral caused the cxl_mem driver to break because the port wasn't probed yet. I could have introduced a scheme to get around this, but it seemed easier to just use Dave's set to fix it.
The isolation support is gated behind the CXL core being built-in because the CXL isolation PCIe service needs the mapping code in cxl/core/regs.c. I realize a rework is planned for the PCIe portdrv to (hopefully) not make this the case, so I've kept the code as minimal as possible.
To build the set I applied Terry's set to the base commit below, Dave's on top of that, then my patches.
Patch Breakdown
===============
Patches 3-5 & 12-13 will need eyes from PCIe folks. Patch 14 needs an ACPI reviewer.
- Patches 1-2: Register mapping updates needed for isolation support
- Patches 3-5: CXL isolation service driver & MSI/-X vector allocation
- Patch 6: Enable CXL.mem isolation
- Patches 7-8: Set up and enable CXL isolation interrupts
- Patch 9: Preventing onlining isolated memory
- Patch 10: Enable CXL.mem transaction timeout
- Patch 11: cxl_pci isolation handler
- Patches 12-13: CXL isolation sysfs attributes
- Patch 14: ECN changes to CXL _OSC method
- Patches 15-16: ECN additions
[1]:
Ben Cheatham (16):
cxl/regs: Add cxl_unmap_component_regs()
cxl/regs: Add CXL Isolation capability mapping
PCI: PCIe portdrv: Add CXL Isolation service driver
PCI: PCIe portdrv: Allocate CXL isolation MSI/-X vector
PCI: PCIe portdrv: Add interface for getting CXL isolation IRQ cxl/core: Enable CXL.mem isolation
cxl/core: Set up isolation interrupts
cxl/core: Enable CXL isolation interrupts
cxl/core: Prevent onlining CXL memory behind isolated ports cxl/core: Enable CXL.mem timeout
cxl/pci: Add isolation handler
PCI: PCIe portdrv: Add cxl_isolation sysfs attributes cxl/core, PCI: PCIe portdrv: Add CXL timeout range programming
ACPI: Add CXL isolation _OSC fields
cxl/core, cxl/acpi: Enable CXL isolation based on _OSC handshake cxl/core, cxl/acpi: Add CXL isolation notify handler
drivers/acpi/pci_root.c | 9 + drivers/cxl/Kconfig | 14 ++ drivers/cxl/acpi.c | 75 +++++++ drivers/cxl/core/core.h | 2 + drivers/cxl/core/pci.c | 138 ++++++++++++ drivers/cxl/core/port.c | 248 +++++++++++++++++++++ drivers/cxl/core/region.c | 3 + drivers/cxl/core/regs.c | 85 +++++-- drivers/cxl/cxl.h | 35 +++ drivers/cxl/cxlmem.h | 4 + drivers/cxl/pci.c | 9 + drivers/pci/pci-sysfs.c | 3 + drivers/pci/pci.h | 4 + drivers/pci/pcie/Makefile | 1 + drivers/pci/pcie/cxl_isolation.c | 371 +++++++++++++++++++++++++++++++ drivers/pci/pcie/portdrv.c | 21 +- drivers/pci/pcie/portdrv.h | 18 +- include/cxl/isolation.h | 66 ++++++ include/linux/acpi.h | 3 + 19 files changed, 1086 insertions(+), 23 deletions(-) create mode 100644 drivers/pci/pcie/cxl_isolation.c create mode 100644 include/cxl/isolation.h
base-commit: a403fe6c0b17f472e01246eb350f5eef105243ac
Signature · 1 line
2.34.1
PATCH 1/16 cxl/regs: Add cxl_unmap_component_regs()
In order to allocate the MSI/-X interrupt for CXL error isolation the PCIe portdrv driver needs to map the MMIO-space isolation capability register that contains the interrupt vector. The CXL core already provides a function to map registers in this space:cxl_map_component_regs(). The mappings given this function are managed by devres. If the isolation registers are left mapped by the PCIe portdrv driver, the CXL driver will run into a devres conflict when it goes to map the same registers during probe.
Add cxl_unmap_component_regs() to be called from the PCIe portdrv driver. This function will unwind the devres allocations done by cxl_map_component_regs(), which will allow the PCIe portdrv driver to map the isolation capability register without conflicts.
Factor out the register mapping retrieval code in cxl_map_component_regs() to be reused by cxl_map/unmap_component_regs().
--- drivers/cxl/core/regs.c | 77 +++++++++++++++++++++++++++++++---------- drivers/cxl/cxl.h | 3 ++ 2 files changed, 62 insertions(+), 18 deletions(-)
drivers/cxl/core/regs.c +59 -18
@@ -201,40 +201,81 @@ void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr, }EXPORT_SYMBOL_NS_GPL (devm_cxl_iomap_block,"CXL" ); -int cxl_map_component_regs (const struct cxl_register_map *map, +struct mapinfo { +const struct cxl_reg_map *rmap; +void __iomem **addr; +}; + +static int cxl_get_mapinfo (const struct cxl_register_map *map,struct cxl_component_regs *regs, -unsigned long map_mask) +unsigned long map_mask,struct mapinfo *info) { -struct device *host = map->host; -struct mapinfo { -const struct cxl_reg_map *rmap; -void __iomem **addr; - } mapinfo[] = { +struct mapinfo mapinfo[] = { { &map->component_map.hdm_decoder, ®s->hdm_decoder }, { &map->component_map.ras, ®s->ras }, };int i;for (i =0 ; i <ARRAY_SIZE (mapinfo); i++) { -struct mapinfo *mi = &mapinfo[i]; -resource_size_t addr; -resource_size_t length; - -if (!mi->rmap->valid) +if (!mapinfo[i].rmap->valid)continue ; -if (!test_bit (mi->rmap->id, &map_mask)) +if (!test_bit (mapinfo[i].rmap->id, &map_mask))continue ; - addr = map->resource + mi->rmap->offset; - length = mi->rmap->size; - *(mi->addr) =devm_cxl_iomap_block (host, addr, length); -if (!*(mi->addr)) -return -ENOMEM ; + + *info = mapinfo[i]; +return 0 ; } +return -ENXIO ; +} + +int cxl_map_component_regs (const struct cxl_register_map *map, +struct cxl_component_regs *regs, +unsigned long map_mask) +{ +struct device *host = map->host; +resource_size_t addr, length; +struct mapinfo mi; +int rc; + + rc =cxl_get_mapinfo (map, regs, map_mask, &mi); +if (rc) +return rc; + + addr = map->resource + mi.rmap->offset; + length = mi.rmap->size; + *mi.addr =devm_cxl_iomap_block (host, addr, length); +if (!(*mi.addr)) +return -ENOMEM ; +return 0 ; }EXPORT_SYMBOL_NS_GPL (cxl_map_component_regs,"CXL" ); +int cxl_unmap_component_regs (const struct cxl_register_map *map, +struct cxl_component_regs *regs, +unsigned long map_mask) +{ +struct device *host = map->host; +resource_size_t addr, length; +struct mapinfo mi; +int rc; + + rc =cxl_get_mapinfo (map, regs, map_mask, &mi); +if (rc) +return rc; + +if (!(*mi.addr)) +return 0 ; + + addr = map->resource + mi.rmap->offset; + length = mi.rmap->size; + +devm_iounmap (host, *mi.addr); +devm_release_mem_region (host, addr, length); +return 0 ; +} +int cxl_map_device_regs (const struct cxl_register_map *map,struct cxl_device_regs *regs) {
drivers/cxl/cxl.h +3 -0
@@ -300,6 +300,9 @@ void cxl_probe_device_regs(struct device *dev, void __iomem *base,int cxl_map_component_regs (const struct cxl_register_map *map,struct cxl_component_regs *regs,unsigned long map_mask); +int cxl_unmap_component_regs (const struct cxl_register_map *map, +struct cxl_component_regs *regs, +unsigned long map_mask);int cxl_map_device_regs (const struct cxl_register_map *map,struct cxl_device_regs *regs);int cxl_map_pmu_regs (struct cxl_register_map *map,struct cxl_pmu_regs *regs);
Signature · 1 line
2.34.1
Re: [PATCH 01/16] cxl/regs: Add cxl_unmap_component_regs()
On Wed, 30 Jul 2025 16:47:03 -0500
Ben Cheatham <[email protected]> wrote:
Hi Ben,
Whilst I know there has been some discussion of whether it is appropriate to enable this functionality without a full use case and definite confirmation someone is going to use it, I'm loath to leave completely unread code on list. (you talk about this in the cover letter).
Quoted 5 lines
In order to allocate the MSI/-X interrupt for CXL error isolation the PCIe portdrv driver needs to map the MMIO-space isolation capability register that contains the interrupt vector. The CXL core already provides a function to map registers in this space:
cxl_map_component_regs(). The mappings given this function are managed
given to, or returned by?
Quoted 40 lines
by devres. If the isolation registers are left mapped by the PCIe portdrv driver, the CXL driver will run into a devres conflict when it goes to map the same registers during probe.
Add
cxl_unmap_component_regs()to be called from the PCIe portdrv driver. This function will unwind the devres allocations done bycxl_map_component_regs(), which will allow the PCIe portdrv driver to map the isolation capability register without conflicts.Factor out the register mapping retrieval code in
cxl_map_component_regs()to be reused by cxl_map/unmap_component_regs().Signed-off-by Ben Cheatham <[email protected]>--- drivers/cxl/core/regs.c | 77 +++++++++++++++++++++++++++++++---------- drivers/cxl/cxl.h | 3 ++ 2 files changed, 62 insertions(+), 18 deletions(-)drivers/cxl/core/regs.c +7
-5@@ -201,40 +201,81 @@ void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr, }EXPORT_SYMBOL_NS_GPL (devm_cxl_iomap_block,"CXL" ); -int cxl_map_component_regs (const struct cxl_register_map *map, +struct mapinfo { +const struct cxl_reg_map *rmap; +void __iomem **addr; +}; + +static int cxl_get_mapinfo (const struct cxl_register_map *map,struct cxl_component_regs *regs, -unsigned long map_mask) +unsigned long map_mask,struct mapinfo *info) { -struct device *host = map->host; -struct mapinfo { -const struct cxl_reg_map *rmap;
drivers/cxl/core/regs.c void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr, · line 219
Quoted 10 lines
drivers/cxl/core/regs.c +1
-3-void __iomem **addr; - } mapinfo[] = { +struct mapinfo mapinfo[] = { { &map->component_map.hdm_decoder, ®s->hdm_decoder }, { &map->component_map.ras, ®s->ras }, };int i;for (i =0 ; i <ARRAY_SIZE (mapinfo); i++) { - struct mapinfo *mi = &mapinfo[i];
Whilst the usefulness of this local variable is reduced I think it is still justified and keeping it will reduce the churn here somewhat.
Quoted 7 lines
drivers/cxl/core/regs.c +1
-5-resource_size_t addr; -resource_size_t length; - -if (!mi->rmap->valid) +if (!mapinfo[i].rmap->valid)continue ; -if (!test_bit (mi->rmap->id, &map_mask))
drivers/cxl/core/regs.c void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr, · line 226
Quoted 10 lines
drivers/cxl/core/regs.c +4
-5+if (!test_bit (mapinfo[i].rmap->id, &map_mask))continue ; - addr = map->resource + mi->rmap->offset; - length = mi->rmap->size; - *(mi->addr) =devm_cxl_iomap_block (host, addr, length); -if (!*(mi->addr)) -return -ENOMEM ; + + *info = mapinfo[i]; +return 0 ;
I'm struggling to see how this logic works. We now only find the first entry in mapinfo that is valid? The new cxl_map_component_regs() doesn't seem to include a loop either so it's not that we enter here multiple times.
I think this only works if only one bit is set in map_mask? It is always called like that, but the function doesn't check it and if we are going to always call it with BIT(X) then pass X in instead that making it inherently only deal with a one hot bitmap.
drivers/cxl/core/regs.c void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr, · line 234
Quoted 8 lines
drivers/cxl/core/regs.c +6
-0} +return -ENXIO ; +} + +int cxl_map_component_regs (const struct cxl_register_map *map, +struct cxl_component_regs *regs, +unsigned long map_mask)
Similarly I'd make this the bit position not the bitmap with 1 bit set.
Quoted 13 lines
drivers/cxl/core/regs.c +13
-0+{ +struct device *host = map->host; +resource_size_t addr, length; +struct mapinfo mi; +int rc; + + rc =cxl_get_mapinfo (map, regs, map_mask, &mi); +if (rc) +return rc; + + addr = map->resource + mi.rmap->offset; + length = mi.rmap->size; + *mi.addr =devm_cxl_iomap_block (host, addr, length);
drivers/cxl/core/regs.c void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr, · line 257
Quoted 10 lines
drivers/cxl/core/regs.c +6
-0+if (!(*mi.addr)) +return -ENOMEM ; +return 0 ; }EXPORT_SYMBOL_NS_GPL (cxl_map_component_regs,"CXL" ); +int cxl_unmap_component_regs (const struct cxl_register_map *map, +struct cxl_component_regs *regs, +unsigned long map_mask)
And this one.
Quoted 8 lines
drivers/cxl/core/regs.c +8
-0+{ +struct device *host = map->host; +resource_size_t addr, length; +struct mapinfo mi; +int rc; + + rc =cxl_get_mapinfo (map, regs, map_mask, &mi); +if (rc)
drivers/cxl/core/regs.c void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr, · line 275
Quoted 10 lines
drivers/cxl/core/regs.c +10
-0+return rc; + +if (!(*mi.addr)) +return 0 ; + + addr = map->resource + mi.rmap->offset; + length = mi.rmap->size; + +devm_iounmap (host, *mi.addr); +devm_release_mem_region (host, addr, length);
Add a little helper for devm_cxl_iounmap_block()
So that it clearly pairs with what happens in devm_cxl_iomap_block()
Quoted 2 lines
drivers/cxl/core/regs.c +2
-0+return 0 ; +}
Re: [PATCH 01/16] cxl/regs: Add cxl_unmap_component_regs()
Quoted 9 lines · Jonathan Cameron
On Wed, 30 Jul 2025 16:47:03 -0500
Ben Cheatham <[email protected]> wrote:Hi Ben,
Whilst I know there has been some discussion of whether it is appropriate to enable this functionality without a full use case and definite confirmation someone is going to use it, I'm loath to leave completely unread code on list. (you talk about this in the cover letter).
Thanks for taking the time to review! I wasn't able to go to the community meeting this month, but I did hear that this was brought up. My plan is to wait on a v2 until I get a customer (if I do at all).
Quoted 9 lines
Quoted 6 lines
In order to allocate the MSI/-X interrupt for CXL error isolation the PCIe portdrv driver needs to map the MMIO-space isolation capability register that contains the interrupt vector. The CXL core already provides a function to map registers in this space:
cxl_map_component_regs(). The mappings given this function are managedgiven to, or returned by?
Probably meant "given by". I'll change it to "returned by" though since I like the specificity.
Quoted 48 lines
Quoted 48 lines
by devres. If the isolation registers are left mapped by the PCIe portdrv driver, the CXL driver will run into a devres conflict when it goes to map the same registers during probe.
Add
cxl_unmap_component_regs()to be called from the PCIe portdrv driver. This function will unwind the devres allocations done bycxl_map_component_regs(), which will allow the PCIe portdrv driver to map the isolation capability register without conflicts.Factor out the register mapping retrieval code in
cxl_map_component_regs()to be reused by cxl_map/unmap_component_regs().Signed-off-by Ben Cheatham <[email protected]>--- drivers/cxl/core/regs.c | 77 +++++++++++++++++++++++++++++++---------- drivers/cxl/cxl.h | 3 ++ 2 files changed, 62 insertions(+), 18 deletions(-)drivers/cxl/core/regs.c +8
-7@@ -201,40 +201,81 @@ void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr, }EXPORT_SYMBOL_NS_GPL (devm_cxl_iomap_block,"CXL" ); -int cxl_map_component_regs (const struct cxl_register_map *map, +struct mapinfo { +const struct cxl_reg_map *rmap; +void __iomem **addr; +}; + +static int cxl_get_mapinfo (const struct cxl_register_map *map,struct cxl_component_regs *regs, -unsigned long map_mask) +unsigned long map_mask,struct mapinfo *info) { -struct device *host = map->host; -struct mapinfo { -const struct cxl_reg_map *rmap; -void __iomem **addr; - } mapinfo[] = { +struct mapinfo mapinfo[] = { { &map->component_map.hdm_decoder, ®s->hdm_decoder }, { &map->component_map.ras, ®s->ras }, };int i;
Quoted 7 lines
drivers/cxl/core/regs.c void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr, · line 219
Quoted 2 lines
drivers/cxl/core/regs.c +0
-1for (i =0 ; i <ARRAY_SIZE (mapinfo); i++) { -struct mapinfo *mi = &mapinfo[i];Whilst the usefulness of this local variable is reduced I think it is still justified and keeping it will reduce the churn here somewhat.
Ok, I'll keep it in.
Quoted 24 lines
Quoted 7 lines
drivers/cxl/core/regs.c +1
-5-resource_size_t addr; -resource_size_t length; - -if (!mi->rmap->valid) +if (!mapinfo[i].rmap->valid)continue ; -if (!test_bit (mi->rmap->id, &map_mask))drivers/cxl/core/regs.c void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr, · line 226
Quoted 10 lines
drivers/cxl/core/regs.c +4
-5+if (!test_bit (mapinfo[i].rmap->id, &map_mask))continue ; - addr = map->resource + mi->rmap->offset; - length = mi->rmap->size; - *(mi->addr) =devm_cxl_iomap_block (host, addr, length); -if (!*(mi->addr)) -return -ENOMEM ; + + *info = mapinfo[i]; +return 0 ;I'm struggling to see how this logic works. We now only find the first entry in mapinfo that is valid? The new
cxl_map_component_regs()doesn't seem to include a loop either so it's not that we enter here multiple times.
Quoted 5 lines
I think this only works if only one bit is set in
map_mask? It is always called like that, but the function doesn't check it and if we are going to always call it with BIT(X) then pass X in instead that making it inherently only deal with a one hot bitmap.
Yeah it looks like this was an oversight on my part and I didn't catch it during testing due to how it's called. I don't have a strong opinion either way, but I would prefer to keep the original behavior since it's more versatile. So, I'll change this function accordingly and keep cxl_map/unmap_component_regs() as-is.
Quoted 51 lines
drivers/cxl/core/regs.c void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr, · line 234
Quoted 9 lines
drivers/cxl/core/regs.c +6
-0} +return -ENXIO ; +} + +int cxl_map_component_regs (const struct cxl_register_map *map, +struct cxl_component_regs *regs, +unsigned long map_mask)Similarly I'd make this the bit position not the bitmap with 1 bit set.
Quoted 13 lines
drivers/cxl/core/regs.c +13
-0+{ +struct device *host = map->host; +resource_size_t addr, length; +struct mapinfo mi; +int rc; + + rc =cxl_get_mapinfo (map, regs, map_mask, &mi); +if (rc) +return rc; + + addr = map->resource + mi.rmap->offset; + length = mi.rmap->size; + *mi.addr =devm_cxl_iomap_block (host, addr, length);drivers/cxl/core/regs.c void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr, · line 257
Quoted 10 lines
drivers/cxl/core/regs.c +6
-0+if (!(*mi.addr)) +return -ENOMEM ; +return 0 ; }EXPORT_SYMBOL_NS_GPL (cxl_map_component_regs,"CXL" ); +int cxl_unmap_component_regs (const struct cxl_register_map *map, +struct cxl_component_regs *regs, +unsigned long map_mask)And this one.
Quoted 13 lines
drivers/cxl/core/regs.c +13
-0+{ +struct device *host = map->host; +resource_size_t addr, length; +struct mapinfo mi; +int rc; + + rc =cxl_get_mapinfo (map, regs, map_mask, &mi); +if (rc) +return rc; + +if (!(*mi.addr)) +return 0 ; +
Quoted 9 lines
drivers/cxl/core/regs.c void __iomem *devm_cxl_iomap_block(struct device *dev, resource_size_t addr, · line 275
Quoted 5 lines
drivers/cxl/core/regs.c +5
-0+ addr = map->resource + mi.rmap->offset; + length = mi.rmap->size; + +devm_iounmap (host, *mi.addr); +devm_release_mem_region (host, addr, length);Add a little helper for
devm_cxl_iounmap_block()
So that it clearly pairs with what happens indevm_cxl_iomap_block()
Sure.
Quoted 4 lines
Quoted 3 lines
drivers/cxl/core/regs.c +2
-0+return 0 ; +}
PATCH 2/16 cxl/regs: Add CXL Isolation capability mapping
In reply to Ben CheathamAdd necessary information to map the CXL Timeout & Isolation Capability (CXL 3.2 8.2.4.24). This will be used in later commits by the CXL core and PCIe portdrv driver to set up and manage the capability.
--- drivers/cxl/core/regs.c | 8 ++++++++ drivers/cxl/cxl.h | 7 +++++++ 2 files changed, 15 insertions(+)
drivers/cxl/core/regs.c +8 -0
@@ -92,6 +92,13 @@ void cxl_probe_component_regs(struct device *dev, void __iomem *base, length =CXL_RAS_CAPABILITY_LENGTH ; rmap = &map->ras;break ; +case CXL_CM_CAP_CAP_ID_ISOLATION : +dev_dbg (dev, +"found Timeout & Isolation capability (0x%x)\n" , + offset); + length =CXL_ISOLATION_CAPABILITY_LENGTH ; + rmap = &map->isolation; +break ;default :dev_dbg (dev,"Unknown CM cap ID: %d (0x%x)\n" , cap_id, offset);
@@ -213,6 +220,7 @@ static int cxl_get_mapinfo(const struct cxl_register_map *map,struct mapinfo mapinfo[] = { { &map->component_map.hdm_decoder, ®s->hdm_decoder }, { &map->component_map.ras, ®s->ras }, + { &map->component_map.isolation, ®s->isolation }, };int i;
drivers/cxl/cxl.h +7 -0
@@ -41,6 +41,7 @@ extern const struct nvdimm_security_ops *cxl_security_ops;#define CXL_CM_CAP_CAP_ID_RAS 0x2#define CXL_CM_CAP_CAP_ID_HDM 0x5 +#define CXL_CM_CAP_CAP_ID_ISOLATION 0x9#define CXL_CM_CAP_CAP_HDM_VERSION 1/* HDM decoders CXL 2.0 8.2.5.12 CXL HDM Decoder Capability Structure */
@@ -133,6 +134,9 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)return 0 ; } +/* CXL 3.2 8.2.4.24 CXL Timeout and Isolation Capability Structure */ +#define CXL_ISOLATION_CAPABILITY_LENGTH 0x10 +/* RAS Registers CXL 2.0 8.2.5.9 CXL RAS Capability Structure */ #define CXL_RAS_UNCORRECTABLE_STATUS_OFFSET 0x0#define CXL_RAS_UNCORRECTABLE_STATUS_MASK (GENMASK(16, 14) | GENMASK(11, 0))
@@ -211,10 +215,12 @@ struct cxl_regs {* Common set of CXL Component register block base pointers * @hdm_decoder: CXL 2.0 8.2.5.12 CXL HDM Decoder Capability Structure * @ras: CXL 2.0 8.2.5.9 CXL RAS Capability Structure +* @isolation: CXL 3.2 8.2.4.24 CXL Timeout & Isolation Capability Structure */ struct_group_tagged (cxl_component_regs, component, void __iomem *hdm_decoder;void __iomem *ras; +void __iomem *isolation; );/* * Common set of CXL Device register block base pointers
@@ -257,6 +263,7 @@ struct cxl_reg_map {struct cxl_component_reg_map {struct cxl_reg_map hdm_decoder;struct cxl_reg_map ras; +struct cxl_reg_map isolation; };struct cxl_device_reg_map {
Signature · 1 line
2.34.1
Re: [PATCH 02/16] cxl/regs: Add CXL Isolation capability mapping
Quoted 5 lines · On Wed, 30 Jul 2025 16:47:04 -0500 Ben Cheatham <[email protected]>…
Add necessary information to map the CXL Timeout & Isolation Capability (CXL 3.2 8.2.4.24). This will be used in later commits by the CXL core and PCIe portdrv driver to set up and manage the capability.
Signed-off-by Ben Cheatham <[email protected]>
PATCH 3/16 PCI: PCIe portdrv: Add CXL Isolation service driver
In reply to Ben CheathamAdd the CXL isolation service, which will provide the necessary information to the PCIe portdrv and CXL drivers to map, setup, and handle CXL isolation interrupts.
Add functions to get the CXL isolation MSI/-X interrupt vector from the PCIe portdrv.
--- drivers/cxl/Kconfig | 14 +++++ drivers/cxl/cxl.h | 4 ++ drivers/pci/pcie/Makefile | 1 + drivers/pci/pcie/cxl_isolation.c | 87 ++++++++++++++++++++++++++++++++ drivers/pci/pcie/portdrv.c | 1 + drivers/pci/pcie/portdrv.h | 18 ++++++- 6 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 drivers/pci/pcie/cxl_isolation.c
drivers/cxl/Kconfig +14 -0
@@ -247,4 +247,18 @@ config CXL_NATIVE_RAS If unsure, or if this kernel is meant for production environments, say Y. +config CXL_ISOLATION + bool "CXL.mem Isolation Support" + depends on PCIEPORTBUS + depends on CXL_BUS=PCIEPORTBUS + help + Enables the CXL.mem isolation PCIe port bus service driver. This + driver, in combination with the CXL driver core, is responsible + for managing CXL-capable PCIe root ports that undergo CXL.mem + error isolation due to either a CXL.mem transaction timeout or + link down condition. Without error isolation, either of these + conditions will trigger a system reset. + + If unsure say 'y' + endif
drivers/cxl/cxl.h +4 -0
@@ -135,6 +135,10 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw) }/* CXL 3.2 8.2.4.24 CXL Timeout and Isolation Capability Structure */ +#define CXL_ISOLATION_CAPABILITY_OFFSET 0x0 +#define CXL_ISOLATION_CAP_MEM_ISO_SUPP BIT(16) +#define CXL_ISOLATION_CAP_INTR_SUPP BIT(26) +#define CXL_ISOLATION_CAP_INTR_MASK GENMASK(31, 27)#define CXL_ISOLATION_CAPABILITY_LENGTH 0x10/* RAS Registers CXL 2.0 8.2.5.9 CXL RAS Capability Structure */
drivers/pci/pcie/Makefile +1 -0
@@ -14,3 +14,4 @@ obj-$(CONFIG_PCIE_PME) += pme.o obj-$(CONFIG_PCIE_DPC) += dpc.o obj-$(CONFIG_PCIE_PTM) += ptm.o obj-$(CONFIG_PCIE_EDR) += edr.o +obj-$(CONFIG_CXL_ISOLATION) += cxl_isolation.o
drivers/pci/pcie/cxl_isolation.c new file +87 -0
87 lines not on this page · raw message
drivers/pci/pcie/portdrv.c +1 -0
@@ -834,6 +834,7 @@ static void __init pcie_init_services(void)pcie_dpc_init ();pcie_bwctrl_init ();pcie_hp_init (); +pcie_cxliso_init (); }static int __init pcie_portdrv_init (void )
drivers/pci/pcie/portdrv.h +17 -1
@@ -22,8 +22,10 @@#define PCIE_PORT_SERVICE_DPC (1 << PCIE_PORT_SERVICE_DPC_SHIFT)#define PCIE_PORT_SERVICE_BWCTRL_SHIFT 4/* Bandwidth Controller (notifications) */ #define PCIE_PORT_SERVICE_BWCTRL (1 << PCIE_PORT_SERVICE_BWCTRL_SHIFT) +#define PCIE_PORT_SERVICE_CXLISO_SHIFT 5/* CXL Timeout & Isolation */ +#define PCIE_PORT_SERVICE_CXLISO (1 << PCIE_PORT_SERVICE_CXLISO_SHIFT) -#define PCIE_PORT_DEVICE_MAXSERVICES 5 +#define PCIE_PORT_DEVICE_MAXSERVICES 6extern bool pcie_ports_dpc_native;
@@ -53,6 +55,12 @@ static inline int pcie_dpc_init(void) { return 0; }int pcie_bwctrl_init (void ); +#ifdef CONFIG_CXL_ISOLATION +int pcie_cxliso_init (void ); +#else +static inline int pcie_cxliso_init (void ) {return 0 ; } +#endif +/* Port Type */ #define PCIE_ANY_PORT (~0)
@@ -123,4 +131,12 @@ static inline void pcie_pme_interrupt_enable(struct pci_dev *dev, bool en) {}#endif /* !CONFIG_PCIE_PME */ struct device *pcie_port_find_device (struct pci_dev *dev,u32 service); + +#ifdef CONFIG_CXL_ISOLATION +int pcie_cxliso_get_intr_vec (struct pci_dev *dev,int *vec); +#else +static inline int pcie_cxliso_get_intr_vec (struct pci_dev *dev,int *vec) +{return -ENXIO ; } +#endif +#endif /* _PORTDRV_H_ */
Signature · 1 line
2.34.1
Re: [PATCH 03/16] PCI: PCIe portdrv: Add CXL Isolation service driver
Quoted 8 lines · On Wed, 30 Jul 2025 16:47:05 -0500 Ben Cheatham <[email protected]>…
Add the CXL isolation service, which will provide the necessary information to the PCIe portdrv and CXL drivers to map, setup, and handle CXL isolation interrupts.
Add functions to get the CXL isolation MSI/-X interrupt vector from the PCIe portdrv.
Signed-off-by Ben Cheatham <[email protected]>
Hmm. I feel a bit guilty I haven't gotten back to a rework of the portdrv. To potentially make that easier (when I or someone else get the time), would it work for you if this only did MSI-X? That would let us handle this in a somewhat 'pluggable' way without having to deal with the limitations of MSI wrt to dynamic interrupt allocation.
Quoted 21 lines
--- drivers/cxl/Kconfig | 14 +++++ drivers/cxl/cxl.h | 4 ++ drivers/pci/pcie/Makefile | 1 + drivers/pci/pcie/cxl_isolation.c | 87 ++++++++++++++++++++++++++++++++ drivers/pci/pcie/portdrv.c | 1 + drivers/pci/pcie/portdrv.h | 18 ++++++- 6 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 drivers/pci/pcie/cxl_isolation.cdrivers/cxl/Kconfig +3
-0@@ -247,4 +247,18 @@ config CXL_NATIVE_RAS If unsure, or if this kernel is meant for production environments, say Y. +config CXL_ISOLATION + bool "CXL.mem Isolation Support" + depends on PCIEPORTBUS
drivers/cxl/Kconfig config CXL_NATIVE_RAS · line 262
Quoted 10 lines
drivers/cxl/Kconfig +10
-0+ depends on CXL_BUS=PCIEPORTBUS + help + Enables the CXL.mem isolation PCIe port bus service driver. This + driver, in combination with the CXL driver core, is responsible + for managing CXL-capable PCIe root ports that undergo CXL.mem + error isolation due to either a CXL.mem transaction timeout or + link down condition. Without error isolation, either of these + conditions will trigger a system reset. + + If unsure say 'y'
I'd drop this last line or say something more about when it makes sense to enable.
Quoted 42 lines
drivers/pci/pcie/cxl_isolation.c new file +36
-0@@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* The CXL Isolation PCIe port service driver provides functions to allocate +* and set up CXL Timeout & Isolation interrupts (CXL 3.2 12.3). This driver +* does no actual interrupt handling, it only provides the information for +* the CXL driver to set up its own handling because the CXL driver is better +* equipped to handle isolation interrupts. +* +* Copyright (C) 2025, Advanced Micro Devices, Inc. +* All Rights Reserved. +* +* Author: Ben Cheatham <[email protected]> +*/ + +#include <linux/pci.h> + +#include "../../cxl/cxlpci.h" +#include "portdrv.h" + +static int get_isolation_intr_vec (u32 cap) +{ +if (!FIELD_GET (CXL_ISOLATION_CAP_INTR_SUPP , cap) || + !FIELD_GET (CXL_ISOLATION_CAP_MEM_ISO_SUPP , cap)) +return -ENXIO ; + +return FIELD_GET (CXL_ISOLATION_CAP_INTR_MASK , cap); +} + +int pcie_cxliso_get_intr_vec (struct pci_dev *dev,int *vec) +{ +struct cxl_component_regs regs; +struct cxl_register_map map; +u32 cap; +int rc; + + rc =cxl_find_regblock (dev,CXL_REGLOC_RBI_COMPONENT , &map);
drivers/pci/pcie/cxl_isolation.c line 46
Quoted 10 lines
drivers/pci/pcie/cxl_isolation.c new file +10
-0+if (rc) +return rc; + + rc =cxl_setup_regs (&map); +if (rc) +return rc; + +if (!map.component_map.isolation.valid) +return -ENXIO ; +
Add some comments here on why we go through this dance of temporary mapping. (I have similar for the CPMU code I never finished upstreaming).
drivers/pci/pcie/cxl_isolation.c line 54
Quoted 8 lines
drivers/pci/pcie/cxl_isolation.c new file +8
-0+ rc =cxl_map_component_regs (&map, ®s, +BIT (CXL_CM_CAP_CAP_ID_ISOLATION )); +if (rc) +return rc; + + cap =readl (regs.isolation +CXL_ISOLATION_CAPABILITY_OFFSET ); + rc =get_isolation_intr_vec (cap); +if (rc <0 ) {
Probably use a goto given common shared stuff to do on exit.
Quoted 6 lines
drivers/pci/pcie/cxl_isolation.c new file +6
-0+cxl_unmap_component_regs (&map, ®s, +BIT (CXL_CM_CAP_CAP_ID_ISOLATION )); +return rc; + } + +if (vec)
drivers/pci/pcie/cxl_isolation.c line 70
Quoted 10 lines
drivers/pci/pcie/cxl_isolation.c new file +10
-0+ *vec = rc; + +cxl_unmap_component_regs (&map, ®s,BIT (CXL_CM_CAP_CAP_ID_ISOLATION )); +return 0 ; + +} + +static int cxl_isolation_probe (struct pcie_device *dev) +{ +if (!pcie_is_cxl (dev->port) ||pcie_cxliso_get_intr_vec (dev->port,NULL ))
The second call has rich error codes so better not to eat them.
if (!pcie_is_cxl(dev->port)) return -ENXIO; rc = pcie_cxl_iso_get_intr_vec(); if (rc) return rc;
drivers/pci/pcie/cxl_isolation.c line 73
Quoted 3 lines
drivers/pci/pcie/cxl_isolation.c new file +3
-0+return -ENXIO ; + +pci_info (dev->port,"CXLISO: Signaling with IRQ %d\n" , dev->irq);
I guess there is history of this for other portdrv services, but to me too noisy for a normal boot and should be trivial to get from /proc/interrupts
Quoted 2 lines
drivers/pci/pcie/cxl_isolation.c new file +2
-0+return 0 ; +}
Re: [PATCH 03/16] PCI: PCIe portdrv: Add CXL Isolation service driver
Quoted 10 lines · Jonathan Cameron
Quoted 7 lines · On Wed, 30 Jul 2025 16:47:05 -0500 Ben Cheatham <[email protected]>…
Add the CXL isolation service, which will provide the necessary information to the PCIe portdrv and CXL drivers to map, setup, and handle CXL isolation interrupts.
Add functions to get the CXL isolation MSI/-X interrupt vector from the PCIe portdrv.
Quoted 8 lines
Quoted 1 line
Signed-off-by Ben Cheatham <[email protected]>Hmm. I feel a bit guilty I haven't gotten back to a rework of the portdrv. To potentially make that easier (when I or someone else get the time), would it work for you if this only did MSI-X? That would let us handle this in a somewhat 'pluggable' way without having to deal with the limitations of MSI wrt to dynamic interrupt allocation.
No need to feel guilt, the latest AMD processors use MSI for this functionality. Relevant /proc/interrupts output on my Turin box:
41: <trim> 0 IR-PCI-MSI-0000:e0:01.1 0-edge PCIe PME, PCIe bwctrl, cxl_isolation
So it looks like I'm stuck with doing this weird dance between the portdrv and cxl drivers and the resulting module dependency.
Quoted 19 lines
Quoted 19 lines
--- drivers/cxl/Kconfig | 14 +++++ drivers/cxl/cxl.h | 4 ++ drivers/pci/pcie/Makefile | 1 + drivers/pci/pcie/cxl_isolation.c | 87 ++++++++++++++++++++++++++++++++ drivers/pci/pcie/portdrv.c | 1 + drivers/pci/pcie/portdrv.h | 18 ++++++- 6 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 drivers/pci/pcie/cxl_isolation.cdrivers/cxl/Kconfig +0
-0@@ -247,4 +247,18 @@ config CXL_NATIVE_RAS If unsure, or if this kernel is meant for production environments, say Y.
Quoted 15 lines
drivers/cxl/Kconfig config CXL_NATIVE_RAS · line 262
Quoted 13 lines
drivers/cxl/Kconfig +13
-0+config CXL_ISOLATION + bool "CXL.mem Isolation Support" + depends on PCIEPORTBUS + depends on CXL_BUS=PCIEPORTBUS + help + Enables the CXL.mem isolation PCIe port bus service driver. This + driver, in combination with the CXL driver core, is responsible + for managing CXL-capable PCIe root ports that undergo CXL.mem + error isolation due to either a CXL.mem transaction timeout or + link down condition. Without error isolation, either of these + conditions will trigger a system reset. + + If unsure say 'y'I'd drop this last line or say something more about when it makes sense to enable.
Ok, will do.
Quoted 48 lines
Quoted 48 lines
drivers/pci/pcie/cxl_isolation.c new file +41
-0@@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* The CXL Isolation PCIe port service driver provides functions to allocate +* and set up CXL Timeout & Isolation interrupts (CXL 3.2 12.3). This driver +* does no actual interrupt handling, it only provides the information for +* the CXL driver to set up its own handling because the CXL driver is better +* equipped to handle isolation interrupts. +* +* Copyright (C) 2025, Advanced Micro Devices, Inc. +* All Rights Reserved. +* +* Author: Ben Cheatham <[email protected]> +*/ + +#include <linux/pci.h> + +#include "../../cxl/cxlpci.h" +#include "portdrv.h" + +static int get_isolation_intr_vec (u32 cap) +{ +if (!FIELD_GET (CXL_ISOLATION_CAP_INTR_SUPP , cap) || + !FIELD_GET (CXL_ISOLATION_CAP_MEM_ISO_SUPP , cap)) +return -ENXIO ; + +return FIELD_GET (CXL_ISOLATION_CAP_INTR_MASK , cap); +} + +int pcie_cxliso_get_intr_vec (struct pci_dev *dev,int *vec) +{ +struct cxl_component_regs regs; +struct cxl_register_map map; +u32 cap; +int rc; + + rc =cxl_find_regblock (dev,CXL_REGLOC_RBI_COMPONENT , &map); +if (rc) +return rc; + + rc =cxl_setup_regs (&map); +if (rc)
Quoted 9 lines
drivers/pci/pcie/cxl_isolation.c line 46
Quoted 5 lines
drivers/pci/pcie/cxl_isolation.c new file +5
-0+return rc; + +if (!map.component_map.isolation.valid) +return -ENXIO ; +Add some comments here on why we go through this dance of temporary mapping. (I have similar for the CPMU code I never finished upstreaming).
Ok.
Quoted 11 lines
drivers/pci/pcie/cxl_isolation.c line 54
Quoted 8 lines
drivers/pci/pcie/cxl_isolation.c new file +8
-0+ rc =cxl_map_component_regs (&map, ®s, +BIT (CXL_CM_CAP_CAP_ID_ISOLATION )); +if (rc) +return rc; + + cap =readl (regs.isolation +CXL_ISOLATION_CAPABILITY_OFFSET ); + rc =get_isolation_intr_vec (cap); +if (rc <0 ) {Probably use a goto given common shared stuff to do on exit.
Sure!
Quoted 9 lines
Quoted 9 lines
drivers/pci/pcie/cxl_isolation.c new file +9
-0+cxl_unmap_component_regs (&map, ®s, +BIT (CXL_CM_CAP_CAP_ID_ISOLATION )); +return rc; + } + +if (vec) + *vec = rc; + +cxl_unmap_component_regs (&map, ®s,BIT (CXL_CM_CAP_CAP_ID_ISOLATION ));
Quoted 9 lines
drivers/pci/pcie/cxl_isolation.c line 70
Quoted 7 lines
drivers/pci/pcie/cxl_isolation.c new file +7
-0+return 0 ; + +} + +static int cxl_isolation_probe (struct pcie_device *dev) +{ +if (!pcie_is_cxl (dev->port) ||pcie_cxliso_get_intr_vec (dev->port,NULL ))The second call has rich error codes so better not to eat them.
Ok.
Quoted 7 lines
if (!pcie_is_cxl(dev->port)) return -ENXIO; rc = pcie_cxl_iso_get_intr_vec(); if (rc) return rc;
Quoted 5 lines
drivers/pci/pcie/cxl_isolation.c line 73
Quoted 3 lines
drivers/pci/pcie/cxl_isolation.c new file +3
-0+return -ENXIO ; + +pci_info (dev->port,"CXLISO: Signaling with IRQ %d\n" , dev->irq);I guess there is history of this for other portdrv services, but to me too noisy for a normal boot and should be trivial to get from
/proc/interrupts
I just went with what the rest of the portdrv services were doing. I'll drop it to a pci_dbg() instead of just deleting it for parity.
Quoted 4 lines
Quoted 3 lines
drivers/pci/pcie/cxl_isolation.c new file +2
-0+return 0 ; +}
PATCH 4/16 PCI: PCIe portdrv: Allocate CXL isolation MSI/-X vector
In reply to Ben CheathamUpdate the PCIe portdrv MSI/-X vector allocation code to include the CXL isolation service.
--- drivers/pci/pcie/portdrv.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-)
drivers/pci/pcie/portdrv.c +16 -4
@@ -50,12 +50,12 @@ static void release_pcie_device(struct device *dev) }/* -* Fill in *pme, *aer, *dpc with the relevant Interrupt Message Numbers if +* Fill in *pme, *aer, *dpc, *iso with the relevant Interrupt Message Numbers if * services are enabled in "mask". Return the number of MSI/MSI-X vectors * required to accommodate the largest Message Number. */ static int pcie_message_numbers (struct pci_dev *dev,int mask, -u32 *pme,u32 *aer,u32 *dpc) +u32 *pme,u32 *aer,u32 *dpc,u32 *iso) {u32 nvec =0 , pos;u16 reg16;
@@ -98,6 +98,11 @@ static int pcie_message_numbers(struct pci_dev *dev, int mask, } } +if (mask &PCIE_PORT_SERVICE_CXLISO ) { +if (pcie_cxliso_get_intr_vec (dev, iso) ==0 ) + nvec =max (nvec, *iso +1 ); + } +return nvec; }
@@ -113,7 +118,7 @@ static int pcie_message_numbers(struct pci_dev *dev, int mask,static int pcie_port_enable_irq_vec (struct pci_dev *dev,int *irqs,int mask) {int nr_entries, nvec, pcie_irq; -u32 pme =0 , aer =0 , dpc =0 ; +u32 pme =0 , aer =0 , dpc =0 , iso =0 ;/* Allocate the maximum possible number of MSI/MSI-X vectors */ nr_entries = pci_alloc_irq_vectors(dev, 1, PCIE_PORT_MAX_MSI_ENTRIES,
@@ -122,7 +127,7 @@ static int pcie_port_enable_irq_vec(struct pci_dev *dev, int *irqs, int mask)return nr_entries;/* See how many and which Interrupt Message Numbers we actually use */ - nvec =pcie_message_numbers (dev, mask, &pme, &aer, &dpc); + nvec =pcie_message_numbers (dev, mask, &pme, &aer, &dpc, &iso);if (nvec > nr_entries) {pci_free_irq_vectors (dev);return -EIO ;
@@ -163,6 +168,9 @@ static int pcie_port_enable_irq_vec(struct pci_dev *dev, int *irqs, int mask)if (mask &PCIE_PORT_SERVICE_DPC ) irqs[PCIE_PORT_SERVICE_DPC_SHIFT ] =pci_irq_vector (dev, dpc); +if (mask &PCIE_PORT_SERVICE_CXLISO ) + irqs[PCIE_PORT_SERVICE_CXLISO_SHIFT ] =pci_irq_vector (dev, iso); +return 0 ; }
@@ -278,6 +286,10 @@ static int get_port_device_capability(struct pci_dev *dev) services |=PCIE_PORT_SERVICE_BWCTRL ; } +if (pci_pcie_type (dev) ==PCI_EXP_TYPE_ROOT_PORT && +pcie_cxliso_get_intr_vec (dev,NULL ) ==0 ) + services |=PCIE_PORT_SERVICE_CXLISO ; +return services; }
Signature · 1 line
2.34.1
Re: [PATCH 04/16] PCI: PCIe portdrv: Allocate CXL isolation MSI/-X vector
Observe the subject line convention for drivers/pci/pcie/portdrv.c.
Quoted 2 lines · Ben Cheatham
Update the PCIe portdrv MSI/-X vector allocation code to include the CXL isolation service.
Use "MSI/MSI-X", not "MSI/-X" to follow PCIe spec formatting and make this more greppable. In subject also.
Bjorn
Re: [PATCH 04/16] PCI: PCIe portdrv: Allocate CXL isolation MSI/-X vector
Hi Bjorn, thanks for taking a look!
Quoted 9 lines · Bjorn Helgaas
Observe the subject line convention for
drivers/pci/pcie/portdrv.c.Quoted 2 lines · Ben Cheatham
Update the PCIe portdrv MSI/-X vector allocation code to include the CXL isolation service.
Use "MSI/MSI-X", not "MSI/-X" to follow PCIe spec formatting and make this more greppable. In subject also.
For sure, I'll update it throughout the series.
Quoted 1 line
Bjorn
PATCH 5/16 PCI: PCIe portdrv: Add interface for getting CXL isolation IRQ
In reply to Ben CheathamAdd a function to the CXL isolation service driver that allows the CXL core to get the necessary information for setting up an interrupt handler.
--- drivers/pci/pcie/cxl_isolation.c | 26 +++++++++++++++++++++++++- include/cxl/isolation.h | 26 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 include/cxl/isolation.h
drivers/pci/pcie/cxl_isolation.c +25 -1
@@ -13,6 +13,7 @@*/ #include <linux/pci.h> +#include <cxl/isolation.h> #include "../../cxl/cxlpci.h" #include "portdrv.h"
@@ -62,14 +63,37 @@ int pcie_cxliso_get_intr_vec(struct pci_dev *dev, int *vec)cxl_unmap_component_regs (&map, ®s,BIT (CXL_CM_CAP_CAP_ID_ISOLATION ));return 0 ; +} + +struct cxl_isolation_info * +pcie_cxl_dport_get_isolation_info (struct pci_dev *dport_dev) +{ +struct device *dev; + dev =pcie_port_find_device (dport_dev,PCIE_PORT_SERVICE_CXLISO ); +if (!dev) +return NULL ; + +return get_service_data (to_pcie_device (dev)); }static int cxl_isolation_probe (struct pcie_device *dev) { -if (!pcie_is_cxl (dev->port) ||pcie_cxliso_get_intr_vec (dev->port,NULL )) +struct cxl_isolation_info *info; +if (!pcie_is_cxl (dev->port) || +pcie_cxliso_get_intr_vec (dev->port,NULL ))return -ENXIO ; + info =devm_kzalloc (&dev->device,sizeof (*info),GFP_KERNEL ); +if (!info) +return -ENOMEM ; + + *info = (struct cxl_isolation_info ) { + .dev = &dev->device, + .irq = dev->irq, + }; + +set_service_data (dev, info);pci_info (dev->port,"CXLISO: Signaling with IRQ %d\n" , dev->irq);return 0 ; }
include/cxl/isolation.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __CXL_ISOLATION_H__ +#define __CXL_ISOLATION_H__ + +#include <linux/pci.h> + +/** +* struct cxl_isolation_info - Information for mapping CXL Isolation interrupts +* @dev: PCIe portdrv service device associated with IRQ +* @irq: IRQ line for interrupt +*/ +struct cxl_isolation_info { +struct device *dev; +int irq; +}; + +#ifdef CONFIG_CXL_ISOLATION +struct cxl_isolation_info * +pcie_cxl_dport_get_isolation_info (struct pci_dev *dport_dev); +#else /* !CONFIG_CXL_ISOLATION */ +static inline struct cxl_isolation_info * +pcie_cxl_dport_get_isolation_info (struct pci_dev *dport_dev) +{return NULL ; } +#endif /* !CONFIG_CXL_ISOLATION */ + +#endif
Signature · 1 line
2.34.1
Re: [PATCH 05/16] PCI: PCIe portdrv: Add interface for getting CXL isolation IRQ
Quoted 3 lines · Ben Cheatham
Add a function to the CXL isolation service driver that allows the CXL core to get the necessary information for setting up an interrupt handler.
[...]
drivers/pci/pcie/cxl_isolation.c int pcie_cxliso_get_intr_vec(struct pci_dev *dev, int *vec) · line 85
Quoted 7 lines
static int
cxl_isolation_probe(struct pcie_device *dev){drivers/pci/pcie/cxl_isolation.c +3
-1-if (!pcie_is_cxl (dev->port) ||pcie_cxliso_get_intr_vec (dev->port,NULL )) +struct cxl_isolation_info *info; +if (!pcie_is_cxl (dev->port) || +pcie_cxliso_get_intr_vec (dev->port,NULL ))return -ENXIO ;
The re-wrapping of the if-condition shouldn't be here, it should be wrapped the way you want it in the patch *introducing* the if-condition.
drivers/pci/pcie/cxl_isolation.c int pcie_cxliso_get_intr_vec(struct pci_dev *dev, int *vec) · line 96
Quoted 10 lines
drivers/pci/pcie/cxl_isolation.c +10
-0+ info =devm_kzalloc (&dev->device,sizeof (*info),GFP_KERNEL ); +if (!info) +return -ENOMEM ; + + *info = (struct cxl_isolation_info ) { + .dev = &dev->device, + .irq = dev->irq, + }; + +set_service_data (dev, info);
No, the irq is already saved in struct pcie_device, there's no need to duplicate that.
drivers/pci/pcie/cxl_isolation.c int pcie_cxliso_get_intr_vec(struct pci_dev *dev, int *vec) · line 78
Quoted 11 lines
drivers/pci/pcie/cxl_isolation.c +9
-0+struct cxl_isolation_info * +pcie_cxl_dport_get_isolation_info (struct pci_dev *dport_dev) +{ +struct device *dev; + dev =pcie_port_find_device (dport_dev,PCIE_PORT_SERVICE_CXLISO ); +if (!dev) +return NULL ; + +return get_service_data (to_pcie_device (dev)); }
Just retrieve the irq from to_pcie_device(dev) and either return it directly or through a call-by-reference parameter.
Thanks,
Lukas
Re: [PATCH 05/16] PCI: PCIe portdrv: Add interface for getting CXL isolation IRQ
Thanks for taking a look Lukas! Responses inline.
Quoted 5 lines · Lukas Wunner
Quoted 3 lines · Ben Cheatham
Add a function to the CXL isolation service driver that allows the CXL core to get the necessary information for setting up an interrupt handler.
[...]
Quoted 11 lines
drivers/pci/pcie/cxl_isolation.c int pcie_cxliso_get_intr_vec(struct pci_dev *dev, int *vec) · line 85
Quoted 7 lines
static int
cxl_isolation_probe(struct pcie_device *dev){drivers/pci/pcie/cxl_isolation.c +3
-1-if (!pcie_is_cxl (dev->port) ||pcie_cxliso_get_intr_vec (dev->port,NULL )) +struct cxl_isolation_info *info; +if (!pcie_is_cxl (dev->port) || +pcie_cxliso_get_intr_vec (dev->port,NULL ))return -ENXIO ;The re-wrapping of the if-condition shouldn't be here, it should be wrapped the way you want it in the patch *introducing* the if-condition.
You're right, don't know why I did that :/.
Quoted 5 lines
Quoted 5 lines
drivers/pci/pcie/cxl_isolation.c +5
-0+ info =devm_kzalloc (&dev->device,sizeof (*info),GFP_KERNEL ); +if (!info) +return -ENOMEM ; + + *info = (struct cxl_isolation_info ) {
Quoted 9 lines
drivers/pci/pcie/cxl_isolation.c int pcie_cxliso_get_intr_vec(struct pci_dev *dev, int *vec) · line 96
Quoted 5 lines
drivers/pci/pcie/cxl_isolation.c +5
-0+ .dev = &dev->device, + .irq = dev->irq, + }; + +set_service_data (dev, info);No, the irq is already saved in struct
pcie_device, there's no need to duplicate that.
Good point, will do. I think I originally had the mapping of the CXL isolation register in the struct cxl_isolation_info, but it makes no sense to keep this around anymore.
Thanks,
Ben
PATCH 6/16 cxl/core: Enable CXL.mem isolation
In reply to Ben CheathamEnable CXL.mem isolation during set up of CXL-capable PCIe Root Ports that have the capability. This capability is optional, so failure to enable isolation is not an error that should fail probe.
--- drivers/cxl/core/pci.c | 45 +++++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/port.c | 36 +++++++++++++++++++++++++++++++++ drivers/cxl/cxl.h | 5 +++++ include/cxl/isolation.h | 10 +++++++++ 4 files changed, 96 insertions(+)
drivers/cxl/core/pci.c +45 -0
@@ -7,6 +7,7 @@#include <linux/pci.h> #include <linux/pci-doe.h> #include <linux/aer.h> +#include <cxl/isolation.h> #include <cxlpci.h> #include <cxlmem.h> #include <cxl.h>
@@ -1170,3 +1171,47 @@ int cxl_port_update_total_dports(struct cxl_port *port)return 0 ; }EXPORT_SYMBOL_NS_GPL (cxl_port_update_total_dports,"CXL" ); + +void cxl_enable_isolation (struct cxl_dport *dport) +{ +u32 ctrl; + + ctrl =readl (dport->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); + ctrl |=CXL_ISOLATION_CTRL_MEM_ISO_ENABLE ; +writel (ctrl, dport->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); + +dev_dbg (dport->dport_dev,"Enabled CXL.mem isolation\n" ); +} + +static int cxl_dport_wait_for_rp_busy (void __iomem *reg) +{ +u32 status; +int i =4 ; + +do { + status =readl (reg +CXL_ISOLATION_STATUS_OFFSET ); +if (!(status &CXL_ISOLATION_STAT_RP_BUSY )) +return 0 ; + +msleep (500 ); + }while (--i); + +return -ETIMEDOUT ; +} + +int cxl_disable_isolation (struct cxl_dport *dport) +{ +u32 ctrl; +int rc; + + rc =cxl_dport_wait_for_rp_busy (dport->regs.isolation); +if (rc) +return rc; + + ctrl =readl (dport->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); + ctrl &=CXL_ISOLATION_CTRL_MEM_ISO_ENABLE ; +writel (ctrl, dport->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); + +dev_dbg (dport->dport_dev,"Disabled CXL.mem isolation\n" ); +return 0 ; +}
drivers/cxl/core/port.c +36 -0
@@ -10,6 +10,7 @@#include <linux/slab.h> #include <linux/idr.h> #include <linux/node.h> +#include <cxl/isolation.h> #include <cxl/einj.h> #include <cxlmem.h> #include <cxlpci.h>
@@ -1173,6 +1174,35 @@ static void cxl_dport_unlink(void *data)sysfs_remove_link (&port->dev.kobj, link_name); } +/** +* cxl_dport_enable_isolation - Enable CXL Isolation for a CXL dport. This is +* an optional capability only supported by PCIe Root Ports. +* +* @dport: CXL-capable PCIe Root Port +* +* Returns 0 if capability unsupported, or when enabled. +*/ +static int cxl_dport_enable_isolation (struct cxl_dport *dport) +{ +u32 cap; +int rc; + +if (!dport->reg_map.component_map.isolation.valid) +return 0 ; + + rc =cxl_map_component_regs (&dport->reg_map, &dport->regs.component, +BIT (CXL_CM_CAP_CAP_ID_ISOLATION )); +if (rc) +return rc; + + cap =readl (dport->regs.isolation +CXL_ISOLATION_CAPABILITY_OFFSET ); +if (!(cap &CXL_ISOLATION_CAP_MEM_ISO_SUPP )) +return 0 ; + +cxl_enable_isolation (dport); +return 0 ; +} +static struct cxl_dport * __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev, int port_id, resource_size_t component_reg_phys,
@@ -1235,6 +1265,12 @@ __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev,dev_dbg (dport_dev,"Component Registers found for dport: %pa\n" , &component_reg_phys); +if (IS_ENABLED (CONFIG_CXL_ISOLATION )) { + rc =cxl_dport_enable_isolation (dport); +if (rc) +return ERR_PTR (rc); + } +cond_cxl_root_lock (port); rc =add_dport (port, dport);cond_cxl_root_unlock (port);
drivers/cxl/cxl.h +5 -0
@@ -139,6 +139,11 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)#define CXL_ISOLATION_CAP_MEM_ISO_SUPP BIT(16)#define CXL_ISOLATION_CAP_INTR_SUPP BIT(26)#define CXL_ISOLATION_CAP_INTR_MASK GENMASK(31, 27) +#define CXL_ISOLATION_CTRL_OFFSET 0x8 +#define CXL_ISOLATION_CTRL_MEM_ISO_ENABLE BIT(16) +#define CXL_ISOLATION_STATUS_OFFSET 0xC +#define CXL_ISOLATION_STAT_MEM_ISO BIT(8) +#define CXL_ISOLATION_STAT_RP_BUSY BIT(14)#define CXL_ISOLATION_CAPABILITY_LENGTH 0x10/* RAS Registers CXL 2.0 8.2.5.9 CXL RAS Capability Structure */
include/cxl/isolation.h +10 -0
@@ -14,6 +14,16 @@ struct cxl_isolation_info {int irq; }; +struct cxl_dport ; +#if IS_ENABLED (CONFIG_CXL_BUS ) +void cxl_enable_isolation (struct cxl_dport *dport); +int cxl_disable_isolation (struct cxl_dport *dport); +#else /* !CONFIG_CXL_BUS */ +static inline void cxl_enable_isolation (struct cxl_dport *dport) {} +static inline int cxl_disable_isolation (struct cxl_dport *dport) +{return -ENXIO ; } +#endif /* !CONFIG_CXL_BUS */ +#ifdef CONFIG_CXL_ISOLATION struct cxl_isolation_info *pcie_cxl_dport_get_isolation_info (struct pci_dev *dport_dev);
Signature · 1 line
2.34.1
Re: [PATCH 06/16] cxl/core: Enable CXL.mem isolation
drivers/cxl/core/pci.c int cxl_port_update_total_dports(struct cxl_port *port) · line 1191
Quoted 12 lines · On Wed, 30 Jul 2025 16:47:08 -0500 Ben Cheatham <[email protected]>…
Enable CXL.mem isolation during set up of CXL-capable PCIe Root Ports that have the capability. This capability is optional, so failure to enable isolation is not an error that should fail probe.
Signed-off-by Ben Cheatham <[email protected]>drivers/cxl/core/pci.c +6
-0+static int cxl_dport_wait_for_rp_busy (void __iomem *reg) +{ +u32 status; +int i =4 ; + + do {
readl_poll_timeout() in iopoll.h should work here.
Quoted 9 lines
drivers/cxl/core/pci.c +9
-0+ status =readl (reg +CXL_ISOLATION_STATUS_OFFSET ); +if (!(status &CXL_ISOLATION_STAT_RP_BUSY )) +return 0 ; + +msleep (500 ); + }while (--i); + +return -ETIMEDOUT ; +}
Re: [PATCH 06/16] cxl/core: Enable CXL.mem isolation
Quoted 9 lines · Jonathan Cameron
Quoted 5 lines · On Wed, 30 Jul 2025 16:47:08 -0500 Ben Cheatham <[email protected]>…
Enable CXL.mem isolation during set up of CXL-capable PCIe Root Ports that have the capability. This capability is optional, so failure to enable isolation is not an error that should fail probe.
Signed-off-by Ben Cheatham <[email protected]>
Quoted 9 lines
drivers/cxl/core/pci.c int cxl_port_update_total_dports(struct cxl_port *port) · line 1191
Quoted 6 lines
drivers/cxl/core/pci.c +6
-0+static int cxl_dport_wait_for_rp_busy (void __iomem *reg) +{ +u32 status; +int i =4 ; + + do {
readl_poll_timeout()iniopoll.hshould work here.
I wasn't aware of that, I'll check it out.
Quoted 10 lines
Quoted 10 lines
drivers/cxl/core/pci.c +9
-0+ status =readl (reg +CXL_ISOLATION_STATUS_OFFSET ); +if (!(status &CXL_ISOLATION_STAT_RP_BUSY )) +return 0 ; + +msleep (500 ); + }while (--i); + +return -ETIMEDOUT ; +}
PATCH 7/16 cxl/core: Set up isolation interrupts
In reply to Ben CheathamRegister a CXL isolation interrupt handler as part of cxl_dport set up. Only CXL-capable PCIe Root Ports have CXL.mem isolation interrupt support. The interrupts are left masked and will be unmasked in a later commit.
A CXL-capable PCIe Root Port that has CXL.mem isolation support and no interrupt support will have any isolation support enabled. If isolation were enabled without interrupts CXL.mem transactions could return poisoned data. This could cause data/system corruption if left unhandled, so the capability is left disabled in this case.
CXL endpoint drivers can add an isolation handler for a device through the isolation_handler member of struct cxl_dev_state. If this handler is not present, the system will panic. If the handler opts to not panic (i.e. returns "CXL_ERR_NONE"), the endpoint driver is charged with maintaining system reliability (cleaning up CXL memory, disabling device state, etc.).
--- drivers/cxl/core/port.c | 113 ++++++++++++++++++++++++++++++++++++++-- drivers/cxl/cxl.h | 1 + drivers/cxl/cxlmem.h | 4 ++ include/cxl/isolation.h | 10 ++++ 4 files changed, 125 insertions(+), 3 deletions(-)
drivers/cxl/core/port.c +110 -3
@@ -1174,15 +1174,117 @@ static void cxl_dport_unlink(void *data)sysfs_remove_link (&port->dev.kobj, link_name); } +struct isolation_intr_data { +struct cxl_dport *dport; +struct cxl_port *port; +}; + +static irqreturn_t cxl_isolation_thread (int irq,void *_data) +{ +struct isolation_intr_data *data = _data; +struct cxl_dport *dport = data->dport; +struct cxl_port *port = data->port; +enum cxl_err_results res, acc; +struct cxl_dev_state *cxlds; +struct cxl_memdev *cxlmd; +struct cxl_dport *iter; +unsigned long index; +struct cxl_ep *ep; +bool lnk_down; +u32 status; + +if (!dport || !port) +return IRQ_NONE ; + +guard (device)(&port->dev); +if (!dport->regs.isolation) + goto panic; + + status =readl (dport->regs.isolation +CXL_ISOLATION_STATUS_OFFSET ); + lnk_down =FIELD_GET (CXL_ISOLATION_STAT_LNK_DOWN , status); + + acc =CXL_ERR_NONE ; +xa_for_each (&port->endpoints, index, ep) { + iter = ep->dport; +while (iter && (&iter->port->dev != &port->dev)) + iter = iter->port->parent_dport; + + res =CXL_ERR_PANIC ; +if (iter->dport_dev == dport->dport_dev) { + cxlmd =to_cxl_memdev (ep->ep); + cxlds = cxlmd->cxlds; + +if (cxlds && cxlds->isolation_handler) + res = cxlds->isolation_handler (cxlds, lnk_down); + } + + acc =max (res, acc); + } + +if (acc ==CXL_ERR_NONE ) +return IRQ_HANDLED ; + +panic: +panic ("%s: downstream devices could not recover from CXL.mem link down\n" , +dev_name (dport->dport_dev)); +return IRQ_NONE ; +} + +static void cxl_dport_free_interrupts (void *data) +{ +struct cxl_isolation_info *info; +struct cxl_dport *dport = data; +struct pci_dev *pdev =to_pci_dev (dport->dport_dev); + + info =pcie_cxl_dport_get_isolation_info (pdev); +if (!info) +return ; + +devm_free_irq (info->dev, info->irq, dport); +} + +static int cxl_dport_setup_interrupts (struct device *host, +struct cxl_dport *dport) +{ +struct isolation_intr_data *data; +struct cxl_isolation_info *info; +u32 cap; +int rc; + + cap =readl (dport->regs.isolation +CXL_ISOLATION_CAPABILITY_OFFSET ); +if (!(cap &CXL_ISOLATION_CAP_INTR_SUPP )) +return -ENXIO ; + + info =pcie_cxl_dport_get_isolation_info (to_pci_dev (dport->dport_dev)); +if (!info) +return -ENXIO ; + + data =devm_kmalloc (host,sizeof (*data),GFP_KERNEL ); +if (!data) +return -ENOMEM ; + data->port = dport->port; + data->dport = dport; + + rc =devm_request_threaded_irq (info->dev, info->irq,NULL , + cxl_isolation_thread, +IRQF_SHARED |IRQF_ONESHOT , +"cxl_isolation" , data); +if (rc) +return rc; + +return devm_add_action_or_reset (host, cxl_dport_free_interrupts, dport); +} +/** * cxl_dport_enable_isolation - Enable CXL Isolation for a CXL dport. This is * an optional capability only supported by PCIe Root Ports. -* +* @host: Host device for @dport * @dport: CXL-capable PCIe Root Port * * Returns 0 if capability unsupported, or when enabled. */ -static int cxl_dport_enable_isolation (struct cxl_dport *dport) +static int cxl_dport_enable_isolation (struct device *host, +struct cxl_dport *dport) {u32 cap;int rc;
@@ -1199,6 +1301,10 @@ static int cxl_dport_enable_isolation(struct cxl_dport *dport)if (!(cap &CXL_ISOLATION_CAP_MEM_ISO_SUPP ))return 0 ; + rc =cxl_dport_setup_interrupts (host, dport); +if (rc) +return rc == -ENXIO ?0 : rc; +cxl_enable_isolation (dport);return 0 ; }
@@ -1266,7 +1372,7 @@ __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev, &component_reg_phys);if (IS_ENABLED (CONFIG_CXL_ISOLATION )) { - rc =cxl_dport_enable_isolation (dport); + rc =cxl_dport_enable_isolation (host, dport);if (rc)return ERR_PTR (rc); }
@@ -1543,6 +1649,7 @@ static void reap_dport(struct cxl_port *port, struct cxl_dport *dport) {devm_release_action (&port->dev, cxl_dport_unlink, dport);devm_release_action (&port->dev, cxl_dport_remove, dport); +devm_release_action (&port->dev, cxl_dport_free_interrupts, dport);devm_kfree (&port->dev, dport); }
drivers/cxl/cxl.h +1 -0
@@ -143,6 +143,7 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)#define CXL_ISOLATION_CTRL_MEM_ISO_ENABLE BIT(16)#define CXL_ISOLATION_STATUS_OFFSET 0xC#define CXL_ISOLATION_STAT_MEM_ISO BIT(8) +#define CXL_ISOLATION_STAT_LNK_DOWN BIT(9)#define CXL_ISOLATION_STAT_RP_BUSY BIT(14)#define CXL_ISOLATION_CAPABILITY_LENGTH 0x10
drivers/cxl/cxlmem.h +4 -0
@@ -9,6 +9,7 @@#include <linux/node.h> #include <cxl/event.h> #include <cxl/mailbox.h> +#include <cxl/isolation.h> #include "cxl.h" /* CXL 2.0 8.2.8.5.1.1 Memory Device Status Register */
@@ -426,6 +427,7 @@ struct cxl_dpa_partition {* @type: Generic Memory Class device or Vendor Specific Memory device * @cxl_mbox: CXL mailbox context * @cxlfs: CXL features context +* @isolation_handler: CXL isolation CXL.mem link down handler */ struct cxl_dev_state {struct device *dev;
@@ -444,6 +446,8 @@ struct cxl_dev_state {#ifdef CONFIG_CXL_FEATURES struct cxl_features_state *cxlfs;#endif +enum cxl_err_results (*isolation_handler)(struct cxl_dev_state *cxlds, +bool lnk_down); };static inline resource_size_t cxl_pmem_size (struct cxl_dev_state *cxlds)
include/cxl/isolation.h +10 -0
@@ -4,6 +4,16 @@#include <linux/pci.h> +/** +* enum cxl_err_results - Possible results of an CXL isolation handler +* @CXL_ERR_NONE: Device can recover without CXL core intervention +* @CXL_ERR_PANIC: Device can't recover +*/ +enum cxl_err_results { +CXL_ERR_NONE =0 , +CXL_ERR_PANIC , +}; +/** * struct cxl_isolation_info - Information for mapping CXL Isolation interrupts * @dev: PCIe portdrv service device associated with IRQ
Signature · 1 line
2.34.1
Re: [PATCH 07/16] cxl/core: Set up isolation interrupts
Quoted 17 lines · On Wed, 30 Jul 2025 16:47:09 -0500 Ben Cheatham <[email protected]>…
Register a CXL isolation interrupt handler as part of
cxl_dportset up. Only CXL-capable PCIe Root Ports have CXL.mem isolation interrupt support. The interrupts are left masked and will be unmasked in a later commit.A CXL-capable PCIe Root Port that has CXL.mem isolation support and no interrupt support will have any isolation support enabled. If isolation were enabled without interrupts CXL.mem transactions could return poisoned data. This could cause data/system corruption if left unhandled, so the capability is left disabled in this case.
CXL endpoint drivers can add an isolation handler for a device through the
isolation_handlermember of structcxl_dev_state. If this handler is not present, the system will panic. If the handler opts to not panic (i.e. returns "CXL_ERR_NONE"), the endpoint driver is charged with maintaining system reliability (cleaning up CXL memory, disabling device state, etc.).
Quoted 7 lines
Signed-off-by Ben Cheatham <[email protected]>/**
*cxl_dport_enable_isolation- Enable CXL Isolation for a CXL dport. This is
* an optional capability only supported by PCIe Root Ports.
- *
Make the edit on original patch if you want to get rid of this line.
Quoted 5 lines
+ * @host: Host device for @dport
* @dport: CXL-capable PCIe Root Port
*
* Returns 0 if capability unsupported, or when enabled. */
Re: [PATCH 07/16] cxl/core: Set up isolation interrupts
Quoted 20 lines · Jonathan Cameron
Quoted 17 lines · On Wed, 30 Jul 2025 16:47:09 -0500 Ben Cheatham <[email protected]>…
Register a CXL isolation interrupt handler as part of
cxl_dportset up. Only CXL-capable PCIe Root Ports have CXL.mem isolation interrupt support. The interrupts are left masked and will be unmasked in a later commit.A CXL-capable PCIe Root Port that has CXL.mem isolation support and no interrupt support will have any isolation support enabled. If isolation were enabled without interrupts CXL.mem transactions could return poisoned data. This could cause data/system corruption if left unhandled, so the capability is left disabled in this case.
CXL endpoint drivers can add an isolation handler for a device through the
isolation_handlermember of structcxl_dev_state. If this handler is not present, the system will panic. If the handler opts to not panic (i.e. returns "CXL_ERR_NONE"), the endpoint driver is charged with maintaining system reliability (cleaning up CXL memory, disabling device state, etc.).
Quoted 9 lines
Quoted 7 lines
Signed-off-by Ben Cheatham <[email protected]>/**
*cxl_dport_enable_isolation- Enable CXL Isolation for a CXL dport. This is
* an optional capability only supported by PCIe Root Ports.
- *Make the edit on original patch if you want to get rid of this line.
Yep, will do.
Quoted 7 lines
Quoted 5 lines
+ * @host: Host device for @dport
* @dport: CXL-capable PCIe Root Port
*
* Returns 0 if capability unsupported, or when enabled. */
PATCH 8/16 cxl/core: Enable CXL isolation interrupts
In reply to Ben CheathamAdd functions to enable and disable CXL isolation interrupts. Use these functions to enable interrupts as part of isolation set up.
--- drivers/cxl/core/core.h | 2 ++ drivers/cxl/core/pci.c | 22 ++++++++++++++++++++++ drivers/cxl/core/port.c | 10 +++++++++- drivers/cxl/cxl.h | 1 + 4 files changed, 34 insertions(+), 1 deletion(-)
drivers/cxl/core/core.h +2 -0
@@ -146,4 +146,6 @@ int cxl_set_feature(struct cxl_mailbox *cxl_mbox, const uuid_t *feat_uuid, u16 *return_code);#endif +void cxl_enable_isolation_interrupts (struct cxl_dport *dport); +void cxl_disable_isolation_interrupts (struct cxl_dport *dport);#endif /* __CXL_CORE_H__ */
drivers/cxl/core/pci.c +22 -0
@@ -1172,6 +1172,28 @@ int cxl_port_update_total_dports(struct cxl_port *port) }EXPORT_SYMBOL_NS_GPL (cxl_port_update_total_dports,"CXL" ); +void cxl_enable_isolation_interrupts (struct cxl_dport *dport) +{ +u32 ctrl; + + ctrl =readl (dport->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); + ctrl |=CXL_ISOLATION_CTRL_MEM_INTR_ENABLE ; +writel (ctrl, dport->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); + +dev_dbg (dport->dport_dev,"Enabled CXL isolation interrupts\n" ); +} + +void cxl_disable_isolation_interrupts (struct cxl_dport *dport) +{ +u32 ctrl; + + ctrl =readl (dport->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); + ctrl &= ~CXL_ISOLATION_CTRL_MEM_INTR_ENABLE ; +writel (ctrl, dport->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); + +dev_dbg (dport->dport_dev,"Disabled CXL isolation interrupts\n" ); +} +void cxl_enable_isolation (struct cxl_dport *dport) {u32 ctrl;
drivers/cxl/core/port.c +9 -1
@@ -1236,6 +1236,9 @@ static void cxl_dport_free_interrupts(void *data)struct cxl_dport *dport = data;struct pci_dev *pdev =to_pci_dev (dport->dport_dev); +if (dport->regs.isolation) +cxl_disable_isolation_interrupts (dport); + info =pcie_cxl_dport_get_isolation_info (pdev);if (!info)return ;
@@ -1272,7 +1275,12 @@ static int cxl_dport_setup_interrupts(struct device *host,if (rc)return rc; -return devm_add_action_or_reset (host, cxl_dport_free_interrupts, dport); + rc =devm_add_action_or_reset (host, cxl_dport_free_interrupts, dport); +if (rc) +return rc; + +cxl_enable_isolation_interrupts (dport); +return 0 ; }/**
drivers/cxl/cxl.h +1 -0
@@ -141,6 +141,7 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)#define CXL_ISOLATION_CAP_INTR_MASK GENMASK(31, 27)#define CXL_ISOLATION_CTRL_OFFSET 0x8#define CXL_ISOLATION_CTRL_MEM_ISO_ENABLE BIT(16) +#define CXL_ISOLATION_CTRL_MEM_INTR_ENABLE BIT(26)#define CXL_ISOLATION_STATUS_OFFSET 0xC#define CXL_ISOLATION_STAT_MEM_ISO BIT(8)#define CXL_ISOLATION_STAT_LNK_DOWN BIT(9)
Signature · 1 line
2.34.1
PATCH 9/16 cxl/core: Prevent onlining CXL memory behind isolated ports
In reply to Ben CheathamThe host will not be able to access the CXL memory on devices enabled/added below an isolated CXL downstream port. Add a check during cxl_mem probe to prevent adding devices below an isolated port. Also add a check to prevent CXL region creation below an isolated port for previously disabled devices below the port.
--- drivers/cxl/core/port.c | 28 ++++++++++++++++++++++++++++ drivers/cxl/core/region.c | 3 +++ drivers/cxl/cxl.h | 2 ++ 3 files changed, 33 insertions(+)
drivers/cxl/core/port.c +28 -0
@@ -869,6 +869,13 @@ static int cxl_port_add(struct cxl_port *port,*/ port->reg_map = cxlds->reg_map; port->reg_map.host = &port->dev; + +if (cxl_endpoint_port_isolated (port)) { +dev_err (&port->dev, +"port is under isolated CXL dport\n" ); +return -EBUSY ; + } + cxlmd->endpoint = port; }else if (parent_dport) { rc =dev_set_name (dev,"port%d" , port->id);
@@ -1174,6 +1181,27 @@ static void cxl_dport_unlink(void *data)sysfs_remove_link (&port->dev.kobj, link_name); } +bool cxl_endpoint_port_isolated (struct cxl_port *ep) +{ +struct cxl_dport *iter; +u32 status; + +for (iter = ep->parent_dport; + iter && iter->port && !is_cxl_root (iter->port); + iter = iter->port->parent_dport) { +if (!iter->regs.isolation) +continue ; + + status =readl (iter->regs.isolation + +CXL_ISOLATION_STATUS_OFFSET ); +if (!(status &CXL_ISOLATION_STATUS_OFFSET )) +return true; + } + +return false; +} +EXPORT_SYMBOL_NS_GPL (cxl_endpoint_port_isolated,"CXL" ); +struct isolation_intr_data {struct cxl_dport *dport;struct cxl_port *port;
drivers/cxl/core/region.c +3 -0
@@ -3407,6 +3407,9 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,int rc, part =READ_ONCE (cxled->part);struct cxl_region *cxlr; +if (cxl_endpoint_port_isolated (cxlmd->endpoint)) +return ERR_PTR (-EBUSY ); + do { cxlr = __create_region(cxlrd, cxlds->part[part].mode, atomic_read(&cxlrd->region_id));
drivers/cxl/cxl.h +2 -0
@@ -838,6 +838,8 @@ pci_ers_result_t cxl_error_detected(struct device *dev);void cxl_port_cor_error_detected (struct device *dev);pci_ers_result_t cxl_port_error_detected (struct device *dev); +bool cxl_endpoint_port_isolated (struct cxl_port *port); +/** * struct cxl_endpoint_dvsec_info - Cached DVSEC info * @mem_enabled: cached value of mem_enabled in the DVSEC at init time
Signature · 1 line
2.34.1
PATCH 10/16 cxl/core: Enable CXL.mem timeout
In reply to Ben CheathamAdd functions to enable and disable CXL.mem transaction timeout. Enable timeout as part of CXL isolation set up.
--- drivers/cxl/core/pci.c | 22 ++++++++++++++++++++++ drivers/cxl/core/port.c | 14 +++++++++----- drivers/cxl/cxl.h | 4 ++++ include/cxl/isolation.h | 5 +++++ 4 files changed, 40 insertions(+), 5 deletions(-)
drivers/cxl/core/pci.c +22 -0
@@ -1237,3 +1237,25 @@ int cxl_disable_isolation(struct cxl_dport *dport)dev_dbg (dport->dport_dev,"Disabled CXL.mem isolation\n" );return 0 ; } + +void cxl_enable_timeout (struct cxl_dport *dport) +{ +u32 ctrl; + + ctrl =readl (dport->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); + ctrl |=CXL_ISOLATION_CTRL_MEM_TIME_ENABLE ; +writel (ctrl, dport->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); + +dev_dbg (dport->dport_dev,"Enabled CXL.mem transaction timeout\n" ); +} + +void cxl_disable_timeout (struct cxl_dport *dport) +{ +u32 ctrl; + + ctrl =readl (dport->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); + ctrl &= ~CXL_ISOLATION_CTRL_MEM_TIME_ENABLE ; +writel (ctrl, dport->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); + +dev_dbg (dport->dport_dev,"Disabled CXL.mem transaction timeout\n" ); +}
drivers/cxl/core/port.c +9 -5
@@ -1312,15 +1312,15 @@ static int cxl_dport_setup_interrupts(struct device *host, }/** -* cxl_dport_enable_isolation - Enable CXL Isolation for a CXL dport. This is -* an optional capability only supported by PCIe Root Ports. +* cxl_dport_enable_timeout_isolation - Enable CXL Isolation for a CXL dport. +* This is an optional capability only supported by PCIe Root Ports. * @host: Host device for @dport * @dport: CXL-capable PCIe Root Port * * Returns 0 if capability unsupported, or when enabled. */ -static int cxl_dport_enable_isolation (struct device *host, -struct cxl_dport *dport) +static int cxl_dport_enable_timeout_isolation (struct device *host, +struct cxl_dport *dport) {u32 cap;int rc;
@@ -1342,6 +1342,10 @@ static int cxl_dport_enable_isolation(struct device *host,return rc == -ENXIO ?0 : rc;cxl_enable_isolation (dport); + +if (!(cap &CXL_ISOLATION_CAP_MEM_TIME_SUPP )) +cxl_enable_timeout (dport); +return 0 ; }
@@ -1408,7 +1412,7 @@ __devm_cxl_add_dport(struct cxl_port *port, struct device *dport_dev, &component_reg_phys);if (IS_ENABLED (CONFIG_CXL_ISOLATION )) { - rc =cxl_dport_enable_isolation (host, dport); + rc =cxl_dport_enable_timeout_isolation (host, dport);if (rc)return ERR_PTR (rc); }
drivers/cxl/cxl.h +4 -0
@@ -136,10 +136,14 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)/* CXL 3.2 8.2.4.24 CXL Timeout and Isolation Capability Structure */ #define CXL_ISOLATION_CAPABILITY_OFFSET 0x0 +#define CXL_ISOLATION_CAP_MEM_TIME_MASK GENMASK(3, 0) +#define CXL_ISOLATION_CAP_MEM_TIME_SUPP BIT(4)#define CXL_ISOLATION_CAP_MEM_ISO_SUPP BIT(16)#define CXL_ISOLATION_CAP_INTR_SUPP BIT(26)#define CXL_ISOLATION_CAP_INTR_MASK GENMASK(31, 27)#define CXL_ISOLATION_CTRL_OFFSET 0x8 +#define CXL_ISOLATION_CTRL_MEM_TIME_MASK GENMASK(3, 0) +#define CXL_ISOLATION_CTRL_MEM_TIME_ENABLE BIT(4)#define CXL_ISOLATION_CTRL_MEM_ISO_ENABLE BIT(16)#define CXL_ISOLATION_CTRL_MEM_INTR_ENABLE BIT(26)#define CXL_ISOLATION_STATUS_OFFSET 0xC
include/cxl/isolation.h +5 -0
@@ -28,10 +28,15 @@ struct cxl_dport;#if IS_ENABLED (CONFIG_CXL_BUS )void cxl_enable_isolation (struct cxl_dport *dport);int cxl_disable_isolation (struct cxl_dport *dport); +void cxl_enable_timeout (struct cxl_dport *dport); +void cxl_disable_timeout (struct cxl_dport *dport); +#else /* !CONFIG_CXL_BUS */ static inline void cxl_enable_isolation (struct cxl_dport *dport) {}static inline int cxl_disable_isolation (struct cxl_dport *dport) {return -ENXIO ; } +static inline void cxl_enable_timeout (struct cxl_dport *dport) {} +static inline void cxl_disable_timeout (struct cxl_dport *dport) {}#endif /* !CONFIG_CXL_BUS */ #ifdef CONFIG_CXL_ISOLATION
Signature · 1 line
2.34.1
PATCH 11/16 cxl/pci: Add isolation handler
In reply to Ben CheathamAdd an error isolation handler for type 3 CXL devices. The current behavior is to log any AER information and then panic.
--- drivers/cxl/pci.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/cxl/pci.c +9 -0
@@ -900,6 +900,13 @@ static struct attribute_group cxl_rcd_group = { };__ATTRIBUTE_GROUPS (cxl_rcd); +static enum cxl_err_results +cxl_pci_isolation_handler (struct cxl_dev_state *cxlds,bool lnk_down) +{ +cxl_error_detected (cxlds->dev); +return CXL_ERR_PANIC ; +} +static int cxl_pci_probe (struct pci_dev *pdev,const struct pci_device_id *id) {struct pci_host_bridge *host_bridge =pci_find_host_bridge (pdev->bus);
@@ -1006,6 +1013,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" ); + cxlds->isolation_handler = cxl_pci_isolation_handler; + cxlmd =devm_cxl_add_memdev (&pdev->dev, cxlds);if (IS_ERR (cxlmd))return PTR_ERR (cxlmd);
Signature · 1 line
2.34.1
PATCH 12/16 PCI: PCIe portdrv: Add cxl_isolation sysfs attributes
In reply to Ben CheathamAdd sysfs attributes to enable/disable CXL isolation and transaction timeout. The intended use for these attributes is to disable isolation and/or timeout as part of device maintenance or hotplug.
The attributes are added under a new "cxl_isolation" group on the PCIe Root Port device.
--- drivers/cxl/core/port.c | 29 ++++++ drivers/pci/pci-sysfs.c | 3 + drivers/pci/pci.h | 4 + drivers/pci/pcie/cxl_isolation.c | 158 +++++++++++++++++++++++++++++++ include/cxl/isolation.h | 8 ++ 5 files changed, 202 insertions(+)
drivers/cxl/core/port.c +29 -0
@@ -1346,6 +1346,7 @@ static int cxl_dport_enable_timeout_isolation(struct device *host,if (!(cap &CXL_ISOLATION_CAP_MEM_TIME_SUPP ))cxl_enable_timeout (dport); +pcie_update_cxl_isolation_group (dport->dport_dev);return 0 ; }
@@ -1598,6 +1599,34 @@ struct cxl_port *find_cxl_port(struct device *dport_dev,return port; } +/** +* cxl_find_pcie_rp - Find CXL port that contains a CXL-capable PCIe Root Port +* @dport_dev: CXL-capable PCIe Root Port device +* @rp: Pointer to store found dport in +* +* Returns CXL port with elevated reference count if @dport_dev is found +*/ +struct cxl_port *cxl_find_pcie_rp (struct pci_dev *dport_dev, +struct cxl_dport **rp) +{ +struct cxl_dport *dport; +struct cxl_port *parent; + + struct cxl_port *hb __free(put_cxl_port) = +find_cxl_port (&dport_dev->dev, &dport); +if (!hb || !dport) +return NULL ; + + parent =parent_port_of (hb); +if (!parent || !is_cxl_root (parent)) +return NULL ; + +if (rp) + *rp = dport; + +return_ptr (hb); +} +static struct cxl_port *find_cxl_port_at (struct cxl_port *parent_port,struct device *dport_dev,struct cxl_dport **dport)
drivers/pci/pci-sysfs.c +3 -0
@@ -1815,6 +1815,9 @@ const struct attribute_group *pci_dev_attr_groups[] = {#endif #ifdef CONFIG_PCI_DOE &pci_doe_sysfs_group, +#endif +#ifdef CONFIG_CXL_ISOLATION + &cxl_isolation_attr_group, #endif NULL, };
drivers/pci/pci.h +4 -0
@@ -677,6 +677,10 @@ static inline void pci_rcec_exit(struct pci_dev *dev) { }static inline void pcie_link_rcec (struct pci_dev *rcec) { }#endif +#ifdef CONFIG_CXL_ISOLATION +extern struct attribute_group cxl_isolation_attr_group; +#endif +#ifdef CONFIG_PCI_ATS /* Address Translation Service */ void pci_ats_init (struct pci_dev *dev);
drivers/pci/pcie/cxl_isolation.c +158 -0
164 lines not on this page · raw message
include/cxl/isolation.h +8 -0
@@ -31,21 +31,29 @@ int cxl_disable_isolation(struct cxl_dport *dport);void cxl_enable_timeout (struct cxl_dport *dport);void cxl_disable_timeout (struct cxl_dport *dport); +struct cxl_port *cxl_find_pcie_rp (struct pci_dev *pdev, +struct cxl_dport **dport);#else /* !CONFIG_CXL_BUS */ static inline void cxl_enable_isolation (struct cxl_dport *dport) {}static inline int cxl_disable_isolation (struct cxl_dport *dport) {return -ENXIO ; }static inline void cxl_enable_timeout (struct cxl_dport *dport) {}static inline void cxl_disable_timeout (struct cxl_dport *dport) {} + +static inline struct cxl_port *cxl_find_pcie_rp (struct pci_dev *pdev, +struct cxl_dport **dport); +{return NULL ; }#endif /* !CONFIG_CXL_BUS */ #ifdef CONFIG_CXL_ISOLATION struct cxl_isolation_info *pcie_cxl_dport_get_isolation_info (struct pci_dev *dport_dev); +void pcie_update_cxl_isolation_group (struct device *dport_dev);#else /* !CONFIG_CXL_ISOLATION */ static inline struct cxl_isolation_info *pcie_cxl_dport_get_isolation_info (struct pci_dev *dport_dev) {return NULL ; } +static inline void pcie_update_cxl_isolation_group (struct device *dport_dev) {}#endif /* !CONFIG_CXL_ISOLATION */ #endif
Signature · 1 line
2.34.1
Re: [PATCH 12/16] PCI: PCIe portdrv: Add cxl_isolation sysfs attributes
Quoted 8 lines · On Wed, 30 Jul 2025 16:47:14 -0500 Ben Cheatham <[email protected]>…
Add sysfs attributes to enable/disable CXL isolation and transaction timeout. The intended use for these attributes is to disable isolation and/or timeout as part of device maintenance or hotplug.
The attributes are added under a new "
cxl_isolation" group on the PCIe Root Port device.Signed-off-by Ben Cheatham <[email protected]>
Comments below apply in quite a few of these functions, I just picked one example to talk about.
Thanks,
Jonathan
Quoted 10 lines
drivers/pci/pcie/cxl_isolation.c +3
-0+static ssize_t timeout_ctrl_show (struct device *dev, +struct device_attribute *attr,char *buf) +{
drivers/pci/pcie/cxl_isolation.c pcie_cxl_dport_get_isolation_info(struct pci_dev *dport_dev) · line 181
Quoted 10 lines
drivers/pci/pcie/cxl_isolation.c +10
-0+struct pci_dev *pdev =to_pci_dev (dev); +struct cxl_port *port; +u32 ctrl; + + struct cxl_dport **dport __free(kfree) = +kzalloc (sizeof (*dport),GFP_KERNEL ); +if (!dport) +return -ENOMEM ; + + port =cxl_find_pcie_rp (pdev, dport);
struct cxl_port *port __free(put_cxl_port) = cxl_find_pcie_rp();
Same for other cases above.
drivers/pci/pcie/cxl_isolation.c
Quoted 1 line
drivers/pci/pcie/cxl_isolation.c +1
-0+if (!port || !(*dport))
leaks device reference if port is set and dport isn't.
drivers/pci/pcie/cxl_isolation.c pcie_cxl_dport_get_isolation_info(struct pci_dev *dport_dev) · line 127
Quoted 3 lines
drivers/pci/pcie/cxl_isolation.c +3
-0+return -ENODEV ; + +if (!(*dport)->regs.isolation)
leaks device reference.
drivers/pci/pcie/cxl_isolation.c pcie_cxl_dport_get_isolation_info(struct pci_dev *dport_dev) · line 131
Quoted 4 lines
drivers/pci/pcie/cxl_isolation.c +4
-0+return -ENXIO ; + + ctrl =readl ((*dport)->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); +put_device (&port->dev);
and no need to do this by hand.
drivers/pci/pcie/cxl_isolation.c pcie_cxl_dport_get_isolation_info(struct pci_dev *dport_dev) · line 199
Quoted 10 lines
drivers/pci/pcie/cxl_isolation.c +10
-0+ +return sysfs_emit (buf,"%lu\n" , +FIELD_GET (CXL_ISOLATION_CTRL_MEM_TIME_ENABLE , ctrl)); +} +DEVICE_ATTR_RW (timeout_ctrl); + +static struct attribute *isolation_attrs[] = { + &dev_attr_timeout_ctrl.attr, + &dev_attr_isolation_ctrl.attr, +NULL ,
My favorite trivial comment :) No need for that trailing comma.
Quoted 1 line
+};
Re: [PATCH 12/16] PCI: PCIe portdrv: Add cxl_isolation sysfs attributes
Quoted 40 lines · Jonathan Cameron
Quoted 8 lines · On Wed, 30 Jul 2025 16:47:14 -0500 Ben Cheatham <[email protected]>…
Add sysfs attributes to enable/disable CXL isolation and transaction timeout. The intended use for these attributes is to disable isolation and/or timeout as part of device maintenance or hotplug.
The attributes are added under a new "
cxl_isolation" group on the PCIe Root Port device.Signed-off-by Ben Cheatham <[email protected]>Comments below apply in quite a few of these functions, I just picked one example to talk about.
Thanks,
Jonathan
Quoted 10 lines
drivers/pci/pcie/cxl_isolation.c +3
-0+static ssize_t timeout_ctrl_show (struct device *dev, +struct device_attribute *attr,char *buf) +{drivers/pci/pcie/cxl_isolation.c pcie_cxl_dport_get_isolation_info(struct pci_dev *dport_dev) · line 181
Quoted 10 lines
drivers/pci/pcie/cxl_isolation.c +10
-0+struct pci_dev *pdev =to_pci_dev (dev); +struct cxl_port *port; +u32 ctrl; + + struct cxl_dport **dport __free(kfree) = +kzalloc (sizeof (*dport),GFP_KERNEL ); +if (!dport) +return -ENOMEM ; + + port =cxl_find_pcie_rp (pdev, dport);struct cxl_port *port __free(put_cxl_port) = cxl_find_pcie_rp();
Quoted 1 line
Same for other cases above.
I realized I could use __free() for device references when implementing Bjorn's suggested changes, so my local version already has this for these funcitons (and next patch).
Quoted 17 lines
drivers/pci/pcie/cxl_isolation.c
Quoted 3 lines
drivers/pci/pcie/cxl_isolation.c +1
-0+if (!port || !(*dport))leaks device reference if port is set and dport isn't.
drivers/pci/pcie/cxl_isolation.c pcie_cxl_dport_get_isolation_info(struct pci_dev *dport_dev) · line 127
Quoted 3 lines
drivers/pci/pcie/cxl_isolation.c +3
-0+return -ENODEV ; + +if (!(*dport)->regs.isolation)leaks device reference.
drivers/pci/pcie/cxl_isolation.c pcie_cxl_dport_get_isolation_info(struct pci_dev *dport_dev) · line 131
Quoted 4 lines
drivers/pci/pcie/cxl_isolation.c +4
-0+return -ENXIO ; + + ctrl =readl ((*dport)->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); +put_device (&port->dev);and no need to do this by hand.
Quoted 11 lines
drivers/pci/pcie/cxl_isolation.c pcie_cxl_dport_get_isolation_info(struct pci_dev *dport_dev) · line 199
Quoted 10 lines
drivers/pci/pcie/cxl_isolation.c +10
-0+ +return sysfs_emit (buf,"%lu\n" , +FIELD_GET (CXL_ISOLATION_CTRL_MEM_TIME_ENABLE , ctrl)); +} +DEVICE_ATTR_RW (timeout_ctrl); + +static struct attribute *isolation_attrs[] = { + &dev_attr_timeout_ctrl.attr, + &dev_attr_isolation_ctrl.attr, +NULL ,My favorite trivial comment :) No need for that trailing comma.
Yep, I'm bad about that one. I'll remove it!
Quoted 4 lines
Quoted 1 line
+};
PATCH 13/16 cxl/core, PCI: PCIe portdrv: Add CXL timeout range programming
In reply to Ben CheathamAdd functions to enable programming the CXL.mem transaction timeout range, if supported. Add a sysfs attribute to the "cxl_isolation" group to allow programming the timeout from userspace.
The attribute can take either the CXL spec-defined hex value for the associated timeout range (CXL 3.2 8.2.4.24.2 field 3:0) or a string with the range. The range string is formatted as the range letter in uppercase or lowercase, with an optional "2" to specify the second range in the aforementioned spec ref.
For example, to program the port with a timeout of 65ms to 210ms (range B) the following strings could be specified: "b2"/"B2". Picking the first portion of range B (16ms to 55ms) would be: "b"/"B".
--- drivers/cxl/core/pci.c | 49 +++++++++++++++ drivers/pci/pcie/cxl_isolation.c | 102 +++++++++++++++++++++++++++++++ include/cxl/isolation.h | 3 + 3 files changed, 154 insertions(+)
drivers/cxl/core/pci.c +49 -0
@@ -1259,3 +1259,52 @@ void cxl_disable_timeout(struct cxl_dport *dport)dev_dbg (dport->dport_dev,"Disabled CXL.mem transaction timeout\n" ); } + +static bool timeout_range_supported (u32 cap,u32 val) +{ +u32 supported =FIELD_GET (CXL_ISOLATION_CAP_MEM_TIME_MASK , cap); + +if (!supported) +return false; + +/* CXL 3.2 8.2.4.24.1 field 3:0 */ +switch (val) { +/* Range A (default) */ +case 0x0 : +case 0x1 : +case 0x2 : +return (supported &BIT (0 )); +/* Range B */ +case 0x5 : +case 0x6 : +return (supported &BIT (1 )); +/* Range C */ +case 0x9 : +case 0xA : +return (supported &BIT (2 )); +case 0xD : +case 0xE : +/* Range D */ +return (supported &BIT (3 )); +default : +return false; + } +} + +int cxl_set_timeout_range (struct cxl_dport *dport,u8 val) +{ +u32 cap, ctrl; + + cap =readl (dport->regs.isolation +CXL_ISOLATION_CAPABILITY_OFFSET ); +if (!(cap &CXL_ISOLATION_CAP_MEM_TIME_SUPP )) +return -ENXIO ; + +if (!timeout_range_supported (cap, val)) +return -EINVAL ; + + ctrl =readl (dport->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); + ctrl &=FIELD_PREP (CXL_ISOLATION_CTRL_MEM_TIME_MASK ,0 ); + ctrl |=FIELD_PREP (CXL_ISOLATION_CTRL_MEM_TIME_MASK , val); +writel (ctrl, dport->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); +return 0 ; +}
drivers/pci/pcie/cxl_isolation.c +102 -0
111 lines not on this page · raw message
include/cxl/isolation.h +3 -0
@@ -30,6 +30,7 @@ void cxl_enable_isolation(struct cxl_dport *dport);int cxl_disable_isolation (struct cxl_dport *dport);void cxl_enable_timeout (struct cxl_dport *dport);void cxl_disable_timeout (struct cxl_dport *dport); +int cxl_set_timeout_range (struct cxl_dport *dport,u8 val);struct cxl_port *cxl_find_pcie_rp (struct pci_dev *pdev,struct cxl_dport **dport);
@@ -39,6 +40,8 @@ static inline int cxl_disable_isolation(struct cxl_dport *dport) {return -ENXIO ; }static inline void cxl_enable_timeout (struct cxl_dport *dport) {}static inline void cxl_disable_timeout (struct cxl_dport *dport) {} +static inline int cxl_set_timeout_range (struct cxl_dport *dport,u8 val) +{return -ENXIO ; }static inline struct cxl_port *cxl_find_pcie_rp (struct pci_dev *pdev,struct cxl_dport **dport);
Signature · 1 line
2.34.1
Re: [PATCH 13/16] cxl/core, PCI: PCIe portdrv: Add CXL timeout range programming
Drop a few of the subject line prefixes and mention something about sysfs. This has nothing to do with portdrv. Following sibling "port service drivers," I guess the prefix would be something like "PCI/CXL:" or "PCI/CXL_ISO:"
Quoted 3 lines · Ben Cheatham
Add functions to enable programming the CXL.mem transaction timeout range, if supported. Add a sysfs attribute to the "
cxl_isolation" group to allow programming the timeout from userspace.
Include a sample path with at least the last 2-3 components. Maybe even an example, e.g.,
# echo B2 > /sys/.../cxl_isolation/timeout_range
Probably also some doc in Documentation/ABI/testing/?
Quoted 9 lines
The attribute can take either the CXL spec-defined hex value for the associated timeout range (CXL 3.2 8.2.4.24.2 field 3:0) or a string with the range. The range string is formatted as the range letter in uppercase or lowercase, with an optional "2" to specify the second range in the aforementioned spec ref.
For example, to program the port with a timeout of 65ms to 210ms (range B) the following strings could be specified: "b2"/"B2". Picking the first portion of range B (16ms to 55ms) would be: "b"/"B".
What's the value of accepting either upper- or lower-case? It doubles the size of ranges[], and I think timeout_range_show() always shows the lower-case one. The spec uses upper-case.
Quoted 132 lines
drivers/pci/pcie/cxl_isolation.c +102
-0+/* CXL 3.2 8.2.4.24.2 CXL Timeout & Isolation Control Register, field 3:0 */ +const struct timeout_ranges { +char *str; +u8 val; +} ranges[] = { + { .str ="a" , .val =0x1 }, + { .str ="A" , .val =0x1 }, + { .str ="a2" , .val =0x2 }, + { .str ="A2" , .val =0x2 }, + { .str ="b" , .val =0x5 }, + { .str ="B" , .val =0x5 }, + { .str ="b2" , .val =0x6 }, + { .str ="B2" , .val =0x6 }, + { .str ="c" , .val =0x9 }, + { .str ="C" , .val =0x9 }, + { .str ="c2" , .val =0xA }, + { .str ="C2" , .val =0xA }, + { .str ="d" , .val =0xD }, + { .str ="D" , .val =0xD }, + { .str ="d2" , .val =0xE }, + { .str ="D2" , .val =0xE }, +}; + +static int timeout_range_str_to_val (const char *str,u8 *val) +{ +char val_buf[32 ] = {0 }; +char *start; + +strscpy (val_buf, str,ARRAY_SIZE (val_buf) -1 ); + start =strim (val_buf); +if (!start) +return -EINVAL ; + +for (int i =0 ; i <ARRAY_SIZE (ranges); i++) +if (strcmp (start, ranges[i].str) ==0 ) +return ranges[i].val; + +return -EINVAL ; +} + +static ssize_t timeout_range_store (struct device *dev, +struct device_attribute *attr, +const char *buf,size_t n) +{ +struct pci_dev *pdev =to_pci_dev (dev); +struct cxl_port *port; +u8 val; +int rc; + + rc =kstrtou8 (buf,0 , &val); +if (rc &&timeout_range_str_to_val (buf, &val) <0 ) +return -EINVAL ; + + struct cxl_dport **dport __free(kfree) = +kzalloc (sizeof (*dport),GFP_KERNEL ); +if (!dport) +return -ENOMEM ; + + port =cxl_find_pcie_rp (pdev, dport); +if (!port || !(*dport)) +return -ENODEV ; + +if (!(*dport)->regs.isolation) +return -ENXIO ; + + rc =cxl_set_timeout_range (*dport, val); +put_device (&port->dev); +return rc ? rc : n; +} + +static ssize_t timeout_range_show (struct device *dev, +struct device_attribute *attr,char * buf) +{ +struct pci_dev *pdev =to_pci_dev (dev); +struct cxl_port *port; +u32 ctrl, val; + + struct cxl_dport **dport __free(kfree) = +kzalloc (sizeof (*dport),GFP_KERNEL ); +if (!dport) +return -ENOMEM ; + + port =cxl_find_pcie_rp (pdev, dport); +if (!port || !(*dport)) +return -ENODEV ; + +if (!(*dport)->regs.isolation) +return -ENXIO ; + + ctrl =readl ((*dport)->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); +put_device (&port->dev); + + val =FIELD_GET (CXL_ISOLATION_CTRL_MEM_TIME_MASK , ctrl); +for (int i =0 ; i <ARRAY_SIZE (ranges); i++) +if (ranges[i].val == val) +return sysfs_emit (buf,"%s\n" , ranges[i].str); + +return -ENXIO ; +} +DEVICE_ATTR_RW (timeout_range); +static struct attribute *isolation_attrs[] = { &dev_attr_timeout_ctrl.attr, &dev_attr_isolation_ctrl.attr, + &dev_attr_timeout_range.attr,NULL , };include/cxl/isolation.h +3
-0@@ -30,6 +30,7 @@ void cxl_enable_isolation(struct cxl_dport *dport);int cxl_disable_isolation (struct cxl_dport *dport);void cxl_enable_timeout (struct cxl_dport *dport);void cxl_disable_timeout (struct cxl_dport *dport); +int cxl_set_timeout_range (struct cxl_dport *dport,u8 val);struct cxl_port *cxl_find_pcie_rp (struct pci_dev *pdev,struct cxl_dport **dport);@@ -39,6 +40,8 @@ static inline int cxl_disable_isolation(struct cxl_dport *dport) {return -ENXIO ; }static inline void cxl_enable_timeout (struct cxl_dport *dport) {}static inline void cxl_disable_timeout (struct cxl_dport *dport) {} +static inline int cxl_set_timeout_range (struct cxl_dport *dport,u8 val) +{return -ENXIO ; }static inline struct cxl_port *cxl_find_pcie_rp (struct pci_dev *pdev,struct cxl_dport **dport);Signature · 1 line
2.34.1
Re: [PATCH 13/16] cxl/core, PCI: PCIe portdrv: Add CXL timeout range programming
Quoted 4 lines · Bjorn Helgaas
Drop a few of the subject line prefixes and mention something about sysfs. This has nothing to do with portdrv. Following sibling "port service drivers," I guess the prefix would be something like "PCI/CXL:" or "PCI/CXL_ISO:"
Will do.
Quoted 6 lines · Ben Cheatham
Quoted 3 lines
Add functions to enable programming the CXL.mem transaction timeout range, if supported. Add a sysfs attribute to the "
cxl_isolation" group to allow programming the timeout from userspace.
Quoted 6 lines
Include a sample path with at least the last 2-3 components. Maybe even an example, e.g.,
# echo B2 > /sys/.../cxl_isolation/timeout_rangeProbably also some doc in
Documentation/ABI/testing/?
I'll add it to the commit message and make an entry under Documentation.
Quoted 7 lines
Quoted 7 lines
The attribute can take either the CXL spec-defined hex value for the associated timeout range (CXL 3.2 8.2.4.24.2 field 3:0) or a string with the range. The range string is formatted as the range letter in uppercase or lowercase, with an optional "2" to specify the second range in the aforementioned spec ref.
Quoted 8 lines
Quoted 3 lines
For example, to program the port with a timeout of 65ms to 210ms (range B) the following strings could be specified: "b2"/"B2". Picking the first portion of range B (16ms to 55ms) would be: "b"/"B".
What's the value of accepting either upper- or lower-case? It doubles the size of ranges[], and I think
timeout_range_show()always shows the lower-case one. The spec uses upper-case.
Just ease of use. I'll restrict it to uppercase to match the spec (unless anyone has a strong opinion otherwise).
Thanks,
Ben
Re: [PATCH 13/16] cxl/core, PCI: PCIe portdrv: Add CXL timeout range programming
In reply to Ben CheathamQuoted 10 lines · On Wed, 30 Jul 2025 16:47:15 -0500 Ben Cheatham <[email protected]>…
Add functions to enable programming the CXL.mem transaction timeout range, if supported. Add a sysfs attribute to the "
cxl_isolation" group to allow programming the timeout from userspace.The attribute can take either the CXL spec-defined hex value for the associated timeout range (CXL 3.2 8.2.4.24.2 field 3:0) or a string with the range. The range string is formatted as the range letter in uppercase or lowercase, with an optional "2" to specify the second range in the aforementioned spec ref.
Quoted 5 lines
For example, to program the port with a timeout of 65ms to 210ms (range B) the following strings could be specified: "b2"/"B2". Picking the first portion of range B (16ms to 55ms) would be: "b"/"B".
Signed-off-by Ben Cheatham <[email protected]>
This needs some ABI Docs.
The spec is exceedingly weird, so working out a sensible way to present it to userspace will be a challenge. I vaguely recall the weird timing description is from some other spec. Any idea where and if there is existing ABI for that?
Quoted 12 lines
drivers/pci/pcie/cxl_isolation.c +7
-0+static ssize_t timeout_range_show (struct device *dev, +struct device_attribute *attr,char * buf) +{ +struct pci_dev *pdev =to_pci_dev (dev); +struct cxl_port *port; +u32 ctrl, val; +
drivers/pci/pcie/cxl_isolation.c static ssize_t timeout_ctrl_show(struct device *dev, · line 282
Quoted 10 lines
drivers/pci/pcie/cxl_isolation.c +10
-0+ struct cxl_dport **dport __free(kfree) = +kzalloc (sizeof (*dport),GFP_KERNEL ); +if (!dport) +return -ENOMEM ; + + port =cxl_find_pcie_rp (pdev, dport); +if (!port || !(*dport)) +return -ENODEV ; + +if (!(*dport)->regs.isolation)
Same issue with reference leak as in previous patch.
Quoted 13 lines
drivers/pci/pcie/cxl_isolation.c +13
-0+return -ENXIO ; + + ctrl =readl ((*dport)->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); +put_device (&port->dev); + + val =FIELD_GET (CXL_ISOLATION_CTRL_MEM_TIME_MASK , ctrl); +for (int i =0 ; i <ARRAY_SIZE (ranges); i++) +if (ranges[i].val == val) +return sysfs_emit (buf,"%s\n" , ranges[i].str); + +return -ENXIO ; +} +DEVICE_ATTR_RW (timeout_range);
Re: [PATCH 13/16] cxl/core, PCI: PCIe portdrv: Add CXL timeout range programming
Quoted 13 lines · Jonathan Cameron
Quoted 10 lines · On Wed, 30 Jul 2025 16:47:15 -0500 Ben Cheatham <[email protected]>…
Add functions to enable programming the CXL.mem transaction timeout range, if supported. Add a sysfs attribute to the "
cxl_isolation" group to allow programming the timeout from userspace.The attribute can take either the CXL spec-defined hex value for the associated timeout range (CXL 3.2 8.2.4.24.2 field 3:0) or a string with the range. The range string is formatted as the range letter in uppercase or lowercase, with an optional "2" to specify the second range in the aforementioned spec ref.
Quoted 7 lines
Quoted 5 lines
For example, to program the port with a timeout of 65ms to 210ms (range B) the following strings could be specified: "b2"/"B2". Picking the first portion of range B (16ms to 55ms) would be: "b"/"B".
Signed-off-by Ben Cheatham <[email protected]>This needs some ABI Docs.
Already done :).
Quoted 4 lines
The spec is exceedingly weird, so working out a sensible way to present it to userspace will be a challenge. I vaguely recall the weird timing description is from some other spec. Any idea where and if there is existing ABI for that?
I don't recall if it's based on another spec. My first version of this had some kind of translation for numbers -> range letters, but I figured it's overkill for something most people will probably leave at the default. I added a spec ref in the docs for where to find the timeout ranges, but I can probably just add the actual ranges in the doc.
Thanks,
Ben
Quoted 40 lines
Quoted 13 lines
drivers/pci/pcie/cxl_isolation.c +7
-0+static ssize_t timeout_range_show (struct device *dev, +struct device_attribute *attr,char * buf) +{ +struct pci_dev *pdev =to_pci_dev (dev); +struct cxl_port *port; +u32 ctrl, val; +drivers/pci/pcie/cxl_isolation.c static ssize_t timeout_ctrl_show(struct device *dev, · line 282
Quoted 10 lines
drivers/pci/pcie/cxl_isolation.c +10
-0+ struct cxl_dport **dport __free(kfree) = +kzalloc (sizeof (*dport),GFP_KERNEL ); +if (!dport) +return -ENOMEM ; + + port =cxl_find_pcie_rp (pdev, dport); +if (!port || !(*dport)) +return -ENODEV ; + +if (!(*dport)->regs.isolation)Same issue with reference leak as in previous patch.
Quoted 13 lines
drivers/pci/pcie/cxl_isolation.c +13
-0+return -ENXIO ; + + ctrl =readl ((*dport)->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); +put_device (&port->dev); + + val =FIELD_GET (CXL_ISOLATION_CTRL_MEM_TIME_MASK , ctrl); +for (int i =0 ; i <ARRAY_SIZE (ranges); i++) +if (ranges[i].val == val) +return sysfs_emit (buf,"%s\n" , ranges[i].str); + +return -ENXIO ; +} +DEVICE_ATTR_RW (timeout_range);
PATCH 14/16 ACPI: Add CXL isolation _OSC fields
In reply to Ben CheathamAdd CXL Timeout and Isolation _OSC support and control fields, as defined in the ECN at the link below. The ECN contents are expected to appear in the CXL 4.0 specification. The link is only accessible to CXL SSWG members, so a brief overview is provided here:
The ECN adds several fields to the CXL _OSC method (CXL 3.2 9.18.2) for the purpose of reserving CXL isolation features for the platform firmware's use. The fields introduced for kernel support reserve toggling the CXL.mem isolation enable bit in the isolation control register (CXL 3.2 8.2.4.24.2) and how the host is notified isolation has occurred.
These fields will be used by the CXL driver to enable CXL isolation according to the result of the handshake. Descriptions of these fields are included in the commit messages of the commits where they are used.
--- drivers/acpi/pci_root.c | 9 +++++++++ include/linux/acpi.h | 3 +++ 2 files changed, 12 insertions(+)
drivers/acpi/pci_root.c +9 -0
@@ -145,10 +145,13 @@ static struct pci_osc_bit_struct cxl_osc_support_bit[] = { { OSC_CXL_2_0_PORT_DEV_REG_ACCESS_SUPPORT, "CXL20PortDevRegAccess" }, { OSC_CXL_PROTOCOL_ERR_REPORTING_SUPPORT, "CXLProtocolErrorReporting" }, { OSC_CXL_NATIVE_HP_SUPPORT, "CXLNativeHotPlug" }, + { OSC_CXL_TIMEOUT_ISOLATION_SUPPORT, "CXLTimeoutIsolation" }, };static struct pci_osc_bit_struct cxl_osc_control_bit[] = { {OSC_CXL_ERROR_REPORTING_CONTROL ,"CXLMemErrorReporting" }, + {OSC_CXL_MEM_ISOLATION_CONTROL ,"CXLMemIsolation" }, + {OSC_CXL_ISOLATION_NOTIF_CONTROL ,"CXLIsolationNotifications" }, }; static void decode_osc_bits(struct acpi_pci_root *root, char *msg, u32 word,
@@ -493,6 +496,8 @@ static u32 calculate_cxl_support(void) support |=OSC_CXL_PROTOCOL_ERR_REPORTING_SUPPORT ;if (IS_ENABLED (CONFIG_HOTPLUG_PCI_PCIE )) support |=OSC_CXL_NATIVE_HP_SUPPORT ; +if (IS_ENABLED (CONFIG_CXL_ISOLATION )) + support |=OSC_CXL_TIMEOUT_ISOLATION_SUPPORT ;return support; }
@@ -535,6 +540,10 @@ static u32 calculate_cxl_control(void)if (IS_ENABLED (CONFIG_MEMORY_FAILURE )) control |=OSC_CXL_ERROR_REPORTING_CONTROL ; +if (IS_ENABLED (CONFIG_CXL_ISOLATION )) + control |= (OSC_CXL_MEM_ISOLATION_CONTROL | +OSC_CXL_ISOLATION_NOTIF_CONTROL ); +return control; }
include/linux/acpi.h +3 -0
@@ -626,9 +626,12 @@ extern u32 osc_sb_native_usb4_control;#define OSC_CXL_2_0_PORT_DEV_REG_ACCESS_SUPPORT 0x00000002#define OSC_CXL_PROTOCOL_ERR_REPORTING_SUPPORT 0x00000004#define OSC_CXL_NATIVE_HP_SUPPORT 0x00000008 +#define OSC_CXL_TIMEOUT_ISOLATION_SUPPORT 0x00000010/* CXL _OSC: Capabilities DWORD 5: Control Field */ #define OSC_CXL_ERROR_REPORTING_CONTROL 0x00000001 +#define OSC_CXL_MEM_ISOLATION_CONTROL 0x00000002 +#define OSC_CXL_ISOLATION_NOTIF_CONTROL 0x00000020static inline u32 acpi_osc_ctx_get_pci_control (struct acpi_osc_context *context) {
Signature · 1 line
2.34.1
Re: [PATCH 14/16] ACPI: Add CXL isolation _OSC fields
Quoted 13 lines · Ben Cheatham
Add CXL Timeout and Isolation
_OSCsupport and control fields, as defined in the ECN at the link below. The ECN contents are expected to appear in the CXL 4.0 specification. The link is only accessible to CXL SSWG members, so a brief overview is provided here:The ECN adds several fields to the CXL
_OSCmethod (CXL 3.2 9.18.2) for the purpose of reserving CXL isolation features for the platform firmware's use. The fields introduced for kernel support reserve toggling the CXL.mem isolation enable bit in the isolation control register (CXL 3.2 8.2.4.24.2) and how the host is notified isolation has occurred.
Quoted 6 lines
These fields will be used by the CXL driver to enable CXL isolation according to the result of the handshake. Descriptions of these fields are included in the commit messages of the commits where they are used.
In case you need this
Quoted 61 lines
--- drivers/acpi/pci_root.c | 9 +++++++++ include/linux/acpi.h | 3 +++ 2 files changed, 12 insertions(+)drivers/acpi/pci_root.c +9
-0@@ -145,10 +145,13 @@ static struct pci_osc_bit_struct cxl_osc_support_bit[] = { { OSC_CXL_2_0_PORT_DEV_REG_ACCESS_SUPPORT, "CXL20PortDevRegAccess" }, { OSC_CXL_PROTOCOL_ERR_REPORTING_SUPPORT, "CXLProtocolErrorReporting" }, { OSC_CXL_NATIVE_HP_SUPPORT, "CXLNativeHotPlug" }, + { OSC_CXL_TIMEOUT_ISOLATION_SUPPORT, "CXLTimeoutIsolation" }, };static struct pci_osc_bit_struct cxl_osc_control_bit[] = { {OSC_CXL_ERROR_REPORTING_CONTROL ,"CXLMemErrorReporting" }, + {OSC_CXL_MEM_ISOLATION_CONTROL ,"CXLMemIsolation" }, + {OSC_CXL_ISOLATION_NOTIF_CONTROL ,"CXLIsolationNotifications" }, }; static void decode_osc_bits(struct acpi_pci_root *root, char *msg, u32 word,@@ -493,6 +496,8 @@ static u32 calculate_cxl_support(void) support |=OSC_CXL_PROTOCOL_ERR_REPORTING_SUPPORT ;if (IS_ENABLED (CONFIG_HOTPLUG_PCI_PCIE )) support |=OSC_CXL_NATIVE_HP_SUPPORT ; +if (IS_ENABLED (CONFIG_CXL_ISOLATION )) + support |=OSC_CXL_TIMEOUT_ISOLATION_SUPPORT ;return support; }@@ -535,6 +540,10 @@ static u32 calculate_cxl_control(void)if (IS_ENABLED (CONFIG_MEMORY_FAILURE )) control |=OSC_CXL_ERROR_REPORTING_CONTROL ; +if (IS_ENABLED (CONFIG_CXL_ISOLATION )) + control |= (OSC_CXL_MEM_ISOLATION_CONTROL | +OSC_CXL_ISOLATION_NOTIF_CONTROL ); +return control; }include/linux/acpi.h +3
-1@@ -626,9 +626,12 @@ extern u32 osc_sb_native_usb4_control;#define OSC_CXL_2_0_PORT_DEV_REG_ACCESS_SUPPORT 0x00000002#define OSC_CXL_PROTOCOL_ERR_REPORTING_SUPPORT 0x00000004#define OSC_CXL_NATIVE_HP_SUPPORT 0x00000008 +#define OSC_CXL_TIMEOUT_ISOLATION_SUPPORT 0x00000010/* CXL _OSC: Capabilities DWORD 5: Control Field */ #define OSC_CXL_ERROR_REPORTING_CONTROL 0x00000001 +#define OSC_CXL_MEM_ISOLATION_CONTROL 0x00000002 +#define OSC_CXL_ISOLATION_NOTIF_CONTROL 0x00000020static inline u32 acpi_osc_ctx_get_pci_control (struct acpi_osc_context *context) { --
PATCH 15/16 cxl/core, cxl/acpi: Enable CXL isolation based on _OSC handshake
In reply to Ben CheathamEnable CXL isolation based on the result of _OSC handshake, if applicable. In the absence of a _OSC interpretation callback (i.e. platform is non-ACPI), assume that we have control of all features.
A link for the ECN (expected in CXL 4.0 spec) that introduces the relevant parts of the _OSC method (CXL 3.2 9.18.2) can be found below. spec). This link is only accesible to CXL SSWG members, so here's a brief overview:
The ECN introduces an _OSC field for controlling whether the OSPM can write to the CXL.mem Isolation Enable bit in the CXL isolation control register (CXL 3.2 8.2.4.24.2). If the firmware reserves control, the OSPM is expected to not modify the isolation enable bit when writing the register.
--- drivers/cxl/acpi.c | 24 ++++++++++++++++++++++++ drivers/cxl/core/port.c | 17 +++++++++++++++-- drivers/cxl/cxl.h | 5 +++++ include/cxl/isolation.h | 4 ++++ 4 files changed, 48 insertions(+), 2 deletions(-)
drivers/cxl/acpi.c +24 -0
@@ -8,6 +8,7 @@#include <linux/pci.h> #include <linux/node.h> #include <asm/div64.h> +#include <cxl/isolation.h> #include "cxlpci.h" #include "cxl.h"
@@ -367,9 +368,32 @@ static int cxl_acpi_setup_hostbridge_uport(struct cxl_root *cxl_root,return 0 ; } +static void decode_isolation_osc (struct cxl_port *hb,u32 iso_cap) +{ +bool err_corr =FIELD_GET (CXL_ISOLATION_CAP_ERR_COR_SUPP , iso_cap); +struct acpi_device *adev =ACPI_COMPANION (hb->uport_dev); +struct acpi_pci_root *pci_root; +u32 osc_ctrl; + +if (!adev) +return ; + + pci_root =acpi_pci_find_root (adev->handle); +if (!pci_root) +return ; + + osc_ctrl = pci_root->osc_ext_control_set; +if (osc_ctrl &OSC_CXL_MEM_ISOLATION_CONTROL ) + hb->isolation_caps |=CXL_ISOLATION_MEM_ENABLE ; + +if (!err_corr || (osc_ctrl &OSC_CXL_ISOLATION_NOTIF_CONTROL )) + hb->isolation_caps |=CXL_ISOLATION_INTERRUPTS ; +} +static const struct cxl_root_ops acpi_root_ops = { .qos_class = cxl_acpi_qos_class, .setup_hostbridge_uport = cxl_acpi_setup_hostbridge_uport, + .get_isolation_caps = decode_isolation_osc, };static void del_cxl_resource (struct resource *res)
drivers/cxl/core/port.c +15 -2
@@ -1322,7 +1322,8 @@ static int cxl_dport_setup_interrupts(struct device *host,static int cxl_dport_enable_timeout_isolation (struct device *host,struct cxl_dport *dport) { -u32 cap; +struct cxl_port *port = dport->port; +u32 cap, ctrl;int rc;if (!dport->reg_map.component_map.isolation.valid)
@@ -1337,11 +1338,23 @@ static int cxl_dport_enable_timeout_isolation(struct device *host,if (!(cap &CXL_ISOLATION_CAP_MEM_ISO_SUPP ))return 0 ; + struct cxl_root *root __free(put_cxl_root) = find_cxl_root(dport->port); +if (root && root->ops && root->ops->get_isolation_caps) + root->ops->get_isolation_caps (port, cap); +else + port->isolation_caps = ~0 ; + + ctrl =readl (dport->regs.isolation +CXL_ISOLATION_CTRL_OFFSET ); +if (!(port->isolation_caps &CXL_ISOLATION_MEM_ENABLE ) && + !(ctrl &CXL_ISOLATION_CTRL_MEM_ISO_ENABLE )) +return 0 ; + rc =cxl_dport_setup_interrupts (host, dport);if (rc)return rc == -ENXIO ?0 : rc; -cxl_enable_isolation (dport); +if (port->isolation_caps &CXL_ISOLATION_MEM_ENABLE ) +cxl_enable_isolation (dport);if (!(cap &CXL_ISOLATION_CAP_MEM_TIME_SUPP ))cxl_enable_timeout (dport);
drivers/cxl/cxl.h +5 -0
@@ -139,6 +139,7 @@ static inline int ways_to_eiw(unsigned int ways, u8 *eiw)#define CXL_ISOLATION_CAP_MEM_TIME_MASK GENMASK(3, 0)#define CXL_ISOLATION_CAP_MEM_TIME_SUPP BIT(4)#define CXL_ISOLATION_CAP_MEM_ISO_SUPP BIT(16) +#define CXL_ISOLATION_CAP_ERR_COR_SUPP BIT(25)#define CXL_ISOLATION_CAP_INTR_SUPP BIT(26)#define CXL_ISOLATION_CAP_INTR_MASK GENMASK(31, 27)#define CXL_ISOLATION_CTRL_OFFSET 0x8
@@ -629,6 +630,7 @@ struct cxl_dax_region {* @cdat: Cached CDAT data * @cdat_available: Should a CDAT attribute be available in sysfs * @pci_latency: Upstream latency in picoseconds +* @isolation_caps: Isolation capabilities given by platform firmware */ struct cxl_port {struct device dev;
@@ -654,6 +656,7 @@ struct cxl_port { } cdat;bool cdat_available;long pci_latency; +u32 isolation_caps; };/**
@@ -679,6 +682,8 @@ struct cxl_root_ops { int *qos_class);int (*setup_hostbridge_uport)(struct cxl_root *cxl_root,struct device *bridge_dev); +void (*get_isolation_caps)(struct cxl_port *hb, +u32 iso_cap); }; static inline struct cxl_dport *
include/cxl/isolation.h +4 -0
@@ -4,6 +4,10 @@#include <linux/pci.h> +/* CXL Isolation capabilities we have control over */ +#define CXL_ISOLATION_MEM_ENABLE BIT(0) +#define CXL_ISOLATION_INTERRUPTS BIT(1) +/** * enum cxl_err_results - Possible results of an CXL isolation handler * @CXL_ERR_NONE: Device can recover without CXL core intervention
Signature · 1 line
2.34.1
PATCH 16/16 cxl/core, cxl/acpi: Add CXL isolation notify handler
In reply to Ben CheathamInstall ACPI 0x80 notify handler for CXL isolation, based on the result of the _OSC negotiation. The handler is once installed per CXL host bridge (HID of "ACPI0016") as part of isolation set up.
A link for the ECN (expected in CXL 4.0 spec) that introduces the relevant parts of the _OSC method (CXL 3.2 9.18.2) can be found below. spec). This link is only accesible to CXL SSWG members, so here's a brief overview:
The ECN introduces a field in the _OSC method to control how the OSPM is notified isolation has occurred. If the ERR_COR Signaling Supported bit in the isolation capability register (CXL 3.2 8.2.4.24.1) is NOT set, this portion of the _OSC can be ignored.
If the OSPM is given control of isolation notification, the mechanism to be used when isolation occurs is an MSI/-X interrupt (pre-ECN behavior). If the platorm firmware reserves control, the OSPM will be notified through a ACPI 0x80 notify on the CXL host bridge ACPI device (ACPI HID:
"ACPI0016").
--- drivers/cxl/acpi.c | 51 +++++++++++++++++++++++++++++++++++++++++ drivers/cxl/core/port.c | 41 +++++++++++++++++++++++++-------- drivers/cxl/cxl.h | 3 +++ 3 files changed, 86 insertions(+), 9 deletions(-)
drivers/cxl/acpi.c +51 -0
@@ -390,10 +390,61 @@ static void decode_isolation_osc(struct cxl_port *hb, u32 iso_cap) hb->isolation_caps |=CXL_ISOLATION_INTERRUPTS ; } +static void isolation_notify_handler (acpi_handle handle,u32 event,void *data) +{ +struct cxl_port *hb = data; +struct cxl_dport *dport; +unsigned long index; + +guard (device)(&hb->dev); +xa_for_each (&hb->dports, index, dport) { +if (dport->regs.isolation) +cxl_isolation_interrupt_handler (dport); + } +} + +static void cxl_remove_iso_handler (void *data) +{ +acpi_handle handle = data; + +acpi_remove_notify_handler (handle,ACPI_DEVICE_NOTIFY , + isolation_notify_handler); +} + +static int cxl_register_iso_handler (struct cxl_port *hb) +{ +struct acpi_device *adev =ACPI_COMPANION (hb->uport_dev); +acpi_handle handle; +int rc; + +if (!adev) +return -EINVAL ; + + handle =acpi_device_handle (adev); + +guard (device)(&hb->dev); +if (devm_is_action_added (&hb->dev, cxl_remove_iso_handler, handle)) +return 0 ; + + rc =acpi_install_notify_handler (handle,ACPI_DEVICE_NOTIFY , + isolation_notify_handler, hb); +if (rc !=AE_OK ) +return -ENXIO ; + + rc =devm_add_action_or_reset (&hb->dev, cxl_remove_iso_handler, + handle); +if (rc) +return rc; + +dev_dbg (&hb->dev,"Installed CXL isolation notify handler\n" ); +return 0 ; +} +static const struct cxl_root_ops acpi_root_ops = { .qos_class = cxl_acpi_qos_class, .setup_hostbridge_uport = cxl_acpi_setup_hostbridge_uport, .get_isolation_caps = decode_isolation_osc, + .register_hb_isolation_handler = cxl_register_iso_handler, };static void del_cxl_resource (struct resource *res)
drivers/cxl/core/port.c +32 -9
73 lines not on this page · raw message
drivers/cxl/cxl.h +3 -0
@@ -684,8 +684,11 @@ struct cxl_root_ops { struct device *bridge_dev);void (*get_isolation_caps)(struct cxl_port *hb,u32 iso_cap); +int (*register_hb_isolation_handler)(struct cxl_port *hb); }; +int cxl_isolation_interrupt_handler (struct cxl_dport *dport); +static inline struct cxl_dport *cxl_find_dport_by_dev (struct cxl_port *port,const struct device *dport_dev) {
Signature · 1 line
2.34.1