3e5111
From 7c4ee4b1708fcd1b9fbfcb9de1be66c8294e6bbb Mon Sep 17 00:00:00 2001
3e5111
Message-Id: <7c4ee4b1708fcd1b9fbfcb9de1be66c8294e6bbb@dist-git>
3e5111
From: Michal Privoznik <mprivozn@redhat.com>
3e5111
Date: Tue, 13 Jun 2017 18:12:13 +0200
3e5111
Subject: [PATCH] qemu: Allow memAccess for hugepages again
3e5111
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1214369
3e5111
https://bugzilla.redhat.com/show_bug.cgi?id=1458638
3e5111
3e5111
Historically, we've always supported memAccess for domains backed
3e5111
by hugepages. However, somewhere along the way we've regressed
3e5111
and stopped allowing such configuration. Fix it.
3e5111
3e5111
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
3e5111
(cherry picked from commit 671d18594f42f24f7cb3f1b2c574ff4ddba0b183)
3e5111
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
3e5111
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
3e5111
---
3e5111
 src/qemu/qemu_command.c                            | 18 ++-----
3e5111
 .../qemuxml2argv-fd-memory-numa-topology2.args     |  2 +-
3e5111
 .../qemuxml2argv-hugepages-memaccess.args          | 42 +++++++++++++++
3e5111
 .../qemuxml2argv-hugepages-memaccess.xml           | 62 ++++++++++++++++++++++
3e5111
 tests/qemuxml2argvtest.c                           |  3 ++
3e5111
 .../qemuxml2xmlout-hugepages-memaccess.xml         |  1 +
3e5111
 tests/qemuxml2xmltest.c                            |  1 +
3e5111
 7 files changed, 114 insertions(+), 15 deletions(-)
3e5111
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess.args
3e5111
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess.xml
3e5111
 create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-hugepages-memaccess.xml
3e5111
3e5111
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
3e5111
index e220bf5ba0..c791214528 100644
3e5111
--- a/src/qemu/qemu_command.c
3e5111
+++ b/src/qemu/qemu_command.c
3e5111
@@ -3345,6 +3345,9 @@ qemuBuildMemoryBackendStr(virJSONValuePtr *backendProps,
3e5111
         memAccess = virDomainNumaGetNodeMemoryAccessMode(def->numa, mem->targetNode);
3e5111
     }
3e5111
 
3e5111
+    if (memAccess == VIR_DOMAIN_MEMORY_ACCESS_DEFAULT)
3e5111
+        memAccess = def->mem.access;
3e5111
+
3e5111
     if (virDomainNumatuneGetMode(def->numa, mem->targetNode, &mode) < 0 &&
3e5111
         virDomainNumatuneGetMode(def->numa, -1, &mode) < 0)
3e5111
         mode = VIR_DOMAIN_NUMATUNE_MEM_STRICT;
