[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [v11 10/15] vfio: add sec_bus_reset notifier to notify phys
From: |
Chen Fan |
Subject: |
[Qemu-devel] [v11 10/15] vfio: add sec_bus_reset notifier to notify physical bus reset is needed |
Date: |
Wed, 24 Jun 2015 17:46:03 +0800 |
Signed-off-by: Chen Fan <address@hidden>
---
hw/vfio/pci.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 83 insertions(+)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index c2af8f1..7cc81ae 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -156,6 +156,7 @@ typedef struct VFIOPCIDevice {
PCIHostDeviceAddress host;
EventNotifier err_notifier;
EventNotifier req_notifier;
+ Notifier sec_bus_reset_notifier;
int (*resetfn)(struct VFIOPCIDevice *);
uint32_t features;
#define VFIO_FEATURE_ENABLE_VGA_BIT 0
@@ -171,6 +172,7 @@ typedef struct VFIOPCIDevice {
bool req_enabled;
bool has_flr;
bool has_pm_reset;
+ bool needs_bus_reset;
bool rom_read_failed;
} VFIOPCIDevice;
@@ -3001,6 +3003,81 @@ static int vfio_check_devices_host_bus_reset(void)
return 0;
}
+/* Update all the reset state of the affected devices in VM */
+static void vfio_pci_host_needs_bus_reset(Notifier *n, void *opaque)
+{
+ VFIOPCIDevice *vdev = container_of(n, VFIOPCIDevice,
sec_bus_reset_notifier);
+ VFIODevice *vbasedev = &vdev->vbasedev;
+ PCIDevice *parent = opaque;
+ VFIOGroup *group;
+ struct vfio_pci_hot_reset_info *info = NULL;
+ struct vfio_pci_dependent_device *devices;
+ int i, ret;
+
+ ret = vfio_get_hot_reset_info(vdev, &info);
+ if (ret) {
+ goto out;
+ }
+
+ vdev->needs_bus_reset = true;
+ /*
+ * qbus_reset_all always reset the devices from the depth level,
+ * here only need to do the reset for the device encounter the aer,
+ * in order to avoid reset the affected device first below the bus,
+ * we only set the top level devices as needs_reset.
+ */
+ if (parent == pci_bridge_get_device(vdev->pdev.bus)) {
+ vbasedev->needs_reset = true;
+ }
+
+ /* List all affected devices by bus reset */
+ devices = &info->devices[0];
+
+ /* Verify that we have all the groups required */
+ for (i = 0; i < info->count; i++) {
+ PCIHostDeviceAddress host;
+ VFIOPCIDevice *tmp;
+ VFIODevice *vbasedev_iter;
+
+ host.domain = devices[i].segment;
+ host.bus = devices[i].bus;
+ host.slot = PCI_SLOT(devices[i].devfn);
+ host.function = PCI_FUNC(devices[i].devfn);
+
+ /* Skip the current device */
+ if (vfio_pci_host_match(&host, &vdev->host)) {
+ continue;
+ }
+
+ /* Ensure we own the group of the affected device */
+ QLIST_FOREACH(group, &vfio_group_list, next) {
+ if (group->groupid == devices[i].group_id) {
+ break;
+ }
+ }
+
+ if (!group) {
+ goto out;
+ }
+
+ /* update all affected device the bus reset status */
+ QLIST_FOREACH(vbasedev_iter, &group->device_list, next) {
+ if (vbasedev_iter->type != VFIO_DEVICE_TYPE_PCI) {
+ continue;
+ }
+ tmp = container_of(vbasedev_iter, VFIOPCIDevice, vbasedev);
+ if (vfio_pci_host_match(&host, &tmp->host)) {
+ tmp->needs_bus_reset = true;
+ tmp->vbasedev.needs_reset = false;
+ break;
+ }
+ }
+ }
+
+out:
+ g_free(info);
+}
+
static int vfio_setup_aer(VFIOPCIDevice *vdev, uint8_t cap_ver,
int pos, uint16_t size)
{
@@ -3069,6 +3146,9 @@ static int vfio_setup_aer(VFIOPCIDevice *vdev, uint8_t
cap_ver,
pdev->exp.aer_cap + PCI_ERR_UNCOR_SEVER, 4);
pci_long_test_and_clear_mask(exp_cap + PCI_ERR_UNCOR_SEVER, ~severity);
+ vdev->sec_bus_reset_notifier.notify = vfio_pci_host_needs_bus_reset;
+ pci_bus_add_reset_notifier(pdev->bus, &vdev->sec_bus_reset_notifier);
+
return 0;
error:
@@ -4053,6 +4133,9 @@ static void vfio_exitfn(PCIDevice *pdev)
vfio_unregister_req_notifier(vdev);
vfio_unregister_err_notifier(vdev);
+ if (vdev->features & VFIO_FEATURE_ENABLE_AER) {
+ pci_bus_remove_reset_notifier(&vdev->sec_bus_reset_notifier);
+ }
pci_device_set_intx_routing_notifier(&vdev->pdev, NULL);
vfio_disable_interrupts(vdev);
if (vdev->intx.mmap_timer) {
--
1.9.3
- [Qemu-devel] [v11 00/15] vfio-pci: pass the aer error to guest, Chen Fan, 2015/06/24
- [Qemu-devel] [v11 04/15] vfio: make the 4 bytes aligned for capability size, Chen Fan, 2015/06/24
- [Qemu-devel] [v11 01/15] vfio: extract vfio_get_hot_reset_info as a single function, Chen Fan, 2015/06/24
- [Qemu-devel] [v11 03/15] pcie: modify the capability size assert, Chen Fan, 2015/06/24
- [Qemu-devel] [v11 02/15] vfio: squeeze out vfio_pci_do_hot_reset for support bus reset, Chen Fan, 2015/06/24
- [Qemu-devel] [v11 05/15] vfio: add pcie extanded capability support, Chen Fan, 2015/06/24
- [Qemu-devel] [v11 06/15] aer: impove pcie_aer_init to support vfio device, Chen Fan, 2015/06/24
- [Qemu-devel] [v11 09/15] pci: add bus reset_notifiers callbacks for host bus reset, Chen Fan, 2015/06/24
- [Qemu-devel] [v11 10/15] vfio: add sec_bus_reset notifier to notify physical bus reset is needed,
Chen Fan <=
- [Qemu-devel] [v11 11/15] vfio: modify vfio_pci_hot_reset to support bus reset, Chen Fan, 2015/06/24
- [Qemu-devel] [v11 08/15] vfio: add check host bus reset is support or not, Chen Fan, 2015/06/24
- [Qemu-devel] [v11 12/15] vfio: do hot bus reset when do virtual secondary bus reset, Chen Fan, 2015/06/24
- [Qemu-devel] [v11 13/15] pcie_aer: expose pcie_aer_msg() interface, Chen Fan, 2015/06/24
- [Qemu-devel] [v11 07/15] vfio: add aer support for vfio device, Chen Fan, 2015/06/24
- [Qemu-devel] [v11 14/15] vfio-pci: pass the aer error to guest, Chen Fan, 2015/06/24
- [Qemu-devel] [v11 15/15] vfio: add 'aer' property to expose aercap, Chen Fan, 2015/06/24
- Re: [Qemu-devel] [v11 00/15] vfio-pci: pass the aer error to guest, Chen Fan, 2015/06/30