From: tip-bot for Jeremy Fitzhardinge <jeremy@goop.org>
To: linux-tip-commits@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, hpa@zytor.com, mingo@redhat.com,
jeremy.fitzhardinge@citrix.com, jeremy@goop.org,
stable@kernel.org, tglx@linutronix.de, mingo@elte.hu
Subject: [tip:x86/asm] x86/i386: Make sure stack-protector segment base is cache aligned
Date: Thu, 3 Sep 2009 20:03:39 GMT [thread overview]
Message-ID: <tip-1ea0d14e480c245683927eecc03a70faf06e80c8@git.kernel.org> (raw)
In-Reply-To: <4AA01893.6000507@goop.org>
Commit-ID: 1ea0d14e480c245683927eecc03a70faf06e80c8
Gitweb: http://git.kernel.org/tip/1ea0d14e480c245683927eecc03a70faf06e80c8
Author: Jeremy Fitzhardinge <jeremy@goop.org>
AuthorDate: Thu, 3 Sep 2009 12:27:15 -0700
Committer: Ingo Molnar <mingo@elte.hu>
CommitDate: Thu, 3 Sep 2009 21:30:51 +0200
x86/i386: Make sure stack-protector segment base is cache aligned
The Intel Optimization Reference Guide says:
In Intel Atom microarchitecture, the address generation unit
assumes that the segment base will be 0 by default. Non-zero
segment base will cause load and store operations to experience
a delay.
- If the segment base isn't aligned to a cache line
boundary, the max throughput of memory operations is
reduced to one [e]very 9 cycles.
[...]
Assembly/Compiler Coding Rule 15. (H impact, ML generality)
For Intel Atom processors, use segments with base set to 0
whenever possible; avoid non-zero segment base address that is
not aligned to cache line boundary at all cost.
We can't avoid having a non-zero base for the stack-protector
segment, but we can make it cache-aligned.
Signed-off-by: Jeremy Fitzhardinge <jeremy.fitzhardinge@citrix.com>
Cc: <stable@kernel.org>
LKML-Reference: <4AA01893.6000507@goop.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
---
arch/x86/include/asm/processor.h | 12 +++++++++++-
arch/x86/include/asm/stackprotector.h | 4 ++--
arch/x86/include/asm/system.h | 2 +-
arch/x86/kernel/cpu/common.c | 2 +-
arch/x86/kernel/head_32.S | 1 -
5 files changed, 15 insertions(+), 6 deletions(-)
diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
index c776826..e597ecc 100644
--- a/arch/x86/include/asm/processor.h
+++ b/arch/x86/include/asm/processor.h
@@ -403,7 +403,17 @@ extern unsigned long kernel_eflags;
extern asmlinkage void ignore_sysret(void);
#else /* X86_64 */
#ifdef CONFIG_CC_STACKPROTECTOR
-DECLARE_PER_CPU(unsigned long, stack_canary);
+/*
+ * Make sure stack canary segment base is cached-aligned:
+ * "For Intel Atom processors, avoid non zero segment base address
+ * that is not aligned to cache line boundary at all cost."
+ * (Optim Ref Manual Assembly/Compiler Coding Rule 15.)
+ */
+struct stack_canary {
+ char __pad[20]; /* canary at %gs:20 */
+ unsigned long canary;
+};
+DECLARE_PER_CPU(struct stack_canary, stack_canary) ____cacheline_aligned;
#endif
#endif /* X86_64 */
diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
index 44efdff..1575177 100644
--- a/arch/x86/include/asm/stackprotector.h
+++ b/arch/x86/include/asm/stackprotector.h
@@ -78,14 +78,14 @@ static __always_inline void boot_init_stack_canary(void)
#ifdef CONFIG_X86_64
percpu_write(irq_stack_union.stack_canary, canary);
#else
- percpu_write(stack_canary, canary);
+ percpu_write(stack_canary.canary, canary);
#endif
}
static inline void setup_stack_canary_segment(int cpu)
{
#ifdef CONFIG_X86_32
- unsigned long canary = (unsigned long)&per_cpu(stack_canary, cpu) - 20;
+ unsigned long canary = (unsigned long)&per_cpu(stack_canary, cpu);
struct desc_struct *gdt_table = get_cpu_gdt_table(cpu);
struct desc_struct desc;
diff --git a/arch/x86/include/asm/system.h b/arch/x86/include/asm/system.h
index 75c49c7..f08f973 100644
--- a/arch/x86/include/asm/system.h
+++ b/arch/x86/include/asm/system.h
@@ -31,7 +31,7 @@ void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
"movl %P[task_canary](%[next]), %%ebx\n\t" \
"movl %%ebx, "__percpu_arg([stack_canary])"\n\t"
#define __switch_canary_oparam \
- , [stack_canary] "=m" (per_cpu_var(stack_canary))
+ , [stack_canary] "=m" (per_cpu_var(stack_canary.canary))
#define __switch_canary_iparam \
, [task_canary] "i" (offsetof(struct task_struct, stack_canary))
#else /* CC_STACKPROTECTOR */
diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
index ced07ba..7d84bc4 100644
--- a/arch/x86/kernel/cpu/common.c
+++ b/arch/x86/kernel/cpu/common.c
@@ -1043,7 +1043,7 @@ DEFINE_PER_CPU(struct orig_ist, orig_ist);
#else /* CONFIG_X86_64 */
#ifdef CONFIG_CC_STACKPROTECTOR
-DEFINE_PER_CPU(unsigned long, stack_canary);
+DEFINE_PER_CPU(struct stack_canary, stack_canary) ____cacheline_aligned;
#endif
/* Make sure %fs and %gs are initialized properly in idle threads */
diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
index cc827ac..7ffec6b 100644
--- a/arch/x86/kernel/head_32.S
+++ b/arch/x86/kernel/head_32.S
@@ -439,7 +439,6 @@ is386: movl $2,%ecx # set MP
jne 1f
movl $per_cpu__gdt_page,%eax
movl $per_cpu__stack_canary,%ecx
- subl $20, %ecx
movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
shrl $16, %ecx
movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
next prev parent reply other threads:[~2009-09-03 20:04 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-03 19:27 [PATCH] x86/i386: make sure stack-protector segment base is cache aligned Jeremy Fitzhardinge
2009-09-03 19:47 ` Eric Dumazet
2009-09-03 20:41 ` Jeremy Fitzhardinge
2009-09-03 21:07 ` Eric Dumazet
2009-09-03 21:31 ` Jeremy Fitzhardinge
2009-09-04 7:58 ` [tip:x86/asm] x86/i386: Put aligned stack-canary in percpu shared_aligned section tip-bot for Jeremy Fitzhardinge
2009-09-03 20:03 ` tip-bot for Jeremy Fitzhardinge [this message]
2009-09-03 20:26 ` [tip:x86/asm] x86/i386: Make sure stack-protector segment base is cache aligned H. Peter Anvin
2009-09-03 20:45 ` Jeremy Fitzhardinge
2009-09-03 21:15 ` H. Peter Anvin
2009-09-03 21:18 ` Ingo Molnar
2009-09-03 21:21 ` H. Peter Anvin
2009-09-04 14:15 ` Arjan van de Ven
2009-09-04 15:59 ` Jeremy Fitzhardinge
2009-09-04 16:06 ` H. Peter Anvin
2009-09-03 21:28 ` Jeremy Fitzhardinge
2009-09-04 2:51 ` Tejun Heo
2009-09-04 2:59 ` Tejun Heo
2009-09-04 3:35 ` H. Peter Anvin
2009-09-04 3:47 ` Tejun Heo
2009-09-04 3:51 ` H. Peter Anvin
2009-09-04 5:06 ` Tejun Heo
2009-09-04 5:12 ` Ingo Molnar
2009-09-04 16:04 ` Jeremy Fitzhardinge
2009-09-04 16:09 ` Tejun Heo
2009-09-04 16:13 ` H. Peter Anvin
2009-09-04 16:01 ` Jeremy Fitzhardinge
2009-09-04 16:52 ` H. Peter Anvin
2009-09-04 16:57 ` Jeremy Fitzhardinge
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=tip-1ea0d14e480c245683927eecc03a70faf06e80c8@git.kernel.org \
--to=jeremy@goop.org \
--cc=hpa@zytor.com \
--cc=jeremy.fitzhardinge@citrix.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=mingo@redhat.com \
--cc=stable@kernel.org \
--cc=tglx@linutronix.de \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox