[PATCH] qemu: auto-assign hostdev interface devices to PCIe

Laine Stump posted 1 patch 3 years, 9 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20200617211745.3704591-1-laine@redhat.com
Test syntax-check failed
src/qemu/qemu_domain_address.c | 8 ++++++++
1 file changed, 8 insertions(+)
[PATCH] qemu: auto-assign hostdev interface devices to PCIe
Posted by Laine Stump 3 years, 9 months ago
Until recently, an <interface type='network'> would automatically be
assigned model "rtl8139" (the default on x86 machinetypes), which in
turn would lead to the device being assigned a PCI address on a
conventional PCI controller (i.e. a pcie-to-pci-bridge). If the
network was a typical Linux host bridge-based network that used an
emulated device, this would be appropriate, since the guest actually
would get an emulated rtl8139 NIC, and that device is a conventional
PCI device.

However, if the network being used was a pool of hostdev devices, the
guest would get an actual PCIe network device assigned from the host
via VFIO; while the interface model in that case is irrelevant for the
QEMU commandline to assign the device, the PCI address would have
already been assigned prior to runtime, so the address assignment
would be done based on the model='rtl8139' - a conventional PCI
device. VFIO assignment of a PCIe device to a conventional PCI slot
works, but we would rather have these devices in a PCIe slot.

Since commit bdb8f2e4186, if <interface type='network'> points to a
etwork that is a pool of hostdev devices, the interface model will be
_unset_ by default. This patch uses that information when deciding
what type of slot to assign to the device: since all hostdev network
interfaces are SR-IOV VFs, and *all* SR-IOV network cards are PCIe, it
is safe to assume that the VFs are PCIe and we should assign then to a
PCIe slot in the guest.

Signed-off-by: Laine Stump <laine@redhat.com>
---

(NB: all talk of PCIe vs. conventional PCI is irrelevant for
machinetypes that don't support PCIe - any requirement for PCIe is
"squashed" down to just "PCI" in those cases)

(Note to Paulo - I realize this doesn't describe exactly what happens
on s390, since the default interface model in that case is "virtio"
rather than "rtl8139", and this patch should actually cause no
behavior change on S390. I'm Cc'ing you since you're the author of the
other patch I mention in the commit message, and also so you can try
running your same tests with this patch added, and verify that it
really doesn't break anything for S390.)


 src/qemu/qemu_domain_address.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 07431343ed..05cf251cd5 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -734,6 +734,14 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
         if (net->model == VIR_DOMAIN_NET_MODEL_E1000E)
             return pcieFlags;
 
+        /* the only time model can be "unknown" is for type='hostdev'
+         * or for type='network' where the network is a pool of
+         * hostdev devices. These will always be pcie on the host, and
+         * should be pcie in the guest if it supports pcie.
+         */
+        if (net->model == VIR_DOMAIN_NET_MODEL_UNKNOWN)
+            return pcieFlags;
+
         return pciFlags;
     }
 
-- 
2.25.4

Re: [PATCH] qemu: auto-assign hostdev interface devices to PCIe
Posted by Paulo de Rezende Pinatti 3 years, 9 months ago

On 17/06/20 23:17, Laine Stump wrote:
[...]
> 
> (Note to Paulo - I realize this doesn't describe exactly what happens
> on s390, since the default interface model in that case is "virtio"
> rather than "rtl8139", and this patch should actually cause no
> behavior change on S390. I'm Cc'ing you since you're the author of the
> other patch I mention in the commit message, and also so you can try
> running your same tests with this patch added, and verify that it
> really doesn't break anything for S390.)
> 

Hi Laine,

Thanks for the note, I ran the same tests with this patch and can 
confirm it still works for S390.

> 
>   src/qemu/qemu_domain_address.c | 8 ++++++++
>   1 file changed, 8 insertions(+)
> 
> diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
> index 07431343ed..05cf251cd5 100644
> --- a/src/qemu/qemu_domain_address.c
> +++ b/src/qemu/qemu_domain_address.c
> @@ -734,6 +734,14 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDefPtr dev,
>           if (net->model == VIR_DOMAIN_NET_MODEL_E1000E)
>               return pcieFlags;
>   
> +        /* the only time model can be "unknown" is for type='hostdev'
> +         * or for type='network' where the network is a pool of
> +         * hostdev devices. These will always be pcie on the host, and
> +         * should be pcie in the guest if it supports pcie.
> +         */
> +        if (net->model == VIR_DOMAIN_NET_MODEL_UNKNOWN)
> +            return pcieFlags;
> +
>           return pciFlags;
>       }
>   
> 

-- 
Best regards,

Paulo de Rezende Pinatti

Re: [PATCH] qemu: auto-assign hostdev interface devices to PCIe
Posted by Andrea Bolognani 3 years, 9 months ago
On Wed, 2020-06-17 at 17:17 -0400, Laine Stump wrote:
> Until recently, an <interface type='network'> would automatically be
> assigned model "rtl8139" (the default on x86 machinetypes), which in
> turn would lead to the device being assigned a PCI address on a
> conventional PCI controller (i.e. a pcie-to-pci-bridge). If the
> network was a typical Linux host bridge-based network that used an
> emulated device, this would be appropriate, since the guest actually
> would get an emulated rtl8139 NIC, and that device is a conventional
> PCI device.
> 
> However, if the network being used was a pool of hostdev devices, the
> guest would get an actual PCIe network device assigned from the host
> via VFIO; while the interface model in that case is irrelevant for the
> QEMU commandline to assign the device, the PCI address would have
> already been assigned prior to runtime, so the address assignment
> would be done based on the model='rtl8139' - a conventional PCI
> device. VFIO assignment of a PCIe device to a conventional PCI slot
> works, but we would rather have these devices in a PCIe slot.
> 
> Since commit bdb8f2e4186, if <interface type='network'> points to a
> etwork that is a pool of hostdev devices, the interface model will be
> _unset_ by default. This patch uses that information when deciding
> what type of slot to assign to the device: since all hostdev network
> interfaces are SR-IOV VFs, and *all* SR-IOV network cards are PCIe, it
> is safe to assume that the VFs are PCIe and we should assign then to a
> PCIe slot in the guest.
> 
> Signed-off-by: Laine Stump <laine@redhat.com>

Reviewed-by: Andrea Bolognani <abologna@redhat.com>

-- 
Andrea Bolognani / Red Hat / Virtualization