__cmpxchg_with_key(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

✨ __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 *old and then exchange with new. heads up though: it must be aligned to size β€” that's not a vibe suggestion, that's a requirement 🌸
  • old β€” the old value, bestie. it gets compared to whatever's sitting at ptr to figure out whether the exchange actually happens. and plot twist: the old value that gets read from *ptr is 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 😌 slay
  • 1 β€” cmpxchg executed unsuccessfully πŸ’€ it happens
  • PGM_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 for size 😭 check your powers of two, bestie

🌈 SEE ALSO

kernel file ./arch/s390/kvm/s390/gaccess.c, plus the whole squad:

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