mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 12:41:29 +00:00
qemu: build vhost-user GPU devices
For each vhost-user GPUs, - build a socket chardev, and pass the vhost-user socket to it - build a vhost-user video device and associate it with the chardev Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Reviewed-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
dc7de8b963
commit
e2b709f92e
@ -4513,16 +4513,23 @@ qemuBuildDeviceVideoStr(const virDomainDef *def,
|
|||||||
virQEMUCapsPtr qemuCaps)
|
virQEMUCapsPtr qemuCaps)
|
||||||
{
|
{
|
||||||
VIR_AUTOCLEAN(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
VIR_AUTOCLEAN(virBuffer) buf = VIR_BUFFER_INITIALIZER;
|
||||||
const char *model;
|
const char *model = NULL;
|
||||||
|
|
||||||
/* We try to chose the best model for primary video device by preferring
|
/* We try to chose the best model for primary video device by preferring
|
||||||
* model with VGA compatibility mode. For some video devices on some
|
* model with VGA compatibility mode. For some video devices on some
|
||||||
* architectures there might not be such model so fallback to one
|
* architectures there might not be such model so fallback to one
|
||||||
* without VGA compatibility mode. */
|
* without VGA compatibility mode. */
|
||||||
|
if (video->backend == VIR_DOMAIN_VIDEO_BACKEND_TYPE_VHOSTUSER) {
|
||||||
|
if (video->primary && qemuDomainSupportsVideoVga(video, qemuCaps))
|
||||||
|
model = "vhost-user-vga";
|
||||||
|
else
|
||||||
|
model = "vhost-user-gpu";
|
||||||
|
} else {
|
||||||
if (video->primary && qemuDomainSupportsVideoVga(video, qemuCaps))
|
if (video->primary && qemuDomainSupportsVideoVga(video, qemuCaps))
|
||||||
model = qemuDeviceVideoTypeToString(video->type);
|
model = qemuDeviceVideoTypeToString(video->type);
|
||||||
else
|
else
|
||||||
model = qemuDeviceVideoSecondaryTypeToString(video->type);
|
model = qemuDeviceVideoSecondaryTypeToString(video->type);
|
||||||
|
}
|
||||||
|
|
||||||
if (!model || STREQ(model, "")) {
|
if (!model || STREQ(model, "")) {
|
||||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -4531,8 +4538,8 @@ qemuBuildDeviceVideoStr(const virDomainDef *def,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (STREQ(model, "virtio-gpu")) {
|
if (STREQ(model, "virtio-gpu") || STREQ(model, "vhost-user-gpu")) {
|
||||||
if (qemuBuildVirtioDevStr(&buf, "virtio-gpu", qemuCaps,
|
if (qemuBuildVirtioDevStr(&buf, model, qemuCaps,
|
||||||
VIR_DOMAIN_DEVICE_VIDEO, video) < 0) {
|
VIR_DOMAIN_DEVICE_VIDEO, video) < 0) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -4575,6 +4582,10 @@ qemuBuildDeviceVideoStr(const virDomainDef *def,
|
|||||||
if (video->heads)
|
if (video->heads)
|
||||||
virBufferAsprintf(&buf, ",max_outputs=%u", video->heads);
|
virBufferAsprintf(&buf, ",max_outputs=%u", video->heads);
|
||||||
}
|
}
|
||||||
|
} else if (video->backend == VIR_DOMAIN_VIDEO_BACKEND_TYPE_VHOSTUSER) {
|
||||||
|
if (video->heads)
|
||||||
|
virBufferAsprintf(&buf, ",max_outputs=%u", video->heads);
|
||||||
|
virBufferAsprintf(&buf, ",chardev=chr-vu-%s", video->info.alias);
|
||||||
} else if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO) {
|
} else if (video->type == VIR_DOMAIN_VIDEO_TYPE_VIRTIO) {
|
||||||
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_MAX_OUTPUTS)) {
|
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_GPU_MAX_OUTPUTS)) {
|
||||||
if (video->heads)
|
if (video->heads)
|
||||||
@ -4686,6 +4697,23 @@ qemuBuildVgaVideoCommand(virCommandPtr cmd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static char *
|
||||||
|
qemuBuildVhostUserChardevStr(const char *alias,
|
||||||
|
int *fd,
|
||||||
|
virCommandPtr cmd)
|
||||||
|
{
|
||||||
|
char *chardev = NULL;
|
||||||
|
|
||||||
|
if (virAsprintf(&chardev, "socket,id=chr-vu-%s,fd=%d", alias, *fd) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
virCommandPassFD(cmd, *fd, VIR_COMMAND_PASS_FD_CLOSE_PARENT);
|
||||||
|
*fd = -1;
|
||||||
|
|
||||||
|
return chardev;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuBuildVideoCommandLine(virCommandPtr cmd,
|
qemuBuildVideoCommandLine(virCommandPtr cmd,
|
||||||
const virDomainDef *def,
|
const virDomainDef *def,
|
||||||
@ -4693,6 +4721,20 @@ qemuBuildVideoCommandLine(virCommandPtr cmd,
|
|||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < def->nvideos; i++) {
|
||||||
|
VIR_AUTOFREE(char *) chardev = NULL;
|
||||||
|
virDomainVideoDefPtr video = def->videos[i];
|
||||||
|
|
||||||
|
if (video->backend == VIR_DOMAIN_VIDEO_BACKEND_TYPE_VHOSTUSER) {
|
||||||
|
if (!(chardev = qemuBuildVhostUserChardevStr(video->info.alias,
|
||||||
|
&QEMU_DOMAIN_VIDEO_PRIVATE(video)->vhost_user_fd,
|
||||||
|
cmd)))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
virCommandAddArgList(cmd, "-chardev", chardev, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < def->nvideos; i++) {
|
for (i = 0; i < def->nvideos; i++) {
|
||||||
VIR_AUTOFREE(char *) str = NULL;
|
VIR_AUTOFREE(char *) str = NULL;
|
||||||
virDomainVideoDefPtr video = def->videos[i];
|
virDomainVideoDefPtr video = def->videos[i];
|
||||||
|
@ -49,7 +49,9 @@ ats=on \
|
|||||||
ats=on \
|
ats=on \
|
||||||
-device virtio-input-host-pci,id=input3,evdev=/dev/input/event1234,bus=pci.0,\
|
-device virtio-input-host-pci,id=input3,evdev=/dev/input/event1234,bus=pci.0,\
|
||||||
addr=0x12,iommu_platform=on,ats=on \
|
addr=0x12,iommu_platform=on,ats=on \
|
||||||
-device virtio-gpu-pci,id=video0,bus=pci.0,addr=0x2,iommu_platform=on,ats=on \
|
-chardev socket,id=chr-vu-video0,fd=0 \
|
||||||
|
-device vhost-user-gpu-pci,id=video0,max_outputs=1,chardev=chr-vu-video0,\
|
||||||
|
bus=pci.0,addr=0x2,iommu_platform=on,ats=on \
|
||||||
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0xc,iommu_platform=on,\
|
-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0xc,iommu_platform=on,\
|
||||||
ats=on \
|
ats=on \
|
||||||
-object rng-random,id=objrng0,filename=/dev/random \
|
-object rng-random,id=objrng0,filename=/dev/random \
|
||||||
|
Loading…
x
Reference in New Issue
Block a user