Skip to content

Commit 1bae0cf

Browse files
yghannambp3tk0v
authored andcommitted
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: Yazen Ghannam <[email protected]> Signed-off-by: Borislav Petkov (AMD) <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 48da1ad commit 1bae0cf

File tree

4 files changed

+33
-24
lines changed

4 files changed

+33
-24
lines changed

arch/x86/include/asm/mce.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ static inline void cmci_recheck(void) {}
245245
int mce_available(struct cpuinfo_x86 *c);
246246
bool mce_is_memory_error(struct mce *m);
247247
bool mce_is_correctable(struct mce *m);
248-
int mce_usable_address(struct mce *m);
248+
bool mce_usable_address(struct mce *m);
249249

250250
DECLARE_PER_CPU(unsigned, mce_exception_count);
251251
DECLARE_PER_CPU(unsigned, mce_poll_count);

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

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -453,35 +453,22 @@ static void mce_irq_work_cb(struct irq_work *entry)
453453
mce_schedule_work();
454454
}
455455

456-
/*
457-
* Check if the address reported by the CPU is in a format we can parse.
458-
* It would be possible to add code for most other cases, but all would
459-
* be somewhat complicated (e.g. segment offset would require an instruction
460-
* parser). So only support physical addresses up to page granularity for now.
461-
*/
462-
int mce_usable_address(struct mce *m)
456+
bool mce_usable_address(struct mce *m)
463457
{
464458
if (!(m->status & MCI_STATUS_ADDRV))
465-
return 0;
459+
return false;
466460

467-
if (m->cpuvendor == X86_VENDOR_AMD)
461+
switch (m->cpuvendor) {
462+
case X86_VENDOR_AMD:
468463
return amd_mce_usable_address(m);
469464

470-
/* Checks after this one are Intel/Zhaoxin-specific: */
471-
if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL &&
472-
boot_cpu_data.x86_vendor != X86_VENDOR_ZHAOXIN)
473-
return 1;
474-
475-
if (!(m->status & MCI_STATUS_MISCV))
476-
return 0;
477-
478-
if (MCI_MISC_ADDR_LSB(m->misc) > PAGE_SHIFT)
479-
return 0;
480-
481-
if (MCI_MISC_ADDR_MODE(m->misc) != MCI_MISC_ADDR_PHYS)
482-
return 0;
465+
case X86_VENDOR_INTEL:
466+
case X86_VENDOR_ZHAOXIN:
467+
return intel_mce_usable_address(m);
483468

484-
return 1;
469+
default:
470+
return true;
471+
}
485472
}
486473
EXPORT_SYMBOL_GPL(mce_usable_address);
487474

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,3 +536,23 @@ bool intel_filter_mce(struct mce *m)
536536

537537
return false;
538538
}
539+
540+
/*
541+
* Check if the address reported by the CPU is in a format we can parse.
542+
* It would be possible to add code for most other cases, but all would
543+
* be somewhat complicated (e.g. segment offset would require an instruction
544+
* parser). So only support physical addresses up to page granularity for now.
545+
*/
546+
bool intel_mce_usable_address(struct mce *m)
547+
{
548+
if (!(m->status & MCI_STATUS_MISCV))
549+
return false;
550+
551+
if (MCI_MISC_ADDR_LSB(m->misc) > PAGE_SHIFT)
552+
return false;
553+
554+
if (MCI_MISC_ADDR_MODE(m->misc) != MCI_MISC_ADDR_PHYS)
555+
return false;
556+
557+
return true;
558+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ void intel_init_cmci(void);
4949
void intel_init_lmce(void);
5050
void intel_clear_lmce(void);
5151
bool intel_filter_mce(struct mce *m);
52+
bool intel_mce_usable_address(struct mce *m);
5253
#else
5354
# define cmci_intel_adjust_timer mce_adjust_timer_default
5455
static inline bool mce_intel_cmci_poll(void) { return false; }
@@ -58,6 +59,7 @@ static inline void intel_init_cmci(void) { }
5859
static inline void intel_init_lmce(void) { }
5960
static inline void intel_clear_lmce(void) { }
6061
static inline bool intel_filter_mce(struct mce *m) { return false; }
62+
static inline bool intel_mce_usable_address(struct mce *m) { return false; }
6163
#endif
6264

6365
void mce_timer_kick(unsigned long interval);

0 commit comments

Comments
 (0)