[libvirt] [PATCH 0/5] qemu: Fix memfd with default hugetlbfs mount

Michal Prívozník (5): qemuxml2argvdata: Drop useless spaces at the beginning of lines qemuxml2xmltest: Move virObjectUnref() call qemuxml2xmltest: Add memfd tests virfile: Introduce and use virFileGetDefaultHugepage qemuBuildMemoryBackendProps: Get pagesize early src/libvirt_private.syms | 1 + src/qemu/qemu_command.c | 14 ++++ src/qemu/qemu_conf.c | 12 +-- src/util/virfile.c | 25 ++++++ src/util/virfile.h | 3 + .../fd-memory-no-numa-topology.xml | 14 +++- .../fd-memory-numa-topology.xml | 12 ++- .../fd-memory-numa-topology2.xml | 70 +++++++++------- .../fd-memory-numa-topology3.xml | 72 +++++++++-------- ...memory-default-hugepage.x86_64-latest.args | 37 +++++++++ .../memfd-memory-default-hugepage.xml | 42 ++++++++++ .../memfd-memory-numa.x86_64-latest.args | 2 +- tests/qemuxml2argvdata/memfd-memory-numa.xml | 80 ++++++++++--------- tests/qemuxml2argvtest.c | 1 + .../fd-memory-no-numa-topology.xml | 1 + .../fd-memory-numa-topology.xml | 1 + .../fd-memory-numa-topology2.xml | 1 + .../fd-memory-numa-topology3.xml | 1 + .../memfd-memory-default-hugepage.xml | 1 + .../qemuxml2xmloutdata/memfd-memory-numa.xml | 1 + tests/qemuxml2xmltest.c | 18 ++++- 21 files changed, 295 insertions(+), 114 deletions(-) create mode 100644 tests/qemuxml2argvdata/memfd-memory-default-hugepage.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/memfd-memory-default-hugepage.xml create mode 120000 tests/qemuxml2xmloutdata/fd-memory-no-numa-topology.xml create mode 120000 tests/qemuxml2xmloutdata/fd-memory-numa-topology.xml create mode 120000 tests/qemuxml2xmloutdata/fd-memory-numa-topology2.xml create mode 120000 tests/qemuxml2xmloutdata/fd-memory-numa-topology3.xml create mode 120000 tests/qemuxml2xmloutdata/memfd-memory-default-hugepage.xml create mode 120000 tests/qemuxml2xmloutdata/memfd-memory-numa.xml -- 2.21.0

There are three test XMLs that have useless spaces at the beginning of each line. I intend to add these to qemuxml2xmltest and make xmlout a symlink to the original XML. In order to do that the XMLs must look better than they do now. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- .../fd-memory-numa-topology2.xml | 62 ++++++++-------- .../fd-memory-numa-topology3.xml | 64 ++++++++--------- tests/qemuxml2argvdata/memfd-memory-numa.xml | 72 +++++++++---------- 3 files changed, 99 insertions(+), 99 deletions(-) diff --git a/tests/qemuxml2argvdata/fd-memory-numa-topology2.xml b/tests/qemuxml2argvdata/fd-memory-numa-topology2.xml index 49beff188b..31f4567737 100644 --- a/tests/qemuxml2argvdata/fd-memory-numa-topology2.xml +++ b/tests/qemuxml2argvdata/fd-memory-numa-topology2.xml @@ -1,31 +1,31 @@ - <domain type='kvm' id='56'> - <name>instance-00000092</name> - <uuid>126f2720-6f8e-45ab-a886-ec9277079a67</uuid> - <memory unit='KiB'>14680064</memory> - <currentMemory unit='KiB'>14680064</currentMemory> - <memoryBacking> - <source type='file'/> - <access mode='private'/> - <allocation mode='immediate'/> - </memoryBacking> - <vcpu placement='static'>20</vcpu> - <os> - <type arch='x86_64' machine='pc-i440fx-wily'>hvm</type> - <boot dev='hd'/> - </os> - <cpu> - <topology sockets='1' cores='8' threads='1'/> - <numa> - <cell id='0' cpus='0-7' memory='14680064' unit='KiB'/> - <cell id='1' cpus='8-15' memory='14680064' unit='KiB' memAccess='shared'/> - </numa> - </cpu> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>destroy</on_crash> - <devices> - <emulator>/usr/bin/qemu-system-x86_64</emulator> - <memballoon model='virtio'/> - </devices> - </domain> +<domain type='kvm' id='56'> + <name>instance-00000092</name> + <uuid>126f2720-6f8e-45ab-a886-ec9277079a67</uuid> + <memory unit='KiB'>14680064</memory> + <currentMemory unit='KiB'>14680064</currentMemory> + <memoryBacking> + <source type='file'/> + <access mode='private'/> + <allocation mode='immediate'/> + </memoryBacking> + <vcpu placement='static'>20</vcpu> + <os> + <type arch='x86_64' machine='pc-i440fx-wily'>hvm</type> + <boot dev='hd'/> + </os> + <cpu> + <topology sockets='1' cores='8' threads='1'/> + <numa> + <cell id='0' cpus='0-7' memory='14680064' unit='KiB'/> + <cell id='1' cpus='8-15' memory='14680064' unit='KiB' memAccess='shared'/> + </numa> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/fd-memory-numa-topology3.xml b/tests/qemuxml2argvdata/fd-memory-numa-topology3.xml index 7933507592..42d8a3bdad 100644 --- a/tests/qemuxml2argvdata/fd-memory-numa-topology3.xml +++ b/tests/qemuxml2argvdata/fd-memory-numa-topology3.xml @@ -1,32 +1,32 @@ - <domain type='kvm' id='56'> - <name>instance-00000092</name> - <uuid>126f2720-6f8e-45ab-a886-ec9277079a67</uuid> - <memory unit='KiB'>14680064</memory> - <currentMemory unit='KiB'>14680064</currentMemory> - <memoryBacking> - <source type='file'/> - <access mode='shared'/> - <allocation mode='immediate'/> - </memoryBacking> - <vcpu placement='static'>32</vcpu> - <os> - <type arch='x86_64' machine='pc-i440fx-wily'>hvm</type> - <boot dev='hd'/> - </os> - <cpu> - <topology sockets='1' cores='24' threads='1'/> - <numa> - <cell id='0' cpus='0-1' memory='14680064' unit='KiB'/> - <cell id='1' cpus='2-3' memory='14680064' unit='KiB' memAccess='shared'/> - <cell id='2' cpus='4-5' memory='14680064' unit='KiB' memAccess='private'/> - </numa> - </cpu> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>destroy</on_crash> - <devices> - <emulator>/usr/bin/qemu-system-x86_64</emulator> - <memballoon model='virtio'/> - </devices> - </domain> +<domain type='kvm' id='56'> + <name>instance-00000092</name> + <uuid>126f2720-6f8e-45ab-a886-ec9277079a67</uuid> + <memory unit='KiB'>14680064</memory> + <currentMemory unit='KiB'>14680064</currentMemory> + <memoryBacking> + <source type='file'/> + <access mode='shared'/> + <allocation mode='immediate'/> + </memoryBacking> + <vcpu placement='static'>32</vcpu> + <os> + <type arch='x86_64' machine='pc-i440fx-wily'>hvm</type> + <boot dev='hd'/> + </os> + <cpu> + <topology sockets='1' cores='24' threads='1'/> + <numa> + <cell id='0' cpus='0-1' memory='14680064' unit='KiB'/> + <cell id='1' cpus='2-3' memory='14680064' unit='KiB' memAccess='shared'/> + <cell id='2' cpus='4-5' memory='14680064' unit='KiB' memAccess='private'/> + </numa> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <memballoon model='virtio'/> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/memfd-memory-numa.xml b/tests/qemuxml2argvdata/memfd-memory-numa.xml index 8416a990fa..41c1f9bfc2 100644 --- a/tests/qemuxml2argvdata/memfd-memory-numa.xml +++ b/tests/qemuxml2argvdata/memfd-memory-numa.xml @@ -1,36 +1,36 @@ - <domain type='kvm' id='56'> - <name>instance-00000092</name> - <uuid>126f2720-6f8e-45ab-a886-ec9277079a67</uuid> - <memory unit='KiB'>14680064</memory> - <currentMemory unit='KiB'>14680064</currentMemory> - <memoryBacking> - <hugepages> - <page size="2" unit="M"/> - </hugepages> - <source type='memfd'/> - <access mode='shared'/> - <allocation mode='immediate'/> - </memoryBacking> - <numatune> - <memnode cellid='0' mode='preferred' nodeset='3'/> - </numatune> - <vcpu placement='static'>8</vcpu> - <os> - <type arch='x86_64' machine='pc-i440fx-wily'>hvm</type> - <boot dev='hd'/> - </os> - <cpu> - <topology sockets='1' cores='8' threads='1'/> - <numa> - <cell id='0' cpus='0-7' memory='14680064' unit='KiB'/> - </numa> - </cpu> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>destroy</on_crash> - <devices> - <emulator>/usr/bin/qemu-system-x86_64</emulator> - <memballoon model='virtio'/> - </devices> - </domain> +<domain type='kvm' id='56'> + <name>instance-00000092</name> + <uuid>126f2720-6f8e-45ab-a886-ec9277079a67</uuid> + <memory unit='KiB'>14680064</memory> + <currentMemory unit='KiB'>14680064</currentMemory> + <memoryBacking> + <hugepages> + <page size="2" unit="M"/> + </hugepages> + <source type='memfd'/> + <access mode='shared'/> + <allocation mode='immediate'/> + </memoryBacking> + <numatune> + <memnode cellid='0' mode='preferred' nodeset='3'/> + </numatune> + <vcpu placement='static'>8</vcpu> + <os> + <type arch='x86_64' machine='pc-i440fx-wily'>hvm</type> + <boot dev='hd'/> + </os> + <cpu> + <topology sockets='1' cores='8' threads='1'/> + <numa> + <cell id='0' cpus='0-7' memory='14680064' unit='KiB'/> + </numa> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <memballoon model='virtio'/> + </devices> +</domain> -- 2.21.0

On Mon, Apr 01, 2019 at 04:04:33PM +0200, Michal Privoznik wrote:
There are three test XMLs that have useless spaces at the beginning of each line. I intend to add these to qemuxml2xmltest and make xmlout a symlink to the original XML. In order to do that the XMLs must look better than they do now.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- .../fd-memory-numa-topology2.xml | 62 ++++++++-------- .../fd-memory-numa-topology3.xml | 64 ++++++++--------- tests/qemuxml2argvdata/memfd-memory-numa.xml | 72 +++++++++---------- 3 files changed, 99 insertions(+), 99 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

The current location looks very arbitrary. Move it to the end of the mymain() function so it is less confusing. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemuxml2xmltest.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 83a0d1cf7b..87336484d1 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -1158,8 +1158,6 @@ mymain(void) QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM, QEMU_CAPS_VIRTIO_PCI_ATS); - virObjectUnref(cfg); - DO_TEST("acpi-table", NONE); DO_TEST("video-device-pciaddr-default", @@ -1297,6 +1295,7 @@ mymain(void) if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL) virFileDeleteTree(fakerootdir); + virObjectUnref(cfg); qemuTestDriverFree(&driver); VIR_FREE(fakerootdir); -- 2.21.0

On Mon, Apr 01, 2019 at 04:04:34PM +0200, Michal Privoznik wrote:
The current location looks very arbitrary. Move it to the end of the mymain() function so it is less confusing.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- tests/qemuxml2xmltest.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Somehow, these were not tested. Use symlinks to point expected output back to the input. This way we can also fix some discrepancies in the input XMLs. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- .../fd-memory-no-numa-topology.xml | 14 +++++++++++--- .../fd-memory-numa-topology.xml | 12 ++++++++++-- .../fd-memory-numa-topology2.xml | 12 ++++++++++-- .../fd-memory-numa-topology3.xml | 12 ++++++++++-- .../memfd-memory-numa.x86_64-latest.args | 2 +- tests/qemuxml2argvdata/memfd-memory-numa.xml | 18 +++++++++++++----- .../fd-memory-no-numa-topology.xml | 1 + .../fd-memory-numa-topology.xml | 1 + .../fd-memory-numa-topology2.xml | 1 + .../fd-memory-numa-topology3.xml | 1 + tests/qemuxml2xmloutdata/memfd-memory-numa.xml | 1 + tests/qemuxml2xmltest.c | 14 ++++++++++++++ 12 files changed, 74 insertions(+), 15 deletions(-) create mode 120000 tests/qemuxml2xmloutdata/fd-memory-no-numa-topology.xml create mode 120000 tests/qemuxml2xmloutdata/fd-memory-numa-topology.xml create mode 120000 tests/qemuxml2xmloutdata/fd-memory-numa-topology2.xml create mode 120000 tests/qemuxml2xmloutdata/fd-memory-numa-topology3.xml create mode 120000 tests/qemuxml2xmloutdata/memfd-memory-numa.xml diff --git a/tests/qemuxml2argvdata/fd-memory-no-numa-topology.xml b/tests/qemuxml2argvdata/fd-memory-no-numa-topology.xml index 243b65d36f..4c30761110 100644 --- a/tests/qemuxml2argvdata/fd-memory-no-numa-topology.xml +++ b/tests/qemuxml2argvdata/fd-memory-no-numa-topology.xml @@ -1,4 +1,4 @@ -<domain type='kvm' id='56'> +<domain type='kvm'> <name>instance-00000092</name> <uuid>126f2720-6f8e-45ab-a886-ec9277079a67</uuid> <memory unit='KiB'>14680064</memory> @@ -16,12 +16,20 @@ <cpu> <topology sockets='8' cores='1' threads='1'/> </cpu> - <clock offset='utc' /> + <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> - <memballoon model='virtio'/> + <controller type='usb' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </memballoon> </devices> </domain> diff --git a/tests/qemuxml2argvdata/fd-memory-numa-topology.xml b/tests/qemuxml2argvdata/fd-memory-numa-topology.xml index ca5402dbb0..f22a8e81f8 100644 --- a/tests/qemuxml2argvdata/fd-memory-numa-topology.xml +++ b/tests/qemuxml2argvdata/fd-memory-numa-topology.xml @@ -19,12 +19,20 @@ <cell id='0' cpus='0-7' memory='14680064' unit='KiB'/> </numa> </cpu> - <clock offset='utc' /> + <clock offset='utc'/> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> - <memballoon model='virtio'/> + <controller type='usb' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </memballoon> </devices> </domain> diff --git a/tests/qemuxml2argvdata/fd-memory-numa-topology2.xml b/tests/qemuxml2argvdata/fd-memory-numa-topology2.xml index 31f4567737..925f39b6ab 100644 --- a/tests/qemuxml2argvdata/fd-memory-numa-topology2.xml +++ b/tests/qemuxml2argvdata/fd-memory-numa-topology2.xml @@ -1,4 +1,4 @@ -<domain type='kvm' id='56'> +<domain type='kvm'> <name>instance-00000092</name> <uuid>126f2720-6f8e-45ab-a886-ec9277079a67</uuid> <memory unit='KiB'>14680064</memory> @@ -26,6 +26,14 @@ <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> - <memballoon model='virtio'/> + <controller type='usb' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </memballoon> </devices> </domain> diff --git a/tests/qemuxml2argvdata/fd-memory-numa-topology3.xml b/tests/qemuxml2argvdata/fd-memory-numa-topology3.xml index 42d8a3bdad..71a8e083c9 100644 --- a/tests/qemuxml2argvdata/fd-memory-numa-topology3.xml +++ b/tests/qemuxml2argvdata/fd-memory-numa-topology3.xml @@ -1,4 +1,4 @@ -<domain type='kvm' id='56'> +<domain type='kvm'> <name>instance-00000092</name> <uuid>126f2720-6f8e-45ab-a886-ec9277079a67</uuid> <memory unit='KiB'>14680064</memory> @@ -27,6 +27,14 @@ <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> - <memballoon model='virtio'/> + <controller type='usb' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </memballoon> </devices> </domain> diff --git a/tests/qemuxml2argvdata/memfd-memory-numa.x86_64-latest.args b/tests/qemuxml2argvdata/memfd-memory-numa.x86_64-latest.args index ee425a737b..c582878a12 100644 --- a/tests/qemuxml2argvdata/memfd-memory-numa.x86_64-latest.args +++ b/tests/qemuxml2argvdata/memfd-memory-numa.x86_64-latest.args @@ -31,7 +31,7 @@ share=yes,size=15032385536,host-nodes=3,policy=preferred \ -no-acpi \ -boot strict=on \ -device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ --device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \ -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ resourcecontrol=deny \ -msg timestamp=on diff --git a/tests/qemuxml2argvdata/memfd-memory-numa.xml b/tests/qemuxml2argvdata/memfd-memory-numa.xml index 41c1f9bfc2..f088f01d11 100644 --- a/tests/qemuxml2argvdata/memfd-memory-numa.xml +++ b/tests/qemuxml2argvdata/memfd-memory-numa.xml @@ -1,20 +1,20 @@ -<domain type='kvm' id='56'> +<domain type='kvm'> <name>instance-00000092</name> <uuid>126f2720-6f8e-45ab-a886-ec9277079a67</uuid> <memory unit='KiB'>14680064</memory> <currentMemory unit='KiB'>14680064</currentMemory> <memoryBacking> <hugepages> - <page size="2" unit="M"/> + <page size='2048' unit='KiB'/> </hugepages> <source type='memfd'/> <access mode='shared'/> <allocation mode='immediate'/> </memoryBacking> + <vcpu placement='static'>8</vcpu> <numatune> - <memnode cellid='0' mode='preferred' nodeset='3'/> + <memnode cellid='0' mode='preferred' nodeset='3'/> </numatune> - <vcpu placement='static'>8</vcpu> <os> <type arch='x86_64' machine='pc-i440fx-wily'>hvm</type> <boot dev='hd'/> @@ -31,6 +31,14 @@ <on_crash>destroy</on_crash> <devices> <emulator>/usr/bin/qemu-system-x86_64</emulator> - <memballoon model='virtio'/> + <controller type='usb' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </memballoon> </devices> </domain> diff --git a/tests/qemuxml2xmloutdata/fd-memory-no-numa-topology.xml b/tests/qemuxml2xmloutdata/fd-memory-no-numa-topology.xml new file mode 120000 index 0000000000..4a35465bd2 --- /dev/null +++ b/tests/qemuxml2xmloutdata/fd-memory-no-numa-topology.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/fd-memory-no-numa-topology.xml \ No newline at end of file diff --git a/tests/qemuxml2xmloutdata/fd-memory-numa-topology.xml b/tests/qemuxml2xmloutdata/fd-memory-numa-topology.xml new file mode 120000 index 0000000000..6ccadd7e24 --- /dev/null +++ b/tests/qemuxml2xmloutdata/fd-memory-numa-topology.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/fd-memory-numa-topology.xml \ No newline at end of file diff --git a/tests/qemuxml2xmloutdata/fd-memory-numa-topology2.xml b/tests/qemuxml2xmloutdata/fd-memory-numa-topology2.xml new file mode 120000 index 0000000000..9c5ab497de --- /dev/null +++ b/tests/qemuxml2xmloutdata/fd-memory-numa-topology2.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/fd-memory-numa-topology2.xml \ No newline at end of file diff --git a/tests/qemuxml2xmloutdata/fd-memory-numa-topology3.xml b/tests/qemuxml2xmloutdata/fd-memory-numa-topology3.xml new file mode 120000 index 0000000000..40ae69bcb0 --- /dev/null +++ b/tests/qemuxml2xmloutdata/fd-memory-numa-topology3.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/fd-memory-numa-topology3.xml \ No newline at end of file diff --git a/tests/qemuxml2xmloutdata/memfd-memory-numa.xml b/tests/qemuxml2xmloutdata/memfd-memory-numa.xml new file mode 120000 index 0000000000..a610bf7a49 --- /dev/null +++ b/tests/qemuxml2xmloutdata/memfd-memory-numa.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/memfd-memory-numa.xml \ No newline at end of file diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 87336484d1..4b8b0db0c6 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -1158,6 +1158,20 @@ mymain(void) QEMU_CAPS_VIRTIO_PCI_IOMMU_PLATFORM, QEMU_CAPS_VIRTIO_PCI_ATS); + DO_TEST("fd-memory-numa-topology", QEMU_CAPS_OBJECT_MEMORY_FILE, + QEMU_CAPS_KVM); + DO_TEST("fd-memory-numa-topology2", QEMU_CAPS_OBJECT_MEMORY_FILE, + QEMU_CAPS_KVM); + DO_TEST("fd-memory-numa-topology3", QEMU_CAPS_OBJECT_MEMORY_FILE, + QEMU_CAPS_KVM); + + DO_TEST("fd-memory-no-numa-topology", QEMU_CAPS_OBJECT_MEMORY_FILE, + QEMU_CAPS_KVM); + + DO_TEST("memfd-memory-numa", + QEMU_CAPS_OBJECT_MEMORY_MEMFD, + QEMU_CAPS_OBJECT_MEMORY_MEMFD_HUGETLB); + DO_TEST("acpi-table", NONE); DO_TEST("video-device-pciaddr-default", -- 2.21.0

On Mon, Apr 01, 2019 at 04:04:35PM +0200, Michal Privoznik wrote:
Somehow, these were not tested. Use symlinks to point expected output back to the input. This way we can also fix some discrepancies in the input XMLs.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- .../fd-memory-no-numa-topology.xml | 14 +++++++++++--- .../fd-memory-numa-topology.xml | 12 ++++++++++-- .../fd-memory-numa-topology2.xml | 12 ++++++++++-- .../fd-memory-numa-topology3.xml | 12 ++++++++++-- .../memfd-memory-numa.x86_64-latest.args | 2 +- tests/qemuxml2argvdata/memfd-memory-numa.xml | 18 +++++++++++++----- .../fd-memory-no-numa-topology.xml | 1 + .../fd-memory-numa-topology.xml | 1 + .../fd-memory-numa-topology2.xml | 1 + .../fd-memory-numa-topology3.xml | 1 + tests/qemuxml2xmloutdata/memfd-memory-numa.xml | 1 + tests/qemuxml2xmltest.c | 14 ++++++++++++++ 12 files changed, 74 insertions(+), 15 deletions(-) create mode 120000 tests/qemuxml2xmloutdata/fd-memory-no-numa-topology.xml create mode 120000 tests/qemuxml2xmloutdata/fd-memory-numa-topology.xml create mode 120000 tests/qemuxml2xmloutdata/fd-memory-numa-topology2.xml create mode 120000 tests/qemuxml2xmloutdata/fd-memory-numa-topology3.xml create mode 120000 tests/qemuxml2xmloutdata/memfd-memory-numa.xml
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

This helper returns the default hugetlbfs mount point from given array of mount points. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/libvirt_private.syms | 1 + src/qemu/qemu_conf.c | 12 ++++-------- src/util/virfile.c | 25 +++++++++++++++++++++++++ src/util/virfile.h | 3 +++ 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 73ef24d66f..d372997605 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1862,6 +1862,7 @@ virFileFindResourceFull; virFileFlock; virFileFreeACLs; virFileGetACLs; +virFileGetDefaultHugepage; virFileGetHugepageSize; virFileGetMountReverseSubtree; virFileGetMountSubtree; diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 42122dcd97..41ce0a978d 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -1914,16 +1914,12 @@ qemuGetDomainDefaultHugepath(const virDomainDef *def, virHugeTLBFSPtr hugetlbfs, size_t nhugetlbfs) { - size_t i; + virHugeTLBFSPtr p; - for (i = 0; i < nhugetlbfs; i++) - if (hugetlbfs[i].deflt) - break; + if (!(p = virFileGetDefaultHugepage(hugetlbfs, nhugetlbfs))) + p = &hugetlbfs[0]; - if (i == nhugetlbfs) - i = 0; - - return qemuGetDomainHugepagePath(def, &hugetlbfs[i]); + return qemuGetDomainHugepagePath(def, p); } diff --git a/src/util/virfile.c b/src/util/virfile.c index ec8d85929c..9f1a965acb 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3735,6 +3735,31 @@ virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs ATTRIBUTE_UNUSED, } #endif /* defined __linux__ */ +/** + * virFileGetDefaultHugepage: + * @fs: array of hugetlbfs mount points + * @nfs: number of items in @fs + * + * In the passed array of hugetlbfs mount points @fs find the + * default one. It's the one which has no '-o pagesize'. + * + * Returns: default hugepage, or + * NULL if none found + */ +virHugeTLBFSPtr +virFileGetDefaultHugepage(virHugeTLBFSPtr fs, + size_t nfs) +{ + size_t i; + + for (i = 0; i < nfs; i++) { + if (fs[i].deflt) + return &fs[i]; + } + + return NULL; +} + int virFileIsSharedFS(const char *path) { return virFileIsSharedFSType(path, diff --git a/src/util/virfile.h b/src/util/virfile.h index 3dedb7666a..df35a32bcc 100644 --- a/src/util/virfile.h +++ b/src/util/virfile.h @@ -334,6 +334,9 @@ int virFileGetHugepageSize(const char *path, int virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs, size_t *ret_nfs); +virHugeTLBFSPtr virFileGetDefaultHugepage(virHugeTLBFSPtr fs, + size_t nfs); + int virFileSetupDev(const char *path, const char *mount_options); -- 2.21.0

