[libvirt PATCH 0/4] qemu: support host-phys-bits-limit

Ján Tomko (4): conf: cpu: add limit for maxphysaddr qemu: add support for setting host-phys-bits-limit qemu: do not require bits for maxphysaddr mode emulate qemu: allow forcing emulated maxphysaddr docs/formatdomain.rst | 10 ++++-- src/conf/cpu_conf.c | 7 ++++ src/conf/cpu_conf.h | 1 + src/conf/schemas/cputypes.rng | 5 +++ src/qemu/qemu_command.c | 8 ++++- src/qemu/qemu_validate.c | 7 ---- .../cpu-phys-bits-emulate-bare.xml | 20 +++++++++++ .../cpu-phys-bits-emulate3.err | 1 - .../cpu-phys-bits-emulate3.xml | 20 ----------- .../cpu-phys-bits-limit.x86_64-latest.args | 34 +++++++++++++++++++ .../qemuxml2argvdata/cpu-phys-bits-limit.xml | 20 +++++++++++ tests/qemuxml2argvtest.c | 3 +- ...u-phys-bits-emulate-bare.x86_64-latest.xml | 31 +++++++++++++++++ .../cpu-phys-bits-limit.x86_64-latest.xml | 31 +++++++++++++++++ tests/qemuxml2xmltest.c | 3 ++ 15 files changed, 169 insertions(+), 32 deletions(-) create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-emulate-bare.xml delete mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-emulate3.err delete mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-emulate3.xml create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-limit.x86_64-latest.args create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-limit.xml create mode 100644 tests/qemuxml2xmloutdata/cpu-phys-bits-emulate-bare.x86_64-latest.xml create mode 100644 tests/qemuxml2xmloutdata/cpu-phys-bits-limit.x86_64-latest.xml -- 2.39.2

