qemu-kvm/kvm-vfio-only-check-region-info-cache-for-initial-region.patch
Miroslav Rezanina 9a3e1e2331 * Mon Nov 03 2025 Miroslav Rezanina <mrezanin@redhat.com> - 10.1.0-4
- kvm-qapi-machine-s390x-add-QAPI-event-SCLP_CPI_INFO_AVAI.patch [RHEL-104009 RHEL-105823 RHEL-73008]
- kvm-tests-functional-add-tests-for-SCLP-event-CPI.patch [RHEL-104009 RHEL-105823 RHEL-73008]
- kvm-redhat-Add-new-rhel9.8.0-and-rhel10.2.0-machine-type.patch [RHEL-104009 RHEL-105823 RHEL-73008]
- kvm-vfio-rename-field-to-num_initial_regions.patch [RHEL-118810]
- kvm-vfio-only-check-region-info-cache-for-initial-region.patch [RHEL-118810]
- kvm-arm-create-new-rhel-10.2-specific-virt-machine-type.patch [RHEL-105826 RHEL-105828]
- kvm-arm-create-new-rhel-9.8-specific-virt-machine-type.patch [RHEL-105826 RHEL-105828]
- kvm-x86-create-new-rhel-10.2-specific-pc-q35-machine-typ.patch [RHEL-105826 RHEL-105828]
- kvm-x86-create-new-rhel-9.8-specific-pc-q35-machine-type.patch [RHEL-105826 RHEL-105828]
- kvm-rh-enable-CONFIG_USB_STORAGE_BOT.patch [RHEL-101929]
- Resolves: RHEL-104009
  ([IBM 10.2 FEAT] KVM: Enhance machine type definition to include CPI and PCI passthru capabilities (qemu))
- Resolves: RHEL-105823
  (Add new -rhel10.2.0 machine type to qemu-kvm [s390x])
- Resolves: RHEL-73008
  ([IBM 10.2 FEAT] KVM: Implement Control Program Identification (qemu))
- Resolves: RHEL-118810
  ([RHEL 10.2] Windows 11 VM fails to boot up with ramfb='on' with QEMU 10.1)
- Resolves: RHEL-105826
  (Add new -rhel10.2.0 machine type to qemu-kvm [aarch64])
- Resolves: RHEL-105828
  (Add new -rhel10.2.0 machine type to qemu-kvm [x86_64])
- Resolves: RHEL-101929
  (enable 'usb-bot' device for proper support of USB CD-ROM drives via libvirt  )
2025-11-03 13:29:51 +01:00

84 lines
2.9 KiB
Diff

From 9659c700e0afab65e7993459764b2e802178873b Mon Sep 17 00:00:00 2001
From: John Levon <john.levon@nutanix.com>
Date: Tue, 14 Oct 2025 17:12:27 +0200
Subject: [PATCH 05/10] vfio: only check region info cache for initial regions
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
RH-Author: Cédric Le Goater <clg@redhat.com>
RH-MergeRequest: 414: Fixes for vfio region cache
RH-Jira: RHEL-118810
RH-Acked-by: Eric Auger <eric.auger@redhat.com>
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
RH-Commit: [2/2] 30b628642ee153e7da612e43aead3c6cd2de9769 (clegoate/qemu-kvm-centos)
It is semantically valid for a VFIO device to increase the number of
regions after initialization. In this case, we'd attempt to check for
cached region info past the size of the ->reginfo array. Check for the
region index and skip the cache in these cases.
This also works around some VGPU use cases which appear to be a bug,
where VFIO_DEVICE_QUERY_GFX_PLANE returns a region index beyond the
reported ->num_regions.
Fixes: 95cdb024 ("vfio: add region info cache")
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Alex Williamson <alex@shazbot.org>
Link: https://lore.kernel.org/qemu-devel/20251014151227.2298892-3-john.levon@nutanix.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit ecbe424a63c9f860a901d6a4a75724b046abd796)
---
hw/vfio/device.c | 27 +++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)
diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index 0b459c0f7c..7ebf41c95e 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -205,10 +205,19 @@ int vfio_device_get_region_info(VFIODevice *vbasedev, int index,
int fd = -1;
int ret;
- /* check cache */
- if (vbasedev->reginfo[index] != NULL) {
- *info = vbasedev->reginfo[index];
- return 0;
+ /*
+ * We only set up the region info cache for the initial number of regions.
+ *
+ * Since a VFIO device may later increase the number of regions then use
+ * such regions with an index past ->num_initial_regions, don't attempt to
+ * use the info cache in those cases.
+ */
+ if (index < vbasedev->num_initial_regions) {
+ /* check cache */
+ if (vbasedev->reginfo[index] != NULL) {
+ *info = vbasedev->reginfo[index];
+ return 0;
+ }
}
*info = g_malloc0(argsz);
@@ -236,10 +245,12 @@ retry:
goto retry;
}
- /* fill cache */
- vbasedev->reginfo[index] = *info;
- if (vbasedev->region_fds != NULL) {
- vbasedev->region_fds[index] = fd;
+ if (index < vbasedev->num_initial_regions) {
+ /* fill cache */
+ vbasedev->reginfo[index] = *info;
+ if (vbasedev->region_fds != NULL) {
+ vbasedev->region_fds[index] = fd;
+ }
}
return 0;
--
2.47.3