From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Alex Williamson" <alex.williamson@redhat.com>,
"Tomita Moeko" <tomitamoeko@gmail.com>,
"Cédric Le Goater" <clg@redhat.com>
Subject: [PULL 5/5] vfio/igd: Fix VGA regions are not exposed in legacy mode
Date: Tue, 29 Jul 2025 08:26:33 +0200 [thread overview]
Message-ID: <20250729062633.452522-6-clg@redhat.com> (raw)
In-Reply-To: <20250729062633.452522-1-clg@redhat.com>
From: Tomita Moeko <tomitamoeko@gmail.com>
In commit a59d06305fff ("vfio/pci: Introduce x-pci-class-code option"),
pci_register_vga() has been moved ouside of vfio_populate_vga(). As a
result, IGD VGA ranges are no longer properly exposed to guest.
To fix this, call pci_register_vga() after vfio_populate_vga() legacy
mode. A wrapper function vfio_pci_config_register_vga() is introduced
to handle it.
Fixes: a59d06305fff ("vfio/pci: Introduce x-pci-class-code option")
Signed-off-by: Tomita Moeko <tomitamoeko@gmail.com>
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
Link: https://lore.kernel.org/qemu-devel/20250723160906.44941-3-tomitamoeko@gmail.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
hw/vfio/pci.h | 1 +
hw/vfio/igd.c | 10 +++++++---
hw/vfio/pci.c | 13 ++++++++++---
3 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/hw/vfio/pci.h b/hw/vfio/pci.h
index bca289035aaebb6c4422b31e26bb1dd76ab5ae72..81465a8214a4008716806ae85c7f320f6b198bb2 100644
--- a/hw/vfio/pci.h
+++ b/hw/vfio/pci.h
@@ -253,6 +253,7 @@ extern const VMStateDescription vfio_display_vmstate;
void vfio_pci_bars_exit(VFIOPCIDevice *vdev);
bool vfio_pci_add_capabilities(VFIOPCIDevice *vdev, Error **errp);
+void vfio_pci_config_register_vga(VFIOPCIDevice *vdev);
bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp);
bool vfio_pci_interrupt_setup(VFIOPCIDevice *vdev, Error **errp);
void vfio_pci_intx_eoi(VFIODevice *vbasedev);
diff --git a/hw/vfio/igd.c b/hw/vfio/igd.c
index 5b1ad1a8048b8753f524059810b1b17015704ac9..ee0767b0b89c085a5147369dd6fcbd3ff21f8927 100644
--- a/hw/vfio/igd.c
+++ b/hw/vfio/igd.c
@@ -574,9 +574,13 @@ static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
* If VGA is not already enabled, try to enable it. We shouldn't be
* using legacy mode without VGA.
*/
- if (!vdev->vga && !vfio_populate_vga(vdev, &err)) {
- error_setg(&err, "Unable to enable VGA access");
- goto error;
+ if (!vdev->vga) {
+ if (vfio_populate_vga(vdev, &err)) {
+ vfio_pci_config_register_vga(vdev);
+ } else {
+ error_setg(&err, "Unable to enable VGA access");
+ goto error;
+ }
}
/* Enable OpRegion and LPC bridge quirk */
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index f5bc5359eb8bdb8ddfa5f2b50d7387f2638bbeb4..4fa692c1a32bcfa4e4939e5fcb64f2bf19905b3b 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -3162,6 +3162,15 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice *vdev)
vdev->req_enabled = false;
}
+void vfio_pci_config_register_vga(VFIOPCIDevice *vdev)
+{
+ assert(vdev->vga != NULL);
+
+ pci_register_vga(&vdev->pdev, &vdev->vga->region[QEMU_PCI_VGA_MEM].mem,
+ &vdev->vga->region[QEMU_PCI_VGA_IO_LO].mem,
+ &vdev->vga->region[QEMU_PCI_VGA_IO_HI].mem);
+}
+
bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
{
PCIDevice *pdev = &vdev->pdev;
@@ -3283,9 +3292,7 @@ bool vfio_pci_config_setup(VFIOPCIDevice *vdev, Error **errp)
vfio_bars_register(vdev);
if (vdev->vga && vfio_is_vga(vdev)) {
- pci_register_vga(&vdev->pdev, &vdev->vga->region[QEMU_PCI_VGA_MEM].mem,
- &vdev->vga->region[QEMU_PCI_VGA_IO_LO].mem,
- &vdev->vga->region[QEMU_PCI_VGA_IO_HI].mem);
+ vfio_pci_config_register_vga(vdev);
}
return true;
--
2.50.1
next prev parent reply other threads:[~2025-07-29 6:28 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-29 6:26 [PULL 0/5] vfio queue Cédric Le Goater
2025-07-29 6:26 ` [PULL 1/5] hw/i386: Fix 'use-legacy-x86-rom' property compatibility Cédric Le Goater
2025-07-29 6:26 ` [PULL 2/5] i386: Build SEV only for 64-bit target Cédric Le Goater
2025-07-29 6:26 ` [PULL 3/5] vfio: fix sub-page bar after cpr Cédric Le Goater
2025-07-29 6:26 ` [PULL 4/5] vfio/igd: Require host VGA decode for legacy mode Cédric Le Goater
2025-07-29 6:26 ` Cédric Le Goater [this message]
2025-07-29 16:59 ` [PULL 0/5] vfio queue Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250729062633.452522-6-clg@redhat.com \
--to=clg@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=tomitamoeko@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).