xen/arm: p2m: flush TLB by VMID when a new domain is creating
PATCH 1/1 xen/arm: p2m: flush TLB by VMID when a new domain is creating
Once the VMID is marked unused, a new domain can reuse the VMID for its own. If the TLB is not flushed, entries can contain wrong translation. When a new p2m is allocated, switch to the new VMID and flush TLB on every physical CPUs.
---
Changes in v2:
- This patch was formerly "xen/arm: p2m: flush TLB when a domain is destroyed
- Flush TLB by VMID in p2m_alloc_table. It will avoid to flush all TLBs every domain destruction.
--- xen/arch/arm/p2m.c | 10 ++++++++++ xen/include/asm-arm/arm32/flushtlb.h | 11 +++++++++++ xen/include/asm-arm/arm64/flushtlb.h | 11 +++++++++++ 3 files changed, 32 insertions(+)
xen/arch/arm/p2m.c +10 -0
@@ -302,6 +302,15 @@ int p2m_alloc_table(struct domain *d) d->arch.vttbr =page_to_maddr (p2m->first_level) | ((uint64_t )p2m->vmid&0xff )<<48 ; +p2m_load_VTTBR (d); + +/* Make sure that all TLBs corresponding to the new VMID are flushed +* before using it +*/ +flush_tlb (); + +p2m_load_VTTBR (current->domain); +spin_unlock (&p2m->lock);return 0 ;
@@ -357,6 +366,7 @@ static void p2m_free_vmid(struct domain *d)spin_lock (&vmid_alloc_lock);if ( p2m->vmid !=INVALID_VMID )clear_bit (p2m->vmid, vmid_mask); +spin_unlock (&vmid_alloc_lock); }
xen/include/asm-arm/arm32/flushtlb.h +11 -0
@@ -12,6 +12,17 @@ static inline void flush_tlb_local(void)isb (); } +/* Flush inner shareable TLBs, current VMID only */ +static inline void flush_tlb (void ) +{ +dsb (); + +WRITE_CP32 ((uint32_t )0 ,TLBIALLIS ); + +dsb (); +isb (); +} +/* Flush local TLBs, all VMIDs, non-hypervisor mode */ static inline void flush_tlb_all_local (void ) {
xen/include/asm-arm/arm64/flushtlb.h +11 -0
@@ -12,6 +12,17 @@ static inline void flush_tlb_local(void) : : : "memory"); } +/* Flush innershareable TLBs, current VMID only */ +static inline void flush_tlb (void ) +{ + asmvolatile ( +"dsb sy;" +"tlbi vmalle1is;" +"dsb sy;" +"isb;" + : : :"memory" ); +} +/* Flush local TLBs, all VMIDs, non-hypervisor mode */ static inline void flush_tlb_all_local (void ) {
Signature · 1 line
1.8.3.1
Quoted 55 lines · Julien Grall
Once the VMID is marked unused, a new domain can reuse the VMID for its own. If the TLB is not flushed, entries can contain wrong translation. When a new p2m is allocated, switch to the new VMID and flush TLB on every physical CPUs.
Signed-off-by Julien Grall <[email protected]>---
Changes in v2:
- This patch was formerly "xen/arm: p2m: flush TLB when a domain is destroyed
- Flush TLB by VMID inp2m_alloc_table. It will avoid to flush all TLBs every domain destruction.--- xen/arch/arm/p2m.c | 10 ++++++++++ xen/include/asm-arm/arm32/flushtlb.h | 11 +++++++++++ xen/include/asm-arm/arm64/flushtlb.h | 11 +++++++++++ 3 files changed, 32 insertions(+)xen/arch/arm/p2m.c +10
-0@@ -302,6 +302,15 @@ int p2m_alloc_table(struct domain *d) d->arch.vttbr =page_to_maddr (p2m->first_level) | ((uint64_t )p2m->vmid&0xff )<<48 ; +p2m_load_VTTBR (d); + +/* Make sure that all TLBs corresponding to the new VMID are flushed +* before using it +*/ +flush_tlb (); + +p2m_load_VTTBR (current->domain); +spin_unlock (&p2m->lock);return 0 ;@@ -357,6 +366,7 @@ static void p2m_free_vmid(struct domain *d)spin_lock (&vmid_alloc_lock);if ( p2m->vmid !=INVALID_VMID )clear_bit (p2m->vmid, vmid_mask); +spin_unlock (&vmid_alloc_lock); }xen/include/asm-arm/arm32/flushtlb.h +0
-0@@ -12,6 +12,17 @@ static inline void flush_tlb_local(void)isb (); }
xen/include/asm-arm/arm32/flushtlb.h static inline void flush_tlb_local(void) · line 24
Quoted 10 lines
xen/include/asm-arm/arm32/flushtlb.h +10
-0+/* Flush inner shareable TLBs, current VMID only */ +static inline void flush_tlb (void ) +{ +dsb (); + +WRITE_CP32 ((uint32_t )0 ,TLBIALLIS ); + +dsb (); +isb (); +}
Why only inner shareable? Shouldn't we use the existing flush_tlb_local instead?
Quoted 4 lines · Stefano Stabellini
Why only inner shareable? Shouldn't we use the existing
flush_tlb_localinstead?
As I understand TLBIALL is only to flush TLB on the local processor, rather than TLBIALLIS which is used to broadcast on all processor.
So here we need to flush on every processor TLBs by VMID.
--
Julien Grall
Stefano Stabellini
Acked-byQuoted 10 lines · Julien Grall
Quoted 4 lines · Stefano Stabellini
Why only inner shareable? Shouldn't we use the existing
flush_tlb_localinstead?As I understand TLBIALL is only to flush TLB on the local processor, rather than TLBIALLIS which is used to broadcast on all processor.
So here we need to flush on every processor TLBs by VMID.
Right, sorry, my mistake.
Quoted 7 lines · Stefano Stabellini
Quoted 6 lines · Julien Grall
Quoted 4 lines · Stefano Stabellini
Why only inner shareable? Shouldn't we use the existing
flush_tlb_localinstead?
Quoted 8 lines
Quoted 4 lines
As I understand TLBIALL is only to flush TLB on the local processor, rather than TLBIALLIS which is used to broadcast on all processor.
So here we need to flush on every processor TLBs by VMID.
Right, sorry, my mistake.
Agreed, + committed.