__cmpxchg_with_key(9)
β¨ __cmpxchg_with_key β¨
okay bestie, so this one is a Kernel API Manual situation β section 9 of the kernel docs, no cap β and it's the page for __cmpxchg_with_key. she's a little niche, she's a little s390-specific, but she ate and we're gonna get into it π«Ά
π NAME
__cmpxchg_with_key β do a cmpxchg, but like, respectfully (it honors storage keys) β¨
π¦ SYNOPSIS
int __cmpxchg_with_key (union kvm_s390_quad *ptr , union kvm_s390_quad
*old , union kvm_s390_quad new , int size , u8 access_key );
yes, that's the whole signature, copy it exactly, don't get creative with it π
π ARGUMENTS
ptrβ this is the address of the value you wanna compare against*oldand then exchange withnew. heads up though: it must be aligned tosizeβ that's not a vibe suggestion, that's a requirement πΈoldβ the old value, bestie. it gets compared to whatever's sitting atptrto figure out whether the exchange actually happens. and plot twist: the old value that gets read from*ptris written back here. so she's doing double duty πnewβ the new value you want to place at*ptr. the main character of the operation, honestly π¦sizeβ the size of the operation, in bytes. and here's the thing: it may only be a power of two up to 16. no weird numbers, no in-between sizes, we're keeping it clean β¨access_keyβ the access key used for checking storage key protection. this one's important, remember her π
π DESCRIPTION
so what she does is: perform a cmpxchg on guest memory, honoring storage key protection. iconic behaviour, honestly π«Ά
and here's the detail you cannot skip: access_key alone determines how key checking is performed β neither storage-protection-override nor fetch-protection-override apply. periodt. π
β οΈ also important, don't miss this: in case of an exception *uval is set to zero. that's the rule, fr fr.
π₯ RETURN
0β cmpxchg executed successfully π slay1β cmpxchg executed unsuccessfully π it happensPGM_PROTECTIONβ an exception happened when trying to access*ptrπ-EAGAINβ maxed out number of retries (byte and short only β yes, only those two!)-EINVALβ invalid value forsizeπ check your powers of two, bestie
π SEE ALSO
kernel file ./arch/s390/kvm/s390/gaccess.c, plus the whole squad:
guest_translate_gva(9)guest_range_to_gpas(9)cmpxchg_guest_abs_with_key(9)guest_translate_address_with_key(9)check_gva_range(9)check_gpa_range(9)kvm_s390_check_low_addr_prot_real(9)walk_guest_tables(9)__gaccess_shadow_fault(9)
iykyk π§
π okay that's the whole page!! this beauty lives over in ./arch/s390/kvm/s390 and the docs are dated October 2026 β so yeah, she's from the future, main character energy only πβ¨π
π¦ 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