From nobody Mon Feb 9 14:33:37 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 153148851979156.28823696357006; Fri, 13 Jul 2018 06:28:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0AFCA3082271; Fri, 13 Jul 2018 13:28:38 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id BBCCD608F7; Fri, 13 Jul 2018 13:28:37 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 703271841C5A; Fri, 13 Jul 2018 13:28:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6DDSZHV032480 for ; Fri, 13 Jul 2018 09:28:35 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6A51510FFE54; Fri, 13 Jul 2018 13:28:35 +0000 (UTC) Received: from localhost (unknown [10.36.112.12]) by smtp.corp.redhat.com (Postfix) with ESMTP id A479710FFE50; Fri, 13 Jul 2018 13:28:30 +0000 (UTC) From: marcandre.lureau@redhat.com To: libvir-list@redhat.com Date: Fri, 13 Jul 2018 15:28:10 +0200 Message-Id: <20180713132824.8655-4-marcandre.lureau@redhat.com> In-Reply-To: <20180713132824.8655-1-marcandre.lureau@redhat.com> References: <20180713132824.8655-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-loop: libvir-list@redhat.com Cc: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [libvirt] [RFC PATCH 03/17] qemu: use memory-backend-memfd if possible X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 13 Jul 2018 13:28:38 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 From: Marc-Andr=C3=A9 Lureau When the memory is shared and the source isn't specified to be a file, we can make use of memory-backend-memfd. Sealing is enabled by default in qemu, hugepage is easier to setup, which makes it a better choice than memory-backend-file. Signed-off-by: Marc-Andr=C3=A9 Lureau --- src/qemu/qemu_command.c | 20 ++++++++++++++++--- tests/qemuxml2argvdata/memfd.args | 28 +++++++++++++++++++++++++++ tests/qemuxml2argvdata/memfd.xml | 32 +++++++++++++++++++++++++++++++ tests/qemuxml2argvtest.c | 2 ++ 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 tests/qemuxml2argvdata/memfd.args create mode 100644 tests/qemuxml2argvdata/memfd.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index f1235099b2..45ab1f85ae 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3137,7 +3137,21 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backend= Props, if (!(props =3D virJSONValueNewObject())) return -1; =20 - if (useHugepage || mem->nvdimmPath || memAccess || + if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_MEMFD) && + memAccess =3D=3D VIR_DOMAIN_MEMORY_ACCESS_SHARED && + !mem->nvdimmPath && + def->mem.source !=3D VIR_DOMAIN_MEMORY_SOURCE_FILE) { + + backendType =3D "memory-backend-memfd"; + + if (useHugepage && + virJSONValueObjectAdd(props, + "b:hugetlb", true, + "U:hugetlbsize", pagesize * 1024, + NULL) < 0) + goto cleanup; + + } else if (useHugepage || mem->nvdimmPath || memAccess || def->mem.source =3D=3D VIR_DOMAIN_MEMORY_SOURCE_FILE) { =20 if (useHugepage) { @@ -7670,8 +7684,8 @@ qemuBuildNumaArgStr(virQEMUDriverConfigPtr cfg, * need to check which approach to use */ for (i =3D 0; i < ncells; i++) { if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_RAM) || - virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE)) { - + virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_FILE) || + virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_MEMORY_MEMFD)) { =20 if (implicit) rc =3D qemuBuildMemoryBackendStr(def, cfg, "ram-node", -1, diff --git a/tests/qemuxml2argvdata/memfd.args b/tests/qemuxml2argvdata/mem= fd.args new file mode 100644 index 0000000000..dda8e272ea --- /dev/null +++ b/tests/qemuxml2argvdata/memfd.args @@ -0,0 +1,28 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/home/test \ +USER=3Dtest \ +LOGNAME=3Dtest \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-i686 \ +-name QEMUGuest1 \ +-S \ +-machine pc,accel=3Dtcg,usb=3Doff,dump-guest-core=3Doff \ +-m 214 \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-object memory-backend-memfd,id=3Dram-node,size=3D224395264 \ +-numa node,nodeid=3D0,memdev=3Dram-node \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-QEMUGuest1/moni= tor.sock,server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-boot c \ +-usb \ +-drive file=3D/dev/HostVG/QEMUGuest1,format=3Draw,if=3Dnone,id=3Ddrive-ide= 0-0-0 \ +-device ide-drive,bus=3Dide.0,unit=3D0,drive=3Ddrive-ide0-0-0,id=3Dide0-0-= 0 \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x3 diff --git a/tests/qemuxml2argvdata/memfd.xml b/tests/qemuxml2argvdata/memf= d.xml new file mode 100644 index 0000000000..c60b169169 --- /dev/null +++ b/tests/qemuxml2argvdata/memfd.xml @@ -0,0 +1,32 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + + + + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i686 + + + +
+ + + + + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index a929e4314e..47bd2ab867 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -945,6 +945,8 @@ mymain(void) DO_TEST("pmu-feature", NONE); DO_TEST("pmu-feature-off", NONE); =20 + DO_TEST("memfd", + QEMU_CAPS_OBJECT_MEMORY_MEMFD); DO_TEST("hugepages", NONE); DO_TEST("hugepages-numa", QEMU_CAPS_PIIX_DISABLE_S3, QEMU_CAPS_PIIX_DISABLE_S4, --=20 2.18.0.129.ge3331758f1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list