vfio/pci: Conversion to realize
This patch converts VFIO PCI to realize function. Also original initfn errors now are propagated using QEMU error objects. All errors are formatted with the same pattern: "vfio: %s: the error description" Signed-off-by: Eric Auger <eric.auger@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
This commit is contained in:
parent
9bdbfbd50d
commit
1a22aca1d0
@ -2513,13 +2513,12 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice *vdev)
|
|||||||
vdev->req_enabled = false;
|
vdev->req_enabled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vfio_initfn(PCIDevice *pdev)
|
static void vfio_realize(PCIDevice *pdev, Error **errp)
|
||||||
{
|
{
|
||||||
VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
|
VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
|
||||||
VFIODevice *vbasedev_iter;
|
VFIODevice *vbasedev_iter;
|
||||||
VFIOGroup *group;
|
VFIOGroup *group;
|
||||||
char *tmp, group_path[PATH_MAX], *group_name;
|
char *tmp, group_path[PATH_MAX], *group_name;
|
||||||
Error *err = NULL;
|
|
||||||
ssize_t len;
|
ssize_t len;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int groupid;
|
int groupid;
|
||||||
@ -2533,9 +2532,9 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (stat(vdev->vbasedev.sysfsdev, &st) < 0) {
|
if (stat(vdev->vbasedev.sysfsdev, &st) < 0) {
|
||||||
error_setg_errno(&err, errno, "no such host device");
|
error_setg_errno(errp, errno, "no such host device");
|
||||||
ret = -errno;
|
error_prepend(errp, ERR_PREFIX, vdev->vbasedev.sysfsdev);
|
||||||
goto error;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
vdev->vbasedev.name = g_strdup(basename(vdev->vbasedev.sysfsdev));
|
vdev->vbasedev.name = g_strdup(basename(vdev->vbasedev.sysfsdev));
|
||||||
@ -2547,8 +2546,8 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
g_free(tmp);
|
g_free(tmp);
|
||||||
|
|
||||||
if (len <= 0 || len >= sizeof(group_path)) {
|
if (len <= 0 || len >= sizeof(group_path)) {
|
||||||
ret = len < 0 ? -errno : -ENAMETOOLONG;
|
error_setg_errno(errp, len < 0 ? errno : ENAMETOOLONG,
|
||||||
error_setg_errno(&err, -ret, "no iommu_group found");
|
"no iommu_group found");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2556,35 +2555,32 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
|
|
||||||
group_name = basename(group_path);
|
group_name = basename(group_path);
|
||||||
if (sscanf(group_name, "%d", &groupid) != 1) {
|
if (sscanf(group_name, "%d", &groupid) != 1) {
|
||||||
error_setg_errno(&err, errno, "failed to read %s", group_path);
|
error_setg_errno(errp, errno, "failed to read %s", group_path);
|
||||||
ret = -errno;
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
trace_vfio_initfn(vdev->vbasedev.name, groupid);
|
trace_vfio_realize(vdev->vbasedev.name, groupid);
|
||||||
|
|
||||||
group = vfio_get_group(groupid, pci_device_iommu_address_space(pdev), &err);
|
group = vfio_get_group(groupid, pci_device_iommu_address_space(pdev), errp);
|
||||||
if (!group) {
|
if (!group) {
|
||||||
ret = -ENOENT;
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
|
QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
|
||||||
if (strcmp(vbasedev_iter->name, vdev->vbasedev.name) == 0) {
|
if (strcmp(vbasedev_iter->name, vdev->vbasedev.name) == 0) {
|
||||||
error_setg(&err, "device is already attached");
|
error_setg(errp, "device is already attached");
|
||||||
vfio_put_group(group);
|
vfio_put_group(group);
|
||||||
ret = -EBUSY;
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = vfio_get_device(group, vdev->vbasedev.name, &vdev->vbasedev, &err);
|
ret = vfio_get_device(group, vdev->vbasedev.name, &vdev->vbasedev, errp);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
vfio_put_group(group);
|
vfio_put_group(group);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = vfio_populate_device(vdev, &err);
|
ret = vfio_populate_device(vdev, errp);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
@ -2595,7 +2591,7 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
vdev->config_offset);
|
vdev->config_offset);
|
||||||
if (ret < (int)MIN(pci_config_size(&vdev->pdev), vdev->config_size)) {
|
if (ret < (int)MIN(pci_config_size(&vdev->pdev), vdev->config_size)) {
|
||||||
ret = ret < 0 ? -errno : -EFAULT;
|
ret = ret < 0 ? -errno : -EFAULT;
|
||||||
error_setg_errno(&err, -ret, "failed to read device config space");
|
error_setg_errno(errp, -ret, "failed to read device config space");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2612,8 +2608,7 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
*/
|
*/
|
||||||
if (vdev->vendor_id != PCI_ANY_ID) {
|
if (vdev->vendor_id != PCI_ANY_ID) {
|
||||||
if (vdev->vendor_id >= 0xffff) {
|
if (vdev->vendor_id >= 0xffff) {
|
||||||
error_setg(&err, "invalid PCI vendor ID provided");
|
error_setg(errp, "invalid PCI vendor ID provided");
|
||||||
ret = -EINVAL;
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
vfio_add_emulated_word(vdev, PCI_VENDOR_ID, vdev->vendor_id, ~0);
|
vfio_add_emulated_word(vdev, PCI_VENDOR_ID, vdev->vendor_id, ~0);
|
||||||
@ -2624,8 +2619,7 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
|
|
||||||
if (vdev->device_id != PCI_ANY_ID) {
|
if (vdev->device_id != PCI_ANY_ID) {
|
||||||
if (vdev->device_id > 0xffff) {
|
if (vdev->device_id > 0xffff) {
|
||||||
error_setg(&err, "invalid PCI device ID provided");
|
error_setg(errp, "invalid PCI device ID provided");
|
||||||
ret = -EINVAL;
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
vfio_add_emulated_word(vdev, PCI_DEVICE_ID, vdev->device_id, ~0);
|
vfio_add_emulated_word(vdev, PCI_DEVICE_ID, vdev->device_id, ~0);
|
||||||
@ -2636,8 +2630,7 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
|
|
||||||
if (vdev->sub_vendor_id != PCI_ANY_ID) {
|
if (vdev->sub_vendor_id != PCI_ANY_ID) {
|
||||||
if (vdev->sub_vendor_id > 0xffff) {
|
if (vdev->sub_vendor_id > 0xffff) {
|
||||||
error_setg(&err, "invalid PCI subsystem vendor ID provided");
|
error_setg(errp, "invalid PCI subsystem vendor ID provided");
|
||||||
ret = -EINVAL;
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
vfio_add_emulated_word(vdev, PCI_SUBSYSTEM_VENDOR_ID,
|
vfio_add_emulated_word(vdev, PCI_SUBSYSTEM_VENDOR_ID,
|
||||||
@ -2648,8 +2641,7 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
|
|
||||||
if (vdev->sub_device_id != PCI_ANY_ID) {
|
if (vdev->sub_device_id != PCI_ANY_ID) {
|
||||||
if (vdev->sub_device_id > 0xffff) {
|
if (vdev->sub_device_id > 0xffff) {
|
||||||
error_setg(&err, "invalid PCI subsystem device ID provided");
|
error_setg(errp, "invalid PCI subsystem device ID provided");
|
||||||
ret = -EINVAL;
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
vfio_add_emulated_word(vdev, PCI_SUBSYSTEM_ID, vdev->sub_device_id, ~0);
|
vfio_add_emulated_word(vdev, PCI_SUBSYSTEM_ID, vdev->sub_device_id, ~0);
|
||||||
@ -2678,14 +2670,14 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
|
|
||||||
vfio_pci_size_rom(vdev);
|
vfio_pci_size_rom(vdev);
|
||||||
|
|
||||||
ret = vfio_msix_early_setup(vdev, &err);
|
ret = vfio_msix_early_setup(vdev, errp);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
vfio_bars_setup(vdev);
|
vfio_bars_setup(vdev);
|
||||||
|
|
||||||
ret = vfio_add_capabilities(vdev, &err);
|
ret = vfio_add_capabilities(vdev, errp);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
goto out_teardown;
|
goto out_teardown;
|
||||||
}
|
}
|
||||||
@ -2703,10 +2695,9 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
struct vfio_region_info *opregion;
|
struct vfio_region_info *opregion;
|
||||||
|
|
||||||
if (vdev->pdev.qdev.hotplugged) {
|
if (vdev->pdev.qdev.hotplugged) {
|
||||||
error_setg(&err,
|
error_setg(errp,
|
||||||
"cannot support IGD OpRegion feature on hotplugged "
|
"cannot support IGD OpRegion feature on hotplugged "
|
||||||
"device");
|
"device");
|
||||||
ret = -EINVAL;
|
|
||||||
goto out_teardown;
|
goto out_teardown;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2714,12 +2705,12 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
|
VFIO_REGION_TYPE_PCI_VENDOR_TYPE | PCI_VENDOR_ID_INTEL,
|
||||||
VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, &opregion);
|
VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION, &opregion);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
error_setg_errno(&err, -ret,
|
error_setg_errno(errp, -ret,
|
||||||
"does not support requested IGD OpRegion feature");
|
"does not support requested IGD OpRegion feature");
|
||||||
goto out_teardown;
|
goto out_teardown;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = vfio_pci_igd_opregion_init(vdev, opregion, &err);
|
ret = vfio_pci_igd_opregion_init(vdev, opregion, errp);
|
||||||
g_free(opregion);
|
g_free(opregion);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
goto out_teardown;
|
goto out_teardown;
|
||||||
@ -2741,7 +2732,7 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
vdev->intx.mmap_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,
|
vdev->intx.mmap_timer = timer_new_ms(QEMU_CLOCK_VIRTUAL,
|
||||||
vfio_intx_mmap_enable, vdev);
|
vfio_intx_mmap_enable, vdev);
|
||||||
pci_device_set_intx_routing_notifier(&vdev->pdev, vfio_intx_update);
|
pci_device_set_intx_routing_notifier(&vdev->pdev, vfio_intx_update);
|
||||||
ret = vfio_intx_enable(vdev, &err);
|
ret = vfio_intx_enable(vdev, errp);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
goto out_teardown;
|
goto out_teardown;
|
||||||
}
|
}
|
||||||
@ -2751,17 +2742,14 @@ static int vfio_initfn(PCIDevice *pdev)
|
|||||||
vfio_register_req_notifier(vdev);
|
vfio_register_req_notifier(vdev);
|
||||||
vfio_setup_resetfn_quirk(vdev);
|
vfio_setup_resetfn_quirk(vdev);
|
||||||
|
|
||||||
return 0;
|
return;
|
||||||
|
|
||||||
out_teardown:
|
out_teardown:
|
||||||
pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
|
pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
|
||||||
vfio_teardown_msi(vdev);
|
vfio_teardown_msi(vdev);
|
||||||
vfio_bars_exit(vdev);
|
vfio_bars_exit(vdev);
|
||||||
error:
|
error:
|
||||||
if (err) {
|
error_prepend(errp, ERR_PREFIX, vdev->vbasedev.name);
|
||||||
error_reportf_err(err, ERR_PREFIX, vdev->vbasedev.name);
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void vfio_instance_finalize(Object *obj)
|
static void vfio_instance_finalize(Object *obj)
|
||||||
@ -2890,7 +2878,7 @@ static void vfio_pci_dev_class_init(ObjectClass *klass, void *data)
|
|||||||
dc->vmsd = &vfio_pci_vmstate;
|
dc->vmsd = &vfio_pci_vmstate;
|
||||||
dc->desc = "VFIO-based PCI device assignment";
|
dc->desc = "VFIO-based PCI device assignment";
|
||||||
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
|
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
|
||||||
pdc->init = vfio_initfn;
|
pdc->realize = vfio_realize;
|
||||||
pdc->exit = vfio_exitfn;
|
pdc->exit = vfio_exitfn;
|
||||||
pdc->config_read = vfio_pci_read_config;
|
pdc->config_read = vfio_pci_read_config;
|
||||||
pdc->config_write = vfio_pci_write_config;
|
pdc->config_write = vfio_pci_write_config;
|
||||||
|
@ -36,7 +36,7 @@ vfio_pci_hot_reset_dep_devices(int domain, int bus, int slot, int function, int
|
|||||||
vfio_pci_hot_reset_result(const char *name, const char *result) "%s hot reset: %s"
|
vfio_pci_hot_reset_result(const char *name, const char *result) "%s hot reset: %s"
|
||||||
vfio_populate_device_config(const char *name, unsigned long size, unsigned long offset, unsigned long flags) "Device %s config:\n size: 0x%lx, offset: 0x%lx, flags: 0x%lx"
|
vfio_populate_device_config(const char *name, unsigned long size, unsigned long offset, unsigned long flags) "Device %s config:\n size: 0x%lx, offset: 0x%lx, flags: 0x%lx"
|
||||||
vfio_populate_device_get_irq_info_failure(void) "VFIO_DEVICE_GET_IRQ_INFO failure: %m"
|
vfio_populate_device_get_irq_info_failure(void) "VFIO_DEVICE_GET_IRQ_INFO failure: %m"
|
||||||
vfio_initfn(const char *name, int group_id) " (%s) group %d"
|
vfio_realize(const char *name, int group_id) " (%s) group %d"
|
||||||
vfio_add_ext_cap_dropped(const char *name, uint16_t cap, uint16_t offset) "%s %x@%x"
|
vfio_add_ext_cap_dropped(const char *name, uint16_t cap, uint16_t offset) "%s %x@%x"
|
||||||
vfio_pci_reset(const char *name) " (%s)"
|
vfio_pci_reset(const char *name) " (%s)"
|
||||||
vfio_pci_reset_flr(const char *name) "%s FLR/VFIO_DEVICE_RESET"
|
vfio_pci_reset_flr(const char *name) "%s FLR/VFIO_DEVICE_RESET"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user