cxl: fixes for hot-removal of devices
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
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.
--- hw/mem/cxl_type3.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/mem/cxl_type3.c +6 -0
@@ -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
PATCH 2/2 cxl_downstream: enable power controller present capability.
In reply to Joshua LantPCI_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.
--- hw/pci-bridge/cxl_downstream.c | 2 ++ 1 file changed, 2 insertions(+)
hw/pci-bridge/cxl_downstream.c +2 -0
@@ -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