3e5111
@@ -3402,7 +3405,7 @@ qemuBuildMemoryBackendStr(virJSONValuePtr *backendProps,
3e5111
     if (!(props = virJSONValueNewObject()))
3e5111
         return -1;
3e5111
 
3e5111
-    if (pagesize || mem->nvdimmPath ||
3e5111
+    if (pagesize || mem->nvdimmPath || memAccess ||
3e5111
         def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_FILE) {
3e5111
         *backendType = "memory-backend-file";
3e5111
 
3e5111
@@ -3439,23 +3442,10 @@ qemuBuildMemoryBackendStr(virJSONValuePtr *backendProps,
3e5111
             break;
3e5111
 
3e5111
         case VIR_DOMAIN_MEMORY_ACCESS_DEFAULT:
3e5111
-            if (def->mem.access == VIR_DOMAIN_MEMORY_ACCESS_SHARED) {
3e5111
-                if (virJSONValueObjectAdd(props, "b:share", true, NULL) < 0)
3e5111
-                    goto cleanup;
3e5111
-            }
3e5111
-            break;
3e5111
-
3e5111
         case VIR_DOMAIN_MEMORY_ACCESS_LAST:
3e5111
             break;
3e5111
         }
3e5111
     } else {
3e5111
-        if (memAccess) {
3e5111
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
3e5111
-                           _("Shared memory mapping is supported "
3e5111
-                             "only with hugepages"));
3e5111
-            goto cleanup;
3e5111
-        }
3e5111
-
3e5111
         *backendType = "memory-backend-ram";
3e5111
     }
3e5111
 
3e5111
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args
3e5111
index 4420b9ab22..e36f98b907 100644
3e5111
--- a/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args
3e5111
+++ b/tests/qemuxml2argvdata/qemuxml2argv-fd-memory-numa-topology2.args
3e5111
@@ -12,7 +12,7 @@ QEMU_AUDIO_DRV=none \
3e5111
 -mem-prealloc \
3e5111
 -smp 20,sockets=1,cores=8,threads=1 \
3e5111
 -object memory-backend-file,id=ram-node0,mem-path=/var/lib/libvirt/qemu/ram,\
3e5111
-size=15032385536 \
3e5111
+share=no,size=15032385536 \
3e5111
 -numa node,nodeid=0,cpus=0-7,memdev=ram-node0 \
3e5111
 -object memory-backend-file,id=ram-node1,mem-path=/var/lib/libvirt/qemu/ram,\
3e5111
 share=yes,size=15032385536 \
3e5111
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess.args b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess.args
3e5111
new file mode 100644
3e5111
index 0000000000..d584d465b5
3e5111
--- /dev/null
3e5111
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess.args
3e5111
@@ -0,0 +1,42 @@
3e5111
+LC_ALL=C \
3e5111
+PATH=/bin \
3e5111
+HOME=/home/test \
3e5111
+USER=test \
3e5111
+LOGNAME=test \
3e5111
+QEMU_AUDIO_DRV=none \
3e5111
+/usr/bin/qemu-system-i686 \
3e5111
+-name QEMUGuest1 \
3e5111
+-S \
3e5111
+-M pc \
3e5111
+-m size=4194304k,slots=16,maxmem=8388608k \
3e5111
+-smp 4,sockets=4,cores=1,threads=1 \
3e5111
+-object memory-backend-file,id=ram-node0,prealloc=yes,\
3e5111
+mem-path=/dev/hugepages1G/libvirt/qemu/-1-QEMUGuest1,share=no,size=1073741824,\
3e5111
+host-nodes=0-3,policy=bind \
3e5111
+-numa node,nodeid=0,cpus=0,memdev=ram-node0 \
3e5111
+-object memory-backend-file,id=ram-node1,prealloc=yes,\
3e5111
+mem-path=/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1,share=yes,size=1073741824,\
3e5111
+host-nodes=0-3,policy=bind \
3e5111
+-numa node,nodeid=1,cpus=1,memdev=ram-node1 \
3e5111
+-object memory-backend-file,id=ram-node2,prealloc=yes,\
3e5111
+mem-path=/dev/hugepages1G/libvirt/qemu/-1-QEMUGuest1,share=no,size=1073741824,\
3e5111
+host-nodes=0-3,policy=bind \
3e5111
+-numa node,nodeid=2,cpus=2,memdev=ram-node2 \
3e5111
+-object memory-backend-file,id=ram-node3,prealloc=yes,\
3e5111
+mem-path=/dev/hugepages1G/libvirt/qemu/-1-QEMUGuest1,share=no,size=1073741824,\
3e5111
+host-nodes=3,policy=bind \
3e5111
+-numa node,nodeid=3,cpus=3,memdev=ram-node3 \
3e5111
+-object memory-backend-file,id=memdimm0,prealloc=yes,\
3e5111
+mem-path=/dev/hugepages2M/libvirt/qemu/-1-QEMUGuest1,share=yes,size=536870912,\
3e5111
+host-nodes=0-3,policy=bind \
3e5111
+-device pc-dimm,node=1,memdev=memdimm0,id=dimm0,slot=0,addr=4294967296 \
3e5111
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
3e5111
+-nographic \
3e5111
+-nodefaults \
3e5111
+-monitor unix:/tmp/lib/domain--1-QEMUGuest1/monitor.sock,server,nowait \
3e5111
+-no-acpi \
3e5111
+-boot c \
3e5111
+-usb \
3e5111
+-drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
3e5111
+-device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
3e5111
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
3e5111
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess.xml b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess.xml
3e5111
new file mode 100644
3e5111
index 0000000000..db9b9430e1
3e5111
--- /dev/null
3e5111
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-memaccess.xml
3e5111
@@ -0,0 +1,62 @@
3e5111
+<domain type='qemu'>
3e5111
+  <name>QEMUGuest1</name>
3e5111
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
3e5111
+  <maxMemory slots='16' unit='KiB'>8388608</maxMemory>
3e5111
+  <memory unit='KiB'>4194304</memory>
3e5111
+  <currentMemory unit='KiB'>4194304</currentMemory>
3e5111
+  <memoryBacking>
3e5111
+    <hugepages>
3e5111
+      <page size='2048' unit='KiB' nodeset='1'/>
3e5111
+      <page size='1048576' unit='KiB' nodeset='0,2-3'/>
3e5111
+    </hugepages>
3e5111
+    <access mode='private'/>
3e5111
+  </memoryBacking>
3e5111
+  <vcpu placement='static'>4</vcpu>
3e5111
+  <numatune>
3e5111
+    <memory mode='strict' nodeset='0-3'/>
3e5111
+    <memnode cellid='3' mode='strict' nodeset='3'/>
3e5111
+  </numatune>
3e5111
+  <os>
3e5111
+    <type arch='i686' machine='pc'>hvm</type>
3e5111
+    <boot dev='hd'/>
3e5111
+  </os>
3e5111
+  <cpu>
3e5111
+    <numa>
3e5111
+      <cell id='0' cpus='0' memory='1048576' unit='KiB'/>
3e5111
+      <cell id='1' cpus='1' memory='1048576' unit='KiB' memAccess='shared'/>
3e5111
+      <cell id='2' cpus='2' memory='1048576' unit='KiB' memAccess='private'/>
3e5111
+      <cell id='3' cpus='3' memory='1048576' unit='KiB'/>
3e5111
+    </numa>
3e5111
+  </cpu>
3e5111
+  <clock offset='utc'/>
3e5111
+  <on_poweroff>destroy</on_poweroff>
3e5111
+  <on_reboot>restart</on_reboot>
3e5111
+  <on_crash>destroy</on_crash>
3e5111
+  <devices>
3e5111
+    <emulator>/usr/bin/qemu-system-i686</emulator>
3e5111
+    <disk type='block' device='disk'>
3e5111
+      <source dev='/dev/HostVG/QEMUGuest1'/>
3e5111
+      <target dev='hda' bus='ide'/>
3e5111
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
3e5111
+    </disk>
3e5111
+    <controller type='usb' index='0'>
3e5111
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/>
3e5111
+    </controller>
3e5111
+    <controller type='ide' index='0'>
3e5111
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x1'/>
3e5111
+    </controller>
3e5111
+    <controller type='pci' index='0' model='pci-root'/>
3e5111
+    <input type='mouse' bus='ps2'/>
3e5111
+    <input type='keyboard' bus='ps2'/>
3e5111
+    <memballoon model='virtio'>
3e5111
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
3e5111
+    </memballoon>
3e5111
+    <memory model='dimm'>
3e5111
+      <target>
3e5111
+        <size unit='KiB'>524288</size>
3e5111
+        <node>1</node>
3e5111
+      </target>
3e5111
+      <address type='dimm' slot='0' base='0x100000000'/>
3e5111
+    </memory>
3e5111
+  </devices>
3e5111
+</domain>
3e5111
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
3e5111
index 175037bf96..77e52bd33b 100644
3e5111
--- a/tests/qemuxml2argvtest.c
3e5111
+++ b/tests/qemuxml2argvtest.c
3e5111
@@ -827,6 +827,9 @@ mymain(void)
3e5111
             QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_OBJECT_MEMORY_FILE);
