qemu-e2k/include/hw/pci
Jonathan Cameron b2999ed8ad hw/pci-bridge: Fix release ordering by embedding PCIBridgeWindows within PCIBridge
The lifetime of the PCIBridgeWindows instance accessed via the windows pointer
in struct PCIBridge is managed separately from the PCIBridge itself.

Triggered by ./qemu-system-x86_64 -M x-remote -display none -monitor stdio
QEMU monitor: device_add cxl-downstream

In some error handling paths (such as the above due to attaching a cxl-downstream
port anything other than a cxl-upstream port) the g_free() of the PCIBridge
windows in pci_bridge_region_cleanup() is called before the final call of
flatview_uref() in address_space_set_flatview() ultimately from
drain_call_rcu()

At one stage this resulted in a crash, currently can still be observed using
valgrind which records a use after free.

When present, only one instance is allocated. pci_bridge_update_mappings()
can operate directly on an instance rather than creating a new one and
swapping it in.  Thus there appears to be no reason to not directly
couple the lifetimes of the two structures by embedding the PCIBridgeWindows
within the PCIBridge removing the need for the problematic separate free.

Patch is same as was posted deep in the discussion.
https://lore.kernel.org/qemu-devel/20230403171232.000020bb@huawei.com/

Reported-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Message-Id: <20230421122550.28234-1-Jonathan.Cameron@huawei.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
2023-05-16 09:14:18 +02:00
..
msi.h hw/xen: Support MSI mapping to PIRQ 2023-03-01 09:09:22 +00:00
msix.h
pci_bridge.h hw/pci-bridge: Fix release ordering by embedding PCIBridgeWindows within PCIBridge 2023-05-16 09:14:18 +02:00
pci_bus.h
pci_device.h include/hw/pci: Split pci_device.h off pci.h 2023-01-08 01:54:22 -05:00
pci_host.h
pci_ids.h remove DEC 21154 PCI bridge 2022-12-21 07:32:24 -05:00
pci_regs.h
pci.h pci: avoid accessing slot_reserved_mask directly outside of pci.c 2023-04-21 04:25:52 -04:00
pcie_aer.h hw/pci/aer: Make PCIE AER error injection facility available for other emulation to use. 2023-03-07 12:39:00 -05:00
pcie_doe.h Don't include headers already included by qemu/osdep.h 2023-02-08 07:28:05 +01:00
pcie_host.h
pcie_port.h hw/pci: Add pcie_count_ds_port() and pcie_find_port_first() helpers 2023-03-07 19:51:07 -05:00
pcie_regs.h hw/pci/aer: Implement PCI_ERR_UNCOR_MASK register 2023-03-07 12:39:00 -05:00
pcie_sriov.h pcie: Introduce pcie_sriov_num_vfs 2023-03-10 15:35:38 +08:00
pcie.h pcie: drop unused PCIExpressIndicator 2023-03-02 03:10:49 -05:00
shpc.h include/hw/pci: Split pci_device.h off pci.h 2023-01-08 01:54:22 -05:00
slotid_cap.h