Re: [RFC PATCH 15/26] x86/alternatives: Non-emulated text poking

From: Peter Zijlstra
Date: Wed Apr 08 2020 - 07:13:36 EST


On Tue, Apr 07, 2020 at 10:03:12PM -0700, Ankur Arora wrote:
> +static void __maybe_unused sync_one(void)
> +{
> + /*
> + * We might be executing in NMI context, and so cannot use
> + * IRET as a synchronizing instruction.
> + *
> + * We could use native_write_cr2() but that is not guaranteed
> + * to work on Xen-PV -- it is emulated by Xen and might not
> + * execute an iret (or similar synchronizing instruction)
> + * internally.
> + *
> + * cpuid() would trap as well. Unclear if that's a solution
> + * either.
> + */
> + if (in_nmi())
> + cpuid_eax(1);
> + else
> + sync_core();
> +}

That's not thinking staight; what do you think the INT3 does when it
happens inside an NMI ?