This is a long pending issue that we haven't fixed. The issue is in QEMU we have implicit device ordering requirement when realizing, otherwise some of the device may not work properly.
The initial requirement comes from when vfio-pci starts to work with vIOMMUs. To make sure vfio-pci will get the correct DMA address space, the vIOMMU device needs to be created before vfio-pci otherwise vfio-pci will stop working when the guest enables the vIOMMU and the device at the same time. AFAIU Libvirt should have code that guarantees that. For QEMU cmdline users, they need to pay attention or things will stop working at some point. Recently there's a growing and similar requirement on vDPA. It's not a hard requirement so far but vDPA has patches that try to workaround this issue. This patchset allows us to realize the devices in the order that e.g. platform devices will be created first (bus device, IOMMU, etc.), then the rest of normal devices. It's done simply by ordering the QemuOptsList of "device" entries before realization. The priority so far comes from migration priorities which could be a little bit odd, but that's really about the same problem and we can clean that part up in the future. Libvirt can still keep its ordering for sure so old QEMU will still work, however that won't be needed for new qemus after this patchset, so with the new binary we should be able to specify qemu cmdline as wish on '-device'. Logically this should also work for vDPA and the workaround code can be done with more straightforward approaches. Please review, thanks. Peter Xu (4): qdev-monitor: Trace qdev creation qemu-config: Allow in-place sorting of QemuOptsList qdev: Export qdev_get_device_class() vl: Prioritize realizations of devices include/monitor/qdev.h | 2 ++ include/qemu/config-file.h | 4 ++++ softmmu/qdev-monitor.c | 4 +++- softmmu/trace-events | 3 +++ softmmu/vl.c | 35 +++++++++++++++++++++++++++ util/qemu-config.c | 48 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 95 insertions(+), 1 deletion(-) -- 2.31.1