[PATCH v4 29/34] x86/amd_nb: Trickle down 'struct cpuinfo_x86' reference

Ahmed S. Darwish posted 34 patches 1 month, 2 weeks ago
There is a newer version of this series
[PATCH v4 29/34] x86/amd_nb: Trickle down 'struct cpuinfo_x86' reference
Posted by Ahmed S. Darwish 1 month, 2 weeks ago
Prepare cpuid_amd_hygon_has_l3_cache(), which is internally a
CPUID(0x80000006) call site, for using the parsed CPUID API instead of
invoking direct CPUID queries.

Since such an API requires a 'struct cpuinfo_x86' reference, trickle it
down from the start of the amd_nb initcall.

Note, accessing the CPUID tables at initcall_5 using this_cpu_ptr()
should be safe, since the 'struct cpuinfo_x86' per-CPU presentation is
finalized at arch/x86/kernel/cpu/common.c :: arch_cpu_finalize_init().
Meanwhile, at kernel init/main.c, do_initcalls() are done much later.

Signed-off-by: Ahmed S. Darwish <darwi@linutronix.de>
---
 arch/x86/kernel/amd_nb.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/amd_nb.c b/arch/x86/kernel/amd_nb.c
index c1acead6227a..a8809778b208 100644
--- a/arch/x86/kernel/amd_nb.c
+++ b/arch/x86/kernel/amd_nb.c
@@ -16,6 +16,7 @@
 
 #include <asm/amd/nb.h>
 #include <asm/cpuid/api.h>
+#include <asm/processor.h>
 
 static u32 *flush_words;
 
@@ -58,7 +59,7 @@ struct amd_northbridge *node_to_amd_nb(int node)
 }
 EXPORT_SYMBOL_GPL(node_to_amd_nb);
 
-static int amd_cache_northbridges(void)
+static int amd_cache_northbridges(struct cpuinfo_x86 *c)
 {
 	struct amd_northbridge *nb;
 	u16 i;
@@ -315,11 +316,13 @@ static __init void fix_erratum_688(void)
 
 static __init int init_amd_nbs(void)
 {
+	struct cpuinfo_x86 *c = this_cpu_ptr(&cpu_info);
+
 	if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
 	    boot_cpu_data.x86_vendor != X86_VENDOR_HYGON)
 		return 0;
 
-	amd_cache_northbridges();
+	amd_cache_northbridges(c);
 	amd_cache_gart();
 
 	fix_erratum_688();
-- 
2.50.1
Re: [PATCH v4 29/34] x86/amd_nb: Trickle down 'struct cpuinfo_x86' reference
Posted by kernel test robot 1 month, 2 weeks ago

Hello,

kernel test robot noticed "BUG:using_smp_processor_id()in_preemptible" on:

commit: 038e81b1617c57babe0381d3660234db5e84fb93 ("[PATCH v4 29/34] x86/amd_nb: Trickle down 'struct cpuinfo_x86' reference")
url: https://github.com/intel-lab-lkp/linux/commits/Ahmed-S-Darwish/x86-cpuid-Remove-transitional-asm-cpuid-h-header/20250815-152019
patch link: https://lore.kernel.org/all/20250815070227.19981-30-darwi@linutronix.de/
patch subject: [PATCH v4 29/34] x86/amd_nb: Trickle down 'struct cpuinfo_x86' reference

in testcase: boot

config: x86_64-randconfig-078-20250816
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)


+--------------------------------------------+------------+------------+
|                                            | 2b4adf7848 | 038e81b161 |
+--------------------------------------------+------------+------------+
| BUG:using_smp_processor_id()in_preemptible | 0          | 12         |
+--------------------------------------------+------------+------------+


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 <oliver.sang@intel.com>
| Closes: https://lore.kernel.org/oe-lkp/202508180405.3e28d0dd-lkp@intel.com


[    1.202568][    T1] BUG: using smp_processor_id() in preemptible [00000000] code: swapper/0/1
[ 1.202670][ T1] caller is init_amd_nbs (arch/x86/kernel/amd_nb.c:319) 
[    1.203596][    T1] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.17.0-rc1-00029-g038e81b1617c #1 PREEMPT(full)
[    1.203603][    T1] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.16.2-debian-1.16.2-1 04/01/2014
[    1.203606][    T1] Call Trace:
[    1.203608][    T1]  <TASK>
[ 1.203612][ T1] dump_stack_lvl (lib/dump_stack.c:122 (discriminator 4)) 
[ 1.203619][ T1] check_preemption_disabled (lib/smp_processor_id.c:51) 
[ 1.203627][ T1] ? hpet_late_init (arch/x86/kernel/amd_nb.c:318) 
[ 1.203633][ T1] init_amd_nbs (arch/x86/kernel/amd_nb.c:319) 
[ 1.203638][ T1] ? hpet_late_init (arch/x86/kernel/amd_nb.c:318) 
[ 1.203644][ T1] ? hpet_late_init (arch/x86/kernel/amd_nb.c:318) 
[ 1.203648][ T1] do_one_initcall (init/main.c:1269) 
[ 1.203655][ T1] ? rdinit_setup (init/main.c:1315) 
[ 1.203661][ T1] ? rcu_is_watching (include/linux/context_tracking.h:128 kernel/rcu/tree.c:751) 
[ 1.203670][ T1] do_initcalls (init/main.c:1330 init/main.c:1347) 
[ 1.203677][ T1] kernel_init_freeable (init/main.c:1583) 
[ 1.203682][ T1] ? rest_init (init/main.c:1461) 
[ 1.203689][ T1] kernel_init (init/main.c:1471) 
[ 1.203696][ T1] ret_from_fork (arch/x86/kernel/process.c:154) 
[ 1.203704][ T1] ? rest_init (init/main.c:1461) 
[ 1.203712][ T1] ret_from_fork_asm (arch/x86/entry/entry_64.S:258) 
[    1.203725][    T1]  </TASK>


The kernel config and materials to reproduce are available at:
https://download.01.org/0day-ci/archive/20250818/202508180405.3e28d0dd-lkp@intel.com



-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH v4 29/34] x86/amd_nb: Trickle down 'struct cpuinfo_x86' reference
Posted by Ahmed S. Darwish 1 month, 2 weeks ago
On Mon, 18 Aug 2025, kernel test robot wrote:
>
> [    1.202568][    T1] BUG: using smp_processor_id() in preemptible [00000000] code: swapper/0/1
> [ 1.202670][ T1] caller is init_amd_nbs (arch/x86/kernel/amd_nb.c:319)
>

Hmm... This is triggered by:

    static __init int init_amd_nbs(void)
    {
	struct cpuinfo_x86 *c = this_cpu_ptr(&cpu_info);
	...
    }

Since this is all __init code anyway, for the next iteration I'll use
'boot_cpu_data' instead of per-CPU cpu_info access.

Thanks!

--
Ahmed S. Darwish
Linutronix GmbH