Skip to contentSkip to conversation

sparc64: Define p4d_page() instead of stubbing it to NULL

PATCH Superseded Rosen Penev 3 participants 5 messages Oct 8 – Oct 9 SPARC + UltraSPARC (sparc/sparc64)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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() as a NULL function to silence clang's warning on an unreachable branch. sparc64 has no p4d leaf mappings, so there is no functional change.

Assisted-by LLM

---
v2: use a NULL function instead.

 arch/sparc/include/asm/pgtable_64.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/include/asm/pgtable_64.h +1 -1
index 35a217bf6e5c..54e563eb0efd 100644
@@ -851,7 +851,7 @@ static inline pmd_t *pud_pgtable(pud_t pud)
 #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)			static inline struct page *p4d_page(p4d_t p4d) { return NULL; }
 
 #define pud_leaf pud_leaf
 static inline bool pud_leaf(pud_t pud)
Signature · 1 line
2.56.0
#1 lore raw
kernel test robot noticed the following build errors:

Hi Rosen,

kernel test robot noticed the following build errors:

[auto build test ERROR on v7.3-rc6]
[also build test ERROR on linus/master next-20261008]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rosen-Penev/sparc64-Define-p4d_page-instead-of-stubbing-it-to-NULL/20261008-121711
base:   v7.3-rc6
patch link:    https://lore.kernel.org/r/20261008191711.223236-1-rosenp%40gmail.com
patch subject: [PATCH v2] sparc64: Define p4d_page() instead of stubbing it to NULL
config: sparc64-defconfig (https://download.01.org/0day-ci/archive/20261009/[email protected]/config)
compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project 242243a5814307de825db3428662d67b064e2cbc)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261009/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> mm/vmalloc.c:849:10: error: expected expression
     849 |                 return p4d_page(*p4d) + ((addr & ~P4D_MASK) >> PAGE_SHIFT);
         |                        ^
   arch/sparc/include/asm/pgtable_64.h:864:25: note: expanded from macro 'p4d_page'
     864 | #define p4d_page(p4d)                   static inline struct page *p4d_page(p4d_t p4d) { return NULL; }
         |                                         ^

1 error generated.

vim +849 mm/vmalloc.c

73bdf0a60e607f Linus Torvalds    2008-10-15  816  
48667e7a43c1a1 Christoph Lameter 2008-02-04  817  /*
c0eb315ad9719e Nicholas Piggin   2021-04-29  818   * Walk a vmap address to the struct page it maps. Huge vmap mappings will
c0eb315ad9719e Nicholas Piggin   2021-04-29  819   * return the tail page that corresponds to the base page address, which
c0eb315ad9719e Nicholas Piggin   2021-04-29  820   * matches small vmap mappings.
48667e7a43c1a1 Christoph Lameter 2008-02-04  821   */
add688fbd32158 malc              2014-01-27  822  struct page *vmalloc_to_page(const void *vmalloc_addr)
48667e7a43c1a1 Christoph Lameter 2008-02-04  823  {
48667e7a43c1a1 Christoph Lameter 2008-02-04  824  	unsigned long addr = (unsigned long) vmalloc_addr;
add688fbd32158 malc              2014-01-27  825  	struct page *page = NULL;
48667e7a43c1a1 Christoph Lameter 2008-02-04  826  	pgd_t *pgd = pgd_offset_k(addr);
c2febafc67734a Kiryl Shutsemau   2017-03-09  827  	p4d_t *p4d;
c2febafc67734a Kiryl Shutsemau   2017-03-09  828  	pud_t *pud;
c2febafc67734a Kiryl Shutsemau   2017-03-09  829  	pmd_t *pmd;
c2febafc67734a Kiryl Shutsemau   2017-03-09  830  	pte_t *ptep, pte;
48667e7a43c1a1 Christoph Lameter 2008-02-04  831  
7aa413def76146 Ingo Molnar       2008-06-19  832  	/*
7aa413def76146 Ingo Molnar       2008-06-19  833  	 * XXX we might need to change this if we add VIRTUAL_BUG_ON for
7aa413def76146 Ingo Molnar       2008-06-19  834  	 * architectures that do not vmalloc module space
7aa413def76146 Ingo Molnar       2008-06-19  835  	 */
73bdf0a60e607f Linus Torvalds    2008-10-15  836  	VIRTUAL_BUG_ON(!is_vmalloc_or_module_addr(vmalloc_addr));
59ea746337c69f Jiri Slaby        2008-06-12  837  
c2febafc67734a Kiryl Shutsemau   2017-03-09  838  	if (pgd_none(*pgd))
c2febafc67734a Kiryl Shutsemau   2017-03-09  839  		return NULL;
c0eb315ad9719e Nicholas Piggin   2021-04-29  840  	if (WARN_ON_ONCE(pgd_leaf(*pgd)))
c0eb315ad9719e Nicholas Piggin   2021-04-29  841  		return NULL; /* XXX: no allowance for huge pgd */
c0eb315ad9719e Nicholas Piggin   2021-04-29  842  	if (WARN_ON_ONCE(pgd_bad(*pgd)))
c0eb315ad9719e Nicholas Piggin   2021-04-29  843  		return NULL;
c0eb315ad9719e Nicholas Piggin   2021-04-29  844  
c2febafc67734a Kiryl Shutsemau   2017-03-09  845  	p4d = p4d_offset(pgd, addr);
c2febafc67734a Kiryl Shutsemau   2017-03-09  846  	if (p4d_none(*p4d))
c2febafc67734a Kiryl Shutsemau   2017-03-09  847  		return NULL;
c0eb315ad9719e Nicholas Piggin   2021-04-29  848  	if (p4d_leaf(*p4d))
c0eb315ad9719e Nicholas Piggin   2021-04-29 @849  		return p4d_page(*p4d) + ((addr & ~P4D_MASK) >> PAGE_SHIFT);
c0eb315ad9719e Nicholas Piggin   2021-04-29  850  	if (WARN_ON_ONCE(p4d_bad(*p4d)))
c0eb315ad9719e Nicholas Piggin   2021-04-29  851  		return NULL;
029c54b0959957 Ard Biesheuvel    2017-06-23  852  
c0eb315ad9719e Nicholas Piggin   2021-04-29  853  	pud = pud_offset(p4d, addr);
c0eb315ad9719e Nicholas Piggin   2021-04-29  854  	if (pud_none(*pud))
c0eb315ad9719e Nicholas Piggin   2021-04-29  855  		return NULL;
c0eb315ad9719e Nicholas Piggin   2021-04-29  856  	if (pud_leaf(*pud))
c0eb315ad9719e Nicholas Piggin   2021-04-29  857  		return pud_page(*pud) + ((addr & ~PUD_MASK) >> PAGE_SHIFT);
c0eb315ad9719e Nicholas Piggin   2021-04-29  858  	if (WARN_ON_ONCE(pud_bad(*pud)))
c2febafc67734a Kiryl Shutsemau   2017-03-09  859  		return NULL;
c0eb315ad9719e Nicholas Piggin   2021-04-29  860  
c2febafc67734a Kiryl Shutsemau   2017-03-09  861  	pmd = pmd_offset(pud, addr);
c0eb315ad9719e Nicholas Piggin   2021-04-29  862  	if (pmd_none(*pmd))
c0eb315ad9719e Nicholas Piggin   2021-04-29  863  		return NULL;
c0eb315ad9719e Nicholas Piggin   2021-04-29  864  	if (pmd_leaf(*pmd))
c0eb315ad9719e Nicholas Piggin   2021-04-29  865  		return pmd_page(*pmd) + ((addr & ~PMD_MASK) >> PAGE_SHIFT);
c0eb315ad9719e Nicholas Piggin   2021-04-29  866  	if (WARN_ON_ONCE(pmd_bad(*pmd)))
c2febafc67734a Kiryl Shutsemau   2017-03-09  867  		return NULL;
db64fe02258f15 Nicholas Piggin   2008-10-18  868  
0d1c81edc61e55 Hugh Dickins      2023-06-08  869  	ptep = pte_offset_kernel(pmd, addr);
c33c794828f212 Ryan Roberts      2023-06-12  870  	pte = ptep_get(ptep);
48667e7a43c1a1 Christoph Lameter 2008-02-04  871  	if (pte_present(pte))
add688fbd32158 malc              2014-01-27  872  		page = pte_page(pte);
c0eb315ad9719e Nicholas Piggin   2021-04-29  873  
add688fbd32158 malc              2014-01-27  874  	return page;
48667e7a43c1a1 Christoph Lameter 2008-02-04  875  }
add688fbd32158 malc              2014-01-27  876  EXPORT_SYMBOL(vmalloc_to_page);
48667e7a43c1a1 Christoph Lameter 2008-02-04  877  

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

#2 lore raw
In reply to Rosen Penev
Quoted 27 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 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() as a NULL function to silence clang's warning on an unreachable branch. sparc64 has no p4d leaf mappings, so there is no functional change.

