-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge tag 'cmpxchg.2024.05.11a' of git://git.kernel.org/pub/scm/linux…
…/kernel/git/paulmck/linux-rcu Pull cmpxchg updates from Paul McKenney: "Provide one-byte and two-byte cmpxchg() support on sparc32, parisc, and csky This provides native one-byte and two-byte cmpxchg() support for sparc32 and parisc, courtesy of Al Viro. This support is provided by the same hashed-array-of-locks technique used for the other atomic operations provided for these two platforms. There is also emulated one-byte cmpxchg() support for csky using a new cmpxchg_emu_u8() function that uses a four-byte cmpxchg() to emulate the one-byte variant. Similar patches for emulation of one-byte cmpxchg() for arc, sh, and xtensa have not yet received maintainer acks, so they are slated for the v6.11 merge window" * tag 'cmpxchg.2024.05.11a' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu: csky: Emulate one-byte cmpxchg lib: Add one-byte emulation function parisc: add u16 support to cmpxchg() parisc: add missing export of __cmpxchg_u8() parisc: unify implementations of __cmpxchg_u{8,32,64} parisc: __cmpxchg_u32(): lift conversion into the callers sparc32: add __cmpxchg_u{8,16}() and teach __cmpxchg() to handle those sizes sparc32: unify __cmpxchg_u{32,64} sparc32: make the first argument of __cmpxchg_u64() volatile u64 * sparc32: make __cmpxchg_u32() return u32
- Loading branch information
Showing
11 changed files
with
133 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* SPDX-License-Identifier: GPL-2.0+ */ | ||
/* | ||
* Emulated 1-byte and 2-byte cmpxchg operations for architectures | ||
* lacking direct support for these sizes. These are implemented in terms | ||
* of 4-byte cmpxchg operations. | ||
* | ||
* Copyright (C) 2024 Paul E. McKenney. | ||
*/ | ||
|
||
#ifndef __LINUX_CMPXCHG_EMU_H | ||
#define __LINUX_CMPXCHG_EMU_H | ||
|
||
uintptr_t cmpxchg_emu_u8(volatile u8 *p, uintptr_t old, uintptr_t new); | ||
|
||
#endif /* __LINUX_CMPXCHG_EMU_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// 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 | ||
* operations. | ||
* | ||
* Copyright (C) 2024 Paul E. McKenney. | ||
*/ | ||
|
||
#include <linux/types.h> | ||
#include <linux/export.h> | ||
#include <linux/instrumented.h> | ||
#include <linux/atomic.h> | ||
#include <linux/panic.h> | ||
#include <linux/bug.h> | ||
#include <asm-generic/rwonce.h> | ||
#include <linux/cmpxchg-emu.h> | ||
|
||
union u8_32 { | ||
u8 b[4]; | ||
u32 w; | ||
}; | ||
|
||
/* 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; | ||
union u8_32 old32; | ||
union u8_32 new32; | ||
u32 ret; | ||
|
||
ret = READ_ONCE(*p32); | ||
do { | ||
old32.w = ret; | ||
if (old32.b[i] != old) | ||
return old32.b[i]; | ||
new32.w = old32.w; | ||
new32.b[i] = new; | ||
instrument_atomic_read_write(p, 1); | ||
ret = data_race(cmpxchg(p32, old32.w, new32.w)); // Overridden above. | ||
} while (ret != old32.w); | ||
return old; | ||
} | ||
EXPORT_SYMBOL_GPL(cmpxchg_emu_u8); |