Re: [PATCH v2 -tip] x86/percpu: Use C for arch_raw_cpu_ptr()

From: Nadav Amit
Date: Wed Oct 18 2023 - 06:55:52 EST




> On Oct 18, 2023, at 12:04 PM, Uros Bizjak <ubizjak@xxxxxxxxx> wrote:
>
> Solved.
>
> All that is needed is to patch cpu_init() from
> arch/x86/kernel/cpu/common.c with:
>
> --cut here--
> diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
> index b14fc8c1c953..61b6fcdf6937 100644
> --- a/arch/x86/kernel/cpu/common.c
> +++ b/arch/x86/kernel/cpu/common.c
> @@ -2228,7 +2232,7 @@ void cpu_init_exception_handling(void)
> */
> void cpu_init(void)
> {
> - struct task_struct *cur = current;
> + struct task_struct *cur = this_cpu_read_stable(pcpu_hot.current_task);
> int cpu = raw_smp_processor_id();

Thanks for solving that, and sorry that I missed it.

The reason I didn’t encounter it before is that in my original patch I created
a new compilation unit which only defined the alias.

Since there might be additional problems (any “current” use in common.c is
dangerous, even in included files), I think that while there may be additional
solutions, defining the alias in a separate compilation unit - as I did before -
is the safest.