2010-02-13 01:40:31

by Jacob Pan

[permalink] [raw]
Subject: [PATCH 6/9] x86: initialize stack canary in secondary start

>From 0d84c04b845a36cf43aaa14c175ef10ff5e50480 Mon Sep 17 00:00:00 2001
From: Jacob Pan <[email protected]>
Date: Thu, 17 Sep 2009 07:36:43 -0700
Subject: [PATCH 6/9] x86: initialize stack canary in secondary start

some secondary clockevent setup code needs to call request_irq, which will
cause fake stack check failure in schedule() if voluntary preemption
model is chosen, it is safe to have stack canary initialized here early,
since start_secondary() does not return.

Signed-off-by: Jacob Pan <[email protected]>
---
arch/x86/kernel/smpboot.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 678d0b8..56ce974 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -48,6 +48,7 @@
#include <linux/err.h>
#include <linux/nmi.h>
#include <linux/tboot.h>
+#include <linux/stackprotector.h>

#include <asm/acpi.h>
#include <asm/desc.h>
@@ -324,6 +325,9 @@ notrace static void __cpuinit start_secondary(void *unused)
/* enable local interrupts */
local_irq_enable();

+ /* to prevent fake stack check failure in clock setup */
+ boot_init_stack_canary();
+
x86_cpuinit.setup_percpu_clockev();

wmb();
--
1.6.5.3


2010-02-20 01:30:20

by Jacob Pan

[permalink] [raw]
Subject: [tip:x86/mrst] x86: Initialize stack canary in secondary start

Commit-ID: 35f720c5930f689647d51ad77e2a8d6f0abf66c8
Gitweb: http://git.kernel.org/tip/35f720c5930f689647d51ad77e2a8d6f0abf66c8
Author: Jacob Pan <[email protected]>
AuthorDate: Thu, 17 Sep 2009 07:36:43 -0700
Committer: H. Peter Anvin <[email protected]>
CommitDate: Fri, 19 Feb 2010 16:25:17 -0800

x86: Initialize stack canary in secondary start

Some secondary clockevent setup code needs to call request_irq, which
will cause fake stack check failure in schedule() if voluntary
preemption model is chosen. It is safe to have stack canary
initialized here early, since start_secondary() does not return.

Signed-off-by: Jacob Pan <[email protected]>
LKML-Reference: <43F901BD926A4E43B106BF17856F07559FB80D02@orsmsx508.amr.corp.intel.com>
Signed-off-by: H. Peter Anvin <[email protected]>
---
arch/x86/kernel/smpboot.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)

diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index b4e870c..3e6150d 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -48,6 +48,7 @@
#include <linux/err.h>
#include <linux/nmi.h>
#include <linux/tboot.h>
+#include <linux/stackprotector.h>

#include <asm/acpi.h>
#include <asm/desc.h>
@@ -324,6 +325,9 @@ notrace static void __cpuinit start_secondary(void *unused)
/* enable local interrupts */
local_irq_enable();

+ /* to prevent fake stack check failure in clock setup */
+ boot_init_stack_canary();
+
x86_cpuinit.setup_percpu_clockev();

wmb();

2010-02-20 08:04:57

by Thomas Gleixner

[permalink] [raw]
Subject: Re: [tip:x86/mrst] x86: Initialize stack canary in secondary start

On Sat, 20 Feb 2010, tip-bot for Jacob Pan wrote:

> Commit-ID: 35f720c5930f689647d51ad77e2a8d6f0abf66c8
> Gitweb: http://git.kernel.org/tip/35f720c5930f689647d51ad77e2a8d6f0abf66c8
> Author: Jacob Pan <[email protected]>
> AuthorDate: Thu, 17 Sep 2009 07:36:43 -0700
> Committer: H. Peter Anvin <[email protected]>
> CommitDate: Fri, 19 Feb 2010 16:25:17 -0800
>
> x86: Initialize stack canary in secondary start
>
> Some secondary clockevent setup code needs to call request_irq, which
> will cause fake stack check failure in schedule() if voluntary
> preemption model is chosen. It is safe to have stack canary
> initialized here early, since start_secondary() does not return.

So with that patch applied we can remove the boot_init_stack_canary()
in process_32/64.c cpu_idle(), can't we ?

Thanks,

tglx


> Signed-off-by: Jacob Pan <[email protected]>
> LKML-Reference: <43F901BD926A4E43B106BF17856F07559FB80D02@orsmsx508.amr.corp.intel.com>
> Signed-off-by: H. Peter Anvin <[email protected]>
> ---
> arch/x86/kernel/smpboot.c | 4 ++++
> 1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
> index b4e870c..3e6150d 100644
> --- a/arch/x86/kernel/smpboot.c
> +++ b/arch/x86/kernel/smpboot.c
> @@ -48,6 +48,7 @@
> #include <linux/err.h>
> #include <linux/nmi.h>
> #include <linux/tboot.h>
> +#include <linux/stackprotector.h>
>
> #include <asm/acpi.h>
> #include <asm/desc.h>
> @@ -324,6 +325,9 @@ notrace static void __cpuinit start_secondary(void *unused)
> /* enable local interrupts */
> local_irq_enable();
>
> + /* to prevent fake stack check failure in clock setup */
> + boot_init_stack_canary();
> +
> x86_cpuinit.setup_percpu_clockev();
>
> wmb();
>

2010-02-22 18:24:18

by Jacob Pan

[permalink] [raw]
Subject: RE: [tip:x86/mrst] x86: Initialize stack canary in secondary start


>So with that patch applied we can remove the boot_init_stack_canary()
>in process_32/64.c cpu_idle(), can't we ?
>

[[JPAN]] i agree, bsp stack canary will be initialized in start_kernel() and
ap stack canary will be covered in start_secondary().
arjan, do you have any comments? here is the new patch.

>From 1073c9f6e1e3b0012f85b5a9c7c83e35bcc16107 Mon Sep 17 00:00:00 2001
From: Jacob Pan <[email protected]>
Date: Mon, 22 Feb 2010 04:14:11 -0800
Subject: [PATCH] x86/boot: reduce redundant stack canary init

move secondary cpu boot stack canary initialization prior to cpu_idle()
then remove boot_init_stack_canary() calls from cpu_idle().
this change reduced redundent stack canary init for the bsp also avoid
fake stack check failure for secondary if early schedule needed before
cpu_idle.

Signed-off-by: Jacob Pan <[email protected]>
---
arch/x86/kernel/process_32.c | 9 ---------
arch/x86/kernel/process_64.c | 9 ---------
arch/x86/kernel/smpboot.c | 4 ++++
3 files changed, 4 insertions(+), 18 deletions(-)

diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
index f6c6266..d4c764a 100644
--- a/arch/x86/kernel/process_32.c
+++ b/arch/x86/kernel/process_32.c
@@ -85,15 +85,6 @@ void cpu_idle(void)
{
int cpu = smp_processor_id();

- /*
- * If we're the non-boot CPU, nothing set the stack canary up
- * for us. CPU0 already has it initialized but no harm in
- * doing it again. This is a good place for updating it, as
- * we wont ever return from this function (so the invalid
- * canaries already on the stack wont ever trigger).
- */
- boot_init_stack_canary();
-
current_thread_info()->status |= TS_POLLING;

/* endless idle loop with no priority at all */
diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
index fc6ad4b..1fd6713 100644
--- a/arch/x86/kernel/process_64.c
+++ b/arch/x86/kernel/process_64.c
@@ -110,15 +110,6 @@ void cpu_idle(void)
{
current_thread_info()->status |= TS_POLLING;

- /*
- * If we're the non-boot CPU, nothing set the stack canary up
- * for us. CPU0 already has it initialized but no harm in
- * doing it again. This is a good place for updating it, as
- * we wont ever return from this function (so the invalid
- * canaries already on the stack wont ever trigger).
- */
- boot_init_stack_canary();
-
/* endless idle loop with no priority at all */
while (1) {
tick_nohz_stop_sched_tick(1);
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index c08829a..820638d 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -48,6 +48,7 @@
#include <linux/err.h>
#include <linux/nmi.h>
#include <linux/tboot.h>
+#include <linux/stackprotector.h>

#include <asm/acpi.h>
#include <asm/desc.h>
@@ -328,6 +329,9 @@ notrace static void __cpuinit start_secondary(void *unused)
/* enable local interrupts */
local_irq_enable();

+ /* to prevent fake stack check failure in clock setup */
+ boot_init_stack_canary();
+
x86_cpuinit.setup_percpu_clockev();

wmb();
--
1.5.6.5