On Mon, Apr 01, 2019 at 04:04:36PM +0200, Michal Privoznik wrote:
This helper returns the default hugetlbfs mount point from given array of mount points.
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/libvirt_private.syms | 1 + src/qemu/qemu_conf.c | 12 ++++-------- src/util/virfile.c | 25 +++++++++++++++++++++++++ src/util/virfile.h | 3 +++ 4 files changed, 33 insertions(+), 8 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

https://bugzilla.redhat.com/show_bug.cgi?id=1693066 Up until memfd introduction (in 24b74d187ca) we did not need to know @pagesize because qemuGetDomainHupageMemPath() could deal with it being zero (value of zero means use the default hugetlbfs mount). But since for memfd we are not passing a path to hugetlbfs mount rather the page size value we need to know its value upfront. Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_command.c | 14 +++++++ ...memory-default-hugepage.x86_64-latest.args | 37 ++++++++++++++++ .../memfd-memory-default-hugepage.xml | 42 +++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + .../memfd-memory-default-hugepage.xml | 1 + tests/qemuxml2xmltest.c | 3 ++ 6 files changed, 98 insertions(+) create mode 100644 tests/qemuxml2argvdata/memfd-memory-default-hugepage.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/memfd-memory-default-hugepage.xml create mode 120000 tests/qemuxml2xmloutdata/memfd-memory-default-hugepage.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f81d20e5f7..ba1b56c2da 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3547,6 +3547,20 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps, pagesize = 0; needHugepage = false; useHugepage = false; + } else if (pagesize == 0) { + virHugeTLBFSPtr p; + + if (!cfg->nhugetlbfs) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("hugetlbfs filesystem is not mounted " + "or disabled by administrator config")); + goto cleanup; + } + + if (!(p = virFileGetDefaultHugepage(cfg->hugetlbfs, cfg->nhugetlbfs))) + p = &cfg->hugetlbfs[0]; + + pagesize = p->size; } if (!(props = virJSONValueNewObject())) diff --git a/tests/qemuxml2argvdata/memfd-memory-default-hugepage.x86_64-latest.args b/tests/qemuxml2argvdata/memfd-memory-default-hugepage.x86_64-latest.args new file mode 100644 index 0000000000..c582878a12 --- /dev/null +++ b/tests/qemuxml2argvdata/memfd-memory-default-hugepage.x86_64-latest.args @@ -0,0 +1,37 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-instance-00000092 \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-instance-00000092/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-instance-00000092/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-instance-00000092/.config \ +QEMU_AUDIO_DRV=none \ +/usr/bin/qemu-system-x86_64 \ +-name guest=instance-00000092,debug-threads=on \ +-S \ +-object secret,id=masterKey0,format=raw,\ +file=/tmp/lib/domain--1-instance-00000092/master-key.aes \ +-machine pc-i440fx-wily,accel=kvm,usb=off,dump-guest-core=off \ +-m 14336 \ +-mem-prealloc \ +-realtime mlock=off \ +-smp 8,sockets=1,cores=8,threads=1 \ +-object memory-backend-memfd,id=ram-node0,hugetlb=yes,hugetlbsize=2097152,\ +share=yes,size=15032385536,host-nodes=3,policy=preferred \ +-numa node,nodeid=0,cpus=0-7,memdev=ram-node0 \ +-uuid 126f2720-6f8e-45ab-a886-ec9277079a67 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server,nowait \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-boot strict=on \ +-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \ +-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3 \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\ +resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvdata/memfd-memory-default-hugepage.xml b/tests/qemuxml2argvdata/memfd-memory-default-hugepage.xml new file mode 100644 index 0000000000..45ff012711 --- /dev/null +++ b/tests/qemuxml2argvdata/memfd-memory-default-hugepage.xml @@ -0,0 +1,42 @@ +<domain type='kvm'> + <name>instance-00000092</name> + <uuid>126f2720-6f8e-45ab-a886-ec9277079a67</uuid> + <memory unit='KiB'>14680064</memory> + <currentMemory unit='KiB'>14680064</currentMemory> + <memoryBacking> + <hugepages/> + <source type='memfd'/> + <access mode='shared'/> + <allocation mode='immediate'/> + </memoryBacking> + <vcpu placement='static'>8</vcpu> + <numatune> + <memnode cellid='0' mode='preferred' nodeset='3'/> + </numatune> + <os> + <type arch='x86_64' machine='pc-i440fx-wily'>hvm</type> + <boot dev='hd'/> + </os> + <cpu> + <topology sockets='1' cores='8' threads='1'/> + <numa> + <cell id='0' cpus='0-7' memory='14680064' unit='KiB'/> + </numa> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <controller type='usb' index='0'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/> + </memballoon> + </devices> +</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 0c0dcae197..ae9b77eee6 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -3045,6 +3045,7 @@ mymain(void) QEMU_CAPS_KVM); DO_TEST_CAPS_LATEST("memfd-memory-numa"); + DO_TEST_CAPS_LATEST("memfd-memory-default-hugepage"); DO_TEST("cpu-check-none", QEMU_CAPS_KVM); DO_TEST("cpu-check-partial", QEMU_CAPS_KVM); diff --git a/tests/qemuxml2xmloutdata/memfd-memory-default-hugepage.xml b/tests/qemuxml2xmloutdata/memfd-memory-default-hugepage.xml new file mode 120000 index 0000000000..27d38522c2 --- /dev/null +++ b/tests/qemuxml2xmloutdata/memfd-memory-default-hugepage.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/memfd-memory-default-hugepage.xml \ No newline at end of file diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 4b8b0db0c6..a17cbdb633 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -1171,6 +1171,9 @@ mymain(void) DO_TEST("memfd-memory-numa", QEMU_CAPS_OBJECT_MEMORY_MEMFD, QEMU_CAPS_OBJECT_MEMORY_MEMFD_HUGETLB); + DO_TEST("memfd-memory-default-hugepage", + QEMU_CAPS_OBJECT_MEMORY_MEMFD, + QEMU_CAPS_OBJECT_MEMORY_MEMFD_HUGETLB); DO_TEST("acpi-table", NONE); -- 2.21.0

On Mon, Apr 01, 2019 at 04:04:37PM +0200, Michal Privoznik wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=1693066
Up until memfd introduction (in 24b74d187ca) we did not need to know @pagesize because qemuGetDomainHupageMemPath() could deal with it being zero (value of zero means use the default hugetlbfs mount). But since for memfd we are not passing a path to hugetlbfs mount rather the page size value we need to know its value upfront.
This phrasing makes it seem like getting the pagesize is being moved,
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_command.c | 14 +++++++ ...memory-default-hugepage.x86_64-latest.args | 37 ++++++++++++++++ .../memfd-memory-default-hugepage.xml | 42 +++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + .../memfd-memory-default-hugepage.xml | 1 + tests/qemuxml2xmltest.c | 3 ++ 6 files changed, 98 insertions(+)
but there are no deletions. I'd expect that now it will no longer be needed in qemuGetDomainHupageMemPath (sic).
create mode 100644 tests/qemuxml2argvdata/memfd-memory-default-hugepage.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/memfd-memory-default-hugepage.xml create mode 120000 tests/qemuxml2xmloutdata/memfd-memory-default-hugepage.xml
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f81d20e5f7..ba1b56c2da 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3547,6 +3547,20 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps, pagesize = 0; needHugepage = false; useHugepage = false; + } else if (pagesize == 0) { + virHugeTLBFSPtr p; + + if (!cfg->nhugetlbfs) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("hugetlbfs filesystem is not mounted " + "or disabled by administrator config")); + goto cleanup; + } + + if (!(p = virFileGetDefaultHugepage(cfg->hugetlbfs, cfg->nhugetlbfs))) + p = &cfg->hugetlbfs[0]; + + pagesize = p->size;
Given how big and beautiful qemuBuildMemoryBackendProps has become, this would look nicer in another wrapper. With the corresponding deletions in qemuGetDomainHupageMemPath: Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

