From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Alex Williamson" <alex.williamson@redhat.com>,
"Eric Auger" <eric.auger@redhat.com>,
"Zhenzhong Duan" <zhenzhong.duan@intel.com>,
"Cédric Le Goater" <clg@redhat.com>
Subject: [PULL 19/22] vfio/pci: Remove vfio_detach_device from vfio_realize error path
Date: Wed, 18 Oct 2023 11:45:28 +0200 [thread overview]
Message-ID: <20231018094531.733211-20-clg@redhat.com> (raw)
In-Reply-To: <20231018094531.733211-1-clg@redhat.com>
From: Eric Auger <eric.auger@redhat.com>
In vfio_realize, on the error path, we currently call
vfio_detach_device() after a successful vfio_attach_device.
While this looks natural, vfio_instance_finalize also induces
a vfio_detach_device(), and it seems to be the right place
instead as other resources are released there which happen
to be a prerequisite to a successful UNSET_CONTAINER.
So let's rely on the finalize vfio_detach_device call to free
all the relevant resources.
Fixes: a28e06621170 ("vfio/pci: Introduce vfio_[attach/detach]_device")
Reported-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Signed-off-by: Eric Auger <eric.auger@redhat.com>
Tested-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
hw/vfio/pci.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 40ae46266e33a2b58ed1069113c2967489ed3b95..6e3f6aba28e55311e8bcc4ac757e18c8aa2433f1 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -3115,7 +3115,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
vfio_populate_device(vdev, &err);
if (err) {
error_propagate(errp, err);
- goto out_detach;
+ goto error;
}
/* Get a copy of config space */
@@ -3125,7 +3125,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
if (ret < (int)MIN(pci_config_size(&vdev->pdev), vdev->config_size)) {
ret = ret < 0 ? -errno : -EFAULT;
error_setg_errno(errp, -ret, "failed to read device config space");
- goto out_detach;
+ goto error;
}
/* vfio emulates a lot for us, but some bits need extra love */
@@ -3144,7 +3144,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
if (vdev->vendor_id != PCI_ANY_ID) {
if (vdev->vendor_id >= 0xffff) {
error_setg(errp, "invalid PCI vendor ID provided");
- goto out_detach;
+ goto error;
}
vfio_add_emulated_word(vdev, PCI_VENDOR_ID, vdev->vendor_id, ~0);
trace_vfio_pci_emulated_vendor_id(vbasedev->name, vdev->vendor_id);
@@ -3155,7 +3155,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
if (vdev->device_id != PCI_ANY_ID) {
if (vdev->device_id > 0xffff) {
error_setg(errp, "invalid PCI device ID provided");
- goto out_detach;
+ goto error;
}
vfio_add_emulated_word(vdev, PCI_DEVICE_ID, vdev->device_id, ~0);
trace_vfio_pci_emulated_device_id(vbasedev->name, vdev->device_id);
@@ -3166,7 +3166,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
if (vdev->sub_vendor_id != PCI_ANY_ID) {
if (vdev->sub_vendor_id > 0xffff) {
error_setg(errp, "invalid PCI subsystem vendor ID provided");
- goto out_detach;
+ goto error;
}
vfio_add_emulated_word(vdev, PCI_SUBSYSTEM_VENDOR_ID,
vdev->sub_vendor_id, ~0);
@@ -3177,7 +3177,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
if (vdev->sub_device_id != PCI_ANY_ID) {
if (vdev->sub_device_id > 0xffff) {
error_setg(errp, "invalid PCI subsystem device ID provided");
- goto out_detach;
+ goto error;
}
vfio_add_emulated_word(vdev, PCI_SUBSYSTEM_ID, vdev->sub_device_id, ~0);
trace_vfio_pci_emulated_sub_device_id(vbasedev->name,
@@ -3210,7 +3210,7 @@ static void vfio_realize(PCIDevice *pdev, Error **errp)
vfio_msix_early_setup(vdev, &err);
if (err) {
error_propagate(errp, err);
- goto out_detach;
+ goto error;
}
vfio_bars_register(vdev);
@@ -3326,8 +3326,6 @@ out_deregister:
out_teardown:
vfio_teardown_msi(vdev);
vfio_bars_exit(vdev);
-out_detach:
- vfio_detach_device(vbasedev);
error:
error_prepend(errp, VFIO_MSG_PREFIX, vbasedev->name);
}
--
2.41.0
next prev parent reply other threads:[~2023-10-18 9:52 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-18 9:45 [PULL 00/22] vfio queue Cédric Le Goater
2023-10-18 9:45 ` [PULL 01/22] scripts/update-linux-headers: Add iommufd.h Cédric Le Goater
2023-10-18 9:45 ` [PULL 02/22] linux-headers: " Cédric Le Goater
2023-10-18 9:45 ` [PULL 03/22] vfio/common: Move IOMMU agnostic helpers to a separate file Cédric Le Goater
2023-10-18 9:45 ` [PULL 04/22] vfio/common: Propagate KVM_SET_DEVICE_ATTR error if any Cédric Le Goater
2023-10-18 9:45 ` [PULL 05/22] vfio/common: Introduce vfio_container_add|del_section_window() Cédric Le Goater
2023-10-18 9:45 ` [PULL 06/22] vfio/common: Extract out vfio_kvm_device_[add/del]_fd Cédric Le Goater
2023-10-18 9:45 ` [PULL 07/22] vfio/pci: Introduce vfio_[attach/detach]_device Cédric Le Goater
2023-10-18 9:45 ` [PULL 08/22] vfio/platform: Use vfio_[attach/detach]_device Cédric Le Goater
2023-10-18 9:45 ` [PULL 09/22] vfio/ap: " Cédric Le Goater
2023-10-18 9:45 ` [PULL 10/22] vfio/ccw: " Cédric Le Goater
2023-10-18 9:45 ` [PULL 11/22] vfio/common: Move VFIO reset handler registration to a group agnostic function Cédric Le Goater
2023-10-18 9:45 ` [PULL 12/22] vfio/common: Introduce a per container device list Cédric Le Goater
2023-10-18 9:45 ` [PULL 13/22] vfio/common: Store the parent container in VFIODevice Cédric Le Goater
2023-10-18 9:45 ` [PULL 14/22] vfio/common: Introduce a global VFIODevice list Cédric Le Goater
2023-10-18 9:45 ` [PULL 15/22] vfio/common: Move legacy VFIO backend code into separate container.c Cédric Le Goater
2023-10-18 9:45 ` [PULL 16/22] vfio/pci: Fix a potential memory leak in vfio_listener_region_add Cédric Le Goater
2023-10-18 9:45 ` [PULL 17/22] vfio/ap: Remove pointless apdev variable Cédric Le Goater
2023-10-18 9:45 ` [PULL 18/22] vfio/ccw: Remove redundant definition of TYPE_VFIO_CCW Cédric Le Goater
2023-10-18 9:45 ` Cédric Le Goater [this message]
2023-10-18 9:45 ` [PULL 20/22] ramfb: add migration support Cédric Le Goater
2023-10-18 9:45 ` [PULL 21/22] ramfb-standalone: " Cédric Le Goater
2023-10-18 9:45 ` [PULL 22/22] hw/vfio: add ramfb " Cédric Le Goater
2023-10-18 22:32 ` [PULL 00/22] vfio queue Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231018094531.733211-20-clg@redhat.com \
--to=clg@redhat.com \
--cc=alex.williamson@redhat.com \
--cc=eric.auger@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=zhenzhong.duan@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).