qemu-e2k/hw
Łukasz Gieryk 58660bfa36 hw/acpi: Make the PCI hot-plug aware of SR-IOV
PCI device capable of SR-IOV support is a new, still-experimental
feature with only a single working example of the Nvme device.

This patch in an attempt to fix a double-free problem when a
SR-IOV-capable Nvme device is hot-unplugged in the following scenario:

Qemu CLI:
---------
-device pcie-root-port,slot=0,id=rp0
-device nvme-subsys,id=subsys0
-device nvme,id=nvme0,bus=rp0,serial=deadbeef,subsys=subsys0,sriov_max_vfs=1,sriov_vq_flexible=2,sriov_vi_flexible=1

Guest OS:
---------
sudo nvme virt-mgmt /dev/nvme0 -c 0 -r 1 -a 1 -n 0
sudo nvme virt-mgmt /dev/nvme0 -c 0 -r 0 -a 1 -n 0
echo 1 > /sys/bus/pci/devices/0000:01:00.0/reset
sleep 1
echo 1 > /sys/bus/pci/devices/0000:01:00.0/sriov_numvfs
nvme virt-mgmt /dev/nvme0 -c 1 -r 1 -a 8 -n 1
nvme virt-mgmt /dev/nvme0 -c 1 -r 0 -a 8 -n 2
nvme virt-mgmt /dev/nvme0 -c 1 -r 0 -a 9 -n 0
sleep 2
echo 01:00.1 > /sys/bus/pci/drivers/nvme/bind

Qemu monitor:
-------------
device_del nvme0

Explanation of the problem and the proposed solution:

1) The current SR-IOV implementation assumes it’s the PhysicalFunction
   that creates and deletes VirtualFunctions.
2) It’s a design decision (the Nvme device at least) for the VFs to be
   of the same class as PF. Effectively, they share the dc->hotpluggable
   value.
3) When a VF is created, it’s added as a child node to PF’s PCI bus
   slot.
4) Monitor/device_del triggers the ACPI mechanism. The implementation is
   not aware of SR/IOV and ejects PF’s PCI slot, directly unrealizing all
   hot-pluggable (!acpi_pcihp_pc_no_hotplug) children nodes.
5) VFs are unrealized directly, and it doesn’t work well with (1).
   SR/IOV structures are not updated, so when it’s PF’s turn to be
   unrealized, it works on stale pointers to already-deleted VFs.

The proposed fix is to make the PCI ACPI code aware of SR/IOV.

Signed-off-by: Łukasz Gieryk <lukasz.gieryk@linux.intel.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
2022-06-23 23:24:29 +02:00
..
9pfs 9pfs: fix 'Twalk' to only send error if no component walked 2022-06-16 12:44:52 +02:00
acpi hw/acpi: Make the PCI hot-plug aware of SR-IOV 2022-06-23 23:24:29 +02:00
adc
alpha
arm aspeed: Add I2C buses to AST1030 model 2022-06-22 09:49:34 +02:00
audio hw/audio/cs4231a: Const'ify global tables 2022-06-11 11:44:50 +02:00
avr
block hw/block/fdc-sysbus: Always mark sysbus floppy controllers as not having DMA 2022-06-11 11:36:14 +02:00
char acpi: serial-is: replace ISADeviceClass::build_aml with AcpiDevAmlIfClass:build_dev_aml 2022-06-09 19:32:48 -04:00
core qdev: unplug blocker for devices 2022-06-15 14:50:41 +01:00
cpu
cris
cxl pci-bridge/cxl_downstream: Add a CXL switch downstream port 2022-06-16 12:54:57 -04:00
display virtio-gpu: Respect UI refresh rate for EDID 2022-06-14 10:34:37 +02:00
dma
gpio
hppa
hyperv
i2c aspeed/i2c: Enable SLAVE_ADDR_RX_MATCH always 2022-06-22 09:49:34 +02:00
i386 hw/i386/pc: Unexport functions used only internally 2022-06-11 11:44:50 +02:00
ide include/hw/ide: Unexport pci_piix3_xen_ide_unplug() 2022-06-09 14:47:42 +01:00
input acpi: pckbd: replace ISADeviceClass::build_aml with AcpiDevAmlIfClass:build_dev_aml 2022-06-09 19:32:48 -04:00
intc pnv/xive2: Access direct mapped thread contexts from all chips 2022-06-20 08:38:58 -03:00
ipack
ipmi acpi: ipmi: use AcpiDevAmlIf interface to build IPMI device descriptors 2022-06-09 19:32:49 -04:00
isa hw/isa/piix3: Inline and remove piix3_create() 2022-06-11 11:44:50 +02:00
loongarch hw/loongarch: Add LoongArch virt power manager support. 2022-06-06 18:14:13 +00:00
m68k
mem
microblaze
mips hw/mips/boston: Initialize g_autofree pointers 2022-06-11 23:50:35 +02:00
misc aspeed/hace: Add missing newlines to unimp messages 2022-06-22 09:49:34 +02:00
net hw/net/fsl_etsec/etsec: Remove obsolete and unused etsec_create() 2022-06-11 11:44:50 +02:00
nios2
nubus
nvme hw/nvme: Update the initalization place for the AER queue 2022-06-23 23:24:29 +02:00
nvram
openrisc
pci vfio-user: handle device interrupts 2022-06-15 16:43:42 +01:00
pci-bridge pci-bridge/cxl_downstream: Add a CXL switch downstream port 2022-06-16 12:54:57 -04:00
pci-host ppc/pnv: fix extra indent spaces with DEFINE_PROP* 2022-06-20 08:38:58 -03:00
pcmcia
ppc ppc: fix boot with sam460ex 2022-06-20 08:38:58 -03:00
rdma
remote vfio-user: handle reset of remote device 2022-06-15 16:43:42 +01:00
riscv hw/core/loader: return image sizes as ssize_t 2022-06-10 09:31:42 +10:00
rtc hw/rtc/mc146818rtc: QOM'ify io_base offset 2022-06-11 11:44:50 +02:00
rx
s390x virtio: stop ioeventfd on reset 2022-06-14 16:50:30 +02:00
scsi virtio,pc,pci: fixes,cleanups,features 2022-06-10 18:15:34 -07:00
sd
sensor
sh4
smbios
sparc
sparc64 hw: Reuse TYPE_I8042 define 2022-06-11 11:44:50 +02:00
ssi
timer Fix 'writeable' typos 2022-06-08 19:38:47 +01:00
tpm acpi: tpm-tis: use AcpiDevAmlIfClass:build_dev_aml to provide device's AML 2022-06-09 19:32:49 -04:00
tricore
usb usbredir: avoid queuing hello packet on snapshot restore 2022-06-14 10:34:36 +02:00
vfio ui/console: Do not return a value with ui_info 2022-06-14 10:34:37 +02:00
virtio vhost: also check queue state in the vhost_dev_set_log error routine 2022-06-16 12:54:58 -04:00
watchdog
xen
xenpv
xtensa
Kconfig hw/loongarch: Add support loongson3 virt machine type. 2022-06-06 18:09:03 +00:00
meson.build hw/loongarch: Add support loongson3 virt machine type. 2022-06-06 18:09:03 +00:00