mm: make arch_has_descending_max_zone_pfns() static

Message ID 20230414080418.110236-1-arnd@kernel.org
State New
Headers
Series mm: make arch_has_descending_max_zone_pfns() static |

Commit Message

Arnd Bergmann April 14, 2023, 8:03 a.m. UTC
  From: Arnd Bergmann <arnd@arndb.de>

clang produces a build failure on x86 for some randconfig builds
after a change that moves around code to mm/mm_init.c:

Cannot find symbol for section 2: .text.
mm/mm_init.o: failed

I have not been able to figure out why this happens, but the __weak
annotation on arch_has_descending_max_zone_pfns() is the trigger here.

Removing the weak function in favor of an open-coded Kconfig option
check avoids the problem and becomes clearer as well as better to
optimize by the compiler.

Fixes: 9420f89db2dd ("mm: move most of core MM initialization to mm/mm_init.c")
Cc: llvm@lists.linux.dev
Signed-off-by: Arnd Bergmann <arnd@arndb.de>
---
 arch/arc/mm/init.c | 5 -----
 include/linux/mm.h | 1 -
 mm/mm_init.c       | 4 ++--
 3 files changed, 2 insertions(+), 8 deletions(-)
  

Comments

kernel test robot April 15, 2023, 6:42 a.m. UTC | #1
Hello,

kernel test robot noticed "kernel_BUG_at_lib/list_debug.c" on:

commit: c31fe5eb2ec68f6d2331fabc924e0030cc6bb2b3 ("[PATCH] mm: make arch_has_descending_max_zone_pfns() static")
url: https://github.com/intel-lab-lkp/linux/commits/Arnd-Bergmann/mm-make-arch_has_descending_max_zone_pfns-static/20230414-160608
base: https://git.kernel.org/cgit/linux/kernel/git/akpm/mm.git mm-everything
patch link: https://lore.kernel.org/all/20230414080418.110236-1-arnd@kernel.org/
patch subject: [PATCH] mm: make arch_has_descending_max_zone_pfns() static

in testcase: boot

compiler: gcc-11
test machine: qemu-system-x86_64 -enable-kvm -cpu SandyBridge -smp 2 -m 16G

(please refer to attached dmesg/kmsg for entire log/backtrace)


+------------------------------------------+------------+------------+
|                                          | 32ed3874f2 | c31fe5eb2e |
+------------------------------------------+------------+------------+
| boot_successes                           | 10         | 0          |
| boot_failures                            | 0          | 6          |
| kernel_BUG_at_lib/list_debug.c           | 0          | 6          |
| invalid_opcode:#[##]                     | 0          | 6          |
| EIP:__list_add_valid                     | 0          | 6          |
| Kernel_panic-not_syncing:Fatal_exception | 0          | 6          |
+------------------------------------------+------------+------------+


If you fix the issue, kindly add following tag
| Reported-by: kernel test robot <oliver.sang@intel.com>
| Link: https://lore.kernel.org/oe-lkp/202304151422.5e4d380b-oliver.sang@intel.com


