On Mon, Aug 23, 2021 at 05:31:46PM -0400, Peter Xu wrote: > On Mon, Aug 23, 2021 at 05:07:03PM -0400, Eduardo Habkost wrote: > > To give just one example: > > > > $ (echo 'info pci';echo quit;) | qemu-system-x86_64 -device virtio-net-pci > > -device e1000e -monitor stdio | tail -n 20 > > Bus 0, device 4, function 0: > > Ethernet controller: PCI device 1af4:1000 > > PCI subsystem 1af4:0001 > > IRQ 0, pin A > > BAR0: I/O at 0xffffffffffffffff [0x001e]. > > BAR1: 32 bit memory at 0xffffffffffffffff [0x00000ffe]. > > BAR4: 64 bit prefetchable memory at 0xffffffffffffffff [0x00003ffe]. > > BAR6: 32 bit memory at 0xffffffffffffffff [0x0003fffe]. > > id "" > > Bus 0, device 5, function 0: > > Ethernet controller: PCI device 8086:10d3 > > PCI subsystem 8086:0000 > > IRQ 0, pin A > > BAR0: 32 bit memory at 0xffffffffffffffff [0x0001fffe]. > > BAR1: 32 bit memory at 0xffffffffffffffff [0x0001fffe]. > > BAR2: I/O at 0xffffffffffffffff [0x001e]. > > BAR3: 32 bit memory at 0xffffffffffffffff [0x00003ffe]. > > BAR6: 32 bit memory at 0xffffffffffffffff [0x0003fffe]. > > id "" > > (qemu) quit > > $ (echo 'info pci';echo quit;) | qemu-system-x86_64 -device e1000e -device > > virtio-net-pci -monitor stdio | tail -n 20 > > Bus 0, device 4, function 0: > > Ethernet controller: PCI device 8086:10d3 > > PCI subsystem 8086:0000 > > IRQ 0, pin A > > BAR0: 32 bit memory at 0xffffffffffffffff [0x0001fffe]. > > BAR1: 32 bit memory at 0xffffffffffffffff [0x0001fffe]. > > BAR2: I/O at 0xffffffffffffffff [0x001e]. > > BAR3: 32 bit memory at 0xffffffffffffffff [0x00003ffe]. > > BAR6: 32 bit memory at 0xffffffffffffffff [0x0003fffe]. > > id "" > > Bus 0, device 5, function 0: > > Ethernet controller: PCI device 1af4:1000 > > PCI subsystem 1af4:0001 > > IRQ 0, pin A > > BAR0: I/O at 0xffffffffffffffff [0x001e]. > > BAR1: 32 bit memory at 0xffffffffffffffff [0x00000ffe]. > > BAR4: 64 bit prefetchable memory at 0xffffffffffffffff [0x00003ffe]. > > BAR6: 32 bit memory at 0xffffffffffffffff [0x0003fffe]. > > id "" > > (qemu) quit > > > > > > If the order of the -device arguments changes, the devices are assigned to > > different PCI slots. > > Thanks for the example. > > Initially I thought about this and didn't think it an issue (because serious > users will always specify addr=XXX for -device; I thought libvirt always does > that), but I do remember that guest OS could identify its hardware config with > devfn number, so nmcli may mess up its config with before/after this change > indeed.. > > I can use a custom sort to replace qsort() to guarantee that. > > Do you have other examples in mind that I may have overlooked, especially I > may > not be able to fix by a custom sort with only moving priority>=1 devices?
I don't have any other example, but I assume address assignment based on ordering is a common pattern in device code. I would take a very close and careful look at the devices with non-default vmsd priority. If you can prove that the 13 device types with non-default priority are all order-insensitive, a custom sort function as you describe might be safe. -- Eduardo