write_guest_with_key(9)
π« 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 headedarβ the access registerdataβ the source address, and it lives in kernel spacelenβ how many bytes we're copying, no capaccess_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
pgmare undefined. Also, parts ofdatamay 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
pgmmay 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:
kvm_s390_real_to_abs(9)_kvm_s390_logical_to_effective(9)kvm_s390_logical_to_effective(9)put_guest_lc(9)write_guest_lc(9)read_guest_lc(9)write_guest(9)read_guest_with_key(9)read_guest(9)read_guest_instr(9)write_guest_abs(9)read_guest_abs(9)write_guest_real(9)read_guest_real(9)
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
- 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