[    0.004000][    T0] ------------[ cut here ]------------
[    0.004000][    T0] kernel BUG at lib/list_debug.c:33!
[    0.004000][    T0] invalid opcode: 0000 [#1] SMP
[    0.004000][    T0] CPU: 0 PID: 0 Comm: swapper Not tainted 6.3.0-rc5-00613-gc31fe5eb2ec6 #42
[ 0.004000][ T0] EIP: __list_add_valid (??:?) 
[ 0.004000][ T0] Code: 56 51 68 78 b0 4c c2 e8 39 c7 de ff 0f 0b b8 f4 60 a4 c2 eb 1c 39 d3 74 04 39 f3 75 19 51 50 53 68 ca b0 4c c2 e8 1b c7 de ff <0f> 0b b8 e8 60 a4 c2 e8 be 71 06 00 8d 65 f8 b0 01 5b 5e 5d 31 d2
All code
========
   0:	56                   	push   %rsi
   1:	51                   	push   %rcx
   2:	68 78 b0 4c c2       	pushq  $0xffffffffc24cb078
   7:	e8 39 c7 de ff       	callq  0xffffffffffdec745
   c:	0f 0b                	ud2    
   e:	b8 f4 60 a4 c2       	mov    $0xc2a460f4,%eax
  13:	eb 1c                	jmp    0x31
  15:	39 d3                	cmp    %edx,%ebx
  17:	74 04                	je     0x1d
  19:	39 f3                	cmp    %esi,%ebx
  1b:	75 19                	jne    0x36
  1d:	51                   	push   %rcx
  1e:	50                   	push   %rax
  1f:	53                   	push   %rbx
  20:	68 ca b0 4c c2       	pushq  $0xffffffffc24cb0ca
  25:	e8 1b c7 de ff       	callq  0xffffffffffdec745
  2a:*	0f 0b                	ud2    		<-- trapping instruction
  2c:	b8 e8 60 a4 c2       	mov    $0xc2a460e8,%eax
  31:	e8 be 71 06 00       	callq  0x671f4
  36:	8d 65 f8             	lea    -0x8(%rbp),%esp
  39:	b0 01                	mov    $0x1,%al
  3b:	5b                   	pop    %rbx
  3c:	5e                   	pop    %rsi
  3d:	5d                   	pop    %rbp
  3e:	31 d2                	xor    %edx,%edx

Code starting with the faulting instruction
===========================================
   0:	0f 0b                	ud2    
   2:	b8 e8 60 a4 c2       	mov    $0xc2a460e8,%eax
   7:	e8 be 71 06 00       	callq  0x671ca
   c:	8d 65 f8             	lea    -0x8(%rbp),%esp
   f:	b0 01                	mov    $0x1,%al
  11:	5b                   	pop    %rbx
  12:	5e                   	pop    %rsi
  13:	5d                   	pop    %rbp
  14:	31 d2                	xor    %edx,%edx
[    0.004000][    T0] EAX: 00000040 EBX: ec373004 ECX: 00000000 EDX: 00000000
[    0.004000][    T0] ESI: c2ba2b20 EDI: ec373004 EBP: c2689e94 ESP: c2689e7c
[    0.004000][    T0] DS: 007b ES: 007b FS: 00d8 GS: 0000 SS: 0068 EFLAGS: 00210046
[    0.004000][    T0] CR0: 80050033 CR2: 00000000 CR3: 02c7d000 CR4: 00040690
[    0.004000][    T0] DR0: 00000000 DR1: 00000000 DR2: 00000000 DR3: 00000000
[    0.004000][    T0] DR6: fffe0ff0 DR7: 00000400
[    0.004000][    T0] Call Trace:
[ 0.004000][ T0] list_add_tail (uncore.c:?) 
[ 0.004000][ T0] __free_one_page (page_alloc.c:?) 
[ 0.004000][ T0] __free_pages_ok (page_alloc.c:?) 
[ 0.004000][ T0] __free_pages_core (??:?) 
[ 0.004000][ T0] memblock_free_pages (??:?) 
[ 0.004000][ T0] memblock_free_all (??:?) 
[ 0.004000][ T0] mem_init (??:?) 
[ 0.004000][ T0] mm_core_init (??:?) 
[ 0.004000][ T0] ? cpu_init (??:?) 
[ 0.004000][ T0] start_kernel (??:?) 
[ 0.004000][ T0] i386_start_kernel (??:?) 
[ 0.004000][ T0] startup_32_smp (??:?) 
[    0.004000][    T0] Modules linked in:
[    0.004000][    T0] ---[ end trace 0000000000000000 ]---
[ 0.004000][ T0] EIP: __list_add_valid (??:?) 
[ 0.004000][ T0] Code: 56 51 68 78 b0 4c c2 e8 39 c7 de ff 0f 0b b8 f4 60 a4 c2 eb 1c 39 d3 74 04 39 f3 75 19 51 50 53 68 ca b0 4c c2 e8 1b c7 de ff <0f> 0b b8 e8 60 a4 c2 e8 be 71 06 00 8d 65 f8 b0 01 5b 5e 5d 31 d2
All code
========
   0:	56                   	push   %rsi
   1:	51                   	push   %rcx
   2:	68 78 b0 4c c2       	pushq  $0xffffffffc24cb078
   7:	e8 39 c7 de ff       	callq  0xffffffffffdec745
   c:	0f 0b                	ud2    
   e:	b8 f4 60 a4 c2       	mov    $0xc2a460f4,%eax
  13:	eb 1c                	jmp    0x31
  15:	39 d3                	cmp    %edx,%ebx
  17:	74 04                	je     0x1d
  19:	39 f3                	cmp    %esi,%ebx
  1b:	75 19                	jne    0x36
  1d:	51                   	push   %rcx
  1e:	50                   	push   %rax
  1f:	53                   	push   %rbx
  20:	68 ca b0 4c c2       	pushq  $0xffffffffc24cb0ca
  25:	e8 1b c7 de ff       	callq  0xffffffffffdec745
  2a:*	0f 0b                	ud2    		<-- trapping instruction
  2c:	b8 e8 60 a4 c2       	mov    $0xc2a460e8,%eax
  31:	e8 be 71 06 00       	callq  0x671f4
  36:	8d 65 f8             	lea    -0x8(%rbp),%esp
  39:	b0 01                	mov    $0x1,%al
  3b:	5b                   	pop    %rbx
  3c:	5e                   	pop    %rsi
  3d:	5d                   	pop    %rbp
  3e:	31 d2                	xor    %edx,%edx

Code starting with the faulting instruction
===========================================
   0:	0f 0b                	ud2    
   2:	b8 e8 60 a4 c2       	mov    $0xc2a460e8,%eax
   7:	e8 be 71 06 00       	callq  0x671ca
   c:	8d 65 f8             	lea    -0x8(%rbp),%esp
   f:	b0 01                	mov    $0x1,%al
  11:	5b                   	pop    %rbx
  12:	5e                   	pop    %rsi
  13:	5d                   	pop    %rbp
  14:	31 d2                	xor    %edx,%edx


To reproduce:

        # build kernel
	cd linux
	cp config-6.3.0-rc5-00613-gc31fe5eb2ec6 .config
	make HOSTCC=gcc-11 CC=gcc-11 ARCH=i386 olddefconfig prepare modules_prepare bzImage modules
	make HOSTCC=gcc-11 CC=gcc-11 ARCH=i386 INSTALL_MOD_PATH=<mod-install-dir> modules_install
	cd <mod-install-dir>
	find lib/ | cpio -o -H newc --quiet | gzip > modules.cgz


        git clone https://github.com/intel/lkp-tests.git
        cd lkp-tests
        bin/lkp qemu -k <bzImage> -m modules.cgz job-script # job-script is attached in this email

        # if come across any failure that blocks the test,
        # please remove ~/.lkp and /lkp dir to run from a clean state.
  
Arnd Bergmann April 15, 2023, 8:09 a.m. UTC | #2
On Sat, Apr 15, 2023, at 08:42, kernel test robot wrote:
> Hello,
>
> kernel test robot noticed "kernel_BUG_at_lib/list_debug.c" on:
>
> commit: c31fe5eb2ec68f6d2331fabc924e0030cc6bb2b3 ("[PATCH] mm: make 
> arch_has_descending_max_zone_pfns() static")

Thanks for the report, that was a logic error on my end, the fix is:

--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1756,7 +1756,7 @@ static void __init free_area_init_memoryless_node(int nid)
  */
 static bool arch_has_descending_max_zone_pfns(void)
 {
-       return !IS_ENABLED(CONFIG_ARC_HAS_PAE40);
+       return IS_ENABLED(CONFIG_ARC) && !IS_ENABLED(CONFIG_ARC_HAS_PAE40);
 }
 
 /**

I'll send a replacement v2 that has this folded in.

    Arnd
  

Patch

diff --git a/arch/arc/mm/init.c b/arch/arc/mm/init.c
index ce4e939a7f07..2b89b6c53801 100644
--- a/arch/arc/mm/init.c
+++ b/arch/arc/mm/init.c
@@ -74,11 +74,6 @@  void __init early_init_dt_add_memory_arch(u64 base, u64 size)
 		base, TO_MB(size), !in_use ? "Not used":"");
 }
 
-bool arch_has_descending_max_zone_pfns(void)
-{
-	return !IS_ENABLED(CONFIG_ARC_HAS_PAE40);
-}
-
 /*
  * First memory setup routine called from setup_arch()
  * 1. setup swapper's mm @init_mm
diff --git a/include/linux/mm.h b/include/linux/mm.h
index ada57b11bb5a..a13cc121841d 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -3061,7 +3061,6 @@  extern void setup_per_cpu_pageset(void);
 extern int min_free_kbytes;
 extern int watermark_boost_factor;
 extern int watermark_scale_factor;
-extern bool arch_has_descending_max_zone_pfns(void);
 
 /* nommu.c */
 extern atomic_long_t mmap_pages_allocated;
diff --git a/mm/mm_init.c b/mm/mm_init.c
index 35302b7bca83..f6165747fd3e 100644
--- a/mm/mm_init.c
+++ b/mm/mm_init.c
@@ -1754,9 +1754,9 @@  static void __init free_area_init_memoryless_node(int nid)
  * Some architectures, e.g. ARC may have ZONE_HIGHMEM below ZONE_NORMAL. For
  * such cases we allow max_zone_pfn sorted in the descending order
  */
-bool __weak arch_has_descending_max_zone_pfns(void)
+static bool arch_has_descending_max_zone_pfns(void)
 {
-	return false;
+	return !IS_ENABLED(CONFIG_ARC_HAS_PAE40);
 }
 
 /**