sgx_virt_einit(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 the SIGSTRUCT structure. that's it. that's what it is πŸ’–
  • token β€” a userspace pointer to the EINITTOKEN structure. iconic little token behavior.
  • secs β€” a userspace pointer to the SECS page. yes the whole page.
  • lepubkeyhash β€” pointer to the guest's virtual SGX_LEPUBKEYHASH MSR 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