]> git.ipfire.org Git - thirdparty/libvirt.git/commit
qemu: assign correct type of PCI address for vhost-scsi when using pcie-root
authorLaine Stump <laine@laine.org>
Fri, 15 Dec 2017 16:42:35 +0000 (11:42 -0500)
committerLaine Stump <laine@laine.org>
Sun, 21 Jan 2018 03:01:24 +0000 (22:01 -0500)
commit18c24bc686af7e59387ced8c07a013eef4e289e6
tree8155c7a81ef74dac419c28942711bdbdae4136f4
parent71d56a397925a1bd55d3aee30afdbdcd1a14f9a8
qemu: assign correct type of PCI address for vhost-scsi when using pcie-root

Commit 10c73bf1 fixed a bug that I had introduced back in commit
70249927 - if a vhost-scsi device had no manually assigned PCI
address, one wouldn't be assigned automatically. There was a slight
problem with the logic of the fix though - in the case of domains with
pcie-root (e.g. those with a q35 machinetype),
qemuDomainDeviceCalculatePCIConnectFlags() will attempt to determine
if the host-side PCI device is Express or legacy by examining sysfs
based on the host-side PCI address stored in
hostdev->source.subsys.u.pci.addr, but that part of the union is only
valid for PCI hostdevs, *not* for SCSI hostdevs. So we end up trying
to read sysfs for some probably-non-existent device, which fails, and
the function virPCIDeviceIsPCIExpress() returns failure (-1).

By coincidence, the return value is being examined as a boolean, and
since -1 is true, we still end up assigning the vhost-scsi device to
an Express slot, but that is just by chance (and could fail in the
case that the gibberish in the "hostside PCI address" was the address
of a real device that happened to be legacy PCI).

Since (according to Paolo Bonzini) vhost-scsi devices appear just like
virtio-scsi devices in the guest, they should follow the same rules as
virtio devices when deciding whether they should be placed in an
Express or a legacy slot. That's accomplished in this patch by
returning early with virtioFlags, rather than erroneously using
hostdev->source.subsys.u.pci.addr. It also adds a test case for PCIe
to assure it doesn't get broken in the future.
src/qemu/qemu_domain_address.c
tests/qemuxml2argvdata/hostdev-scsi-vhost-scsi-pcie.args [new file with mode: 0644]
tests/qemuxml2argvdata/hostdev-scsi-vhost-scsi-pcie.xml [new file with mode: 0644]
tests/qemuxml2argvtest.c
tests/qemuxml2xmloutdata/hostdev-scsi-vhost-scsi-pcie.xml [new file with mode: 0644]
tests/qemuxml2xmltest.c