From nobody Sat Apr 20 10:34:42 2024 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=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1619700968; cv=none; d=zohomail.com; s=zohoarc; b=hbHJw0oBdPl/fC64pYNB40p27mlwg1mOnQcXYBIgT2UL5GsWym64kA81HrYQnfiaRyTpKJINycmuSjJTJMg9+EBTU4qywElsEbq1iqxRn18016oKtE5intkt1GEzc5B8kddSzObxQH710jJCcVUGoipXDEAAB9K8bf5Q9TPRUbM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1619700968; 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=J1wgs5rfhNB/KoMddGZouXipXiEaE3LL71Ha7HxoBMo=; b=aV1dzrwX30kepLmsDawE87LNd1q7CILCTmXso50J3okOEi0S1q2G/n2HqYh2BgB+sZX56rFicS2yqctxAMR3jwCkt9ddsLJWktbwS13EQrf80Vt+PEHzNTaooaAq4pxAnxokHqDEVaFxCfTW7LuItki9YiC9QsYwcXG4sSqy2IM= 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 1619700968776464.29053199038344; Thu, 29 Apr 2021 05:56:08 -0700 (PDT) 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-289-l4ch1KsPN4qLklXBfsH3CA-1; Thu, 29 Apr 2021 08:56:04 -0400 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 2B43A19251AB; Thu, 29 Apr 2021 12:55:59 +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 0801F6ACE4; Thu, 29 Apr 2021 12:55:59 +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 BF2ED1806D30; Thu, 29 Apr 2021 12:55:58 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 13TCti7R024582 for ; Thu, 29 Apr 2021 08:55:44 -0400 Received: by smtp.corp.redhat.com (Postfix) id B2C7D17C53; Thu, 29 Apr 2021 12:55:44 +0000 (UTC) Received: from mimecast-mx01.redhat.com (mimecast02.extmail.prod.ext.phx2.redhat.com [10.5.110.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id ACF025DF26 for ; Thu, 29 Apr 2021 12:55:41 +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-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 012E2107ACE4 for ; Thu, 29 Apr 2021 12:55:41 +0000 (UTC) Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-523-VsRWYrb9OlK8wb2n9rR7Ag-1; Thu, 29 Apr 2021 08:55:38 -0400 Received: by mail-pg1-f177.google.com with SMTP id j7so37664601pgi.3 for ; Thu, 29 Apr 2021 05:55:38 -0700 (PDT) Received: from C02D383UML85.bytedance.net ([139.177.225.251]) by smtp.gmail.com with ESMTPSA id r3sm2581210pgn.82.2021.04.29.05.55.34 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Apr 2021 05:55:36 -0700 (PDT) X-MC-Unique: l4ch1KsPN4qLklXBfsH3CA-1 X-MC-Unique: VsRWYrb9OlK8wb2n9rR7Ag-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=J1wgs5rfhNB/KoMddGZouXipXiEaE3LL71Ha7HxoBMo=; b=clV4bLc4tCj5580rvXcD386lpi078yEpEw27UrCTd7Lsiu9WcDOGgU8r8uQkbW8RmQ cWrGXYNKa2Nn0wsPaFq6pxMMNFmd2zC54lB5DztfvDCvhPvADAwrzhtTgq/MwXVQ5ODi DsMsD1BOpaM4mbmgF9e97S8kpixp/1/LNrVDky+8X3ppJd4XbIL+7D4e0DYTyW142kPk epoNTt1883Fsi3hbjhFO1SGYVNoYU1rTC4kmqXtTELPR9qPK+DOSHHgLAMDi2TjxnmsQ sjG5USL7imNljT11u9dZW7som8CR5R+sHlh5olv1eY7BSO/LeTSWwfu84vC9lut9ErOG s3jg== X-Gm-Message-State: AOAM531fS+SFf6TEi5ntgS5ruP65qSp7trsB3Xiu8eqlV/Q/lljOcSQz 70hF3xAc66SVCDStryGxVdMxXjUWgGE7SvD3 X-Google-Smtp-Source: ABdhPJyk9s9fW2kp9XdFF+4iRPgmfoDBf1P4vX5ReetjJ5+2bz6Gq3gafvfLd0d+K+Ouq02pqgEgNQ== X-Received: by 2002:a63:144d:: with SMTP id 13mr24551244pgu.138.1619700937140; Thu, 29 Apr 2021 05:55:37 -0700 (PDT) From: Zhiyong Ye To: libvir-list@redhat.com Subject: [PATCH] qemu: add support for max-ram-below-4g option Date: Thu, 29 Apr 2021 20:55:18 +0800 Message-Id: <20210429125518.27917-3-yezhiyong@bytedance.com> In-Reply-To: <20210429125518.27917-1-yezhiyong@bytedance.com> References: <20210429125518.27917-1-yezhiyong@bytedance.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.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: Zhiyong Ye , zhangruien , zhenwei pi 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 'below4g' attribute added in 'memory' element can be used to specify the low memory area, which allows to get a larger PCI I/O window below 4G when reduce it to a smaller value, and when raise value allows legacy non-PAE guests to have as much memory as possible in the 32bit address space below 4G. It does not share the ``unit`` parameter with the actual memory size and its unit defaults to "KiB". Signed-off-by: Zhiyong Ye Signed-off-by: zhenwei pi Signed-off-by: zhangruien --- docs/formatdomain.rst | 10 ++++-- docs/schemas/domaincommon.rng | 5 +++ src/conf/domain_conf.c | 6 ++++ src/conf/domain_conf.h | 3 ++ src/conf/domain_validate.c | 13 ++++++++ src/qemu/qemu_command.c | 4 +++ tests/qemuxml2argvdata/memory-below4g.args | 29 ++++++++++++++++ tests/qemuxml2argvdata/memory-below4g.xml | 26 +++++++++++++++ tests/qemuxml2argvtest.c | 1 + tests/qemuxml2xmloutdata/memory-below4g.xml | 37 +++++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 11 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 tests/qemuxml2argvdata/memory-below4g.args create mode 100644 tests/qemuxml2argvdata/memory-below4g.xml create mode 100644 tests/qemuxml2xmloutdata/memory-below4g.xml diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 1b9b221611..fd074a224e 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -940,8 +940,14 @@ Memory Allocation `NUMA <#elementsCPU>`__ is configured for the guest the ``memory`` elem= ent can be omitted. In the case of crash, optional attribute ``dumpCore`` c= an be used to control whether the guest memory should be included in the gene= rated - coredump or not (values "on", "off"). ``unit`` :since:`since 0.9.11` , - ``dumpCore`` :since:`since 0.10.2 (QEMU only)` + coredump or not (values "on", "off"). Besides, the optional ``below4g`` + attribute can be used to specify the low memory area, which allows to g= et a + larger PCI I/O window below 4G when reduce it to a smaller value, and w= hen + raise value allows legacy non-PAE guests to have as much memory as poss= ible + in the 32bit address space below 4G. It does not share the ``unit`` par= ameter + with the actual memory size and its unit defaults to "KiB". ``unit`` : + since:`since 0.9.11` , ``dumpCore`` : since:`since 0.10.2 (QEMU only)`, + ``below4g`` :since:`since 7.3.0 (QEMU only)`. ``maxMemory`` The run time maximum memory allocation of the guest. The initial memory specified by either the ```` element or the NUMA cell size diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index a2e5c50c1d..8f2ac1ad33 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -643,6 +643,11 @@ + + + + + diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index a72d58f488..272fcd894e 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -19786,6 +19786,10 @@ virDomainDefParseMemory(virDomainDef *def, &def->mem.max_memory, false, false) < 0) goto error; =20 + if (virDomainParseMemory("./memory[1]/@below4g", NULL, ctxt, + &def->mem.max_ram_below_4g, false, true) < 0) + goto error; + if (virXPathUInt("string(./maxMemory[1]/@slots)", ctxt, &def->mem.memo= ry_slots) =3D=3D -2) { virReportError(VIR_ERR_XML_ERROR, "%s", _("Failed to parse memory slot count")); @@ -28844,6 +28848,8 @@ virDomainDefFormatInternalSetRootName(virDomainDef = *def, if (def->mem.dump_core) virBufferAsprintf(buf, " dumpCore=3D'%s'", virTristateSwitchTypeToString(def->mem.dump_core= )); + if (def->mem.max_ram_below_4g > 0) + virBufferAsprintf(buf, " below4g=3D'%llu'", def->mem.max_ram_below= _4g); virBufferAsprintf(buf, " unit=3D'KiB'>%llu\n", virDomainDefGetMemoryTotal(def)); =20 diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h index 4838687edf..a939d43e93 100644 --- a/src/conf/domain_conf.h +++ b/src/conf/domain_conf.h @@ -2597,6 +2597,9 @@ struct _virDomainMemtune { unsigned long long max_memory; /* in kibibytes */ unsigned int memory_slots; /* maximum count of RAM memory slots */ =20 + /* maximum memory below the 4GiB boundary (32bit boundary) */ + unsigned long long max_ram_below_4g; /* in kibibytes */ + bool nosharepages; bool locked; int dump_core; /* enum virTristateSwitch */ diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c index 686b9e8d16..afa9e2e821 100644 --- a/src/conf/domain_validate.c +++ b/src/conf/domain_validate.c @@ -1384,6 +1384,19 @@ virDomainDefMemtuneValidate(const virDomainDef *def) } } =20 + if (mem->max_ram_below_4g && + mem->max_ram_below_4g < 1024) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("maximum memory size below the 4GiB boundary must= be " + "greater than or equal to 1MiB")); + return -1; + } else if (mem->max_ram_below_4g > 4 * 1024 * 1024) { + virReportError(VIR_ERR_XML_DETAIL, "%s", + _("maximum memory size below the 4GiB boundary must= be " + "less than or equal to 4GiB")); + return -1; + } + return 0; } =20 diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index be93182092..c69ad781e6 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6961,6 +6961,10 @@ qemuBuildMachineCommandLine(virCommand *cmd, cfg->dumpGuestCore ? "on" : "off"); } =20 + if (def->mem.max_ram_below_4g > 0) + virBufferAsprintf(&buf, ",max-ram-below-4g=3D%llu", + def->mem.max_ram_below_4g * 1024); + if (def->mem.nosharepages) virBufferAddLit(&buf, ",mem-merge=3Doff"); =20 diff --git a/tests/qemuxml2argvdata/memory-below4g.args b/tests/qemuxml2arg= vdata/memory-below4g.args new file mode 100644 index 0000000000..f55386a2a2 --- /dev/null +++ b/tests/qemuxml2argvdata/memory-below4g.args @@ -0,0 +1,29 @@ +LC_ALL=3DC \ +PATH=3D/bin \ +HOME=3D/tmp/lib/domain--1-QEMUGuest1 \ +USER=3Dtest \ +LOGNAME=3Dtest \ +XDG_DATA_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.local/share \ +XDG_CACHE_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.cache \ +XDG_CONFIG_HOME=3D/tmp/lib/domain--1-QEMUGuest1/.config \ +QEMU_AUDIO_DRV=3Dnone \ +/usr/bin/qemu-system-i386 \ +-name QEMUGuest1 \ +-S \ +-machine pc,accel=3Dtcg,usb=3Doff,dump-guest-core=3Doff,max-ram-below-4g= =3D112197632 \ +-m 214 \ +-realtime mlock=3Doff \ +-smp 1,sockets=3D1,cores=3D1,threads=3D1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=3Dcharmonitor,path=3D/tmp/lib/domain--1-QEMUGuest1/moni= tor.sock,server=3Don,wait=3Doff \ +-mon chardev=3Dcharmonitor,id=3Dmonitor,mode=3Dcontrol \ +-rtc base=3Dutc \ +-no-shutdown \ +-no-acpi \ +-usb \ +-drive file=3D/dev/HostVG/QEMUGuest1,format=3Draw,if=3Dnone,id=3Ddrive-ide= 0-0-0 \ +-device ide-hd,bus=3Dide.0,unit=3D0,drive=3Ddrive-ide0-0-0,id=3Dide0-0-0,b= ootindex=3D1 \ +-device virtio-balloon-pci,id=3Dballoon0,bus=3Dpci.0,addr=3D0x3 diff --git a/tests/qemuxml2argvdata/memory-below4g.xml b/tests/qemuxml2argv= data/memory-below4g.xml new file mode 100644 index 0000000000..a843ef72a2 --- /dev/null +++ b/tests/qemuxml2argvdata/memory-below4g.xml @@ -0,0 +1,26 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 214 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i386 + + + +
+ + + + + + diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index f0efe98d7e..d26455d36c 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -1055,6 +1055,7 @@ mymain(void) driver.config->dumpGuestCore =3D true; DO_TEST("machine-core-off", NONE); driver.config->dumpGuestCore =3D false; + DO_TEST("memory-below4g", NONE); DO_TEST("machine-smm-opt", QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE, QEMU_CAPS_DEVICE_PCI_BRIDGE, diff --git a/tests/qemuxml2xmloutdata/memory-below4g.xml b/tests/qemuxml2xm= loutdata/memory-below4g.xml new file mode 100644 index 0000000000..44f58fc93b --- /dev/null +++ b/tests/qemuxml2xmloutdata/memory-below4g.xml @@ -0,0 +1,37 @@ + + QEMUGuest1 + c7a5fdbd-edaf-9455-926a-d65c16db1809 + 219136 + 219136 + 1 + + hvm + + + + destroy + restart + destroy + + /usr/bin/qemu-system-i386 + + + + +
+ + +
+ + +
+ + + + +