[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC v10 11/19] get all affected groups for each device sup
From: |
Chen Fan |
Subject: |
[Qemu-devel] [RFC v10 11/19] get all affected groups for each device support aer |
Date: |
Tue, 16 Jun 2015 16:10:55 +0800 |
Add the affected groups without any devices into VM,
it can keep the VM ownship the all groups. and use a
reference to make the group visible.
Signed-off-by: Chen Fan <address@hidden>
---
hw/vfio/pci.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 116 insertions(+), 7 deletions(-)
diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index e1bbd03..ade3196 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -2822,6 +2822,113 @@ static int vfio_add_std_cap(VFIOPCIDevice *vdev,
uint8_t pos)
return 0;
}
+static bool vfio_pci_host_match(PCIHostDeviceAddress *host1,
+ PCIHostDeviceAddress *host2)
+{
+ return (host1->domain == host2->domain && host1->bus == host2->bus &&
+ host1->slot == host2->slot && host1->function == host2->function);
+}
+
+static int vfio_get_affected_groups(VFIOPCIDevice *vdev)
+{
+ struct vfio_pci_hot_reset_info *info = NULL;
+ struct vfio_pci_dependent_device *devices;
+ PCIHostDeviceAddress host;
+ VFIOGroup *group;
+ int ret, i;
+ struct vfio_group_head vfio_groups =
+ QLIST_HEAD_INITIALIZER(vfio_groups);
+
+ ret = vfio_get_hot_reset_info(vdev, &info);
+ if (ret) {
+ goto out;
+ }
+
+ /* 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++) {
+ 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;
+ }
+
+ /* Get all affected groups into VM */
+ group = vfio_get_group(devices[i].group_id, NULL);
+ if (!group) {
+ error_report("vfio: failed to get affected group %d",
+ devices[i].group_id);
+ ret = -1;
+ goto out;
+ }
+
+ QLIST_INSERT_HEAD(&vfio_groups, group, next);
+ }
+ ret = 0;
+out:
+ if (ret && !QLIST_EMPTY(&vfio_groups)) {
+ QLIST_FOREACH(group, &vfio_groups, next) {
+ vfio_put_group(group);
+ }
+ vdev->features &= ~VFIO_FEATURE_ENABLE_AER;
+ }
+ g_free(info);
+ return ret;
+}
+
+static int vfio_put_affected_groups(VFIOPCIDevice *vdev)
+{
+ struct vfio_pci_hot_reset_info *info = NULL;
+ struct vfio_pci_dependent_device *devices;
+ PCIHostDeviceAddress host;
+ VFIOGroup *group;
+ int ret, i;
+
+ ret = vfio_get_hot_reset_info(vdev, &info);
+ if (ret) {
+ goto out;
+ }
+
+ /* 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++) {
+ 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)
+ continue;
+
+ vfio_put_group(group);
+ }
+
+ ret = 0;
+out:
+ g_free(info);
+ return ret;
+}
+
static int vfio_setup_aer(VFIOPCIDevice *vdev, uint8_t cap_ver,
int pos, uint16_t size)
{
@@ -2858,6 +2965,12 @@ static int vfio_setup_aer(VFIOPCIDevice *vdev, uint8_t
cap_ver,
dev_iter = pci_bridge_get_device(dev_iter->bus);
}
+ /* Ensure own all affected groups */
+ ret = vfio_get_affected_groups(vdev);
+ if (ret) {
+ return ret;
+ }
+
errcap = vfio_pci_read_config(pdev, pdev->exp.aer_cap + PCI_ERR_CAP, 4);
/*
* The ability to record multiple headers is depending on
@@ -3013,13 +3126,6 @@ static void vfio_pci_post_reset(VFIOPCIDevice *vdev)
vfio_enable_intx(vdev);
}
-static bool vfio_pci_host_match(PCIHostDeviceAddress *host1,
- PCIHostDeviceAddress *host2)
-{
- return (host1->domain == host2->domain && host1->bus == host2->bus &&
- host1->slot == host2->slot && host1->function == host2->function);
-}
-
static int vfio_pci_hot_reset(VFIOPCIDevice *vdev, bool single)
{
VFIOGroup *group;
@@ -3851,6 +3957,9 @@ static void vfio_instance_finalize(Object *obj)
g_free(vdev->rom);
vfio_put_device(vdev);
vfio_put_group(group);
+ if (vdev->features & VFIO_FEATURE_ENABLE_AER) {
+ vfio_put_affected_groups(vdev);
+ }
}
static void vfio_exitfn(PCIDevice *pdev)
--
1.9.3
- [Qemu-devel] [RFC v10 03/19] pcie: modify the capability size assert, (continued)
- [Qemu-devel] [RFC v10 03/19] pcie: modify the capability size assert, Chen Fan, 2015/06/16
- [Qemu-devel] [RFC v10 02/19] vfio: squeeze out vfio_pci_do_hot_reset for support bus reset, Chen Fan, 2015/06/16
- [Qemu-devel] [RFC v10 04/19] vfio: make the 4 bytes aligned for capability size, Chen Fan, 2015/06/16
- [Qemu-devel] [RFC v10 06/19] aer: impove pcie_aer_init to support vfio device, Chen Fan, 2015/06/16
- [Qemu-devel] [RFC v10 08/19] vfio: add ref for group to support own affected groups, Chen Fan, 2015/06/16
- [Qemu-devel] [RFC v10 05/19] vfio: add pcie extanded capability support, Chen Fan, 2015/06/16
- [Qemu-devel] [RFC v10 10/19] vfio: improve vfio_get_group to support adding as is NULL., Chen Fan, 2015/06/16
- [Qemu-devel] [RFC v10 07/19] vfio: add aer support for vfio device, Chen Fan, 2015/06/16
- [Qemu-devel] [RFC v10 09/19] vfio: extract vfio_register_container_listener from vfio_connect_container, Chen Fan, 2015/06/16
- [Qemu-devel] [RFC v10 11/19] get all affected groups for each device support aer,
Chen Fan <=
- [Qemu-devel] [RFC v10 12/19] vfio: add check host bus reset is support or not, Chen Fan, 2015/06/16
- [Qemu-devel] [RFC v10 14/19] vfio: add sec_bus_reset notifier to notify physical bus reset is needed, Chen Fan, 2015/06/16
- [Qemu-devel] [RFC v10 15/19] vfio: improve vfio_pci_hot_reset to support more case, Chen Fan, 2015/06/16
- [Qemu-devel] [RFC v10 16/19] vfio: do hot bus reset when do virtual secondary bus reset, Chen Fan, 2015/06/16
- [Qemu-devel] [RFC v10 17/19] pcie_aer: expose pcie_aer_msg() interface, Chen Fan, 2015/06/16
- [Qemu-devel] [RFC v10 18/19] vfio-pci: pass the aer error to guest, Chen Fan, 2015/06/16
- [Qemu-devel] [RFC v10 13/19] pci: add bus reset_notifiers callbacks for host bus reset, Chen Fan, 2015/06/16