Re: [RFC PATCH] x86/arch_prctl: Add ARCH_SET_XCR0 to mask XCR0 per-thread

From: Dave Hansen
Date: Mon Jun 18 2018 - 13:43:46 EST


On 06/18/2018 07:42 AM, Keno Fischer wrote:
>> But, in any case, so how is this supposed to work?
>>
>> // get features we are disabling into values matching the
>> // hardware "init state".
>> __asm__("XRSTOR %reg1,%reg2", ...);
>> prctl(PRCTL_SET_XCR0, something);
>>
>> ?
> I was primarily thinking of the ptracer use case,
>
> ptrace(PTRACE_SETFPXREGS, <recorded regs>)
> <inject arch_prctl using ptrace>
>
> in which case there isn't a problem, because the unrecorded regs
> should be in the initial state.

So, to be useful, this interface needs to be called before an
application can run XGETBV or XSAVE for the first time and caches a
"bad" value. I think that means that it might not be feasible to use
outside of cases where you ptrace() something and inject things before
it has a chance to run any real instructions.

Fundamentally, I think that makes _this_ interface pretty useless in
practice. The only practical option is to have a _future_ XCR0 value
set by the prctl() and then have it get made active by the kernel at
execve().

IMNHO, if you haven't guessed yet, I think this whole exercise is a dead
end. Just boot an identical XCR0 VM on your new hardware and do replay
there. Done.