[libvirt PATCH] qemu: require memfd memory for virtio 'blob' support

The virtio-gpu 'blob' support was insufficiently validated. Qemu requires a memfd memory backing in order to use udmabuf and enable blob support. Example error: $ virsh start rhel9 error: Failed to start domain 'rhel9' error: internal error: qemu unexpectedly closed the monitor: 2023-07-18T02:33:57.083178Z qemu-kvm: -device {"driver":"virtio-vga","id":"video0","max_outputs":1,"blob":true,"bus":"pcie.0","addr":"0x1"}: cannot enable blob resources without udmabuf Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com> --- src/qemu/qemu_validate.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 7e09e2c52f..139e6f3d62 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -2598,6 +2598,7 @@ qemuValidateDomainDeviceDefHostdev(const virDomainHostdevDef *hostdev, static int qemuValidateDomainDeviceDefVideo(const virDomainVideoDef *video, + const virDomainDef *def, virQEMUCaps *qemuCaps) { virDomainCapsDeviceVideo videoCaps = { 0 }; @@ -2714,11 +2715,18 @@ qemuValidateDomainDeviceDefVideo(const virDomainVideoDef *video, } if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO) { - if (video->blob != VIR_TRISTATE_SWITCH_ABSENT && - !virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_BLOB)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("this QEMU does not support 'blob' for virtio-gpu devices")); - return -1; + if (video->blob != VIR_TRISTATE_SWITCH_ABSENT) { + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_BLOB)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("this QEMU does not support 'blob' for virtio-gpu devices")); + return -1; + } + if (video->blob == VIR_TRISTATE_SWITCH_ON + && def->mem.source != VIR_DOMAIN_MEMORY_SOURCE_MEMFD) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("'blob' support for virtio-gpu devices requires a memfd memory backend")); + return -1; + } } } @@ -5217,7 +5225,7 @@ qemuValidateDomainDeviceDef(const virDomainDeviceDef *dev, qemuCaps); case VIR_DOMAIN_DEVICE_VIDEO: - return qemuValidateDomainDeviceDefVideo(dev->data.video, qemuCaps); + return qemuValidateDomainDeviceDefVideo(dev->data.video, def, qemuCaps); case VIR_DOMAIN_DEVICE_DISK: return qemuValidateDomainDeviceDefDisk(dev->data.disk, def, qemuCaps); -- 2.41.0

On 7/18/23 16:48, Jonathon Jongsma wrote:
The virtio-gpu 'blob' support was insufficiently validated. Qemu requires a memfd memory backing in order to use udmabuf and enable blob support. Example error:
$ virsh start rhel9 error: Failed to start domain 'rhel9' error: internal error: qemu unexpectedly closed the monitor: 2023-07-18T02:33:57.083178Z qemu-kvm: -device {"driver":"virtio-vga","id":"video0","max_outputs":1,"blob":true,"bus":"pcie.0","addr":"0x1"}: cannot enable blob resources without udmabuf
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com> --- src/qemu/qemu_validate.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-)
You forgot to update tests. Squash this in: diff --git i/tests/qemuxml2argvdata/video-virtio-blob-on.x86_64-latest.args w/tests/qemuxml2argvdata/video-virtio-blob-on.x86_64-latest.args index ef37e32e5e..577422426b 100644 --- i/tests/qemuxml2argvdata/video-virtio-blob-on.x86_64-latest.args +++ w/tests/qemuxml2argvdata/video-virtio-blob-on.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=1048576k \ --object '{"qom-type":"memory-backend-ram","id":"pc.ram","size":1073741824}' \ +-object '{"qom-type":"memory-backend-memfd","id":"pc.ram","x-use-canonical-path-for-ramblock-id":false,"size":1073741824}' \ -overcommit mem-lock=off \ -smp 1,sockets=1,cores=1,threads=1 \ -uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \ diff --git i/tests/qemuxml2argvdata/video-virtio-blob-on.xml w/tests/qemuxml2argvdata/video-virtio-blob-on.xml index 2b8a913f49..96ccf13079 100644 --- i/tests/qemuxml2argvdata/video-virtio-blob-on.xml +++ w/tests/qemuxml2argvdata/video-virtio-blob-on.xml @@ -3,6 +3,9 @@ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <memory unit='KiB'>1048576</memory> <currentMemory unit='KiB'>1048576</currentMemory> + <memoryBacking> + <source type='memfd'/> + </memoryBacking> <vcpu placement='static'>1</vcpu> <os> <type arch='x86_64' machine='pc'>hvm</type> diff --git i/tests/qemuxml2xmloutdata/video-virtio-blob-on.x86_64-latest.xml w/tests/qemuxml2xmloutdata/video-virtio-blob-on.x86_64-latest.xml index 410db67592..40f40b4132 100644 --- i/tests/qemuxml2xmloutdata/video-virtio-blob-on.x86_64-latest.xml +++ w/tests/qemuxml2xmloutdata/video-virtio-blob-on.x86_64-latest.xml @@ -3,6 +3,9 @@ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid> <memory unit='KiB'>1048576</memory> <currentMemory unit='KiB'>1048576</currentMemory> + <memoryBacking> + <source type='memfd'/> + </memoryBacking> <vcpu placement='static'>1</vcpu> <os> <type arch='x86_64' machine='pc'>hvm</type> Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal
participants (2)
-
Jonathon Jongsma
-
Michal Prívozník