diff mbox series

[Xen-devel,for-next,12/16] xen/arm: p2m: Introduce p2m_tlb_flush_sync, export it and use it

Message ID 20171123183210.12045-13-julien.grall@linaro.org
State Superseded
Headers show
Series xen/arm: Stage-2 handling cleanup | expand

Commit Message

Julien Grall Nov. 23, 2017, 6:32 p.m. UTC
Multiple places in the code requires to flush the TLBs wonly when
p2m->need_flush is set.

Rather than open-coding it, introduce a new helper p2m_tlb_flush_sync to
do it.

Note that p2m_tlb_flush_sync is exported as it might be used by other
part of Xen.

Signed-off-by: Julien Grall <julien.grall@linaro.org>
---
 xen/arch/arm/p2m.c        | 27 +++++++++++++--------------
 xen/include/asm-arm/p2m.h |  2 ++
 2 files changed, 15 insertions(+), 14 deletions(-)

Comments

Stefano Stabellini Dec. 7, 2017, 10:14 p.m. UTC | #1
On Thu, 23 Nov 2017, Julien Grall wrote:
> Multiple places in the code requires to flush the TLBs wonly when
                                                         ^ only

Aside from this

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> p2m->need_flush is set.
> 
> Rather than open-coding it, introduce a new helper p2m_tlb_flush_sync to
> do it.
> 
> Note that p2m_tlb_flush_sync is exported as it might be used by other
> part of Xen.
> 
> Signed-off-by: Julien Grall <julien.grall@linaro.org>
> ---
>  xen/arch/arm/p2m.c        | 27 +++++++++++++--------------
>  xen/include/asm-arm/p2m.h |  2 ++
>  2 files changed, 15 insertions(+), 14 deletions(-)
> 
> diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
> index d466a5bc43..37498d8ff1 100644
> --- a/xen/arch/arm/p2m.c
> +++ b/xen/arch/arm/p2m.c
> @@ -52,21 +52,15 @@ static const paddr_t level_masks[] =
>  static const uint8_t level_orders[] =
>      { ZEROETH_ORDER, FIRST_ORDER, SECOND_ORDER, THIRD_ORDER };
>  
> -static void p2m_tlb_flush(struct p2m_domain *p2m);
> -
>  /* Unlock the flush and do a P2M TLB flush if necessary */
>  void p2m_write_unlock(struct p2m_domain *p2m)
>  {
> -    if ( p2m->need_flush )
> -    {
> -        p2m->need_flush = false;
> -        /*
> -         * The final flush is done with the P2M write lock taken to
> -         * to avoid someone else modify the P2M before the TLB
> -         * invalidation has completed.
> -         */
> -        p2m_tlb_flush(p2m);
> -    }
> +    /*
> +     * The final flush is done with the P2M write lock taken to avoid
> +     * someone else modifying the P2M wbefore the TLB invalidation has
> +     * completed.
> +     */
> +    p2m_tlb_flush_sync(p2m);
>  
>      write_unlock(&p2m->lock);
>  }
> @@ -178,6 +172,12 @@ static void p2m_force_tlb_flush_sync(struct p2m_domain *p2m)
>      p2m->need_flush = false;
>  }
>  
> +void p2m_tlb_flush_sync(struct p2m_domain *p2m)
> +{
> +    if ( p2m->need_flush )
> +        p2m_force_tlb_flush_sync(p2m);
> +}
> +
>  /*
>   * Find and map the root page table. The caller is responsible for
>   * unmapping the table.
> @@ -674,8 +674,7 @@ static void p2m_free_entry(struct p2m_domain *p2m,
>       * XXX: Should we defer the free of the page table to avoid the
>       * flush?
>       */
> -    if ( p2m->need_flush )
> -        p2m_force_tlb_flush_sync(p2m);
> +    p2m_tlb_flush_sync(p2m);
>  
>      mfn = _mfn(entry.p2m.base);
>      ASSERT(mfn_valid(mfn));
> diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
> index faadcfe8fe..a0abc84ed8 100644
> --- a/xen/include/asm-arm/p2m.h
> +++ b/xen/include/asm-arm/p2m.h
> @@ -204,6 +204,8 @@ static inline int p2m_is_write_locked(struct p2m_domain *p2m)
>      return rw_is_write_locked(&p2m->lock);
>  }
>  
> +void p2m_tlb_flush_sync(struct p2m_domain *p2m);
> +
>  /* Look up the MFN corresponding to a domain's GFN. */
>  mfn_t p2m_lookup(struct domain *d, gfn_t gfn, p2m_type_t *t);
diff mbox series

Patch

diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index d466a5bc43..37498d8ff1 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -52,21 +52,15 @@  static const paddr_t level_masks[] =
 static const uint8_t level_orders[] =
     { ZEROETH_ORDER, FIRST_ORDER, SECOND_ORDER, THIRD_ORDER };
 
-static void p2m_tlb_flush(struct p2m_domain *p2m);
-
 /* Unlock the flush and do a P2M TLB flush if necessary */
 void p2m_write_unlock(struct p2m_domain *p2m)
 {
-    if ( p2m->need_flush )
-    {
-        p2m->need_flush = false;
-        /*
-         * The final flush is done with the P2M write lock taken to
-         * to avoid someone else modify the P2M before the TLB
-         * invalidation has completed.
-         */
-        p2m_tlb_flush(p2m);
-    }
+    /*
+     * The final flush is done with the P2M write lock taken to avoid
+     * someone else modifying the P2M wbefore the TLB invalidation has
+     * completed.
+     */
+    p2m_tlb_flush_sync(p2m);
 
     write_unlock(&p2m->lock);
 }
@@ -178,6 +172,12 @@  static void p2m_force_tlb_flush_sync(struct p2m_domain *p2m)
     p2m->need_flush = false;
 }
 
+void p2m_tlb_flush_sync(struct p2m_domain *p2m)
+{
+    if ( p2m->need_flush )
+        p2m_force_tlb_flush_sync(p2m);
+}
+
 /*
  * Find and map the root page table. The caller is responsible for
  * unmapping the table.
@@ -674,8 +674,7 @@  static void p2m_free_entry(struct p2m_domain *p2m,
      * XXX: Should we defer the free of the page table to avoid the
      * flush?
      */
-    if ( p2m->need_flush )
-        p2m_force_tlb_flush_sync(p2m);
+    p2m_tlb_flush_sync(p2m);
 
     mfn = _mfn(entry.p2m.base);
     ASSERT(mfn_valid(mfn));
diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
index faadcfe8fe..a0abc84ed8 100644
--- a/xen/include/asm-arm/p2m.h
+++ b/xen/include/asm-arm/p2m.h
@@ -204,6 +204,8 @@  static inline int p2m_is_write_locked(struct p2m_domain *p2m)
     return rw_is_write_locked(&p2m->lock);
 }
 
+void p2m_tlb_flush_sync(struct p2m_domain *p2m);
+
 /* Look up the MFN corresponding to a domain's GFN. */
 mfn_t p2m_lookup(struct domain *d, gfn_t gfn, p2m_type_t *t);