All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xen-devel] [PATCH] x86/p2m: fix non-translated handling of iommu mappings
@ 2019-07-22 15:32 Roger Pau Monne
  2019-07-22 15:33 ` Paul Durrant
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Roger Pau Monne @ 2019-07-22 15:32 UTC (permalink / raw)
  To: xen-devel
  Cc: Wei Liu, George Dunlap, Andrew Cooper, Paul Durrant, Jan Beulich,
	Roger Pau Monne

The current usage of need_iommu_pt_sync in p2m for non-translated
guests is wrong because it doesn't correctly handle a relaxed PV
hardware domain, that has need_sync set to false, but still need
entries to be added from calls to {set/clear}_identity_p2m_entry.

Adjust the code in guest_physmap_add_page to also check whether the
domain has an iommu instead of whether it needs syncing or not in
order to take a reference to a page to be mapped.

Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
---
Cc: George Dunlap <george.dunlap@eu.citrix.com>
Cc: Jan Beulich <jbeulich@suse.com>
Cc: Andrew Cooper <andrew.cooper3@citrix.com>
Cc: Wei Liu <wl@xen.org>
Cc: Paul Durrant <Paul.Durrant@citrix.com>
---
 xen/arch/x86/mm/p2m.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
index fef97c82f6..88a2430c8c 100644
--- a/xen/arch/x86/mm/p2m.c
+++ b/xen/arch/x86/mm/p2m.c
@@ -836,7 +836,7 @@ guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn,
          */
         for ( i = 0; i < (1UL << page_order); ++i, ++page )
         {
-            if ( !need_iommu_pt_sync(d) )
+            if ( !has_iommu_pt(d) )
                 /* nothing */;
             else if ( get_page_and_type(page, d, PGT_writable_page) )
                 put_page_and_type(page);
@@ -1341,7 +1341,7 @@ int set_identity_p2m_entry(struct domain *d, unsigned long gfn_l,
 
     if ( !paging_mode_translate(p2m->domain) )
     {
-        if ( !need_iommu_pt_sync(d) )
+        if ( !has_iommu_pt(d) )
             return 0;
         return iommu_legacy_map(d, _dfn(gfn_l), _mfn(gfn_l), PAGE_ORDER_4K,
                                 IOMMUF_readable | IOMMUF_writable);
@@ -1432,7 +1432,7 @@ int clear_identity_p2m_entry(struct domain *d, unsigned long gfn_l)
 
     if ( !paging_mode_translate(d) )
     {
-        if ( !need_iommu_pt_sync(d) )
+        if ( !has_iommu_pt(d) )
             return 0;
         return iommu_legacy_unmap(d, _dfn(gfn_l), PAGE_ORDER_4K);
     }
-- 
2.20.1 (Apple Git-117)


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [Xen-devel] [PATCH] x86/p2m: fix non-translated handling of iommu mappings
  2019-07-22 15:32 [Xen-devel] [PATCH] x86/p2m: fix non-translated handling of iommu mappings Roger Pau Monne
@ 2019-07-22 15:33 ` Paul Durrant
  2019-07-23 10:32 ` Jan Beulich
  2019-08-20  1:57 ` Roman Shaposhnik
  2 siblings, 0 replies; 6+ messages in thread
From: Paul Durrant @ 2019-07-22 15:33 UTC (permalink / raw)
  To: Roger Pau Monne, xen-devel
  Cc: Andrew Cooper, Wei Liu, George Dunlap, Jan Beulich, Roger Pau Monne

> -----Original Message-----
> From: Roger Pau Monne <roger.pau@citrix.com>
> Sent: 22 July 2019 16:32
> To: xen-devel@lists.xenproject.org
> Cc: Roger Pau Monne <roger.pau@citrix.com>; George Dunlap <George.Dunlap@citrix.com>; Jan Beulich
> <jbeulich@suse.com>; Andrew Cooper <Andrew.Cooper3@citrix.com>; Wei Liu <wl@xen.org>; Paul Durrant
> <Paul.Durrant@citrix.com>
> Subject: [PATCH] x86/p2m: fix non-translated handling of iommu mappings
> 
> The current usage of need_iommu_pt_sync in p2m for non-translated
> guests is wrong because it doesn't correctly handle a relaxed PV
> hardware domain, that has need_sync set to false, but still need
> entries to be added from calls to {set/clear}_identity_p2m_entry.
> 
> Adjust the code in guest_physmap_add_page to also check whether the
> domain has an iommu instead of whether it needs syncing or not in
> order to take a reference to a page to be mapped.
> 
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> ---
> Cc: George Dunlap <george.dunlap@eu.citrix.com>
> Cc: Jan Beulich <jbeulich@suse.com>
> Cc: Andrew Cooper <andrew.cooper3@citrix.com>
> Cc: Wei Liu <wl@xen.org>
> Cc: Paul Durrant <Paul.Durrant@citrix.com>

Reviewed-by: Paul Durrant <paul.durrant@citrix.com>

> ---
>  xen/arch/x86/mm/p2m.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
> index fef97c82f6..88a2430c8c 100644
> --- a/xen/arch/x86/mm/p2m.c
> +++ b/xen/arch/x86/mm/p2m.c
> @@ -836,7 +836,7 @@ guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn,
>           */
>          for ( i = 0; i < (1UL << page_order); ++i, ++page )
>          {
> -            if ( !need_iommu_pt_sync(d) )
> +            if ( !has_iommu_pt(d) )
>                  /* nothing */;
>              else if ( get_page_and_type(page, d, PGT_writable_page) )
>                  put_page_and_type(page);
> @@ -1341,7 +1341,7 @@ int set_identity_p2m_entry(struct domain *d, unsigned long gfn_l,
> 
>      if ( !paging_mode_translate(p2m->domain) )
>      {
> -        if ( !need_iommu_pt_sync(d) )
> +        if ( !has_iommu_pt(d) )
>              return 0;
>          return iommu_legacy_map(d, _dfn(gfn_l), _mfn(gfn_l), PAGE_ORDER_4K,
>                                  IOMMUF_readable | IOMMUF_writable);
> @@ -1432,7 +1432,7 @@ int clear_identity_p2m_entry(struct domain *d, unsigned long gfn_l)
> 
>      if ( !paging_mode_translate(d) )
>      {
> -        if ( !need_iommu_pt_sync(d) )
> +        if ( !has_iommu_pt(d) )
>              return 0;
>          return iommu_legacy_unmap(d, _dfn(gfn_l), PAGE_ORDER_4K);
>      }
> --
> 2.20.1 (Apple Git-117)

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [Xen-devel] [PATCH] x86/p2m: fix non-translated handling of iommu mappings
  2019-07-22 15:32 [Xen-devel] [PATCH] x86/p2m: fix non-translated handling of iommu mappings Roger Pau Monne
  2019-07-22 15:33 ` Paul Durrant
@ 2019-07-23 10:32 ` Jan Beulich
  2019-07-23 12:40   ` Roger Pau Monné
  2019-08-20  1:57 ` Roman Shaposhnik
  2 siblings, 1 reply; 6+ messages in thread
From: Jan Beulich @ 2019-07-23 10:32 UTC (permalink / raw)
  To: Roger Pau Monne
  Cc: George Dunlap, xen-devel, Paul Durrant, Wei Liu, Andrew Cooper

On 22.07.2019 17:32, Roger Pau Monne wrote:
> The current usage of need_iommu_pt_sync in p2m for non-translated
> guests is wrong because it doesn't correctly handle a relaxed PV
> hardware domain, that has need_sync set to false, but still need
> entries to be added from calls to {set/clear}_identity_p2m_entry.
> 
> Adjust the code in guest_physmap_add_page to also check whether the
> domain has an iommu instead of whether it needs syncing or not in
> order to take a reference to a page to be mapped.

Why this seemingly unrelated change? I ask because ...

> --- a/xen/arch/x86/mm/p2m.c
> +++ b/xen/arch/x86/mm/p2m.c
> @@ -836,7 +836,7 @@ guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn,
>            */
>           for ( i = 0; i < (1UL << page_order); ++i, ++page )
>           {
> -            if ( !need_iommu_pt_sync(d) )
> +            if ( !has_iommu_pt(d) )
>                   /* nothing */;
>               else if ( get_page_and_type(page, d, PGT_writable_page) )
>                   put_page_and_type(page);

... this parallels the code in iommu_hwdom_init(), which similarly
uses need_iommu_pt_sync() (and during the prior discussion you did
agree with Paul that it shouldn't be changed). IOW the patch for
now can have my R-b only with this change and the respective part
of the description dropped.

Jan
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [Xen-devel] [PATCH] x86/p2m: fix non-translated handling of iommu mappings
  2019-07-23 10:32 ` Jan Beulich
@ 2019-07-23 12:40   ` Roger Pau Monné
  0 siblings, 0 replies; 6+ messages in thread
From: Roger Pau Monné @ 2019-07-23 12:40 UTC (permalink / raw)
  To: Jan Beulich
  Cc: George Dunlap, xen-devel, Paul Durrant, Wei Liu, Andrew Cooper

On Tue, Jul 23, 2019 at 10:32:41AM +0000, Jan Beulich wrote:
> On 22.07.2019 17:32, Roger Pau Monne wrote:
> > The current usage of need_iommu_pt_sync in p2m for non-translated
> > guests is wrong because it doesn't correctly handle a relaxed PV
> > hardware domain, that has need_sync set to false, but still need
> > entries to be added from calls to {set/clear}_identity_p2m_entry.
> > 
> > Adjust the code in guest_physmap_add_page to also check whether the
> > domain has an iommu instead of whether it needs syncing or not in
> > order to take a reference to a page to be mapped.
> 
> Why this seemingly unrelated change? I ask because ...
> 
> > --- a/xen/arch/x86/mm/p2m.c
> > +++ b/xen/arch/x86/mm/p2m.c
> > @@ -836,7 +836,7 @@ guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn,
> >            */
> >           for ( i = 0; i < (1UL << page_order); ++i, ++page )
> >           {
> > -            if ( !need_iommu_pt_sync(d) )
> > +            if ( !has_iommu_pt(d) )
> >                   /* nothing */;
> >               else if ( get_page_and_type(page, d, PGT_writable_page) )
> >                   put_page_and_type(page);
> 
> ... this parallels the code in iommu_hwdom_init(), which similarly
> uses need_iommu_pt_sync() (and during the prior discussion you did
> agree with Paul that it shouldn't be changed). IOW the patch for
> now can have my R-b only with this change and the respective part
> of the description dropped.

OK, this is again not needed for a relaxed PV hardware domain because
all RAM is already mapped on the iommu page tables.

Let me update the commit and resend.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [Xen-devel] [PATCH] x86/p2m: fix non-translated handling of iommu mappings
  2019-07-22 15:32 [Xen-devel] [PATCH] x86/p2m: fix non-translated handling of iommu mappings Roger Pau Monne
  2019-07-22 15:33 ` Paul Durrant
  2019-07-23 10:32 ` Jan Beulich
@ 2019-08-20  1:57 ` Roman Shaposhnik
  2019-08-20  7:36   ` Roger Pau Monné
  2 siblings, 1 reply; 6+ messages in thread
From: Roman Shaposhnik @ 2019-08-20  1:57 UTC (permalink / raw)
  To: Roger Pau Monne
  Cc: Wei Liu, George Dunlap, Andrew Cooper, Paul Durrant, Jan Beulich,
	xen-devel

On Mon, Jul 22, 2019 at 8:33 AM Roger Pau Monne <roger.pau@citrix.com> wrote:
>
> The current usage of need_iommu_pt_sync in p2m for non-translated
> guests is wrong because it doesn't correctly handle a relaxed PV
> hardware domain, that has need_sync set to false, but still need
> entries to be added from calls to {set/clear}_identity_p2m_entry.
>
> Adjust the code in guest_physmap_add_page to also check whether the
> domain has an iommu instead of whether it needs syncing or not in
> order to take a reference to a page to be mapped.
>
> Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> ---
> Cc: George Dunlap <george.dunlap@eu.citrix.com>
> Cc: Jan Beulich <jbeulich@suse.com>
> Cc: Andrew Cooper <andrew.cooper3@citrix.com>
> Cc: Wei Liu <wl@xen.org>
> Cc: Paul Durrant <Paul.Durrant@citrix.com>

Tested-by: Roman Shaposhnik <roman@zededa.com>

> ---
>  xen/arch/x86/mm/p2m.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/xen/arch/x86/mm/p2m.c b/xen/arch/x86/mm/p2m.c
> index fef97c82f6..88a2430c8c 100644
> --- a/xen/arch/x86/mm/p2m.c
> +++ b/xen/arch/x86/mm/p2m.c
> @@ -836,7 +836,7 @@ guest_physmap_add_page(struct domain *d, gfn_t gfn, mfn_t mfn,
>           */
>          for ( i = 0; i < (1UL << page_order); ++i, ++page )
>          {
> -            if ( !need_iommu_pt_sync(d) )
> +            if ( !has_iommu_pt(d) )
>                  /* nothing */;
>              else if ( get_page_and_type(page, d, PGT_writable_page) )
>                  put_page_and_type(page);
> @@ -1341,7 +1341,7 @@ int set_identity_p2m_entry(struct domain *d, unsigned long gfn_l,
>
>      if ( !paging_mode_translate(p2m->domain) )
>      {
> -        if ( !need_iommu_pt_sync(d) )
> +        if ( !has_iommu_pt(d) )
>              return 0;
>          return iommu_legacy_map(d, _dfn(gfn_l), _mfn(gfn_l), PAGE_ORDER_4K,
>                                  IOMMUF_readable | IOMMUF_writable);
> @@ -1432,7 +1432,7 @@ int clear_identity_p2m_entry(struct domain *d, unsigned long gfn_l)
>
>      if ( !paging_mode_translate(d) )
>      {
> -        if ( !need_iommu_pt_sync(d) )
> +        if ( !has_iommu_pt(d) )
>              return 0;
>          return iommu_legacy_unmap(d, _dfn(gfn_l), PAGE_ORDER_4K);
>      }
> --
> 2.20.1 (Apple Git-117)
>
>
> _______________________________________________
> Xen-devel mailing list
> Xen-devel@lists.xenproject.org
> https://lists.xenproject.org/mailman/listinfo/xen-devel

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

* Re: [Xen-devel] [PATCH] x86/p2m: fix non-translated handling of iommu mappings
  2019-08-20  1:57 ` Roman Shaposhnik
@ 2019-08-20  7:36   ` Roger Pau Monné
  0 siblings, 0 replies; 6+ messages in thread
From: Roger Pau Monné @ 2019-08-20  7:36 UTC (permalink / raw)
  To: Roman Shaposhnik
  Cc: Wei Liu, George Dunlap, Andrew Cooper, Paul Durrant, Jan Beulich,
	xen-devel

On Mon, Aug 19, 2019 at 06:57:06PM -0700, Roman Shaposhnik wrote:
> On Mon, Jul 22, 2019 at 8:33 AM Roger Pau Monne <roger.pau@citrix.com> wrote:
> >
> > The current usage of need_iommu_pt_sync in p2m for non-translated
> > guests is wrong because it doesn't correctly handle a relaxed PV
> > hardware domain, that has need_sync set to false, but still need
> > entries to be added from calls to {set/clear}_identity_p2m_entry.
> >
> > Adjust the code in guest_physmap_add_page to also check whether the
> > domain has an iommu instead of whether it needs syncing or not in
> > order to take a reference to a page to be mapped.
> >
> > Signed-off-by: Roger Pau Monné <roger.pau@citrix.com>
> > ---
> > Cc: George Dunlap <george.dunlap@eu.citrix.com>
> > Cc: Jan Beulich <jbeulich@suse.com>
> > Cc: Andrew Cooper <andrew.cooper3@citrix.com>
> > Cc: Wei Liu <wl@xen.org>
> > Cc: Paul Durrant <Paul.Durrant@citrix.com>
> 
> Tested-by: Roman Shaposhnik <roman@zededa.com>

There's a v2 of the patch, but I guess your TB also applies to it.

Thanks, Roger.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

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

end of thread, other threads:[~2019-08-20  7:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-22 15:32 [Xen-devel] [PATCH] x86/p2m: fix non-translated handling of iommu mappings Roger Pau Monne
2019-07-22 15:33 ` Paul Durrant
2019-07-23 10:32 ` Jan Beulich
2019-07-23 12:40   ` Roger Pau Monné
2019-08-20  1:57 ` Roman Shaposhnik
2019-08-20  7:36   ` Roger Pau Monné

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.