]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
sparc64: fix hugetlb for sun4u
authorAnthony Yznaga <anthony.yznaga@oracle.com>
Wed, 16 Jul 2025 01:24:46 +0000 (18:24 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 19 Oct 2025 14:33:53 +0000 (16:33 +0200)
commit 6fd44a481b3c6111e4801cec964627791d0f3ec5 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: c7d9f77d33a7 ("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>
arch/sparc/mm/hugetlbpage.c

index c276d70a7479951994edb6e8aec384f9cfea1470..305f191ba81b1d3ab1f1505705bab2903019f96b 100644 (file)
@@ -130,6 +130,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
 
 static pte_t sun4u_hugepage_shift_to_tte(pte_t entry, unsigned int shift)
 {
+       unsigned long hugepage_size = _PAGE_SZ4MB_4U;
+
+       pte_val(entry) = pte_val(entry) & ~_PAGE_SZALL_4U;
+
+       switch (shift) {
+       case HPAGE_256MB_SHIFT:
+               hugepage_size = _PAGE_SZ256MB_4U;
+               pte_val(entry) |= _PAGE_PMD_HUGE;
+               break;
+       case HPAGE_SHIFT:
+               pte_val(entry) |= _PAGE_PMD_HUGE;
+               break;
+       case HPAGE_64K_SHIFT:
+               hugepage_size = _PAGE_SZ64K_4U;
+               break;
+       default:
+               WARN_ONCE(1, "unsupported hugepage shift=%u\n", shift);
+       }
+
+       pte_val(entry) = pte_val(entry) | hugepage_size;
        return entry;
 }