All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] memory: warning on out of scope notification
@ 2019-06-24  8:26 Yan Zhao
  2019-06-24  8:39 ` [Qemu-devel] [PATCH v3] " Yan Zhao
  0 siblings, 1 reply; 4+ messages in thread
From: Yan Zhao @ 2019-06-24  8:26 UTC (permalink / raw)
  To: pbonzini; +Cc: Auger Eric, Yan Zhao, qemu-devel

if an entry has parts out of scope of notifier's range, print warning
message.

Out of scope mapping/unmapping would cause problem, as in below case:

1. initially there are two notifiers with ranges
0-0xfedfffff, 0xfef00000-0xffffffffffffffff,
IOVAs from 0x3c000000 - 0x3c1fffff is in shadow page table.

2. in vfio, memory_region_register_iommu_notifier() is followed by
memory_region_iommu_replay(), which will first call address space
unmap,
and walk and add back all entries in vtd shadow page table. e.g.
(1) for notifier 0-0xfedfffff,
    IOVAs from 0 - 0xffffffff get unmapped,
    and IOVAs from 0x3c000000 - 0x3c1fffff get mapped
(2) for notifier 0xfef00000-0xffffffffffffffff
    IOVAs from 0 - 0x7fffffffff get unmapped,
    but IOVAs from 0x3c000000 - 0x3c1fffff cannot get mapped back.

Cc: Auger Eric <eric.auger@redhat.com>
Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>

---
v2:
1. added a local variable entry_end (Auger Eric)
2. using PRIx64 as format for address range in warning message
(Auger Eric)

---
 memory.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/memory.c b/memory.c
index 0a089a7..3aacc09 100644
--- a/memory.c
+++ b/memory.c
@@ -1937,12 +1937,13 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
                               IOMMUTLBEntry *entry)
 {
     IOMMUNotifierFlag request_flags;
+    hwaddr entry_end = entry->iova + entry->addr_mask;
 
     /*
      * Skip the notification if the notification does not overlap
      * with registered range.
      */
-    if (notifier->start > entry->iova + entry->addr_mask ||
+    if (notifier->start > entry_end ||
         notifier->end < entry->iova) {
         return;
     }
@@ -1953,6 +1954,16 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
         request_flags = IOMMU_NOTIFIER_UNMAP;
     }
 
+    if (entry->iova < notifier->start ||
+            entry_end > notifier->end) {
+        warn_report("%s IOMMUTLBEntry 0x%" PRIx64 "-0x%" PRIx64
+                "outside of notifier scope 0x%" PRIx64 "-0x%" PRIx64,
+                (request_flags == IOMMU_NOTIFIER_MAP) ?
+                "Mapping" : "Unmapping",
+                entry->iova, entry->iova + entry->addr_mask,
+                notifier->start, notifier->end);
+    }
+
     if (notifier->notifier_flags & request_flags) {
         notifier->notify(notifier, entry);
     }
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Qemu-devel] [PATCH v3] memory: warning on out of scope notification
  2019-06-24  8:26 [Qemu-devel] [PATCH v2] memory: warning on out of scope notification Yan Zhao
@ 2019-06-24  8:39 ` Yan Zhao
  2019-06-24 10:11   ` Auger Eric
  0 siblings, 1 reply; 4+ messages in thread
From: Yan Zhao @ 2019-06-24  8:39 UTC (permalink / raw)
  To: pbonzini; +Cc: Auger Eric, Yan Zhao, qemu-devel

if an entry has parts out of scope of notifier's range, print warning
message.

Out of scope mapping/unmapping would cause problem, as in below case:

1. initially there are two notifiers with ranges
0-0xfedfffff, 0xfef00000-0xffffffffffffffff,
IOVAs from 0x3c000000 - 0x3c1fffff is in shadow page table.

2. in vfio, memory_region_register_iommu_notifier() is followed by
memory_region_iommu_replay(), which will first call address space
unmap,
and walk and add back all entries in vtd shadow page table. e.g.
(1) for notifier 0-0xfedfffff,
    IOVAs from 0 - 0xffffffff get unmapped,
    and IOVAs from 0x3c000000 - 0x3c1fffff get mapped
(2) for notifier 0xfef00000-0xffffffffffffffff
    IOVAs from 0 - 0x7fffffffff get unmapped,
    but IOVAs from 0x3c000000 - 0x3c1fffff cannot get mapped back.

Cc: Auger Eric <eric.auger@redhat.com>
Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>

---
v3:
refined code style and message format

v2:
1. added a local variable entry_end (Auger Eric)
2. using PRIx64 as format for address range in warning message
(Auger Eric)
---
 memory.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/memory.c b/memory.c
index 0a089a7..c7154ab 100644
--- a/memory.c
+++ b/memory.c
@@ -1937,13 +1937,13 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
                               IOMMUTLBEntry *entry)
 {
     IOMMUNotifierFlag request_flags;
+    hwaddr entry_end = entry->iova + entry->addr_mask;
 
     /*
      * Skip the notification if the notification does not overlap
      * with registered range.
      */
-    if (notifier->start > entry->iova + entry->addr_mask ||
-        notifier->end < entry->iova) {
+    if (notifier->start > entry_end || notifier->end < entry->iova) {
         return;
     }
 
@@ -1953,6 +1953,15 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
         request_flags = IOMMU_NOTIFIER_UNMAP;
     }
 
+    if (entry->iova < notifier->start || entry_end > notifier->end) {
+        warn_report("%s IOMMUTLBEntry 0x%" PRIx64 " - 0x%" PRIx64
+                " outside of notifier scope 0x%" PRIx64 " - 0x%" PRIx64,
+                (request_flags == IOMMU_NOTIFIER_MAP) ?
+                "Mapping" : "Unmapping",
+                entry->iova, entry->iova + entry->addr_mask,
+                notifier->start, notifier->end);
+    }
+
     if (notifier->notifier_flags & request_flags) {
         notifier->notify(notifier, entry);
     }
-- 
2.7.4



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v3] memory: warning on out of scope notification
  2019-06-24  8:39 ` [Qemu-devel] [PATCH v3] " Yan Zhao
