[libvirt] [PATCH v3 1/3] qemu: Use virtio-pci by default for mach-virt guests

Laine Stump laine at laine.org
Tue Jan 10 08:38:11 UTC 2017


On 12/23/2016 01:54 PM, Andrea Bolognani wrote:
> virtio-pci is the way forward for aarch64 guests: it's faster
> and less alien to people coming from other architectures.
> Now that guest support is finally getting there (Fedora 24,
> CentOS 7.3, Ubuntu 16.04 and Debian testing all support
> virtio-pci out of the box), we'd like to start using it by
> default instead of virtio-mmio.
>
> Users and applications can already opt-in by explicitly using
>
>    <address type='pci'/>
>
> inside the relevant elements, but that's kind of cumbersome and
> requires all users and management applications to adapt, which
> we'd really like to avoid.
>
> What we can do instead is use virtio-mmio only if the guest
> already has at least one virtio-mmio device, and use virtio-pci
> in all other situations.
>
> That means existing virtio-mmio guests will keep using the old
> addressing scheme, and new guests will automatically be created
> using virtio-pci instead. Users can still override the default
> in either direction.
>
> Existing tests such as aarch64-aavmf-virtio-mmio and
> aarch64-virtio-pci-default already cover all possible
> scenarios, so no additions to the test suites are necessary.
> ---
>   src/qemu/qemu_domain_address.c                     | 51 ++++++++++++++++++++--
>   ...l2argv-aarch64-virt-2.6-virtio-pci-default.args | 14 +++---
>   .../qemuxml2argv-aarch64-virtio-pci-default.args   | 17 +++++---
>   .../qemuxml2argv-aarch64-virtio-pci-default.xml    |  3 --
>   tests/qemuxml2argvtest.c                           |  1 +
>   .../qemuxml2xmlout-aarch64-virtio-pci-default.xml  | 40 ++++++++++++++---
>   tests/qemuxml2xmltest.c                            |  1 +
>   7 files changed, 106 insertions(+), 21 deletions(-)
>
> diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
> index be4ed23..d2f7953 100644
> --- a/src/qemu/qemu_domain_address.c
> +++ b/src/qemu/qemu_domain_address.c
> @@ -398,6 +398,44 @@ qemuDomainAssignS390Addresses(virDomainDefPtr def,
>   }
>   
>   
> +static int
> +qemuDomainHasVirtioMMIODevicesCallback(virDomainDefPtr def ATTRIBUTE_UNUSED,
> +                                       virDomainDeviceDefPtr dev ATTRIBUTE_UNUSED,
> +                                       virDomainDeviceInfoPtr info,
> +                                       void *opaque)
> +{
> +    if (info->type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO) {
> +        /* We can stop iterating as soon as we find the first
> +         * virtio-mmio device */
> +        *((bool *) opaque) = true;
> +        return -1;
> +    }
> +
> +    return 0;
> +}
> +
> +
> +/**
> + * qemuDomainHasVirtioMMIODevices:
> + * @def: domain definition
> + *
> + * Scan @def looking for devices with a virtio-mmio address.
> + *
> + * Returns: true if there are any, false otherwise
> + */
> +static bool
> +qemuDomainHasVirtioMMIODevices(virDomainDefPtr def)
> +{
> +    bool result = false;
> +
> +    virDomainDeviceInfoIterate(def,
> +                               qemuDomainHasVirtioMMIODevicesCallback,
> +                               &result);
> +
> +    return result;
> +}
> +
> +
>   static void
>   qemuDomainAssignARMVirtioMMIOAddresses(virDomainDefPtr def,
>                                          virQEMUCapsPtr qemuCaps)
> @@ -410,9 +448,16 @@ qemuDomainAssignARMVirtioMMIOAddresses(virDomainDefPtr def,
>             qemuDomainMachineIsVirt(def)))
>           return;
>   
> -    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_MMIO)) {
> -        qemuDomainPrimeVirtioDeviceAddresses(
> -            def, VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO);
> +    /* We use virtio-mmio by default on mach-virt guests only if they already
> +     * have at least one virtio-mmio device: in all other cases, we prefer
> +     * virtio-pci */
> +    if (qemuDomainMachineHasPCIeRoot(def) &&
> +        !qemuDomainHasVirtioMMIODevices(def)) {
> +        qemuDomainPrimeVirtioDeviceAddresses(def,
> +                                             VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI);


I'm having trouble remembering, and it's too early in the morning to go 
looking in the code - it seems like priming the addresses with PCI might 
not be necessary - as long as we simply *don't* prime them with 
virtio-mmio. I could be misremembering though. ACK either way.

(ACK is based on the assumption that all concerned ARM parties have 
agreed that it's time to do this. I *think* that is the case :-)


> +    } else if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_MMIO)) {
> +        qemuDomainPrimeVirtioDeviceAddresses(def,
> +                                             VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_MMIO);
>       }
>   }
>   
> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virt-2.6-virtio-pci-default.args b/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virt-2.6-virtio-pci-default.args
> index 75db1a4..df03c6e 100644
> --- a/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virt-2.6-virtio-pci-default.args
> +++ b/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virt-2.6-virtio-pci-default.args
> @@ -21,14 +21,18 @@ QEMU_AUDIO_DRV=none \
>   -initrd /aarch64.initrd \
>   -append 'earlyprintk console=ttyAMA0,115200n8 rw root=/dev/vda rootwait' \
>   -dtb /aarch64.dtb \
> --device virtio-serial-device,id=virtio-serial0 \
> +-device i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1 \
> +-device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x0 \
> +-device ioh3420,port=0x10,chassis=3,id=pci.3,bus=pcie.0,addr=0x2 \
> +-device virtio-serial-pci,id=virtio-serial0,bus=pci.2,addr=0x2 \
>   -drive file=/aarch64.raw,format=raw,if=none,id=drive-virtio-disk0 \
> --device virtio-blk-device,drive=drive-virtio-disk0,id=virtio-disk0 \
> --device virtio-net-device,vlan=0,id=net0,mac=52:54:00:09:a4:37 \
> +-device virtio-blk-pci,bus=pci.2,addr=0x3,drive=drive-virtio-disk0,\
> +id=virtio-disk0 \
> +-device virtio-net-pci,vlan=0,id=net0,mac=52:54:00:09:a4:37,bus=pci.2,addr=0x1 \
>   -net user,vlan=0,name=hostnet0 \
>   -serial pty \
>   -chardev pty,id=charconsole1 \
>   -device virtconsole,chardev=charconsole1,id=console1 \
> --device virtio-balloon-device,id=balloon0 \
> +-device virtio-balloon-pci,id=balloon0,bus=pci.2,addr=0x4 \
>   -object rng-random,id=objrng0,filename=/dev/random \
> --device virtio-rng-device,rng=objrng0,id=rng0
> +-device virtio-rng-pci,rng=objrng0,id=rng0,bus=pci.2,addr=0x5
> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virtio-pci-default.args b/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virtio-pci-default.args
> index b5b010c..080b025 100644
> --- a/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virtio-pci-default.args
> +++ b/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virtio-pci-default.args
> @@ -21,14 +21,21 @@ QEMU_AUDIO_DRV=none \
>   -initrd /aarch64.initrd \
>   -append 'earlyprintk console=ttyAMA0,115200n8 rw root=/dev/vda rootwait' \
>   -dtb /aarch64.dtb \
> --device virtio-serial-device,id=virtio-serial0 \
> +-device ioh3420,port=0x8,chassis=1,id=pci.1,bus=pcie.0,addr=0x1 \
> +-device ioh3420,port=0x10,chassis=2,id=pci.2,bus=pcie.0,addr=0x2 \
> +-device ioh3420,port=0x18,chassis=3,id=pci.3,bus=pcie.0,addr=0x3 \
> +-device ioh3420,port=0x20,chassis=4,id=pci.4,bus=pcie.0,addr=0x4 \
> +-device ioh3420,port=0x28,chassis=5,id=pci.5,bus=pcie.0,addr=0x5 \
> +-device ioh3420,port=0x30,chassis=6,id=pci.6,bus=pcie.0,addr=0x6 \
> +-device virtio-serial-pci,id=virtio-serial0,bus=pci.2,addr=0x0 \
>   -drive file=/aarch64.raw,format=raw,if=none,id=drive-virtio-disk0 \
> --device virtio-blk-device,drive=drive-virtio-disk0,id=virtio-disk0 \
> --device virtio-net-device,vlan=0,id=net0,mac=52:54:00:09:a4:37 \
> +-device virtio-blk-pci,bus=pci.3,addr=0x0,drive=drive-virtio-disk0,\
> +id=virtio-disk0 \
> +-device virtio-net-pci,vlan=0,id=net0,mac=52:54:00:09:a4:37,bus=pci.1,addr=0x0 \
>   -net user,vlan=0,name=hostnet0 \
>   -serial pty \
>   -chardev pty,id=charconsole1 \
>   -device virtconsole,chardev=charconsole1,id=console1 \
> --device virtio-balloon-device,id=balloon0 \
> +-device virtio-balloon-pci,id=balloon0,bus=pci.4,addr=0x0 \
>   -object rng-random,id=objrng0,filename=/dev/random \
> --device virtio-rng-device,rng=objrng0,id=rng0
> +-device virtio-rng-pci,rng=objrng0,id=rng0,bus=pci.5,addr=0x0
> diff --git a/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virtio-pci-default.xml b/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virtio-pci-default.xml
> index ad34615..2a84a96 100644
> --- a/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virtio-pci-default.xml
> +++ b/tests/qemuxml2argvdata/qemuxml2argv-aarch64-virtio-pci-default.xml
> @@ -38,9 +38,6 @@
>         <target type='virtio' port='0'/>
>       </console>
>       <memballoon model='virtio'/>
> -    <!--
> -      This actually doesn't work in practice because vexpress only has
> -      4 virtio slots available, rng makes 5 -->
>       <rng model='virtio'>
>         <backend model='random'>/dev/random</backend>
>       </rng>
> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
> index ab3ad08..301f83e 100644
> --- a/tests/qemuxml2argvtest.c
> +++ b/tests/qemuxml2argvtest.c
> @@ -2135,6 +2135,7 @@ mymain(void)
>          specified. */
>       DO_TEST("aarch64-virtio-pci-default",
>               QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_DTB,
> +            QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY,
>               QEMU_CAPS_DEVICE_VIRTIO_MMIO,
>               QEMU_CAPS_DEVICE_VIRTIO_RNG, QEMU_CAPS_OBJECT_RNG_RANDOM,
>               QEMU_CAPS_OBJECT_GPEX, QEMU_CAPS_DEVICE_PCI_BRIDGE,
> diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-aarch64-virtio-pci-default.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-aarch64-virtio-pci-default.xml
> index 7c3fc19..a568f11 100644
> --- a/tests/qemuxml2xmloutdata/qemuxml2xmlout-aarch64-virtio-pci-default.xml
> +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-aarch64-virtio-pci-default.xml
> @@ -30,16 +30,46 @@
>       <disk type='file' device='disk'>
>         <source file='/aarch64.raw'/>
>         <target dev='vda' bus='virtio'/>
> -      <address type='virtio-mmio'/>
> +      <address type='pci' domain='0x0000' bus='0x03' slot='0x00' function='0x0'/>
>       </disk>
>       <controller type='pci' index='0' model='pcie-root'/>
>       <controller type='virtio-serial' index='0'>
> -      <address type='virtio-mmio'/>
> +      <address type='pci' domain='0x0000' bus='0x02' slot='0x00' function='0x0'/>
> +    </controller>
> +    <controller type='pci' index='1' model='pcie-root-port'>
> +      <model name='ioh3420'/>
> +      <target chassis='1' port='0x8'/>
> +      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x0'/>
> +    </controller>
> +    <controller type='pci' index='2' model='pcie-root-port'>
> +      <model name='ioh3420'/>
> +      <target chassis='2' port='0x10'/>
> +      <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/>
> +    </controller>
> +    <controller type='pci' index='3' model='pcie-root-port'>
> +      <model name='ioh3420'/>
> +      <target chassis='3' port='0x18'/>
> +      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
> +    </controller>
> +    <controller type='pci' index='4' model='pcie-root-port'>
> +      <model name='ioh3420'/>
> +      <target chassis='4' port='0x20'/>
> +      <address type='pci' domain='0x0000' bus='0x00' slot='0x04' function='0x0'/>
> +    </controller>
> +    <controller type='pci' index='5' model='pcie-root-port'>
> +      <model name='ioh3420'/>
> +      <target chassis='5' port='0x28'/>
> +      <address type='pci' domain='0x0000' bus='0x00' slot='0x05' function='0x0'/>
> +    </controller>
> +    <controller type='pci' index='6' model='pcie-root-port'>
> +      <model name='ioh3420'/>
> +      <target chassis='6' port='0x30'/>
> +      <address type='pci' domain='0x0000' bus='0x00' slot='0x06' function='0x0'/>
>       </controller>
>       <interface type='user'>
>         <mac address='52:54:00:09:a4:37'/>
>         <model type='virtio'/>
> -      <address type='virtio-mmio'/>
> +      <address type='pci' domain='0x0000' bus='0x01' slot='0x00' function='0x0'/>
>       </interface>
>       <serial type='pty'>
>         <target port='0'/>
> @@ -51,11 +81,11 @@
>         <target type='virtio' port='1'/>
>       </console>
>       <memballoon model='virtio'>
> -      <address type='virtio-mmio'/>
> +      <address type='pci' domain='0x0000' bus='0x04' slot='0x00' function='0x0'/>
>       </memballoon>
>       <rng model='virtio'>
>         <backend model='random'>/dev/random</backend>
> -      <address type='virtio-mmio'/>
> +      <address type='pci' domain='0x0000' bus='0x05' slot='0x00' function='0x0'/>
>       </rng>
>     </devices>
>   </domain>
> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
> index ddd17cb..bbd4687 100644
> --- a/tests/qemuxml2xmltest.c
> +++ b/tests/qemuxml2xmltest.c
> @@ -961,6 +961,7 @@ mymain(void)
>               QEMU_CAPS_DEVICE_VIRTIO_RNG, QEMU_CAPS_OBJECT_RNG_RANDOM);
>       DO_TEST("aarch64-virtio-pci-default",
>               QEMU_CAPS_NODEFCONFIG, QEMU_CAPS_DTB,
> +            QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY,
>               QEMU_CAPS_DEVICE_VIRTIO_MMIO,
>               QEMU_CAPS_DEVICE_VIRTIO_RNG, QEMU_CAPS_OBJECT_RNG_RANDOM,
>               QEMU_CAPS_OBJECT_GPEX, QEMU_CAPS_DEVICE_PCI_BRIDGE,





More information about the libvir-list mailing list