arm64: tlb: fix the TTL value of tlb_get_level
Subsystems (4)
PATCH 1/1 arm64: tlb: fix the TTL value of tlb_get_level
The TTL field indicates the level of page table walk holding the *leaf* entry for the address being invalidated. But currently, the TTL field may be set to an incorrent value in the following stack:
pte_free_tlb
__pte_free_tlb
tlb_remove_table
tlb_table_invalidate
tlb_flush_mmu_tlbonly
tlb_flushIn this case, we just want to flush a PTE page, but the tlb->cleared_pmds is set and we get tlb_level = 2 in the tlb_get_level() function. This may cause some unexpected problems.
This patch set the TTL field to 0 if tlb->freed_tables is set. The tlb->freed_tables indicates page table pages are freed, not the leaf entry.
--- arch/arm64/include/asm/tlb.h | 4 ++++ 1 file changed, 4 insertions(+)
arch/arm64/include/asm/tlb.h +4 -0
@@ -28,6 +28,10 @@ static void tlb_flush(struct mmu_gather *tlb);*/ static inline int tlb_get_level (struct mmu_gather *tlb) { +/* The TTL field is only valid for the leaf entry. */ +if (tlb->freed_tables) +return 0 ; +if (tlb->cleared_ptes && !(tlb->cleared_pmds || tlb->cleared_puds || tlb->cleared_p4ds))
Signature · 1 line
2.26.2
Will Deacon
maintainerQuoted 31 lines · Zhenyu Ye
The TTL field indicates the level of page table walk holding the *leaf* entry for the address being invalidated. But currently, the TTL field may be set to an incorrent value in the following stack:
pte_free_tlb__pte_free_tlb tlb_remove_table tlb_table_invalidate tlb_flush_mmu_tlbonly tlb_flushIn this case, we just want to flush a PTE page, but the
tlb->cleared_pmdsis set and we gettlb_level= 2 in thetlb_get_level()function. This may cause some unexpected problems.This patch set the TTL field to 0 if
tlb->freed_tablesis set. Thetlb->freed_tablesindicates page table pages are freed, not the leaf entry.Fixes c4ab2cbc1d87 ("arm64: tlb: Set the TTL field in flush_tlb_range")Reported-by ZhuRui <[email protected]>Signed-off-by Zhenyu Ye <[email protected]>--- arch/arm64/include/asm/tlb.h | 4 ++++ 1 file changed, 4 insertions(+)arch/arm64/include/asm/tlb.h +0
-0
arch/arm64/include/asm/tlb.h static void tlb_flush(struct mmu_gather *tlb); · line 37
Quoted 10 lines
arch/arm64/include/asm/tlb.h +4
-0@@ -28,6 +28,10 @@ static void tlb_flush(struct mmu_gather *tlb);*/ static inline int tlb_get_level (struct mmu_gather *tlb) { +/* The TTL field is only valid for the leaf entry. */ +if (tlb->freed_tables) +return 0 ; +if (tlb->cleared_ptes && !(tlb->cleared_pmds || tlb->cleared_puds || tlb->cleared_p4ds))
Thanks. I can't see a better way around this, so I'll queue the patch. The stage-2 page-table code looks ok afaict, but please can you check it too?
Cheers,
Will
Quoted 36 lines · Will Deacon
Quoted 35 lines · Zhenyu Ye
The TTL field indicates the level of page table walk holding the *leaf* entry for the address being invalidated. But currently, the TTL field may be set to an incorrent value in the following stack:
pte_free_tlb__pte_free_tlb tlb_remove_table tlb_table_invalidate tlb_flush_mmu_tlbonly tlb_flushIn this case, we just want to flush a PTE page, but the
tlb->cleared_pmdsis set and we gettlb_level= 2 in thetlb_get_level()function. This may cause some unexpected problems.This patch set the TTL field to 0 if
tlb->freed_tablesis set. Thetlb->freed_tablesindicates page table pages are freed, not the leaf entry.Fixes c4ab2cbc1d87 ("arm64: tlb: Set the TTL field in flush_tlb_range")Reported-by ZhuRui <[email protected]>Signed-off-by Zhenyu Ye <[email protected]>--- arch/arm64/include/asm/tlb.h | 4 ++++ 1 file changed, 4 insertions(+)arch/arm64/include/asm/tlb.h +1
-0@@ -28,6 +28,10 @@ static void tlb_flush(struct mmu_gather *tlb);*/ static inline int tlb_get_level (struct mmu_gather *tlb) { +/* The TTL field is only valid for the leaf entry. */
Quoted 8 lines
arch/arm64/include/asm/tlb.h static void tlb_flush(struct mmu_gather *tlb); · line 37
Quoted 6 lines
arch/arm64/include/asm/tlb.h +3
-0+if (tlb->freed_tables) +return 0 ; +if (tlb->cleared_ptes && !(tlb->cleared_pmds || tlb->cleared_puds || tlb->cleared_p4ds))Thanks. I can't see a better way around this, so I'll queue the patch.
If you haven't queued it already, feel free to add:
I'd also add:
Signature · 1 line
Catalin
Quoted 12 lines · Will Deacon
Quoted 11 lines · Zhenyu Ye
arch/arm64/include/asm/tlb.h +3
-0@@ -28,6 +28,10 @@ static void tlb_flush(struct mmu_gather *tlb);*/ static inline int tlb_get_level (struct mmu_gather *tlb) { +/* The TTL field is only valid for the leaf entry. */ +if (tlb->freed_tables) +return 0 ;
Quoted 8 lines
arch/arm64/include/asm/tlb.h static void tlb_flush(struct mmu_gather *tlb); · line 37
Quoted 4 lines
arch/arm64/include/asm/tlb.h +1
-0+if (tlb->cleared_ptes && !(tlb->cleared_pmds || tlb->cleared_puds || tlb->cleared_p4ds))Thanks. I can't see a better way around this, so I'll queue the patch. The stage-2 page-table code looks ok afaict, but please can you check it too?
The stage-2 page-table codes seem to be correct to me.
Thanks,
Zhenyu
Will Deacon
maintainerQuoted 22 lines · Zhenyu Ye
Quoted 12 lines · Will Deacon
Quoted 11 lines · Zhenyu Ye
arch/arm64/include/asm/tlb.h +3
-0@@ -28,6 +28,10 @@ static void tlb_flush(struct mmu_gather *tlb);*/ static inline int tlb_get_level (struct mmu_gather *tlb) { +/* The TTL field is only valid for the leaf entry. */ +if (tlb->freed_tables) +return 0 ;Quoted 8 lines
arch/arm64/include/asm/tlb.h static void tlb_flush(struct mmu_gather *tlb); · line 37
Quoted 4 lines
arch/arm64/include/asm/tlb.h +1
-0+if (tlb->cleared_ptes && !(tlb->cleared_pmds || tlb->cleared_puds || tlb->cleared_p4ds))Thanks. I can't see a better way around this, so I'll queue the patch. The stage-2 page-table code looks ok afaict, but please can you check it too?
Quoted 1 line
The stage-2 page-table codes seem to be correct to me.
Thanks for having a look.
Will
Quoted 4 lines · Zhenyu Ye
The TTL field indicates the level of page table walk holding the *leaf* entry for the address being invalidated. But currently, the TTL field may be set to an incorrent value in the following stack:
Quoted 8 lines
pte_free_tlb__pte_free_tlb tlb_remove_table tlb_table_invalidate tlb_flush_mmu_tlbonly tlb_flush[...]
Applied to arm64 (for-next/mm), thanks!
[1/1] arm64: tlb: fix the TTL value of tlb_get_level
https://git.kernel.org/arm64/c/52218fcd61cb
Cheers,
Signature · 5 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev