Commit 1de195dd authored by Alexandre Ghiti's avatar Alexandre Ghiti Committed by Andrew Morton
Browse files

riscv: fix set_huge_pte_at() for NAPOT mappings when a swap entry is set

We used to determine the number of page table entries to set for a NAPOT
hugepage by using the pte value which actually fails when the pte to set
is a swap entry.

So take advantage of a recent fix for arm64 reported in [1] which
introduces the size of the mapping as an argument of set_huge_pte_at(): we
can then use this size to compute the number of page table entries to set
for a NAPOT region.

Link: https://lkml.kernel.org/r/20230928151846.8229-3-alexghiti@rivosinc.com


Fixes: 82a1a1f3 ("riscv: mm: support Svnapot in hugetlb page")
Signed-off-by: default avatarAlexandre Ghiti <alexghiti@rivosinc.com>
Reported-by: default avatarRyan Roberts <ryan.roberts@arm.com>
Closes: https://lore.kernel.org/linux-arm-kernel/20230922115804.2043771-1-ryan.roberts@arm.com/

 [1]
Reviewed-by: default avatarAndrew Jones <ajones@ventanamicro.com>
Cc: Albert Ou <aou@eecs.berkeley.edu>
Cc: Palmer Dabbelt <palmer@dabbelt.com>
Cc: Paul Walmsley <paul.walmsley@sifive.com>
Cc: Qinglin Pan <panqinglin2020@iscas.ac.cn>
Cc: Conor Dooley <conor@kernel.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
parent 117b1bb0
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -183,15 +183,22 @@ void set_huge_pte_at(struct mm_struct *mm,
		     pte_t pte,
		     unsigned long sz)
{
	unsigned long hugepage_shift;
	int i, pte_num;

	if (!pte_napot(pte)) {
		set_pte_at(mm, addr, ptep, pte);
		return;
	}
	if (sz >= PGDIR_SIZE)
		hugepage_shift = PGDIR_SHIFT;
	else if (sz >= P4D_SIZE)
		hugepage_shift = P4D_SHIFT;
	else if (sz >= PUD_SIZE)
		hugepage_shift = PUD_SHIFT;
	else if (sz >= PMD_SIZE)
		hugepage_shift = PMD_SHIFT;
	else
		hugepage_shift = PAGE_SHIFT;

	pte_num = napot_pte_num(napot_cont_order(pte));
	for (i = 0; i < pte_num; i++, ptep++, addr += PAGE_SIZE)
	pte_num = sz >> hugepage_shift;
	for (i = 0; i < pte_num; i++, ptep++, addr += (1 << hugepage_shift))
		set_pte_at(mm, addr, ptep, pte);
}