On 4/2/19 2:57 PM, Ján Tomko wrote:
On Mon, Apr 01, 2019 at 04:04:37PM +0200, Michal Privoznik wrote:
https://bugzilla.redhat.com/show_bug.cgi?id=1693066
Up until memfd introduction (in 24b74d187ca) we did not need to know @pagesize because qemuGetDomainHupageMemPath() could deal with it being zero (value of zero means use the default hugetlbfs mount). But since for memfd we are not passing a path to hugetlbfs mount rather the page size value we need to know its value upfront.
This phrasing makes it seem like getting the pagesize is being moved,
Signed-off-by: Michal Privoznik <mprivozn@redhat.com> --- src/qemu/qemu_command.c | 14 +++++++ ...memory-default-hugepage.x86_64-latest.args | 37 ++++++++++++++++ .../memfd-memory-default-hugepage.xml | 42 +++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + .../memfd-memory-default-hugepage.xml | 1 + tests/qemuxml2xmltest.c | 3 ++ 6 files changed, 98 insertions(+)
but there are no deletions. I'd expect that now it will no longer be needed in qemuGetDomainHupageMemPath (sic).
In fact, it is. See below.
create mode 100644 tests/qemuxml2argvdata/memfd-memory-default-hugepage.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/memfd-memory-default-hugepage.xml create mode 120000 tests/qemuxml2xmloutdata/memfd-memory-default-hugepage.xml
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f81d20e5f7..ba1b56c2da 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3547,6 +3547,20 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps, pagesize = 0; needHugepage = false; useHugepage = false; + } else if (pagesize == 0) { + virHugeTLBFSPtr p; + + if (!cfg->nhugetlbfs) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("hugetlbfs filesystem is not mounted " + "or disabled by administrator config")); + goto cleanup; + } + + if (!(p = virFileGetDefaultHugepage(cfg->hugetlbfs, cfg->nhugetlbfs))) + p = &cfg->hugetlbfs[0]; + + pagesize = p->size;
Given how big and beautiful qemuBuildMemoryBackendProps has become, this would look nicer in another wrapper.
Okay.
With the corresponding deletions in qemuGetDomainHupageMemPath:
qemuGetDomainHupageMemPath is called when building -mem-path too (qemuBuildMemPathStr). And that's the place where pagesize can be 0 too.
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Thanks. Michal
participants (2)
-
Ján Tomko
-
Michal Privoznik