render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
9119d9
From b6d5f5ac3f21362e2e790d3ad3bc3875652b6489 Mon Sep 17 00:00:00 2001
9119d9
Message-Id: <b6d5f5ac3f21362e2e790d3ad3bc3875652b6489@dist-git>
9119d9
From: Michal Privoznik <mprivozn@redhat.com>
9119d9
Date: Thu, 18 Sep 2014 14:39:57 +0200
9119d9
Subject: [PATCH] conf: Disallow nonexistent NUMA nodes for hugepages
9119d9
9119d9
https://bugzilla.redhat.com/show_bug.cgi?id=1135396
9119d9
9119d9
As of 136ad4974 it is possible to specify different huge pages per
9119d9
guest NUMA node. However, there's no check if nodeset specified in
9119d9
./hugepages/page contains only those guest NUMA nodes that exist.
9119d9
In other words with current code it is possible to define meaningless
9119d9
combination:
9119d9
9119d9
  <memoryBacking>
9119d9
    <hugepages>
9119d9
      <page size='1048576' unit='KiB' nodeset='0,2-3'/>
9119d9
      <page size='2048' unit='KiB' nodeset='1,4'/>
9119d9
    </hugepages>
9119d9
  </memoryBacking>
9119d9
  <vcpu placement='static'>4</vcpu>
9119d9
  <cpu>
9119d9
    <numa>
9119d9
      <cell id='0' cpus='0' memory='1048576'/>
9119d9
      <cell id='1' cpus='1' memory='1048576'/>
9119d9
      <cell id='2' cpus='2' memory='1048576'/>
9119d9
      <cell id='3' cpus='3' memory='1048576'/>
9119d9
    </numa>
9119d9
  </cpu>
9119d9
9119d9
Notice the node 4 in <hugepages/>?
9119d9
9119d9
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
9119d9
(cherry picked from commit ec982f6d929f3c2343d4ea9b06e49c23e6c526ba)
9119d9
9119d9
Conflicts:
9119d9
	tests/qemuxml2argvtest.c: Context as c7abf2c8 is not
9119d9
        backported yet.
9119d9
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
9119d9
---
9119d9
 src/qemu/qemu_command.c                            | 24 ++++++++++++
9119d9
 .../qemuxml2argv-hugepages-pages4.xml              | 45 ++++++++++++++++++++++
9119d9
 tests/qemuxml2argvtest.c                           |  2 +
9119d9
 3 files changed, 71 insertions(+)
9119d9
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages4.xml
9119d9
9119d9
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
9119d9
index 81395a8..45667d9 100644
9119d9
--- a/src/qemu/qemu_command.c
9119d9
+++ b/src/qemu/qemu_command.c
9119d9
@@ -6549,6 +6549,30 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg,
9119d9
         goto cleanup;
9119d9
     }
9119d9
 
9119d9
+    for (i = 0; i < def->mem.nhugepages; i++) {
9119d9
+        ssize_t next_bit, pos = 0;
9119d9
+
9119d9
+        if (!def->mem.hugepages[i].nodemask) {
9119d9
+            /* This is the master hugepage to use. Skip it as it has no
9119d9
+             * nodemask anyway. */
9119d9
+            continue;
9119d9
+        }
9119d9
+
9119d9
+        if (def->cpu && def->cpu->ncells) {
9119d9
+            /* Fortunately, we allow only guest NUMA nodes to be continuous
9119d9
+             * starting from zero. */
9119d9
+            pos = def->cpu->ncells - 1;
9119d9
+        }
9119d9
+
9119d9
+        next_bit = virBitmapNextSetBit(def->mem.hugepages[i].nodemask, pos);
9119d9
+        if (next_bit >= 0) {
9119d9
+            virReportError(VIR_ERR_XML_DETAIL,
9119d9
+                           _("hugepages: node %zd not found"),
9119d9
+                           next_bit);
9119d9
+            goto cleanup;
9119d9
+        }
9119d9
+    }
9119d9
+
9119d9
     for (i = 0; i < def->cpu->ncells; i++) {
9119d9
         int cellmem = VIR_DIV_UP(def->cpu->cells[i].mem, 1024);
9119d9
         def->cpu->cells[i].mem = cellmem * 1024;
9119d9
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages4.xml b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages4.xml
9119d9
new file mode 100644
9119d9
index 0000000..a3ed29b
9119d9
--- /dev/null
9119d9
+++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages4.xml
9119d9
@@ -0,0 +1,45 @@
9119d9
+<domain type='qemu'>
9119d9
+  <name>QEMUGuest1</name>
9119d9
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
9119d9
+  <memory unit='KiB'>4194304</memory>
9119d9
+  <currentMemory unit='KiB'>4194304</currentMemory>
9119d9
+  <memoryBacking>
9119d9
+    <hugepages>
9119d9
+      <page size='2048' unit='KiB' nodeset='1,4'/>
9119d9
+      <page size='1048576' unit='KiB' nodeset='0,2-3'/>
9119d9
+    </hugepages>
9119d9
+  </memoryBacking>
9119d9
+  <vcpu placement='static'>4</vcpu>
9119d9
+  <numatune>
9119d9
+    <memory mode='strict' nodeset='0-3'/>
9119d9
+    <memnode cellid='3' mode='strict' nodeset='3'/>
9119d9
+  </numatune>
9119d9
+  <os>
9119d9
+    <type arch='i686' machine='pc'>hvm</type>
9119d9
+    <boot dev='hd'/>
9119d9
+  </os>
9119d9
+  <cpu>
9119d9
+    <numa>
9119d9
+      <cell id='0' cpus='0' memory='1048576'/>
9119d9
+      <cell id='1' cpus='1' memory='1048576'/>
9119d9
+      <cell id='2' cpus='2' memory='1048576'/>
9119d9
+      <cell id='3' cpus='3' memory='1048576'/>
9119d9
+    </numa>
9119d9
+  </cpu>
9119d9
+  <clock offset='utc'/>
9119d9
+  <on_poweroff>destroy</on_poweroff>
9119d9
+  <on_reboot>restart</on_reboot>
9119d9
+  <on_crash>destroy</on_crash>
9119d9
+  <devices>
9119d9
+    <emulator>/usr/bin/qemu</emulator>
9119d9
+    <disk type='block' device='disk'>
9119d9
+      <source dev='/dev/HostVG/QEMUGuest1'/>
9119d9
+      <target dev='hda' bus='ide'/>
9119d9
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
9119d9
+    </disk>
9119d9
+    <controller type='usb' index='0'/>
9119d9
+    <controller type='ide' index='0'/>
9119d9
+    <controller type='pci' index='0' model='pci-root'/>
9119d9
+    <memballoon model='virtio'/>
9119d9
+  </devices>
9119d9
+</domain>
9119d9
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
9119d9
index 515058e..3b5f31a 100644
9119d9
--- a/tests/qemuxml2argvtest.c
9119d9
+++ b/tests/qemuxml2argvtest.c
9119d9
@@ -686,6 +686,8 @@ mymain(void)
9119d9
             QEMU_CAPS_OBJECT_MEMORY_FILE);
9119d9
     DO_TEST("hugepages-shared", QEMU_CAPS_MEM_PATH, QEMU_CAPS_OBJECT_MEMORY_RAM,
9119d9
             QEMU_CAPS_OBJECT_MEMORY_FILE);
9119d9
+    DO_TEST_FAILURE("hugepages-pages4", QEMU_CAPS_MEM_PATH,
9119d9
+            QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_OBJECT_MEMORY_FILE);
9119d9
     DO_TEST("nosharepages", QEMU_CAPS_MACHINE_OPT, QEMU_CAPS_MEM_MERGE);
9119d9
     DO_TEST("disk-cdrom", NONE);
9119d9
     DO_TEST("disk-cdrom-network-http", QEMU_CAPS_KVM, QEMU_CAPS_DEVICE,
9119d9
-- 
9119d9
2.1.0
9119d9