Skip to contentSkip to conversation

vfio queue

GIT PULL Applied Cédric Le Goater 2 participants 10 messages Oct 15 Checkpatch

lore
Share & tools
lore
#0 lore raw

The following changes since commit d5b5083cb783c447001e862c2b525e59f48ad78c:

Merge tag 'block-pull-request' of https://gitlab.com/stefanha/qemu into staging (2026-10-15 11:53:41 +0200)

are available in the Git repository at:

https://github.com/legoater/qemu/ tags/pull-vfio-20261015

for you to fetch changes up to 2240c14c16dfc6c3b9840677f0d153165af7d4ee:

vfio/migration: Don't reset a device on a declined stop transition (2026-10-15 13:15:24 +0200)

----------------------------------------------------------------
vfio queue:

* Fix UBSAN shift error in MTRR mask computation on AMD EPYC with 52 physical address bits
* Add Fixes: tag validation to checkpatch
* Reject virtio-net failover during vfio-user init
* Sanitize DBUF_CTL POWER_STATE for iGPU passthrough, fixing display corruption on first boot
* Thread vf-token through iommufd bind
* Make MTL/ARL guests fall back to BAR-based framebuffer access in passthrough
* Update igd-assign.txt for Intel MTL and newer platforms
* Don't reset a VFIO device on a declined stop transition

----------------------------------------------------------------
Cédric Le Goater (2):
target/i386/kvm: Fix UBSAN shift error in MTRR mask computation scripts/checkpatch: validate Fixes: tag format and commit ancestry

Hugo Komatsu (1):
vfio-user: reject failover during init

Mikhail Malyshev (1):
vfio/igd: sanitize DBUF_CTL POWER_STATE for iGPU passthrough

Pankaj Kumar (1):
vfio/migration: Don't reset a device on a declined stop transition

Tushar Dave (1):
hw/vfio: thread vf-token through iommufd bind

Yuan Wang (2):
vfio/igd: Make MTL/ARL guests fall back to BAR-based framebuffer access vfio/igd: Update igd-assign.txt for Intel MTL and newer platforms

 docs/igd-assign.txt   |   2 +-
 hw/vfio-user/pci.c    |   5 ++
 hw/vfio/igd.c         | 168 +++++++++++++++++++++++++++++++++++++++++++++++++-
 hw/vfio/iommufd.c     |  10 +++
 hw/vfio/migration.c   |  38 ++++++++++--
 target/i386/kvm/kvm.c |   3 +-
 scripts/checkpatch.pl |  66 ++++++++++++++++++++
 7 files changed, 281 insertions(+), 11 deletions(-)
#1 lore raw

[PULL 2/8] scripts/checkpatch: validate Fixes: tag format and commit ancestry

Adapt the kernel's checkpatch Fixes: tag validation for QEMU.

Add a git_commit_info() helper to resolve commit hashes and validate the Fixes: tag in commit messages. The canonical form is:

Fixes <12+ chars of sha1> ("<title line>")

The check validates capitalization, spacing, hash length, lowercase hex, and quoted title. When the format is wrong and the commit can be resolved, suggest the corrected Fixes: line.

When running inside a git repository, also verify that the referenced commit is an ancestor of master.

Lines matching "Fixes: CVE-*" are skipped. The check can be disabled with --no-fixes-tag.

---
 scripts/checkpatch.pl | 66 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
scripts/checkpatch.pl +66 -0
index 9838a64178510f216ff22e9259de22320b9da731..5df266acb1729e0174969c50d4eaaafb1e7b1ce4 100755
@@ -21,6 +21,7 @@ use Getopt::Long qw(:config no_auto_abbrev);
 my $quiet = 0;
 my $tree = 1;
 my $chk_signoff = 1;
+my $chk_fixes_tag = 1;
 my $chk_patch = undef;
 my $chk_branch = undef;
 my $tst_only;
@@ -54,6 +55,7 @@ Options:
   -q, --quiet                quiet
   --no-tree                  run without a qemu tree
   --no-signoff               do not check for 'Signed-off-by' line
+  --no-fixes-tag             do not check for 'Fixes:' tag
   --patch                    treat FILE as patchfile
   --branch                   treat args as GIT revision list
   --emacs                    emacs compile window format
@@ -94,6 +96,7 @@ GetOptions(
 	'q|quiet+'		=> \$quiet,
 	'tree!'			=> \$tree,
 	'signoff!'		=> \$chk_signoff,
+	'fixes-tag!'		=> \$chk_fixes_tag,
 	'patch!'		=> \$chk_patch,
 	'branch!'		=> \$chk_branch,
 	'emacs!'		=> \$emacs,
@@ -441,6 +444,10 @@ sub build_types {
 build_types();
 
 $chk_signoff = 0 if ($file);
+$chk_fixes_tag = 0 if ($file);
+
+my $gitroot = $ENV{'GIT_DIR'};
+$gitroot = ".git" if !defined($gitroot);
 
 my @rawlines = ();
 my @lines = ();
@@ -561,6 +568,24 @@ sub which {
 	return "";
 }
 
+sub git_commit_info {
+	my ($commit, $id, $desc) = @_;
+
+	return ($id, $desc) if ((which("git") eq "") || !(-e "$gitroot"));
+
+	my $output = `git log --no-color --format='%H %s' -1 $commit 2>/dev/null`;
+	if ($? != 0) {
+		$id = undef;
+	} else {
+		chomp $output;
+		$output =~ s/^\s*//gm;
+		$id = substr($output, 0, 12);
+		$desc = substr($output, 41);
+	}
+
+	return ($id, $desc);
+}
+
 sub expand_tabs {
 	my ($str) = @_;
 
@@ -1855,6 +1880,47 @@ sub process {
 			}
 		}
 
+# Check Fixes: tag format and commit validity
+		if ($chk_fixes_tag &&
+		    $line =~ /^\s*(fixes:?)\s*(?:commit\s*)?([0-9a-f]{5,40})\s*(.*)?/i) {
+			my $tag = $1;
+			my $orig_commit = $2;
+			my $title = $3;
+
+			if ($line !~ /^\s*Fixes:\s+CVE/i) {
+				my $tag_case = not ($tag eq "Fixes:");
+				my $tag_space = not ($line =~ /^fixes:? [0-9a-f]{5,40}/i);
+				my $id_length = not ($orig_commit =~ /^[0-9a-f]{12,40}$/);
+				my $id_case = not ($orig_commit !~ /[A-F]/);
+
+				my $id = "0123456789ab";
+				my $description = "commit title";
+				my $has_quotes = 0;
+
+				if (defined $title && $title =~ /^\("(.*?)"\)$/) {
+					$description = $1 if ($1);
+					$has_quotes = 1;
+				} elsif (defined $title && $title =~ /^\(?(.*?)\)?$/) {
+					$description = $1 if ($1);
+				}
+
+				my ($cid, $ctitle) = git_commit_info($orig_commit, $id, $description);
+
+				if (defined($cid) && ($ctitle ne $description || $tag_case || $tag_space || $id_length || $id_case || !$has_quotes)) {
+					my $fixed = "Fixes: $cid (\"$ctitle\")";
+					WARN("Please use correct Fixes: style 'Fixes: <12+ chars of sha1> (\"<title line>\")'" .
+						" - ie: '$fixed'\n" . $herecurr);
+				}
+				if (which("git") ne "" && -e "$gitroot") {
+					my $hash = defined($cid) ? $cid : $orig_commit;
+					`git merge-base --is-ancestor $hash master 2>/dev/null`;
+					if ($? != 0) {
+						WARN("Fixes: commit $hash is not an ancestor of master\n" . $herecurr);
+					}
+				}
+			}
+		}
+
 # Check SPDX-License-Identifier references a permitted license
 		if (($rawline =~ m,SPDX-License-Identifier: (.*?)(\*/)?\s*$,) &&
 			$rawline !~ /^-/) {
Signature · 1 line
2.56.0
#2 lore raw

[PULL 3/8] vfio-user: reject failover during init

In reply to Cédric Le Goater

From: Hugo Komatsu <[email protected]>

Virtio-net failover is a networking feature that relies on a primary and standby device pair. This is not currently supported for vfio-user. Refuse initialization if this property is set.

---
 hw/vfio-user/pci.c | 5 +++++
 1 file changed, 5 insertions(+)
hw/vfio-user/pci.c +5 -0
index e7573d4a9f088c1afc8ed2709932842247abf6ac..983e1d4ad470bfa887a3a60e88e2f255f0ed085a 100644
@@ -266,6 +266,11 @@ static void vfio_user_pci_realize(PCIDevice *pdev, Error **errp)
         return;
     }
 
+    if (pdev->failover_pair_id) {
+        error_setg(errp, "vfio-user: failover is not supported");
+        return;
+    }
+
     sock_name = udev->socket->u.q_unix.path;
 
     vbasedev->name = g_strdup_printf("vfio-user:%s", sock_name);
Signature · 1 line
2.56.0
#3 lore raw

[PULL 1/8] target/i386/kvm: Fix UBSAN shift error in MTRR mask computation

In reply to Cédric Le Goater

On AMD EPYC processors, raw CPUID leaf 0x80000008 reports 52 physical address bits. When a machine type such as microvm forces host_phys_bits=true, the CPU ends up with phys_bits=52, causing MAKE_64BIT_MASK(52, 0) to shift by 64 - which is undefined behavior.

Fix by only computing the mask when phys_bits < 52.

---
 target/i386/kvm/kvm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
target/i386/kvm/kvm.c +1 -2
index a72b6e6b74cc7e16bb721d9a32332a0ed8473fc1..da922f72d71e00bd10ce087ccc9828c9692501d0 100644
@@ -5064,8 +5064,7 @@ static int kvm_get_msrs(X86CPU *cpu)
      * we're migrating to.
      */
 
-    if (cpu->fill_mtrr_mask) {
-        assert(cpu->phys_bits <= 52);
+    if (cpu->fill_mtrr_mask && cpu->phys_bits < 52) {
         mtrr_top_bits = MAKE_64BIT_MASK(cpu->phys_bits, 52 - cpu->phys_bits);
     } else {
         mtrr_top_bits = 0;
Signature · 1 line
2.56.0
#4 lore raw

[PULL 6/8] vfio/igd: Make MTL/ARL guests fall back to BAR-based framebuffer access

In reply to Cédric Le Goater

From: Yuan Wang <[email protected]>

Meteor Lake and Arrow Lake GOP can read BAR0 MMIO offset 0x138914 to detect whether direct framebuffer access via DSM is available.

In a VFIO passthrough VM, the guest cannot access the host DSM memory region via such a pointer. If the guest GOP enables that path, it may hand off a DSM-based framebuffer address that the guest cannot actually use.

Intercept reads from the detection register and return 0 so the guest does not enable the DSM-based path and instead keeps using the standard BAR-based framebuffer address.

---
 hw/vfio/igd.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 46 insertions(+), 3 deletions(-)
hw/vfio/igd.c +46 -3
index 5e6160763cefb9d9739dd0a6462137c49109e81a..4c7d6545924ca49cbe0285f77b422517b1c59159 100644
@@ -96,6 +96,8 @@ static int igd_gen(VFIOPCIDevice *vdev)
     case 0x4C00:    /* Rocket Lake */
     case 0x4600:    /* Alder Lake */
     case 0xA700:    /* Raptor Lake */
+    case 0x7D00:    /* Meteor Lake / Arrow Lake */
+    case 0xB600:    /* Arrow Lake */
         return 12;
     }
 
@@ -452,8 +454,30 @@ static bool vfio_pci_igd_override_gms(int gen, uint32_t gms, uint32_t *gmch)
     return ret;
 }
 
-#define IGD_GGC_MMIO_OFFSET     0x108040
-#define IGD_BDSM_MMIO_OFFSET    0x1080C0
+#define IGD_GGC_MMIO_OFFSET         0x108040
+#define IGD_BDSM_MMIO_OFFSET        0x1080C0
+#define IGD_MTL_PCODE_STOLEN_ACCESS 0x138914
+
+#define IGD_IS_MTL_OR_ARL(vdev) \
+    ((((vdev)->device_id & 0xff00) == 0x7d00) || \
+     (((vdev)->device_id & 0xff00) == 0xb600))
+
+static uint64_t vfio_igd_pcode_stolen_access_read(void *opaque, hwaddr addr,
+                                                  unsigned size)
+{
+    return 0;
+}
+
+static void vfio_igd_pcode_stolen_access_write(void *opaque, hwaddr addr,
+                                               uint64_t data, unsigned size)
+{
+}
+
+static const MemoryRegionOps vfio_igd_pcode_stolen_access_quirk = {
+    .read = vfio_igd_pcode_stolen_access_read,
+    .write = vfio_igd_pcode_stolen_access_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+};
 
 /*
  * IGD BAR0 DBUF_CTL sanitize quirk.
@@ -547,7 +571,7 @@ static const MemoryRegionOps igd_dbuf_ctl_ops = {
 
 void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
 {
-    VFIOQuirk *ggc_quirk, *bdsm_quirk;
+    VFIOQuirk *ggc_quirk, *bdsm_quirk, *pcode_stolen_access_quirk;
     VFIOConfigMirrorQuirk *ggc_mirror, *bdsm_mirror;
     int gen;
 
@@ -562,6 +586,25 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
         return;
     }
 
+    /*
+     * MTL/ARL guests must keep using the BAR-based framebuffer address.
+     * Return 0 for PCODE stolen memory access detection (0x138914) so GOP
+     * stays on the standard access path in the VM.
+     */
+    if (IGD_IS_MTL_OR_ARL(vdev)) {
+        pcode_stolen_access_quirk = vfio_quirk_alloc(1);
+        memory_region_init_io(pcode_stolen_access_quirk->mem, OBJECT(vdev),
+                              &vfio_igd_pcode_stolen_access_quirk, vdev,
+                              "vfio-igd-pcode-stolen-access-quirk", 4);
+        memory_region_add_subregion_overlap(vdev->bars[nr].region.mem,
+                                            IGD_MTL_PCODE_STOLEN_ACCESS,
+                                            pcode_stolen_access_quirk->mem,
+                                            1);
+
+        QLIST_INSERT_HEAD(&vdev->bars[nr].quirks,
+                          pcode_stolen_access_quirk, next);
+    }
+
     if (vdev->igd_gms) {
         ggc_quirk = vfio_quirk_alloc(1);
         ggc_mirror = ggc_quirk->data = g_malloc0(sizeof(*ggc_mirror));
Signature · 1 line
2.56.0
#5 lore raw

[PULL 5/8] hw/vfio: thread vf-token through iommufd bind

In reply to Cédric Le Goater

From: Tushar Dave <[email protected]>

A VF fails to bind through the iommufd/cdev backend when its PF is bound to vfio-pci and requires a matching VF token.

QEMU currently initializes struct vfio_device_bind_iommufd without the token flag or token UUID.

Pass the existing vf-token device property to the IOMMUFD bind ioctl for PCI devices.

---
 hw/vfio/iommufd.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
hw/vfio/iommufd.c +10 -0
index 242644aa0010cd5af817a5d451308d730bc0daa4..de482128bf1bda6f2f7cdc35afa4621da6c29b4f 100644
@@ -155,6 +155,7 @@ static void iommufd_cdev_kvm_device_del(VFIODevice *vbasedev)
 
 static bool iommufd_cdev_connect_and_bind(VFIODevice *vbasedev, Error **errp)
 {
+    VFIOPCIDevice *vdev = vfio_pci_from_vfio_device(vbasedev);
     IOMMUFDBackend *iommufd = vbasedev->iommufd;
     struct vfio_device_bind_iommufd bind = {
         .argsz = sizeof(bind),
@@ -180,6 +181,15 @@ static bool iommufd_cdev_connect_and_bind(VFIODevice *vbasedev, Error **errp)
 
     /* Bind device to iommufd */
     bind.iommufd = iommufd->fd;
+
+    /*
+     * Pass the VF token when binding a PCI device.
+     */
+    if (vdev && !qemu_uuid_is_null(&vdev->vf_token)) {
+        bind.flags |= VFIO_DEVICE_BIND_FLAG_TOKEN;
+        bind.token_uuid_ptr = (uintptr_t)&vdev->vf_token;
+    }
+
     if (ioctl(vbasedev->fd, VFIO_DEVICE_BIND_IOMMUFD, &bind)) {
         error_setg_errno(errp, errno, "error bind device fd=%d to iommufd=%d",
                          vbasedev->fd, bind.iommufd);
Signature · 1 line
2.56.0
#6 lore raw

[PULL 7/8] vfio/igd: Update igd-assign.txt for Intel MTL and newer platforms

In reply to Cédric Le Goater

From: Yuan Wang <[email protected]>

Update the igd-assign.txt documentation to reflect the addition of the 0006 patch in the ECI repository. This patch is required to enable support for Meteor Lake (MTL) and subsequent Intel platforms.

Starting from MTL, the hardware-accessible BDSM (Base of Data Stolen Memory) register in the PCI configuration space has been removed. Instead, IGD devices now access stolen memory via MMIO BAR2 (LMEMBAR). Consequently, guest firmware no longer needs to program the legacy BDSM register.

---
 docs/igd-assign.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
docs/igd-assign.txt +1 -1
index e54040335ba72dc971babb4d776e46d94f342f70..b9abfdbac3503f7e0e187a15fd0787d2bfef77f1 100644
@@ -263,6 +263,6 @@ Footnotes
 [2] # echo "vfio-pci" > /sys/bus/pci/devices/0000:00:02.0/driver_override
 [3] https://web.archive.org/web/20240827012422/https://bugzilla.tianocore.org/show_bug.cgi?id=935
     Tianocore bugzilla was down since Jan 2025 :(
-[4] https://eci.intel.com/docs/3.3/components/kvm-hypervisor.html, Patch 0001-0004
+[4] https://eci.intel.com/docs/3.3/components/kvm-hypervisor.html, Patch 0001-0004, 0006
 [5] https://github.com/tomitamoeko/VfioIgdPkg
 [6] https://winraid.level1techs.com/t/tool-guide-news-uefi-bios-updater-ubu/30357
Signature · 1 line
2.56.0
#7 lore raw

[PULL 8/8] vfio/migration: Don't reset a device on a declined stop transition

In reply to Cédric Le Goater

From: Pankaj Kumar <[email protected]>

QEMU resets a VFIO device whenever a migration state transition it requests fails. This is done by vfio_migration_set_state_or_reset(), which passes VFIO_DEVICE_STATE_ERROR as the recover state, forcing an immediate VFIO_DEVICE_RESET.

However, a device may legitimately decline a state transition, e.g. a vGPU that refuses to stop while a profiling/debug session is active in the guest. Such a device is still healthy and running the guest, so resetting it destroys a perfectly good VM.

Instead of resetting on a declined stop, recover the device to its current state. The current device state is always a valid, already-reached state, so recovering to it is effectively a no-op transition that cannot itself fail and trigger a reset.

Introduce a helper, vfio_migration_set_state_or_recover(), that selects the recover state based on the transition direction, and route the vmstate change and save-completion paths through it:

- vfio_vmstate_change() and vfio_vmstate_change_prepare() recover to the current device state for the stop direction. The resume direction keeps ERROR as the recover state, since a device that cannot resume is genuinely broken.

- vfio_save_complete_precopy() recovers to the current device state rather than STOP. If it runs after an earlier stop was declined (the device still in a running state), the stop-copy attempt is then rolled back instead of resetting the device.

The existing vfio_migration_set_state_or_reset() is retained for the paths that must still reset on failure (save cleanup and the migration-failed notifier).

This lets vendor drivers decline a stop as a matter of policy without losing the guest, and lets such drivers drop their own workarounds that swallowed the spurious reset.

---
 hw/vfio/migration.c | 38 +++++++++++++++++++++++++++++++++-----
 1 file changed, 33 insertions(+), 5 deletions(-)
hw/vfio/migration.c +33 -5
index 73c49d8c24f21803de7c8615da63abecfd76b882..69d50cebdd5f1636a1f8b03967b6b01e7979e532 100644
@@ -246,6 +246,25 @@ vfio_migration_set_state_or_reset(VFIODevice *vbasedev,
                                     VFIO_DEVICE_STATE_ERROR, errp);
 }
 
+/*
+ * On a stop-direction transition failure, recover the device to its current
+ * state instead of resetting it: the current state is valid and already
+ * reached, so recovering to it is effectively a no-op that cannot itself fail.
+ * On a resume-direction (running) failure, the device is genuinely broken, so
+ * reset it by using ERROR as the recover state.
+ */
+static int
+vfio_migration_set_state_or_recover(VFIODevice *vbasedev,
+                                    enum vfio_device_mig_state new_state,
+                                    bool running, Error **errp)
+{
+    VFIOMigration *migration = vbasedev->migration;
+    enum vfio_device_mig_state recover_state =
+        running ? VFIO_DEVICE_STATE_ERROR : migration->device_state;
+
+    return vfio_migration_set_state(vbasedev, new_state, recover_state, errp);
+}
+
 static int vfio_load_buffer(QEMUFile *f, VFIODevice *vbasedev,
                             uint64_t data_size)
 {
@@ -771,9 +790,16 @@ static int vfio_save_complete_precopy(QEMUFile *f, void *opaque)
 
     trace_vfio_save_complete_precopy_start(vbasedev->name);
 
-    /* We reach here with device state STOP or STOP_COPY only */
-    ret = vfio_migration_set_state(vbasedev, VFIO_DEVICE_STATE_STOP_COPY,
-                                   VFIO_DEVICE_STATE_STOP, &local_err);
+    /*
+     * We normally reach here with the device in STOP or STOP_COPY. However, if
+     * an earlier stop transition was declined by the device, it may still be in
+     * a running state. Recover to the current device state rather than STOP, so
+     * a device that declines the stop-copy transition is rolled back to its
+     * current state instead of being reset out from under the guest.
+     */
+    ret = vfio_migration_set_state_or_recover(vbasedev,
+                                              VFIO_DEVICE_STATE_STOP_COPY,
+                                              false, &local_err);
     if (ret) {
         error_report_err(local_err);
         return ret;
@@ -1009,7 +1035,8 @@ static void vfio_vmstate_change_prepare(void *opaque, bool running,
         vfio_final_precopy_reinit_check(vbasedev);
     }
 
-    ret = vfio_migration_set_state_or_reset(vbasedev, new_state, &local_err);
+    ret = vfio_migration_set_state_or_recover(vbasedev, new_state, running,
+                                              &local_err);
     if (ret) {
         /*
          * Migration should be aborted in this case, but vm_state_notify()
@@ -1040,7 +1067,8 @@ static void vfio_vmstate_change(void *opaque, bool running, RunState state)
                 VFIO_DEVICE_STATE_STOP;
     }
 
-    ret = vfio_migration_set_state_or_reset(vbasedev, new_state, &local_err);
+    ret = vfio_migration_set_state_or_recover(vbasedev, new_state, running,
+                                              &local_err);
     if (ret) {
         /*
          * Migration should be aborted in this case, but vm_state_notify()
Signature · 1 line
2.56.0
#8 lore raw

[PULL 4/8] vfio/igd: sanitize DBUF_CTL POWER_STATE for iGPU passthrough

In reply to Cédric Le Goater

From: Mikhail Malyshev <[email protected]>

On some hosts the firmware POST modeset leaves the display data buffer (DBUF) powered, so the passed-through iGPU's DBUF_CTL registers read back POWER_STATE=1 while POWER_REQUEST=0 -- an inconsistent leftover that never occurs under GVT-g, which emulates the register so POWER_STATE follows POWER_REQUEST.

This was observed with a Windows guest (Intel KMD) on QEMU 9.1; a Linux/i915 guest was not tested. On the first-boot modeset the guest driver samples POWER_STATE to decide which DBUF slices are already enabled, sees the stale "powered" bit, and therefore never issues POWER_REQUEST. DBUF then powers down, the plane FIFO underruns, and scanout is corrupted (vertical stripes) until a full modeset (e.g. a display sleep/wake) re-requests power.

The programming is a single inconsistent read-modify-write. Traced with x-no-mmap=on so every BAR0 access is visible:

  read  0x45008 = 0x4040c000   STATE=1, REQUEST=0 (stale leftover)
  write 0x45008 = 0x4043c000   RMW: tracker bits only; REQUEST still 0
  read  0x45008 = 0x0043c000   STATE=0: DBUF powered down -> underrun

The driver sees STATE=1, assumes the slice is already powered, and leaves REQUEST clear. Only after a display sleep/wake does it set REQUEST, which is why sleep/wake repairs the display:

write 0x45008 = 0x8043c000 REQUEST=1
read 0x45008 = 0xc043c000 STATE follows -> powered, scanout clean

The same pattern occurs on the other slice registers (0x44fe8, 0x44300, 0x44304).

Present a consistent view like GVT-g: trap the DBUF_CTL slice registers (S1..S4, only as many as the generation exposes) in BAR0 and clear POWER_STATE on read whenever POWER_REQUEST is not set. Writes pass straight through to the device.

---
 hw/vfio/igd.c | 119 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 119 insertions(+)
hw/vfio/igd.c +119 -0
index 413a49aae9163c6500bc50f29e5454f698addaa4..5e6160763cefb9d9739dd0a6462137c49109e81a 100644
@@ -455,6 +455,96 @@ static bool vfio_pci_igd_override_gms(int gen, uint32_t gms, uint32_t *gmch)
 #define IGD_GGC_MMIO_OFFSET     0x108040
 #define IGD_BDSM_MMIO_OFFSET    0x1080C0
 
+/*
+ * IGD BAR0 DBUF_CTL sanitize quirk.
+ *
+ * On hosts where the firmware POST modeset left the display engine powered,
+ * DBUF_CTL reads back POWER_STATE=1 while POWER_REQUEST=0 -- an inconsistent
+ * leftover that never occurs under GVT-g (which emulates the register so
+ * STATE follows REQUEST).  A passed-through guest driver samples POWER_STATE
+ * to decide which DBUF slices are already enabled, sees this stale "powered"
+ * bit, and therefore never issues POWER_REQUEST.  DBUF then powers down, the
+ * plane FIFO underruns, and scanout is corrupted until a full modeset (e.g.
+ * a display sleep/wake) re-requests power.
+ *
+ * Present a consistent view like GVT-g: intercept DBUF_CTL reads and clear
+ * POWER_STATE whenever POWER_REQUEST is not set.  Writes pass straight
+ * through to the device.
+ */
+#define IGD_DBUF_POWER_REQUEST  (1u << 31)
+#define IGD_DBUF_POWER_STATE    (1u << 30)
+
+/*
+ * DBUF_CTL slice registers within BAR0, in slice order (i915 numbers these
+ * S1..S4).  How many slices exist is generation-dependent, so only the first
+ * igd_dbuf_ctl_nslices(gen) entries are real DBUF_CTL registers on a given
+ * part; the rest are unrelated registers and must not be trapped.
+ */
+static const uint32_t igd_dbuf_ctl_offsets[] = {
+    0x45008, /* S1 */ 0x44FE8, /* S2 */ 0x44300, /* S3 */ 0x44304, /* S4 */
+};
+
+/*
+ * DBUF slice count by generation, matching i915 dbuf.slice_mask:
+ * gen9/10 = 1 (S1), gen11 = 2 (S1-S2), gen12+ = 4 (S1-S4).
+ *
+ * Within gen12 the slice count is actually per-platform, not per-gen: ADL-P /
+ * RPL-P / DG2 expose 4 slices, but TGL / RKL / ADL-S have only 2.  We return 4
+ * for all gen12+ (igd_gen() can't distinguish them), so on a <4-slice gen12
+ * part S3/S4 (0x44300/0x44304) are over-trapped.  This is harmless in practice:
+ * the read handler only mutates a value when POWER_REQUEST=0 && POWER_STATE=1,
+ * which whatever register lives at those offsets is very unlikely to present.
+ * A fully-correct count would have to key off the PCI device ID.
+ */
+static int igd_dbuf_ctl_nslices(int gen)
+{
+    if (gen <= 10) {
+        return 1;
+    }
+    if (gen == 11) {
+        return 2;
+    }
+    return 4;
+}
+
+typedef struct IGDDbufCtlQuirk {
+    VFIOPCIDevice *vdev;
+    uint32_t bar_offset;    /* offset within BAR0 MMIO */
+    uint8_t bar;
+} IGDDbufCtlQuirk;
+
+static uint64_t igd_dbuf_ctl_read(void *opaque, hwaddr addr, unsigned size)
+{
+    IGDDbufCtlQuirk *q = opaque;
+    VFIOPCIDevice *vdev = q->vdev;
+    uint64_t val = vfio_region_read(&vdev->bars[q->bar].region,
+                                    addr + q->bar_offset, size);
+
+    if (size == 4 && !(val & IGD_DBUF_POWER_REQUEST) &&
+        (val & IGD_DBUF_POWER_STATE)) {
+        val &= ~(uint64_t)IGD_DBUF_POWER_STATE;
+        error_report_once("IGD quirk: DBUF_CTL@0x%x cleared stale "
+                          "POWER_STATE (POWER_REQUEST=0)", q->bar_offset);
+    }
+    return val;
+}
+
+static void igd_dbuf_ctl_write(void *opaque, hwaddr addr,
+                               uint64_t data, unsigned size)
+{
+    IGDDbufCtlQuirk *q = opaque;
+    VFIOPCIDevice *vdev = q->vdev;
+
+    vfio_region_write(&vdev->bars[q->bar].region,
+                      addr + q->bar_offset, data, size);
+}
+
+static const MemoryRegionOps igd_dbuf_ctl_ops = {
+    .read = igd_dbuf_ctl_read,
+    .write = igd_dbuf_ctl_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+};
+
 void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
 {
     VFIOQuirk *ggc_quirk, *bdsm_quirk;
@@ -507,6 +597,35 @@ void vfio_probe_igd_bar0_quirk(VFIOPCIDevice *vdev, int nr)
                                         1);
 
     QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, bdsm_quirk, next);
+
+    /*
+     * DBUF_CTL sanitize quirk (gen9+): trap the DBUF_CTL slice registers so
+     * POWER_STATE is reported consistently with POWER_REQUEST (see
+     * igd_dbuf_ctl_read()).  Only trap slices that actually exist on this
+     * generation -- the remaining offsets are unrelated registers.
+     */
+    if (gen >= 9) {
+        int i, nslices = igd_dbuf_ctl_nslices(gen);
+        VFIOQuirk *dbuf_quirk = vfio_quirk_alloc(nslices);
+        IGDDbufCtlQuirk *dq;
+
+        dq = g_new0(IGDDbufCtlQuirk, nslices);
+        dbuf_quirk->data = dq;
+
+        for (i = 0; i < nslices; i++) {
+            dq[i].vdev = vdev;
+            dq[i].bar = nr;
+            dq[i].bar_offset = igd_dbuf_ctl_offsets[i];
+            memory_region_init_io(&dbuf_quirk->mem[i], OBJECT(vdev),
+                                  &igd_dbuf_ctl_ops, &dq[i],
+                                  "vfio-igd-dbuf-ctl-quirk", 4);
+            memory_region_add_subregion_overlap(vdev->bars[nr].region.mem,
+                                                igd_dbuf_ctl_offsets[i],
+                                                &dbuf_quirk->mem[i], 1);
+        }
+
+        QLIST_INSERT_HEAD(&vdev->bars[nr].quirks, dbuf_quirk, next);
+    }
 }
 
 static bool vfio_pci_igd_config_quirk(VFIOPCIDevice *vdev, Error **errp)
Signature · 1 line
2.56.0
#9 lore raw
In reply to Cédric Le Goater
Quoted 15 lines · Cédric Le Goater

The following changes since commit d5b5083cb783c447001e862c2b525e59f48ad78c:

   Merge tag 'block-pull-request' ofhttps://gitlab.com/stefanha/qemu into staging (2026-10-15 11:53:41 +0200)

are available in the Git repository at:

   https://github.com/legoater/qemu/ tags/pull-vfio-20261015

for you to fetch changes up to 2240c14c16dfc6c3b9840677f0d153165af7d4ee:

vfio/migration: Don't reset a device on a declined stop transition (2026-10-15 13:15:24 +0200)

----------------------------------------------------------------
vfio queue:

Quoted 11 lines

* Fix UBSAN shift error in MTRR mask computation on AMD EPYC with 52 physical address bits
* Add Fixes: tag validation to checkpatch
* Reject virtio-net failover during vfio-user init
* Sanitize DBUF_CTL POWER_STATE for iGPU passthrough, fixing display corruption on first boot
* Thread vf-token through iommufd bind
* Make MTL/ARL guests fall back to BAR-based framebuffer access in passthrough
* Update igd-assign.txt for Intel MTL and newer platforms
* Don't reset a VFIO device on a declined stop transition

Applied, thanks.

r~