xen/arm: p2m: flush tlb when a domain is destroyed
PATCH 1/1 xen/arm: p2m: flush tlb when a domain is destroyed
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. Arm assembly doesn't provide instruction to flush TLB by VMID, except for current VMID but the domain is already unscheduled from every physical CPUs. So flush TLB for all VMIDs on every CPU (inner shareable).
--- xen/arch/arm/p2m.c | 3 +++ xen/include/asm-arm/arm32/flushtlb.h | 11 +++++++++++ 2 files changed, 14 insertions(+)
xen/arch/arm/p2m.c +3 -0
@@ -357,6 +357,9 @@ static void p2m_free_vmid(struct domain *d)spin_lock (&vmid_alloc_lock);if ( p2m->vmid !=INVALID_VMID )clear_bit (p2m->vmid, vmid_mask); + +flush_tlb_all (); +spin_unlock (&vmid_alloc_lock); }
xen/include/asm-arm/arm32/flushtlb.h +11 -0
@@ -23,6 +23,17 @@ static inline void flush_tlb_all_local(void) isb(); } +/* Flush inner shareable TLBs, all VMIDs, non-hypervisor mode */ +static inline void flush_tlb_all (void ) +{ +dsb (); + +WRITE_CP32 ((uint32_t )0 ,TLBIALLNSNHIS ); + +dsb (); +isb (); +} +#endif /* __ASM_ARM_ARM32_FLUSHTLB_H__ */ /* * Local variables:
Signature · 1 line
1.7.10.4
Quoted 5 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. Arm assembly doesn't provide instruction to flush TLB by VMID, except for current VMID but the domain is already unscheduled from every physical CPUs. So flush TLB for all VMIDs on every CPU (inner shareable).
Did you consider temporarily switching to the VMID in order to flush it? Or flushing on allocate rather than free or flushing when the p2m is first loaded (via a hook in p2m_load_vttbr)?
xen/include/asm-arm/arm32/flushtlb.h
Quoted 25 lines
Signed-off-by Julien Grall <[email protected]>--- xen/arch/arm/p2m.c | 3 +++ xen/include/asm-arm/arm32/flushtlb.h | 11 +++++++++++ 2 files changed, 14 insertions(+)xen/arch/arm/p2m.c +3
-0@@ -357,6 +357,9 @@ static void p2m_free_vmid(struct domain *d)spin_lock (&vmid_alloc_lock);if ( p2m->vmid !=INVALID_VMID )clear_bit (p2m->vmid, vmid_mask); + +flush_tlb_all (); +spin_unlock (&vmid_alloc_lock); }xen/include/asm-arm/arm32/flushtlb.h +0
-0
This needs an arm64 version too.
xen/include/asm-arm/arm32/flushtlb.h static inline void flush_tlb_all_local(void) · line 31
Quoted 10 lines
xen/include/asm-arm/arm32/flushtlb.h +6
-0@@ -23,6 +23,17 @@ static inline void flush_tlb_all_local(void)isb (); } +/* Flush inner shareable TLBs, all VMIDs, non-hypervisor mode */ +static inline void flush_tlb_all (void ) +{ +dsb (); + +WRITE_CP32 ((uint32_t )0 ,TLBIALLNSNHIS );
Is the cast really necessary? I'd have thought that at the very most 0U would be all that was needed.
Quoted 8 lines
xen/include/asm-arm/arm32/flushtlb.h +5
-0+ +dsb (); + isb(); +} +#endif /* __ASM_ARM_ARM32_FLUSHTLB_H__ */ /* * Local variables: