All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Cao jin <caoj.fnst@cn.fujitsu.com>
Cc: chen.fan.fnst@cn.fujitsu.com, izumi.taku@jp.fujitsu.com,
	alex.williamson@redhat.com, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 06/11] pci: add a is_valid_func callback to check device if complete
Date: Wed, 9 Mar 2016 18:22:24 +0200	[thread overview]
Message-ID: <20160309162224.GA5279@redhat.com> (raw)
In-Reply-To: <1457320984-6540-7-git-send-email-caoj.fnst@cn.fujitsu.com>

On Mon, Mar 07, 2016 at 11:22:59AM +0800, Cao jin wrote:
> From: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
> 
> Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>

So if you create a mess, you discover it when
you later add function 0.
Why not call this when function is added?
O(N^2) on # of functions, but that # is up to 256 so maybe
that is not too bad.

> ---
>  hw/pci/pci.c         | 39 +++++++++++++++++++++++++++++++++++++++
>  include/hw/pci/pci.h |  1 +
>  2 files changed, 40 insertions(+)
> 
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index d940f79..72650c5 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -1836,6 +1836,31 @@ PCIDevice *pci_find_device(PCIBus *bus, int bus_num, uint8_t devfn)
>      return bus->devices[devfn];
>  }
>  
> +static void pci_bus_check_device(PCIDevice *pdev, Error **errp)
> +{
> +    PCIBus *bus = pdev->bus;
> +    PCIDeviceClass *pc;
> +    int i;
> +    Error *local_err = NULL;
> +
> +    for (i = 0; i < ARRAY_SIZE(bus->devices); ++i) {
> +        if (!bus->devices[i]) {
> +            continue;
> +        }
> +
> +        pc = PCI_DEVICE_GET_CLASS(bus->devices[i]);
> +        if (!pc->is_valid_func) {
> +            continue;
> +        }
> +
> +        pc->is_valid_func(bus->devices[i], &local_err);
> +        if (local_err) {
> +            error_propagate(errp, local_err);
> +            return;
> +        }
> +    }
> +}
> +
>  static void pci_qdev_realize(DeviceState *qdev, Error **errp)
>  {
>      PCIDevice *pci_dev = (PCIDevice *)qdev;
> @@ -1878,6 +1903,20 @@ static void pci_qdev_realize(DeviceState *qdev, Error **errp)
>          pci_qdev_unrealize(DEVICE(pci_dev), NULL);
>          return;
>      }
> +
> +    /*
> +     *  If the function is func 0, indicate the closure of the slot.
> +     *  then we get the chance to check all functions on same device
> +     *  if valid.
> +     */
> +    if (pci_get_function_0(pci_dev) == pci_dev) {
> +        pci_bus_check_device(pci_dev, &local_err);
> +        if (local_err) {
> +            error_propagate(errp, local_err);
> +            pci_qdev_unrealize(DEVICE(pci_dev), NULL);
> +            return;
> +        }
> +    }
>  }
>  
>  static void pci_default_realize(PCIDevice *dev, Error **errp)
> diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
> index dedf277..4e56256 100644
> --- a/include/hw/pci/pci.h
> +++ b/include/hw/pci/pci.h
> @@ -191,6 +191,7 @@ typedef struct PCIDeviceClass {
>  
>      void (*realize)(PCIDevice *dev, Error **errp);
>      int (*init)(PCIDevice *dev);/* TODO convert to realize() and remove */
> +    void (*is_valid_func)(PCIDevice *dev, Error **errp);
>      PCIUnregisterFunc *exit;
>      PCIConfigReadFunc *config_read;
>      PCIConfigWriteFunc *config_write;
> -- 
> 1.9.3
> 
> 

  reply	other threads:[~2016-03-09 16:22 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-07  3:22 [Qemu-devel] [PATCH v2 Resend 00/11] vfio-pci: pass the aer error to guest, part2 Cao jin
2016-03-07  3:22 ` [Qemu-devel] [PATCH v2 01/11] vfio: extract vfio_get_hot_reset_info as a single function Cao jin
2016-03-07  3:22 ` [Qemu-devel] [PATCH v2 02/11] vfio: squeeze out vfio_pci_do_hot_reset for support bus reset Cao jin
2016-03-07  3:22 ` [Qemu-devel] [PATCH v2 03/11] vfio: add pcie extended capability support Cao jin
2016-03-07  3:22 ` [Qemu-devel] [PATCH v2 04/11] vfio: add aer support for vfio device Cao jin
2016-03-08 22:55   ` Alex Williamson
2016-03-09  1:21     ` Chen Fan
2016-03-07  3:22 ` [Qemu-devel] [PATCH v2 05/11] vfio: add check host bus reset is support or not Cao jin
2016-03-08 22:55   ` Alex Williamson
2016-03-09  1:26     ` Chen Fan
2016-03-09 16:47   ` Michael S. Tsirkin
2016-03-09 16:59     ` Alex Williamson
2016-03-09 17:21       ` Michael S. Tsirkin
2016-03-07  3:22 ` [Qemu-devel] [PATCH v2 06/11] pci: add a is_valid_func callback to check device if complete Cao jin
2016-03-09 16:22   ` Michael S. Tsirkin [this message]
2016-03-09 16:50     ` Alex Williamson
2016-03-09 17:14       ` Michael S. Tsirkin
2016-03-10  2:00         ` Chen Fan
2016-03-07  3:23 ` [Qemu-devel] [PATCH v2 07/11] vfio: add check aer functionality for hotplug device Cao jin
2016-03-07  3:23 ` [Qemu-devel] [PATCH v2 08/11] pci: introduce pci bus pre reset Cao jin
2016-03-07  3:23 ` [Qemu-devel] [PATCH v2 09/11] vfio: vote a device to do host bus reset Cao jin
2016-03-09 10:07   ` Michael S. Tsirkin
2016-03-09 16:37   ` Alex Williamson
2016-03-10  6:15     ` Chen Fan
2016-03-10 14:16       ` Michael S. Tsirkin
2016-03-09 16:39   ` Michael S. Tsirkin
2016-03-09 17:09     ` Alex Williamson
2016-03-09 17:31       ` Michael S. Tsirkin
2016-03-07  3:23 ` [Qemu-devel] [PATCH v2 10/11] vfio-pci: pass the aer error to guest Cao jin
2016-03-07  3:23 ` [Qemu-devel] [PATCH v2 11/11] vfio: add 'aer' property to expose aercap Cao jin
  -- strict thread matches above, loose matches on Subject: below --
2016-02-19 10:42 [Qemu-devel] [PATCH v2 00/11] vfio-pci: pass the aer error to guest, part2 Cao jin
2016-02-19 10:42 ` [Qemu-devel] [PATCH v2 06/11] pci: add a is_valid_func callback to check device if complete Cao jin

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=20160309162224.GA5279@redhat.com \
    --to=mst@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=caoj.fnst@cn.fujitsu.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 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.