Skip to content

Commit f11445b

Browse files
committed
x86/mce: Use arch atomic and bit helpers
The arch helpers do not have explicit KASAN instrumentation. Use them in noinstr code. Inline a couple more functions with single call sites, while at it: mce_severity_amd_smca() has a single call-site which is noinstr so force the inlining and fix: vmlinux.o: warning: objtool: mce_severity_amd.constprop.0()+0xca: call to \ mce_severity_amd_smca() leaves .noinstr.text section Always inline mca_msr_reg(): text data bss dec hex filename 16065240 128031326 36405368 180501934 ac23dae vmlinux.before 16065240 128031294 36405368 180501902 ac23d8e vmlinux.after and mce_no_way_out() as the latter one is used only once, to fix: vmlinux.o: warning: objtool: mce_read_aux()+0x53: call to mca_msr_reg() leaves .noinstr.text section vmlinux.o: warning: objtool: do_machine_check()+0xc9: call to mce_no_way_out() leaves .noinstr.text section Signed-off-by: Borislav Petkov <bp@suse.de> Acked-by: Marco Elver <elver@google.com> Link: https://lore.kernel.org/r/20220204083015.17317-4-bp@alien8.de
1 parent c0f6799 commit f11445b

3 files changed

Lines changed: 41 additions & 42 deletions

File tree

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

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -173,27 +173,6 @@ void mce_unregister_decode_chain(struct notifier_block *nb)
173173
}
174174
EXPORT_SYMBOL_GPL(mce_unregister_decode_chain);
175175

