render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
Blob Blame History Raw
From 55b75332573754c82426a1baff5f66221557939b Mon Sep 17 00:00:00 2001
Message-Id: <55b75332573754c82426a1baff5f66221557939b.1389183248.git.jdenemar@redhat.com>
From: Laine Stump <laine@laine.org>
Date: Tue, 24 Dec 2013 04:24:02 -0700
Subject: [PATCH] qemu: properly set MaxMemLock when hotplugging with VFIO

This resolves:

  https://bugzilla.redhat.com/show_bug.cgi?id=1035490

virProcessSetMaxMemLock() (which is a wrapper over prlimit(3)) expects
the memory size in bytes, but libvirt's domain definition (which was
being used by qemuDomainAttachHostPciDevice()) stores all memory
tuning parameters in KiB. This was being accounted for when setting
MaxMemLock at domain startup time (so cold-plugged devices would
work), but not for hotplug.

This patch simplifies the few lines that call
virProcessSetMemMaxLock(), and multiply the amount * 1024 so that
we're locking the correct amount of memory.

Note that even without this patch, hot-plug of a managed='no' device
would appear to succeed (at least on my system) while managed='yes'
would fail. I guess in one case the memory was coincidentally already
resident and in the other it wasn't. However, this apparently
successful hotplug would result in a device that was not fully usable
by the guest.

(cherry picked from commit 6d867f72f4f5fd75905e81b2d43350e7091fca64)

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 src/qemu/qemu_hotplug.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 24a2096..fae7e14 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1015,6 +1015,7 @@ int qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver,
     bool teardowncgroup = false;
     bool teardownlabel = false;
     int backend = hostdev->source.subsys.u.pci.backend;
+    unsigned long long memKB;
 
     if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs+1) < 0)
         return -1;
@@ -1032,16 +1033,18 @@ int qemuDomainAttachHostPciDevice(virQEMUDriverPtr driver,
             goto error;
         }
 
-        /* VFIO requires all of the guest's memory to be locked resident.
-         * In this case, the guest's memory may already be locked, but it
+        /* VFIO requires all of the guest's memory to be locked
+         * resident (plus an additional 1GiB to cover IO space). During
+         * hotplug, the guest's memory may already be locked, but it
          * doesn't hurt to "change" the limit to the same value.
+         * NB: the domain's memory tuning parameters are stored as
+         * Kibibytes, but virProcessSetMaxMemLock expects the value in
+         * bytes.
          */
-        if (vm->def->mem.hard_limit)
-            virProcessSetMaxMemLock(vm->pid, vm->def->mem.hard_limit);
-        else
-            virProcessSetMaxMemLock(vm->pid,
-                                    vm->def->mem.max_balloon + (1024 * 1024));
-
+        memKB = vm->def->mem.hard_limit
+            ? vm->def->mem.hard_limit
+            : vm->def->mem.max_balloon + (1024 * 1024);
+        virProcessSetMaxMemLock(vm->pid, memKB * 1024);
         break;
 
     case VIR_DOMAIN_HOSTDEV_PCI_BACKEND_DEFAULT:
-- 
1.8.5.2