Re: [PATCH 2/2] x86/pkeys: Set XINUSE[PKRU] to 1 so that PKRU is XRSTOR'd correctly
From: Aruna Ramakrishna
Date: Wed Nov 13 2024 - 15:05:11 EST
> On Nov 13, 2024, at 11:10 AM, Dave Hansen <dave.hansen@xxxxxxxxx> wrote:
>
> On 11/13/24 10:14, Aruna Ramakrishna wrote:
>> PKRU value is not XRSTOR'd from the XSAVE area if the corresponding
>> XINUSE[i] bit is 0. When PKRU value is set to 0, it sets XINUSE[PKRU]
>> to 0 on AMD systems, which means the value updated on the sigframe
>> later (after a wrpkru(0)) is ignored.
>
> I think this is confusing XINUSE and XSTATE_BV.
>
> XINUSE is really internal to the CPU and is partially exposed in
> xgetbv(1). But XINUSE is monolithic; it includes user and supervisor state.
>
> XSTATE_BV is the actual memory location in the XSAVE buffer.
>
> So I think it's incorrect to say that XRSTOR behavior depends on XINUSE.
> XRSTOR behavior depends on XSTATE_BV.
You’re right; XSTATE_BV[i] is set during XSAVE based on XINUSE[i], and
XRSTOR restores based on XSTATE_BV. I will reword that (and change the
variable name in update_pkru_in_sigframe()) for v2.
Thanks,
Aruna