sgx_virt_einit(9)
π sgx_virt_einit(9)
okay so bestie, we're in the Kernel API Manual today, and this little icon is sgx_virt_einit β the function that runs EINIT on behalf of a guest. yes it's giving virtualization. yes it's giving SGX. yes we're gonna understand it. let's go π«Ά
β¨ NAME β¨
sgx_virt_einit β Run EINIT on behalf of guest β¨
like literally that's the whole job. it runs EINIT, but for the guest. no cap.
πΈ SYNOPSIS πΈ
int sgx_virt_einit (void __user *sigstruct , void __user *token , void
__user *secs , u64 *lepubkeyhash , int *trapnr );
yup. five arguments. all of them matter. we're gonna walk through every single one, don't worry π
π¦ ARGUMENTS π¦
sigstructβ a userspace pointer to theSIGSTRUCTstructure. that's it. that's what it is πtokenβ a userspace pointer to theEINITTOKENstructure. iconic little token behavior.secsβ a userspace pointer to theSECSpage. yes the whole page.lepubkeyhashβ pointer to the guest's virtualSGX_LEPUBKEYHASHMSR values. note the emphasis on virtual bestie, the asterisks are load-bearing πtrapnrβ the trap number injected to the guest in case of an EINIT error. like a little "something went wrong" delivery service.
π₯ DESCRIPTION π₯
so here's the vibe: KVM traps EINIT, and this function runs EINIT on behalf of the guest. that's the main character move.
but here's the spicy part πΆοΈ β if SGX_LC is available in the host, the SGX driver may rewrite the hardware values at wish. at wish! so KVM needs to update the hardware values to the guest's virtual MSR values, in order to ensure EINIT is executed with the expected hardware values. the way that this is all about making sure the values line up β obsessed. it's literally a vibe check for your MSRs π
β RETURN β
0β EINIT was successful. slay! π<0β on error. π not slay, but we respect the honesty.
π SEE ALSO π
- the kernel file
./arch/x86/kernel/cpu/sgx/virt.c sgx_virt_ecreate(9)β the sibling! the companion! the other half of the virtual SGX duo π§
ngl none of this is optional reading, the file path is right there, go look at it bestie π
okay and finally, for the credits portion of the group chat π: this page comes from ./arch/x86/kernel/cpu/sgx, dated October 2026, and the version string is sgx_virt_einit(9) in both the header and the footer because symmetry is beautiful. periodt. πβ¨
π¦ 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