All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Yunhui Cui" <cuiyunhui@bytedance.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH v8 3/3] riscv: store percpu offset into thread_info
Date: Fri, 03 Jul 2026 12:54:17 +0000	[thread overview]
Message-ID: <20260703125418.573231F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260703122832.15984-4-cuiyunhui@bytedance.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Missing initialization of `pcpu_offset` in `arch_cpuhp_kick_ap_alive` causes secondary CPUs to use the boot CPU's per-cpu data during early boot, leading to memory corruption.
--

commit cfb659978a0a1c24330d1d94b1f3e36871d66657
Author: Yunhui Cui <cuiyunhui@bytedance.com>

riscv: store percpu offset into thread_info
    
RISC-V percpu addressing currently derives the base offset from the CPU
number and __per_cpu_offset[]. Cache the current CPU percpu offset in
thread_info so percpu accesses can load it directly. Keep the cached value
up to date for the boot CPU, context switches and secondary CPU bringup.

Link: https://lists.riscv.org/g/tech-privileged/topic/risc_v_tech_arch_review/113437553?page=2

> diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c
> index f6ef57930b50a..7876854d16279 100644
> --- a/arch/riscv/kernel/smpboot.c
> +++ b/arch/riscv/kernel/smpboot.c

[ ... ]

> @@ -191,6 +191,7 @@ int __cpu_up(unsigned int cpu, struct task_struct *tidle)
>  {
>  	int ret;
>  	tidle->thread_info.cpu = cpu;
> +	tidle->thread_info.pcpu_offset = per_cpu_offset(cpu);
>  

[Severity: High]
Does this code also need to update arch_cpuhp_kick_ap_alive() for the
CONFIG_HOTPLUG_PARALLEL case?

If CONFIG_HOTPLUG_PARALLEL is enabled, secondary CPUs are booted via
arch_cpuhp_kick_ap_alive() instead of __cpu_up(). Because the idle thread
is forked from init_task, it inherits CPU 0's pcpu_offset.

Without initializing tidle->thread_info.pcpu_offset in
arch_cpuhp_kick_ap_alive(), the secondary CPU will start executing with
CPU 0's per-cpu offset.

Any per-cpu access before __my_cpu_offset is explicitly re-initialized
in smp_callin() will concurrently modify CPU 0's per-cpu state without
locking, which could lead to memory corruption.

>  	ret = start_secondary_cpu(cpu, tidle);
>  	if (!ret) {

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260703122832.15984-1-cuiyunhui@bytedance.com?part=3

  reply	other threads:[~2026-07-03 12:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-03 12:28 [PATCH v8 0/3] riscv: fix PIO helpers and add optimized percpu ops Yunhui Cui
2026-07-03 12:28 ` Yunhui Cui
2026-07-03 12:28 ` [PATCH v8 1/3] riscv: io: avoid null-pointer arithmetic in PIO helpers Yunhui Cui
2026-07-03 12:28   ` Yunhui Cui
2026-07-13 18:03   ` Paul Walmsley
2026-07-13 18:03     ` Paul Walmsley
2026-07-14  6:23     ` [External] " yunhui cui
2026-07-14  6:23       ` yunhui cui
2026-07-03 12:28 ` [PATCH v8 2/3] riscv: introduce percpu.h into include/asm Yunhui Cui
2026-07-03 12:28   ` Yunhui Cui
2026-07-03 12:28 ` [PATCH v8 3/3] riscv: store percpu offset into thread_info Yunhui Cui
2026-07-03 12:28   ` Yunhui Cui
2026-07-03 12:54   ` sashiko-bot [this message]
2026-07-03 21:02   ` Thomas Gleixner
2026-07-03 21:02     ` Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260703125418.573231F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cuiyunhui@bytedance.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.