Skip to content

Commit 48da1ad

Browse files
yghannambp3tk0v
authored andcommitted
x86/mce: Define amd_mce_usable_address()
Currently, all valid MCA_ADDR values are assumed to be usable on AMD systems. However, this is not correct in most cases. Notifiers expecting usable addresses may then operate on inappropriate values. Define a helper function to do AMD-specific checks for a usable memory address. List out all known cases. [ bp: Tone down the capitalized words. ] Signed-off-by: Yazen Ghannam <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 495a91d commit 48da1ad

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,44 @@ bool amd_mce_is_memory_error(struct mce *m)
746746
return legacy_mce_is_memory_error(m);
747747
}
748748

749+
/*
750+
* AMD systems do not have an explicit indicator that the value in MCA_ADDR is
751+
* a system physical address. Therefore, individual cases need to be detected.
752+
* Future cases and checks will be added as needed.
753+
*
754+
* 1) General case
755+
* a) Assume address is not usable.
756+
* 2) Poison errors
757+
* a) Indicated by MCA_STATUS[43]: poison. Defined for all banks except legacy
758+
* northbridge (bank 4).
759+
* b) Refers to poison consumption in the core. Does not include "no action",
760+
* "action optional", or "deferred" error severities.
761+
* c) Will include a usable address so that immediate action can be taken.
762+
* 3) Northbridge DRAM ECC errors
763+
* a) Reported in legacy bank 4 with extended error code (XEC) 8.
764+
* b) MCA_STATUS[43] is *not* defined as poison in legacy bank 4. Therefore,
765+
* this bit should not be checked.
766+
*
767+
* NOTE: SMCA UMC memory errors fall into case #1.
768+
*/
769+
bool amd_mce_usable_address(struct mce *m)
770+
{
771+
/* Check special northbridge case 3) first. */
772+
if (!mce_flags.smca) {
773+
if (legacy_mce_is_memory_error(m))
774+
return true;
775+
else if (m->bank == 4)
776+
return false;
777+
}
778+
779+
/* Check poison bit for all other bank types. */
780+
if (m->status & MCI_STATUS_POISON)
781+
return true;
782+
783+
/* Assume address is not usable for all others. */
784+
return false;
785+
}
786+
749787
static void __log_error(unsigned int bank, u64 status, u64 addr, u64 misc)
750788
{
751789
struct mce m;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,9 @@ int mce_usable_address(struct mce *m)
464464
if (!(m->status & MCI_STATUS_ADDRV))
465465
return 0;
466466

467+
if (m->cpuvendor == X86_VENDOR_AMD)
468+
return amd_mce_usable_address(m);
469+
467470
/* Checks after this one are Intel/Zhaoxin-specific: */
468471
if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL &&
469472
boot_cpu_data.x86_vendor != X86_VENDOR_ZHAOXIN)

arch/x86/kernel/cpu/mce/internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ extern bool filter_mce(struct mce *m);
210210

211211
#ifdef CONFIG_X86_MCE_AMD
212212
extern bool amd_filter_mce(struct mce *m);
213+
bool amd_mce_usable_address(struct mce *m);
213214

214215
/*
215216
* If MCA_CONFIG[McaLsbInStatusSupported] is set, extract ErrAddr in bits
@@ -237,6 +238,7 @@ static __always_inline void smca_extract_err_addr(struct mce *m)
237238

238239
#else
239240
static inline bool amd_filter_mce(struct mce *m) { return false; }
241+
static inline bool amd_mce_usable_address(struct mce *m) { return false; }
240242
static inline void smca_extract_err_addr(struct mce *m) { }
241243
#endif
242244

0 commit comments

Comments
 (0)