devices: video: Use virtio default more often

This is from Gerd's suggestions here:
https://www.kraxel.org/blog/2019/09/display-devices-in-qemu/

When the guest supports it, we should use virtio. qxl is on the way
out, and the benefits are marginal and add a security and maintenance
burden.

While here, check domcaps that qxl or virtio are actually available.
Modern qemu has device modules, so device support may not be installed.

Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2022-02-03 13:11:20 -05:00
parent f291ad2541
commit 1ab6dd50be
7 changed files with 30 additions and 8 deletions

View File

@ -54,7 +54,7 @@
</graphics>
<sound model="ich9"/>
<video>
<model type="qxl"/>
<model type="virtio"/>
</video>
<memballoon model="virtio"/>
<rng model="virtio">

View File

@ -49,7 +49,7 @@
<image compression="off"/>
</graphics>
<video>
<model type="qxl"/>
<model type="virtio"/>
</video>
<memballoon model="virtio"/>
<rng model="virtio">
@ -106,7 +106,7 @@
<image compression="off"/>
</graphics>
<video>
<model type="qxl"/>
<model type="virtio"/>
</video>
<memballoon model="virtio"/>
<rng model="virtio">

View File

@ -217,7 +217,7 @@
</tpm>
<graphics type="vnc" port="-1"/>
<video>
<model type="bochs"/>
<model type="virtio"/>
</video>
<watchdog model="ib700" action="pause"/>
<memballoon model="virtio" autodeflate="on" freePageReporting="on">
@ -505,7 +505,7 @@
</tpm>
<graphics type="vnc" port="-1"/>
<video>
<model type="bochs"/>
<model type="virtio"/>
</video>
<watchdog model="ib700" action="pause"/>
<memballoon model="virtio" autodeflate="on" freePageReporting="on">

View File

@ -48,7 +48,7 @@
<input type="tablet" bus="usb"/>
<graphics type="vnc" port="-1"/>
<video>
<model type="vga"/>
<model type="virtio"/>
</video>
<memballoon model="virtio"/>
<rng model="virtio">

View File

@ -44,8 +44,13 @@ class DeviceVideo(Device):
# virtio is implied in this case
return "virtio"
if (guest.lookup_domcaps().supports_video_virtio() and
guest.osinfo.supports_virtiogpu()):
# When the guest supports it, this is the top preference
return "virtio"
if (guest.os.is_x86() and
guest.has_spice()):
guest.has_spice() and
guest.lookup_domcaps().supports_video_qxl()):
# qxl is only beneficial over regular vga when paired with spice.
# The device still may not be available though
return "qxl"

View File

@ -44,6 +44,9 @@ class _CapsBlock(_HasValues):
def enum_names(self):
return [e.name for e in self.enums]
def has_enum(self, name):
return name in self.enum_names()
def get_enum(self, name):
for enum in self.enums:
if enum.name == name:
@ -359,6 +362,16 @@ class DomainCapabilities(XMLBuilder):
models = self.devices.video.get_enum("modelType").get_values()
return bool("bochs" in models)
def supports_video_qxl(self):
if not self.devices.video.has_enum("modelType"):
# qxl long predates modelType in domcaps, so if it is missing,
# use spice support as a rough value
return self.supports_graphics_spice()
return "qxl" in self.devices.video.get_enum("modelType").get_values()
def supports_video_virtio(self):
return "virtio" in self.devices.video.get_enum("modelType").get_values()
def supports_tpm_emulator(self):
"""
Returns False if either libvirt or qemu do not have support for
@ -393,7 +406,6 @@ class DomainCapabilities(XMLBuilder):
sourceTypes = self.memorybacking.get_enum("sourceType").get_values()
return bool("memfd" in sourceTypes)
XML_NAME = "domainCapabilities"
os = XMLChildProperty(_OS, is_single=True)
cpu = XMLChildProperty(_CPU, is_single=True)

View File

@ -469,6 +469,11 @@ class _OsVariant(object):
"http://pcisig.com/pci/1af4/1044"]
return bool(self._device_filter(devids=devids, extra_devs=extra_devs))
def supports_virtiogpu(self, extra_devs=None):
# virtio1.0-gpu and virtio1.0
devids = ["http://pcisig.com/pci/1af4/1050"]
return bool(self._device_filter(devids=devids, extra_devs=extra_devs))
def supports_virtioballoon(self, extra_devs=None):
# virtio-balloon and virtio1.0-balloon
devids = ["http://pcisig.com/pci/1af4/1002",