[libvirt] [PATCH v3] qemu: Forbid <memoryBacking><locked> without <memtune><hard_limit>

Andrea Bolognani posted 1 patch 7 years, 1 month ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1486473409-12106-1-git-send-email-abologna@redhat.com
src/qemu/qemu_domain.c                           | 10 ++++++++++
tests/qemuxml2argvdata/qemuxml2argv-mlock-on.xml |  3 +++
2 files changed, 13 insertions(+)
[libvirt] [PATCH v3] qemu: Forbid <memoryBacking><locked> without <memtune><hard_limit>
Posted by Andrea Bolognani 7 years, 1 month ago
In order for memory locking to work, the hard limit on memory
locking (and usage) has to be set appropriately by the user.

The documentation mentions the requirement already: with this
patch, it's going to be enforced by runtime checks as well,
by forbidding a non-compliant guest from being defined as well
as edited and started.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1316774
---
Changes from [v2]

  * Address review feedback:
    - move the check from BuildCommandLine to Validate.

Changes from [v1]

  * Address review feeback:
    - check in BuildCommandLine rather than in PostParse,
      so that non-compliant guests will merely fail to
      start rather than disappear completely.

[v1] https://www.redhat.com/archives/libvir-list/2017-February/msg00180.html
[v2] https://www.redhat.com/archives/libvir-list/2017-February/msg00214.html

 src/qemu/qemu_domain.c                           | 10 ++++++++++
 tests/qemuxml2argvdata/qemuxml2argv-mlock-on.xml |  3 +++
 2 files changed, 13 insertions(+)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index c6ce090..ce3aa69 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2831,6 +2831,16 @@ qemuDomainDefValidate(const virDomainDef *def,
         }
     }
 
+    /* Memory locking can only work properly if the memory locking limit
+     * for the QEMU process has been raised appropriately: the default one
+     * is extrememly low, so there's no way the guest will fit in there */
+    if (def->mem.locked && !virMemoryLimitIsSet(def->mem.hard_limit)) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+                       _("Setting <memoryBacking><locked> requires "
+                         "<memtune><hard_limit> to be set as well"));
+        goto cleanup;
+    }
+
     if (qemuDomainDefValidateVideo(def) < 0)
         goto cleanup;
 
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-mlock-on.xml b/tests/qemuxml2argvdata/qemuxml2argv-mlock-on.xml
index 20a5eaa..2046663 100644
--- a/tests/qemuxml2argvdata/qemuxml2argv-mlock-on.xml
+++ b/tests/qemuxml2argvdata/qemuxml2argv-mlock-on.xml
@@ -3,6 +3,9 @@
   <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
   <memory unit='KiB'>219136</memory>
   <currentMemory unit='KiB'>219136</currentMemory>
+  <memtune>
+    <hard_limit unit='KiB'>256000</hard_limit>
+  </memtune>
   <memoryBacking>
     <locked/>
   </memoryBacking>
-- 
2.7.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v3] qemu: Forbid <memoryBacking><locked> without <memtune><hard_limit>
Posted by Pavel Hrdina 7 years, 1 month ago
On Tue, Feb 07, 2017 at 02:16:49PM +0100, Andrea Bolognani wrote:
> In order for memory locking to work, the hard limit on memory
> locking (and usage) has to be set appropriately by the user.
> 
> The documentation mentions the requirement already: with this
> patch, it's going to be enforced by runtime checks as well,
> by forbidding a non-compliant guest from being defined as well
> as edited and started.
> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1316774
> ---
> Changes from [v2]
> 
>   * Address review feedback:
>     - move the check from BuildCommandLine to Validate.
> 
> Changes from [v1]
> 
>   * Address review feeback:
>     - check in BuildCommandLine rather than in PostParse,
>       so that non-compliant guests will merely fail to
>       start rather than disappear completely.
> 
> [v1] https://www.redhat.com/archives/libvir-list/2017-February/msg00180.html
> [v2] https://www.redhat.com/archives/libvir-list/2017-February/msg00214.html
> 
>  src/qemu/qemu_domain.c                           | 10 ++++++++++
>  tests/qemuxml2argvdata/qemuxml2argv-mlock-on.xml |  3 +++
>  2 files changed, 13 insertions(+)

ACK

Pavel
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v3] qemu: Forbid <memoryBacking><locked> without <memtune><hard_limit>
Posted by Andrea Bolognani 7 years, 1 month ago
On Tue, 2017-02-07 at 18:05 +0100, Pavel Hrdina wrote:
> ACK

Pushed, thanks :)

-- 
Andrea Bolognani / Red Hat / Virtualization

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list