All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
To: qemu-devel@nongnu.org
Cc: izumi.taku@jp.fujitsu.com, alex.williamson@redhat.com
Subject: [Qemu-devel] [RFC v7 04/11] vfio: add check host bus reset is support or not
Date: Tue, 19 May 2015 12:42:46 +0800	[thread overview]
Message-ID: <0a0a9cca04fd00560d356133f7b89512c567e5fa.1432008287.git.chen.fan.fnst@cn.fujitsu.com> (raw)
In-Reply-To: <cover.1432008287.git.chen.fan.fnst@cn.fujitsu.com>

when machine is done, we should check the all vfio devices
whether support host bus reset, then when need virtual secondary
bus reset, we should reset host bus.

Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
---
 hw/vfio/pci.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 83 insertions(+)

diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
index 43869e9..ff639db 100644
--- a/hw/vfio/pci.c
+++ b/hw/vfio/pci.c
@@ -168,6 +168,7 @@ typedef struct VFIOPCIDevice {
     bool req_enabled;
     bool has_flr;
     bool has_pm_reset;
+    bool has_bus_reset;
     bool rom_read_failed;
 } VFIOPCIDevice;
 
@@ -3533,6 +3534,82 @@ static void vfio_pci_host_needs_bus_reset(Notifier *n, void *opaque)
     vbasedev->needs_bus_reset = true;
 }
 
+static void vfio_check_host_bus_reset(VFIODevice *vbasedev)
+{
+    VFIOPCIDevice *vdev = container_of(vbasedev, VFIOPCIDevice, vbasedev);
+    struct vfio_pci_hot_reset_info *info = NULL;
+    struct vfio_pci_dependent_device *devices;
+    VFIOGroup *group;
+    int ret, i;
+
+    ret = vfio_get_hot_reset_info(vdev, &info);
+    if (ret < 0) {
+        goto out;
+    }
+
+    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);
+
+        if (vfio_pci_host_match(&host, &vdev->host)) {
+            continue;
+        }
+
+        QLIST_FOREACH(group, &vfio_group_list, next) {
+            if (group->groupid == devices[i].group_id) {
+                break;
+            }
+        }
+
+        if (!group) {
+            goto out;
+        }
+
+        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)) {
+                if (PCI_BUS(vdev->pdev.bus) !=
+                    PCI_BUS(tmp->pdev.bus)) {
+                    goto out;
+                }
+            }
+        }
+    }
+
+    vdev->has_bus_reset = true;
+
+out:
+    g_free(info);
+}
+
+static void vfio_pci_machine_done_notify(Notifier *notifier, void *unused)
+{
+    VFIOGroup *group;
+    VFIODevice *vbasedev;
+
+    QLIST_FOREACH(group, &vfio_group_list, next) {
+         QLIST_FOREACH(vbasedev, &group->device_list, next) {
+             vfio_check_host_bus_reset(vbasedev);
+         }
+    }
+}
+
+static Notifier machine_notifier = {
+    .notify = vfio_pci_machine_done_notify,
+};
+
 static int vfio_initfn(PCIDevice *pdev)
 {
     VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev);
@@ -3821,6 +3898,12 @@ static const TypeInfo vfio_pci_dev_info = {
 static void register_vfio_pci_dev_type(void)
 {
     type_register_static(&vfio_pci_dev_info);
+
+    /*
+     * Register notifier when machine init is done, since we need
+     * check the configration manner after all vfio device are inited.
+     */
+    qemu_add_machine_init_done_notifier(&machine_notifier);
 }
 
 type_init(register_vfio_pci_dev_type)
-- 
1.9.3

  parent reply	other threads:[~2015-05-19  4:45 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-19  4:42 [Qemu-devel] [RFC v7 00/11] vfio-pci: pass the aer error to guest Chen Fan
2015-05-19  4:42 ` [Qemu-devel] [RFC v7 01/11] vfio: extract vfio_get_hot_reset_info as a single function Chen Fan
2015-05-19 19:34   ` Alex Williamson
2015-05-19  4:42 ` [Qemu-devel] [RFC v7 02/11] vfio: squeeze out vfio_pci_do_hot_reset for support bus reset Chen Fan
2015-05-19  4:42 ` [Qemu-devel] [RFC v7 03/11] qdev: add bus reset_notifiers callbacks for host " Chen Fan
2015-05-19 19:34   ` Alex Williamson
2015-05-19  4:42 ` Chen Fan [this message]
2015-05-19 19:34   ` [Qemu-devel] [RFC v7 04/11] vfio: add check host bus reset is support or not Alex Williamson
2015-05-20  7:24     ` Chen Fan
2015-05-20 18:47       ` Alex Williamson
2015-05-19  4:42 ` [Qemu-devel] [RFC v7 05/11] vfio: do hot bus reset when do virtual secondary bus reset Chen Fan
2015-05-19 19:34   ` Alex Williamson
2015-05-20  9:59     ` Chen Fan
2015-05-20 18:47       ` Alex Williamson
2015-05-19  4:42 ` [Qemu-devel] [RFC v7 06/11] vfio: add pcie extanded capability support Chen Fan
2015-05-19  4:42 ` [Qemu-devel] [RFC v7 07/11] aer: impove pcie_aer_init to support vfio device Chen Fan
2015-05-19  4:42 ` [Qemu-devel] [RFC v7 08/11] vfio: add aer support for " Chen Fan
2015-05-19  4:42 ` [Qemu-devel] [RFC v7 09/11] pcie_aer: expose pcie_aer_msg() interface Chen Fan
2015-05-19  4:42 ` [Qemu-devel] [RFC v7 10/11] vfio-pci: pass the aer error to guest Chen Fan
2015-05-19  4:42 ` [Qemu-devel] [RFC v7 11/11] vfio: add 'aer' property to expose aercap Chen Fan
2015-05-19 19:34   ` Alex Williamson
2015-05-20  3:43     ` Chen Fan
2015-05-20 18:47       ` Alex Williamson
2015-05-21  1:53         ` Chen Fan

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=0a0a9cca04fd00560d356133f7b89512c567e5fa.1432008287.git.chen.fan.fnst@cn.fujitsu.com \
    --to=chen.fan.fnst@cn.fujitsu.com \
    --cc=alex.williamson@redhat.com \
    --cc=izumi.taku@jp.fujitsu.com \
    --cc=qemu-devel@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.