Skip to content

Commit 75182b1

Browse files
amlutoIngo Molnar
authored andcommitted
x86/asm/entry: Switch all C consumers of kernel_stack to this_cpu_sp0()
This will make modifying the semantics of kernel_stack easier. The change to ist_begin_non_atomic() is necessary because sp0 no longer points to the same THREAD_SIZE-aligned region as RSP; it's one byte too high for that. At Denys' suggestion, rather than offsetting it, just check explicitly that we're in the correct range ending at sp0. This has the added benefit that we no longer assume that the thread stack is aligned to THREAD_SIZE. Suggested-by: Denys Vlasenko <dvlasenk@redhat.com> Signed-off-by: Andy Lutomirski <luto@amacapital.net> Cc: Borislav Petkov <bp@alien8.de> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Oleg Nesterov <oleg@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/ef8254ad414cbb8034c9a56396eeb24f5dd5b0de.1425611534.git.luto@amacapital.net Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 8ef46a6 commit 75182b1

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed

arch/x86/include/asm/thread_info.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,7 @@ DECLARE_PER_CPU(unsigned long, kernel_stack);
159159
static inline struct thread_info *current_thread_info(void)
160160
{
161161
struct thread_info *ti;
162-
ti = (void *)(this_cpu_read_stable(kernel_stack) +
163-
KERNEL_STACK_OFFSET - THREAD_SIZE);
162+
ti = (void *)(this_cpu_sp0() - THREAD_SIZE);
164163
return ti;
165164
}
166165

arch/x86/kernel/traps.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ void ist_begin_non_atomic(struct pt_regs *regs)
174174
* will catch asm bugs and any attempt to use ist_preempt_enable
175175
* from double_fault.
176176
*/
177-
BUG_ON(((current_stack_pointer() ^ this_cpu_read_stable(kernel_stack))
178-
& ~(THREAD_SIZE - 1)) != 0);
177+
BUG_ON((unsigned long)(this_cpu_sp0() - current_stack_pointer()) >=
178+
THREAD_SIZE);
179179

180180
preempt_count_sub(HARDIRQ_OFFSET);
181181
}

0 commit comments

Comments
 (0)