Re: [PATCH V2 4/7] mm: Use pmdp_get() for accessing PMD entries

From: Anshuman Khandual
Date: Thu Sep 19 2024 - 03:21:58 EST




On 9/19/24 00:27, kernel test robot wrote:
> Hi Anshuman,
>
> kernel test robot noticed the following build errors:
>
> [auto build test ERROR on char-misc/char-misc-testing]
> [also build test ERROR on char-misc/char-misc-next char-misc/char-misc-linus brauner-vfs/vfs.all dennis-percpu/for-next linus/master v6.11]
> [cannot apply to akpm-mm/mm-everything next-20240918]
> [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/Anshuman-Khandual/m68k-mm-Change-pmd_val/20240917-153331
> base: char-misc/char-misc-testing
> patch link: https://lore.kernel.org/r/20240917073117.1531207-5-anshuman.khandual%40arm.com
> patch subject: [PATCH V2 4/7] mm: Use pmdp_get() for accessing PMD entries
> config: um-allnoconfig (https://download.01.org/0day-ci/archive/20240919/202409190205.YJ5gtx3T-lkp@xxxxxxxxx/config)
> compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240919/202409190205.YJ5gtx3T-lkp@xxxxxxxxx/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 <lkp@xxxxxxxxx>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202409190205.YJ5gtx3T-lkp@xxxxxxxxx/
>
> All errors (new ones prefixed by >>):
>
> In file included from mm/pgtable-generic.c:10:
> In file included from include/linux/pagemap.h:11:
> In file included from include/linux/highmem.h:12:
> In file included from include/linux/hardirq.h:11:
> In file included from arch/um/include/asm/hardirq.h:5:
> In file included from include/asm-generic/hardirq.h:17:
> In file included from include/linux/irq.h:20:
> In file included from include/linux/io.h:14:
> In file included from arch/um/include/asm/io.h:24:
> include/asm-generic/io.h:548:31: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> 548 | val = __raw_readb(PCI_IOBASE + addr);
> | ~~~~~~~~~~ ^
> include/asm-generic/io.h:561:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> 561 | val = __le16_to_cpu((__le16 __force)__raw_readw(PCI_IOBASE + addr));
> | ~~~~~~~~~~ ^
> include/uapi/linux/byteorder/little_endian.h:37:51: note: expanded from macro '__le16_to_cpu'
> 37 | #define __le16_to_cpu(x) ((__force __u16)(__le16)(x))
> | ^
> In file included from mm/pgtable-generic.c:10:
> In file included from include/linux/pagemap.h:11:
> In file included from include/linux/highmem.h:12:
> In file included from include/linux/hardirq.h:11:
> In file included from arch/um/include/asm/hardirq.h:5:
> In file included from include/asm-generic/hardirq.h:17:
> In file included from include/linux/irq.h:20:
> In file included from include/linux/io.h:14:
> In file included from arch/um/include/asm/io.h:24:
> include/asm-generic/io.h:574:61: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> 574 | val = __le32_to_cpu((__le32 __force)__raw_readl(PCI_IOBASE + addr));
> | ~~~~~~~~~~ ^
> include/uapi/linux/byteorder/little_endian.h:35:51: note: expanded from macro '__le32_to_cpu'
> 35 | #define __le32_to_cpu(x) ((__force __u32)(__le32)(x))
> | ^
> In file included from mm/pgtable-generic.c:10:
> In file included from include/linux/pagemap.h:11:
> In file included from include/linux/highmem.h:12:
> In file included from include/linux/hardirq.h:11:
> In file included from arch/um/include/asm/hardirq.h:5:
> In file included from include/asm-generic/hardirq.h:17:
> In file included from include/linux/irq.h:20:
> In file included from include/linux/io.h:14:
> In file included from arch/um/include/asm/io.h:24:
> include/asm-generic/io.h:585:33: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> 585 | __raw_writeb(value, PCI_IOBASE + addr);
> | ~~~~~~~~~~ ^
> include/asm-generic/io.h:595:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> 595 | __raw_writew((u16 __force)cpu_to_le16(value), PCI_IOBASE + addr);
> | ~~~~~~~~~~ ^
> include/asm-generic/io.h:605:59: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> 605 | __raw_writel((u32 __force)cpu_to_le32(value), PCI_IOBASE + addr);
> | ~~~~~~~~~~ ^
> include/asm-generic/io.h:693:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> 693 | readsb(PCI_IOBASE + addr, buffer, count);
> | ~~~~~~~~~~ ^
> include/asm-generic/io.h:701:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> 701 | readsw(PCI_IOBASE + addr, buffer, count);
> | ~~~~~~~~~~ ^
> include/asm-generic/io.h:709:20: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> 709 | readsl(PCI_IOBASE + addr, buffer, count);
> | ~~~~~~~~~~ ^
> include/asm-generic/io.h:718:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> 718 | writesb(PCI_IOBASE + addr, buffer, count);
> | ~~~~~~~~~~ ^
> include/asm-generic/io.h:727:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> 727 | writesw(PCI_IOBASE + addr, buffer, count);
> | ~~~~~~~~~~ ^
> include/asm-generic/io.h:736:21: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
> 736 | writesl(PCI_IOBASE + addr, buffer, count);

Not sure if the above warnings are actually caused by this patch.

> | ~~~~~~~~~~ ^
>>> mm/pgtable-generic.c:54:2: error: cannot take the address of an rvalue of type 'pgd_t'
> 54 | pmd_ERROR(pmdp_get(pmd));
> | ^~~~~~~~~~~~~~~~~~~~~~~~
> include/asm-generic/pgtable-nopmd.h:36:28: note: expanded from macro 'pmd_ERROR'
> 36 | #define pmd_ERROR(pmd) (pud_ERROR((pmd).pud))
> | ^~~~~~~~~~~~~~~~~~~~
> include/asm-generic/pgtable-nopud.h:32:28: note: expanded from macro 'pud_ERROR'
> 32 | #define pud_ERROR(pud) (p4d_ERROR((pud).p4d))
> | ^~~~~~~~~~~~~~~~~~~~
> include/asm-generic/pgtable-nop4d.h:25:28: note: expanded from macro 'p4d_ERROR'
> 25 | #define p4d_ERROR(p4d) (pgd_ERROR((p4d).pgd))
> | ^~~~~~~~~~~~~~~~~~~~
> arch/um/include/asm/pgtable-2level.h:31:67: note: expanded from macro 'pgd_ERROR'
> 31 | printk("%s:%d: bad pgd %p(%08lx).\n", __FILE__, __LINE__, &(e), \
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~
> 32 | pgd_val(e))
> | ~~~~~~~~~~~
> include/linux/printk.h:465:60: note: expanded from macro 'printk'
> 465 | #define printk(fmt, ...) printk_index_wrap(_printk, fmt, ##__VA_ARGS__)
> | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
> include/linux/printk.h:437:19: note: expanded from macro 'printk_index_wrap'
> 437 | _p_func(_fmt, ##__VA_ARGS__); \
> | ^~~~~~~~~~~
> 12 warnings and 1 error generated.
>
>
> vim +/pgd_t +54 mm/pgtable-generic.c
>
> 46
> 47 /*
> 48 * Note that the pmd variant below can't be stub'ed out just as for p4d/pud
> 49 * above. pmd folding is special and typically pmd_* macros refer to upper
> 50 * level even when folded
> 51 */
> 52 void pmd_clear_bad(pmd_t *pmd)
> 53 {
> > 54 pmd_ERROR(pmdp_get(pmd));
> 55 pmd_clear(pmd);
> 56 }
> 57
>

But the above build error can be fixed with the following change.

diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
index 8a5032ec231f..f442c1e3156a 100644
--- a/arch/um/include/asm/pgtable-3level.h
+++ b/arch/um/include/asm/pgtable-3level.h
@@ -43,13 +43,13 @@
#define USER_PTRS_PER_PGD ((TASK_SIZE + (PGDIR_SIZE - 1)) / PGDIR_SIZE)

#define pte_ERROR(e) \
- printk("%s:%d: bad pte %p(%016lx).\n", __FILE__, __LINE__, &(e), \
+ printk("%s:%d: bad pte (%016lx).\n", __FILE__, __LINE__, \
pte_val(e))
#define pmd_ERROR(e) \
- printk("%s:%d: bad pmd %p(%016lx).\n", __FILE__, __LINE__, &(e), \
+ printk("%s:%d: bad pmd (%016lx).\n", __FILE__, __LINE__, \
pmd_val(e))
#define pgd_ERROR(e) \
- printk("%s:%d: bad pgd %p(%016lx).\n", __FILE__, __LINE__, &(e), \
+ printk("%s:%d: bad pgd (%016lx).\n", __FILE__, __LINE__, \
pgd_val(e))

#define pud_none(x) (!(pud_val(x) & ~_PAGE_NEWPAGE))