qemu-kvm/kvm-vfio-rename-field-to-num_initial_regions.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

254 lines
10 KiB
Diff

From de33fcdabae841dba89fae781d6391164b22740f Mon Sep 17 00:00:00 2001
From: John Levon <john.levon@nutanix.com>
Date: Tue, 14 Oct 2025 17:12:26 +0200
Subject: [PATCH 04/10] vfio: rename field to "num_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: [1/2] 62524d77e79b6a57c4e61762cd61449280e4f2cd (clegoate/qemu-kvm-centos)
We set VFIODevice::num_regions at initialization time, and do not
otherwise refresh it. As it is valid in theory for a VFIO device to
later increase the number of supported regions, rename the field to
"num_initial_regions" to better reflect its semantics.
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-2-john.levon@nutanix.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit aaca725884b57c9245528a0afb3f32e078543faf)
Conflicts: Modified hw/core/sysbus-fdt.c and hw/vfio/platform.c
---
hw/core/sysbus-fdt.c | 14 +++++++-------
hw/vfio-user/device.c | 2 +-
hw/vfio/ccw.c | 4 ++--
hw/vfio/device.c | 12 ++++++------
hw/vfio/iommufd.c | 3 ++-
hw/vfio/pci.c | 4 ++--
hw/vfio/platform.c | 10 +++++-----
include/hw/vfio/vfio-device.h | 2 +-
8 files changed, 26 insertions(+), 25 deletions(-)
diff --git a/hw/core/sysbus-fdt.c b/hw/core/sysbus-fdt.c
index c339a27875..1e1966813f 100644
--- a/hw/core/sysbus-fdt.c
+++ b/hw/core/sysbus-fdt.c
@@ -236,15 +236,15 @@ static int add_calxeda_midway_xgmac_fdt_node(SysBusDevice *sbdev, void *opaque)
qemu_fdt_setprop(fdt, nodename, "dma-coherent", "", 0);
- reg_attr = g_new(uint32_t, vbasedev->num_regions * 2);
- for (i = 0; i < vbasedev->num_regions; i++) {
+ reg_attr = g_new(uint32_t, vbasedev->num_initial_regions * 2);
+ for (i = 0; i < vbasedev->num_initial_regions; i++) {
mmio_base = platform_bus_get_mmio_addr(pbus, sbdev, i);
reg_attr[2 * i] = cpu_to_be32(mmio_base);
reg_attr[2 * i + 1] = cpu_to_be32(
memory_region_size(vdev->regions[i]->mem));
}
qemu_fdt_setprop(fdt, nodename, "reg", reg_attr,
- vbasedev->num_regions * 2 * sizeof(uint32_t));
+ vbasedev->num_initial_regions * 2 * sizeof(uint32_t));
irq_attr = g_new(uint32_t, vbasedev->num_irqs * 3);
for (i = 0; i < vbasedev->num_irqs; i++) {
@@ -330,7 +330,7 @@ static int add_amd_xgbe_fdt_node(SysBusDevice *sbdev, void *opaque)
g_free(dt_name);
- if (vbasedev->num_regions != 5) {
+ if (vbasedev->num_initial_regions != 5) {
error_report("%s Does the host dt node combine XGBE/PHY?", __func__);
exit(1);
}
@@ -374,15 +374,15 @@ static int add_amd_xgbe_fdt_node(SysBusDevice *sbdev, void *opaque)
guest_clock_phandles[0],
guest_clock_phandles[1]);
- reg_attr = g_new(uint32_t, vbasedev->num_regions * 2);
- for (i = 0; i < vbasedev->num_regions; i++) {
+ reg_attr = g_new(uint32_t, vbasedev->num_initial_regions * 2);
+ for (i = 0; i < vbasedev->num_initial_regions; i++) {
mmio_base = platform_bus_get_mmio_addr(pbus, sbdev, i);
reg_attr[2 * i] = cpu_to_be32(mmio_base);
reg_attr[2 * i + 1] = cpu_to_be32(
memory_region_size(vdev->regions[i]->mem));
}
qemu_fdt_setprop(guest_fdt, nodename, "reg", reg_attr,
- vbasedev->num_regions * 2 * sizeof(uint32_t));
+ vbasedev->num_initial_regions * 2 * sizeof(uint32_t));
irq_attr = g_new(uint32_t, vbasedev->num_irqs * 3);
for (i = 0; i < vbasedev->num_irqs; i++) {
diff --git a/hw/vfio-user/device.c b/hw/vfio-user/device.c
index 0609a7dc25..64ef35b320 100644
--- a/hw/vfio-user/device.c
+++ b/hw/vfio-user/device.c
@@ -134,7 +134,7 @@ static int vfio_user_device_io_get_region_info(VFIODevice *vbasedev,
VFIOUserFDs fds = { 0, 1, fd};
int ret;
- if (info->index > vbasedev->num_regions) {
+ if (info->index > vbasedev->num_initial_regions) {
return -EINVAL;
}
diff --git a/hw/vfio/ccw.c b/hw/vfio/ccw.c
index 9560b8d851..4d9588e7aa 100644
--- a/hw/vfio/ccw.c
+++ b/hw/vfio/ccw.c
@@ -484,9 +484,9 @@ static bool vfio_ccw_get_region(VFIOCCWDevice *vcdev, Error **errp)
* We always expect at least the I/O region to be present. We also
* may have a variable number of regions governed by capabilities.
*/
- if (vdev->num_regions < VFIO_CCW_CONFIG_REGION_INDEX + 1) {
+ if (vdev->num_initial_regions < VFIO_CCW_CONFIG_REGION_INDEX + 1) {
error_setg(errp, "vfio: too few regions (%u), expected at least %u",
- vdev->num_regions, VFIO_CCW_CONFIG_REGION_INDEX + 1);
+ vdev->num_initial_regions, VFIO_CCW_CONFIG_REGION_INDEX + 1);
return false;
}
diff --git a/hw/vfio/device.c b/hw/vfio/device.c
index 52a1996dc4..0b459c0f7c 100644
--- a/hw/vfio/device.c
+++ b/hw/vfio/device.c
@@ -257,7 +257,7 @@ int vfio_device_get_region_info_type(VFIODevice *vbasedev, uint32_t type,
{
int i;
- for (i = 0; i < vbasedev->num_regions; i++) {
+ for (i = 0; i < vbasedev->num_initial_regions; i++) {
struct vfio_info_cap_header *hdr;
struct vfio_region_info_cap_type *cap_type;
@@ -466,7 +466,7 @@ void vfio_device_prepare(VFIODevice *vbasedev, VFIOContainerBase *bcontainer,
int i;
vbasedev->num_irqs = info->num_irqs;
- vbasedev->num_regions = info->num_regions;
+ vbasedev->num_initial_regions = info->num_regions;
vbasedev->flags = info->flags;
vbasedev->reset_works = !!(info->flags & VFIO_DEVICE_FLAGS_RESET);
@@ -476,10 +476,10 @@ void vfio_device_prepare(VFIODevice *vbasedev, VFIOContainerBase *bcontainer,
QLIST_INSERT_HEAD(&vfio_device_list, vbasedev, global_next);
vbasedev->reginfo = g_new0(struct vfio_region_info *,
- vbasedev->num_regions);
+ vbasedev->num_initial_regions);
if (vbasedev->use_region_fds) {
- vbasedev->region_fds = g_new0(int, vbasedev->num_regions);
- for (i = 0; i < vbasedev->num_regions; i++) {
+ vbasedev->region_fds = g_new0(int, vbasedev->num_initial_regions);
+ for (i = 0; i < vbasedev->num_initial_regions; i++) {
vbasedev->region_fds[i] = -1;
}
}
@@ -489,7 +489,7 @@ void vfio_device_unprepare(VFIODevice *vbasedev)
{
int i;
- for (i = 0; i < vbasedev->num_regions; i++) {
+ for (i = 0; i < vbasedev->num_initial_regions; i++) {
g_free(vbasedev->reginfo[i]);
if (vbasedev->region_fds != NULL && vbasedev->region_fds[i] != -1) {
close(vbasedev->region_fds[i]);
diff --git a/hw/vfio/iommufd.c b/hw/vfio/iommufd.c
index 48c590b6a9..dbcd861b27 100644
--- a/hw/vfio/iommufd.c
+++ b/hw/vfio/iommufd.c
@@ -668,7 +668,8 @@ found_container:
vfio_iommufd_cpr_register_device(vbasedev);
trace_iommufd_cdev_device_info(vbasedev->name, devfd, vbasedev->num_irqs,
- vbasedev->num_regions, vbasedev->flags);
+ vbasedev->num_initial_regions,
+ vbasedev->flags);
return true;
err_listener_register:
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 48da233cb2..9486521a90 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2933,9 +2933,9 @@ bool vfio_pci_populate_device(VFIOPCIDevice *vdev, Error **errp)
return false;
}
- if (vbasedev->num_regions < VFIO_PCI_CONFIG_REGION_INDEX + 1) {
+ if (vbasedev->num_initial_regions < VFIO_PCI_CONFIG_REGION_INDEX + 1) {
error_setg(errp, "unexpected number of io regions %u",
- vbasedev->num_regions);
+ vbasedev->num_initial_regions);
return false;
}
diff --git a/hw/vfio/platform.c b/hw/vfio/platform.c
index 5c1795a26f..c9349ba7b7 100644
--- a/hw/vfio/platform.c
+++ b/hw/vfio/platform.c
@@ -148,7 +148,7 @@ static void vfio_mmap_set_enabled(VFIOPlatformDevice *vdev, bool enabled)
{
int i;
- for (i = 0; i < vdev->vbasedev.num_regions; i++) {
+ for (i = 0; i < vdev->vbasedev.num_initial_regions; i++) {
vfio_region_mmaps_set_enabled(vdev->regions[i], enabled);
}
}
@@ -453,9 +453,9 @@ static bool vfio_populate_device(VFIODevice *vbasedev, Error **errp)
return false;
}
- vdev->regions = g_new0(VFIORegion *, vbasedev->num_regions);
+ vdev->regions = g_new0(VFIORegion *, vbasedev->num_initial_regions);
- for (i = 0; i < vbasedev->num_regions; i++) {
+ for (i = 0; i < vbasedev->num_initial_regions; i++) {
char *name = g_strdup_printf("VFIO %s region %d\n", vbasedev->name, i);
vdev->regions[i] = g_new0(VFIORegion, 1);
@@ -499,7 +499,7 @@ irq_err:
g_free(intp);
}
reg_error:
- for (i = 0; i < vbasedev->num_regions; i++) {
+ for (i = 0; i < vbasedev->num_initial_regions; i++) {
if (vdev->regions[i]) {
vfio_region_finalize(vdev->regions[i]);
}
@@ -608,7 +608,7 @@ static void vfio_platform_realize(DeviceState *dev, Error **errp)
}
}
- for (i = 0; i < vbasedev->num_regions; i++) {
+ for (i = 0; i < vbasedev->num_initial_regions; i++) {
if (vfio_region_mmap(vdev->regions[i])) {
warn_report("%s mmap unsupported, performance may be slow",
memory_region_name(vdev->regions[i]->mem));
diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h
index 9290774299..df81d319b2 100644
--- a/include/hw/vfio/vfio-device.h
+++ b/include/hw/vfio/vfio-device.h
@@ -74,7 +74,7 @@ typedef struct VFIODevice {
VFIODeviceOps *ops;
VFIODeviceIOOps *io_ops;
unsigned int num_irqs;
- unsigned int num_regions;
+ unsigned int num_initial_regions;
unsigned int flags;
VFIOMigration *migration;
Error *migration_blocker;
--
2.47.3