mm: move phys_mem_access_prot_allowed to header
Subsystems (4)
PATCH 1/1 mm: move phys_mem_access_prot_allowed to header
phys_mem_access_prot_allowed is only implemented for X86. For others, it returns 1. Move it to header to avoid using __weak.
Fixes compilation with make LLVM=1 ARCH=mips
--- drivers/char/mem.c | 6 ------ include/linux/pgtable.h | 8 ++++++++ 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/char/mem.c +0 -6
@@ -239,12 +239,6 @@ static ssize_t write_mem(struct file *file, const char __user *buf,return written; } -int __weak phys_mem_access_prot_allowed (struct file *file, -unsigned long pfn,unsigned long size,pgprot_t *vma_prot) -{ -return 1 ; -} -#ifndef __HAVE_PHYS_MEM_ACCESS_PROT/*
include/linux/pgtable.h +8 -0
@@ -2154,8 +2154,16 @@ static inline int pmd_free_pte_page(pmd_t *pmd, unsigned long addr)#endif struct file ; +#ifdef CONFIG_X86 int phys_mem_access_prot_allowed (struct file *file,unsigned long pfn,unsigned long size,pgprot_t *vma_prot); +#else +static inline +int phys_mem_access_prot_allowed (struct file *file,unsigned long pfn, +unsigned long size,pgprot_t *vma_prot) { +return 1 ; +} +#endif #ifndef CONFIG_X86_ESPFIX64 static inline void init_espfix_bsp (void ) { }
Signature · 1 line
2.54.0
Arnd Bergmann
maintainerQuoted 4 lines · Rosen Penev
phys_mem_access_prot_allowedis only implemented for X86. For others, it returns 1. Move it to header to avoid using__weak.Fixes compilation with make LLVM=1 ARCH=mips
Can you describe what exactly goes wrong here on mips?
drivers/char/mem.c static ssize_t write_mem(struct file *file, const · line 248
Quoted 11 lines
drivers/char/mem.c +0
-6@@ -239,12 +239,6 @@ static ssize_t write_mem(struct file *file, constchar __user *buf, return written; } -int __weak phys_mem_access_prot_allowed (struct file *file, -unsigned long pfn,unsigned long size,pgprot_t *vma_prot) -{ -return 1 ; -} -
Removing __weak functions is usually an improvement, but I think we can go further here, see the discussion from last year at
https://lore.kernel.org/all/[email protected]/#t
Arnd
Quoted 8 lines · Arnd Bergmann
Quoted 4 lines · Rosen Penev
phys_mem_access_prot_allowedis only implemented for X86. For others, it returns 1. Move it to header to avoid using__weak.Fixes compilation with make LLVM=1 ARCH=mips
Can you describe what exactly goes wrong here on mips?
Cannot find symbol for section 4: .text.phys_mem_access_prot_allowed. drivers/char/mem.o: failed
It's full of similar errors in drivers/pci/ as well. clang on MIPS doesn't seem to like __weak.
Quoted 16 lines
drivers/char/mem.c static ssize_t write_mem(struct file *file, const · line 248
Quoted 12 lines
drivers/char/mem.c +0
-6@@ -239,12 +239,6 @@ static ssize_t write_mem(struct file *file, constchar __user *buf, return written; } -int __weak phys_mem_access_prot_allowed (struct file *file, -unsigned long pfn,unsigned long size,pgprot_t *vma_prot) -{ -return 1 ; -} -Removing
__weakfunctions is usually an improvement, but I think we can go further here, see the discussion from last year at
Quoted 1 line
I hold no opinion on that.
Quoted 2 lines
Arnd
Arnd Bergmann
maintainerQuoted 6 lines · Rosen Penev
Quoted 5 lines · Arnd Bergmann
Quoted 3 lines · Rosen Penev
phys_mem_access_prot_allowedis only implemented for X86. For others, it returns 1. Move it to header to avoid using__weak.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Fixes compilation with make LLVM=1 ARCH=mips
Can you describe what exactly goes wrong here on mips?
Cannot find symbol for section 4: .text.phys_mem_access_prot_allowed.
drivers/char/mem.o: failedIt's full of similar errors in
drivers/pci/as well. clang on MIPS doesn't seem to like__weak.
This certainly feels like a toolchain bug. I would not mind having the PCI code converted away from the __weak functions, but it should not just fail with a linker error like this.
Does this happen with both ld.bfd and ld.lld? Which version of clang and lld are you using?
Arnd
Quoted 14 lines · Arnd Bergmann
Quoted 12 lines · Rosen Penev
Quoted 8 lines · Arnd Bergmann
Quoted 4 lines · Rosen Penev
phys_mem_access_prot_allowedis only implemented for X86. For others, it returns 1. Move it to header to avoid using__weak.Fixes compilation with make LLVM=1 ARCH=mips
Can you describe what exactly goes wrong here on mips?
Cannot find symbol for section 4: .text.phys_mem_access_prot_allowed.
drivers/char/mem.o: failed
Quoted 6 lines
Quoted 2 lines
It's full of similar errors in
drivers/pci/as well. clang on MIPS doesn't seem to like__weak.This certainly feels like a toolchain bug. I would not mind having the PCI code converted away from the
__weakfunctions, but it should not just fail with a linker error like this.
FWIW I just tested
make LLVM=1 ARCH=powerpc -j 31
which results in no such errors. So probably.
Quoted 3 lines
Does this happen with both ld.bfd and ld.lld? Which version of clang and lld are you using?
clang version 22.1.3
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
lld the same.
I don't specify lld explicitly. I assume LLVM=1 does that.
Quoted 2 lines
Arnd
Arnd Bergmann
maintainerQuoted 10 lines · Rosen Penev
Quoted 3 lines · Arnd Bergmann
Does this happen with both ld.bfd and ld.lld? Which version of clang and lld are you using?
clang version 22.1.3
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir:/usr/binlld the same.
Ok. I've tried to reproduce this with Nathan's llvm-22.1.3 build from https://mirrors.edge.kernel.org/pub/tools/llvm/, but don't see this problem on mips defconfig. Are you using a particular configuration, or do you see this on every build?
Quoted 1 line
I don't specify lld explicitly. I assume LLVM=1 does that.
Yes, by default it will use ld.lld. For cross-checking, you can try passing LD=mips-linux-ld.bfd (or whereever you have installed your cross or multiarch binutils), which should still work just fine.
Arnd
Quoted 11 lines · Arnd Bergmann
Quoted 9 lines · Rosen Penev
Quoted 3 lines · Arnd Bergmann
Does this happen with both ld.bfd and ld.lld? Which version of clang and lld are you using?
clang version 22.1.3
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir:/usr/bin
Quoted 6 lines
Quoted 1 line
lld the same.
Ok. I've tried to reproduce this with Nathan's llvm-22.1.3 build from https://mirrors.edge.kernel.org/pub/tools/llvm/, but don't see this problem on mips defconfig. Are you using a particular configuration, or do you see this on every build?
I use allmodconfig. And yes, every build. I'm using a fully updated Arch Linux.
Quoted 7 lines
Quoted 2 lines
I don't specify lld explicitly. I assume LLVM=1 does that.
Yes, by default it will use ld.lld. For cross-checking, you can try passing LD=mips-linux-ld.bfd (or whereever you have installed your cross or multiarch binutils), which should still work just fine.
Arch seems to not provide such a thing.
Quoted 2 lines
Arnd
Quoted 10 lines · Arnd Bergmann
Quoted 9 lines · Rosen Penev
Quoted 3 lines · Arnd Bergmann
Does this happen with both ld.bfd and ld.lld? Which version of clang and lld are you using?
clang version 22.1.3
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir:/usr/bin
Quoted 6 lines
Quoted 1 line
lld the same.
Ok. I've tried to reproduce this with Nathan's llvm-22.1.3 build from https://mirrors.edge.kernel.org/pub/tools/llvm/, but don't see this problem on mips defconfig. Are you using a particular configuration, or do you see this on every build?
This is just the same old integrated assembler vs. recordmcount bug:
https://github.com/ClangBuiltLinux/linux/issues/981
https://github.com/ClangBuiltLinux/linux/issues/1830
It requires CONFIG_LD_DEAD_CODE_DATA_ELIMINATION=y with ftrace, which MIPS allmodconfig enables. PowerPC worked around this in commit f8b2336f15f3 ("powerpc: Avoid dead code/data elimination when using recordmcount"). Maybe something along the same lines should be done for MIPS.
Cheers,
Nathan
Quoted 21 lines · Nathan Chancellor
Quoted 10 lines · Arnd Bergmann
Quoted 9 lines · Rosen Penev
Quoted 3 lines · Arnd Bergmann
Does this happen with both ld.bfd and ld.lld? Which version of clang and lld are you using?
clang version 22.1.3
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir:/usr/binQuoted 6 lines
Quoted 1 line
lld the same.
Ok. I've tried to reproduce this with Nathan's llvm-22.1.3 build from https://mirrors.edge.kernel.org/pub/tools/llvm/, but don't see this problem on mips defconfig. Are you using a particular configuration, or do you see this on every build?
This is just the same old integrated assembler vs. recordmcount bug:
Quoted 8 lines
https://github.com/ClangBuiltLinux/linux/issues/981
https://github.com/ClangBuiltLinux/linux/issues/1830It requires
CONFIG_LD_DEAD_CODE_DATA_ELIMINATION=ywith ftrace, which MIPS allmodconfig enables. PowerPC worked around this in commitf8b2336f15f3("powerpc: Avoid dead code/data elimination when using recordmcount"). Maybe something along the same lines should be done for MIPS.
arch/mips/Kconfig +1 -1
@@ -82,7 +82,7 @@ config MIPS select HAVE_IRQ_TIME_ACCOUNTING select HAVE_KPROBES select HAVE_KRETPROBES - select HAVE_LD_DEAD_CODE_DATA_ELIMINATION + select HAVE_LD_DEAD_CODE_DATA_ELIMINATION if HAVE_OBJTOOL_MCOUNT select HAVE_MOD_ARCH_SPECIFIC select HAVE_NMI select HAVE_PAGE_SIZE_4KB if !CPU_LOONGSON2EF && !CPU_LOONGSON64
fixes it. I see master has a different line for powerpc. I defer to the experts on this.
Quoted 3 lines
Cheers,
Nathan