[libvirt PATCH] qemu: fix memlock without vIOMMU

Jonathon Jongsma posted 1 patch 1 year, 5 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20221117201339.277956-1-jjongsma@redhat.com
src/qemu/qemu_domain.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
[libvirt PATCH] qemu: fix memlock without vIOMMU
Posted by Jonathon Jongsma 1 year, 5 months ago
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=2111317

Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
---
 src/qemu/qemu_domain.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index ef1a9c8c74..8ae458ae45 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -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;
-- 
2.38.1
Re: [libvirt PATCH] qemu: fix memlock without vIOMMU
Posted by Laine Stump 1 year, 5 months ago
On 11/17/22 3:13 PM, Jonathon Jongsma wrote:
> 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=2111317
> 
> Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com>
> ---
>   src/qemu/qemu_domain.c | 10 +++++++---
>   1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
> index ef1a9c8c74..8ae458ae45 100644
> --- a/src/qemu/qemu_domain.c
> +++ b/src/qemu/qemu_domain.c
> @@ -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;

Reviewed-by: Laine Stump <laine@redhat.com>