* [PATCH 1/2] powerpc/mce: mce_init use early_cpu_to_node
@ 2022-07-11 3:06 Nicholas Piggin
2022-07-11 3:06 ` [PATCH 2/2] powerpc/64: poison __per_cpu_offset to catch use-before-init Nicholas Piggin
2022-07-29 13:02 ` [PATCH 1/2] powerpc/mce: mce_init use early_cpu_to_node Michael Ellerman
0 siblings, 2 replies; 4+ messages in thread
From: Nicholas Piggin @ 2022-07-11 3:06 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Ganesh Goudar, Nicholas Piggin
cpu_to_node is not available (setup_arch() is called before
setup_per_cpu_areas() by start_kernel()).
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/kernel/mce.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/powerpc/kernel/mce.c b/arch/powerpc/kernel/mce.c
index 18173199b79d..6c5d30fba766 100644
--- a/arch/powerpc/kernel/mce.c
+++ b/arch/powerpc/kernel/mce.c
@@ -756,7 +756,7 @@ void __init mce_init(void)
mce_info = memblock_alloc_try_nid(sizeof(*mce_info),
__alignof__(*mce_info),
MEMBLOCK_LOW_LIMIT,
- limit, cpu_to_node(i));
+ limit, early_cpu_to_node(i));
if (!mce_info)
goto err;
paca_ptrs[i]->mce_info = mce_info;
--
2.35.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] powerpc/64: poison __per_cpu_offset to catch use-before-init
2022-07-11 3:06 [PATCH 1/2] powerpc/mce: mce_init use early_cpu_to_node Nicholas Piggin
@ 2022-07-11 3:06 ` Nicholas Piggin
2022-08-01 12:02 ` Michael Ellerman
2022-07-29 13:02 ` [PATCH 1/2] powerpc/mce: mce_init use early_cpu_to_node Michael Ellerman
1 sibling, 1 reply; 4+ messages in thread
From: Nicholas Piggin @ 2022-07-11 3:06 UTC (permalink / raw)
To: linuxppc-dev; +Cc: Ganesh Goudar, Nicholas Piggin
If the boot CPU tries to access per-cpu data of other CPUs before
per cpu areas are set up, it will unexpectedly use offset 0.
Try to catch such accesses by poisoning the __per_cpu_offset array.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
arch/powerpc/include/asm/percpu.h | 1 +
arch/powerpc/kernel/paca.c | 2 +-
arch/powerpc/kernel/setup_64.c | 2 +-
3 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/arch/powerpc/include/asm/percpu.h b/arch/powerpc/include/asm/percpu.h
index 8e5b7d0b851c..6ca1a9fc5725 100644
--- a/arch/powerpc/include/asm/percpu.h
+++ b/arch/powerpc/include/asm/percpu.h
@@ -7,6 +7,7 @@
* Same as asm-generic/percpu.h, except that we store the per cpu offset
* in the paca. Based on the x86-64 implementation.
*/
+#define PER_CPU_OFFSET_POISON 0xfeeeeeeeeeeeeeeeULL
#ifdef CONFIG_SMP
diff --git a/arch/powerpc/kernel/paca.c b/arch/powerpc/kernel/paca.c
index ba593fd60124..914d27c8b84a 100644
--- a/arch/powerpc/kernel/paca.c
+++ b/arch/powerpc/kernel/paca.c
@@ -223,7 +223,7 @@ void __init initialise_paca(struct paca_struct *new_paca, int cpu)
new_paca->hw_cpu_id = 0xffff;
new_paca->kexec_state = KEXEC_STATE_NONE;
new_paca->__current = &init_task;
- new_paca->data_offset = 0xfeeeeeeeeeeeeeeeULL;
+ new_paca->data_offset = PER_CPU_OFFSET_POISON;
#ifdef CONFIG_PPC_64S_HASH_MMU
new_paca->slb_shadow_ptr = NULL;
#endif
diff --git a/arch/powerpc/kernel/setup_64.c b/arch/powerpc/kernel/setup_64.c
index 5761f08dae95..60f0d1258526 100644
--- a/arch/powerpc/kernel/setup_64.c
+++ b/arch/powerpc/kernel/setup_64.c
@@ -812,7 +812,7 @@ static __init int pcpu_cpu_to_node(int cpu)
return early_cpu_to_node(cpu);
}
-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly;
+unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = { [0 ... NR_CPUS-1 ] = PER_CPU_OFFSET_POISON };
EXPORT_SYMBOL(__per_cpu_offset);
void __init setup_per_cpu_areas(void)
--
2.35.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] powerpc/mce: mce_init use early_cpu_to_node
2022-07-11 3:06 [PATCH 1/2] powerpc/mce: mce_init use early_cpu_to_node Nicholas Piggin
2022-07-11 3:06 ` [PATCH 2/2] powerpc/64: poison __per_cpu_offset to catch use-before-init Nicholas Piggin
@ 2022-07-29 13:02 ` Michael Ellerman
1 sibling, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2022-07-29 13:02 UTC (permalink / raw)
To: Nicholas Piggin, linuxppc-dev; +Cc: Ganesh Goudar
On Mon, 11 Jul 2022 13:06:52 +1000, Nicholas Piggin wrote:
> cpu_to_node is not available (setup_arch() is called before
> setup_per_cpu_areas() by start_kernel()).
>
>
Patch 1 applied to powerpc/next.
[1/2] powerpc/mce: mce_init use early_cpu_to_node
https://git.kernel.org/powerpc/c/f57261e69825b332f22480b37a33e03d066c0da2
cheers
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] powerpc/64: poison __per_cpu_offset to catch use-before-init
2022-07-11 3:06 ` [PATCH 2/2] powerpc/64: poison __per_cpu_offset to catch use-before-init Nicholas Piggin
@ 2022-08-01 12:02 ` Michael Ellerman
0 siblings, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2022-08-01 12:02 UTC (permalink / raw)
To: Nicholas Piggin, linuxppc-dev; +Cc: Ganesh Goudar, Nicholas Piggin
Nicholas Piggin <npiggin@gmail.com> writes:
> If the boot CPU tries to access per-cpu data of other CPUs before
> per cpu areas are set up, it will unexpectedly use offset 0.
>
> Try to catch such accesses by poisoning the __per_cpu_offset array.
I wasn't sure about this.
On bare metal it's just an instant checkstop which is very user hostile.
I worry it's just going to cause unusual configurations/options to crash
for folks, like eg. booting with page_poison=1 did a while back.
Can we put it behind a debug option? Maybe CONFIG_DEBUG_VM ?
cheers
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-08-01 12:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-11 3:06 [PATCH 1/2] powerpc/mce: mce_init use early_cpu_to_node Nicholas Piggin
2022-07-11 3:06 ` [PATCH 2/2] powerpc/64: poison __per_cpu_offset to catch use-before-init Nicholas Piggin
2022-08-01 12:02 ` Michael Ellerman
2022-07-29 13:02 ` [PATCH 1/2] powerpc/mce: mce_init use early_cpu_to_node Michael Ellerman
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.