copy_uabi_to_xstate(9)
π copy_uabi_to_xstate(9) β a Kernel API Manual moment
okay bestie, sit down, because we're about to talk about translating a UABI format buffer into the kernel's internal, hardware-dependent xstate format. it's giving "glow-up but for structs." β¨
πΈ NAME
copy_uabi_to_xstate β literally copy a UABI format buffer into the kernel's xstate π«Ά
π SYNOPSIS
int copy_uabi_to_xstate (struct fpstate *fpstate , const void *kbuf ,
const void __user *ubuf , u32 *pkru );
β¨ ARGUMENTS
fpstateβ the fpstate buffer you're copying to. the destination. the main character πkbufβ the UABI format buffer, but only if it's coming from the kernel πubufβ the UABI format buffer, but only if it's coming from userspace πΈpkruβ where you write the PKRU value to. that's it, that's the whole job π
π¦ DESCRIPTION
so what this bad boy does is convert from the UABI format into the kernel's internal, hardware-dependent format. lowkey iconic of it. π
and here's the tea: this function ultimately has three different callers with distinct PKRU behavior. not two. not four. three. periodt. π₯
- when it's called from sigreturn, the PKRU register gets restored from
fpstatevia anXRSTOR. so correctly copying the UABI format buffer intofpstateis genuinely enough to cover this case β but the caller will also pass a pointer to thethread_struct'spkrufield inpkru, and updating it is harmless. no cap, it's fine π«Ά - when it's called from ptrace, the PKRU register gets restored from the
thread_struct'spkrufield, and a pointer to that is passed inpkru. the kernel restores it manually, so thatXRSTORbehavior β the one where the PKRU register gets reset to the hardware init value (0) if the corresponding xfeatures bit isn't set β gets emulated right here. yes, we're doing the emulation ourselves, we're built different π - when it's called from KVM, the PKRU register gets restored from the vcpu's
pkrufield, and a pointer to that is passed inpkru. here's the thing though: KVM hasn't usedXRSTOR, and it hasn't had that PKRU-resetting behavior described above. so to preserve that KVM behavior, it passesNULLforpkruif the xfeatures bit is not set. respect the legacy, bestie π
ngl, the whole point of this page is that pkru can mean three slightly different things depending on who's calling. know your caller. π
π SEE ALSO
- kernel file
./arch/x86/kernel/fpu/xstate.c check_xtile_data_against_struct(9)__copy_xstate_to_uabi_buf(9)copy_xstate_to_uabi_buf(9)xsaves(9)xrstors(9)fpstate_realloc(9)fpu_xstate_prctl(9)
go read those too, iykyk π
and that's the whole page, bestie! π this little gem lives in ./arch/x86/kernel/fpu and it's dated October 2026, all wrapped up in the Kernel API Manual. mwah, slay, go convert some buffers responsibly πβ¨π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms