aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/entry/common.c
diff options
context:
space:
mode:
authorAndy Lutomirski <luto@kernel.org>2015-10-05 20:48:23 -0400
committerIngo Molnar <mingo@kernel.org>2015-10-09 03:41:13 -0400
commit39b48e575e92e31251b74b4b48cea2129cee90bd (patch)
tree0a57f6053546e0a191920e99415ad9e605231aeb /arch/x86/entry/common.c
parentdd636071c3d8044c802b7a365e9934724a929530 (diff)
x86/entry: Split and inline prepare_exit_to_usermode()
GCC is unable to properly optimize functions that have a very short likely case and a longer and register-heavier cold part -- it fails to sink all of the register saving and stack frame setup code into the unlikely part. Help it out with prepare_exit_to_usermode() by splitting it into two parts and inline the hot part. Saves 6-8 cycles for compat syscalls. Signed-off-by: Andy Lutomirski <luto@kernel.org> Cc: Andy Lutomirski <luto@amacapital.net> 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: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: linux-kernel@vger.kernel.org Link: http://lkml.kernel.org/r/9fc53eda4a5b924070952f12fa4ae3e477640a07.1444091585.git.luto@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'arch/x86/entry/common.c')
-rw-r--r--arch/x86/entry/common.c43
1 files changed, 28 insertions, 15 deletions
diff --git a/arch/x86/entry/common.c b/arch/x86/entry/common.c
index d0874210d5b5..66ccbd664d4c 100644
--- a/arch/x86/entry/common.c
+++ b/arch/x86/entry/common.c
@@ -218,14 +218,12 @@ long syscall_trace_enter(struct pt_regs *regs)
218 return syscall_trace_enter_phase2(regs, arch, phase1_result); 218 return syscall_trace_enter_phase2(regs, arch, phase1_result);
219} 219}
220 220
221/* Called with IRQs disabled. */ 221#define EXIT_TO_USERMODE_LOOP_FLAGS \
222__visible void prepare_exit_to_usermode(struct pt_regs *regs) 222 (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
223{ 223 _TIF_NEED_RESCHED | _TIF_USER_RETURN_NOTIFY)
224 if (IS_ENABLED(CONFIG_PROVE_LOCKING) && WARN_ON(!irqs_disabled()))
225 local_irq_disable();
226
227 lockdep_sys_exit();
228 224
225static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags)
226{
229 /* 227 /*
230 * In order to return to user mode, we need to have IRQs off with 228 * In order to return to user mode, we need to have IRQs off with
231 * none of _TIF_SIGPENDING, _TIF_NOTIFY_RESUME, _TIF_USER_RETURN_NOTIFY, 229 * none of _TIF_SIGPENDING, _TIF_NOTIFY_RESUME, _TIF_USER_RETURN_NOTIFY,
@@ -235,14 +233,6 @@ __visible void prepare_exit_to_usermode(struct pt_regs *regs)
235 * work to clear some of the flags can sleep. 233 * work to clear some of the flags can sleep.
236 */ 234 */
237 while (true) { 235 while (true) {
238 u32 cached_flags =
239 READ_ONCE(pt_regs_to_thread_info(regs)->flags);
240
241 if (!(cached_flags & (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME |
242 _TIF_UPROBE | _TIF_NEED_RESCHED |
243 _TIF_USER_RETURN_NOTIFY)))
244 break;
245
246 /* We have work to do. */ 236 /* We have work to do. */
247 local_irq_enable(); 237 local_irq_enable();
248 238
@@ -266,7 +256,30 @@ __visible void prepare_exit_to_usermode(struct pt_regs *regs)
266 256
267 /* Disable IRQs and retry */ 257 /* Disable IRQs and retry */
268 local_irq_disable(); 258 local_irq_disable();
259
260 cached_flags = READ_ONCE(pt_regs_to_thread_info(regs)->flags);
261
262 if (!(cached_flags & EXIT_TO_USERMODE_LOOP_FLAGS))
263 break;
264
269 } 265 }
266}
267
268/* Called with IRQs disabled. */
269__visible inline void prepare_exit_to_usermode(struct pt_regs *regs)
270{
271 u32 cached_flags;
272
273 if (IS_ENABLED(CONFIG_PROVE_LOCKING) && WARN_ON(!irqs_disabled()))
274 local_irq_disable();
275
276 lockdep_sys_exit();
277
278 cached_flags =
279 READ_ONCE(pt_regs_to_thread_info(regs)->flags);
280
281 if (unlikely(cached_flags & EXIT_TO_USERMODE_LOOP_FLAGS))
282 exit_to_usermode_loop(regs, cached_flags);
270 283
271 user_enter(); 284 user_enter();
272} 285}