Skip to contentSkip to conversation

arm64/mm: Optimize TLB flush in unmap_hotplug_[pmd|pud]_range()

PATCH Applied Anshuman Khandual 4 participants 5 messages Jun 26 – Jun 29 arm64

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 arm64/mm: Optimize TLB flush in unmap_hotplug_[pmd|pud]_range()

flush_tlb_kernel_range() could flush down an entire block mapping just with a single PAGE_SIZE stride. This capability was being used umapping PMD and PUD based block mappings in unmap_hotplug_[pmd|pud]_range().

But later on the commit 48478b9f7913
("arm64/mm: Enable batched TLB flush in unmap_hotplug_range()") replaced this PAGE_SIZE stride with [PMD|PUD]_SIZE strides, hence forcing multiple PAGE_SIZE stride based TLB flushes on platforms where TLB range operation is not supported. Revert back to the earlier TLB behaviour along with the required comments that were dropped earlier.

Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc David Hildenbrand <[email protected]>
Fixes 48478b9f7913 ("arm64/mm: Enable batched TLB flush in unmap_hotplug_range()")
---
 arch/arm64/mm/mmu.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
arch/arm64/mm/mmu.c +10 -2
index 8242f93f05e4..5ff0041f4a5f 100644
@@ -1509,7 +1509,11 @@ static void unmap_hotplug_pmd_range(pud_t *pudp, unsigned long addr,
 			if (free_mapped) {
 				/* CONT blocks are not supported in the vmemmap */
 				WARN_ON(pmd_cont(pmd));
-				flush_tlb_kernel_range(addr, addr + PMD_SIZE);
+				/*
+				 * One TLBI should be sufficient here as the PMD_SIZE
+				 * range is mapped with a single block entry.
+				 */
+				flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
 				free_hotplug_page_range(pmd_page(pmd),
 							PMD_SIZE, altmap);
 			}
@@ -1539,7 +1543,11 @@ static void unmap_hotplug_pud_range(p4d_t *p4dp, unsigned long addr,
 		if (pud_leaf(pud)) {
 			pud_clear(pudp);
 			if (free_mapped) {
-				flush_tlb_kernel_range(addr, addr + PUD_SIZE);
+				/*
+				 * One TLBI should be sufficient here as the PUD_SIZE
+				 * range is mapped with a single block entry.
+				 */
+				flush_tlb_kernel_range(addr, addr + PAGE_SIZE);
 				free_hotplug_page_range(pud_page(pud),
 							PUD_SIZE, altmap);
 			}
Signature · 1 line
2.30.2
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 11 lines · Anshuman Khandual

flush_tlb_kernel_range() could flush down an entire block mapping just with a single PAGE_SIZE stride. This capability was being used umapping PMD and PUD based block mappings in unmap_hotplug_[pmd|pud]_range().

But later on the commit 48478b9f7913
("arm64/mm: Enable batched TLB flush in unmap_hotplug_range()") replaced this PAGE_SIZE stride with [PMD|PUD]_SIZE strides, hence forcing multiple PAGE_SIZE stride based TLB flushes on platforms where TLB range operation is not supported. Revert back to the earlier TLB behaviour along with the required comments that were dropped earlier.

Quoted 10 lines
Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc David Hildenbrand <[email protected]>
Fixes 48478b9f7913 ("arm64/mm: Enable batched TLB flush in unmap_hotplug_range()")
Reviewed-by on v1 1/1
#2 lore raw
In reply to Anshuman Khandual
Quoted 11 lines · Anshuman Khandual

flush_tlb_kernel_range() could flush down an entire block mapping just with a single PAGE_SIZE stride. This capability was being used umapping PMD and PUD based block mappings in unmap_hotplug_[pmd|pud]_range().

But later on the commit 48478b9f7913
("arm64/mm: Enable batched TLB flush in unmap_hotplug_range()") replaced this PAGE_SIZE stride with [PMD|PUD]_SIZE strides, hence forcing multiple PAGE_SIZE stride based TLB flushes on platforms where TLB range operation is not supported. Revert back to the earlier TLB behaviour along with the required comments that were dropped earlier.

Right, it looked like the right thing to do in that commit. I wonder if we can make the comments even clearer to prevent his happening another time, incorporating the HW consideration.

In any case

Quoted 19 lines
Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc David Hildenbrand <[email protected]>
Fixes 48478b9f7913 ("arm64/mm: Enable batched TLB flush in unmap_hotplug_range()")
---
 arch/arm64/mm/mmu.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
arch/arm64/mm/mmu.c +0 -0
index 8242f93f05e4..5ff0041f4a5f 100644

arch/arm64/mm/mmu.c static void unmap_hotplug_pmd_range(pud_t *pudp, unsigned long addr, · line 1515

Quoted 8 lines
arch/arm64/mm/mmu.c +4 -1
@@ -1509,7 +1509,11 @@ static void unmap_hotplug_pmd_range(pud_t *pudp, unsigned long addr,
 			if (free_mapped) {
 				/* CONT blocks are not supported in the vmemmap */
 				WARN_ON(pmd_cont(pmd));
-				flush_tlb_kernel_range(addr, addr + PMD_SIZE);
+				/*
+				 * One TLBI should be sufficient here as the PMD_SIZE
+				 * range is mapped with a single block entry.
+				 */

"Flush only a single page, resulting in a single TLBi for this large block mapping, avoiding multiple TLBIs on HW without TLB range flushes."

Signature · 3 lines
Cheers,

David
maintainer
#3 lore raw
Quoted 35 lines · David Hildenbrand (Arm)
Quoted 11 lines · Anshuman Khandual

flush_tlb_kernel_range() could flush down an entire block mapping just with a single PAGE_SIZE stride. This capability was being used umapping PMD and PUD based block mappings in unmap_hotplug_[pmd|pud]_range().

But later on the commit 48478b9f7913
("arm64/mm: Enable batched TLB flush in unmap_hotplug_range()") replaced this PAGE_SIZE stride with [PMD|PUD]_SIZE strides, hence forcing multiple PAGE_SIZE stride based TLB flushes on platforms where TLB range operation is not supported. Revert back to the earlier TLB behaviour along with the required comments that were dropped earlier.

Right, it looked like the right thing to do in that commit. I wonder if we can make the comments even clearer to prevent his happening another time, incorporating the HW consideration.

In any case

Quoted 14 lines
Cc Catalin Marinas <[email protected]>
Cc Will Deacon <[email protected]>
Cc Ryan Roberts <[email protected]>
Cc David Hildenbrand <[email protected]>
Fixes 48478b9f7913 ("arm64/mm: Enable batched TLB flush in unmap_hotplug_range()")
---
 arch/arm64/mm/mmu.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
Quoted 16 lines

arch/arm64/mm/mmu.c static void unmap_hotplug_pmd_range(pud_t *pudp, unsigned long addr, · line 1515

Quoted 13 lines
arch/arm64/mm/mmu.c +4 -1
index 8242f93f05e4..5ff0041f4a5f 100644
@@ -1509,7 +1509,11 @@ static void unmap_hotplug_pmd_range(pud_t *pudp, unsigned long addr,
 			if (free_mapped) {
 				/* CONT blocks are not supported in the vmemmap */
 				WARN_ON(pmd_cont(pmd));
-				flush_tlb_kernel_range(addr, addr + PMD_SIZE);
+				/*
+				 * One TLBI should be sufficient here as the PMD_SIZE
+				 * range is mapped with a single block entry.
+				 */

"Flush only a single page, resulting in a single TLBi for this large block mapping, avoiding multiple TLBIs on HW without TLB range flushes."

I'll add something like this when applying and I'll rewrite the commit message as well.

Cheers,

Will

maintainer Applied
#4 lore raw
In reply to Anshuman Khandual
Quoted 4 lines · Anshuman Khandual

flush_tlb_kernel_range() could flush down an entire block mapping just with a single PAGE_SIZE stride. This capability was being used umapping PMD and PUD based block mappings in unmap_hotplug_[pmd|pud]_range().

Quoted 8 lines

But later on the commit 48478b9f7913
("arm64/mm: Enable batched TLB flush in unmap_hotplug_range()") replaced this PAGE_SIZE stride with [PMD|PUD]_SIZE strides, hence forcing multiple PAGE_SIZE stride based TLB flushes on platforms where TLB range operation is not supported. Revert back to the earlier TLB behaviour along with the required comments that were dropped earlier.

[...]

Applied to arm64 (for-next/fixes), thanks!

[1/1] arm64/mm: Optimize TLB flush in unmap_hotplug_[pmd|pud]_range()

      https://git.kernel.org/arm64/c/ff4c5a0de1f2

Cheers,

Signature · 5 lines
Will

https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev