Skip to contentSkip to conversation

arm64: tlbflush: Add some comments for TLB batched flushing

PATCH Superseded Yicong Yang 3 participants 3 messages Jul 29, 2023 – Aug 1, 2023

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64: tlbflush: Add some comments for TLB batched flushing

From: Yicong Yang <[email protected]>

Add comments for arch_flush_tlb_batched_pending() and arch_tlbbatch_flush() to illustrate why only a DSB is needed.

Cc Catalin Marinas <[email protected]>
---
 arch/arm64/include/asm/tlbflush.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
arch/arm64/include/asm/tlbflush.h +15 -0
index 3456866c6a1d..2bad230b95b4 100644
@@ -300,11 +300,26 @@ static inline void arch_tlbbatch_add_pending(struct arch_tlbflush_unmap_batch *b
 	__flush_tlb_page_nosync(mm, uaddr);
 }
 
+/*
+ * If mprotect/munmap/etc occurs during TLB batched flushing, we need to
+ * synchronise all the TLBI issued by a DSB to avoid the race mentioned in
+ * flush_tlb_batched_pending().
+ */
 static inline void arch_flush_tlb_batched_pending(struct mm_struct *mm)
 {
 	dsb(ish);
 }
 
+/*
+ * To support TLB batched flush for multiple pages unmapping, we only send
+ * the TLBI for each page in arch_tlbbatch_add_pending() and wait for the
+ * completion at the end in arch_tlbbatch_flush(). Since we've already issued
+ * TLBI for each page so only a DSB is needed to synchronise its effect on the
+ * other CPUs.
+ *
+ * This will save the time waiting on DSB comparing issuing a TLBI;DSB sequence
+ * for each page.
+ */
 static inline void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch)
 {
 	dsb(ish);
Signature · 1 line
2.24.0
maintainer Reviewed-by on v1 1/1
#1 lore raw

arch/arm64/include/asm/tlbflush.h static inline void arch_tlbbatch_add_pending(struct arch_tlbflush_unmap_batch *b · line 305

Quoted 11 lines · Yicong Yang
arch/arm64/include/asm/tlbflush.h +3 -0
index 3456866c6a1d..2bad230b95b4 100644
@@ -300,11 +300,26 @@ static inline void arch_tlbbatch_add_pending(struct arch_tlbflush_unmap_batch *b
 	__flush_tlb_page_nosync(mm, uaddr);
 }
 
+/*
+ * If mprotect/munmap/etc occurs during TLB batched flushing, we need to
+ * synchronise all the TLBI issued by a DSB to avoid the race mentioned in

Nitpick: s/by a DSB/with a DSB/ as it somehow reads that the DSB issued the TLBI.

Since the rest of the series went in via the mm tree, I assume Andrew will pick this up as well.

Thanks.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Yicong Yang

Yicong Yang <[email protected]> writes:

Thanks! I was reading this code the other day and it took me a while to figure out what was going on. These comments would have been very helpful and match my understanding, so:

Quoted 43 lines

From: Yicong Yang <[email protected]>

Add comments for arch_flush_tlb_batched_pending() and arch_tlbbatch_flush() to illustrate why only a DSB is needed.

Cc Catalin Marinas <[email protected]>
---
 arch/arm64/include/asm/tlbflush.h | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
arch/arm64/include/asm/tlbflush.h +15 -0
index 3456866c6a1d..2bad230b95b4 100644
@@ -300,11 +300,26 @@ static inline void arch_tlbbatch_add_pending(struct arch_tlbflush_unmap_batch *b
 	__flush_tlb_page_nosync(mm, uaddr);
 }
 
+/*
+ * If mprotect/munmap/etc occurs during TLB batched flushing, we need to
+ * synchronise all the TLBI issued by a DSB to avoid the race mentioned in
+ * flush_tlb_batched_pending().
+ */
 static inline void arch_flush_tlb_batched_pending(struct mm_struct *mm)
 {
 	dsb(ish);
 }
 
+/*
+ * To support TLB batched flush for multiple pages unmapping, we only send
+ * the TLBI for each page in arch_tlbbatch_add_pending() and wait for the
+ * completion at the end in arch_tlbbatch_flush(). Since we've already issued
+ * TLBI for each page so only a DSB is needed to synchronise its effect on the
+ * other CPUs.
+ *
+ * This will save the time waiting on DSB comparing issuing a TLBI;DSB sequence
+ * for each page.
+ */
 static inline void arch_tlbbatch_flush(struct arch_tlbflush_unmap_batch *batch)
 {
 	dsb(ish);