Assisted-by LLM

---
v2: use a NULL function instead.

 arch/sparc/include/asm/pgtable_64.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/include/asm/pgtable_64.h +0 -0
index 35a217bf6e5c..54e563eb0efd 100644

arch/sparc/include/asm/pgtable_64.h static inline pmd_t *pud_pgtable(pud_t pud) · line 854

Quoted 5 lines
arch/sparc/include/asm/pgtable_64.h +1 -1
@@ -851,7 +851,7 @@ static inline pmd_t *pud_pgtable(pud_t pud)
 #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)			static inline struct page *p4d_page(p4d_t p4d) { return NULL; }

Huh? Why did you keep the macro instead of replacing it with the static inline function wholesale? This should have just be

-#define p4d_page(p4d) NULL
+static inline struct page *p4d_page(p4d_t p4d) { return NULL; }

no?

Quoted 5 lines
arch/sparc/include/asm/pgtable_64.h +0 -0
 #define pud_leaf pud_leaf
 static inline bool pud_leaf(pud_t pud)
Signature · 1 line
2.56.0
Signature · 2 lines
Cheers,
Nathan
#3 lore raw
Quoted 41 lines · Nathan Chancellor
Quoted 27 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 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() as a NULL function to silence clang's warning on an unreachable branch. sparc64 has no p4d leaf mappings, so there is no functional change.

Assisted-by LLM

---
v2: use a NULL function instead.

 arch/sparc/include/asm/pgtable_64.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/include/asm/pgtable_64.h +0 -0
index 35a217bf6e5c..54e563eb0efd 100644

arch/sparc/include/asm/pgtable_64.h static inline pmd_t *pud_pgtable(pud_t pud) · line 854

Quoted 5 lines
arch/sparc/include/asm/pgtable_64.h +1 -1
@@ -851,7 +851,7 @@ static inline pmd_t *pud_pgtable(pud_t pud)
 #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)                        static inline struct page *p4d_page(p4d_t p4d) { return NULL; }

Huh? Why did you keep the macro instead of replacing it with the static inline function wholesale? This should have just be

(quoted diff) +1 -1
-#define p4d_page(p4d)                  NULL
+static inline struct page *p4d_page(p4d_t p4d) { return NULL; }
Quoted 1 line

no?

Was not thinking. I sent a v3 and actually tested compilation this time.

Quoted 10 lines
Quoted 6 lines
arch/sparc/include/asm/pgtable_64.h +0 -1
 #define pud_leaf pud_leaf
 static inline bool pud_leaf(pud_t pud)
--

2.56.0

--
Cheers,
Nathan

#4 lore raw
In reply to Rosen Penev
kernel test robot noticed the following build errors:

Hi Rosen,

kernel test robot noticed the following build errors:

[auto build test ERROR on v7.3-rc6]
[also build test ERROR on linus/master next-20261008]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Rosen-Penev/sparc64-Define-p4d_page-instead-of-stubbing-it-to-NULL/20261008-121711
base:   v7.3-rc6
patch link:    https://lore.kernel.org/r/20261008191711.223236-1-rosenp%40gmail.com
patch subject: [PATCH v2] sparc64: Define p4d_page() instead of stubbing it to NULL
config: sparc-randconfig-1000-20261010 (https://download.01.org/0day-ci/archive/20261010/[email protected]/config)
compiler: sparc64-linux-gcc (GCC) 8.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261010/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

In file included from arch/sparc/include/asm/pgtable.h:5,

                    from include/linux/pgtable.h:6,
                    from include/linux/mm.h:31,
                    from mm/vmalloc.c:12:
   mm/vmalloc.c: In function 'vmalloc_to_page':
>> arch/sparc/include/asm/pgtable_64.h:864:25: error: expected expression before 'static'
    #define p4d_page(p4d)   static inline struct page *p4d_page(p4d_t p4d) { return NULL; }
                            ^~~~~~
   mm/vmalloc.c:849:10: note: in expansion of macro 'p4d_page'
      return p4d_page(*p4d) + ((addr & ~P4D_MASK) >> PAGE_SHIFT);
             ^~~~~~~~

vim +/static +864 arch/sparc/include/asm/pgtable_64.h

862
863 /* only used by the stubbed out hugetlb gup code, should never be called */

 > 864	#define p4d_page(p4d)			static inline struct page *p4d_page(p4d_t p4d) { return NULL; }

865

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki