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

x86/mce/amd: Make threshold bank setting hotplug robust

Handle the cases when the CPU goes offline before the bank
setting/reading happens.

[ bp: Write commit message. ]

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Borislav Petkov <bp@suse.de>
Link: https://lkml.kernel.org/r/20200403161943.1458-8-bp@alien8.de

authored by

Thomas Gleixner and committed by
Borislav Petkov
a037f3ca f26d2580

+11 -3
+11 -3
arch/x86/kernel/cpu/mce/amd.c
··· 386 386 struct thresh_restart *tr = _tr; 387 387 u32 hi, lo; 388 388 389 + /* sysfs write might race against an offline operation */ 390 + if (this_cpu_read(threshold_banks)) 391 + return; 392 + 389 393 rdmsr(tr->b->address, lo, hi); 390 394 391 395 if (tr->b->threshold_limit < (hi & THRESHOLD_MAX)) ··· 1089 1085 memset(&tr, 0, sizeof(tr)); 1090 1086 tr.b = b; 1091 1087 1092 - smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1); 1088 + if (smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1)) 1089 + return -ENODEV; 1093 1090 1094 1091 return size; 1095 1092 } ··· 1114 1109 b->threshold_limit = new; 1115 1110 tr.b = b; 1116 1111 1117 - smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1); 1112 + if (smp_call_function_single(b->cpu, threshold_restart_bank, &tr, 1)) 1113 + return -ENODEV; 1118 1114 1119 1115 return size; 1120 1116 } ··· 1124 1118 { 1125 1119 u32 lo, hi; 1126 1120 1127 - rdmsr_on_cpu(b->cpu, b->address, &lo, &hi); 1121 + /* CPU might be offline by now */ 1122 + if (rdmsr_on_cpu(b->cpu, b->address, &lo, &hi)) 1123 + return -ENODEV; 1128 1124 1129 1125 return sprintf(buf, "%u\n", ((hi & THRESHOLD_MAX) - 1130 1126 (THRESHOLD_MAX - b->threshold_limit)));