Skip to content

Commit 78ce241

Browse files
suryasaimadhuKAGA-KOKO
authored andcommitted
x86/MCE/AMD: Cache SMCA MISC block addresses
... into a global, two-dimensional array and service subsequent reads from that cache to avoid rdmsr_on_cpu() calls during CPU hotplug (IPIs with IRQs disabled). In addition, this fixes a KASAN slab-out-of-bounds read due to wrong usage of the bank->blocks pointer. Fixes: 27bd595 ("x86/mce/AMD: Get address from already initialized block") Reported-by: Johannes Hirte <[email protected]> Tested-by: Johannes Hirte <[email protected]> Signed-off-by: Borislav Petkov <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: Yazen Ghannam <[email protected]> Link: http://lkml.kernel.org/r/20180414004230.GA2033@probook
1 parent 73fcb1a commit 78ce241

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

arch/x86/kernel/cpu/mcheck/mce_amd.c

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ static struct smca_bank_name smca_names[] = {
9494
[SMCA_SMU] = { "smu", "System Management Unit" },
9595
};
9696

97+
static u32 smca_bank_addrs[MAX_NR_BANKS][NR_BLOCKS] __ro_after_init =
98+
{
99+
[0 ... MAX_NR_BANKS - 1] = { [0 ... NR_BLOCKS - 1] = -1 }
100+
};
101+
97102
const char *smca_get_name(enum smca_bank_types t)
98103
{
99104
if (t >= N_SMCA_BANK_TYPES)
@@ -443,20 +448,26 @@ static u32 smca_get_block_address(unsigned int cpu, unsigned int bank,
443448
if (!block)
444449
return MSR_AMD64_SMCA_MCx_MISC(bank);
445450

451+
/* Check our cache first: */
452+
if (smca_bank_addrs[bank][block] != -1)
453+
return smca_bank_addrs[bank][block];
454+
446455
/*
447456
* For SMCA enabled processors, BLKPTR field of the first MISC register
448457
* (MCx_MISC0) indicates presence of additional MISC regs set (MISC1-4).
449458
*/
450459
if (rdmsr_safe_on_cpu(cpu, MSR_AMD64_SMCA_MCx_CONFIG(bank), &low, &high))
451-
return addr;
460+
goto out;
452461

453462
if (!(low & MCI_CONFIG_MCAX))
454-
return addr;
463+
goto out;
455464

456465
if (!rdmsr_safe_on_cpu(cpu, MSR_AMD64_SMCA_MCx_MISC(bank), &low, &high) &&
457466
(low & MASK_BLKPTR_LO))
458-
return MSR_AMD64_SMCA_MCx_MISCy(bank, block - 1);
467+
addr = MSR_AMD64_SMCA_MCx_MISCy(bank, block - 1);
459468

469+
out:
470+
smca_bank_addrs[bank][block] = addr;
460471
return addr;
461472
}
462473

@@ -468,18 +479,6 @@ static u32 get_block_address(unsigned int cpu, u32 current_addr, u32 low, u32 hi
468479
if ((bank >= mca_cfg.banks) || (block >= NR_BLOCKS))
469480
return addr;
470481

471-
/* Get address from already initialized block. */
472-
if (per_cpu(threshold_banks, cpu)) {
473-
struct threshold_bank *bankp = per_cpu(threshold_banks, cpu)[bank];
474-
475-
if (bankp && bankp->blocks) {
476-
struct threshold_block *blockp = &bankp->blocks[block];
477-
478-
if (blockp)
479-
return blockp->address;
480-
}
481-
}
482-
483482
if (mce_flags.smca)
484483
return smca_get_block_address(cpu, bank, block);
485484

0 commit comments

Comments
 (0)