Skip to contentSkip to conversation

cxl: fixes for hot-removal of devices

PATCH New Joshua Lant 1 participant 3 messages May 20

lore
Share & tools
lore
#0 lore raw

cover cxl: fixes for hot-removal of devices

As requested from the discussion in:
https://lore.kernel.org/linux-cxl/[email protected]/T/#t

Two bugs have been found when testing cxl topologies for managed hot-remove of a device:

Patch 1 properly unmaps the backend memory device, allowing it to be remapped if the removed device is re-added.

Patch 2 sets the power controller present capability in the downstream port. This is required to notify the device from the guest of removal.

Modifications from linked RFC (patches 3 & 4):

- Originally patch 3 (1 here) unmaps only on exit. It should also unmap in the error goto in the realize function.
- "Fixes:" tags added to commit messages.

Joshua Lant (2):
cxl-type3: Properly unmap the memory-backend on device exit
cxl_downstream: enable power controller present capability.

 hw/mem/cxl_type3.c             | 6 ++++++
 hw/pci-bridge/cxl_downstream.c | 2 ++
 2 files changed, 8 insertions(+)
Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/2 cxl-type3: Properly unmap the memory-backend on device exit

Currently the memory backend remains mapped, meaning that if the device owning the backend is hot-removed, it cannot be readded in the same QEMU instance.

Fixes 5fcc499ee34 ("mem/cxl_type3: Add read and write functions for associated hostmem.")
---
 hw/mem/cxl_type3.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/mem/cxl_type3.c +6 -0
index 4739239da3..105526edd4 100644
@@ -1049,12 +1049,15 @@ err_free_special_ops:
     g_free(regs->special_ops);
     if (ct3d->dc.host_dc) {
         cxl_destroy_dc_regions(ct3d);
+        host_memory_backend_set_mapped(ct3d->dc.host_dc, false);
         address_space_destroy(&ct3d->dc.host_dc_as);
     }
     if (ct3d->hostpmem) {
+        host_memory_backend_set_mapped(ct3d->hostpmem, false);
         address_space_destroy(&ct3d->hostpmem_as);
     }
     if (ct3d->hostvmem) {
+        host_memory_backend_set_mapped(ct3d->hostvmem, false);
         address_space_destroy(&ct3d->hostvmem_as);
     }
 }
@@ -1072,12 +1075,15 @@ static void ct3_exit(PCIDevice *pci_dev)
     cxl_destroy_cci(&ct3d->cci);
     if (ct3d->dc.host_dc) {
         cxl_destroy_dc_regions(ct3d);
+        host_memory_backend_set_mapped(ct3d->dc.host_dc, false);
         address_space_destroy(&ct3d->dc.host_dc_as);
     }
     if (ct3d->hostpmem) {
+        host_memory_backend_set_mapped(ct3d->hostpmem, false);
         address_space_destroy(&ct3d->hostpmem_as);
     }
     if (ct3d->hostvmem) {
+        host_memory_backend_set_mapped(ct3d->hostvmem, false);
         address_space_destroy(&ct3d->hostvmem_as);
     }
 }
Signature · 1 line
2.47.3
#2 lore raw

PATCH 2/2 cxl_downstream: enable power controller present capability.

In reply to Joshua Lant

PCI_EXP_SLTCAP_PCP (Power Controller Present) must be set in the DSP's slot capabilities for PCIe managed hot-remove to complete. Without this notification from the guest of removal cannot be sent back to the device.

Fixes 845f94de78c ("hw/pci-bridge/cxl_upstream: Provide x-speed and x-width properties.")
---
 hw/pci-bridge/cxl_downstream.c | 2 ++
 1 file changed, 2 insertions(+)
hw/pci-bridge/cxl_downstream.c +2 -0
index ec450d1aa0..6ba6f1aa52 100644
@@ -228,6 +228,8 @@ static const Property cxl_dsp_props[] = {
     DEFINE_PROP_PCIE_LINK_WIDTH("x-width", PCIESlot,
                                 width, PCIE_LINK_WIDTH_16),
     DEFINE_PROP_BOOL("x-256b-flit", PCIESlot, flitmode, true),
+    DEFINE_PROP_BIT(COMPAT_PROP_PCP, PCIDevice, cap_present,
+                    QEMU_PCIE_SLTCAP_PCP_BITNR, true),
 };
 
 static void cxl_dsp_class_init(ObjectClass *oc, const void *data)
Signature · 1 line
2.47.3