3e5111
     DO_TEST("hugepages-pages5", QEMU_CAPS_MEM_PATH);
3e5111
     DO_TEST("hugepages-pages6", NONE);
3e5111
+    DO_TEST("hugepages-memaccess", QEMU_CAPS_OBJECT_MEMORY_FILE,
3e5111
+            QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_DEVICE_PC_DIMM,
3e5111
+            QEMU_CAPS_NUMA);
3e5111
     DO_TEST("nosharepages", QEMU_CAPS_MACHINE_OPT, QEMU_CAPS_MEM_MERGE);
3e5111
     DO_TEST("disk-cdrom", NONE);
3e5111
     DO_TEST("disk-iscsi", NONE);
3e5111
diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-hugepages-memaccess.xml b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hugepages-memaccess.xml
3e5111
new file mode 120000
3e5111
index 0000000000..23cef8e67d
3e5111
--- /dev/null
3e5111
+++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hugepages-memaccess.xml
3e5111
@@ -0,0 +1 @@
3e5111
+../qemuxml2argvdata/qemuxml2argv-hugepages-memaccess.xml
3e5111
\ No newline at end of file
3e5111
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
3e5111
index 72eac5e716..511d1b3fb9 100644
3e5111
--- a/tests/qemuxml2xmltest.c
3e5111
+++ b/tests/qemuxml2xmltest.c
3e5111
@@ -420,6 +420,7 @@ mymain(void)
3e5111
     DO_TEST("hugepages-pages2", NONE);
3e5111
     DO_TEST("hugepages-pages3", NONE);
3e5111
     DO_TEST("hugepages-shared", NONE);
3e5111
+    DO_TEST("hugepages-memaccess", NONE);
3e5111
     DO_TEST("nosharepages", NONE);
3e5111
     DO_TEST("restore-v2", NONE);
3e5111
     DO_TEST("migrate", NONE);
3e5111
-- 
3e5111
2.13.1
3e5111