Skip to content

Commit a377ac1

Browse files
committed
x86/entry: Move user return notifier out of loop
Guests and user space share certain MSRs. KVM sets these MSRs to guest values once and does not set them back to user space values on every VM exit to spare the costly MSR operations. User return notifiers ensure that these MSRs are set back to the correct values before returning to user space in exit_to_usermode_loop(). There is no reason to evaluate the TIF flag indicating that user return notifiers need to be invoked in the loop. The important point is that they are invoked before returning to user space. Move the invocation out of the loop into the section which does the last preperatory steps before returning to user space. That section is not preemptible and runs with interrupts disabled until the actual return. Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 0b085e6 commit a377ac1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

arch/x86/entry/common.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static long syscall_trace_enter(struct pt_regs *regs)
208208

209209
#define EXIT_TO_USERMODE_LOOP_FLAGS \
210210
(_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
211-
_TIF_NEED_RESCHED | _TIF_USER_RETURN_NOTIFY | _TIF_PATCH_PENDING)
211+
_TIF_NEED_RESCHED | _TIF_PATCH_PENDING)
212212

213213
static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags)
214214
{
@@ -242,9 +242,6 @@ static void exit_to_usermode_loop(struct pt_regs *regs, u32 cached_flags)
242242
rseq_handle_notify_resume(NULL, regs);
243243
}
244244

245-
if (cached_flags & _TIF_USER_RETURN_NOTIFY)
246-
fire_user_return_notifiers();
247-
248245
/* Disable IRQs and retry */
249246
local_irq_disable();
250247

@@ -273,6 +270,9 @@ static void __prepare_exit_to_usermode(struct pt_regs *regs)
273270
/* Reload ti->flags; we may have rescheduled above. */
274271
cached_flags = READ_ONCE(ti->flags);
275272

273+
if (cached_flags & _TIF_USER_RETURN_NOTIFY)
274+
fire_user_return_notifiers();
275+
276276
if (unlikely(cached_flags & _TIF_IO_BITMAP))
277277
tss_update_io_bitmap();
278278

0 commit comments

Comments
 (0)