Skip to content

Commit 487d654

Browse files
committed
x86/mce: Remove noinstr annotation from mce_setup()
Instead, sandwitch around the call which is done in noinstr context and mark the caller - mce_gather_info() - as noinstr. Also, document what the whole instrumentation strategy with #MC is going to be in the future and where it all is supposed to be going to. Signed-off-by: Borislav Petkov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 88f66a4 commit 487d654

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ static struct irq_work mce_irq_work;
127127
BLOCKING_NOTIFIER_HEAD(x86_mce_decoder_chain);
128128

129129
/* Do initial initialization of a struct mce */
130-
noinstr void mce_setup(struct mce *m)
130+
void mce_setup(struct mce *m)
131131
{
132132
memset(m, 0, sizeof(struct mce));
133133
m->cpu = m->extcpu = smp_processor_id();
@@ -430,9 +430,15 @@ static noinstr void mce_wrmsrl(u32 msr, u64 v)
430430
* check into our "mce" struct so that we can use it later to assess
431431
* the severity of the problem as we read per-bank specific details.
432432
*/
433-
static inline void mce_gather_info(struct mce *m, struct pt_regs *regs)
433+
static noinstr void mce_gather_info(struct mce *m, struct pt_regs *regs)
434434
{
435+
/*
436+
* Enable instrumentation around mce_setup() which calls external
437+
* facilities.
438+
*/
439+
instrumentation_begin();
435440
mce_setup(m);
441+
instrumentation_end();
436442

437443
m->mcgstatus = mce_rdmsrl(MSR_IA32_MCG_STATUS);
438444
if (regs) {
@@ -1312,11 +1318,11 @@ static noinstr void unexpected_machine_check(struct pt_regs *regs)
13121318
}
13131319

13141320
/*
1315-
* The actual machine check handler. This only handles real
1316-
* exceptions when something got corrupted coming in through int 18.
1321+
* The actual machine check handler. This only handles real exceptions when
1322+
* something got corrupted coming in through int 18.
13171323
*
1318-
* This is executed in NMI context not subject to normal locking rules. This
1319-
* implies that most kernel services cannot be safely used. Don't even
1324+
* This is executed in #MC context not subject to normal locking rules.
1325+
* This implies that most kernel services cannot be safely used. Don't even
13201326
* think about putting a printk in there!
13211327
*
13221328
* On Intel systems this is entered on all CPUs in parallel through
@@ -1328,6 +1334,14 @@ static noinstr void unexpected_machine_check(struct pt_regs *regs)
13281334
* issues: if the machine check was due to a failure of the memory
13291335
* backing the user stack, tracing that reads the user stack will cause
13301336
* potentially infinite recursion.
1337+
*
1338+
* Currently, the #MC handler calls out to a number of external facilities
1339+
* and, therefore, allows instrumentation around them. The optimal thing to
1340+
* have would be to do the absolutely minimal work required in #MC context
1341+
* and have instrumentation disabled only around that. Further processing can
1342+
* then happen in process context where instrumentation is allowed. Achieving
1343+
* that requires careful auditing and modifications. Until then, the code
1344+
* allows instrumentation temporarily, where required. *
13311345
*/
13321346
noinstr void do_machine_check(struct pt_regs *regs)
13331347
{

0 commit comments

Comments
 (0)