License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0 */
|
2011-08-19 02:48:06 +08:00
|
|
|
#ifndef ASM_X86_CMPXCHG_H
|
|
|
|
#define ASM_X86_CMPXCHG_H
|
|
|
|
|
2011-08-30 05:47:58 +08:00
|
|
|
#include <linux/compiler.h>
|
2016-01-27 05:12:04 +08:00
|
|
|
#include <asm/cpufeatures.h>
|
2011-08-19 02:48:06 +08:00
|
|
|
#include <asm/alternative.h> /* Provides LOCK_PREFIX */
|
|
|
|
|
2011-08-30 05:47:58 +08:00
|
|
|
/*
|
2018-12-03 17:47:34 +08:00
|
|
|
* Non-existent functions to indicate usage errors at link time
|
2011-08-30 05:47:58 +08:00
|
|
|
* (or compile-time if the compiler implements __compiletime_error().
|
|
|
|
*/
|
|
|
|
extern void __xchg_wrong_size(void)
|
|
|
|
__compiletime_error("Bad argument size for xchg");
|
|
|
|
extern void __cmpxchg_wrong_size(void)
|
|
|
|
__compiletime_error("Bad argument size for cmpxchg");
|
|
|
|
extern void __xadd_wrong_size(void)
|
|
|
|
__compiletime_error("Bad argument size for xadd");
|
2011-09-29 02:49:28 +08:00
|
|
|
extern void __add_wrong_size(void)
|
|
|
|
__compiletime_error("Bad argument size for add");
|
2011-08-19 02:48:06 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Constants for operation sizes. On 32-bit, the 64-bit size it set to
|
|
|
|
* -1 because sizeof will never return -1, thereby making those switch
|
|
|
|
* case statements guaranteeed dead code which the compiler will
|
|
|
|
* eliminate, and allowing the "missing symbol in the default case" to
|
|
|
|
* indicate a usage error.
|
|
|
|
*/
|
|
|
|
#define __X86_CASE_B 1
|
|
|
|
#define __X86_CASE_W 2
|
|
|
|
#define __X86_CASE_L 4
|
|
|
|
#ifdef CONFIG_64BIT
|
|
|
|
#define __X86_CASE_Q 8
|
|
|
|
#else
|
|
|
|
#define __X86_CASE_Q -1 /* sizeof will never return -1 */
|
|
|
|
#endif
|
|
|
|
|
2011-10-01 03:14:10 +08:00
|
|
|
/*
|
|
|
|
* An exchange-type operation, which takes a value and a pointer, and
|
2013-04-25 15:20:54 +08:00
|
|
|
* returns the old value.
|
2011-10-01 03:14:10 +08:00
|
|
|
*/
|
|
|
|
#define __xchg_op(ptr, arg, op, lock) \
|
|
|
|
({ \
|
|
|
|
__typeof__ (*(ptr)) __ret = (arg); \
|
|
|
|
switch (sizeof(*(ptr))) { \
|
|
|
|
case __X86_CASE_B: \
|
|
|
|
asm volatile (lock #op "b %b0, %1\n" \
|
2012-04-03 07:15:33 +08:00
|
|
|
: "+q" (__ret), "+m" (*(ptr)) \
|
2011-10-01 03:14:10 +08:00
|
|
|
: : "memory", "cc"); \
|
|
|
|
break; \
|
|
|
|
case __X86_CASE_W: \
|
|
|
|
asm volatile (lock #op "w %w0, %1\n" \
|
|
|
|
: "+r" (__ret), "+m" (*(ptr)) \
|
|
|
|
: : "memory", "cc"); \
|
|
|
|
break; \
|
|
|
|
case __X86_CASE_L: \
|
|
|
|
asm volatile (lock #op "l %0, %1\n" \
|
|
|
|
: "+r" (__ret), "+m" (*(ptr)) \
|
|
|
|
: : "memory", "cc"); \
|
|
|
|
break; \
|
|
|
|
case __X86_CASE_Q: \
|
|
|
|
asm volatile (lock #op "q %q0, %1\n" \
|
|
|
|
: "+r" (__ret), "+m" (*(ptr)) \
|
|
|
|
: : "memory", "cc"); \
|
|
|
|
break; \
|
|
|
|
default: \
|
|
|
|
__ ## op ## _wrong_size(); \
|
|
|
|
} \
|
|
|
|
__ret; \
|
|
|
|
})
|
|
|
|
|
2011-08-19 02:48:06 +08:00
|
|
|
/*
|
|
|
|
* Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
|
|
|
|
* Since this is generally used to protect other memory information, we
|
|
|
|
* use "asm volatile" and "memory" clobbers to prevent gcc from moving
|
|
|
|
* information around.
|
|
|
|
*/
|
2018-07-16 19:30:09 +08:00
|
|
|
#define arch_xchg(ptr, v) __xchg_op((ptr), (v), xchg, "")
|
2011-08-19 02:48:06 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Atomic compare and exchange. Compare OLD with MEM, if identical,
|
|
|
|
* store NEW in MEM. Return the initial value in MEM. Success is
|
|
|
|
* indicated by comparing RETURN with OLD.
|
|
|
|
*/
|
|
|
|
#define __raw_cmpxchg(ptr, old, new, size, lock) \
|
|
|
|
({ \
|
|
|
|
__typeof__(*(ptr)) __ret; \
|
|
|
|
__typeof__(*(ptr)) __old = (old); \
|
|
|
|
__typeof__(*(ptr)) __new = (new); \
|
|
|
|
switch (size) { \
|
|
|
|
case __X86_CASE_B: \
|
|
|
|
{ \
|
|
|
|
volatile u8 *__ptr = (volatile u8 *)(ptr); \
|
|
|
|
asm volatile(lock "cmpxchgb %2,%1" \
|
|
|
|
: "=a" (__ret), "+m" (*__ptr) \
|
|
|
|
: "q" (__new), "0" (__old) \
|
|
|
|
: "memory"); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
case __X86_CASE_W: \
|
|
|
|
{ \
|
|
|
|
volatile u16 *__ptr = (volatile u16 *)(ptr); \
|
|
|
|
asm volatile(lock "cmpxchgw %2,%1" \
|
|
|
|
: "=a" (__ret), "+m" (*__ptr) \
|
|
|
|
: "r" (__new), "0" (__old) \
|
|
|
|
: "memory"); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
case __X86_CASE_L: \
|
|
|
|
{ \
|
|
|
|
volatile u32 *__ptr = (volatile u32 *)(ptr); \
|
|
|
|
asm volatile(lock "cmpxchgl %2,%1" \
|
|
|
|
: "=a" (__ret), "+m" (*__ptr) \
|
|
|
|
: "r" (__new), "0" (__old) \
|
|
|
|
: "memory"); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
case __X86_CASE_Q: \
|
|
|
|
{ \
|
|
|
|
volatile u64 *__ptr = (volatile u64 *)(ptr); \
|
|
|
|
asm volatile(lock "cmpxchgq %2,%1" \
|
|
|
|
: "=a" (__ret), "+m" (*__ptr) \
|
|
|
|
: "r" (__new), "0" (__old) \
|
|
|
|
: "memory"); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
default: \
|
|
|
|
__cmpxchg_wrong_size(); \
|
|
|
|
} \
|
|
|
|
__ret; \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define __cmpxchg(ptr, old, new, size) \
|
|
|
|
__raw_cmpxchg((ptr), (old), (new), (size), LOCK_PREFIX)
|
|
|
|
|
|
|
|
#define __sync_cmpxchg(ptr, old, new, size) \
|
|
|
|
__raw_cmpxchg((ptr), (old), (new), (size), "lock; ")
|
|
|
|
|
|
|
|
#define __cmpxchg_local(ptr, old, new, size) \
|
|
|
|
__raw_cmpxchg((ptr), (old), (new), (size), "")
|
|
|
|
|
2007-10-11 17:20:03 +08:00
|
|
|
#ifdef CONFIG_X86_32
|
2012-10-03 01:01:25 +08:00
|
|
|
# include <asm/cmpxchg_32.h>
|
2007-10-11 17:20:03 +08:00
|
|
|
#else
|
2012-10-03 01:01:25 +08:00
|
|
|
# include <asm/cmpxchg_64.h>
|
2007-10-11 17:20:03 +08:00
|
|
|
#endif
|
2011-08-19 02:48:06 +08:00
|
|
|
|
2018-01-30 01:26:05 +08:00
|
|
|
#define arch_cmpxchg(ptr, old, new) \
|
2012-01-26 23:47:37 +08:00
|
|
|
__cmpxchg(ptr, old, new, sizeof(*(ptr)))
|
2011-08-19 02:48:06 +08:00
|
|
|
|
2018-01-30 01:26:05 +08:00
|
|
|
#define arch_sync_cmpxchg(ptr, old, new) \
|
2012-01-26 23:47:37 +08:00
|
|
|
__sync_cmpxchg(ptr, old, new, sizeof(*(ptr)))
|
2011-08-19 02:48:06 +08:00
|
|
|
|
2018-01-30 01:26:05 +08:00
|
|
|
#define arch_cmpxchg_local(ptr, old, new) \
|
2012-01-26 23:47:37 +08:00
|
|
|
__cmpxchg_local(ptr, old, new, sizeof(*(ptr)))
|
2011-08-19 02:48:06 +08:00
|
|
|
|
locking/atomic: Introduce atomic_try_cmpxchg()
Add a new cmpxchg interface:
bool try_cmpxchg(u{8,16,32,64} *ptr, u{8,16,32,64} *val, u{8,16,32,64} new);
Where the boolean returns the result of the compare; and thus if the
exchange happened; and in case of failure, the new value of *ptr is
returned in *val.
This allows simplification/improvement of loops like:
for (;;) {
new = val $op $imm;
old = cmpxchg(ptr, val, new);
if (old == val)
break;
val = old;
}
into:
do {
} while (!try_cmpxchg(ptr, &val, val $op $imm));
while also generating better code (GCC6 and onwards).
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-02-01 23:39:38 +08:00
|
|
|
|
|
|
|
#define __raw_try_cmpxchg(_ptr, _pold, _new, size, lock) \
|
|
|
|
({ \
|
|
|
|
bool success; \
|
2017-06-17 17:15:28 +08:00
|
|
|
__typeof__(_ptr) _old = (__typeof__(_ptr))(_pold); \
|
locking/atomic: Introduce atomic_try_cmpxchg()
Add a new cmpxchg interface:
bool try_cmpxchg(u{8,16,32,64} *ptr, u{8,16,32,64} *val, u{8,16,32,64} new);
Where the boolean returns the result of the compare; and thus if the
exchange happened; and in case of failure, the new value of *ptr is
returned in *val.
This allows simplification/improvement of loops like:
for (;;) {
new = val $op $imm;
old = cmpxchg(ptr, val, new);
if (old == val)
break;
val = old;
}
into:
do {
} while (!try_cmpxchg(ptr, &val, val $op $imm));
while also generating better code (GCC6 and onwards).
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-02-01 23:39:38 +08:00
|
|
|
__typeof__(*(_ptr)) __old = *_old; \
|
|
|
|
__typeof__(*(_ptr)) __new = (_new); \
|
|
|
|
switch (size) { \
|
|
|
|
case __X86_CASE_B: \
|
|
|
|
{ \
|
|
|
|
volatile u8 *__ptr = (volatile u8 *)(_ptr); \
|
|
|
|
asm volatile(lock "cmpxchgb %[new], %[ptr]" \
|
|
|
|
CC_SET(z) \
|
|
|
|
: CC_OUT(z) (success), \
|
|
|
|
[ptr] "+m" (*__ptr), \
|
|
|
|
[old] "+a" (__old) \
|
|
|
|
: [new] "q" (__new) \
|
|
|
|
: "memory"); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
case __X86_CASE_W: \
|
|
|
|
{ \
|
|
|
|
volatile u16 *__ptr = (volatile u16 *)(_ptr); \
|
|
|
|
asm volatile(lock "cmpxchgw %[new], %[ptr]" \
|
|
|
|
CC_SET(z) \
|
|
|
|
: CC_OUT(z) (success), \
|
|
|
|
[ptr] "+m" (*__ptr), \
|
|
|
|
[old] "+a" (__old) \
|
|
|
|
: [new] "r" (__new) \
|
|
|
|
: "memory"); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
case __X86_CASE_L: \
|
|
|
|
{ \
|
|
|
|
volatile u32 *__ptr = (volatile u32 *)(_ptr); \
|
|
|
|
asm volatile(lock "cmpxchgl %[new], %[ptr]" \
|
|
|
|
CC_SET(z) \
|
|
|
|
: CC_OUT(z) (success), \
|
|
|
|
[ptr] "+m" (*__ptr), \
|
|
|
|
[old] "+a" (__old) \
|
|
|
|
: [new] "r" (__new) \
|
|
|
|
: "memory"); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
case __X86_CASE_Q: \
|
|
|
|
{ \
|
|
|
|
volatile u64 *__ptr = (volatile u64 *)(_ptr); \
|
|
|
|
asm volatile(lock "cmpxchgq %[new], %[ptr]" \
|
|
|
|
CC_SET(z) \
|
|
|
|
: CC_OUT(z) (success), \
|
|
|
|
[ptr] "+m" (*__ptr), \
|
|
|
|
[old] "+a" (__old) \
|
|
|
|
: [new] "r" (__new) \
|
|
|
|
: "memory"); \
|
|
|
|
break; \
|
|
|
|
} \
|
|
|
|
default: \
|
|
|
|
__cmpxchg_wrong_size(); \
|
|
|
|
} \
|
2017-03-27 19:54:38 +08:00
|
|
|
if (unlikely(!success)) \
|
|
|
|
*_old = __old; \
|
|
|
|
likely(success); \
|
locking/atomic: Introduce atomic_try_cmpxchg()
Add a new cmpxchg interface:
bool try_cmpxchg(u{8,16,32,64} *ptr, u{8,16,32,64} *val, u{8,16,32,64} new);
Where the boolean returns the result of the compare; and thus if the
exchange happened; and in case of failure, the new value of *ptr is
returned in *val.
This allows simplification/improvement of loops like:
for (;;) {
new = val $op $imm;
old = cmpxchg(ptr, val, new);
if (old == val)
break;
val = old;
}
into:
do {
} while (!try_cmpxchg(ptr, &val, val $op $imm));
while also generating better code (GCC6 and onwards).
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-02-01 23:39:38 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
#define __try_cmpxchg(ptr, pold, new, size) \
|
|
|
|
__raw_try_cmpxchg((ptr), (pold), (new), (size), LOCK_PREFIX)
|
|
|
|
|
2018-01-30 01:26:05 +08:00
|
|
|
#define try_cmpxchg(ptr, pold, new) \
|
locking/atomic: Introduce atomic_try_cmpxchg()
Add a new cmpxchg interface:
bool try_cmpxchg(u{8,16,32,64} *ptr, u{8,16,32,64} *val, u{8,16,32,64} new);
Where the boolean returns the result of the compare; and thus if the
exchange happened; and in case of failure, the new value of *ptr is
returned in *val.
This allows simplification/improvement of loops like:
for (;;) {
new = val $op $imm;
old = cmpxchg(ptr, val, new);
if (old == val)
break;
val = old;
}
into:
do {
} while (!try_cmpxchg(ptr, &val, val $op $imm));
while also generating better code (GCC6 and onwards).
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Brian Gerst <brgerst@gmail.com>
Cc: Denys Vlasenko <dvlasenk@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Josh Poimboeuf <jpoimboe@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linux-kernel@vger.kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2017-02-01 23:39:38 +08:00
|
|
|
__try_cmpxchg((ptr), (pold), (new), sizeof(*(ptr)))
|
|
|
|
|
2011-06-22 03:00:55 +08:00
|
|
|
/*
|
|
|
|
* xadd() adds "inc" to "*ptr" and atomically returns the previous
|
|
|
|
* value of "*ptr".
|
|
|
|
*
|
|
|
|
* xadd() is locked when multiple CPUs are online
|
|
|
|
*/
|
2011-10-01 03:14:10 +08:00
|
|
|
#define __xadd(ptr, inc, lock) __xchg_op((ptr), (inc), xadd, lock)
|
2011-06-22 03:00:55 +08:00
|
|
|
#define xadd(ptr, inc) __xadd((ptr), (inc), LOCK_PREFIX)
|
2011-09-29 02:49:28 +08:00
|
|
|
|
2012-01-03 01:02:18 +08:00
|
|
|
#define __cmpxchg_double(pfx, p1, p2, o1, o2, n1, n2) \
|
|
|
|
({ \
|
|
|
|
bool __ret; \
|
|
|
|
__typeof__(*(p1)) __old1 = (o1), __new1 = (n1); \
|
|
|
|
__typeof__(*(p2)) __old2 = (o2), __new2 = (n2); \
|
|
|
|
BUILD_BUG_ON(sizeof(*(p1)) != sizeof(long)); \
|
|
|
|
BUILD_BUG_ON(sizeof(*(p2)) != sizeof(long)); \
|
|
|
|
VM_BUG_ON((unsigned long)(p1) % (2 * sizeof(long))); \
|
|
|
|
VM_BUG_ON((unsigned long)((p1) + 1) != (unsigned long)(p2)); \
|
2018-09-28 16:33:05 +08:00
|
|
|
asm volatile(pfx "cmpxchg%c5b %1" \
|
|
|
|
CC_SET(e) \
|
|
|
|
: CC_OUT(e) (__ret), \
|
|
|
|
"+m" (*(p1)), "+m" (*(p2)), \
|
|
|
|
"+a" (__old1), "+d" (__old2) \
|
|
|
|
: "i" (2 * sizeof(long)), \
|
2012-01-03 01:02:18 +08:00
|
|
|
"b" (__new1), "c" (__new2)); \
|
|
|
|
__ret; \
|
|
|
|
})
|
|
|
|
|
2018-01-30 01:26:05 +08:00
|
|
|
#define arch_cmpxchg_double(p1, p2, o1, o2, n1, n2) \
|
2012-01-03 01:02:18 +08:00
|
|
|
__cmpxchg_double(LOCK_PREFIX, p1, p2, o1, o2, n1, n2)
|
|
|
|
|
2018-01-30 01:26:05 +08:00
|
|
|
#define arch_cmpxchg_double_local(p1, p2, o1, o2, n1, n2) \
|
2012-01-03 01:02:18 +08:00
|
|
|
__cmpxchg_double(, p1, p2, o1, o2, n1, n2)
|
|
|
|
|
2011-08-19 02:48:06 +08:00
|
|
|
#endif /* ASM_X86_CMPXCHG_H */
|