Skip to content

Commit 0a5b288

Browse files
committed
x86/mce: Prevent severity computation from being instrumented
Mark all the MCE severity computation logic noinstr and allow instrumentation when it "calls out". Fixes vmlinux.o: warning: objtool: do_machine_check()+0xc5d: call to mce_severity() leaves .noinstr.text section Signed-off-by: Borislav Petkov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 4fbce46 commit 0a5b288

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

arch/x86/kernel/cpu/mce/severity.c

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,24 +263,36 @@ static bool is_copy_from_user(struct pt_regs *regs)
263263
* distinguish an exception taken in user from from one
264264
* taken in the kernel.
265265
*/
266-
static int error_context(struct mce *m, struct pt_regs *regs)
266+
static noinstr int error_context(struct mce *m, struct pt_regs *regs)
267267
{
268+
int fixup_type;
269+
bool copy_user;
270+
268271
if ((m->cs & 3) == 3)
269272
return IN_USER;
273+
270274
if (!mc_recoverable(m->mcgstatus))
271275
return IN_KERNEL;
272276

273-
switch (ex_get_fixup_type(m->ip)) {
277+
/* Allow instrumentation around external facilities usage. */
278+
instrumentation_begin();
279+
fixup_type = ex_get_fixup_type(m->ip);
280+
copy_user = is_copy_from_user(regs);
281+
instrumentation_end();
282+
283+
switch (fixup_type) {
274284
case EX_TYPE_UACCESS:
275285
case EX_TYPE_COPY:
276-
if (!regs || !is_copy_from_user(regs))
286+
if (!regs || !copy_user)
277287
return IN_KERNEL;
278288
m->kflags |= MCE_IN_KERNEL_COPYIN;
279289
fallthrough;
290+
280291
case EX_TYPE_FAULT_MCE_SAFE:
281292
case EX_TYPE_DEFAULT_MCE_SAFE:
282293
m->kflags |= MCE_IN_KERNEL_RECOV;
283294
return IN_KERNEL_RECOV;
295+
284296
default:
285297
return IN_KERNEL;
286298
}
@@ -315,8 +327,8 @@ static int mce_severity_amd_smca(struct mce *m, enum context err_ctx)
315327
* See AMD Error Scope Hierarchy table in a newer BKDG. For example
316328
* 49125_15h_Models_30h-3Fh_BKDG.pdf, section "RAS Features"
317329
*/
318-
static int mce_severity_amd(struct mce *m, struct pt_regs *regs, int tolerant,
319-
char **msg, bool is_excp)
330+
static noinstr int mce_severity_amd(struct mce *m, struct pt_regs *regs, int tolerant,
331+
char **msg, bool is_excp)
320332
{
321333
enum context ctx = error_context(m, regs);
322334

@@ -368,8 +380,8 @@ static int mce_severity_amd(struct mce *m, struct pt_regs *regs, int tolerant,
368380
return MCE_KEEP_SEVERITY;
369381
}
370382

371-
static int mce_severity_intel(struct mce *m, struct pt_regs *regs,
372-
int tolerant, char **msg, bool is_excp)
383+
static noinstr int mce_severity_intel(struct mce *m, struct pt_regs *regs,
384+
int tolerant, char **msg, bool is_excp)
373385
{
374386
enum exception excp = (is_excp ? EXCP_CONTEXT : NO_EXCP);
375387
enum context ctx = error_context(m, regs);
@@ -405,8 +417,8 @@ static int mce_severity_intel(struct mce *m, struct pt_regs *regs,
405417
}
406418
}
407419

408-
int mce_severity(struct mce *m, struct pt_regs *regs, int tolerant, char **msg,
409-
bool is_excp)
420+
int noinstr mce_severity(struct mce *m, struct pt_regs *regs, int tolerant, char **msg,
421+
bool is_excp)
410422
{
411423
if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD ||
412424
boot_cpu_data.x86_vendor == X86_VENDOR_HYGON)

0 commit comments

Comments
 (0)