All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: Auger Eric <eric.auger@redhat.com>
Cc: qemu-devel@nongnu.org, tianyu.lan@intel.com,
	kevin.tian@intel.com, mst@redhat.com, jan.kiszka@siemens.com,
	jasowang@redhat.com, alex.williamson@redhat.com,
	Marcel Apfelbaum <marcel@redhat.com>,
	bd.aviv@gmail.com, David Gibson <david@gibson.dropbear.id.au>
Subject: Re: [Qemu-devel] [PATCH v8 3/9] memory: provide iommu_replay_all()
Date: Fri, 7 Apr 2017 12:17:20 +0800	[thread overview]
Message-ID: <20170407041720.GH3981@pxdev.xzpeter.org> (raw)
In-Reply-To: <20170406114647.GC3981@pxdev.xzpeter.org>

On Thu, Apr 06, 2017 at 07:46:47PM +0800, Peter Xu wrote:
> On Thu, Apr 06, 2017 at 12:52:19PM +0200, Auger Eric wrote:
> > Hi Peter,
> > 
> > On 06/04/2017 09:08, Peter Xu wrote:

[...]

> > > +void memory_region_iommu_replay_all(MemoryRegion *mr)
> > > +{
> > > +    IOMMUNotifier *notifier;
> > > +
> > > +    IOMMU_NOTIFIER_FOREACH(notifier, mr) {
> > > +        memory_region_iommu_replay(mr, notifier, false);
> > It is not fully clear to me what is the consequence of setting
> > is_write=false always?
> 
> I am not quite sure about it either, on why we are having the is_write
> parameter on memory_region_iommu_replay(). It's there since the first
> commit that introduced the interface:
> 
>     commit a788f227ef7bd2912fcaacdfe13d13ece2998149
>     Author: David Gibson <david@gibson.dropbear.id.au>
>     Date:   Wed Sep 30 12:13:55 2015 +1000
> 
>     memory: Allow replay of IOMMU mapping notifications
> 
> However imho that should be a check against page RW permissions, which
> seems unecessary during replay. Or say, not sure whether below patch
> would be good (as a standalone one besides current patch/series):
> 
> ------8<------
> 
> diff --git a/hw/vfio/common.c b/hw/vfio/common.c
> index 6b33b9f..d008a4b 100644
> --- a/hw/vfio/common.c
> +++ b/hw/vfio/common.c
> @@ -488,7 +488,7 @@ static void vfio_listener_region_add(MemoryListener *listener,
>          QLIST_INSERT_HEAD(&container->giommu_list, giommu, giommu_next);
>  
>          memory_region_register_iommu_notifier(giommu->iommu, &giommu->n);
> -        memory_region_iommu_replay(giommu->iommu, &giommu->n, false);
> +        memory_region_iommu_replay(giommu->iommu, &giommu->n);
>  
>          return;
>      }
> diff --git a/include/exec/memory.h b/include/exec/memory.h
> index c4fc94d..5ab0151 100644
> --- a/include/exec/memory.h
> +++ b/include/exec/memory.h
> @@ -725,11 +725,8 @@ void memory_region_register_iommu_notifier(MemoryRegion *mr,
>   *
>   * @mr: the memory region to observe
>   * @n: the notifier to which to replay iommu mappings
> - * @is_write: Whether to treat the replay as a translate "write"
> - *     through the iommu
>   */
> -void memory_region_iommu_replay(MemoryRegion *mr, IOMMUNotifier *n,
> -                                bool is_write);
> +void memory_region_iommu_replay(MemoryRegion *mr, IOMMUNotifier *n);
>  
>  /**
>   * memory_region_iommu_replay_all: replay existing IOMMU translations
> diff --git a/memory.c b/memory.c
> index b782d5b..155ca1c 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -1620,8 +1620,7 @@ uint64_t memory_region_iommu_get_min_page_size(MemoryRegion *mr)
>      return TARGET_PAGE_SIZE;
>  }
>  
> -void memory_region_iommu_replay(MemoryRegion *mr, IOMMUNotifier *n,
> -                                bool is_write)
> +void memory_region_iommu_replay(MemoryRegion *mr, IOMMUNotifier *n)
>  {
>      hwaddr addr, granularity;
>      IOMMUTLBEntry iotlb;
> @@ -1635,7 +1634,13 @@ void memory_region_iommu_replay(MemoryRegion *mr, IOMMUNotifier *n,
>      granularity = memory_region_iommu_get_min_page_size(mr);
>  
>      for (addr = 0; addr < memory_region_size(mr); addr += granularity) {
> -        iotlb = mr->iommu_ops->translate(mr, addr, is_write);
> +        /*
> +         * For a replay, we don't need to do permission check.
> +         * Assuming a "read" operation here to make sure we will pass
> +         * the check (in case we don't have write permission on the
> +         * page).
> +         */
> +        iotlb = mr->iommu_ops->translate(mr, addr, false);
>          if (iotlb.perm != IOMMU_NONE) {
>              n->notify(n, &iotlb);
>          }
> @@ -1653,7 +1658,7 @@ void memory_region_iommu_replay_all(MemoryRegion *mr)
>      IOMMUNotifier *notifier;
>  
>      IOMMU_NOTIFIER_FOREACH(notifier, mr) {
> -        memory_region_iommu_replay(mr, notifier, false);
> +        memory_region_iommu_replay(mr, notifier);
>      }
>  }
> 
> ----->8------

This follow-up patch has an assumption that all the pages would have
read permission. That may not be true, e.g., for write-only pages. A
better way (after a short discussion with David Gibson) would be
converting is_write in iommu_ops.translate() to IOMMUAccessFlags, so
that we can pass in IOMMU_NONE here (it means, we don't check
permission for this page translation). Further, we can remove the
is_write parameter in memory_region_iommu_replay().

In all cases, I'll move this change out of current series and send a
fresh-new post after 2.10. Thanks,

-- peterx

  reply	other threads:[~2017-04-07  4:17 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-06  7:08 [Qemu-devel] [PATCH v8 0/9] VT-d: vfio enablement and misc enhances Peter Xu
2017-04-06  7:08 ` [Qemu-devel] [PATCH v8 1/9] memory: add section range info for IOMMU notifier Peter Xu
2017-04-06 10:42   ` Auger Eric
2017-04-06 10:52     ` Peter Xu
2017-04-06 11:54   ` Michael S. Tsirkin
2017-04-06 15:10   ` Alex Williamson
2017-04-06  7:08 ` [Qemu-devel] [PATCH v8 2/9] memory: provide IOMMU_NOTIFIER_FOREACH macro Peter Xu
2017-04-06 10:45   ` Auger Eric
2017-04-06 11:12     ` Peter Xu
2017-04-06 11:30       ` Auger Eric
2017-04-06 11:54   ` Michael S. Tsirkin
2017-04-06  7:08 ` [Qemu-devel] [PATCH v8 3/9] memory: provide iommu_replay_all() Peter Xu
2017-04-06 10:52   ` Auger Eric
2017-04-06 11:46     ` Peter Xu
2017-04-07  4:17       ` Peter Xu [this message]
2017-04-06 11:55   ` Michael S. Tsirkin
2017-04-06  7:08 ` [Qemu-devel] [PATCH v8 4/9] memory: introduce memory_region_notify_one() Peter Xu
2017-04-06 10:54   ` Auger Eric
2017-04-06 11:55   ` Michael S. Tsirkin
2017-04-06  7:08 ` [Qemu-devel] [PATCH v8 5/9] memory: add MemoryRegionIOMMUOps.replay() callback Peter Xu
2017-04-06 10:58   ` Auger Eric
2017-04-06 11:57   ` Michael S. Tsirkin
2017-04-06  7:08 ` [Qemu-devel] [PATCH v8 6/9] intel_iommu: use the correct memory region for device IOTLB notification Peter Xu
2017-04-06 11:57   ` Michael S. Tsirkin
2017-04-06  7:08 ` [Qemu-devel] [PATCH v8 7/9] intel_iommu: provide its own replay() callback Peter Xu
2017-04-06 11:57   ` Michael S. Tsirkin
2017-04-06  7:08 ` [Qemu-devel] [PATCH v8 8/9] intel_iommu: allow dynamic switch of IOMMU region Peter Xu
2017-04-06 11:58   ` Michael S. Tsirkin
2017-04-06  7:08 ` [Qemu-devel] [PATCH v8 9/9] intel_iommu: enable remote IOTLB Peter Xu
2017-04-06 11:58   ` Michael S. Tsirkin
2017-04-06 11:53 ` [Qemu-devel] [PATCH v8 0/9] VT-d: vfio enablement and misc enhances Michael S. Tsirkin
2017-04-06 15:25   ` Peter Xu
2017-04-06 12:00 ` Michael S. Tsirkin
2017-04-06 15:27   ` Peter Xu

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=20170407041720.GH3981@pxdev.xzpeter.org \
    --to=peterx@redhat.com \
    --cc=alex.williamson@redhat.com \
    --cc=bd.aviv@gmail.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=eric.auger@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=jasowang@redhat.com \
    --cc=kevin.tian@intel.com \
    --cc=marcel@redhat.com \
    --cc=mst@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=tianyu.lan@intel.com \
    /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.