Skip to content

Commit 04f7ce3

Browse files
gerald-schaefertorvalds
authored andcommitted
mm/debug_vm_pgtable: fix alignment for pmd/pud_advanced_tests()
In pmd/pud_advanced_tests(), the vaddr is aligned up to the next pmd/pud entry, and so it does not match the given pmdp/pudp and (aligned down) pfn any more. For s390, this results in memory corruption, because the IDTE instruction used e.g. in xxx_get_and_clear() will take the vaddr for some calculations, in combination with the given pmdp. It will then end up with a wrong table origin, ending on ...ff8, and some of those wrongly set low-order bits will also select a wrong pagetable level for the index addition. IDTE could therefore invalidate (or 0x20) something outside of the page tables, depending on the wrongly picked index, which in turn depends on the random vaddr. As result, we sometimes see "BUG task_struct (Not tainted): Padding overwritten" on s390, where one 0x5a padding value got overwritten with 0x7a. Fix this by aligning down, similar to how the pmd/pud_aligned pfns are calculated. Link: https://lkml.kernel.org/r/20210525130043.186290-2-gerald.schaefer@linux.ibm.com Fixes: a5c3b9f ("mm/debug_vm_pgtable: add tests validating advanced arch page table helpers") Signed-off-by: Gerald Schaefer <gerald.schaefer@linux.ibm.com> Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com> Cc: Vineet Gupta <vgupta@synopsys.com> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Paul Walmsley <paul.walmsley@sifive.com> Cc: <stable@vger.kernel.org> [5.9+] Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 0711f0d commit 04f7ce3

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

mm/debug_vm_pgtable.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static void __init pmd_advanced_tests(struct mm_struct *mm,
192192

193193
pr_debug("Validating PMD advanced\n");
194194
/* Align the address wrt HPAGE_PMD_SIZE */
195-
vaddr = (vaddr & HPAGE_PMD_MASK) + HPAGE_PMD_SIZE;
195+
vaddr &= HPAGE_PMD_MASK;
196196

197197
pgtable_trans_huge_deposit(mm, pmdp, pgtable);
198198

@@ -330,7 +330,7 @@ static void __init pud_advanced_tests(struct mm_struct *mm,
330330

331331
pr_debug("Validating PUD advanced\n");
332332
/* Align the address wrt HPAGE_PUD_SIZE */
333-
vaddr = (vaddr & HPAGE_PUD_MASK) + HPAGE_PUD_SIZE;
333+
vaddr &= HPAGE_PUD_MASK;
334334

335335
set_pud_at(mm, vaddr, pudp, pud);
336336
pudp_set_wrprotect(mm, vaddr, pudp);

0 commit comments

Comments
 (0)