aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/entry/common.c
diff options
context:
space:
mode:
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}