Skip to content

Commit 9632dd9

Browse files
Anthony Yznagagregkh
authored andcommitted
sparc64: fix hugetlb for sun4u
commit 6fd44a4 upstream. An attempt to exercise sparc hugetlb code in a sun4u-based guest running under qemu results in the guest hanging due to being stuck in a trap loop. This is due to invalid hugetlb TTEs being installed that do not have the expected _PAGE_PMD_HUGE and page size bits set. Although the breakage has gone apparently unnoticed for several years, fix it now so there is the option to exercise sparc hugetlb code under qemu. This can be useful because sun4v support in qemu does not support linux guests currently and sun4v-based hardware resources may not be readily available. Fix tested with a 6.15.2 and 6.16-rc6 kernels by running libhugetlbfs tests on a qemu guest running Debian 13. Fixes: c7d9f77 ("sparc64: Multi-page size support") Cc: stable@vger.kernel.org Signed-off-by: Anthony Yznaga <anthony.yznaga@oracle.com> Tested-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> Reviewed-by: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> Reviewed-by: Andreas Larsson <andreas@gaisler.com> Link: https://lore.kernel.org/r/20250716012446.10357-1-anthony.yznaga@oracle.com Signed-off-by: Andreas Larsson <andreas@gaisler.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 8019b36 commit 9632dd9

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

arch/sparc/mm/hugetlbpage.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
130130

131131
static pte_t sun4u_hugepage_shift_to_tte(pte_t entry, unsigned int shift)
132132
{
133+
unsigned long hugepage_size = _PAGE_SZ4MB_4U;
134+
135+
pte_val(entry) = pte_val(entry) & ~_PAGE_SZALL_4U;
136+
137+
switch (shift) {
138+
case HPAGE_256MB_SHIFT:
139+
hugepage_size = _PAGE_SZ256MB_4U;
140+
pte_val(entry) |= _PAGE_PMD_HUGE;
141+
break;
142+
case HPAGE_SHIFT:
143+
pte_val(entry) |= _PAGE_PMD_HUGE;
144+
break;
145+
case HPAGE_64K_SHIFT:
146+
hugepage_size = _PAGE_SZ64K_4U;
147+
break;
148+
default:
149+
WARN_ONCE(1, "unsupported hugepage shift=%u\n", shift);
150+
}
151+
152+
pte_val(entry) = pte_val(entry) | hugepage_size;
133153
return entry;
134154
}
135155

0 commit comments

Comments
 (0)