Re: [PATCH] x86/mce: Check that memory address is usable for recovery

Tony Luck
2023-04-18T18:24:03Z

On Tue, Apr 18, 2023 at 01:51:37PM -0400, Yazen Ghannam wrote:
> I agree. And I think all these checks should be baked into the severity.
> We'll need additional, fine-grained severity levels though.
>
> The "m.cs" and "m.kflags" checks could also be baked in.
>
> Instead of just one AR severity:
> ...
> MCE_AR_SEVERITY,
> MCE_PANIC_SEVERITY,
>
> replace it with specific cases:
> ...
> MCE_AR_USER_RECOV,
> MCE_AR_USER_KILL,
> MCE_AR_KERNEL_COPYIN,
> MCE_AR_KERNEL_RECOV,
> MCE_PANIC_SEVERITY,
>
> Then the #MC handler can look like this:
>
> if (worst < MCE_AR_USER_RECOV)
> goto out;
>
> if (severity == MCE_AR_USER_RECOV)
> queue_task_work(&m, msg, kill_me_maybe);
>
> if (severity == MCE_AR_USER_KILL)
> force_sig(SIGBUS);
>
> if (severity == MCE_AR_KERNEL_COPYIN)
> queue_task_work(&m, msg, kill_me_never);
>
> if (severity == MCE_AR_KERNEL_RECOV) {
> if (!fixup_exception(regs, X86_TRAP_MC, 0, 0))
> mce_panic("Failed kernel mode recovery");
> }
>
> I can take a shot at this if it seems reasonable.

That looks much cleaner. There may be some extra MCE_AR_KERNEL* options
in the future (I'd like someday to address COPYOUT when the corrupt
kernel data is in the page cache). But I don't think the number of cases
is going to explode into dozens of cases.

> What do you think?

Brave person ... you are going to have to tinker with
arch/x86/kernel/cpu/mce/severity.c ! Good luck.

-Tony