qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Alexey Kardashevskiy <aik@ozlabs.ru>
Cc: qemu-devel@nongnu.org, qemu-ppc@nongnu.org,
	Alexander Graf <agraf@suse.de>,
	David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [Qemu-devel] [PATCH qemu v17 12/12] spapr_iommu, vfio, memory: Notify IOMMU about starting/stopping listening
Date: Fri, 3 Jun 2016 10:59:15 -0600	[thread overview]
Message-ID: <20160603105915.08b4d2b1@t450s.home> (raw)
In-Reply-To: <201606011013.u51A9ALx023064@mx0a-001b2d01.pphosted.com>

On Wed,  1 Jun 2016 18:57:43 +1000
Alexey Kardashevskiy <aik@ozlabs.ru> wrote:

> The sPAPR TCE tables manage 2 copies when VFIO is using an IOMMU -
> a guest view of the table and a hardware TCE table. If there is no VFIO
> presense in the address space, then just the guest view is used, if
> this is the case, it is allocated in the KVM. However since there is no
> support yet for VFIO in KVM TCE hypercalls, when we start using VFIO,
> we need to move the guest view from KVM to the userspace; and we need
> to do this for every IOMMU on a bus with VFIO devices.
> 
> This adds notify_started/notify_stopped callbacks in MemoryRegionIOMMUOps
> to notify IOMMU that listeners were set/removed. This allows IOMMU to
> take necessary steps before actual notifications happen and do proper
> cleanup when the last notifier is removed.
> 
> This implements the callbacks for the sPAPR IOMMU - notify_started()
> reallocated the guest view to the user space, notify_stopped() does
> the opposite.
> 
> This removes explicit spapr_tce_set_need_vfio() call from PCI hotplug
> path as the new callbacks do this better - they notify IOMMU at
> the exact moment when the configuration is changed, and this also
> includes the case of PCI hot unplug.
> 
> This adds MemoryRegion* to memory_region_unregister_iommu_notifier()
> as we need iommu_ops to call notify_stopped() and Notifier* does not
> store the owner.
> 
> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
> Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
> ---
> Changes:
> v17:
> * replaced IOMMU users counting with simple QLIST_EMPTY()
> * renamed the callbacks
> * removed requirement for region_del() to be called on memory_listener_unregister()
> 
> v16:
> * added a use counter in VFIOAddressSpace->VFIOIOMMUMR
> 
> v15:
> * s/need_vfio/vfio-Users/g
> ---

This should be two separate patches, patch #2:

>  hw/ppc/spapr_iommu.c  | 12 ++++++++++++
>  hw/ppc/spapr_pci.c    |  6 ------

patch #1:

>  hw/vfio/common.c      |  5 +++--
>  include/exec/memory.h |  8 +++++++-
>  memory.c              | 10 +++++++++-
>  5 files changed, 31 insertions(+), 10 deletions(-)

Otherwise

Acked-by: Alex Williamson <alex.williamson@redhat.com>

> 
> diff --git a/hw/ppc/spapr_iommu.c b/hw/ppc/spapr_iommu.c
> index 90a45c0..994a8a0 100644
> --- a/hw/ppc/spapr_iommu.c
> +++ b/hw/ppc/spapr_iommu.c
> @@ -156,6 +156,16 @@ static uint64_t spapr_tce_get_page_sizes(MemoryRegion *iommu)
>      return 1ULL << tcet->page_shift;
>  }
>  
> +static void spapr_tce_notify_started(MemoryRegion *iommu)
> +{
> +    spapr_tce_set_need_vfio(container_of(iommu, sPAPRTCETable, iommu), true);
> +}
> +
> +static void spapr_tce_notify_stopped(MemoryRegion *iommu)
> +{
> +    spapr_tce_set_need_vfio(container_of(iommu, sPAPRTCETable, iommu), false);
> +}
> +
>  static int spapr_tce_table_post_load(void *opaque, int version_id)
>  {
>      sPAPRTCETable *tcet = SPAPR_TCE_TABLE(opaque);
> @@ -236,6 +246,8 @@ static const VMStateDescription vmstate_spapr_tce_table = {
>  static MemoryRegionIOMMUOps spapr_iommu_ops = {
>      .translate = spapr_tce_translate_iommu,
>      .get_page_sizes = spapr_tce_get_page_sizes,
> +    .notify_started = spapr_tce_notify_started,
> +    .notify_stopped = spapr_tce_notify_stopped,
>  };
>  
>  static int spapr_tce_table_realize(DeviceState *dev)
> diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c
> index bcf0360..06ce902 100644
> --- a/hw/ppc/spapr_pci.c
> +++ b/hw/ppc/spapr_pci.c
> @@ -1089,12 +1089,6 @@ static void spapr_phb_add_pci_device(sPAPRDRConnector *drc,
>      void *fdt = NULL;
>      int fdt_start_offset = 0, fdt_size;
>  
> -    if (object_dynamic_cast(OBJECT(pdev), "vfio-pci")) {
> -        sPAPRTCETable *tcet = spapr_tce_find_by_liobn(phb->dma_liobn[0]);
> -
> -        spapr_tce_set_need_vfio(tcet, true);
> -    }
> -
>      fdt = create_device_tree(&fdt_size);
>      fdt_start_offset = spapr_create_pci_child_dt(phb, pdev, fdt, 0);
>      if (!fdt_start_offset) {
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 7f55c26..356640e 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -522,7 +522,8 @@ static void vfio_listener_region_del(MemoryListener *listener,
>  
>          QLIST_FOREACH(giommu, &container->giommu_list, giommu_next) {
>              if (giommu->iommu == section->mr) {
> -                memory_region_unregister_iommu_notifier(&giommu->n);
> +                memory_region_unregister_iommu_notifier(giommu->iommu,
> +                                                        &giommu->n);
>                  QLIST_REMOVE(giommu, giommu_next);
>                  g_free(giommu);
>                  break;
> @@ -1094,7 +1095,7 @@ static void vfio_disconnect_container(VFIOGroup *group)
>          QLIST_REMOVE(container, next);
>  
>          QLIST_FOREACH_SAFE(giommu, &container->giommu_list, giommu_next, tmp) {
> -            memory_region_unregister_iommu_notifier(&giommu->n);
> +            memory_region_unregister_iommu_notifier(giommu->iommu, &giommu->n);
>              QLIST_REMOVE(giommu, giommu_next);
>              g_free(giommu);
>          }
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index bd9625f..f08439b 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -151,6 +151,10 @@ struct MemoryRegionIOMMUOps {
>      IOMMUTLBEntry (*translate)(MemoryRegion *iommu, hwaddr addr, bool is_write);
>      /* Returns supported page sizes */
>      uint64_t (*get_page_sizes)(MemoryRegion *iommu);
> +    /* Called when the first notifier is set */
> +    void (*notify_started)(MemoryRegion *iommu);
> +    /* Called when the last notifier is removed */
> +    void (*notify_stopped)(MemoryRegion *iommu);
>  };
>  
>  typedef struct CoalescedMemoryRange CoalescedMemoryRange;
> @@ -619,9 +623,11 @@ void memory_region_iommu_replay(MemoryRegion *mr, Notifier *n, bool is_write);
>   * memory_region_unregister_iommu_notifier: unregister a notifier for
>   * changes to IOMMU translation entries.
>   *
> + * @mr: the memory region which was observed and for which notity_stopped()
> + *      needs to be called
>   * @n: the notifier to be removed.
>   */
> -void memory_region_unregister_iommu_notifier(Notifier *n);
> +void memory_region_unregister_iommu_notifier(MemoryRegion *mr, Notifier *n);
>  
>  /**
>   * memory_region_name: get a memory region's name
> diff --git a/memory.c b/memory.c
> index 761ae92..ee41649 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -1497,6 +1497,10 @@ bool memory_region_is_logging(MemoryRegion *mr, uint8_t client)
>  
>  void memory_region_register_iommu_notifier(MemoryRegion *mr, Notifier *n)
>  {
> +    if (mr->iommu_ops->notify_started &&
> +        QLIST_EMPTY(&mr->iommu_notify.notifiers)) {
> +        mr->iommu_ops->notify_started(mr);
> +    }
>      notifier_list_add(&mr->iommu_notify, n);
>  }
>  
> @@ -1530,9 +1534,13 @@ void memory_region_iommu_replay(MemoryRegion *mr, Notifier *n, bool is_write)
>      }
>  }
>  
> -void memory_region_unregister_iommu_notifier(Notifier *n)
> +void memory_region_unregister_iommu_notifier(MemoryRegion *mr, Notifier *n)
>  {
>      notifier_remove(n);
> +    if (mr->iommu_ops->notify_stopped &&
> +        QLIST_EMPTY(&mr->iommu_notify.notifiers)) {
> +        mr->iommu_ops->notify_stopped(mr);
> +    }
>  }
>  
>  void memory_region_notify_iommu(MemoryRegion *mr,

  parent reply	other threads:[~2016-06-03 16:59 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1464771463-37214-1-git-send-email-aik@ozlabs.ru>
2016-06-01  8:57 ` [Qemu-devel] [PATCH qemu v17 01/12] vmstate: Define VARRAY with VMS_ALLOC Alexey Kardashevskiy
2016-06-01  8:57 ` [Qemu-devel] [PATCH qemu v17 02/12] spapr_iommu: Introduce "enabled" state for TCE table Alexey Kardashevskiy
2016-06-01  8:57 ` [Qemu-devel] [PATCH qemu v17 03/12] spapr_iommu: Migrate full state Alexey Kardashevskiy
2016-06-01  8:57 ` [Qemu-devel] [PATCH qemu v17 04/12] spapr_iommu: Add root memory region Alexey Kardashevskiy
2016-06-01  8:57 ` [Qemu-devel] [PATCH qemu v17 05/12] spapr_pci: Reset DMA config on PHB reset Alexey Kardashevskiy
2016-06-01  8:57 ` [Qemu-devel] [PATCH qemu v17 06/12] memory: Add reporting of supported page sizes Alexey Kardashevskiy
2016-06-01  8:57 ` [Qemu-devel] [PATCH qemu v17 07/12] vfio: spapr: Add DMA memory preregistering (SPAPR IOMMU v2) Alexey Kardashevskiy
2016-06-01  8:57 ` [Qemu-devel] [PATCH qemu v17 08/12] spapr_pci: Add and export DMA resetting helper Alexey Kardashevskiy
2016-06-01  8:57 ` [Qemu-devel] [PATCH qemu v17 09/12] vfio: Add host side DMA window capabilities Alexey Kardashevskiy
2016-06-01  8:57 ` [Qemu-devel] [PATCH qemu v17 10/12] vfio/spapr: Create DMA window dynamically (SPAPR IOMMU v2) Alexey Kardashevskiy
2016-06-01  8:57 ` [Qemu-devel] [PATCH qemu v17 11/12] spapr_pci/spapr_pci_vfio: Support Dynamic DMA Windows (DDW) Alexey Kardashevskiy
2016-06-01  8:57 ` [Qemu-devel] [PATCH qemu v17 12/12] spapr_iommu, vfio, memory: Notify IOMMU about starting/stopping listening Alexey Kardashevskiy
     [not found] ` <201606010902.u518wwmb029353@mx0a-001b2d01.pphosted.com>
2016-06-02  3:35   ` [Qemu-devel] [PATCH qemu v17 06/12] memory: Add reporting of supported page sizes David Gibson
2016-06-06 13:31     ` Paolo Bonzini
2016-06-07  3:42       ` Alexey Kardashevskiy
2016-06-08  6:00       ` David Gibson
2016-06-08  6:05         ` Alexey Kardashevskiy
2016-06-14 21:41           ` Alexey Kardashevskiy
2016-06-15  6:15           ` David Gibson
     [not found] ` <201606010900.u518wvH7046287@mx0a-001b2d01.pphosted.com>
2016-06-02  4:18   ` [Qemu-devel] [PATCH qemu v17 07/12] vfio: spapr: Add DMA memory preregistering (SPAPR IOMMU v2) David Gibson
     [not found] ` <201606010902.u518x15j023604@mx0a-001b2d01.pphosted.com>
2016-06-02  4:19   ` [Qemu-devel] [PATCH qemu v17 08/12] spapr_pci: Add and export DMA resetting helper David Gibson
     [not found] ` <201606010901.u518wwEL029369@mx0a-001b2d01.pphosted.com>
2016-06-03  7:23   ` [Qemu-devel] [PATCH qemu v17 09/12] vfio: Add host side DMA window capabilities David Gibson
     [not found] ` <201606011012.u51A9A6i023070@mx0a-001b2d01.pphosted.com>
2016-06-03  7:37   ` [Qemu-devel] [PATCH qemu v17 10/12] vfio/spapr: Create DMA window dynamically (SPAPR IOMMU v2) David Gibson
2016-06-06  6:45     ` Alexey Kardashevskiy
2016-06-08  5:56       ` David Gibson
     [not found] ` <201606010902.u51902Zl007699@mx0a-001b2d01.pphosted.com>
2016-06-03 15:37   ` [Qemu-devel] [PATCH qemu v17 06/12] memory: Add reporting of supported page sizes Alex Williamson
     [not found] ` <201606010900.u51900Om007391@mx0a-001b2d01.pphosted.com>
2016-06-03 16:13   ` [Qemu-devel] [PATCH qemu v17 07/12] vfio: spapr: Add DMA memory preregistering (SPAPR IOMMU v2) Alex Williamson
2016-06-06  6:04     ` Alexey Kardashevskiy
2016-06-06 17:20       ` Alex Williamson
2016-06-07  3:10         ` Alexey Kardashevskiy
     [not found] ` <201606010901.u518x843001647@mx0a-001b2d01.pphosted.com>
2016-06-03 16:32   ` [Qemu-devel] [PATCH qemu v17 09/12] vfio: Add host side DMA window capabilities Alex Williamson
     [not found] ` <201606010901.u518x7AQ001537@mx0a-001b2d01.pphosted.com>
2016-06-03 16:50   ` [Qemu-devel] [PATCH qemu v17 10/12] vfio/spapr: Create DMA window dynamically (SPAPR IOMMU v2) Alex Williamson
     [not found] ` <201606011013.u51A9ALx023064@mx0a-001b2d01.pphosted.com>
2016-06-03 16:59   ` Alex Williamson [this message]
     [not found] ` <201606010901.u518x1wF023568@mx0a-001b2d01.pphosted.com>
2016-06-06  5:57   ` [Qemu-devel] [PATCH qemu v17 11/12] spapr_pci/spapr_pci_vfio: Support Dynamic DMA Windows (DDW) David Gibson
2016-06-06  8:12     ` Alexey Kardashevskiy
2016-06-08  5:57       ` David Gibson
2016-06-08  6:09         ` Alexey Kardashevskiy
2016-06-09  4:28           ` David Gibson

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=20160603105915.08b4d2b1@t450s.home \
    --to=alex.williamson@redhat.com \
    --cc=agraf@suse.de \
    --cc=aik@ozlabs.ru \
    --cc=david@gibson.dropbear.id.au \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@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).