linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Borislav Petkov <bp@alien8.de>
To: Tony Luck <tony.luck@intel.com>
Cc: X86 ML <x86@kernel.org>, LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH v1 10/12] x86/mce: Move the tainting outside of the noinstr region
Date: Wed,  8 Dec 2021 12:13:41 +0100	[thread overview]
Message-ID: <20211208111343.8130-11-bp@alien8.de> (raw)
In-Reply-To: <20211208111343.8130-1-bp@alien8.de>

From: Borislav Petkov <bp@suse.de>

add_taint() is yet another external facility which the #MC handler
calls. Move that tainting call into the instrumentation-allowed part of
the handler.

Fixes

  vmlinux.o: warning: objtool: do_machine_check()+0x617: call to add_taint() leaves .noinstr.text section

While at it, allow instrumentation around the mce_log() call.

Fixes

  vmlinux.o: warning: objtool: do_machine_check()+0x690: call to mce_log() leaves .noinstr.text section

Signed-off-by: Borislav Petkov <bp@suse.de>
---
 arch/x86/kernel/cpu/mce/core.c | 41 +++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c
index eafa7f350fa2..782724b1204f 100644
--- a/arch/x86/kernel/cpu/mce/core.c
+++ b/arch/x86/kernel/cpu/mce/core.c
@@ -1180,13 +1180,14 @@ static noinstr bool mce_check_crashing_cpu(void)
 	return false;
 }
 
-static void __mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *final,
-			    unsigned long *toclear, unsigned long *valid_banks,
-			    int no_way_out, int *worst)
+static __always_inline int
+__mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *final,
+		unsigned long *toclear, unsigned long *valid_banks, int no_way_out,
+		int *worst)
 {
 	struct mce_bank *mce_banks = this_cpu_ptr(mce_banks_array);
 	struct mca_config *cfg = &mca_cfg;
-	int severity, i;
+	int severity, i, taint = 0;
 
 	for (i = 0; i < this_cpu_read(mce_num_banks); i++) {
 		__clear_bit(i, toclear);
@@ -1213,7 +1214,7 @@ static void __mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *fin
 			continue;
 
 		/* Set taint even when machine check was not enabled. */
-		add_taint(TAINT_MACHINE_CHECK, LOCKDEP_NOW_UNRELIABLE);
+		taint++;
 
 		severity = mce_severity(m, regs, cfg->tolerant, NULL, true);
 
@@ -1236,7 +1237,13 @@ static void __mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *fin
 		/* assuming valid severity level != 0 */
 		m->severity = severity;
 
+		/*
+		 * Enable instrumentation around the mce_log() call which is
+		 * done in #MC context, where instrumentation is disabled.
+		 */
+		instrumentation_begin();
 		mce_log(m);
+		instrumentation_end();
 
 		if (severity > *worst) {
 			*final = *m;
@@ -1246,6 +1253,8 @@ static void __mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *fin
 
 	/* mce_clear_state will clear *final, save locally for use later */
 	*m = *final;
+
+	return taint;
 }
 
 static void kill_me_now(struct callback_head *ch)
@@ -1354,7 +1363,7 @@ static noinstr void unexpected_machine_check(struct pt_regs *regs)
  */
 noinstr void do_machine_check(struct pt_regs *regs)
 {
-	int worst = 0, order, no_way_out, kill_current_task, lmce;
+	int worst = 0, order, no_way_out, kill_current_task, lmce, taint = 0;
 	DECLARE_BITMAP(valid_banks, MAX_NR_BANKS) = { 0 };
 	DECLARE_BITMAP(toclear, MAX_NR_BANKS) = { 0 };
 	struct mca_config *cfg = &mca_cfg;
@@ -1433,7 +1442,7 @@ noinstr void do_machine_check(struct pt_regs *regs)
 		order = mce_start(&no_way_out);
 	}
 
-	__mc_scan_banks(&m, regs, final, toclear, valid_banks, no_way_out, &worst);
+	taint = __mc_scan_banks(&m, regs, final, toclear, valid_banks, no_way_out, &worst);
 
 	if (!no_way_out)
 		mce_clear_state(toclear);
@@ -1465,17 +1474,19 @@ noinstr void do_machine_check(struct pt_regs *regs)
 		}
 	}
 
-	if (worst != MCE_AR_SEVERITY && !kill_current_task)
-		goto out;
-
 	/*
-	 * Enable instrumentation around the external facilities like
-	 * task_work_add() (via queue_task_work()), fixup_exception() etc.
-	 * For now, that is. Fixing this properly would need a lot more involved
-	 * reorganization.
+	 * Enable instrumentation around the external facilities like task_work_add()
+	 * (via queue_task_work()), fixup_exception() etc. For now, that is. Fixing this
+	 * properly would need a lot more involved reorganization.
 	 */
 	instrumentation_begin();
 
+	if (taint)
+		add_taint(TAINT_MACHINE_CHECK, LOCKDEP_NOW_UNRELIABLE);
+
+	if (worst != MCE_AR_SEVERITY && !kill_current_task)
+		goto out;
+
 	/* Fault was in user mode and we need to take some action */
 	if ((m.cs & 3) == 3) {
 		/* If this triggers there is no way to recover. Die hard. */
@@ -1505,9 +1516,9 @@ noinstr void do_machine_check(struct pt_regs *regs)
 			queue_task_work(&m, msg, kill_me_never);
 	}
 
+out:
 	instrumentation_end();
 
-out:
 	mce_wrmsrl(MSR_IA32_MCG_STATUS, 0);
 }
 EXPORT_SYMBOL_GPL(do_machine_check);
-- 
2.29.2


  parent reply	other threads:[~2021-12-08 11:14 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-08 11:13 [PATCH v1 00/12] x86/mce: Correct the noinstr annotation Borislav Petkov
2021-12-08 11:13 ` [PATCH v1 01/12] x86/mce: Do not use memset to clear the banks bitmaps Borislav Petkov
2021-12-13 17:35   ` [tip: ras/core] " tip-bot2 for Borislav Petkov
2021-12-08 11:13 ` [PATCH v1 02/12] x86/mce: Remove function-local cpus variables Borislav Petkov
2021-12-13 17:35   ` [tip: ras/core] " tip-bot2 for Borislav Petkov
2021-12-08 11:13 ` [PATCH v1 03/12] x86/mce: Use mce_rdmsrl() in severity checking code Borislav Petkov
2021-12-13 17:35   ` [tip: ras/core] " tip-bot2 for Borislav Petkov
2021-12-08 11:13 ` [PATCH v1 04/12] x86/mce: Remove noinstr annotation from mce_setup() Borislav Petkov
2021-12-09 12:16   ` Peter Zijlstra
2021-12-10 14:18     ` Borislav Petkov
2021-12-13 17:35   ` [tip: ras/core] " tip-bot2 for Borislav Petkov
2021-12-08 11:13 ` [PATCH v1 05/12] x86/mce: Allow instrumentation during task work queueing Borislav Petkov
2021-12-09 12:17   ` Peter Zijlstra
2021-12-13 17:35   ` [tip: ras/core] " tip-bot2 for Borislav Petkov
2021-12-08 11:13 ` [PATCH v1 06/12] x86/mce: Prevent severity computation from being instrumented Borislav Petkov
2021-12-13 17:35   ` [tip: ras/core] " tip-bot2 for Borislav Petkov
2021-12-08 11:13 ` [PATCH v1 07/12] x86/mce: Mark mce_panic() noinstr Borislav Petkov
2021-12-13 17:35   ` [tip: ras/core] " tip-bot2 for Borislav Petkov
2021-12-08 11:13 ` [PATCH v1 08/12] x86/mce: Mark mce_end() noinstr Borislav Petkov
2021-12-13 17:35   ` [tip: ras/core] " tip-bot2 for Borislav Petkov
2021-12-08 11:13 ` [PATCH v1 09/12] x86/mce: Mark mce_read_aux() noinstr Borislav Petkov
2021-12-13 17:35   ` [tip: ras/core] " tip-bot2 for Borislav Petkov
2021-12-08 11:13 ` Borislav Petkov [this message]
2021-12-13 17:35   ` [tip: ras/core] x86/mce: Move the tainting outside of the noinstr region tip-bot2 for Borislav Petkov
2021-12-08 11:13 ` [PATCH v1 11/12] x86/mce: Mark mce_timed_out() noinstr Borislav Petkov
2021-12-13 17:35   ` [tip: ras/core] " tip-bot2 for Borislav Petkov
2021-12-08 11:13 ` [PATCH v1 12/12] x86/mce: Mark mce_start() noinstr Borislav Petkov
2021-12-13 17:35   ` [tip: ras/core] " tip-bot2 for Borislav Petkov
2021-12-09 12:19 ` [PATCH v1 00/12] x86/mce: Correct the noinstr annotation 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=20211208111343.8130-11-bp@alien8.de \
    --to=bp@alien8.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tony.luck@intel.com \
    --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).