176-
u32 mca_msr_reg(int bank, enum mca_msr reg)
177-
{
178-
if (mce_flags.smca) {
179-
switch (reg) {
180-
case MCA_CTL: return MSR_AMD64_SMCA_MCx_CTL(bank);
181-
case MCA_ADDR: return MSR_AMD64_SMCA_MCx_ADDR(bank);
182-
case MCA_MISC: return MSR_AMD64_SMCA_MCx_MISC(bank);
183-
case MCA_STATUS: return MSR_AMD64_SMCA_MCx_STATUS(bank);
184-
}
185-
}
186-
187-
switch (reg) {
188-
case MCA_CTL: return MSR_IA32_MCx_CTL(bank);
189-
case MCA_ADDR: return MSR_IA32_MCx_ADDR(bank);
190-
case MCA_MISC: return MSR_IA32_MCx_MISC(bank);
191-
case MCA_STATUS: return MSR_IA32_MCx_STATUS(bank);
192-
}
193-
194-
return 0;
195-
}
196-
197176
static void __print_mce(struct mce *m)
198177
{
199178
pr_emerg(HW_ERR "CPU %d: Machine Check%s: %Lx Bank %d: %016Lx\n",
@@ -814,7 +793,8 @@ EXPORT_SYMBOL_GPL(machine_check_poll);
814793
* the severity assessment code. Pretend that EIPV was set, and take the
815794
* ip/cs values from the pt_regs that mce_gather_info() ignored earlier.
816795
*/
817-
static void quirk_sandybridge_ifu(int bank, struct mce *m, struct pt_regs *regs)
796+
static __always_inline void
797+
quirk_sandybridge_ifu(int bank, struct mce *m, struct pt_regs *regs)
818798
{
819799
if (bank != 0)
820800
return;
@@ -838,8 +818,8 @@ static void quirk_sandybridge_ifu(int bank, struct mce *m, struct pt_regs *regs)
838818
* Do a quick check if any of the events requires a panic.
839819
* This decides if we keep the events around or clear them.
840820
*/
841-
static int mce_no_way_out(struct mce *m, char **msg, unsigned long *validp,
842-
struct pt_regs *regs)
821+
static __always_inline int mce_no_way_out(struct mce *m, char **msg, unsigned long *validp,
822+
struct pt_regs *regs)
843823
{
844824
char *tmp = *msg;
845825
int i;
@@ -849,7 +829,7 @@ static int mce_no_way_out(struct mce *m, char **msg, unsigned long *validp,
849829
if (!(m->status & MCI_STATUS_VAL))
850830
continue;
851831

852-
__set_bit(i, validp);
832+
arch___set_bit(i, validp);
853833
if (mce_flags.snb_ifu_quirk)
854834
quirk_sandybridge_ifu(i, m, regs);
855835

@@ -1015,24 +995,24 @@ static noinstr int mce_start(int *no_way_out)
1015995
if (!timeout)
1016996
return ret;
1017997

1018-
atomic_add(*no_way_out, &global_nwo);
998+
arch_atomic_add(*no_way_out, &global_nwo);
1019999
/*
10201000
* Rely on the implied barrier below, such that global_nwo
10211001
* is updated before mce_callin.
10221002
*/
1023-
order = atomic_inc_return(&mce_callin);
1024-
cpumask_clear_cpu(smp_processor_id(), &mce_missing_cpus);
1003+
order = arch_atomic_inc_return(&mce_callin);
1004+
arch_cpumask_clear_cpu(smp_processor_id(), &mce_missing_cpus);
10251005

10261006
/* Enable instrumentation around calls to external facilities */
10271007
instrumentation_begin();
10281008

10291009
/*
10301010
* Wait for everyone.
10311011
*/
1032-
while (atomic_read(&mce_callin) != num_online_cpus()) {
1012+
while (arch_atomic_read(&mce_callin) != num_online_cpus()) {
10331013
if (mce_timed_out(&timeout,
10341014
"Timeout: Not all CPUs entered broadcast exception handler")) {
1035-
atomic_set(&global_nwo, 0);
1015+
arch_atomic_set(&global_nwo, 0);
10361016
goto out;
10371017
}
10381018
ndelay(SPINUNIT);
@@ -1047,18 +1027,18 @@ static noinstr int mce_start(int *no_way_out)
10471027
/*
10481028
* Monarch: Starts executing now, the others wait.
10491029
*/
1050-
atomic_set(&mce_executing, 1);
1030+
arch_atomic_set(&mce_executing, 1);
10511031
} else {
10521032
/*
10531033
* Subject: Now start the scanning loop one by one in
10541034
* the original callin order.
10551035
* This way when there are any shared banks it will be
10561036
* only seen by one CPU before cleared, avoiding duplicates.
10571037
*/
1058-
while (atomic_read(&mce_executing) < order) {
1038+
while (arch_atomic_read(&mce_executing) < order) {
10591039
if (mce_timed_out(&timeout,
10601040
"Timeout: Subject CPUs unable to finish machine check processing")) {
1061-
atomic_set(&global_nwo, 0);
1041+
arch_atomic_set(&global_nwo, 0);
10621042
goto out;
10631043
}
10641044
ndelay(SPINUNIT);
@@ -1068,7 +1048,7 @@ static noinstr int mce_start(int *no_way_out)
10681048
/*
10691049
* Cache the global no_way_out state.
10701050
*/
1071-
*no_way_out = atomic_read(&global_nwo);
1051+
*no_way_out = arch_atomic_read(&global_nwo);
10721052

10731053
ret = order;
10741054

@@ -1153,12 +1133,12 @@ static noinstr int mce_end(int order)
11531133
return ret;
11541134
}
11551135

1156-
static void mce_clear_state(unsigned long *toclear)
1136+
static __always_inline void mce_clear_state(unsigned long *toclear)
11571137
{
11581138
int i;
11591139

11601140
for (i = 0; i < this_cpu_read(mce_num_banks); i++) {
1161-
if (test_bit(i, toclear))
1141+
if (arch_test_bit(i, toclear))
11621142
mce_wrmsrl(mca_msr_reg(i, MCA_STATUS), 0);
11631143
}
11641144
}
@@ -1208,8 +1188,8 @@ __mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *final,
12081188
int severity, i, taint = 0;
12091189

12101190
for (i = 0; i < this_cpu_read(mce_num_banks); i++) {
1211-
__clear_bit(i, toclear);
1212-
if (!test_bit(i, valid_banks))
1191+
arch___clear_bit(i, toclear);
1192+
if (!arch_test_bit(i, valid_banks))
12131193
continue;
12141194

12151195
if (!mce_banks[i].ctl)
@@ -1244,7 +1224,7 @@ __mc_scan_banks(struct mce *m, struct pt_regs *regs, struct mce *final,
12441224
severity == MCE_UCNA_SEVERITY) && !no_way_out)
12451225
continue;
12461226

1247-
__set_bit(i, toclear);
1227+
arch___set_bit(i, toclear);
12481228

12491229
/* Machine check event was not enabled. Clear, but ignore. */
12501230
if (severity == MCE_NO_SEVERITY)

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

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ enum mca_msr {
182182
MCA_MISC,
183183
};
184184

185-
u32 mca_msr_reg(int bank, enum mca_msr reg);
186-
187185
/* Decide whether to add MCE record to MCE event pool or filter it out. */
188186
extern bool filter_mce(struct mce *m);
189187

@@ -209,4 +207,25 @@ static inline void winchip_machine_check(struct pt_regs *regs) {}
209207

210208
noinstr u64 mce_rdmsrl(u32 msr);
211209

210+
static __always_inline u32 mca_msr_reg(int bank, enum mca_msr reg)
211+
{
212+
if (mce_flags.smca) {
213+
switch (reg) {
214+
case MCA_CTL: return MSR_AMD64_SMCA_MCx_CTL(bank);
215+
case MCA_ADDR: return MSR_AMD64_SMCA_MCx_ADDR(bank);
216+
case MCA_MISC: return MSR_AMD64_SMCA_MCx_MISC(bank);
217+
case MCA_STATUS: return MSR_AMD64_SMCA_MCx_STATUS(bank);
218+
}
219+
}
220+
221+
switch (reg) {
222+
case MCA_CTL: return MSR_IA32_MCx_CTL(bank);
223+
case MCA_ADDR: return MSR_IA32_MCx_ADDR(bank);
224+
case MCA_MISC: return MSR_IA32_MCx_MISC(bank);
225+
case MCA_STATUS: return MSR_IA32_MCx_STATUS(bank);
226+
}
227+
228+
return 0;
229+
}
230+
212231
#endif /* __X86_MCE_INTERNAL_H__ */

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ static noinstr int error_context(struct mce *m, struct pt_regs *regs)
301301
}
302302
}
303303

304-
static int mce_severity_amd_smca(struct mce *m, enum context err_ctx)
304+
static __always_inline int mce_severity_amd_smca(struct mce *m, enum context err_ctx)
305305
{
306306
u64 mcx_cfg;
307307

0 commit comments

Comments
 (0)