[tip: ras/core] x86/mce: Mark mce_panic() noinstr

From: tip-bot2 for Borislav Petkov
Date: Mon Dec 13 2021 - 12:35:32 EST


The following commit has been merged into the ras/core branch of tip:

Commit-ID: 3c7ce80a818fa7950be123cac80cd078e5ac1013
Gitweb: https://git.kernel.org/tip/3c7ce80a818fa7950be123cac80cd078e5ac1013
Author: Borislav Petkov <bp@xxxxxxx>
AuthorDate: Mon, 01 Nov 2021 13:39:35 +01:00
Committer: Borislav Petkov <bp@xxxxxxx>
CommitterDate: Mon, 13 Dec 2021 14:13:01 +01:00

x86/mce: Mark mce_panic() noinstr

And allow instrumentation inside it because it does calls to other
facilities which will not be tagged noinstr.

Fixes

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

Signed-off-by: Borislav Petkov <bp@xxxxxxx>
Link: https://lore.kernel.org/r/20211208111343.8130-8-bp@xxxxxxxxx
---
arch/x86/kernel/cpu/mce/core.c | 15 ++++++++++++---
1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/arch/x86/kernel/cpu/mce/core.c b/arch/x86/kernel/cpu/mce/core.c
index d788ccc..ec0f7bb 100644
--- a/arch/x86/kernel/cpu/mce/core.c
+++ b/arch/x86/kernel/cpu/mce/core.c
@@ -266,11 +266,17 @@ static void wait_for_panic(void)
panic("Panicing machine check CPU died");
}

-static void mce_panic(const char *msg, struct mce *final, char *exp)
+static noinstr void mce_panic(const char *msg, struct mce *final, char *exp)
{
- int apei_err = 0;
struct llist_node *pending;
struct mce_evt_llist *l;
+ int apei_err = 0;
+
+ /*
+ * Allow instrumentation around external facilities usage. Not that it
+ * matters a whole lot since the machine is going to panic anyway.
+ */
+ instrumentation_begin();

if (!fake_panic) {
/*
@@ -285,7 +291,7 @@ static void mce_panic(const char *msg, struct mce *final, char *exp)
} else {
/* Don't log too much for fake panic */
if (atomic_inc_return(&mce_fake_panicked) > 1)
- return;
+ goto out;
}
pending = mce_gen_pool_prepare_records();
/* First print corrected ones that are still unlogged */
@@ -321,6 +327,9 @@ static void mce_panic(const char *msg, struct mce *final, char *exp)
panic(msg);
} else
pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
+
+out:
+ instrumentation_end();
}

/* Support code for software error injection */