[PATCH 0/3] qemu: fix shared memory validation for vhost-user interfaces

Use the common check which produces hard errors instead of the post-start check adding a warning which wasn't updated with the new logic. Peter Krempa (3): qemuxmlconftest: Include shared memory 'net-vhostuser' test cases qemuValidateDomainDeviceDefNetwork: Require shared memory for all vhost-user interfaces qemu: process: Remove un-updated 'qemuProcessStartWarnShmem' src/qemu/qemu_process.c | 54 ------------------- src/qemu/qemu_validate.c | 9 ++-- .../net-vhostuser-fail.x86_64-latest.xml | 3 ++ tests/qemuxmlconfdata/net-vhostuser-fail.xml | 3 ++ .../net-vhostuser-multiq.x86_64-latest.args | 2 +- .../net-vhostuser-multiq.x86_64-latest.xml | 3 ++ .../qemuxmlconfdata/net-vhostuser-multiq.xml | 3 ++ ...vhostuser-passt-no-shmem.x86_64-latest.err | 2 +- .../net-vhostuser.x86_64-latest.args | 2 +- .../net-vhostuser.x86_64-latest.xml | 3 ++ tests/qemuxmlconfdata/net-vhostuser.xml | 3 ++ 11 files changed, 24 insertions(+), 63 deletions(-) -- 2.48.1

