write_guest_with_key(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’« write_guest_with_key(9) β€” a Kernel API Manual moment ✨

okay bestie, buckle up, because this one is from the Kernel API Manual and it's lowkey iconic: it's all about yeeting bytes from kernel space into guest space πŸŽ€


✨ NAME ✨

write_guest_with_key β€” copy data from kernel space to guest space 🫢


🌸 SYNOPSIS 🌸

int write_guest_with_key (struct kvm_vcpu *vcpu , unsigned long ga , u8
ar , void *data , unsigned long len , u8 access_key );

πŸ¦‹ ARGUMENTS πŸ¦‹

  • vcpu β€” the virtual cpu, the main character of this whole situation πŸ’…
  • ga β€” the guest address, i.e. where the data is headed
  • ar β€” the access register
  • data β€” the source address, and it lives in kernel space
  • len β€” how many bytes we're copying, no cap
  • access_key β€” the access key that the storage key needs to match πŸ”‘

πŸ’– DESCRIPTION πŸ’–

So what it does is: copy len bytes from data (kernel space) over to ga (guest address). Easy enough, right? But the way it actually gets there is kind of a whole investigation πŸ‘‘

To copy data into guest space, the PSW of the vcpu gets inspected, fr fr:

  • if DAT is off, the data gets copied to guest real or absolute memory
  • if DAT is on, the data gets copied to the address space as specified by the address space bits of the PSW: Primary, secondary, home space, or access register mode

The addressing mode of the PSW gets inspected too, so that address wrap around is taken into account for 24-, 31- and 64-bit addressing mode β€” this matters if the to-be-copied data crosses page boundaries in guest address space. And before copying any data at all, it performs low address, DAT and key protection checks. like, it does its homework first, we love a prepared queen 🌸

Also, hear me out: this function modifies the 'struct kvm_s390_pgm_info pgm' member of vcpu. If there's an access exception (e.g. a protection exception), pgm will contain all the data necessary so that a subsequent call to 'kvm_s390_inject_prog_vcpu' will inject a correct exception into the guest. But if no access exception happened, the contents of pgm are undefined when this function returns 😭 so don't go reading them, bestie.


πŸ”₯ RETURN πŸ”₯

  • zero on success ✨
  • a negative value if e.g. the guest mapping is broken, or in case of out-of-memory. In this case the contents of pgm are undefined. Also, parts of data may have been copied to guest space πŸ‘€
  • a positive value if an access exception happened. In this case the returned value is the program interruption code, and the contents of pgm may be used to inject an exception into the guest. No data has been copied to guest space. periodt πŸ’…

πŸ’€ NOTE πŸ’€

in case an access exception is recognized, no data has been copied to guest space β€” and yes, that's also true if the to-be-copied data would cross one or more page boundaries in guest space. So this function may be used for nullifying and suppressing instruction emulation. It may also be used for terminating instructions, if it is undefined whether data has been changed in guest space in case of an exception. like… that's the fine print, don't skip it πŸ™ˆ


🌈 SEE ALSO 🌈

Kernel file ./arch/s390/kvm/s390/gaccess.h and all these gorgeous neighbours:


okay that's the whole page, mwah πŸ’‹ this one lives in ./arch/s390/kvm/s390 and it's dated October 2026 β€” screenshot it, cite it, slay it πŸ§šβ€β™€οΈπŸ’œ

πŸ“¦ where this page comes from