aboutsummaryrefslogtreecommitdiff
path: root/hw/s390x
diff options
context:
space:
mode:
authorAlex Williamson <alex.williamson@redhat.com>2023-06-01 08:45:06 -0600
committerCédric Le Goater <clg@redhat.com>2023-06-30 06:02:51 +0200
commit634f38f0f73f12b86a53195782b26506c107a418 (patch)
treef7027e64f5315a3713a2e2900715c57e015d4e16 /hw/s390x
parent745c42912a04306e8c7765dd4cc1574a92de4446 (diff)
downloadqemu-634f38f0f73f12b86a53195782b26506c107a418.zip
qemu-634f38f0f73f12b86a53195782b26506c107a418.tar.gz
qemu-634f38f0f73f12b86a53195782b26506c107a418.tar.bz2
vfio: Implement a common device info helper
A common helper implementing the realloc algorithm for handling capabilities. Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Reviewed-by: Cédric Le Goater <clg@redhat.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com> Reviewed-by: Robin Voetter <robin@streamhpc.com> Signed-off-by: Cédric Le Goater <clg@redhat.com>
Diffstat (limited to 'hw/s390x')
-rw-r--r--hw/s390x/s390-pci-vfio.c37
1 files changed, 5 insertions, 32 deletions
diff --git a/hw/s390x/s390-pci-vfio.c b/hw/s390x/s390-pci-vfio.c
index f51190d..59a2e03 100644
--- a/hw/s390x/s390-pci-vfio.c
+++ b/hw/s390x/s390-pci-vfio.c
@@ -289,38 +289,11 @@ static void s390_pci_read_pfip(S390PCIBusDevice *pbdev,
memcpy(pbdev->zpci_fn.pfip, cap->pfip, CLP_PFIP_NR_SEGMENTS);
}
-static struct vfio_device_info *get_device_info(S390PCIBusDevice *pbdev,
- uint32_t argsz)
+static struct vfio_device_info *get_device_info(S390PCIBusDevice *pbdev)
{
- struct vfio_device_info *info = g_malloc0(argsz);
- VFIOPCIDevice *vfio_pci;
- int fd;
+ VFIOPCIDevice *vfio_pci = container_of(pbdev->pdev, VFIOPCIDevice, pdev);
- vfio_pci = container_of(pbdev->pdev, VFIOPCIDevice, pdev);
- fd = vfio_pci->vbasedev.fd;
-
- /*
- * If the specified argsz is not large enough to contain all capabilities
- * it will be updated upon return from the ioctl. Retry until we have
- * a big enough buffer to hold the entire capability chain. On error,
- * just exit and rely on CLP defaults.
- */
-retry:
- info->argsz = argsz;
-
- if (ioctl(fd, VFIO_DEVICE_GET_INFO, info)) {
- trace_s390_pci_clp_dev_info(vfio_pci->vbasedev.name);
- g_free(info);
- return NULL;
- }
-
- if (info->argsz > argsz) {
- argsz = info->argsz;
- info = g_realloc(info, argsz);
- goto retry;
- }
-
- return info;
+ return vfio_get_device_info(vfio_pci->vbasedev.fd);
}
/*
@@ -335,7 +308,7 @@ bool s390_pci_get_host_fh(S390PCIBusDevice *pbdev, uint32_t *fh)
assert(fh);
- info = get_device_info(pbdev, sizeof(*info));
+ info = get_device_info(pbdev);
if (!info) {
return false;
}
@@ -356,7 +329,7 @@ void s390_pci_get_clp_info(S390PCIBusDevice *pbdev)
{
g_autofree struct vfio_device_info *info = NULL;
- info = get_device_info(pbdev, sizeof(*info));
+ info = get_device_info(pbdev);
if (!info) {
return;
}