Commit 75581a20 authored by Borislav Petkov's avatar Borislav Petkov

x86/mce: Move the tainting outside of the noinstr region

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: default avatarBorislav Petkov <bp@suse.de>
Link: https://lore.kernel.org/r/20211208111343.8130-11-bp@alien8.de
parent db6c996d
...@@ -1180,13 +1180,14 @@ static noinstr bool mce_check_crashing_cpu(void) ...@@ -1180,13 +1180,14 @@ static noinstr bool mce_check_crashing_cpu(void)
return false; return false;
} }
static void __mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *final, static __always_inline int
unsigned long *toclear, unsigned long *valid_banks, __mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *final,
int no_way_out, int *worst) 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 mce_bank *mce_banks = this_cpu_ptr(mce_banks_array);
struct mca_config *cfg = &mca_cfg; 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++) { for (i = 0; i < this_cpu_read(mce_num_banks); i++) {
__clear_bit(i, toclear); __clear_bit(i, toclear);
...@@ -1213,7 +1214,7 @@ static void __mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *fin ...@@ -1213,7 +1214,7 @@ static void __mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *fin
continue; continue;
/* Set taint even when machine check was not enabled. */ /* 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); 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 ...@@ -1236,7 +1237,13 @@ static void __mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *fin
/* assuming valid severity level != 0 */ /* assuming valid severity level != 0 */
m->severity = severity; 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); mce_log(m);
instrumentation_end();
if (severity > *worst) { if (severity > *worst) {
*final = *m; *final = *m;
...@@ -1246,6 +1253,8 @@ static void __mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *fin ...@@ -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 */ /* mce_clear_state will clear *final, save locally for use later */
*m = *final; *m = *final;
return taint;
} }
static void kill_me_now(struct callback_head *ch) static void kill_me_now(struct callback_head *ch)
...@@ -1362,7 +1371,7 @@ static noinstr void unexpected_machine_check(struct pt_regs *regs) ...@@ -1362,7 +1371,7 @@ static noinstr void unexpected_machine_check(struct pt_regs *regs)
*/ */
noinstr void do_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(valid_banks, MAX_NR_BANKS) = { 0 };
DECLARE_BITMAP(toclear, MAX_NR_BANKS) = { 0 }; DECLARE_BITMAP(toclear, MAX_NR_BANKS) = { 0 };
struct mca_config *cfg = &mca_cfg; struct mca_config *cfg = &mca_cfg;
...@@ -1441,7 +1450,7 @@ noinstr void do_machine_check(struct pt_regs *regs) ...@@ -1441,7 +1450,7 @@ noinstr void do_machine_check(struct pt_regs *regs)
order = mce_start(&no_way_out); 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) if (!no_way_out)
mce_clear_state(toclear); mce_clear_state(toclear);
...@@ -1473,17 +1482,19 @@ noinstr void do_machine_check(struct pt_regs *regs) ...@@ -1473,17 +1482,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 * Enable instrumentation around the external facilities like task_work_add()
* task_work_add() (via queue_task_work()), fixup_exception() etc. * (via queue_task_work()), fixup_exception() etc. For now, that is. Fixing this
* For now, that is. Fixing this properly would need a lot more involved * properly would need a lot more involved reorganization.
* reorganization.
*/ */
instrumentation_begin(); 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 */ /* Fault was in user mode and we need to take some action */
if ((m.cs & 3) == 3) { if ((m.cs & 3) == 3) {
/* If this triggers there is no way to recover. Die hard. */ /* If this triggers there is no way to recover. Die hard. */
...@@ -1513,9 +1524,9 @@ noinstr void do_machine_check(struct pt_regs *regs) ...@@ -1513,9 +1524,9 @@ noinstr void do_machine_check(struct pt_regs *regs)
queue_task_work(&m, msg, kill_me_never); queue_task_work(&m, msg, kill_me_never);
} }
out:
instrumentation_end(); instrumentation_end();
out:
mce_wrmsrl(MSR_IA32_MCG_STATUS, 0); mce_wrmsrl(MSR_IA32_MCG_STATUS, 0);
} }
EXPORT_SYMBOL_GPL(do_machine_check); EXPORT_SYMBOL_GPL(do_machine_check);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment