]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: fix memlock without vIOMMU
authorJonathon Jongsma <jjongsma@redhat.com>
Thu, 17 Nov 2022 18:15:23 +0000 (12:15 -0600)
committerJonathon Jongsma <jjongsma@redhat.com>
Mon, 21 Nov 2022 21:37:41 +0000 (15:37 -0600)
When there is no vIOMMU, vfio devices don't need to lock the entire guest
memory per-device, but they still need to lock the entire guest memory to
share between all vfio devices. This memory accounting is not shared
with vDPA devices, so it should be added to the memlock limit separately.

Commit 8d5704e2 added support for multiple vfio/vdpa devices but
calculated the limits incorrectly when there were both vdpa and vfio
devices and no vIOMMU. In this case, the memory lock limit was not
increased separately for the vfio devices.

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

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
src/qemu/qemu_domain.c

index ef1a9c8c741adf8eb76a62f90d52f3830e65605c..8ae458ae45bfbcb2d2478bf7a489eddbf4249435 100644 (file)
@@ -9470,10 +9470,14 @@ qemuDomainGetMemLockLimitBytes(virDomainDef *def,
          */
         int factor = nvdpa;
 
-        if (def->iommu)
-            factor += nvfio;
+        if (nvfio || forceVFIO) {
+            if (nvfio && def->iommu)
+                factor += nvfio;
+            else
+                factor += 1;
+        }
 
-        memKB = MAX(factor, 1) * virDomainDefGetMemoryTotal(def) + 1024 * 1024;
+        memKB = factor * virDomainDefGetMemoryTotal(def) + 1024 * 1024;
     }
 
     return memKB << 10;