From nobody Fri May 3 05:44:18 2024 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 Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1502204669436650.7515224065503; Tue, 8 Aug 2017 08:04:29 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9FD73356ED; Tue, 8 Aug 2017 15:04:26 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B6B01845A2; Tue, 8 Aug 2017 15:04:25 +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 8156214B1E; Tue, 8 Aug 2017 15:04:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v78F4Kmt003119 for ; Tue, 8 Aug 2017 11:04:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id B9D56183D6; Tue, 8 Aug 2017 15:04:20 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3D2F095239 for ; Tue, 8 Aug 2017 15:04:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 9FD73356ED Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 8 Aug 2017 17:04:15 +0200 Message-Id: <6d9d7f5e3994296a26f5c6160d73455500671d2f.1502204645.git.mprivozn@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] qemuBuildMemoryBackendStr: Handle one more corner case 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: , MIME-Version: 1.0 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Tue, 08 Aug 2017 15:04:28 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1458638 This code is so complicated because we allow enabling the same bits at many places. Just like in this case: huge pages can be enabled by global element under or on per basis. To complicate things a bit more, users are allowed to not specify any specific page size in which case the default page size is used. And this is what is causing this bug. If no page size is specified, @pagesize is keeping value of zero throughout whole function. Therefore we need yet another boolean to hold [use, don't use] information as we can't sue @pagesize for that. Signed-off-by: Michal Privoznik --- src/qemu/qemu_command.c | 22 ++++++-- .../qemuxml2argv-hugepages-pages7.args | 35 ++++++++++++ .../qemuxml2argv-hugepages-pages7.xml | 65 ++++++++++++++++++= ++++ tests/qemuxml2argvtest.c | 2 + .../qemuxml2xmlout-hugepages-pages7.xml | 1 + tests/qemuxml2xmltest.c | 1 + 6 files changed, 120 insertions(+), 6 deletions(-) create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages7.ar= gs create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages7.xml create mode 120000 tests/qemuxml2xmloutdata/qemuxml2xmlout-hugepages-pages= 7.xml diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 604650596..68fc13706 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -3250,8 +3250,6 @@ qemuBuildMemoryBackendStr(virJSONValuePtr *backendPro= ps, virBitmapPtr autoNodeset, bool force) { - virDomainHugePagePtr master_hugepage =3D NULL; - virDomainHugePagePtr hugepage =3D NULL; virDomainNumatuneMemMode mode; const long system_page_size =3D virGetSystemPageSizeKB(); virDomainMemoryAccess memAccess =3D mem->access; @@ -3264,6 +3262,13 @@ qemuBuildMemoryBackendStr(virJSONValuePtr *backendPr= ops, bool nodeSpecified =3D virDomainNumatuneNodeSpecified(def->numa, mem->= targetNode); unsigned long long pagesize =3D mem->pagesize; bool needHugepage =3D !!pagesize; + bool useHugepage =3D !!pagesize; + + /* The difference between @needHugepage and @useHugepage is that the l= atter + * is true whenever huge page is defined for the current memory cell. + * Either directly, or transitively via global domain huge pages. The + * former is true whenever "memory-backend-file" must be used to satis= fy + * @useHugepage. */ =20 *backendProps =3D NULL; *backendType =3D NULL; @@ -3290,6 +3295,8 @@ qemuBuildMemoryBackendStr(virJSONValuePtr *backendPro= ps, mode =3D VIR_DOMAIN_NUMATUNE_MEM_STRICT; =20 if (pagesize =3D=3D 0) { + virDomainHugePagePtr master_hugepage =3D NULL; + virDomainHugePagePtr hugepage =3D NULL; bool thisHugepage =3D false; =20 /* Find the huge page size we want to use */ @@ -3327,8 +3334,10 @@ qemuBuildMemoryBackendStr(virJSONValuePtr *backendPr= ops, hugepage =3D master_hugepage; } =20 - if (hugepage) + if (hugepage) { pagesize =3D hugepage->size; + useHugepage =3D true; + } } =20 if (pagesize =3D=3D system_page_size) { @@ -3336,17 +3345,18 @@ qemuBuildMemoryBackendStr(virJSONValuePtr *backendP= rops, * of regular system page size, it's as if they * hasn't specified any huge pages at all. */ pagesize =3D 0; - hugepage =3D NULL; + needHugepage =3D false; + useHugepage =3D false; } =20 if (!(props =3D virJSONValueNewObject())) return -1; =20 - if (pagesize || mem->nvdimmPath || memAccess || + if (useHugepage || mem->nvdimmPath || memAccess || def->mem.source =3D=3D VIR_DOMAIN_MEMORY_SOURCE_FILE) { *backendType =3D "memory-backend-file"; =20 - if (pagesize) { + if (useHugepage) { if (qemuGetDomainHupageMemPath(def, cfg, pagesize, &memPath) <= 0) goto cleanup; prealloc =3D true; diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages7.args b/te= sts/qemuxml2argvdata/qemuxml2argv-hugepages-pages7.args new file mode 100644 index 000000000..e4229dce6 --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages7.args @@ -0,0 +1,35 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/home/test \ +USER=3Dtest \ +LOGNAME=3Dtest \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-x86_64 \ +-name fedora \ +-S \ +-M pc-i440fx-2.3 \ +-m size=3D1048576k,slots=3D16,maxmem=3D1099511627776k \ +-smp 2,sockets=3D2,cores=3D1,threads=3D1 \ +-mem-prealloc \ +-mem-path /dev/hugepages2M/libvirt/qemu/-1-fedora \ +-numa node,nodeid=3D0,cpus=3D0-1,mem=3D1024 \ +-object memory-backend-file,id=3Dmemdimm0,prealloc=3Dyes,\ +mem-path=3D/dev/hugepages1G/libvirt/qemu/-1-fedora,size=3D1073741824,\ +host-nodes=3D1-3,policy=3Dbind \ +-device pc-dimm,node=3D0,memdev=3Dmemdimm0,id=3Ddimm0,slot=3D0 \ +-object memory-backend-file,id=3Dmemdimm1,prealloc=3Dyes,\ +mem-path=3D/dev/hugepages2M/libvirt/qemu/-1-fedora,share=3Dno,size=3D53687= 0912 \ +-device pc-dimm,node=3D0,memdev=3Dmemdimm1,id=3Ddimm1,slot=3D1 \ +-uuid 63840878-0deb-4095-97e6-fc444d9bc9fa \ +-nographic \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-fedora/monitor.= sock,\ +server,nowait \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dreadline \ +-boot c \ +-usb \ +-drive file=3D/var/lib/libvirt/images/fedora.qcow2,format=3Dqcow2,if=3Dnon= e,\ +id=3Ddrive-virtio-disk0 \ +-device virtio-blk-pci,bus=3Dpci.0,addr=3D0x7,drive=3Ddrive-virtio-disk0,\ +id=3Dvirtio-disk0 \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x3 diff --git a/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages7.xml b/tes= ts/qemuxml2argvdata/qemuxml2argv-hugepages-pages7.xml new file mode 100644 index 000000000..d75cf5afa --- /dev/null +++ b/tests/qemuxml2argvdata/qemuxml2argv-hugepages-pages7.xml @@ -0,0 +1,65 @@ + + fedora + 63840878-0deb-4095-97e6-fc444d9bc9fa + 1099511627776 + 2621439 + 2621439 + + + + 2 + + hvm + + + + + + + + + + + + + + destroy + restart + restart + + /usr/bin/qemu-system-x86_64 + + + + +
+ + +
+ + + + + +
+ + + + 1-3 + 1048576 + + + 1048576 + 0 + +
+ + + + 524287 + 0 + +
+ + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 655c89bc3..993805231 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -844,6 +844,8 @@ mymain(void) QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_OBJECT_MEMORY_FILE); DO_TEST("hugepages-pages5", QEMU_CAPS_MEM_PATH); DO_TEST("hugepages-pages6", NONE); + DO_TEST("hugepages-pages7", QEMU_CAPS_MEM_PATH, + QEMU_CAPS_DEVICE_PC_DIMM, QEMU_CAPS_OBJECT_MEMORY_FILE); DO_TEST("hugepages-memaccess", QEMU_CAPS_OBJECT_MEMORY_FILE, QEMU_CAPS_OBJECT_MEMORY_RAM, QEMU_CAPS_DEVICE_PC_DIMM, QEMU_CAPS_NUMA); diff --git a/tests/qemuxml2xmloutdata/qemuxml2xmlout-hugepages-pages7.xml b= /tests/qemuxml2xmloutdata/qemuxml2xmlout-hugepages-pages7.xml new file mode 120000 index 000000000..9aafa6e95 --- /dev/null +++ b/tests/qemuxml2xmloutdata/qemuxml2xmlout-hugepages-pages7.xml @@ -0,0 +1 @@ +../qemuxml2argvdata/qemuxml2argv-hugepages-pages7.xml \ No newline at end of file diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 0d549adec..311b71356 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -433,6 +433,7 @@ mymain(void) DO_TEST("hugepages-pages4", NONE); DO_TEST("hugepages-pages5", NONE); DO_TEST("hugepages-pages6", NONE); + DO_TEST("hugepages-pages7", NONE); DO_TEST("hugepages-shared", NONE); DO_TEST("hugepages-memaccess", NONE); DO_TEST("hugepages-memaccess2", NONE); --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list