Skip to content

Commit 1de195d

Browse files
Alexandre Ghitiakpm00
authored andcommitted
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/[email protected] Fixes: 82a1a1f ("riscv: mm: support Svnapot in hugetlb page") Signed-off-by: Alexandre Ghiti <[email protected]> Reported-by: Ryan Roberts <[email protected]> Closes: https://lore.kernel.org/linux-arm-kernel/[email protected]/ [1] Reviewed-by: Andrew Jones <[email protected]> Cc: Albert Ou <[email protected]> Cc: Palmer Dabbelt <[email protected]> Cc: Paul Walmsley <[email protected]> Cc: Qinglin Pan <[email protected]> Cc: Conor Dooley <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent 117b1bb commit 1de195d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

arch/riscv/mm/hugetlbpage.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,22 @@ void set_huge_pte_at(struct mm_struct *mm,
183183
pte_t pte,
184184
unsigned long sz)
185185
{
186+
unsigned long hugepage_shift;
186187
int i, pte_num;
187188

188-
if (!pte_napot(pte)) {
189-
set_pte_at(mm, addr, ptep, pte);
190-
return;
191-
}
189+
if (sz >= PGDIR_SIZE)
190+
hugepage_shift = PGDIR_SHIFT;
191+
else if (sz >= P4D_SIZE)
192+
hugepage_shift = P4D_SHIFT;
193+
else if (sz >= PUD_SIZE)
194+
hugepage_shift = PUD_SHIFT;
195+
else if (sz >= PMD_SIZE)
196+
hugepage_shift = PMD_SHIFT;
197+
else
198+
hugepage_shift = PAGE_SHIFT;
192199

193-
pte_num = napot_pte_num(napot_cont_order(pte));
194-
for (i = 0; i < pte_num; i++, ptep++, addr += PAGE_SIZE)
200+
pte_num = sz >> hugepage_shift;
201+
for (i = 0; i < pte_num; i++, ptep++, addr += (1 << hugepage_shift))
195202
set_pte_at(mm, addr, ptep, pte);
196203
}
197204

0 commit comments

Comments
 (0)