@ 2019-06-24 10:11   ` Auger Eric
  2019-06-25  3:04     ` Yan Zhao
  0 siblings, 1 reply; 4+ messages in thread
From: Auger Eric @ 2019-06-24 10:11 UTC (permalink / raw)
  To: Yan Zhao, pbonzini; +Cc: qemu-devel

Hi Yan,

On 6/24/19 10:39 AM, Yan Zhao wrote:
> if an entry has parts out of scope of notifier's range, print warning
> message.
> 
> Out of scope mapping/unmapping would cause problem, as in below case:
> 
> 1. initially there are two notifiers with ranges
> 0-0xfedfffff, 0xfef00000-0xffffffffffffffff,
> IOVAs from 0x3c000000 - 0x3c1fffff is in shadow page table.
> 
> 2. in vfio, memory_region_register_iommu_notifier() is followed by
> memory_region_iommu_replay(), which will first call address space
> unmap,
> and walk and add back all entries in vtd shadow page table. e.g.
> (1) for notifier 0-0xfedfffff,
>     IOVAs from 0 - 0xffffffff get unmapped,
>     and IOVAs from 0x3c000000 - 0x3c1fffff get mapped
> (2) for notifier 0xfef00000-0xffffffffffffffff
>     IOVAs from 0 - 0x7fffffffff get unmapped,
>     but IOVAs from 0x3c000000 - 0x3c1fffff cannot get mapped back.
> 
> Cc: Auger Eric <eric.auger@redhat.com>
> Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
> 
> ---
> v3:
> refined code style and message format
> 
> v2:
> 1. added a local variable entry_end (Auger Eric)
> 2. using PRIx64 as format for address range in warning message
> (Auger Eric)
> ---
>  memory.c | 13 +++++++++++--
>  1 file changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/memory.c b/memory.c
> index 0a089a7..c7154ab 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -1937,13 +1937,13 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
>                                IOMMUTLBEntry *entry)
>  {
>      IOMMUNotifierFlag request_flags;
> +    hwaddr entry_end = entry->iova + entry->addr_mask;
>  
>      /*
>       * Skip the notification if the notification does not overlap
>       * with registered range.
>       */
> -    if (notifier->start > entry->iova + entry->addr_mask ||
> -        notifier->end < entry->iova) {
> +    if (notifier->start > entry_end || notifier->end < entry->iova) {
>          return;
>      }
>  
> @@ -1953,6 +1953,15 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
>          request_flags = IOMMU_NOTIFIER_UNMAP;
>      }
>  
> +    if (entry->iova < notifier->start || entry_end > notifier->end) {
> +        warn_report("%s IOMMUTLBEntry 0x%" PRIx64 " - 0x%" PRIx64
> +                " outside of notifier scope 0x%" PRIx64 " - 0x%" PRIx64,
> +                (request_flags == IOMMU_NOTIFIER_MAP) ?
> +                "Mapping" : "Unmapping",
> +                entry->iova, entry->iova + entry->addr_mask,
entry_end as well.

Then shouldn't we assert in that case?

Thanks

Eric
> +                notifier->start, notifier->end);
> +    }
> +
>      if (notifier->notifier_flags & request_flags) {
>          notifier->notify(notifier, entry);
>      }
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH v3] memory: warning on out of scope notification
  2019-06-24 10:11   ` Auger Eric
@ 2019-06-25  3:04     ` Yan Zhao
  0 siblings, 0 replies; 4+ messages in thread
From: Yan Zhao @ 2019-06-25  3:04 UTC (permalink / raw)
  To: Auger Eric; +Cc: pbonzini, qemu-devel

On Mon, Jun 24, 2019 at 06:11:11PM +0800, Auger Eric wrote:
> Hi Yan,
> 
> On 6/24/19 10:39 AM, Yan Zhao wrote:
> > if an entry has parts out of scope of notifier's range, print warning
> > message.
> > 
> > Out of scope mapping/unmapping would cause problem, as in below case:
> > 
> > 1. initially there are two notifiers with ranges
> > 0-0xfedfffff, 0xfef00000-0xffffffffffffffff,
> > IOVAs from 0x3c000000 - 0x3c1fffff is in shadow page table.
> > 
> > 2. in vfio, memory_region_register_iommu_notifier() is followed by
> > memory_region_iommu_replay(), which will first call address space
> > unmap,
> > and walk and add back all entries in vtd shadow page table. e.g.
> > (1) for notifier 0-0xfedfffff,
> >     IOVAs from 0 - 0xffffffff get unmapped,
> >     and IOVAs from 0x3c000000 - 0x3c1fffff get mapped
> > (2) for notifier 0xfef00000-0xffffffffffffffff
> >     IOVAs from 0 - 0x7fffffffff get unmapped,
> >     but IOVAs from 0x3c000000 - 0x3c1fffff cannot get mapped back.
> > 
> > Cc: Auger Eric <eric.auger@redhat.com>
> > Signed-off-by: Yan Zhao <yan.y.zhao@intel.com>
> > 
> > ---
> > v3:
> > refined code style and message format
> > 
> > v2:
> > 1. added a local variable entry_end (Auger Eric)
> > 2. using PRIx64 as format for address range in warning message
> > (Auger Eric)
> > ---
> >  memory.c | 13 +++++++++++--
> >  1 file changed, 11 insertions(+), 2 deletions(-)
> > 
> > diff --git a/memory.c b/memory.c
> > index 0a089a7..c7154ab 100644
> > --- a/memory.c
> > +++ b/memory.c
> > @@ -1937,13 +1937,13 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
> >                                IOMMUTLBEntry *entry)
> >  {
> >      IOMMUNotifierFlag request_flags;
> > +    hwaddr entry_end = entry->iova + entry->addr_mask;
> >  
> >      /*
> >       * Skip the notification if the notification does not overlap
> >       * with registered range.
> >       */
> > -    if (notifier->start > entry->iova + entry->addr_mask ||
> > -        notifier->end < entry->iova) {
> > +    if (notifier->start > entry_end || notifier->end < entry->iova) {
> >          return;
> >      }
> >  
> > @@ -1953,6 +1953,15 @@ void memory_region_notify_one(IOMMUNotifier *notifier,
> >          request_flags = IOMMU_NOTIFIER_UNMAP;
> >      }
> >  
> > +    if (entry->iova < notifier->start || entry_end > notifier->end) {
> > +        warn_report("%s IOMMUTLBEntry 0x%" PRIx64 " - 0x%" PRIx64
> > +                " outside of notifier scope 0x%" PRIx64 " - 0x%" PRIx64,
> > +                (request_flags == IOMMU_NOTIFIER_MAP) ?
> > +                "Mapping" : "Unmapping",
> > +                entry->iova, entry->iova + entry->addr_mask,
> entry_end as well.
> 
> Then shouldn't we assert in that case?
>
Yes, assert is good. I'll change warning to assert then.
Thanks
Yan

> Thanks
> 
> Eric
> > +                notifier->start, notifier->end);
> > +    }
> > +
> >      if (notifier->notifier_flags & request_flags) {
> >          notifier->notify(notifier, entry);
> >      }
> > 


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-06-25  3:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-24  8:26 [Qemu-devel] [PATCH v2] memory: warning on out of scope notification Yan Zhao
2019-06-24  8:39 ` [Qemu-devel] [PATCH v3] " Yan Zhao
2019-06-24 10:11   ` Auger Eric
2019-06-25  3:04     ` Yan Zhao

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.