sparc64: Define p4d_page() instead of stubbing it to NULL
PATCH 1/1 sparc64: Define p4d_page() instead of stubbing it to NULL
A sparc64 allmodconfig build with LLVM fails in vmalloc_to_page():
mm/vmalloc.c: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic]
sparc64 defines p4d_page() as NULL, on the assumption that it is only used by stubbed out hugetlb gup code. Generic code now uses it in vmalloc_to_page(), ptdump and KASAN. In vmalloc_to_page() the NULL is used in pointer arithmetic, which clang diagnoses even though the branch is unreachable on sparc64.
Define p4d_page() in terms of p4d_pgtable(), the same way pud_page() is defined in terms of pud_pgtable(). sparc64 has no p4d leaf mappings, so there is no functional change.
--- arch/sparc/include/asm/pgtable_64.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
arch/sparc/include/asm/pgtable_64.h +1 -2
@@ -850,8 +850,7 @@ static inline pmd_t *pud_pgtable(pud_t pud)#define p4d_present (p4d) (p4d_val(p4d) != 0U)#define p4d_clear (p4dp) (p4d_val(*(p4dp)) = 0UL) -/* only used by the stubbed out hugetlb gup code, should never be called */ -#define p4d_page (p4d) NULL +#define p4d_page (p4d) virt_to_page((void *)p4d_pgtable(p4d))#define pud_leaf pud_leafstatic inline bool pud_leaf (pud_t pud)
Signature · 1 line
2.56.0
Quoted 12 lines · Rosen Penev
A sparc64 allmodconfig build with LLVM fails in
vmalloc_to_page():
mm/vmalloc.c: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic]sparc64 defines
p4d_page()as NULL, on the assumption that it is only used by stubbed out hugetlb gup code. Generic code now uses it invmalloc_to_page(), ptdump and KASAN. Invmalloc_to_page()the NULL is used in pointer arithmetic, which clang diagnoses even though the branch is unreachable on sparc64.
Has this been reported as a bug to the clang project? As it throwing an error on a rather obviously unreachable branch.
Best regards,
Kjetil Oftedal
Quoted 14 lines · Kjetil Oftedal
Quoted 12 lines · Rosen Penev
A sparc64 allmodconfig build with LLVM fails in
vmalloc_to_page():
mm/vmalloc.c: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic]sparc64 defines
p4d_page()as NULL, on the assumption that it is only used by stubbed out hugetlb gup code. Generic code now uses it invmalloc_to_page(), ptdump and KASAN. Invmalloc_to_page()the NULL is used in pointer arithmetic, which clang diagnoses even though the branch is unreachable on sparc64.
Quoted 2 lines
Has this been reported as a bug to the clang project? As it throwing an error on a rather obviously unreachable branch.
Technically the error part is self-inflicted on the part of the kernel since allmodconfig enables CONFIG_WERROR. That said, while it might be nice for the compiler not to warn in any case of dead code, that's just not how it works for either GCC or clang (none of these should be visible if that were the case):
https://godbolt.org/z/K3nfW4n5f
Signature · 2 lines
Cheers, Nathan
Quoted 16 lines · Nathan Chancellor
Quoted 14 lines · Kjetil Oftedal
Quoted 12 lines · Rosen Penev
A sparc64 allmodconfig build with LLVM fails in
vmalloc_to_page():
mm/vmalloc.c: error: performing pointer arithmetic on a null pointer has undefined behavior [-Werror,-Wnull-pointer-arithmetic]sparc64 defines
p4d_page()as NULL, on the assumption that it is only used by stubbed out hugetlb gup code. Generic code now uses it invmalloc_to_page(), ptdump and KASAN. Invmalloc_to_page()the NULL is used in pointer arithmetic, which clang diagnoses even though the branch is unreachable on sparc64.
Quoted 8 lines
Quoted 2 lines
Has this been reported as a bug to the clang project? As it throwing an error on a rather obviously unreachable branch.
Technically the error part is self-inflicted on the part of the kernel since allmodconfig enables
CONFIG_WERROR. That said, while it might be nice for the compiler not to warn in any case of dead code, that's just not how it works for either GCC or clang (none of these should be visible if that were the case):
LLM suggests as an alternative:
/* sparc64 has no p4d leaf mappings, so this is never called */ static inline struct page *p4d_page(p4d_t p4d)
{
return NULL;
}Not sure how to proceed.
Quoted 5 lines
https://godbolt.org/z/K3nfW4n5f
--
Cheers,
Nathan
Quoted 9 lines · Rosen Penev
LLM suggests as an alternative:
/* sparc64 has no p4d leaf mappings, so this is never called */ static inline struct page *p4d_page(p4d_t p4d)
{ return NULL; }Not sure how to proceed.
That seems like a more reasonable fix to me, as it is still obvious this is not supported while hiding the NULL value from clang's frontend that emits the warning. It could be worth a comment that it is an inline function and not a macro to avoid the warning but I guess that is up to the sparc maintainers.
Signature · 2 lines
Cheers, Nathan
Andreas Larsson
maintainerQuoted 9 lines · Nathan Chancellor
Quoted 8 lines · Rosen Penev
LLM suggests as an alternative:
/* sparc64 has no p4d leaf mappings, so this is never called */ static inline struct page *p4d_page(p4d_t p4d)
{ return NULL; }
Quoted 7 lines
Quoted 1 line
Not sure how to proceed.
That seems like a more reasonable fix to me, as it is still obvious this is not supported while hiding the NULL value from clang's frontend that emits the warning. It could be worth a comment that it is an inline function and not a macro to avoid the warning but I guess that is up to the sparc maintainers.
I agree, including comment.
Regarding "ptdump and KASAN" in the commit message, while true, both these are locked behind KASAN which is not supported by sparc64.
Cheers,
Andreas