| // SPDX-License-Identifier: GPL-2.0+ |
| * Emulated 1-byte cmpxchg operation for architectures lacking direct |
| * support for this size. This is implemented in terms of 4-byte cmpxchg |
| * Copyright (C) 2024 Paul E. McKenney. |
| #include <linux/export.h> |
| #include <linux/instrumented.h> |
| #include <linux/atomic.h> |
| #include <asm-generic/rwonce.h> |
| #include <linux/cmpxchg-emu.h> |
| /* Emulate one-byte cmpxchg() in terms of 4-byte cmpxchg. */ |
| uintptr_t cmpxchg_emu_u8(volatile u8 *p, uintptr_t old, uintptr_t new) |
| u32 *p32 = (u32 *)(((uintptr_t)p) & ~0x3); |
| int i = ((uintptr_t)p) & 0x3; |
| instrument_atomic_read_write(p, 1); |
| ret = data_race(cmpxchg(p32, old32.w, new32.w)); // Overridden above. |
| } while (ret != old32.w); |
| EXPORT_SYMBOL_GPL(cmpxchg_emu_u8); |