Skip to content

Commit 8ef46a6

Browse files
amlutoIngo Molnar
authored andcommitted
x86/asm/entry: Add this_cpu_sp0() to read sp0 for the current cpu
We currently store references to the top of the kernel stack in multiple places: kernel_stack (with an offset) and init_tss.x86_tss.sp0 (no offset). The latter is defined by hardware and is a clean canonical way to find the top of the stack. Add an accessor so we can start using it. This needs minor paravirt tweaks. On native, sp0 defines the top of the kernel stack and is therefore always correct. On Xen and lguest, the hypervisor tracks the top of the stack, but we want to start reading sp0 in the kernel. Fixing this is simple: just update our local copy of sp0 as well as the hypervisor's copy on task switches. Signed-off-by: Andy Lutomirski <luto@amacapital.net> Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com> Cc: Borislav Petkov <bp@alien8.de> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Rusty Russell <rusty@rustcorp.com.au> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/8d675581859712bee09a055ed8f785d80dac1eca.1425611534.git.luto@amacapital.net Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 5eca745 commit 8ef46a6

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

arch/x86/include/asm/processor.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,11 @@ static inline void native_swapgs(void)
564564
#endif
565565
}
566566

567+
static inline unsigned long this_cpu_sp0(void)
568+
{
569+
return this_cpu_read_stable(init_tss.x86_tss.sp0);
570+
}
571+
567572
#ifdef CONFIG_PARAVIRT
568573
#include <asm/paravirt.h>
569574
#else

arch/x86/kernel/process.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
* on exact cacheline boundaries, to eliminate cacheline ping-pong.
3939
*/
4040
__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
41+
EXPORT_PER_CPU_SYMBOL_GPL(init_tss);
4142

4243
#ifdef CONFIG_X86_64
4344
static DEFINE_PER_CPU(unsigned char, is_idle);

arch/x86/lguest/boot.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,7 @@ static void lguest_load_sp0(struct tss_struct *tss,
10761076
{
10771077
lazy_hcall3(LHCALL_SET_STACK, __KERNEL_DS | 0x1, thread->sp0,
10781078
THREAD_SIZE / PAGE_SIZE);
1079+
tss->x86_tss.sp0 = thread->sp0;
10791080
}
10801081

10811082
/* Let's just say, I wouldn't do debugging under a Guest. */

arch/x86/xen/enlighten.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ static void xen_load_sp0(struct tss_struct *tss,
912912
mcs = xen_mc_entry(0);
913913
MULTI_stack_switch(mcs.mc, __KERNEL_DS, thread->sp0);
914914
xen_mc_issue(PARAVIRT_LAZY_CPU);
915+
tss->x86_tss.sp0 = thread->sp0;
915916
}
916917

917918
static void xen_set_iopl_mask(unsigned mask)

0 commit comments

Comments
 (0)