Re: [Xen-devel] [PATCH v4 01/39] arm/p2m: Introduce p2m_(switch|restore)_vttbr_and_(g|s)et_flags

2017-10-09 Thread Julien Grall

Hi Sergej,

On 30/08/17 19:32, Sergej Proskurin wrote:

This commit introduces macros for switching and restoring the vttbr
considering the currently set irq flags. We define these macros, as the
following commits will use the associated functionality multiple times
throughout different files.

Signed-off-by: Sergej Proskurin 
---
Cc: Stefano Stabellini 
Cc: Julien Grall 
---
v4: Save the content of VTTBR_EL2 inside of the introduced macro
 "p2m_switch_vttbr_and_get_flags".

 Move the introduced macros into ./xen/include/asm-arm/p2m.h, as they will
 be used by different files in the future commits.


I don't like the idea of moving such macros in p2m.h because it expose 
the underlying implementation of P2M.


A better solution would be introduce a helper to translate from a guest 
VA to guest PA in p2m.c. This helper will switch to the host P2M if 
necessary.


Cheers,

--
Julien Grall

___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel


[Xen-devel] [PATCH v4 01/39] arm/p2m: Introduce p2m_(switch|restore)_vttbr_and_(g|s)et_flags

2017-08-30 Thread Sergej Proskurin
This commit introduces macros for switching and restoring the vttbr
considering the currently set irq flags. We define these macros, as the
following commits will use the associated functionality multiple times
throughout different files.

Signed-off-by: Sergej Proskurin 
---
Cc: Stefano Stabellini 
Cc: Julien Grall 
---
v4: Save the content of VTTBR_EL2 inside of the introduced macro
"p2m_switch_vttbr_and_get_flags".

Move the introduced macros into ./xen/include/asm-arm/p2m.h, as they will
be used by different files in the future commits.
---
 xen/arch/arm/p2m.c| 15 ++-
 xen/include/asm-arm/p2m.h | 21 +
 2 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/xen/arch/arm/p2m.c b/xen/arch/arm/p2m.c
index c484469e6c..4334e3bc81 100644
--- a/xen/arch/arm/p2m.c
+++ b/xen/arch/arm/p2m.c
@@ -147,22 +147,11 @@ static void p2m_flush_tlb(struct p2m_domain *p2m)
  * ARM only provides an instruction to flush TLBs for the current
  * VMID. So switch to the VTTBR of a given P2M if different.
  */
-ovttbr = READ_SYSREG64(VTTBR_EL2);
-if ( ovttbr != p2m->vttbr )
-{
-local_irq_save(flags);
-WRITE_SYSREG64(p2m->vttbr, VTTBR_EL2);
-isb();
-}
+p2m_switch_vttbr_and_get_flags(ovttbr, p2m->vttbr, flags);
 
 flush_tlb();
 
-if ( ovttbr != READ_SYSREG64(VTTBR_EL2) )
-{
-WRITE_SYSREG64(ovttbr, VTTBR_EL2);
-isb();
-local_irq_restore(flags);
-}
+p2m_restore_vttbr_and_set_flags(ovttbr, flags);
 }
 
 /*
diff --git a/xen/include/asm-arm/p2m.h b/xen/include/asm-arm/p2m.h
index aa0d60ae3a..500dc88fbc 100644
--- a/xen/include/asm-arm/p2m.h
+++ b/xen/include/asm-arm/p2m.h
@@ -12,6 +12,27 @@
 
 #define paddr_bits PADDR_BITS
 
+#define p2m_switch_vttbr_and_get_flags(ovttbr, nvttbr, flags)   \
+({  \
+ ovttbr = READ_SYSREG64(VTTBR_EL2); \
+ if ( ovttbr != nvttbr )\
+ {  \
+local_irq_save(flags);  \
+WRITE_SYSREG64(nvttbr, VTTBR_EL2);  \
+isb();  \
+ }  \
+})
+
+#define p2m_restore_vttbr_and_set_flags(ovttbr, flags)  \
+({  \
+ if ( ovttbr != READ_SYSREG64(VTTBR_EL2) )  \
+ {  \
+WRITE_SYSREG64(ovttbr, VTTBR_EL2);  \
+isb();  \
+local_irq_restore(flags);   \
+ }  \
+})
+
 /* Holds the bit size of IPAs in p2m tables.  */
 extern unsigned int p2m_ipa_bits;
 
-- 
2.13.3


___
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel