Patch "powerpc/64: Fix task_cpu in early boot when booting non-zero cpuid" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    powerpc/64: Fix task_cpu in early boot when booting non-zero cpuid

to the 6.1-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     powerpc-64-fix-task_cpu-in-early-boot-when-booting-n.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 25a79a5199e1332eab0c9e63969ce0a2c26fc4ab
Author: Nicholas Piggin <npiggin@xxxxxxxxx>
Date:   Fri Dec 16 21:59:28 2022 +1000

    powerpc/64: Fix task_cpu in early boot when booting non-zero cpuid
    
    [ Upstream commit 9fa24404f5044967753a6cd3e5e36f57686bec6e ]
    
    powerpc/64 can boot on a non-zero SMP processor id. Initially, the boot
    CPU is said to be "assumed to be 0" until early_init_devtree() discovers
    the id from the device tree. That is not a good description because the
    assumption can be wrong and that has to be handled, the better
    description is that 0 is used as a placeholder, and things are fixed
    after the real id is discovered.
    
    smp_processor_id() is set to the boot cpuid, but task_cpu(current) is
    not, which causes the smp_processor_id() == task_cpu(current) invariant
    to be broken until init_idle() in sched_init().
    
    This is quite fragile and could lead to subtle bugs in future. One bug
    is that validate_sp_size uses task_cpu() to get the process stack, so
    any stack trace from the booting CPU between early_init_devtree()
    and sched_init() will have problems. Early on paca_ptrs[0] will be
    poisoned, so that can cause machine checks dereferencing that memory
    in real mode. Later, validating the current stack pointer against the
    idle task of a different secondary will probably cause no stack trace
    to be printed.
    
    Fix this by setting thread_info->cpu right after smp_processor_id() is
    set to the boot cpuid.
    
    Signed-off-by: Nicholas Piggin <npiggin@xxxxxxxxx>
    [mpe: Fix SMP=n build as reported by sfr]
    Signed-off-by: Michael Ellerman <mpe@xxxxxxxxxxxxxx>
    Link: https://lore.kernel.org/r/20221216115930.2667772-3-npiggin@xxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index a0dee7354fe6b..a43865e0fb4bf 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -396,6 +396,11 @@ void __init early_setup(unsigned long dt_ptr)
 	}
 	fixup_boot_paca(paca_ptrs[boot_cpuid]);
 	setup_paca(paca_ptrs[boot_cpuid]); /* install the paca into registers */
+	// smp_processor_id() now reports boot_cpuid
+
+#ifdef CONFIG_SMP
+	task_thread_info(current)->cpu = boot_cpuid; // fix task_cpu(current)
+#endif
 
 	/*
 	 * Configure exception handlers. This include setting up trampolines



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux