From nobody Sun Feb 8 16:31:00 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=1605132766; cv=none; d=zohomail.com; s=zohoarc; b=ONu8HDvAxRBMh/Si8zCi8BSLZhkfP/jqG629igrBGsHPiRbjbxventlxiRB9ApGCo41R1Y8PhXli6CcUMbS43E26d/MvMZ408GBNQ7QodbDO5Sk2HI9HEpVPGqu5RBHdv8K+og6bSrk93qmiAsyBi44UzvbO4ylytLizeJ1Jw1o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1605132766; 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=+dCkezk6O2naFuAd1mqVt9Mp30/Tj+kl2acF6ggNnVM=; b=HiL8HviAPg3kyWqFbQ3yGkTK1A3bP15DTzQv2rNCZi2PfVT0SVN+7+4cXUr4Rd8Pwr71wft4qvjTPpO/RkaFFCPDUrZec7aL8BIxZdJexcft5HicYamNULXXnxYI7D2Oy+0zKSZMAMhG4B0fEKO/lb9jagXlclQPFhdTnUI/1Ss= 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 1605132766075174.9059181942439; Wed, 11 Nov 2020 14:12:46 -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-526-itr3uT6wONqSHMtJhnZgHA-1; Wed, 11 Nov 2020 17:12:42 -0500 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 mimecast-mx01.redhat.com (Postfix) with ESMTPS id B29A61084D6C; Wed, 11 Nov 2020 22:12:37 +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 2AF5755792; Wed, 11 Nov 2020 22:12: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 902A058103; Wed, 11 Nov 2020 22:12:36 +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 0ABM7lCV006119 for ; Wed, 11 Nov 2020 17:07:47 -0500 Received: by smtp.corp.redhat.com (Postfix) id 75A402157F45; Wed, 11 Nov 2020 22:07:47 +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 7007F2166BA3 for ; Wed, 11 Nov 2020 22:07:45 +0000 (UTC) Received: from us-smtp-1.mimecast.com (us-smtp-1.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 1FDBC85828F for ; Wed, 11 Nov 2020 22:07:45 +0000 (UTC) Received: from mail-qk1-f176.google.com (mail-qk1-f176.google.com [209.85.222.176]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-407-3_55TcA5O_aqJTPBqWKC9Q-1; Wed, 11 Nov 2020 17:07:43 -0500 Received: by mail-qk1-f176.google.com with SMTP id d9so3396176qke.8 for ; Wed, 11 Nov 2020 14:07:42 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Nov 2020 14:07:41 -0800 (PST) X-MC-Unique: itr3uT6wONqSHMtJhnZgHA-1 X-MC-Unique: 3_55TcA5O_aqJTPBqWKC9Q-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=+dCkezk6O2naFuAd1mqVt9Mp30/Tj+kl2acF6ggNnVM=; b=Nl8Csou3aAIpR9Rqj+xiE5Vg2Uukd1tICoQdJX1J3tb1bKSCD7GDxJv0XHkFIcQ7tW DxQJBoMmDjE06jG9St4IOkdqVUMZYenMIo89fQY8fzkdIfZo4YE+3gVeZOL4OfIfTaNd LagDjP+yOlrWTDaEEG8Q8x5yCoS7tt5ZZJusPHOY7SDrs+lIOoXnY0esReh6Sfmr2lRy 9l2iYt9wJN8tyM0HmDi/YSIjfgQlSbWRg+AsCi4VnLcmOaZk6gstdqdyfPYi32CcgwEX fsRSbO8SiI38rZsiE/QqHcBA6rIxur+1vNG43h1QRiUd5z6+g7k0GlC7HpCGex0ZjOfj c//w== X-Gm-Message-State: AOAM5336GwMMIqujcqbmQKiWiORn3Dxz9Nw6Fh3dp7z3xyUjNOys+9hN ee0FEvxD55NaLTCsbL2qHQmm6ODbnSjoVQ== X-Google-Smtp-Source: ABdhPJziDY6izA13LXPI03Xaf1Nv9SyaIRo2qAVVANRDgHy+BuzOZ9ezA7Zxj4VMdQU213iOLyXLPg== X-Received: by 2002:a37:a405:: with SMTP id n5mr16908874qke.93.1605132462362; Wed, 11 Nov 2020 14:07:42 -0800 (PST) From: Daniel Henrique Barboza To: libvir-list@redhat.com Subject: [PATCH v1 06/10] qemu_domain.c: move size check for mem modules after alignment Date: Wed, 11 Nov 2020 19:07:21 -0300 Message-Id: <20201111220725.356297-7-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.6 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.15 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" The loop in which 'hotplugmem' is calculated in qemuDomainAlignMemorySizes() is throwing a max size overflow error. This is a reminiscent of the time where this loop was doing the memory module alignment. It doesn't hurt to leave the check here, but it makes more sense to move it to the places where the alignments are being done. Signed-off-by: Daniel Henrique Barboza --- src/conf/domain_conf.c | 9 +++++++++ src/qemu/qemu_domain.c | 20 ++++++++++---------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index e4aecc9a4d..943084ef71 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -16852,11 +16852,20 @@ virDomainSEVDefParseXML(xmlNodePtr sevNode, int virDomainMemoryDeviceAlignSizePseries(virDomainMemoryDefPtr mem) { + unsigned long long maxmemkb =3D virMemoryMaxValue(false) >> 10; unsigned long long ppc64AlignSize =3D 256 * 1024; unsigned long long guestArea; =20 if (mem->model !=3D VIR_DOMAIN_MEMORY_MODEL_NVDIMM) { mem->size =3D VIR_ROUND_UP(mem->size, ppc64AlignSize); + + if (mem->size > maxmemkb) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("size of memory module overflowed after " + "alignment")); + return -1; + } + return 0; } =20 diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index c06c33f8d0..7067d49d7a 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -5350,11 +5350,19 @@ qemuDomainMemoryDefPostParse(virDomainMemoryDefPtr = mem, /* For x86, dimm memory modules require 2MiB alignment rather than * the 1MiB we are using elsewhere. */ unsigned int x86MemoryModuleSizeAlignment =3D 2048; + unsigned long long maxmemkb =3D virMemoryMaxValue(false) >> 10; =20 /* ppc64 memory module alignment is done in * virDomainMemoryDefPostParse(). */ - if (!ARCH_IS_PPC64(arch)) + if (!ARCH_IS_PPC64(arch)) { mem->size =3D VIR_ROUND_UP(mem->size, x86MemoryModuleSizeAlignment= ); + if (mem->size > maxmemkb) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("size of memory module overflowed after " + "alignment")); + return -1; + } + } =20 return 0; } @@ -8093,17 +8101,9 @@ qemuDomainAlignMemorySizes(virDomainDefPtr def) * * - 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++) { + for (i =3D 0; i < def->nmems; i++) hotplugmem +=3D def->mems[i]->size; =20 - if (def->mems[i]->size > maxmemkb) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("size of memory module '%zu' overflowed after= " - "alignment"), i); - return -1; - } - } - /* Align initial memory size, if NUMA is present calculate it as total= of * individual aligned NUMA node sizes. */ if (initialmem =3D=3D 0) { --=20 2.26.2