x86/mce: Prevent severity computation from being instrumented
authorBorislav Petkov <bp@suse.de>
Wed, 13 Oct 2021 07:47:50 +0000 (09:47 +0200)
committerBorislav Petkov <bp@suse.de>
Mon, 13 Dec 2021 13:12:48 +0000 (14:12 +0100)
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 <bp@suse.de>
Link: https://lore.kernel.org/r/20211208111343.8130-7-bp@alien8.de
arch/x86/kernel/cpu/mce/severity.c

index 00e97ebbd94a31943f7ad74be021386a69f67dfd..a326467697051e846d1c1a9694f04d45b551f97f 100644 (file)
@@ -263,24 +263,36 @@ static bool is_copy_from_user(struct pt_regs *regs)
  * distinguish an exception taken in user from from one
  * taken in the kernel.
  */
-static int error_context(struct mce *m, struct pt_regs *regs)
+static noinstr int error_context(struct mce *m, struct pt_regs *regs)
 {
+       int fixup_type;
+       bool copy_user;
+
        if ((m->cs & 3) == 3)
                return IN_USER;
+
        if (!mc_recoverable(m->mcgstatus))
                return IN_KERNEL;
 
-       switch (ex_get_fixup_type(m->ip)) {
+       /* Allow instrumentation around external facilities usage. */
+       instrumentation_begin();
+       fixup_type = ex_get_fixup_type(m->ip);
+       copy_user  = is_copy_from_user(regs);
+       instrumentation_end();
+
+       switch (fixup_type) {
        case EX_TYPE_UACCESS:
        case EX_TYPE_COPY:
-               if (!regs || !is_copy_from_user(regs))
+               if (!regs || !copy_user)
                        return IN_KERNEL;
                m->kflags |= MCE_IN_KERNEL_COPYIN;
                fallthrough;
+
        case EX_TYPE_FAULT_MCE_SAFE:
        case EX_TYPE_DEFAULT_MCE_SAFE:
                m->kflags |= MCE_IN_KERNEL_RECOV;
                return IN_KERNEL_RECOV;
+
        default:
                return IN_KERNEL;
        }
@@ -315,8 +327,8 @@ static int mce_severity_amd_smca(struct mce *m, enum context err_ctx)
  * See AMD Error Scope Hierarchy table in a newer BKDG. For example
  * 49125_15h_Models_30h-3Fh_BKDG.pdf, section "RAS Features"
  */
-static int mce_severity_amd(struct mce *m, struct pt_regs *regs, int tolerant,
-                           char **msg, bool is_excp)
+static noinstr int mce_severity_amd(struct mce *m, struct pt_regs *regs, int tolerant,
+                                   char **msg, bool is_excp)
 {
        enum context ctx = error_context(m, regs);
 
@@ -368,8 +380,8 @@ static int mce_severity_amd(struct mce *m, struct pt_regs *regs, int tolerant,
        return MCE_KEEP_SEVERITY;
 }
 
-static int mce_severity_intel(struct mce *m, struct pt_regs *regs,
-                             int tolerant, char **msg, bool is_excp)
+static noinstr int mce_severity_intel(struct mce *m, struct pt_regs *regs,
+                                     int tolerant, char **msg, bool is_excp)
 {
        enum exception excp = (is_excp ? EXCP_CONTEXT : NO_EXCP);
        enum context ctx = error_context(m, regs);
@@ -405,8 +417,8 @@ static int mce_severity_intel(struct mce *m, struct pt_regs *regs,
        }
 }
 
-int mce_severity(struct mce *m, struct pt_regs *regs, int tolerant, char **msg,
-                bool is_excp)
+int noinstr mce_severity(struct mce *m, struct pt_regs *regs, int tolerant, char **msg,
+                        bool is_excp)
 {
        if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD ||
            boot_cpu_data.x86_vendor == X86_VENDOR_HYGON)