2
0
mirror of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2025-09-04 20:19:47 +08:00
linux/arch/riscv/kernel
Vivian Wang 2b29be967a riscv: cpu_ops_sbi: Use static array for boot_data
Since commit 6b9f29b81b ("riscv: Enable pcpu page first chunk
allocator"), if NUMA is enabled, the page percpu allocator may be used
on very sparse configurations, or when requested on boot with
percpu_alloc=page.

In that case, percpu data gets put in the vmalloc area. However,
sbi_hsm_hart_start() needs the physical address of a sbi_hart_boot_data,
and simply assumes that __pa() would work. This causes the just started
hart to immediately access an invalid address and hang.

Fortunately, struct sbi_hart_boot_data is not too large, so we can
simply allocate an array for boot_data statically, putting it in the
kernel image.

This fixes NUMA=y SMP boot on Sophgo SG2042.

To reproduce on QEMU: Set CONFIG_NUMA=y and CONFIG_DEBUG_VIRTUAL=y, then
run with:

  qemu-system-riscv64 -M virt -smp 2 -nographic \
    -kernel arch/riscv/boot/Image \
    -append "percpu_alloc=page"

Kernel output:

[    0.000000] Booting Linux on hartid 0
[    0.000000] Linux version 6.16.0-rc1 (dram@sakuya) (riscv64-unknown-linux-gnu-gcc (GCC) 14.2.1 20250322, GNU ld (GNU Binutils) 2.44) #11 SMP Tue Jun 24 14:56:22 CST 2025
...
[    0.000000] percpu: 28 4K pages/cpu s85784 r8192 d20712
...
[    0.083192] smp: Bringing up secondary CPUs ...
[    0.086722] ------------[ cut here ]------------
[    0.086849] virt_to_phys used for non-linear address: (____ptrval____) (0xff2000000001d080)
[    0.088001] WARNING: CPU: 0 PID: 1 at arch/riscv/mm/physaddr.c:14 __virt_to_phys+0xae/0xe8
[    0.088376] Modules linked in:
[    0.088656] CPU: 0 UID: 0 PID: 1 Comm: swapper/0 Not tainted 6.16.0-rc1 #11 NONE
[    0.088833] Hardware name: riscv-virtio,qemu (DT)
[    0.088948] epc : __virt_to_phys+0xae/0xe8
[    0.089001]  ra : __virt_to_phys+0xae/0xe8
[    0.089037] epc : ffffffff80021eaa ra : ffffffff80021eaa sp : ff2000000004bbc0
[    0.089057]  gp : ffffffff817f49c0 tp : ff60000001d60000 t0 : 5f6f745f74726976
[    0.089076]  t1 : 0000000000000076 t2 : 705f6f745f747269 s0 : ff2000000004bbe0
[    0.089095]  s1 : ff2000000001d080 a0 : 0000000000000000 a1 : 0000000000000000
[    0.089113]  a2 : 0000000000000000 a3 : 0000000000000000 a4 : 0000000000000000
[    0.089131]  a5 : 0000000000000000 a6 : 0000000000000000 a7 : 0000000000000000
[    0.089155]  s2 : ffffffff8130dc00 s3 : 0000000000000001 s4 : 0000000000000001
[    0.089174]  s5 : ffffffff8185eff8 s6 : ff2000007f1eb000 s7 : ffffffff8002a2ec
[    0.089193]  s8 : 0000000000000001 s9 : 0000000000000001 s10: 0000000000000000
[    0.089211]  s11: 0000000000000000 t3 : ffffffff8180a9f7 t4 : ffffffff8180a9f7
[    0.089960]  t5 : ffffffff8180a9f8 t6 : ff2000000004b9d8
[    0.089984] status: 0000000200000120 badaddr: ffffffff80021eaa cause: 0000000000000003
[    0.090101] [<ffffffff80021eaa>] __virt_to_phys+0xae/0xe8
[    0.090228] [<ffffffff8001d796>] sbi_cpu_start+0x6e/0xe8
[    0.090247] [<ffffffff8001a5da>] __cpu_up+0x1e/0x8c
[    0.090260] [<ffffffff8002a32e>] bringup_cpu+0x42/0x258
[    0.090277] [<ffffffff8002914c>] cpuhp_invoke_callback+0xe0/0x40c
[    0.090292] [<ffffffff800294e0>] __cpuhp_invoke_callback_range+0x68/0xfc
[    0.090320] [<ffffffff8002a96a>] _cpu_up+0x11a/0x244
[    0.090334] [<ffffffff8002aae6>] cpu_up+0x52/0x90
[    0.090384] [<ffffffff80c09350>] bringup_nonboot_cpus+0x78/0x118
[    0.090411] [<ffffffff80c11060>] smp_init+0x34/0xb8
[    0.090425] [<ffffffff80c01220>] kernel_init_freeable+0x148/0x2e4
[    0.090442] [<ffffffff80b83802>] kernel_init+0x1e/0x14c
[    0.090455] [<ffffffff800124ca>] ret_from_fork_kernel+0xe/0xf0
[    0.090471] [<ffffffff80b8d9c2>] ret_from_fork_kernel_asm+0x16/0x18
[    0.090560] ---[ end trace 0000000000000000 ]---
[    1.179875] CPU1: failed to come online
[    1.190324] smp: Brought up 1 node, 1 CPU

Cc: stable@vger.kernel.org
Reported-by: Han Gao <rabenda.cn@gmail.com>
Fixes: 6b9f29b81b ("riscv: Enable pcpu page first chunk allocator")
Reviewed-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Tested-by: Alexandre Ghiti <alexghiti@rivosinc.com>
Signed-off-by: Vivian Wang <wangruikang@iscas.ac.cn>
Link: https://lore.kernel.org/r/20250624-riscv-hsm-boot-data-array-v1-1-50b5eeafbe61@iscas.ac.cn
Signed-off-by: Alexandre Ghiti <alexghiti@rivosinc.com>
2025-06-30 06:58:11 +00:00
..
compat_vdso Makefile: remove redundant tool coverage variables 2024-05-14 23:35:48 +09:00
pi riscv: Do not use fortify in early code 2024-10-25 06:18:36 -07:00
probes riscv: uprobes: Add missing fence.i after building the XOL buffer 2025-04-24 13:20:02 -07:00
tests treewide: replace or remove redundant def_bool in Kconfig files 2024-02-20 20:47:45 +09:00
vdso riscv: vdso: Exclude .rodata from the PT_DYNAMIC segment 2025-06-10 13:06:48 -07:00
vendor_extensions riscv: Fix sparse warning in vendor_extensions/sifive.c 2025-06-23 15:57:59 -07:00
.gitignore
acpi_numa.c ACPI: NUMA: initialize all values of acpi_early_node_map to NUMA_NO_NODE 2024-09-20 01:31:26 -07:00
acpi.c mm/ioremap: pass pgprot_t to ioremap_prot() instead of unsigned long 2025-03-16 22:06:23 -07:00
alternative.c asm-generic: introduce text-patching.h 2024-11-07 14:25:15 -08:00
asm-offsets.c riscv: uaccess: Only restore the CSR_STATUS SUM bit 2025-06-05 14:03:17 -07:00
bugs.c riscv: Add ghostwrite vulnerability 2025-01-18 12:33:39 -08:00
cacheinfo.c riscv: cacheinfo: Use of_property_present() for non-boolean properties 2025-02-14 13:04:20 -08:00
cfi.c bpf, riscv64/cfi: Support kCFI + BPF on riscv64 2024-03-06 15:18:16 -08:00
compat_signal.c riscv: compat: signal: Add rt_frame implementation 2022-05-17 16:37:21 -07:00
compat_syscall_table.c riscv: convert to generic syscall table 2024-07-10 14:23:38 +02:00
copy-unaligned.h RISC-V: Report vector unaligned access speed hwprobe 2024-10-18 12:38:34 -07:00
copy-unaligned.S riscv: Use SYM_*() assembly macros instead of deprecated ones 2023-11-06 09:42:47 -08:00
cpu_ops_sbi.c riscv: cpu_ops_sbi: Use static array for boot_data 2025-06-30 06:58:11 +00:00
cpu_ops_spinwait.c riscv: prevent pt_regs corruption for secondary idle threads 2024-05-30 09:42:51 -07:00
cpu_ops.c riscv: Use the same CPU operations for all CPUs 2024-01-04 15:03:07 -08:00
cpu-hotplug.c riscv: Use '%u' to format the output of 'cpu' 2024-10-25 06:18:40 -07:00
cpu.c riscv: Add vendor extensions to /proc/cpuinfo 2024-07-22 15:36:55 -07:00
cpufeature.c riscv: Add support for Zicbop 2025-06-05 11:09:37 -07:00
crash_dump.c vmcore: convert copy_oldmem_page() to take an iov_iter 2022-04-29 14:37:59 -07:00
crash_save_regs.S RISC-V: Fixup get incorrect user mode PC for kernel mode regs 2022-08-11 08:54:40 -07:00
efi-header.S include: pe.h: Fix PE definitions 2025-05-21 16:46:37 +02:00
efi.c riscv: Use accessors to page table entries instead of direct dereference 2023-12-20 10:48:15 -08:00
entry.S RISC-V Patches for the 6.16 Merge Window, Part 1 2025-06-06 18:05:18 -07:00
fpu.S RISC-V: Replace RISCV_MISALIGNED with RISCV_SCALAR_MISALIGNED 2024-10-18 12:38:32 -07:00
ftrace.c riscv: ftrace: support direct call using call_ops 2025-06-05 11:09:31 -07:00
head.h riscv: entry: Convert to generic entry 2023-03-23 08:47:00 -07:00
head.S RISC-V: KVM: Remove scounteren initialization 2025-05-21 09:34:55 +05:30
hibernate-asm.S riscv: Use SYM_*() assembly macros instead of deprecated ones 2023-11-06 09:42:47 -08:00
hibernate.c riscv: hibernate: remove WARN_ON in save_processor_state 2023-06-23 10:06:22 -07:00
image-vars.h efi: move screen_info into efi init code 2023-10-17 16:33:39 +02:00
irq.c Merge patch "drivers: perf: Do not broadcast to other cpus when starting a counter" 2023-11-09 06:44:13 -08:00
jump_label.c riscv: Move nop definition to insn-def.h 2025-03-20 09:14:42 +00:00
kernel_mode_fpu.c riscv: add support for kernel-mode FPU 2024-05-19 14:36:19 -07:00
kernel_mode_vector.c riscv: vector: Support xtheadvector save/restore 2025-01-18 12:33:33 -08:00
kexec_elf.c riscv: kexec_file: Split the loading of kernel and others 2025-06-05 11:09:33 -07:00
kexec_image.c riscv: kexec_file: Support loading Image binary file 2025-06-05 11:09:34 -07:00
kexec_relocate.S riscv: kexec: Cleanup riscv_kexec_relocate 2023-09-20 02:53:29 -07:00
kgdb.c riscv: KGDB: Remove ".option norvc/.option rvc" for kgdb_compiled_break 2025-04-16 07:29:34 -07:00
machine_kexec_file.c riscv: kexec_file: Support loading Image binary file 2025-06-05 11:09:34 -07:00
machine_kexec.c kexec: Consolidate machine_kexec_mask_interrupts() implementation 2024-12-11 20:32:34 +01:00
Makefile Kbuild updates for v6.16 2025-06-07 10:05:35 -07:00
Makefile.syscalls syscalls: fix syscall macros for newfstat/newfstatat 2024-08-02 15:20:47 +02:00
mcount-dyn.S riscv: ftrace: support direct call using call_ops 2025-06-05 11:09:31 -07:00
mcount.S riscv: fgraph: Fix stack layout to match __arch_ftrace_regs argument of ftrace_return_to_handler 2025-03-19 12:03:25 +00:00
module-sections.c riscv: module: Optimize PLT/GOT entry counting 2025-06-05 11:09:43 -07:00
module.c riscv: module: Fix out-of-bounds relocation access 2025-04-14 13:07:07 +00:00
paravirt.c RISC-V: KVM: Rename the SBI_STA_SHMEM_DISABLE to a generic name 2024-04-22 11:13:52 +05:30
patch.c asm-generic: introduce text-patching.h 2024-11-07 14:25:15 -08:00
perf_callchain.c The biggest change here is eliminating the awful idea that KVM had, of 2024-11-23 16:00:50 -08:00
perf_regs.c
process.c RISC-V Patches for the 6.16 Merge Window, Part 1 2025-06-06 18:05:18 -07:00
ptrace.c riscv: Allow ptrace control of the tagged address ABI 2024-10-24 14:12:57 -07:00
reset.c riscv: Use do_kernel_power_off() 2022-05-19 19:30:30 +02:00
return_address.c riscv: add CALLER_ADDRx support 2024-02-22 12:17:47 -08:00
riscv_ksyms.c riscv: Omit optimized string routines when using KASAN 2024-09-19 01:10:00 -07:00
sbi_ecall.c riscv: Fix RISCV_ALTERNATIVE_EARLY 2024-09-03 07:57:55 -07:00
sbi-ipi.c RISC-V: Enable the IPI before workqueue_online_cpu() 2024-08-01 07:15:43 -07:00
sbi.c riscv: sbi: add SBI FWFT extension calls 2025-06-04 15:11:02 -07:00
setup.c riscv: export boot_cpu_hartid 2025-06-23 16:30:05 -07:00
signal.c riscv: signal: fix signal frame size 2025-02-14 13:06:44 -08:00
smp.c riscv: print hartid on bringup 2025-04-01 07:03:03 +00:00
smpboot.c riscv: print hartid on bringup 2025-04-01 07:03:03 +00:00
soc.c
stacktrace.c riscv: remove useless pc check in stacktrace handling 2025-03-18 09:06:21 +00:00
suspend_entry.S riscv: Use SYM_*() assembly macros instead of deprecated ones 2023-11-06 09:42:47 -08:00
suspend.c riscv: Add stimecmp save and restore 2025-03-18 12:59:03 +00:00
sys_hwprobe.c Merge tag 'riscv-mw1-6.16-rc1' of ssh://gitolite.kernel.org/pub/scm/linux/kernel/git/alexghiti/linux into for-next 2025-06-05 12:26:06 -07:00
sys_riscv.c syscalls: mmap(): use unsigned offset type consistently 2024-06-25 15:57:38 +02:00
syscall_table.c riscv: convert to generic syscall table 2024-07-10 14:23:38 +02:00
time.c RISC-V: paravirt: Add skeleton for pv-time support 2023-12-30 11:25:03 +05:30
traps_misaligned.c Revert "riscv: misaligned: fix sleeping function called during misaligned access handling" 2025-06-23 15:38:09 -07:00
traps.c riscv: misaligned: enable IRQs while handling misaligned accesses 2025-05-08 12:00:36 +00:00
unaligned_access_speed.c riscv: misaligned: request misaligned exception from SBI 2025-06-04 15:11:03 -07:00
vdso.c riscv: enable mseal sysmap for RV64 2025-06-05 14:03:08 -07:00
vec-copy-unaligned.S riscv: Fix the __riscv_copy_vec_words_unaligned implementation 2025-03-18 13:37:27 +00:00
vector.c RISC-V Patches for the 6.14 Merge Window, Part 1 2025-01-31 15:13:25 -08:00
vendor_extensions.c riscv: Add SiFive xsfvqmaccdod and xsfvqmaccqoq vendor extensions 2025-05-08 11:01:43 -07:00
vmcore_info.c riscv: don't export va_kernel_pa_offset in vmcoreinfo for XIP kernel 2024-09-12 07:22:56 -07:00
vmlinux-xip.lds.S riscv: remove limit on the size of read-only section for XIP kernel 2024-09-12 07:23:02 -07:00
vmlinux.lds.S riscv: Add runtime constant support 2025-03-20 09:15:03 +00:00