The vhost-user protocol requires shared memory support to work properly. Our test XMLs didn't have it configured as for interface the check if shared memory is present only produces a warning instead of a proper error. Upcoming patches will be moving the check to become fatal so the test cases need to be fixed first. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- tests/qemuxmlconfdata/net-vhostuser-fail.x86_64-latest.xml | 3 +++ tests/qemuxmlconfdata/net-vhostuser-fail.xml | 3 +++ tests/qemuxmlconfdata/net-vhostuser-multiq.x86_64-latest.args | 2 +- tests/qemuxmlconfdata/net-vhostuser-multiq.x86_64-latest.xml | 3 +++ tests/qemuxmlconfdata/net-vhostuser-multiq.xml | 3 +++ tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.args | 2 +- tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.xml | 3 +++ tests/qemuxmlconfdata/net-vhostuser.xml | 3 +++ 8 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/qemuxmlconfdata/net-vhostuser-fail.x86_64-latest.xml b/tests/qemuxmlconfdata/net-vhostuser-fail.x86_64-latest.xml index 60e591001d..ce1ebf9462 100644 --- a/tests/qemuxmlconfdata/net-vhostuser-fail.x86_64-latest.xml +++ b/tests/qemuxmlconfdata/net-vhostuser-fail.x86_64-latest.xml @@ -3,6 +3,9 @@ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <memory unit='KiB'>219136</memory> <currentMemory unit='KiB'>219136</currentMemory> + <memoryBacking> + <access mode='shared'/> + </memoryBacking> <vcpu placement='static'>1</vcpu> <os> <type arch='x86_64' machine='pc'>hvm</type> diff --git a/tests/qemuxmlconfdata/net-vhostuser-fail.xml b/tests/qemuxmlconfdata/net-vhostuser-fail.xml index d50589af6f..b6b0b977d5 100644 --- a/tests/qemuxmlconfdata/net-vhostuser-fail.xml +++ b/tests/qemuxmlconfdata/net-vhostuser-fail.xml @@ -3,6 +3,9 @@ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <memory unit='KiB'>219136</memory> <currentMemory unit='KiB'>219136</currentMemory> + <memoryBacking> + <access mode='shared'/> + </memoryBacking> <vcpu placement='static'>1</vcpu> <os> <type arch='x86_64' machine='pc'>hvm</type> diff --git a/tests/qemuxmlconfdata/net-vhostuser-multiq.x86_64-latest.args b/tests/qemuxmlconfdata/net-vhostuser-multiq.x86_64-latest.args index 922758a034..4ea3d4eebd 100644 --- a/tests/qemuxmlconfdata/net-vhostuser-multiq.x86_64-latest.args +++ b/tests/qemuxmlconfdata/net-vhostuser-multiq.x86_64-latest.args @@ -14,7 +14,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ -accel tcg \ -cpu qemu64 \ -m size=219136k \ --object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \ +-object '{"qom-type":"memory-backend-file","id":"pc.ram","mem-path":"/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/pc.ram","share":true,"x-use-canonical-path-for-ramblock-id":false,"size":224395264}' \ -overcommit mem-lock=off \ -smp 1,sockets=1,cores=1,threads=1 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ diff --git a/tests/qemuxmlconfdata/net-vhostuser-multiq.x86_64-latest.xml b/tests/qemuxmlconfdata/net-vhostuser-multiq.x86_64-latest.xml index 5c2cf70a4b..93524c2864 100644 --- a/tests/qemuxmlconfdata/net-vhostuser-multiq.x86_64-latest.xml +++ b/tests/qemuxmlconfdata/net-vhostuser-multiq.x86_64-latest.xml @@ -3,6 +3,9 @@ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <memory unit='KiB'>219136</memory> <currentMemory unit='KiB'>219136</currentMemory> + <memoryBacking> + <access mode='shared'/> + </memoryBacking> <vcpu placement='static'>1</vcpu> <os> <type arch='x86_64' machine='pc'>hvm</type> diff --git a/tests/qemuxmlconfdata/net-vhostuser-multiq.xml b/tests/qemuxmlconfdata/net-vhostuser-multiq.xml index ed492ea41a..fa324c9d17 100644 --- a/tests/qemuxmlconfdata/net-vhostuser-multiq.xml +++ b/tests/qemuxmlconfdata/net-vhostuser-multiq.xml @@ -3,6 +3,9 @@ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <memory unit='KiB'>219136</memory> <currentMemory unit='KiB'>219136</currentMemory> + <memoryBacking> + <access mode='shared'/> + </memoryBacking> <vcpu placement='static'>1</vcpu> <os> <type arch='x86_64' machine='pc'>hvm</type> diff --git a/tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.args b/tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.args index bc1de8c8ed..f5925c77fe 100644 --- a/tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.args +++ b/tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.args @@ -14,7 +14,7 @@ XDG_CONFIG_HOME=/var/lib/libvirt/qemu/domain--1-QEMUGuest1/.config \ -accel tcg \ -cpu qemu64 \ -m size=219136k \ --object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":224395264}' \ +-object '{"qom-type":"memory-backend-file","id":"pc.ram","mem-path":"/var/lib/libvirt/qemu/ram/-1-QEMUGuest1/pc.ram","share":true,"x-use-canonical-path-for-ramblock-id":false,"size":224395264}' \ -overcommit mem-lock=off \ -smp 1,sockets=1,cores=1,threads=1 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ diff --git a/tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.xml b/tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.xml index c77d46147e..44bebef2c8 100644 --- a/tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.xml +++ b/tests/qemuxmlconfdata/net-vhostuser.x86_64-latest.xml @@ -3,6 +3,9 @@ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <memory unit='KiB'>219136</memory> <currentMemory unit='KiB'>219136</currentMemory> + <memoryBacking> + <access mode='shared'/> + </memoryBacking> <vcpu placement='static'>1</vcpu> <os> <type arch='x86_64' machine='pc'>hvm</type> diff --git a/tests/qemuxmlconfdata/net-vhostuser.xml b/tests/qemuxmlconfdata/net-vhostuser.xml index e55a30a54f..91d1abc027 100644 --- a/tests/qemuxmlconfdata/net-vhostuser.xml +++ b/tests/qemuxmlconfdata/net-vhostuser.xml @@ -3,6 +3,9 @@ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <memory unit='KiB'>219136</memory> <currentMemory unit='KiB'>219136</currentMemory> + <memoryBacking> + <access mode='shared'/> + </memoryBacking> <vcpu placement='static'>1</vcpu> <os> <type arch='x86_64' machine='pc'>hvm</type> -- 2.48.1

Currently we produce only a warning into the log if a non-passt vhost-user interface is configured with shared memory. Since we do make it fatal with all other vhost-user types, fix the check to trigger also for normal-vhost-user interfaces. Since passt-based vhost-user interfaces are checked separately the check will no longer be required. Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_validate.c | 9 +++------ .../net-vhostuser-passt-no-shmem.x86_64-latest.err | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 4ab7af36f3..4282d8c11d 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1843,12 +1843,6 @@ qemuValidateDomainDeviceDefNetwork(const virDomainNetDef *net, return -1; } - if (net->type == VIR_DOMAIN_NET_TYPE_VHOSTUSER && - net->backend.type == VIR_DOMAIN_NET_BACKEND_PASST) { - if (qemuValidateDomainDefVhostUserRequireSharedMemory(def, "interface type=\"vhostuser\" backend type=\"passt\"") < 0) - return -1; - } - if (net->type == VIR_DOMAIN_NET_TYPE_VDPA) { if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_NETDEV_VHOST_VDPA)) { virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", @@ -1872,6 +1866,9 @@ qemuValidateDomainDeviceDefNetwork(const virDomainNetDef *net, _("'reconnect' attribute is not supported when source mode='server' for <interface type='vhostuser'>")); return -1; } + + if (qemuValidateDomainDefVhostUserRequireSharedMemory(def, "interface") < 0) + return -1; } if (!virDomainNetIsVirtioModel(net)) { diff --git a/tests/qemuxmlconfdata/net-vhostuser-passt-no-shmem.x86_64-latest.err b/tests/qemuxmlconfdata/net-vhostuser-passt-no-shmem.x86_64-latest.err index 274af5c722..babde17518 100644 --- a/tests/qemuxmlconfdata/net-vhostuser-passt-no-shmem.x86_64-latest.err +++ b/tests/qemuxmlconfdata/net-vhostuser-passt-no-shmem.x86_64-latest.err @@ -1 +1 @@ -unsupported configuration: 'interface type="vhostuser" backend type="passt"' requires shared memory +unsupported configuration: 'interface' requires shared memory -- 2.48.1

The checks in qemuProcessStartWarnShmem are no longer current. Since previous patch made it fatal for vhost-user interfaces to be configured without shared memory this warning code can be deleted. Resolves: https://issues.redhat.com/browse/RHEL-80533 Signed-off-by: Peter Krempa <pkrempa@redhat.com> --- src/qemu/qemu_process.c | 54 ----------------------------------------- 1 file changed, 54 deletions(-) diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 7b7b5c17e3..0173fbe3be 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -5409,56 +5409,6 @@ qemuProcessMakeDir(virQEMUDriver *driver, } -static void -qemuProcessStartWarnShmem(virDomainObj *vm) -{ - size_t i; - bool check_shmem = false; - bool shmem = vm->def->nshmems; - - /* - * For vhost-user to work, the domain has to have some type of - * shared memory configured. We're not the proper ones to judge - * whether shared hugepages or shm are enough and will be in the - * future, so we'll just warn in case neither is configured. - * Moreover failing would give the false illusion that libvirt is - * really checking that everything works before running the domain - * and not only we are unable to do that, but it's also not our - * aim to do so. - */ - for (i = 0; i < vm->def->nnets; i++) { - if (virDomainNetGetActualType(vm->def->nets[i]) == - VIR_DOMAIN_NET_TYPE_VHOSTUSER) { - check_shmem = true; - break; - } - } - - if (!check_shmem) - return; - - /* - * This check is by no means complete. We merely check - * whether there are *some* hugepages enabled and *some* NUMA - * nodes with shared memory access. - */ - if (!shmem && vm->def->mem.nhugepages) { - for (i = 0; i < virDomainNumaGetNodeCount(vm->def->numa); i++) { - if (virDomainNumaGetNodeMemoryAccessMode(vm->def->numa, i) == - VIR_DOMAIN_MEMORY_ACCESS_SHARED) { - shmem = true; - break; - } - } - } - - if (!shmem) { - VIR_WARN("Detected vhost-user interface without any shared memory, " - "the interface might not be operational"); - } -} - - static int qemuProcessStartValidateGraphics(virDomainObj *vm) { @@ -5693,10 +5643,6 @@ qemuProcessStartValidate(virQEMUDriver *driver, if (qemuProcessStartValidateTSC(driver, vm) < 0) return -1; - VIR_DEBUG("Checking for any possible (non-fatal) issues"); - - qemuProcessStartWarnShmem(vm); - return 0; } -- 2.48.1

On 3/11/25 09:12, Peter Krempa wrote:
Use the common check which produces hard errors instead of the post-start check adding a warning which wasn't updated with the new logic.
Peter Krempa (3): qemuxmlconftest: Include shared memory 'net-vhostuser' test cases qemuValidateDomainDeviceDefNetwork: Require shared memory for all vhost-user interfaces qemu: process: Remove un-updated 'qemuProcessStartWarnShmem'
src/qemu/qemu_process.c | 54 ------------------- src/qemu/qemu_validate.c | 9 ++-- .../net-vhostuser-fail.x86_64-latest.xml | 3 ++ tests/qemuxmlconfdata/net-vhostuser-fail.xml | 3 ++ .../net-vhostuser-multiq.x86_64-latest.args | 2 +- .../net-vhostuser-multiq.x86_64-latest.xml | 3 ++ .../qemuxmlconfdata/net-vhostuser-multiq.xml | 3 ++ ...vhostuser-passt-no-shmem.x86_64-latest.err | 2 +- .../net-vhostuser.x86_64-latest.args | 2 +- .../net-vhostuser.x86_64-latest.xml | 3 ++ tests/qemuxmlconfdata/net-vhostuser.xml | 3 ++ 11 files changed, 24 insertions(+), 63 deletions(-)
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal
participants (2)
-
Michal Prívozník
-
Peter Krempa