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 07/10] pci: introduce pci bus pre reset
Date: Wed, 17 Feb 2016 17:52:04 +0200	[thread overview]
Message-ID: <20160217155204.GA2299@redhat.com> (raw)
In-Reply-To: <1455705833-17682-8-git-send-email-caoj.fnst@cn.fujitsu.com>

On Wed, Feb 17, 2016 at 06:43:51PM +0800, Cao jin wrote:
> From: Chen Fan <chen.fan.fnst@cn.fujitsu.com>
> 
> avoid repeat bus reset, here introduce a sequence ID for each time
> bus hot reset, so each vfio device could know whether they've already
> been reset for that sequence ID.
> 
> Signed-off-by: Chen Fan <chen.fan.fnst@cn.fujitsu.com>

If the assumption that vfio functions are combined
in the same way as on the host, then this is not needed:
just reset when function 0 is reset.

I suggest we do it this way at stage one.
Add more checks when the functionality is in place.

> ---
>  hw/core/qdev.c           |  4 ++--
>  hw/pci/pci.c             | 25 +++++++++++++++++++++++++
>  hw/pci/pci_bridge.c      |  5 ++++-
>  include/hw/pci/pci_bus.h |  4 ++++
>  include/hw/qdev-core.h   |  3 +++
>  5 files changed, 38 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/core/qdev.c b/hw/core/qdev.c
> index 779de2b..e36fa07 100644
> --- a/hw/core/qdev.c
> +++ b/hw/core/qdev.c
> @@ -304,14 +304,14 @@ void qdev_unplug(DeviceState *dev, Error **errp)
>      }
>  }
>  
> -static int qdev_reset_one(DeviceState *dev, void *opaque)
> +int qdev_reset_one(DeviceState *dev, void *opaque)
>  {
>      device_reset(dev);
>  
>      return 0;
>  }
>  
> -static int qbus_reset_one(BusState *bus, void *opaque)
> +int qbus_reset_one(BusState *bus, void *opaque)
>  {
>      BusClass *bc = BUS_GET_CLASS(bus);
>      if (bc->reset) {
> diff --git a/hw/pci/pci.c b/hw/pci/pci.c
> index e41925e..ff978bc 100644
> --- a/hw/pci/pci.c
> +++ b/hw/pci/pci.c
> @@ -258,6 +258,29 @@ void pci_device_reset(PCIDevice *dev)
>      pci_do_device_reset(dev);
>  }
>  
> +int pcibus_pre_reset(BusState *qbus, void *opaque)
> +{
> +    BusState *bus = (BusState *)opaque;
> +    PCIBus *pci_bus = DO_UPCAST(PCIBus, qbus, qbus);
> +    static unsigned int reset_seqid;
> +
> +    /*
> +     * To distinguish the different reset times, we
> +     * recalculate the global reset seqid with a given bus.
> +     */
> +    if (qbus == bus) {
> +        reset_seqid++;
> +        if (!reset_seqid) {
> +            reset_seqid = 1;
> +	}
> +    }
> +
> +    pci_bus->bus_in_reset = true;
> +    pci_bus->reset_seqid = reset_seqid;
> +
> +    return 0;
> +}
> +
>  /*
>   * Trigger pci bus reset under a given bus.
>   * Called via qbus_reset_all on RST# assert, after the devices
> @@ -277,6 +300,8 @@ static void pcibus_reset(BusState *qbus)
>      for (i = 0; i < bus->nirq; i++) {
>          assert(bus->irq_count[i] == 0);
>      }
> +
> +    bus->bus_in_reset = false;
>  }
>  
>  static void pci_host_bus_register(PCIBus *bus, DeviceState *parent)
> diff --git a/hw/pci/pci_bridge.c b/hw/pci/pci_bridge.c
> index 7eab9d5..6c35171 100644
> --- a/hw/pci/pci_bridge.c
> +++ b/hw/pci/pci_bridge.c
> @@ -269,7 +269,10 @@ void pci_bridge_write_config(PCIDevice *d,
>      newctl = pci_get_word(d->config + PCI_BRIDGE_CONTROL);
>      if (~oldctl & newctl & PCI_BRIDGE_CTL_BUS_RESET) {
>          /* Trigger hot reset on 0->1 transition. */
> -        qbus_reset_all(&s->sec_bus.qbus);
> +        qbus_walk_children(&s->sec_bus.qbus, NULL,
> +                           pcibus_pre_reset,
> +                           qdev_reset_one,
> +                           qbus_reset_one, &s->sec_bus.qbus);
>      }
>  }
>  
> diff --git a/include/hw/pci/pci_bus.h b/include/hw/pci/pci_bus.h
> index 7812fa9..9dd2d6c 100644
> --- a/include/hw/pci/pci_bus.h
> +++ b/include/hw/pci/pci_bus.h
> @@ -40,11 +40,15 @@ struct PCIBus {
>      int nirq;
>      int *irq_count;
>  
> +    bool bus_in_reset;
> +    uint32_t reset_seqid;
> +
>      NotifierWithReturnList hotplug_notifiers;
>  };
>  
>  void pci_bus_add_hotplug_notifier(PCIBus *bus, NotifierWithReturn *notify);
>  void pci_bus_remove_hotplug_notifier(NotifierWithReturn *notify);
> +int pcibus_pre_reset(BusState *qbus, void *opaque);
>  
>  typedef struct PCIBridgeWindows PCIBridgeWindows;
>  
> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
> index abcdee8..3d71c17 100644
> --- a/include/hw/qdev-core.h
> +++ b/include/hw/qdev-core.h
> @@ -401,4 +401,7 @@ static inline bool qbus_is_hotpluggable(BusState *bus)
>  void device_listener_register(DeviceListener *listener);
>  void device_listener_unregister(DeviceListener *listener);
>  
> +int qdev_reset_one(DeviceState *dev, void *opaque);
> +int qbus_reset_one(BusState *bus, void *opaque);
> +
>  #endif
> -- 
> 1.9.3
> 
> 

  reply	other threads:[~2016-02-17 15:52 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-17 10:43 [Qemu-devel] [PATCH 00/10] vfio-pci: pass the aer error to guest, part2 Cao jin
2016-02-17 10:43 ` [Qemu-devel] [PATCH 01/10] vfio: extract vfio_get_hot_reset_info as a single function Cao jin
2016-02-17 10:43 ` [Qemu-devel] [PATCH 02/10] vfio: squeeze out vfio_pci_do_hot_reset for support bus reset Cao jin
2016-02-17 10:43 ` [Qemu-devel] [PATCH 03/10] vfio: add pcie extended capability support Cao jin
2016-02-17 10:43 ` [Qemu-devel] [PATCH 04/10] vfio: add aer support for vfio device Cao jin
2016-02-17 10:43 ` [Qemu-devel] [PATCH 05/10] vfio: add check host bus reset is support or not Cao jin
2016-02-17 10:43 ` [Qemu-devel] [PATCH 06/10] add check reset mechanism when hotplug vfio device Cao jin
2016-02-17 15:55   ` Michael S. Tsirkin
2016-02-17 10:43 ` [Qemu-devel] [PATCH 07/10] pci: introduce pci bus pre reset Cao jin
2016-02-17 15:52   ` Michael S. Tsirkin [this message]
2016-02-17 10:43 ` [Qemu-devel] [PATCH 08/10] vfio: introduce last reset sequence id Cao jin
2016-02-17 15:56   ` Michael S. Tsirkin
2016-02-17 10:43 ` [Qemu-devel] [PATCH 09/10] vfio-pci: pass the aer error to guest 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=20160217155204.GA2299@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.