[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 02/16] vfio/pci: Extract mdev check into an helper
From: |
Cédric Le Goater |
Subject: |
[PULL 02/16] vfio/pci: Extract mdev check into an helper |
Date: |
Tue, 23 Jul 2024 16:00:05 +0200 |
From: Joao Martins <joao.m.martins@oracle.com>
In preparation to skip initialization of the HostIOMMUDevice for mdev,
extract the checks that validate if a device is an mdev into helpers.
A vfio_device_is_mdev() is created, and subsystems consult VFIODevice::mdev
to check if it's mdev or not.
Signed-off-by: Joao Martins <joao.m.martins@oracle.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
---
include/hw/vfio/vfio-common.h | 2 ++
hw/vfio/helpers.c | 14 ++++++++++++++
hw/vfio/pci.c | 12 +++---------
3 files changed, 19 insertions(+), 9 deletions(-)
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index
e8ddf92bb18547f0d3b811b3d757cbae7fec8b8d..98acae8c1c975390c6cd0fdc02a1282f64ea2987
100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -116,6 +116,7 @@ typedef struct VFIODevice {
DeviceState *dev;
int fd;
int type;
+ bool mdev;
bool reset_works;
bool needs_reset;
bool no_mmap;
@@ -231,6 +232,7 @@ void vfio_region_exit(VFIORegion *region);
void vfio_region_finalize(VFIORegion *region);
void vfio_reset_handler(void *opaque);
struct vfio_device_info *vfio_get_device_info(int fd);
+bool vfio_device_is_mdev(VFIODevice *vbasedev);
bool vfio_attach_device(char *name, VFIODevice *vbasedev,
AddressSpace *as, Error **errp);
void vfio_detach_device(VFIODevice *vbasedev);
diff --git a/hw/vfio/helpers.c b/hw/vfio/helpers.c
index
b14edd46edc9069bb148359a1b419253ff4e5ef0..7e23e9080c9d2860dea51ca5ef5fbc840d42a32d
100644
--- a/hw/vfio/helpers.c
+++ b/hw/vfio/helpers.c
@@ -675,3 +675,17 @@ int vfio_device_get_aw_bits(VFIODevice *vdev)
return HOST_IOMMU_DEVICE_CAP_AW_BITS_MAX;
}
+
+bool vfio_device_is_mdev(VFIODevice *vbasedev)
+{
+ g_autofree char *subsys = NULL;
+ g_autofree char *tmp = NULL;
+
+ if (!vbasedev->sysfsdev) {
+ return false;
+ }
+
+ tmp = g_strdup_printf("%s/subsystem", vbasedev->sysfsdev);
+ subsys = realpath(tmp, NULL);
+ return subsys && (strcmp(subsys, "/sys/bus/mdev") == 0);
+}
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index
e03d9f3ba5461f55f6351d937aba5d522a9128ec..b34e91468a533ab4d550bf2392e940b867f7b34c
100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2963,12 +2963,9 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
ERRP_GUARD();
VFIOPCIDevice *vdev = VFIO_PCI(pdev);
VFIODevice *vbasedev = &vdev->vbasedev;
- char *subsys;
int i, ret;
- bool is_mdev;
char uuid[UUID_STR_LEN];
g_autofree char *name = NULL;
- g_autofree char *tmp = NULL;
if (vbasedev->fd < 0 && !vbasedev->sysfsdev) {
if (!(~vdev->host.domain || ~vdev->host.bus ||
@@ -2997,14 +2994,11 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
* stays in sync with the active working set of the guest driver. Prevent
* the x-balloon-allowed option unless this is minimally an mdev device.
*/
- tmp = g_strdup_printf("%s/subsystem", vbasedev->sysfsdev);
- subsys = realpath(tmp, NULL);
- is_mdev = subsys && (strcmp(subsys, "/sys/bus/mdev") == 0);
- free(subsys);
+ vbasedev->mdev = vfio_device_is_mdev(vbasedev);
- trace_vfio_mdev(vbasedev->name, is_mdev);
+ trace_vfio_mdev(vbasedev->name, vbasedev->mdev);
- if (vbasedev->ram_block_discard_allowed && !is_mdev) {
+ if (vbasedev->ram_block_discard_allowed && !vbasedev->mdev) {
error_setg(errp, "x-balloon-allowed only potentially compatible "
"with mdev devices");
goto error;
--
2.45.2
- [PULL 00/16] vfio queue, Cédric Le Goater, 2024/07/23
- [PULL 01/16] hw/vfio/container: Fix SIGSEV on vfio_container_instance_finalize(), Cédric Le Goater, 2024/07/23
- [PULL 02/16] vfio/pci: Extract mdev check into an helper,
Cédric Le Goater <=
- [PULL 04/16] backends/iommufd: Extend iommufd_backend_get_device_info() to fetch HW capabilities, Cédric Le Goater, 2024/07/23
- [PULL 03/16] vfio/iommufd: Don't initialize nor set a HOST_IOMMU_DEVICE with mdev, Cédric Le Goater, 2024/07/23
- [PULL 05/16] vfio/iommufd: Return errno in iommufd_cdev_attach_ioas_hwpt(), Cédric Le Goater, 2024/07/23
- [PULL 06/16] vfio/ap: Don't initialize HOST_IOMMU_DEVICE with mdev, Cédric Le Goater, 2024/07/23
- [PULL 07/16] vfio/ccw: Don't initialize HOST_IOMMU_DEVICE with mdev, Cédric Le Goater, 2024/07/23
- [PULL 08/16] vfio/iommufd: Introduce auto domain creation, Cédric Le Goater, 2024/07/23
- [PULL 09/16] vfio/{iommufd,container}: Remove caps::aw_bits, Cédric Le Goater, 2024/07/23
- [PULL 10/16] vfio/iommufd: Add hw_caps field to HostIOMMUDeviceCaps, Cédric Le Goater, 2024/07/23
- [PULL 12/16] vfio/iommufd: Probe and request hwpt dirty tracking capability, Cédric Le Goater, 2024/07/23
- [PULL 11/16] vfio/{iommufd, container}: Invoke HostIOMMUDevice::realize() during attach_device(), Cédric Le Goater, 2024/07/23