From nobody Wed May 1 20:36:04 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; 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 1534758530606618.7220980547; Mon, 20 Aug 2018 02:48:50 -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 592ED81116; Mon, 20 Aug 2018 09:48:44 +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 55CED2D0A4; Mon, 20 Aug 2018 09:48:43 +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 5D15718005CF; Mon, 20 Aug 2018 09:48:41 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w7K9mej6007145 for ; Mon, 20 Aug 2018 05:48:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 214292142F22; Mon, 20 Aug 2018 09:48:40 +0000 (UTC) Received: from lhuang.nay.redhat.com (unknown [10.66.6.19]) by smtp.corp.redhat.com (Postfix) with ESMTP id CF2792142F20; Mon, 20 Aug 2018 09:48:36 +0000 (UTC) From: Luyao Huang To: libvir-list@redhat.com Date: Mon, 20 Aug 2018 17:48:33 +0800 Message-Id: <1534758513-21040-1-git-send-email-lhuang@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-loop: libvir-list@redhat.com Cc: Luyao Huang Subject: [libvirt] [PATCH] qemu: domain: validate memory access during validate domain config 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.28]); Mon, 20 Aug 2018 09:48:48 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" commit 6534b3c4 try to raise an error when there is no numa nodes but set access=3D'shared' in domain config. In that commit, we add a memory acc= ess validate function for memory device, but this check is not related to memory device and won't work if there is no memory device in guest xml. Move the memory access related check in the domain config validate function, and simplify the unit test xml to avoid other error. https://bugzilla.redhat.com/show_bug.cgi?id=3D1448149#c14 Signed-off-by: Luyao Huang --- src/qemu/qemu_domain.c | 55 +++++++++++----------- tests/qemuxml2argvdata/hugepages-memaccess3.xml | 62 +--------------------= ---- tests/qemuxml2argvtest.c | 6 +-- 3 files changed, 32 insertions(+), 91 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index f570081..f0c461b 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -3888,6 +3888,29 @@ qemuDomainDefValidateFeatures(const virDomainDef *de= f, =20 =20 static int +qemuDomainDefValidateMemory(const virDomainDef *def) +{ + const long system_page_size =3D virGetSystemPageSizeKB(); + + /* We can't guarantee any other mem.access + * if no guest NUMA nodes are defined. */ + if (def->mem.nhugepages !=3D 0 && + def->mem.hugepages[0].size !=3D system_page_size && + virDomainNumaGetNodeCount(def->numa) =3D=3D 0 && + def->mem.access !=3D VIR_DOMAIN_MEMORY_ACCESS_DEFAULT && + def->mem.access !=3D VIR_DOMAIN_MEMORY_ACCESS_PRIVATE) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("memory access mode '%s' not supported " + "without guest numa node"), + virDomainMemoryAccessTypeToString(def->mem.access)); + return -1; + } + + return 0; +} + + +static int qemuDomainDefValidate(const virDomainDef *def, virCapsPtr caps ATTRIBUTE_UNUSED, void *opaque) @@ -4009,6 +4032,9 @@ qemuDomainDefValidate(const virDomainDef *def, if (qemuDomainDefValidateFeatures(def, qemuCaps) < 0) goto cleanup; =20 + if (qemuDomainDefValidateMemory(def) < 0) + goto cleanup; + ret =3D 0; =20 cleanup: @@ -5531,30 +5557,6 @@ qemuDomainDeviceDefValidateController(const virDomai= nControllerDef *controller, =20 =20 static int -qemuDomainDeviceDefValidateMemory(const virDomainMemoryDef *memory ATTRIBU= TE_UNUSED, - const virDomainDef *def) -{ - const long system_page_size =3D virGetSystemPageSizeKB(); - - /* We can't guarantee any other mem.access - * if no guest NUMA nodes are defined. */ - if (def->mem.nhugepages !=3D 0 && - def->mem.hugepages[0].size !=3D system_page_size && - virDomainNumaGetNodeCount(def->numa) =3D=3D 0 && - def->mem.access !=3D VIR_DOMAIN_MEMORY_ACCESS_DEFAULT && - def->mem.access !=3D VIR_DOMAIN_MEMORY_ACCESS_PRIVATE) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("memory access mode '%s' not supported " - "without guest numa node"), - virDomainMemoryAccessTypeToString(def->mem.access)); - return -1; - } - - return 0; -} - - -static int qemuDomainDeviceDefValidateVsock(const virDomainVsockDef *vsock, const virDomainDef *def, virQEMUCapsPtr qemuCaps) @@ -5712,10 +5714,6 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef= *dev, qemuCaps); break; =20 - case VIR_DOMAIN_DEVICE_MEMORY: - ret =3D qemuDomainDeviceDefValidateMemory(dev->data.memory, def); - break; - case VIR_DOMAIN_DEVICE_VSOCK: ret =3D qemuDomainDeviceDefValidateVsock(dev->data.vsock, def, qem= uCaps); break; @@ -5737,6 +5735,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef = *dev, case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_NVRAM: case VIR_DOMAIN_DEVICE_SHMEM: + case VIR_DOMAIN_DEVICE_MEMORY: case VIR_DOMAIN_DEVICE_PANIC: case VIR_DOMAIN_DEVICE_IOMMU: case VIR_DOMAIN_DEVICE_NONE: diff --git a/tests/qemuxml2argvdata/hugepages-memaccess3.xml b/tests/qemuxm= l2argvdata/hugepages-memaccess3.xml index 8ec38d8..43c3ec6 100644 --- a/tests/qemuxml2argvdata/hugepages-memaccess3.xml +++ b/tests/qemuxml2argvdata/hugepages-memaccess3.xml @@ -12,76 +12,18 @@ hvm - - - - - - - - - - destroy restart destroy - - - - /usr/bin/qemu-system-x86_64 - - - - - -
- - -
- + - -
- - -
- - -
- - - - - - - - - - - -
- - - - - - - -