Skip to content

Commit 97245d0

Browse files
torvaldsIngo Molnar
authored andcommitted
x86/entry: Get rid of pt_regs_to_thread_info()
It was a nice optimization while it lasted, but thread_info is moving and this optimization will no longer work. Quoting Linus: Oh Gods, Andy. That pt_regs_to_thread_info() thing made me want to do unspeakable acts on a poor innocent wax figure that looked _exactly_ like you. [ Changelog written by Andy. ] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Andy Lutomirski <luto@kernel.org> Cc: Borislav Petkov <bp@alien8.de> Cc: Brian Gerst <brgerst@gmail.com> Cc: Denys Vlasenko <dvlasenk@redhat.com> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Jann Horn <jann@thejh.net> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lkml.kernel.org/r/6376aa81c68798cc81631673f52bd91a3e078944.1473801993.git.luto@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent b9d989c commit 97245d0

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

arch/x86/entry/common.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@
3131
#define CREATE_TRACE_POINTS
3232
#include <trace/events/syscalls.h>
3333

34-
static struct thread_info *pt_regs_to_thread_info(struct pt_regs *regs)
35-
{
36-
unsigned long top_of_stack =
37-
(unsigned long)(regs + 1) + TOP_OF_KERNEL_STACK_PADDING;
38-
return (struct thread_info *)(top_of_stack - THREAD_SIZE);
39-
}
40-
4134
#ifdef CONFIG_CONTEXT_TRACKING
4235
/* Called on entry from user mode with IRQs off. */
4336
__visible inline void enter_from_user_mode(void)
@@ -71,7 +64,7 @@ static long syscall_trace_enter(struct pt_regs *regs)
7164
{
7265
u32 arch = in_ia32_syscall() ? AUDIT_ARCH_I386 : AUDIT_ARCH_X86_64;
7366

74-
struct thread_info *ti = pt_regs_to_thread_info(regs);
67+
struct thread_info *ti = current_thread_info();
7568
unsigned long ret = 0;
7669
bool emulated = false;
7770
u32 work;
@@ -173,18 +166,17 @@ static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags)
173166
/* Disable IRQs and retry */
174167
local_irq_disable();
175168

176-
cached_flags = READ_ONCE(pt_regs_to_thread_info(regs)->flags);
169+
cached_flags = READ_ONCE(current_thread_info()->flags);
177170

178171
if (!(cached_flags & EXIT_TO_USERMODE_LOOP_FLAGS))
179172
break;
180-
181173
}
182174
}
183175

184176
/* Called with IRQs disabled. */
185177
__visible inline void prepare_exit_to_usermode(struct pt_regs *regs)
186178
{
187-
struct thread_info *ti = pt_regs_to_thread_info(regs);
179+
struct thread_info *ti = current_thread_info();
188180
u32 cached_flags;
189181

190182
if (IS_ENABLED(CONFIG_PROVE_LOCKING) && WARN_ON(!irqs_disabled()))
@@ -247,7 +239,7 @@ static void syscall_slow_exit_work(struct pt_regs *regs, u32 cached_flags)
247239
*/
248240
__visible inline void syscall_return_slowpath(struct pt_regs *regs)
249241
{
250-
struct thread_info *ti = pt_regs_to_thread_info(regs);
242+
struct thread_info *ti = current_thread_info();
251243
u32 cached_flags = READ_ONCE(ti->flags);
252244

253245
CT_WARN_ON(ct_state() != CONTEXT_KERNEL);
@@ -270,7 +262,7 @@ __visible inline void syscall_return_slowpath(struct pt_regs *regs)
270262
#ifdef CONFIG_X86_64
271263
__visible void do_syscall_64(struct pt_regs *regs)
272264
{
273-
struct thread_info *ti = pt_regs_to_thread_info(regs);
265+
struct thread_info *ti = current_thread_info();
274266
unsigned long nr = regs->orig_ax;
275267

276268
enter_from_user_mode();
@@ -303,7 +295,7 @@ __visible void do_syscall_64(struct pt_regs *regs)
303295
*/
304296
static __always_inline void do_syscall_32_irqs_on(struct pt_regs *regs)
305297
{
306-
struct thread_info *ti = pt_regs_to_thread_info(regs);
298+
struct thread_info *ti = current_thread_info();
307299
unsigned int nr = (unsigned int)regs->orig_ax;
308300

309301
#ifdef CONFIG_IA32_EMULATION

0 commit comments

Comments
 (0)