File fe39e1b1-qemu-Adjust-max-memlock-on-mdev-hotplug.patch of Package libvirt.16761

commit fe39e1b181bbe10aa08868fc132315a569bfb730
Author: Eric Farman <farman@linux.ibm.com>
Date:   Tue Sep 3 22:09:48 2019 +0200

    qemu: Adjust max memlock on mdev hotplug
    
    When starting a domain, we use the presence of a vfio-pci or
    mdev hostdev to determine if the memlock maximum needs to be
    increased.  But if we hotplug either of these devices, only the
    vfio-pci path gets that love.  This means that attaching a, say,
    vfio-ccw device will appear to succeed but the device may be
    unusable as the guest may see I/O errors on long CCW chains.
    The host, meanwhile, would be flooded with these messages:
    
      vfio_pin_page_external: Task qemu-system-s39 (11584) RLIMIT_MEMLOCK (65536) exceeded
    
    Let's adjust the maximum memlock value in the mdev hotplug path,
    so that the domain has the same value as if it were started with
    one or more mdev devices in its configuration.
    
    Signed-off-by: Eric Farman <farman@linux.ibm.com>
    Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
    Reviewed-by: Pavel Hrdina <phrdina@redhat.com>

Index: libvirt-5.1.0/src/qemu/qemu_hotplug.c
===================================================================
--- libvirt-5.1.0.orig/src/qemu/qemu_hotplug.c
+++ libvirt-5.1.0/src/qemu/qemu_hotplug.c
@@ -2991,6 +2991,7 @@ qemuDomainAttachMediatedDevice(virQEMUDr
     bool teardowncgroup = false;
     bool teardownlabel = false;
     bool teardowndevice = false;
+    bool teardownmemlock = false;
     qemuDomainObjPrivatePtr priv = vm->privateData;
     virDomainDeviceDef dev = { VIR_DOMAIN_DEVICE_HOSTDEV,
                                 { .hostdev = hostdev } };
@@ -3034,6 +3035,10 @@ qemuDomainAttachMediatedDevice(virQEMUDr
     if (VIR_REALLOC_N(vm->def->hostdevs, vm->def->nhostdevs + 1) < 0)
         goto cleanup;
 
+    if (qemuDomainAdjustMaxMemLockHostdev(vm, hostdev) < 0)
+        goto cleanup;
+    teardownmemlock = true;
+
     qemuDomainObjEnterMonitor(driver, vm);
     ret = qemuMonitorAddDevice(priv->mon, devstr);
     if (qemuDomainObjExitMonitor(driver, vm) < 0) {
@@ -3049,6 +3054,8 @@ qemuDomainAttachMediatedDevice(virQEMUDr
     ret = 0;
  cleanup:
     if (ret < 0) {
+        if (teardownmemlock && qemuDomainAdjustMaxMemLock(vm) < 0)
+            VIR_WARN("Unable to reset maximum locked memory on hotplug fail");
         if (teardowncgroup && qemuTeardownHostdevCgroup(vm, hostdev) < 0)
             VIR_WARN("Unable to remove host device cgroup ACL on hotplug fail");
         if (teardownlabel &&
openSUSE Build Service is sponsored by