lkml.org 
[lkml]   [2022]   [Jan]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[PATCH AUTOSEL 5.16 123/217] x86/mce: Prevent severity computation from being instrumented
    Date
    From: Borislav Petkov <bp@suse.de>

    [ Upstream commit 0a5b288e85bbef5227bb6397e31fcf1d7ba9142a ]

    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
    Signed-off-by: Sasha Levin <sashal@kernel.org>
    ---
    arch/x86/kernel/cpu/mce/severity.c | 30 +++++++++++++++++++++---------
    1 file changed, 21 insertions(+), 9 deletions(-)

    diff --git a/arch/x86/kernel/cpu/mce/severity.c b/arch/x86/kernel/cpu/mce/severity.c
    index bb019a594a2c9..171a1495111b1 100644
    --- a/arch/x86/kernel/cpu/mce/severity.c
    +++ b/arch/x86/kernel/cpu/mce/severity.c
    @@ -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;
    }
    @@ -317,8 +329,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);

    @@ -370,8 +382,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);
    @@ -407,8 +419,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)
    --
    2.34.1
    \
     
     \ /
      Last update: 2022-01-18 03:34    [W:4.096 / U:0.084 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site