linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: x86@kernel.org, Steven Rostedt <rostedt@goodmis.org>,
	Brian Gerst <brgerst@gmail.com>, Juergen Gross <jgross@suse.com>,
	Paolo Bonzini <pbonzini@redhat.com>,
	Arnd Bergmann <arnd@arndb.de>
Subject: [patch 08/16] x86/entry: Implement user mode C entry points for #DB and #MCE
Date: Tue, 25 Feb 2020 23:33:29 +0100	[thread overview]
Message-ID: <20200225224144.911992536@linutronix.de> (raw)
In-Reply-To: 20200225223321.231477305@linutronix.de

The MCE entry point uses the same mechanism as the IST entry point for
now. For #DB split the inner workings and just keep the ist_enter/exit
magic in the IST variant. Fixup the ASM code to emit the proper
noist_##cfunc call.

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
 arch/x86/entry/entry_64.S      |    2 +-
 arch/x86/kernel/cpu/mce/core.c |   11 +++++++++++
 arch/x86/kernel/traps.c        |   30 ++++++++++++++++++++++--------
 3 files changed, 34 insertions(+), 9 deletions(-)

--- a/arch/x86/entry/entry_64.S
+++ b/arch/x86/entry/entry_64.S
@@ -646,7 +646,7 @@ SYM_CODE_START(\asmsym)
 
 	/* Switch to the regular task stack and use the noist entry point */
 .Lfrom_usermode_switch_stack_\@:
-	idtentry_body vector \cfunc, has_error_code=0
+	idtentry_body vector noist_\cfunc, has_error_code=0
 
 _ASM_NOKPROBE(\asmsym)
 SYM_CODE_END(\asmsym)
--- a/arch/x86/kernel/cpu/mce/core.c
+++ b/arch/x86/kernel/cpu/mce/core.c
@@ -1898,11 +1898,22 @@ static void unexpected_machine_check(str
 /* Call the installed machine check handler for this CPU setup. */
 void (*machine_check_vector)(struct pt_regs *) = unexpected_machine_check;
 
+/* MCE hit kernel mode */
 DEFINE_IDTENTRY_MCE(exc_machine_check)
 {
 	machine_check_vector(regs);
 }
 
+#ifdef CONFIG_X86_64
+/*
+ * The user mode variant (same content for now).
+ */
+DEFINE_IDTENTRY_MCE_USER(exc_machine_check)
+{
+	machine_check_vector(regs);
+}
+#endif
+
 /*
  * Called for each booted CPU to set up machine checks.
  * Must be called with preempt off:
--- a/arch/x86/kernel/traps.c
+++ b/arch/x86/kernel/traps.c
@@ -739,15 +739,13 @@ static bool is_sysenter_singlestep(struc
  *
  * May run on IST stack.
  */
-DEFINE_IDTENTRY_DEBUG(exc_debug)
+static void notrace handle_debug(struct pt_regs *regs)
 {
 	struct task_struct *tsk = current;
 	int user_icebp = 0;
 	unsigned long dr6;
 	int si_code;
 
-	ist_enter(regs);
-
 	get_debugreg(dr6, 6);
 	/*
 	 * The Intel SDM says:
@@ -776,7 +774,7 @@ DEFINE_IDTENTRY_DEBUG(exc_debug)
 		     is_sysenter_singlestep(regs))) {
 		dr6 &= ~DR_STEP;
 		if (!dr6)
-			goto exit;
+			return;
 		/*
 		 * else we might have gotten a single-step trap and hit a
 		 * watchpoint at the same time, in which case we should fall
@@ -797,12 +795,12 @@ DEFINE_IDTENTRY_DEBUG(exc_debug)
 
 #ifdef CONFIG_KPROBES
 	if (kprobe_debug_handler(regs))
-		goto exit;
+		return;
 #endif
 
 	if (notify_die(DIE_DEBUG, "debug", regs, (long)&dr6, 0,
 		       SIGTRAP) == NOTIFY_STOP)
-		goto exit;
+		return;
 
 	/*
 	 * Let others (NMI) know that the debug stack is in use
@@ -818,7 +816,7 @@ DEFINE_IDTENTRY_DEBUG(exc_debug)
 				 X86_TRAP_DB);
 		cond_local_irq_disable(regs);
 		debug_stack_usage_dec();
-		goto exit;
+		return;
 	}
 
 	if (WARN_ON_ONCE((dr6 & DR_STEP) && !user_mode(regs))) {
@@ -837,11 +835,27 @@ DEFINE_IDTENTRY_DEBUG(exc_debug)
 		send_sigtrap(regs, 0, si_code);
 	cond_local_irq_disable(regs);
 	debug_stack_usage_dec();
+}
+NOKPROBE_SYMBOL(handle_debug);
 
-exit:
+/*
+ * IST stack entry.
+ */
+DEFINE_IDTENTRY_DEBUG(exc_debug)
+{
+	ist_enter(regs);
+	handle_debug(regs);
 	ist_exit(regs);
 }
 
+#ifdef CONFIG_X86_64
+/* User entry, runs on regular task stack */
+DEFINE_IDTENTRY_DEBUG_USER(exc_debug)
+{
+	handle_debug(regs);
+}
+#endif
+
 /*
  * Note that we play around with the 'TS' bit in an attempt to get
  * the correct behaviour even in the presence of the asynchronous


  parent reply	other threads:[~2020-02-25 23:26 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-25 22:33 [patch 00/16] x86/entry: Consolidation - Part IV Thomas Gleixner
2020-02-25 22:33 ` [patch 01/16] x86/entry: Provide IDTENTRY_IST Thomas Gleixner
2020-02-25 22:33 ` [patch 02/16] x86/entry: Convert Machine Check to IDTENTRY_IST Thomas Gleixner
2020-02-25 22:33 ` [patch 03/16] x86/idtentry: Provide IDTENTRY_XEN for XEN/PV Thomas Gleixner
2020-02-25 22:33 ` [patch 04/16] x86/entry: Convert NMI to IDTENTRY_NMI Thomas Gleixner
2020-02-25 22:33 ` [patch 05/16] x86/entry: Convert Debug exception to IDTENTRY_DB Thomas Gleixner
2020-02-25 22:33 ` [patch 06/16] x86/entry/64: Remove error code clearing from #DB and #MCE ASM stub Thomas Gleixner
2020-02-25 22:33 ` [patch 07/16] x86/entry: Provide IDTRENTRY_NOIST variants for #DB and #MC Thomas Gleixner
2020-02-25 22:33 ` Thomas Gleixner [this message]
2020-02-25 22:33 ` [patch 09/16] x86/entry: Provide IDTENTRY_DF Thomas Gleixner
2020-02-25 22:33 ` [patch 10/16] x86/entry: Convert double fault exception to IDTENTRY_DF Thomas Gleixner
2020-02-25 22:33 ` [patch 11/16] x86/entry: Switch XEN/PV hypercall entry to IDTENTRY Thomas Gleixner
2020-02-25 22:33 ` [patch 12/16] x86/entry/64: Simplify idtentry_body Thomas Gleixner
2020-02-25 22:33 ` [patch 13/16] x86/entry: Move irqflags and context tracking to C for simple idtentries Thomas Gleixner
2020-02-26  8:05   ` Peter Zijlstra
2020-02-26  9:20     ` Peter Zijlstra
2020-02-26 15:11       ` Andy Lutomirski
2020-02-26 16:28         ` Peter Zijlstra
2020-02-26 19:15           ` Andy Lutomirski
2020-02-26 20:25             ` Thomas Gleixner
2020-02-26 17:05     ` Frederic Weisbecker
2020-02-26 17:09       ` Andy Lutomirski
2020-02-26 17:17         ` Frederic Weisbecker
2020-02-25 22:33 ` [patch 14/16] x86/entry: Provide IDTENTRY_CR2 Thomas Gleixner
2020-02-25 22:33 ` [patch 15/16] x86/entry: Switch page fault exceptions to idtentry_simple Thomas Gleixner
2020-03-05 21:51   ` Andy Lutomirski
2020-03-05 23:02     ` Thomas Gleixner
2020-02-25 22:33 ` [patch 16/16] x86/entry: Disable interrupts in IDTENTRY Thomas Gleixner
2020-02-26  9:23   ` Peter Zijlstra
2020-02-26 20:21     ` Thomas Gleixner
2020-02-27  8:41       ` Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200225224144.911992536@linutronix.de \
    --to=tglx@linutronix.de \
    --cc=arnd@arndb.de \
    --cc=brgerst@gmail.com \
    --cc=jgross@suse.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=rostedt@goodmis.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).