Commit 1bae0cfe authored by Yazen Ghannam's avatar Yazen Ghannam Committed by Borislav Petkov (AMD)

x86/mce: Cleanup mce_usable_address()

Move Intel-specific checks into a helper function.

Explicitly use "bool" for return type.

No functional change intended.
Signed-off-by: default avatarYazen Ghannam <yazen.ghannam@amd.com>
Signed-off-by: default avatarBorislav Petkov (AMD) <bp@alien8.de>
Link: https://lore.kernel.org/r/20230613141142.36801-4-yazen.ghannam@amd.com
parent 48da1ad8
...@@ -245,7 +245,7 @@ static inline void cmci_recheck(void) {} ...@@ -245,7 +245,7 @@ static inline void cmci_recheck(void) {}
int mce_available(struct cpuinfo_x86 *c); int mce_available(struct cpuinfo_x86 *c);
bool mce_is_memory_error(struct mce *m); bool mce_is_memory_error(struct mce *m);
bool mce_is_correctable(struct mce *m); bool mce_is_correctable(struct mce *m);
int mce_usable_address(struct mce *m); bool mce_usable_address(struct mce *m);
DECLARE_PER_CPU(unsigned, mce_exception_count); DECLARE_PER_CPU(unsigned, mce_exception_count);
DECLARE_PER_CPU(unsigned, mce_poll_count); DECLARE_PER_CPU(unsigned, mce_poll_count);
......
...@@ -453,35 +453,22 @@ static void mce_irq_work_cb(struct irq_work *entry) ...@@ -453,35 +453,22 @@ static void mce_irq_work_cb(struct irq_work *entry)
mce_schedule_work(); mce_schedule_work();
} }
/* bool mce_usable_address(struct mce *m)
* Check if the address reported by the CPU is in a format we can parse.
* It would be possible to add code for most other cases, but all would
* be somewhat complicated (e.g. segment offset would require an instruction
* parser). So only support physical addresses up to page granularity for now.
*/
int mce_usable_address(struct mce *m)
{ {
if (!(m->status & MCI_STATUS_ADDRV)) if (!(m->status & MCI_STATUS_ADDRV))
return 0; return false;
if (m->cpuvendor == X86_VENDOR_AMD) switch (m->cpuvendor) {
case X86_VENDOR_AMD:
return amd_mce_usable_address(m); return amd_mce_usable_address(m);
/* Checks after this one are Intel/Zhaoxin-specific: */ case X86_VENDOR_INTEL:
if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL && case X86_VENDOR_ZHAOXIN:
boot_cpu_data.x86_vendor != X86_VENDOR_ZHAOXIN) return intel_mce_usable_address(m);
return 1;
if (!(m->status & MCI_STATUS_MISCV))
return 0;
if (MCI_MISC_ADDR_LSB(m->misc) > PAGE_SHIFT)
return 0;
if (MCI_MISC_ADDR_MODE(m->misc) != MCI_MISC_ADDR_PHYS)
return 0;
return 1; default:
return true;
}
} }
EXPORT_SYMBOL_GPL(mce_usable_address); EXPORT_SYMBOL_GPL(mce_usable_address);
......
...@@ -536,3 +536,23 @@ bool intel_filter_mce(struct mce *m) ...@@ -536,3 +536,23 @@ bool intel_filter_mce(struct mce *m)
return false; return false;
} }
/*
* Check if the address reported by the CPU is in a format we can parse.
* It would be possible to add code for most other cases, but all would
* be somewhat complicated (e.g. segment offset would require an instruction
* parser). So only support physical addresses up to page granularity for now.
*/
bool intel_mce_usable_address(struct mce *m)
{
if (!(m->status & MCI_STATUS_MISCV))
return false;
if (MCI_MISC_ADDR_LSB(m->misc) > PAGE_SHIFT)
return false;
if (MCI_MISC_ADDR_MODE(m->misc) != MCI_MISC_ADDR_PHYS)
return false;
return true;
}
...@@ -49,6 +49,7 @@ void intel_init_cmci(void); ...@@ -49,6 +49,7 @@ void intel_init_cmci(void);
void intel_init_lmce(void); void intel_init_lmce(void);
void intel_clear_lmce(void); void intel_clear_lmce(void);
bool intel_filter_mce(struct mce *m); bool intel_filter_mce(struct mce *m);
bool intel_mce_usable_address(struct mce *m);
#else #else
# define cmci_intel_adjust_timer mce_adjust_timer_default # define cmci_intel_adjust_timer mce_adjust_timer_default
static inline bool mce_intel_cmci_poll(void) { return false; } static inline bool mce_intel_cmci_poll(void) { return false; }
...@@ -58,6 +59,7 @@ static inline void intel_init_cmci(void) { } ...@@ -58,6 +59,7 @@ static inline void intel_init_cmci(void) { }
static inline void intel_init_lmce(void) { } static inline void intel_init_lmce(void) { }
static inline void intel_clear_lmce(void) { } static inline void intel_clear_lmce(void) { }
static inline bool intel_filter_mce(struct mce *m) { return false; } static inline bool intel_filter_mce(struct mce *m) { return false; }
static inline bool intel_mce_usable_address(struct mce *m) { return false; }
#endif #endif
void mce_timer_kick(unsigned long interval); void mce_timer_kick(unsigned long interval);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment