From: Alex Williamson <alex.williamson@redhat.com>
To: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
Cc: izumi.taku@jp.fujitsu.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [RFC v9 10/18] get all affected groups for each device support aer
Date: Tue, 09 Jun 2015 15:22:55 -0600 [thread overview]
Message-ID: <1433884975.4927.142.camel@redhat.com> (raw)
In-Reply-To: <e0cde7893e69a0e0ab21ec1a3cf99d4487ee685b.1433812962.git.chen.fan.fnst@cn.fujitsu.com>
On Tue, 2015-06-09 at 11:37 +0800, Chen Fan wrote:
> 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 <chen.fan.fnst@cn.fujitsu.com>
> ---
> hw/vfio/pci.c | 115 ++++++++++++++++++++++++++++++++++++++++++++++++++++++----
> 1 file changed, 108 insertions(+), 7 deletions(-)
>
> diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c
> index 7a3fad7..06006ce 100644
> --- a/hw/vfio/pci.c
> +++ b/hw/vfio/pci.c
> @@ -2822,6 +2822,105 @@ 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_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;
> +
> + group->ref--;
> + vfio_put_group(group);
> + }
> +
> + ret = 0;
> +out:
> + g_free(info);
> + return ret;
> +}
> +
> +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;
> +
> + 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;
There needs to be an unwind here, if the error occurs during hotplug,
we've just left QEMU in a state where some groups have extra references.
> + }
> + group->ref++;
If we're going to have a group reference, get_group should increment it
and put_group should decrement it, we shouldn't modify it externally
from those functions.
> + }
> + 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 +2957,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) {
> + goto error;
> + }
> +
> 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 +3118,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 +3949,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)
next prev parent reply other threads:[~2015-06-09 21:23 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-06-09 3:37 [Qemu-devel] [RFC v9 00/18] vfio-pci: pass the aer error to guest Chen Fan
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 01/18] vfio: extract vfio_get_hot_reset_info as a single function Chen Fan
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 02/18] vfio: squeeze out vfio_pci_do_hot_reset for support bus reset Chen Fan
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 03/18] pcie: modify the capability size assert Chen Fan
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 04/18] vfio: make the 4 bytes aligned for capability size Chen Fan
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 05/18] vfio: add pcie extanded capability support Chen Fan
2015-06-09 21:22 ` Alex Williamson
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 06/18] aer: impove pcie_aer_init to support vfio device Chen Fan
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 07/18] vfio: add aer support for " Chen Fan
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 08/18] vfio: improve vfio_get_group to support adding group without devices Chen Fan
2015-06-09 21:23 ` Alex Williamson
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 09/18] vfio: add ref for group to support own affected groups Chen Fan
2015-06-09 21:23 ` Alex Williamson
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 10/18] get all affected groups for each device support aer Chen Fan
2015-06-09 21:22 ` Alex Williamson [this message]
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 11/18] vfio: add check host bus reset is support or not Chen Fan
2015-06-09 21:23 ` Alex Williamson
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 12/18] pci: add bus reset_notifiers callbacks for host bus reset Chen Fan
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 13/18] vfio: add sec_bus_reset notifier to notify physical bus reset is needed Chen Fan
2015-06-09 21:23 ` Alex Williamson
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 14/18] vfio: improve vfio_pci_hot_reset to support more case Chen Fan
2015-06-09 21:24 ` Alex Williamson
2015-06-16 8:10 ` Chen Fan
2015-06-16 14:08 ` Alex Williamson
2015-06-17 6:28 ` Chen Fan
2015-06-17 15:23 ` Alex Williamson
2015-06-18 10:27 ` Chen Fan
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 15/18] vfio: do hot bus reset when do virtual secondary bus reset Chen Fan
2015-06-09 21:23 ` Alex Williamson
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 16/18] pcie_aer: expose pcie_aer_msg() interface Chen Fan
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 17/18] vfio-pci: pass the aer error to guest Chen Fan
2015-06-09 3:37 ` [Qemu-devel] [RFC v9 18/18] vfio: add 'aer' property to expose aercap 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=1433884975.4927.142.camel@redhat.com \
--to=alex.williamson@redhat.com \
--cc=chen.fan.fnst@cn.fujitsu.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 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).