Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

x86/mce: Convert the CEC to use the MCE notifier

The CEC code has its claws in a couple of routines in mce/core.c.
Convert it to just register itself on the normal MCE notifier chain.

[ bp: Make cec_add_elem() and cec_init() static. ]

Signed-off-by: Tony Luck <tony.luck@intel.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Tested-by: Tony Luck <tony.luck@intel.com>
Link: https://lkml.kernel.org/r/20200214222720.13168-3-tony.luck@intel.com

authored by

Tony Luck and committed by
Borislav Petkov
9554bfe4 c9c6d216

+28 -26
-19
arch/x86/kernel/cpu/mce/core.c
··· 544 544 } 545 545 EXPORT_SYMBOL_GPL(mce_is_correctable); 546 546 547 - static bool cec_add_mce(struct mce *m) 548 - { 549 - if (!m) 550 - return false; 551 - 552 - /* We eat only correctable DRAM errors with usable addresses. */ 553 - if (mce_is_memory_error(m) && 554 - mce_is_correctable(m) && 555 - mce_usable_address(m)) 556 - if (!cec_add_elem(m->addr >> PAGE_SHIFT)) 557 - return true; 558 - 559 - return false; 560 - } 561 - 562 547 static int mce_early_notifier(struct notifier_block *nb, unsigned long val, 563 548 void *data) 564 549 { ··· 551 566 552 567 if (!m) 553 568 return NOTIFY_DONE; 554 - 555 - if (cec_add_mce(m)) 556 - return NOTIFY_STOP; 557 569 558 570 /* Emit the trace record: */ 559 571 trace_mce_record(m); ··· 2594 2612 static_branch_inc(&mcsafe_key); 2595 2613 2596 2614 mcheck_debugfs_init(); 2597 - cec_init(); 2598 2615 2599 2616 /* 2600 2617 * Flush out everything that has been logged during early boot, now that
+28 -2
drivers/ras/cec.c
··· 309 309 return ret; 310 310 } 311 311 312 - int cec_add_elem(u64 pfn) 312 + static int cec_add_elem(u64 pfn) 313 313 { 314 314 struct ce_array *ca = &ce_arr; 315 315 unsigned int to = 0; ··· 527 527 return 1; 528 528 } 529 529 530 - void __init cec_init(void) 530 + static int cec_notifier(struct notifier_block *nb, unsigned long val, 531 + void *data) 532 + { 533 + struct mce *m = (struct mce *)data; 534 + 535 + if (!m) 536 + return NOTIFY_DONE; 537 + 538 + /* We eat only correctable DRAM errors with usable addresses. */ 539 + if (mce_is_memory_error(m) && 540 + mce_is_correctable(m) && 541 + mce_usable_address(m)) 542 + if (!cec_add_elem(m->addr >> PAGE_SHIFT)) 543 + return NOTIFY_STOP; 544 + 545 + return NOTIFY_DONE; 546 + } 547 + 548 + static struct notifier_block cec_nb = { 549 + .notifier_call = cec_notifier, 550 + .priority = MCE_PRIO_CEC, 551 + }; 552 + 553 + static void __init cec_init(void) 531 554 { 532 555 if (ce_arr.disabled) 533 556 return; ··· 569 546 INIT_DELAYED_WORK(&cec_work, cec_work_fn); 570 547 schedule_delayed_work(&cec_work, CEC_DECAY_DEFAULT_INTERVAL); 571 548 549 + mce_register_decode_chain(&cec_nb); 550 + 572 551 pr_info("Correctable Errors collector initialized.\n"); 573 552 } 553 + late_initcall(cec_init); 574 554 575 555 int __init parse_cec_param(char *str) 576 556 {
-5
include/linux/ras.h
··· 17 17 #endif 18 18 19 19 #ifdef CONFIG_RAS_CEC 20 - void __init cec_init(void); 21 20 int __init parse_cec_param(char *str); 22 - int cec_add_elem(u64 pfn); 23 - #else 24 - static inline void __init cec_init(void) { } 25 - static inline int cec_add_elem(u64 pfn) { return -ENODEV; } 26 21 #endif 27 22 28 23 #ifdef CONFIG_RAS