From nobody Sun Feb 8 19:40:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1605132578; cv=none; d=zohomail.com; s=zohoarc; b=jbpx1oyJx7YQgtc75rFgqrr4D/xL4jRUd71OSwI49inCh7mgpr8sAxoXrTs8VU4t13Mb/+oc/5E4gQ2mlBBa20Ysm/OdlCLvNiq5B/HUJo/gdO9BySQeq2alR+5SmKTp7UV6sbYIMq8+urQ2KLPZc6WrWzSEd8aN8Z7KJQkybDU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605132578; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ukzmyI4mrZjsEjDywtJh9ODro2d5lzhg7Ee67pGLtxA=; b=Lxe0pSgj+ZLT0L90s3zkSs1LC2+9uLMWl4+rv2bCHT+v132wvsL+RVvNPefHaeHkiyLDxa4jpRyi4cO0rIJbk1Qdpa6Xc45bNsypR9vtJeYgtWJdJi0hlcpoWHdlGPffonB4gFyMtsDfUgeUCUZYDvGywiD4zy5anBpCw11CGEo= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1605132578049923.0980641770186; Wed, 11 Nov 2020 14:09:38 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-6-46M3t9vBPCex4qHBELEp6w-1; Wed, 11 Nov 2020 17:09:34 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id C10F38DFB42; Wed, 11 Nov 2020 22:09:28 +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 9D5AE73672; Wed, 11 Nov 2020 22:09:28 +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 640AA5810C; Wed, 11 Nov 2020 22:09:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 0ABM7kZP006110 for ; Wed, 11 Nov 2020 17:07:46 -0500 Received: by smtp.corp.redhat.com (Postfix) id 167FE202278F; Wed, 11 Nov 2020 22:07:46 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast01.extmail.prod.ext.rdu2.redhat.com [10.11.55.17]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0F20D2022794 for ; Wed, 11 Nov 2020 22:07:43 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [207.211.31.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id B159C85829F for ; Wed, 11 Nov 2020 22:07:43 +0000 (UTC) Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-257-0dwGKn_4NSWz2MqU1PW9AA-1; Wed, 11 Nov 2020 17:07:41 -0500 Received: by mail-qk1-f181.google.com with SMTP id r7so3424417qkf.3 for ; Wed, 11 Nov 2020 14:07:41 -0800 (PST) Received: from rekt.ibmuc.com ([2804:431:c7c7:b9cd:904e:d02:53c4:1c05]) by smtp.gmail.com with ESMTPSA id a200sm3427842qkb.66.2020.11.11.14.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 14:07:40 -0800 (PST) X-MC-Unique: 46M3t9vBPCex4qHBELEp6w-1 X-MC-Unique: 0dwGKn_4NSWz2MqU1PW9AA-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ukzmyI4mrZjsEjDywtJh9ODro2d5lzhg7Ee67pGLtxA=; b=SYiAKP4mM548pCU1xWV7yzNQJuo+Etp3Luk+62reQR6q/IEUWhYnn72x7cg86e+B6m vYwm9iwSf92dMyfyw21QEAtwvTuj7MNVH90JS+WxySP0UQpUIESIhfLsKjxuT6/Sm0wl FGLBF2Djd9phlC4xUW051yMHSUlfOwnyfGFj1YDuFQUDBcv5KA7PF5vLTaKs2A0le2J/ lm4eUbCF1LR7Wi7IIhkdPHHFJRBSCAqtGOSxmTi/vQMFeuEHYA5OTjue6z7+Bn9yw+xP LEz9xDotWp8bU0bDT46TsSFdeOcHGoPmVFU76NtSIbJOQDGPFsxjavvICEQQnDvhWO9w 5VOg== X-Gm-Message-State: AOAM530/Oa4R1MbZ6cbFwgnFskHHHLhpRvastSUmak8DmudDM1ejPKP2 zybtDxw2vxVlrmAyHYJmStwEpr+dV20zhg== X-Google-Smtp-Source: ABdhPJyjNG1YvQVe44UkcVylJgSCPvYEbtRicwEt7rNhf+X9kQ9xWhmZl51ydk0338I8FpeAu3qovg== X-Received: by 2002:ae9:dcc1:: with SMTP id q184mr28415429qkf.436.1605132460742; Wed, 11 Nov 2020 14:07:40 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 05/10] qemu_domain.c: align x86 memory module in post parse time Date: Wed, 11 Nov 2020 19:07:20 -0300 Message-Id: <20201111220725.356297-6-danielhb413@gmail.com> In-Reply-To: <20201111220725.356297-1-danielhb413@gmail.com> References: <20201111220725.356297-1-danielhb413@gmail.com> MIME-Version: 1.0 X-Mimecast-Impersonation-Protect: Policy=CLT - Impersonation Protection Definition; Similar Internal Domain=false; Similar Monitored External Domain=false; Custom External Domain=false; Mimecast External Domain=false; Newly Observed Domain=false; Internal User Name=false; Custom Display Name List=false; Reply-to Address Mismatch=false; Targeted Threat Dictionary=false; Mimecast Threat Dictionary=false; Custom Threat Dictionary=false X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: libvir-list@redhat.com Cc: Daniel Henrique Barboza 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: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This is already being done for pSeries guests, so let's extend the treatment for x86. The difference here is that the existing x86 alignment in the QEMU driver might be restricted only to QEMU, meaning that we can't put it in virDomainMemoryDefPostParse() without infering that all hypervisors would handle it the same way. Instead, let's create a qemuDomainMemoryDefPostParse() that will be called in qemuDomainDeviceDefPostParse() to do that. After this change, def->nmems will always be aligned after parsing time. qemuDomainAlignMemorySizes() doesn't need to align each memory module before calculating 'hotplugmem'. We'll also generated aligned values in the resulting XML as well. Some xml2xml tests were changed to reflect this new behavior. Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_domain.c | 45 +++++++++++-------- tests/qemuxml2argvdata/hugepages-nvdimm.xml | 2 +- .../memory-hotplug-nvdimm-access.xml | 2 +- .../memory-hotplug-nvdimm-align.xml | 2 +- .../memory-hotplug-nvdimm-label.xml | 2 +- .../memory-hotplug-nvdimm-pmem.xml | 2 +- .../memory-hotplug-nvdimm-readonly.xml | 2 +- .../memory-hotplug-nvdimm.xml | 2 +- tests/qemuxml2argvdata/pages-dimm-discard.xml | 2 +- .../memory-hotplug-dimm.xml | 4 +- 10 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index e40c122311..c06c33f8d0 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5343,6 +5343,23 @@ qemuDomainTPMDefPostParse(virDomainTPMDefPtr tpm, } =20 =20 +static int +qemuDomainMemoryDefPostParse(virDomainMemoryDefPtr mem, + virArch arch) +{ + /* For x86, dimm memory modules require 2MiB alignment rather than + * the 1MiB we are using elsewhere. */ + unsigned int x86MemoryModuleSizeAlignment =3D 2048; + + /* ppc64 memory module alignment is done in + * virDomainMemoryDefPostParse(). */ + if (!ARCH_IS_PPC64(arch)) + mem->size =3D VIR_ROUND_UP(mem->size, x86MemoryModuleSizeAlignment= ); + + return 0; +} + + static int qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr dev, const virDomainDef *def, @@ -5400,6 +5417,10 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr d= ev, ret =3D qemuDomainTPMDefPostParse(dev->data.tpm, def->os.arch); break; =20 + case VIR_DOMAIN_DEVICE_MEMORY: + ret =3D qemuDomainMemoryDefPostParse(dev->data.memory, def->os.arc= h); + break; + case VIR_DOMAIN_DEVICE_LEASE: case VIR_DOMAIN_DEVICE_FS: case VIR_DOMAIN_DEVICE_INPUT: @@ -5412,7 +5433,6 @@ qemuDomainDeviceDefPostParse(virDomainDeviceDefPtr de= v, case VIR_DOMAIN_DEVICE_MEMBALLOON: case VIR_DOMAIN_DEVICE_NVRAM: case VIR_DOMAIN_DEVICE_RNG: - case VIR_DOMAIN_DEVICE_MEMORY: case VIR_DOMAIN_DEVICE_IOMMU: case VIR_DOMAIN_DEVICE_AUDIO: ret =3D 0; @@ -8042,15 +8062,6 @@ qemuDomainGetMemorySizeAlignment(const virDomainDef = *def) } =20 =20 -static unsigned long long -qemuDomainGetMemoryModuleSizeAlignment(void) -{ - /* For x86, dimm memory modules require 2MiB alignment rather than - * the 1MiB we are using elsewhere. */ - return 2048; -} - - int qemuDomainAlignMemorySizes(virDomainDefPtr def) { @@ -8077,16 +8088,12 @@ qemuDomainAlignMemorySizes(virDomainDefPtr def) virDomainNumaSetNodeMemorySize(def->numa, i, mem); } =20 - /* Align memory module sizes. This needs to occur before 'initialmem' - * calculation because virDomainDefGetMemoryInitial() uses the size - * of the modules in the math. */ + /* Calculate hotplugmem. The memory modules are already aligned at this + * point: + * + * - ppc64 mem modules are being aligned by virDomainMemoryDefPostPars= e(); + * - x86 mem modules are being aligned by qemuDomainMemoryDefPostParse= (). */ for (i =3D 0; i < def->nmems; i++) { - /* ppc64 memory modules are aligned by virDomainMemoryDefPostParse= (). */ - if (!ARCH_IS_PPC64(def->os.arch)) { - align =3D qemuDomainGetMemoryModuleSizeAlignment(); - def->mems[i]->size =3D VIR_ROUND_UP(def->mems[i]->size, align); - } - hotplugmem +=3D def->mems[i]->size; =20 if (def->mems[i]->size > maxmemkb) { diff --git a/tests/qemuxml2argvdata/hugepages-nvdimm.xml b/tests/qemuxml2ar= gvdata/hugepages-nvdimm.xml index 144d02b56e..d356ad12a8 100644 --- a/tests/qemuxml2argvdata/hugepages-nvdimm.xml +++ b/tests/qemuxml2argvdata/hugepages-nvdimm.xml @@ -39,7 +39,7 @@ /tmp/nvdimm - 523264 + 524288 0
diff --git a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-access.xml b/test= s/qemuxml2argvdata/memory-hotplug-nvdimm-access.xml index a1cc1264eb..4ac5589076 100644 --- a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-access.xml +++ b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-access.xml @@ -48,7 +48,7 @@ /tmp/nvdimm - 523264 + 524288 0
diff --git a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-align.xml b/tests= /qemuxml2argvdata/memory-hotplug-nvdimm-align.xml index 018a693aaf..2436b1a1af 100644 --- a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-align.xml +++ b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-align.xml @@ -49,7 +49,7 @@ 2048 - 523264 + 524288 0
diff --git a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-label.xml b/tests= /qemuxml2argvdata/memory-hotplug-nvdimm-label.xml index c9d54a6088..6e8902a25e 100644 --- a/tests/qemuxml2argvdata/memory-hotplug-nvdimm-label.xml +++ b/tests/qemuxml2argvdata/memory-hotplug-nvdimm-label.xml @@ -48,7 +48,7 @@ /tmp/nvdimm - 523264 + 524288 0