arch/s390/include/asm/cmpxchg.h
Source file repositories/reference/linux-study-clean/arch/s390/include/asm/cmpxchg.h
File Facts
- System
- Linux kernel
- Corpus path
arch/s390/include/asm/cmpxchg.h- Extension
.h- Size
- 6239 bytes
- Lines
- 274
- Domain
- Architecture Layer
- Bucket
- arch/s390
- Inferred role
- Architecture Layer: implementation source
- Status
- source implementation candidate
Why This File Exists
CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
- CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.
Dependency Surface
linux/mmdebug.hlinux/types.hlinux/bug.hasm/asm.h
Detected Declarations
function __cs_asmfunction __csg_asmfunction __arch_cmpxchg1function __arch_cmpxchg2function __arch_cmpxchgfunction __arch_xchg1function __arch_xchg2function __arch_xchgfunction arch_cmpxchg128function arch_try_cmpxchg128
Annotated Snippet
#ifndef __ASM_CMPXCHG_H
#define __ASM_CMPXCHG_H
#include <linux/mmdebug.h>
#include <linux/types.h>
#include <linux/bug.h>
#include <asm/asm.h>
void __cmpxchg_called_with_bad_pointer(void);
static __always_inline u32 __cs_asm(u64 ptr, u32 old, u32 new)
{
asm volatile(
" cs %[old],%[new],%[ptr]"
: [old] "+d" (old), [ptr] "+Q" (*(u32 *)ptr)
: [new] "d" (new)
: "memory", "cc");
return old;
}
static __always_inline u64 __csg_asm(u64 ptr, u64 old, u64 new)
{
asm volatile(
" csg %[old],%[new],%[ptr]"
: [old] "+d" (old), [ptr] "+QS" (*(u64 *)ptr)
: [new] "d" (new)
: "memory", "cc");
return old;
}
static __no_sanitize_or_inline u8 __arch_cmpxchg1(u64 ptr, u8 old, u8 new)
{
union {
u8 b[4];
u32 w;
} old32, new32;
u32 prev;
int i;
i = ptr & 3;
ptr &= ~0x3;
prev = READ_ONCE(*(u32 *)ptr);
do {
old32.w = prev;
if (old32.b[i] != old)
return old32.b[i];
new32.w = old32.w;
new32.b[i] = new;
prev = __cs_asm(ptr, old32.w, new32.w);
} while (prev != old32.w);
return old;
}
static __no_sanitize_or_inline u16 __arch_cmpxchg2(u64 ptr, u16 old, u16 new)
{
union {
u16 b[2];
u32 w;
} old32, new32;
u32 prev;
int i;
i = (ptr & 3) >> 1;
ptr &= ~0x3;
prev = READ_ONCE(*(u32 *)ptr);
do {
old32.w = prev;
if (old32.b[i] != old)
return old32.b[i];
new32.w = old32.w;
new32.b[i] = new;
prev = __cs_asm(ptr, old32.w, new32.w);
} while (prev != old32.w);
return old;
}
static __always_inline u64 __arch_cmpxchg(u64 ptr, u64 old, u64 new, int size)
{
switch (size) {
case 1: return __arch_cmpxchg1(ptr, old & 0xff, new & 0xff);
case 2: return __arch_cmpxchg2(ptr, old & 0xffff, new & 0xffff);
case 4: return __cs_asm(ptr, old & 0xffffffff, new & 0xffffffff);
case 8: return __csg_asm(ptr, old, new);
default: __cmpxchg_called_with_bad_pointer();
}
return old;
}
#define arch_cmpxchg(ptr, o, n) \
({ \
Annotation
- Immediate include surface: `linux/mmdebug.h`, `linux/types.h`, `linux/bug.h`, `asm/asm.h`.
- Detected declarations: `function __cs_asm`, `function __csg_asm`, `function __arch_cmpxchg1`, `function __arch_cmpxchg2`, `function __arch_cmpxchg`, `function __arch_xchg1`, `function __arch_xchg2`, `function __arch_xchg`, `function arch_cmpxchg128`, `function arch_try_cmpxchg128`.
- Atlas domain: Architecture Layer / arch/s390.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.