Re: [RFC PATCH 03/12] x86/fpu/xstate: Add xsaves_nmi

From: Dave Hansen
Date: Fri Jun 13 2025 - 11:19:37 EST


On 6/13/25 07:54, Liang, Kan wrote:
>> One other thing...
>>
>> XSAVES uses the modified optimization. That means if you did something
>> like this:
>>
>> NMI=>
>> xsaves_nmi();
>> <=IRET
>> ... run a little bit in the kernel
>> NMI=> // another NMI
>> xsaves_nmi();
>> <=IRET
>>
>> The second XSAVES might not actually write anything to the buffer
>> because the registers didn't change (they weren't modified). Is that OK?
> Yes. The per-cpu buffer in perf is only used by this XSAVES. No one will
> clear it or modify it between the two xsaves_nmi().

What prevents it from being freed, reallocated to some other user, freed
and reallocated to the per-cpu buffer? ;)

But, really, the thing that saves you here is that the modified
optimization only comes into effect if you XRSTOR from an XSAVE buffer.
This buffer is only ever XSAVES'd to.

So I think it's safe ... from the modified optimization. I'll look at
the init optimization later in the series.