Add a limit attribute to restrict the maximum physical address bits that would be used for the guest CPU: <cpu mode='host-passthrough'> <maxphysaddr mode='passthrough' limit='39'/> </cpu> https://gitlab.com/libvirt/libvirt/-/issues/450 https://bugzilla.redhat.com/show_bug.cgi?id=2171860 Signed-off-by: Ján Tomko <jtomko@redhat.com> --- docs/formatdomain.rst | 7 ++++- src/conf/cpu_conf.c | 7 +++++ src/conf/cpu_conf.h | 1 + src/conf/schemas/cputypes.rng | 5 +++ .../qemuxml2argvdata/cpu-phys-bits-limit.xml | 20 ++++++++++++ .../cpu-phys-bits-limit.x86_64-latest.xml | 31 +++++++++++++++++++ tests/qemuxml2xmltest.c | 2 ++ 7 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-limit.xml create mode 100644 tests/qemuxml2xmloutdata/cpu-phys-bits-limit.x86_64-latest.xml diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 638768c18d..29854037a9 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -1353,7 +1353,7 @@ following collection of elements. :since:`Since 0.7.5` <cpu mode='host-passthrough' migratable='off'> <cache mode='passthrough'/> - <maxphysaddr mode='passthrough'/> + <maxphysaddr mode='passthrough' limit='39'/> <feature policy='disable' name='lahf_lm'/> ... @@ -1623,6 +1623,11 @@ In case no restrictions need to be put on CPU model and its features, a simpler The ``bits`` attribute is mandatory if the ``mode`` attribute is set to ``emulate`` and specifies the virtual CPU address size in bits. + ``limit`` + The ``limit`` attribute can be used to restrict the maximum value of + address bits for ``passthrough`` mode, i.e. in case the host CPU reports + more bits than that, ``limit`` is used. :since:`Since 9.2.0` + Guest NUMA topology can be specified using the ``numa`` element. :since:`Since 0.9.8` diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c index a33f39ef31..bbe454ed10 100644 --- a/src/conf/cpu_conf.c +++ b/src/conf/cpu_conf.c @@ -680,6 +680,11 @@ virCPUDefParseXML(xmlXPathContextPtr ctxt, VIR_XML_PROP_NONNEGATIVE, &def->addr->bits, -1) < 0) return -1; + + if (virXMLPropInt(maxphysaddrNode, "limit", 10, + VIR_XML_PROP_NONNEGATIVE, + &def->addr->limit, -1) < 0) + return -1; } *cpu = g_steal_pointer(&def); @@ -855,6 +860,8 @@ virCPUDefFormatBuf(virBuffer *buf, virCPUMaxPhysAddrModeTypeToString(def->addr->mode)); if (def->addr->bits != -1) virBufferAsprintf(buf, " bits='%d'", def->addr->bits); + if (def->addr->limit != -1) + virBufferAsprintf(buf, " limit='%d'", def->addr->limit); virBufferAddLit(buf, "/>\n"); } diff --git a/src/conf/cpu_conf.h b/src/conf/cpu_conf.h index 113d349708..6a00c0aaf9 100644 --- a/src/conf/cpu_conf.h +++ b/src/conf/cpu_conf.h @@ -128,6 +128,7 @@ VIR_ENUM_DECL(virCPUMaxPhysAddrMode); typedef struct _virCPUMaxPhysAddrDef virCPUMaxPhysAddrDef; struct _virCPUMaxPhysAddrDef { int bits; /* -1 for unspecified */ + int limit; /* -1 for unspecified */ virCPUMaxPhysAddrMode mode; }; diff --git a/src/conf/schemas/cputypes.rng b/src/conf/schemas/cputypes.rng index 3e79bdd563..db1aa57158 100644 --- a/src/conf/schemas/cputypes.rng +++ b/src/conf/schemas/cputypes.rng @@ -318,6 +318,11 @@ <ref name="unsignedInt"/> </attribute> </optional> + <optional> + <attribute name="limit"> + <ref name="unsignedInt"/> + </attribute> + </optional> </element> </define> diff --git a/tests/qemuxml2argvdata/cpu-phys-bits-limit.xml b/tests/qemuxml2argvdata/cpu-phys-bits-limit.xml new file mode 100644 index 0000000000..aabfb77523 --- /dev/null +++ b/tests/qemuxml2argvdata/cpu-phys-bits-limit.xml @@ -0,0 +1,20 @@ +<domain type='kvm'> + <name>foo</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <cpu mode='host-passthrough'> + <maxphysaddr mode='passthrough' limit='39'/> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/qemuxml2xmloutdata/cpu-phys-bits-limit.x86_64-latest.xml b/tests/qemuxml2xmloutdata/cpu-phys-bits-limit.x86_64-latest.xml new file mode 100644 index 0000000000..ced2d9c5ca --- /dev/null +++ b/tests/qemuxml2xmloutdata/cpu-phys-bits-limit.x86_64-latest.xml @@ -0,0 +1,31 @@ +<domain type='kvm'> + <name>foo</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <cpu mode='host-passthrough' check='none' migratable='on'> + <maxphysaddr mode='passthrough' limit='39'/> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <controller type='usb' index='0' model='piix3-uhci'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <audio id='1' type='none'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> + </devices> +</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 2d2d800523..3b4ef697c6 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -1307,6 +1307,8 @@ mymain(void) DO_TEST_CAPS_LATEST("crypto-builtin"); + DO_TEST_CAPS_LATEST("cpu-phys-bits-limit"); + cleanup: if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL) virFileDeleteTree(fakerootdir); -- 2.39.2

On Wed, Mar 01, 2023 at 13:34:32 +0100, Ján Tomko wrote:
Add a limit attribute to restrict the maximum physical address bits that would be used for the guest CPU:
<cpu mode='host-passthrough'> <maxphysaddr mode='passthrough' limit='39'/> </cpu>
https://gitlab.com/libvirt/libvirt/-/issues/450 https://bugzilla.redhat.com/show_bug.cgi?id=2171860
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- docs/formatdomain.rst | 7 ++++- src/conf/cpu_conf.c | 7 +++++ src/conf/cpu_conf.h | 1 + src/conf/schemas/cputypes.rng | 5 +++ .../qemuxml2argvdata/cpu-phys-bits-limit.xml | 20 ++++++++++++ .../cpu-phys-bits-limit.x86_64-latest.xml | 31 +++++++++++++++++++ tests/qemuxml2xmltest.c | 2 ++ 7 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-limit.xml create mode 100644 tests/qemuxml2xmloutdata/cpu-phys-bits-limit.x86_64-latest.xml
- I find it weird that 'limit' is a signed integer, while 0 doesn't make sense. I guess you copied what 'bits' does, although that has the same problem. - The code doesn't validate that 'limit' is used only form mode 'passthrough'. Docs imply that it doesn't make sense elsewhere. Reviewed-by: Peter Krempa <pkrempa@redhat.com>

Translate <maxphysaddr limit='39'/> to: host-phys-bits-limit=39 https://gitlab.com/libvirt/libvirt/-/issues/450 https://bugzilla.redhat.com/show_bug.cgi?id=2171860 Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/qemu/qemu_command.c | 3 ++ .../cpu-phys-bits-limit.x86_64-latest.args | 34 +++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + 3 files changed, 38 insertions(+) create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-limit.x86_64-latest.args diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 4839d45a34..7eae858813 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6450,6 +6450,9 @@ qemuBuildCpuCommandLine(virCommand *cmd, switch (addr->mode) { case VIR_CPU_MAX_PHYS_ADDR_MODE_PASSTHROUGH: virBufferAddLit(&buf, ",host-phys-bits=on"); + + if (addr->limit > 0) + virBufferAsprintf(&buf, ",host-phys-bits-limit=%d", addr->limit); break; case VIR_CPU_MAX_PHYS_ADDR_MODE_EMULATE: diff --git a/tests/qemuxml2argvdata/cpu-phys-bits-limit.x86_64-latest.args b/tests/qemuxml2argvdata/cpu-phys-bits-limit.x86_64-latest.args new file mode 100644 index 0000000000..a4652ba9f4 --- /dev/null +++ b/tests/qemuxml2argvdata/cpu-phys-bits-limit.x86_64-latest.args @@ -0,0 +1,34 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-foo \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-foo/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-foo/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-foo/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=foo,debug-threads=on \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-foo/master-key.aes"}' \ +-machine pc,usb=off,dump-guest-core=off,memory-backend=pc.ram \ +-accel kvm \ +-cpu host,migratable=on,host-phys-bits=on,host-phys-bits-limit=39 \ +-m 214 \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-boot strict=on \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x2"}' \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ +-msg timestamp=on diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 5a33c336c8..492f98b3f1 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -2987,6 +2987,7 @@ mymain(void) DO_TEST("cpu-phys-bits-emulate2", QEMU_CAPS_KVM); DO_TEST_PARSE_ERROR("cpu-phys-bits-emulate3", QEMU_CAPS_KVM); DO_TEST_PARSE_ERROR("cpu-phys-bits-passthrough2", QEMU_CAPS_KVM); + DO_TEST_CAPS_LATEST("cpu-phys-bits-limit"); DO_TEST_CAPS_VER("sgx-epc", "7.0.0"); -- 2.39.2

On Wed, Mar 01, 2023 at 13:34:33 +0100, Ján Tomko wrote:
Translate <maxphysaddr limit='39'/> to: host-phys-bits-limit=39
https://gitlab.com/libvirt/libvirt/-/issues/450 https://bugzilla.redhat.com/show_bug.cgi?id=2171860
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/qemu/qemu_command.c | 3 ++ .../cpu-phys-bits-limit.x86_64-latest.args | 34 +++++++++++++++++++ tests/qemuxml2argvtest.c | 1 + 3 files changed, 38 insertions(+) create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-limit.x86_64-latest.args
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 4839d45a34..7eae858813 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6450,6 +6450,9 @@ qemuBuildCpuCommandLine(virCommand *cmd, switch (addr->mode) { case VIR_CPU_MAX_PHYS_ADDR_MODE_PASSTHROUGH: virBufferAddLit(&buf, ",host-phys-bits=on"); + + if (addr->limit > 0) + virBufferAsprintf(&buf, ",host-phys-bits-limit=%d", addr->limit); break;
Continuation from previous patch: - here you format it only when mode is _PASSTHROUGH - Value 0 is in a limbo state, parser accepts it but it doesn't get formatted on the commandline Reviewed-by: Peter Krempa <pkrempa@redhat.com>

Make the bits attribute optional. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- docs/formatdomain.rst | 3 +- src/qemu/qemu_validate.c | 7 ----- .../cpu-phys-bits-emulate-bare.xml | 20 ++++++++++++ .../cpu-phys-bits-emulate3.err | 1 - .../cpu-phys-bits-emulate3.xml | 20 ------------ tests/qemuxml2argvtest.c | 1 - ...u-phys-bits-emulate-bare.x86_64-latest.xml | 31 +++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 8 files changed, 54 insertions(+), 30 deletions(-) create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-emulate-bare.xml delete mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-emulate3.err delete mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-emulate3.xml create mode 100644 tests/qemuxml2xmloutdata/cpu-phys-bits-emulate-bare.x86_64-latest.xml diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 29854037a9..ae482d7905 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -1615,7 +1615,8 @@ In case no restrictions need to be put on CPU model and its features, a simpler passed through to the virtual CPUs ``emulate`` The hypervisor will define a specific value for the number of bits - of physical addresses via the ``bits`` attribute, which is mandatory. + of physical addresses via the ``bits`` attribute, which is optional + :since:`since 9.2.0` The number of bits cannot exceed the number of physical address bits supported by the hypervisor. diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index c877aa73d4..59d07a53d5 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -353,13 +353,6 @@ qemuValidateDomainDefCpu(virQEMUDriver *driver, break; case VIR_CPU_MAX_PHYS_ADDR_MODE_EMULATE: - if (addr->bits == -1) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, - _("if using CPU maximum physical address mode='%s', bits= must be specified too"), - virCPUMaxPhysAddrModeTypeToString(VIR_CPU_MAX_PHYS_ADDR_MODE_EMULATE)); - return -1; - } - if (driver->hostcpu && driver->hostcpu->addr && cpu->addr->bits > driver->hostcpu->addr->bits) { diff --git a/tests/qemuxml2argvdata/cpu-phys-bits-emulate-bare.xml b/tests/qemuxml2argvdata/cpu-phys-bits-emulate-bare.xml new file mode 100644 index 0000000000..30a14894dd --- /dev/null +++ b/tests/qemuxml2argvdata/cpu-phys-bits-emulate-bare.xml @@ -0,0 +1,20 @@ +<domain type='kvm'> + <name>foo</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <cpu mode='host-passthrough'> + <maxphysaddr mode='emulate'/> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + </devices> +</domain> diff --git a/tests/qemuxml2argvdata/cpu-phys-bits-emulate3.err b/tests/qemuxml2argvdata/cpu-phys-bits-emulate3.err deleted file mode 100644 index 5e21998259..0000000000 --- a/tests/qemuxml2argvdata/cpu-phys-bits-emulate3.err +++ /dev/null @@ -1 +0,0 @@ -unsupported configuration: if using CPU maximum physical address mode='emulate', bits= must be specified too diff --git a/tests/qemuxml2argvdata/cpu-phys-bits-emulate3.xml b/tests/qemuxml2argvdata/cpu-phys-bits-emulate3.xml deleted file mode 100644 index 30a14894dd..0000000000 --- a/tests/qemuxml2argvdata/cpu-phys-bits-emulate3.xml +++ /dev/null @@ -1,20 +0,0 @@ -<domain type='kvm'> - <name>foo</name> - <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> - <memory unit='KiB'>219136</memory> - <currentMemory unit='KiB'>219136</currentMemory> - <vcpu placement='static'>1</vcpu> - <os> - <type arch='x86_64' machine='pc'>hvm</type> - <boot dev='hd'/> - </os> - <cpu mode='host-passthrough'> - <maxphysaddr mode='emulate'/> - </cpu> - <clock offset='utc'/> - <on_poweroff>destroy</on_poweroff> - <on_reboot>restart</on_reboot> - <on_crash>destroy</on_crash> - <devices> - </devices> -</domain> diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index 492f98b3f1..a7c6b1639e 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -2985,7 +2985,6 @@ mymain(void) DO_TEST("cpu-phys-bits-passthrough", QEMU_CAPS_KVM); DO_TEST("cpu-phys-bits-emulate", QEMU_CAPS_KVM); DO_TEST("cpu-phys-bits-emulate2", QEMU_CAPS_KVM); - DO_TEST_PARSE_ERROR("cpu-phys-bits-emulate3", QEMU_CAPS_KVM); DO_TEST_PARSE_ERROR("cpu-phys-bits-passthrough2", QEMU_CAPS_KVM); DO_TEST_CAPS_LATEST("cpu-phys-bits-limit"); diff --git a/tests/qemuxml2xmloutdata/cpu-phys-bits-emulate-bare.x86_64-latest.xml b/tests/qemuxml2xmloutdata/cpu-phys-bits-emulate-bare.x86_64-latest.xml new file mode 100644 index 0000000000..94b3627a46 --- /dev/null +++ b/tests/qemuxml2xmloutdata/cpu-phys-bits-emulate-bare.x86_64-latest.xml @@ -0,0 +1,31 @@ +<domain type='kvm'> + <name>foo</name> + <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> + <memory unit='KiB'>219136</memory> + <currentMemory unit='KiB'>219136</currentMemory> + <vcpu placement='static'>1</vcpu> + <os> + <type arch='x86_64' machine='pc'>hvm</type> + <boot dev='hd'/> + </os> + <cpu mode='host-passthrough' check='none' migratable='on'> + <maxphysaddr mode='emulate'/> + </cpu> + <clock offset='utc'/> + <on_poweroff>destroy</on_poweroff> + <on_reboot>restart</on_reboot> + <on_crash>destroy</on_crash> + <devices> + <emulator>/usr/bin/qemu-system-x86_64</emulator> + <controller type='usb' index='0' model='piix3-uhci'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x01' function='0x2'/> + </controller> + <controller type='pci' index='0' model='pci-root'/> + <input type='mouse' bus='ps2'/> + <input type='keyboard' bus='ps2'/> + <audio id='1' type='none'/> + <memballoon model='virtio'> + <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0'/> + </memballoon> + </devices> +</domain> diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index 3b4ef697c6..1f618fa99a 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -1308,6 +1308,7 @@ mymain(void) DO_TEST_CAPS_LATEST("crypto-builtin"); DO_TEST_CAPS_LATEST("cpu-phys-bits-limit"); + DO_TEST_CAPS_LATEST("cpu-phys-bits-emulate-bare"); cleanup: if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL) -- 2.39.2

On Wed, Mar 01, 2023 at 13:34:34 +0100, Ján Tomko wrote:
Make the bits attribute optional.
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- docs/formatdomain.rst | 3 +- src/qemu/qemu_validate.c | 7 ----- .../cpu-phys-bits-emulate-bare.xml | 20 ++++++++++++ .../cpu-phys-bits-emulate3.err | 1 - .../cpu-phys-bits-emulate3.xml | 20 ------------ tests/qemuxml2argvtest.c | 1 - ...u-phys-bits-emulate-bare.x86_64-latest.xml | 31 +++++++++++++++++++ tests/qemuxml2xmltest.c | 1 + 8 files changed, 54 insertions(+), 30 deletions(-) create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-emulate-bare.xml delete mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-emulate3.err delete mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-emulate3.xml create mode 100644 tests/qemuxml2xmloutdata/cpu-phys-bits-emulate-bare.x86_64-latest.xml
diff --git a/docs/formatdomain.rst b/docs/formatdomain.rst index 29854037a9..ae482d7905 100644 --- a/docs/formatdomain.rst +++ b/docs/formatdomain.rst @@ -1615,7 +1615,8 @@ In case no restrictions need to be put on CPU model and its features, a simpler passed through to the virtual CPUs ``emulate`` The hypervisor will define a specific value for the number of bits - of physical addresses via the ``bits`` attribute, which is mandatory. + of physical addresses via the ``bits`` attribute, which is optional + :since:`since 9.2.0`
I'm lacking a justification or explanation why this is done.

Treat: <maxphysaddr mode="emulate"/> as a request not to take the maximum address size from the host. This is useful if QEMU changes the default. Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/qemu/qemu_command.c | 5 ++++- tests/qemuxml2argvtest.c | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 7eae858813..24a211d9f7 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -6456,7 +6456,10 @@ qemuBuildCpuCommandLine(virCommand *cmd, break; case VIR_CPU_MAX_PHYS_ADDR_MODE_EMULATE: - virBufferAsprintf(&buf, ",phys-bits=%d", addr->bits); + if (addr->bits > 0) + virBufferAsprintf(&buf, ",phys-bits=%d", addr->bits); + else + virBufferAddLit(&buf, ",host-phys-bits=off"); break; case VIR_CPU_MAX_PHYS_ADDR_MODE_LAST: diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c index a7c6b1639e..41116c9571 100644 --- a/tests/qemuxml2argvtest.c +++ b/tests/qemuxml2argvtest.c @@ -2987,6 +2987,7 @@ mymain(void) DO_TEST("cpu-phys-bits-emulate2", QEMU_CAPS_KVM); DO_TEST_PARSE_ERROR("cpu-phys-bits-passthrough2", QEMU_CAPS_KVM); DO_TEST_CAPS_LATEST("cpu-phys-bits-limit"); + DO_TEST_CAPS_LATEST("cpu-phys-bits-emulate-bare"); DO_TEST_CAPS_VER("sgx-epc", "7.0.0"); -- 2.39.2

On Wed, Mar 01, 2023 at 13:34:35 +0100, Ján Tomko wrote:
Treat: <maxphysaddr mode="emulate"/> as a request not to take the maximum address size from the host. This is useful if QEMU changes the default.
Signed-off-by: Ján Tomko <jtomko@redhat.com> --- src/qemu/qemu_command.c | 5 ++++- tests/qemuxml2argvtest.c | 1 + 2 files changed, 5 insertions(+), 1 deletion(-)
So I guess this kind of belongs together with 3/4, right? I think they can and should be justified together.

Signed-off-by: Ján Tomko <jtomko@redhat.com> --- ...-phys-bits-emulate-bare.x86_64-latest.args | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/qemuxml2argvdata/cpu-phys-bits-emulate-bare.x86_64-latest.args diff --git a/tests/qemuxml2argvdata/cpu-phys-bits-emulate-bare.x86_64-latest.args b/tests/qemuxml2argvdata/cpu-phys-bits-emulate-bare.x86_64-latest.args new file mode 100644 index 0000000000..3fa8384ace --- /dev/null +++ b/tests/qemuxml2argvdata/cpu-phys-bits-emulate-bare.x86_64-latest.args @@ -0,0 +1,34 @@ +LC_ALL=C \ +PATH=/bin \ +HOME=/tmp/lib/domain--1-foo \ +USER=test \ +LOGNAME=test \ +XDG_DATA_HOME=/tmp/lib/domain--1-foo/.local/share \ +XDG_CACHE_HOME=/tmp/lib/domain--1-foo/.cache \ +XDG_CONFIG_HOME=/tmp/lib/domain--1-foo/.config \ +/usr/bin/qemu-system-x86_64 \ +-name guest=foo,debug-threads=on \ +-S \ +-object '{"qom-type":"secret","id":"masterKey0","format":"raw","file":"/tmp/lib/domain--1-foo/master-key.aes"}' \ +-machine pc,usb=off,dump-guest-core=off,memory-backend=pc.ram \ +-accel kvm \ +-cpu host,migratable=on,host-phys-bits=off \ +-m 214 \ +-object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \ +-overcommit mem-lock=off \ +-smp 1,sockets=1,cores=1,threads=1 \ +-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ +-display none \ +-no-user-config \ +-nodefaults \ +-chardev socket,id=charmonitor,fd=1729,server=on,wait=off \ +-mon chardev=charmonitor,id=monitor,mode=control \ +-rtc base=utc \ +-no-shutdown \ +-no-acpi \ +-boot strict=on \ +-device '{"driver":"piix3-usb-uhci","id":"usb","bus":"pci.0","addr":"0x1.0x2"}' \ +-audiodev '{"id":"audio1","driver":"none"}' \ +-device '{"driver":"virtio-balloon-pci","id":"balloon0","bus":"pci.0","addr":"0x2"}' \ +-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,resourcecontrol=deny \ +-msg timestamp=on -- 2.39.2
participants (2)
-
Ján Tomko
-
Peter Krempa