Skip to content

Commit

Permalink
x86/fault: Skip the AMD erratum torvalds#91 workaround on unaffected …
Browse files Browse the repository at this point in the history
…CPUs

According to the Revision Guide for AMD Athlon™ 64 and AMD Opteron™
Processors, only early revisions of family 0xF are affected. This will
avoid unnecessarily fetching instruction bytes before sending SIGSEGV to
user programs.

Signed-off-by: Andy Lutomirski <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Link: https://lkml.kernel.org/r/477173b7784bc28afb3e53d76ae5ef143917e8dd.1612924255.git.luto@kernel.org
  • Loading branch information
amluto authored and suryasaimadhu committed Feb 10, 2021
1 parent 35f1c89 commit d24df8e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions arch/x86/mm/fault.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,26 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
}
}

static bool is_amd_k8_pre_npt(void)
{
struct cpuinfo_x86 *c = &boot_cpu_data;

return unlikely(IS_ENABLED(CONFIG_CPU_SUP_AMD) &&
c->x86_vendor == X86_VENDOR_AMD &&
c->x86 == 0xf && c->x86_model < 0x40);
}

static int
is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
{
unsigned char *max_instr;
unsigned char *instr;
int prefetch = 0;

/* Erratum #91 affects AMD K8, pre-NPT CPUs */
if (!is_amd_k8_pre_npt())
return 0;

/*
* If it was a exec (instruction fetch) fault on NX page, then
* do not ignore the fault:
Expand Down

0 comments on commit d24df8e

Please sign in to comment.