@@ -1180,13 +1180,14 @@ static noinstr bool mce_check_crashing_cpu(void)
11801180 return false;
11811181}
11821182
1183- static void __mc_scan_banks (struct mce * m , struct pt_regs * regs , struct mce * final ,
1184- unsigned long * toclear , unsigned long * valid_banks ,
1185- int no_way_out , int * worst )
1183+ static __always_inline int
1184+ __mc_scan_banks (struct mce * m , struct pt_regs * regs , struct mce * final ,
1185+ unsigned long * toclear , unsigned long * valid_banks , int no_way_out ,
1186+ int * worst )
11861187{
11871188 struct mce_bank * mce_banks = this_cpu_ptr (mce_banks_array );
11881189 struct mca_config * cfg = & mca_cfg ;
1189- int severity , i ;
1190+ int severity , i , taint = 0 ;
11901191
11911192 for (i = 0 ; i < this_cpu_read (mce_num_banks ); i ++ ) {
11921193 __clear_bit (i , toclear );
@@ -1213,7 +1214,7 @@ static void __mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *fin
12131214 continue ;
12141215
12151216 /* Set taint even when machine check was not enabled. */
1216- add_taint ( TAINT_MACHINE_CHECK , LOCKDEP_NOW_UNRELIABLE ) ;
1217+ taint ++ ;
12171218
12181219 severity = mce_severity (m , regs , cfg -> tolerant , NULL , true);
12191220
@@ -1236,7 +1237,13 @@ static void __mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *fin
12361237 /* assuming valid severity level != 0 */
12371238 m -> severity = severity ;
12381239
1240+ /*
1241+ * Enable instrumentation around the mce_log() call which is
1242+ * done in #MC context, where instrumentation is disabled.
1243+ */
1244+ instrumentation_begin ();
12391245 mce_log (m );
1246+ instrumentation_end ();
12401247
12411248 if (severity > * worst ) {
12421249 * final = * m ;
@@ -1246,6 +1253,8 @@ static void __mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *fin
12461253
12471254 /* mce_clear_state will clear *final, save locally for use later */
12481255 * m = * final ;
1256+
1257+ return taint ;
12491258}
12501259
12511260static void kill_me_now (struct callback_head * ch )
@@ -1362,7 +1371,7 @@ static noinstr void unexpected_machine_check(struct pt_regs *regs)
13621371 */
13631372noinstr void do_machine_check (struct pt_regs * regs )
13641373{
1365- int worst = 0 , order , no_way_out , kill_current_task , lmce ;
1374+ int worst = 0 , order , no_way_out , kill_current_task , lmce , taint = 0 ;
13661375 DECLARE_BITMAP (valid_banks , MAX_NR_BANKS ) = { 0 };
13671376 DECLARE_BITMAP (toclear , MAX_NR_BANKS ) = { 0 };
13681377 struct mca_config * cfg = & mca_cfg ;
@@ -1441,7 +1450,7 @@ noinstr void do_machine_check(struct pt_regs *regs)
14411450 order = mce_start (& no_way_out );
14421451 }
14431452
1444- __mc_scan_banks (& m , regs , final , toclear , valid_banks , no_way_out , & worst );
1453+ taint = __mc_scan_banks (& m , regs , final , toclear , valid_banks , no_way_out , & worst );
14451454
14461455 if (!no_way_out )
14471456 mce_clear_state (toclear );
@@ -1473,17 +1482,19 @@ noinstr void do_machine_check(struct pt_regs *regs)
14731482 }
14741483 }
14751484
1476- if (worst != MCE_AR_SEVERITY && !kill_current_task )
1477- goto out ;
1478-
14791485 /*
1480- * Enable instrumentation around the external facilities like
1481- * task_work_add() (via queue_task_work()), fixup_exception() etc.
1482- * For now, that is. Fixing this properly would need a lot more involved
1483- * reorganization.
1486+ * Enable instrumentation around the external facilities like task_work_add()
1487+ * (via queue_task_work()), fixup_exception() etc. For now, that is. Fixing this
1488+ * properly would need a lot more involved reorganization.
14841489 */
14851490 instrumentation_begin ();
14861491
1492+ if (taint )
1493+ add_taint (TAINT_MACHINE_CHECK , LOCKDEP_NOW_UNRELIABLE );
1494+
1495+ if (worst != MCE_AR_SEVERITY && !kill_current_task )
1496+ goto out ;
1497+
14871498 /* Fault was in user mode and we need to take some action */
14881499 if ((m .cs & 3 ) == 3 ) {
14891500 /* If this triggers there is no way to recover. Die hard. */
@@ -1513,9 +1524,9 @@ noinstr void do_machine_check(struct pt_regs *regs)
15131524 queue_task_work (& m , msg , kill_me_never );
15141525 }
15151526
1527+ out :
15161528 instrumentation_end ();
15171529
1518- out :
15191530 mce_wrmsrl (MSR_IA32_MCG_STATUS , 0 );
15201531}
15211532EXPORT_SYMBOL_GPL (do_machine_check );
0 commit comments