Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7c68af6e authored by Avi Kivity's avatar Avi Kivity Committed by H. Peter Anvin
Browse files

core, x86: Add user return notifiers



Add a general per-cpu notifier that is called whenever the kernel is
about to return to userspace.  The notifier uses a thread_info flag
and existing checks, so there is no impact on user return or context
switch fast paths.

This will be used initially to speed up KVM task switching by lazily
updating MSRs.

Signed-off-by: default avatarAvi Kivity <avi@redhat.com>
LKML-Reference: <1253342422-13811-1-git-send-email-avi@redhat.com>
Signed-off-by: default avatarH. Peter Anvin <hpa@zytor.com>
parent 817b33d3
Loading
Loading
Loading
Loading
+10 −0
Original line number Original line Diff line number Diff line
@@ -83,6 +83,13 @@ config KRETPROBES
	def_bool y
	def_bool y
	depends on KPROBES && HAVE_KRETPROBES
	depends on KPROBES && HAVE_KRETPROBES


config USER_RETURN_NOTIFIER
	bool
	depends on HAVE_USER_RETURN_NOTIFIER
	help
	  Provide a kernel-internal notification when a cpu is about to
	  switch to user mode.

config HAVE_IOREMAP_PROT
config HAVE_IOREMAP_PROT
	bool
	bool


@@ -126,4 +133,7 @@ config HAVE_DMA_API_DEBUG
config HAVE_DEFAULT_NO_SPIN_MUTEXES
config HAVE_DEFAULT_NO_SPIN_MUTEXES
	bool
	bool


config HAVE_USER_RETURN_NOTIFIER
	bool

source "kernel/gcov/Kconfig"
source "kernel/gcov/Kconfig"
+1 −0
Original line number Original line Diff line number Diff line
@@ -50,6 +50,7 @@ config X86
	select HAVE_KERNEL_BZIP2
	select HAVE_KERNEL_BZIP2
	select HAVE_KERNEL_LZMA
	select HAVE_KERNEL_LZMA
	select HAVE_ARCH_KMEMCHECK
	select HAVE_ARCH_KMEMCHECK
	select HAVE_USER_RETURN_NOTIFIER


config OUTPUT_FORMAT
config OUTPUT_FORMAT
	string
	string
+5 −2
Original line number Original line Diff line number Diff line
@@ -83,6 +83,7 @@ struct thread_info {
#define TIF_SYSCALL_AUDIT	7	/* syscall auditing active */
#define TIF_SYSCALL_AUDIT	7	/* syscall auditing active */
#define TIF_SECCOMP		8	/* secure computing */
#define TIF_SECCOMP		8	/* secure computing */
#define TIF_MCE_NOTIFY		10	/* notify userspace of an MCE */
#define TIF_MCE_NOTIFY		10	/* notify userspace of an MCE */
#define TIF_USER_RETURN_NOTIFY	11	/* notify kernel of userspace return */
#define TIF_NOTSC		16	/* TSC is not accessible in userland */
#define TIF_NOTSC		16	/* TSC is not accessible in userland */
#define TIF_IA32		17	/* 32bit process */
#define TIF_IA32		17	/* 32bit process */
#define TIF_FORK		18	/* ret_from_fork */
#define TIF_FORK		18	/* ret_from_fork */
@@ -107,6 +108,7 @@ struct thread_info {
#define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
#define _TIF_SYSCALL_AUDIT	(1 << TIF_SYSCALL_AUDIT)
#define _TIF_SECCOMP		(1 << TIF_SECCOMP)
#define _TIF_SECCOMP		(1 << TIF_SECCOMP)
#define _TIF_MCE_NOTIFY		(1 << TIF_MCE_NOTIFY)
#define _TIF_MCE_NOTIFY		(1 << TIF_MCE_NOTIFY)
#define _TIF_USER_RETURN_NOTIFY	(1 << TIF_USER_RETURN_NOTIFY)
#define _TIF_NOTSC		(1 << TIF_NOTSC)
#define _TIF_NOTSC		(1 << TIF_NOTSC)
#define _TIF_IA32		(1 << TIF_IA32)
#define _TIF_IA32		(1 << TIF_IA32)
#define _TIF_FORK		(1 << TIF_FORK)
#define _TIF_FORK		(1 << TIF_FORK)
@@ -142,13 +144,14 @@ struct thread_info {


/* Only used for 64 bit */
/* Only used for 64 bit */
#define _TIF_DO_NOTIFY_MASK						\
#define _TIF_DO_NOTIFY_MASK						\
	(_TIF_SIGPENDING|_TIF_MCE_NOTIFY|_TIF_NOTIFY_RESUME)
	(_TIF_SIGPENDING | _TIF_MCE_NOTIFY | _TIF_NOTIFY_RESUME |	\
	 _TIF_USER_RETURN_NOTIFY)


/* flags to check in __switch_to() */
/* flags to check in __switch_to() */
#define _TIF_WORK_CTXSW							\
#define _TIF_WORK_CTXSW							\
	(_TIF_IO_BITMAP|_TIF_DEBUGCTLMSR|_TIF_DS_AREA_MSR|_TIF_NOTSC)
	(_TIF_IO_BITMAP|_TIF_DEBUGCTLMSR|_TIF_DS_AREA_MSR|_TIF_NOTSC)


#define _TIF_WORK_CTXSW_PREV _TIF_WORK_CTXSW
#define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
#define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW|_TIF_DEBUG)
#define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW|_TIF_DEBUG)


#define PREEMPT_ACTIVE		0x10000000
#define PREEMPT_ACTIVE		0x10000000
+2 −0
Original line number Original line Diff line number Diff line
@@ -9,6 +9,7 @@
#include <linux/pm.h>
#include <linux/pm.h>
#include <linux/clockchips.h>
#include <linux/clockchips.h>
#include <linux/random.h>
#include <linux/random.h>
#include <linux/user-return-notifier.h>
#include <trace/events/power.h>
#include <trace/events/power.h>
#include <asm/system.h>
#include <asm/system.h>
#include <asm/apic.h>
#include <asm/apic.h>
@@ -224,6 +225,7 @@ void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p,
		 */
		 */
		memset(tss->io_bitmap, 0xff, prev->io_bitmap_max);
		memset(tss->io_bitmap, 0xff, prev->io_bitmap_max);
	}
	}
	propagate_user_return_notify(prev_p, next_p);
}
}


int sys_fork(struct pt_regs *regs)
int sys_fork(struct pt_regs *regs)
+3 −0
Original line number Original line Diff line number Diff line
@@ -19,6 +19,7 @@
#include <linux/stddef.h>
#include <linux/stddef.h>
#include <linux/personality.h>
#include <linux/personality.h>
#include <linux/uaccess.h>
#include <linux/uaccess.h>
#include <linux/user-return-notifier.h>


#include <asm/processor.h>
#include <asm/processor.h>
#include <asm/ucontext.h>
#include <asm/ucontext.h>
@@ -872,6 +873,8 @@ do_notify_resume(struct pt_regs *regs, void *unused, __u32 thread_info_flags)
		if (current->replacement_session_keyring)
		if (current->replacement_session_keyring)
			key_replace_session_keyring();
			key_replace_session_keyring();
	}
	}
	if (thread_info_flags & _TIF_USER_RETURN_NOTIFY)
		fire_user_return_notifiers();


#ifdef CONFIG_X86_32
#ifdef CONFIG_X86_32
	clear_thread_flag(TIF_IRET);
	clear_thread_flag(TIF_IRET);
Loading