From nobody Sun Feb 8 16:31:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1605132471; cv=none; d=zohomail.com; s=zohoarc; b=cS0v++M1Fumg/glawpTB4aYDqpie6dwoEQts3UIKjSvj8V5e5fzw0X0WPxzheXrkwrpjsrPvfcsb2yyDs/z3/MS7mfY2NKMPxKQqKZTOINasNMoPsjEL3B24Ddml+Rrviej8imgKbr3yoiMiHWkbsqVKCtWO0SU+hcpb7mYmp60= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605132471; 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=GbXtOMRAPX3SkRziKrJBZfiX+o/lH+cpgzPDFdyyXcU=; b=ZvtGv9XJFgt6szjI4TEZn1isHRjTyyTDZyZ36XxA9rgLgkljv/2PnDYqraEoVzIpYQALYFEXrUnj1nodOHEHuIZSfFmqW2twSJUUoASQ4Y6DumFFFh26cGvo8B/uxq+HDfuKIJ2KZ5BMvr6/SSY5QBD02E5lPh/n6IiFBZssV9g= ARC-Authentication-Results: i=1; mx.zohomail.com; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1605132471759578.4463706477945; Wed, 11 Nov 2020 14:07:51 -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-79-Fv1j3ox8OJq1DRulgOHmTQ-1; Wed, 11 Nov 2020 17:07:48 -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 C2DDA6409A; Wed, 11 Nov 2020 22:07:42 +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 A2BC77366A; Wed, 11 Nov 2020 22:07:42 +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 6E99B18199CD; Wed, 11 Nov 2020 22:07:42 +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 0ABM7dC9006061 for ; Wed, 11 Nov 2020 17:07:39 -0500 Received: by smtp.corp.redhat.com (Postfix) id 27FF2115D346; Wed, 11 Nov 2020 22:07:39 +0000 (UTC) Received: from mimecast-mx02.redhat.com (mimecast03.extmail.prod.ext.rdu2.redhat.com [10.11.55.19]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 24157115D342 for ; Wed, 11 Nov 2020 22:07:39 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) (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 0C8F0811E76 for ; Wed, 11 Nov 2020 22:07:39 +0000 (UTC) Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-568-3mz6To1uPhmdpeeq3GAqgw-1; Wed, 11 Nov 2020 17:07:36 -0500 Received: by mail-qv1-f43.google.com with SMTP id ed14so1773384qvb.4 for ; Wed, 11 Nov 2020 14:07:36 -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.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 14:07:35 -0800 (PST) X-MC-Unique: Fv1j3ox8OJq1DRulgOHmTQ-1 X-MC-Unique: 3mz6To1uPhmdpeeq3GAqgw-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=GbXtOMRAPX3SkRziKrJBZfiX+o/lH+cpgzPDFdyyXcU=; b=KhacFiEeKvB7f40HEgB9JEXs75KtfuTPrMm1qXqKMryIP6Z8X9heVqynEGQvV0D8nE 5WfSiECCGszKDFb3tYdOaNErepM8lm7Pr/wy5EpzEhoLkctQPR14DJ3ioyln+cnvFL4w 3gLg3Mw4pWq4gX5+NrTJDkbX10bAiKYbehBvs9YTX+FI1K6bMy/6WeIhQL245Bp5Blo5 MC0wuwUt6akNEylwgp16+4IQ8jMb1XYZPaa3ZnP/LD/tgx4U1FK53nuV+2iJyizS8BjY VTjH8AA7KWBFyNLWQ/9Pn403Nagryb3sYJ807ZJVxbEHf4fN3fZ2b+SNt1abM/d6EeRU y3oA== X-Gm-Message-State: AOAM533zeXneroc6oLzgduhNf4osuMYskJOeOwFgZRn6E9EHxolIDBIp 3te0W7d0epuaMxgIemKBCzoxMP7gxt8= X-Google-Smtp-Source: ABdhPJzVuNPJ/Sa4/278mJSkAZ9x4v64967uAV+5hEf3l1cT2yFCSlNRw1cIVLDXmyKXggxaOcIolA== X-Received: by 2002:ad4:50a2:: with SMTP id d2mr26889151qvq.21.1605132455940; Wed, 11 Nov 2020 14:07:35 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 02/10] qemu_domain.c: align memory modules before calculating 'initialmem' Date: Wed, 11 Nov 2020 19:07:17 -0300 Message-Id: <20201111220725.356297-3-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.3 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" qemuDomainAlignMemorySizes() has an operation order problem. We are calculating 'initialmem' without aligning the memory modules first. Since we're aligning the dimms afterwards this can create inconsistencies in the end result. x86 has alignment of 1-2MiB and it's not severely impacted by it, but pSeries works with 256MiB alignment and the difference is noticeable. This is the case of the existing 'memory-hotplug-ppc64-nonuma' test. The test consists of a 2GiB (aligned value) guest with 2 ~520MiB dimms, both unaligned. 'initialmem' is calculated by taking total_mem and subtracting the dimms size (via virDomainDefGetMemoryInitial()), which wil give us 2GiB - 520MiB - 520MiB, ending up with a little more than an 1GiB of 'initialmem'. Note that this value is now unaligned, and will be aligned up via VIR_ROUND_UP(), and we'll end up with 'initialmem' of 1GiB + 256MiB. Given that the dimms are aligned later on, the end result for QEMU is that the guest will have a 'mem' size of 1310720k, plus the two 512 MiB dimms, exceeding in 256MiB the desired 2GiB memory and currentMemory specified in the XML. This behavior was found when trying to push ppc64 memory alignment to postparse, as done in the next patch. In that case, the memory modules are aligned before entering qemuDomainAlignMemorySizes() and the 'memory-hotplug-ppc64-nonuma' test started to fail. Fortunately the fix is simple: align the memory modules before calculating 'initialmem' in qemuDomainAlignMemorySizes(). Signed-off-by: Daniel Henrique Barboza --- src/qemu/qemu_domain.c | 42 ++++++++++--------- .../memory-hotplug-ppc64-nonuma.args | 2 +- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 375a9e5075..5a17887fa1 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -8083,25 +8083,9 @@ qemuDomainAlignMemorySizes(virDomainDefPtr def) virDomainNumaSetNodeMemorySize(def->numa, i, mem); } =20 - /* align initial memory size, if NUMA is present calculate it as total= of - * individual aligned NUMA node sizes */ - if (initialmem =3D=3D 0) - initialmem =3D VIR_ROUND_UP(virDomainDefGetMemoryInitial(def), ali= gn); - - if (initialmem > maxmemcapped) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("initial memory size overflowed after alignment")= ); - return -1; - } - - def->mem.max_memory =3D VIR_ROUND_UP(def->mem.max_memory, align); - if (def->mem.max_memory > maxmemkb) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("maximum memory size overflowed after alignment")= ); - return -1; - } - - /* Align memory module sizes */ + /* Align memory module sizes. This needs to occur before 'initialmem' + * calculation because virDomainDefGetMemoryInitial() uses the size + * of the modules in the math. */ for (i =3D 0; i < def->nmems; i++) { if (def->mems[i]->model =3D=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM && ARCH_IS_PPC64(def->os.arch)) { @@ -8122,6 +8106,26 @@ qemuDomainAlignMemorySizes(virDomainDefPtr def) } } =20 + /* Align initial memory size, if NUMA is present calculate it as total= of + * individual aligned NUMA node sizes. */ + if (initialmem =3D=3D 0) { + align =3D qemuDomainGetMemorySizeAlignment(def); + initialmem =3D VIR_ROUND_UP(virDomainDefGetMemoryInitial(def), ali= gn); + } + + if (initialmem > maxmemcapped) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("initial memory size overflowed after alignment")= ); + return -1; + } + + def->mem.max_memory =3D VIR_ROUND_UP(def->mem.max_memory, align); + if (def->mem.max_memory > maxmemkb) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("maximum memory size overflowed after alignment")= ); + return -1; + } + virDomainDefSetMemoryTotal(def, initialmem + hotplugmem); =20 return 0; diff --git a/tests/qemuxml2argvdata/memory-hotplug-ppc64-nonuma.args b/test= s/qemuxml2argvdata/memory-hotplug-ppc64-nonuma.args index 91cea9d8bf..78406f7f04 100644 --- a/tests/qemuxml2argvdata/memory-hotplug-ppc64-nonuma.args +++ b/tests/qemuxml2argvdata/memory-hotplug-ppc64-nonuma.args @@ -11,7 +11,7 @@ QEMU_AUDIO_DRV=3Dnone \ -name QEMUGuest1 \ -S \ -machine pseries,accel=3Dkvm,usb=3Doff,dump-guest-core=3Doff \ --m size=3D1310720k,slots=3D16,maxmem=3D4194304k \ +-m size=3D1048576k,slots=3D16,maxmem=3D4194304k \ -realtime mlock=3Doff \ -smp 1,sockets=3D1,cores=3D1,threads=3D1 \ -object memory-backend-ram,id=3Dmemdimm0,size=3D536870912 \ --=20 2.26.2