@@ -460,23 +460,6 @@ static void mce_irq_work_cb(struct irq_work *entry)
460460 mce_schedule_work ();
461461}
462462
463- static void mce_report_event (struct pt_regs * regs )
464- {
465- if (regs -> flags & (X86_VM_MASK |X86_EFLAGS_IF )) {
466- mce_notify_irq ();
467- /*
468- * Triggering the work queue here is just an insurance
469- * policy in case the syscall exit notify handler
470- * doesn't run soon enough or ends up running on the
471- * wrong CPU (can happen when audit sleeps)
472- */
473- mce_schedule_work ();
474- return ;
475- }
476-
477- irq_work_queue (& mce_irq_work );
478- }
479-
480463/*
481464 * Check if the address reported by the CPU is in a format we can parse.
482465 * It would be possible to add code for most other cases, but all would
@@ -712,19 +695,49 @@ bool machine_check_poll(enum mcp_flags flags, mce_banks_t *b)
712695
713696 barrier ();
714697 m .status = mce_rdmsrl (msr_ops .status (i ));
698+
699+ /* If this entry is not valid, ignore it */
715700 if (!(m .status & MCI_STATUS_VAL ))
716701 continue ;
717702
718703 /*
719- * Uncorrected or signalled events are handled by the exception
720- * handler when it is enabled, so don't process those here.
721- *
722- * TBD do the same check for MCI_STATUS_EN here?
704+ * If we are logging everything (at CPU online) or this
705+ * is a corrected error, then we must log it.
723706 */
724- if (!(flags & MCP_UC ) &&
725- (m .status & (mca_cfg .ser ? MCI_STATUS_S : MCI_STATUS_UC )))
726- continue ;
707+ if ((flags & MCP_UC ) || !(m .status & MCI_STATUS_UC ))
708+ goto log_it ;
709+
710+ /*
711+ * Newer Intel systems that support software error
712+ * recovery need to make additional checks. Other
713+ * CPUs should skip over uncorrected errors, but log
714+ * everything else.
715+ */
716+ if (!mca_cfg .ser ) {
717+ if (m .status & MCI_STATUS_UC )
718+ continue ;
719+ goto log_it ;
720+ }
727721
722+ /* Log "not enabled" (speculative) errors */
723+ if (!(m .status & MCI_STATUS_EN ))
724+ goto log_it ;
725+
726+ /*
727+ * Log UCNA (SDM: 15.6.3 "UCR Error Classification")
728+ * UC == 1 && PCC == 0 && S == 0
729+ */
730+ if (!(m .status & MCI_STATUS_PCC ) && !(m .status & MCI_STATUS_S ))
731+ goto log_it ;
732+
733+ /*
734+ * Skip anything else. Presumption is that our read of this
735+ * bank is racing with a machine check. Leave the log alone
736+ * for do_machine_check() to deal with it.
737+ */
738+ continue ;
739+
740+ log_it :
728741 error_seen = true;
729742
730743 mce_read_aux (& m , i );
@@ -1301,7 +1314,8 @@ void do_machine_check(struct pt_regs *regs, long error_code)
13011314 mce_panic ("Fatal machine check on current CPU" , & m , msg );
13021315
13031316 if (worst > 0 )
1304- mce_report_event (regs );
1317+ irq_work_queue (& mce_irq_work );
1318+
13051319 mce_wrmsrl (MSR_IA32_MCG_STATUS , 0 );
13061320
13071321 sync_core ();
@@ -1451,13 +1465,12 @@ EXPORT_SYMBOL_GPL(mce_notify_irq);
14511465static int __mcheck_cpu_mce_banks_init (void )
14521466{
14531467 int i ;
1454- u8 num_banks = mca_cfg .banks ;
14551468
1456- mce_banks = kcalloc (num_banks , sizeof (struct mce_bank ), GFP_KERNEL );
1469+ mce_banks = kcalloc (MAX_NR_BANKS , sizeof (struct mce_bank ), GFP_KERNEL );
14571470 if (!mce_banks )
14581471 return - ENOMEM ;
14591472
1460- for (i = 0 ; i < num_banks ; i ++ ) {
1473+ for (i = 0 ; i < MAX_NR_BANKS ; i ++ ) {
14611474 struct mce_bank * b = & mce_banks [i ];
14621475
14631476 b -> ctl = -1ULL ;
@@ -1471,28 +1484,19 @@ static int __mcheck_cpu_mce_banks_init(void)
14711484 */
14721485static int __mcheck_cpu_cap_init (void )
14731486{
1474- unsigned b ;
14751487 u64 cap ;
1488+ u8 b ;
14761489
14771490 rdmsrl (MSR_IA32_MCG_CAP , cap );
14781491
14791492 b = cap & MCG_BANKCNT_MASK ;
1480- if (!mca_cfg .banks )
1481- pr_info ("CPU supports %d MCE banks\n" , b );
1482-
1483- if (b > MAX_NR_BANKS ) {
1484- pr_warn ("Using only %u machine check banks out of %u\n" ,
1485- MAX_NR_BANKS , b );
1493+ if (WARN_ON_ONCE (b > MAX_NR_BANKS ))
14861494 b = MAX_NR_BANKS ;
1487- }
14881495
1489- /* Don't support asymmetric configurations today */
1490- WARN_ON (mca_cfg .banks != 0 && b != mca_cfg .banks );
1491- mca_cfg .banks = b ;
1496+ mca_cfg .banks = max (mca_cfg .banks , b );
14921497
14931498 if (!mce_banks ) {
14941499 int err = __mcheck_cpu_mce_banks_init ();
1495-
14961500 if (err )
14971501 return err ;
14981502 }
@@ -1771,6 +1775,14 @@ static void __mcheck_cpu_init_timer(void)
17711775 mce_start_timer (t );
17721776}
17731777
1778+ bool filter_mce (struct mce * m )
1779+ {
1780+ if (boot_cpu_data .x86_vendor == X86_VENDOR_AMD )
1781+ return amd_filter_mce (m );
1782+
1783+ return false;
1784+ }
1785+
17741786/* Handle unconfigured int18 (should never happen) */
17751787static void unexpected_machine_check (struct pt_regs * regs , long error_code )
17761788{
@@ -2425,8 +2437,8 @@ static int fake_panic_set(void *data, u64 val)
24252437 return 0 ;
24262438}
24272439
2428- DEFINE_SIMPLE_ATTRIBUTE (fake_panic_fops , fake_panic_get ,
2429- fake_panic_set , "%llu\n" );
2440+ DEFINE_DEBUGFS_ATTRIBUTE (fake_panic_fops , fake_panic_get , fake_panic_set ,
2441+ "%llu\n" );
24302442
24312443static int __init mcheck_debugfs_init (void )
24322444{
@@ -2435,8 +2447,8 @@ static int __init mcheck_debugfs_init(void)
24352447 dmce = mce_get_debugfs_dir ();
24362448 if (!dmce )
24372449 return - ENOMEM ;
2438- ffake_panic = debugfs_create_file ("fake_panic" , 0444 , dmce , NULL ,
2439- & fake_panic_fops );
2450+ ffake_panic = debugfs_create_file_unsafe ("fake_panic" , 0444 , dmce ,
2451+ NULL , & fake_panic_fops );
24402452 if (!ffake_panic )
24412453 return - ENOMEM ;
24422454
@@ -2451,6 +2463,8 @@ EXPORT_SYMBOL_GPL(mcsafe_key);
24512463
24522464static int __init mcheck_late_init (void )
24532465{
2466+ pr_info ("Using %d MCE banks\n" , mca_cfg .banks );
2467+
24542468 if (mca_cfg .recovery )
24552469 static_branch_inc (& mcsafe_key );
24562470
0 commit comments