Skip to content

Commit ac18054

Browse files
author
Ingo Molnar
committed
Revert "x86/refcount: Work around GCC inlining bug"
This reverts commit 9e1725b. See this commit for details about the revert: e769742 ("Revert "x86/jump-labels: Macrofy inline assembly code to work around GCC inlining bugs"") The conflict resolution for interaction with: 288e452: ("x86/asm: 'Simplify' GEN_*_RMWcc() macros") was provided by Masahiro Yamada. Conflicts: arch/x86/include/asm/refcount.h Reported-by: Masahiro Yamada <yamada.masahiro@socionext.com> Reviewed-by: Borislav Petkov <bp@alien8.de> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Cc: Juergen Gross <jgross@suse.com> Cc: Richard Biener <rguenther@suse.de> Cc: Kees Cook <keescook@chromium.org> Cc: Segher Boessenkool <segher@kernel.crashing.org> Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Josh Poimboeuf <jpoimboe@redhat.com> Cc: Nadav Amit <namit@vmware.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: linux-kernel@vger.kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 851a4cd commit ac18054

File tree

2 files changed

+33
-49
lines changed

2 files changed

+33
-49
lines changed

arch/x86/include/asm/refcount.h

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,41 +4,6 @@
44
* x86-specific implementation of refcount_t. Based on PAX_REFCOUNT from
55
* PaX/grsecurity.
66
*/
7-
8-
#ifdef __ASSEMBLY__
9-
10-
#include <asm/asm.h>
11-
#include <asm/bug.h>
12-
13-
.macro REFCOUNT_EXCEPTION counter:req
14-
.pushsection .text..refcount
15-
111: lea \counter, %_ASM_CX
16-
112: ud2
17-
ASM_UNREACHABLE
18-
.popsection
19-
113: _ASM_EXTABLE_REFCOUNT(112b, 113b)
20-
.endm
21-
22-
/* Trigger refcount exception if refcount result is negative. */
23-
.macro REFCOUNT_CHECK_LT_ZERO counter:req
24-
js 111f
25-
REFCOUNT_EXCEPTION counter="\counter"
26-
.endm
27-
28-
/* Trigger refcount exception if refcount result is zero or negative. */
29-
.macro REFCOUNT_CHECK_LE_ZERO counter:req
30-
jz 111f
31-
REFCOUNT_CHECK_LT_ZERO counter="\counter"
32-
.endm
33-
34-
/* Trigger refcount exception unconditionally. */
35-
.macro REFCOUNT_ERROR counter:req
36-
jmp 111f
37-
REFCOUNT_EXCEPTION counter="\counter"
38-
.endm
39-
40-
#else /* __ASSEMBLY__ */
41-
427
#include <linux/refcount.h>
438
#include <asm/bug.h>
449

@@ -50,45 +15,67 @@
5015
* central refcount exception. The fixup address for the exception points
5116
* back to the regular execution flow in .text.
5217
*/
18+
#define _REFCOUNT_EXCEPTION \
19+
".pushsection .text..refcount\n" \
20+
"111:\tlea %[var], %%" _ASM_CX "\n" \
21+
"112:\t" ASM_UD2 "\n" \
22+
ASM_UNREACHABLE \
23+
".popsection\n" \
24+
"113:\n" \
25+
_ASM_EXTABLE_REFCOUNT(112b, 113b)
26+
27+
/* Trigger refcount exception if refcount result is negative. */
28+
#define REFCOUNT_CHECK_LT_ZERO \
29+
"js 111f\n\t" \
30+
_REFCOUNT_EXCEPTION
31+
32+
/* Trigger refcount exception if refcount result is zero or negative. */
33+
#define REFCOUNT_CHECK_LE_ZERO \
34+
"jz 111f\n\t" \
35+
REFCOUNT_CHECK_LT_ZERO
36+
37+
/* Trigger refcount exception unconditionally. */
38+
#define REFCOUNT_ERROR \
39+
"jmp 111f\n\t" \
40+
_REFCOUNT_EXCEPTION
5341

5442
static __always_inline void refcount_add(unsigned int i, refcount_t *r)
5543
{
5644
asm volatile(LOCK_PREFIX "addl %1,%0\n\t"
57-
"REFCOUNT_CHECK_LT_ZERO counter=\"%[counter]\""
58-
: [counter] "+m" (r->refs.counter)
45+
REFCOUNT_CHECK_LT_ZERO
46+
: [var] "+m" (r->refs.counter)
5947
: "ir" (i)
6048
: "cc", "cx");
6149
}
6250

6351
static __always_inline void refcount_inc(refcount_t *r)
6452
{
6553
asm volatile(LOCK_PREFIX "incl %0\n\t"
66-
"REFCOUNT_CHECK_LT_ZERO counter=\"%[counter]\""
67-
: [counter] "+m" (r->refs.counter)
54+
REFCOUNT_CHECK_LT_ZERO
55+
: [var] "+m" (r->refs.counter)
6856
: : "cc", "cx");
6957
}
7058

7159
static __always_inline void refcount_dec(refcount_t *r)
7260
{
7361
asm volatile(LOCK_PREFIX "decl %0\n\t"
74-
"REFCOUNT_CHECK_LE_ZERO counter=\"%[counter]\""
75-
: [counter] "+m" (r->refs.counter)
62+
REFCOUNT_CHECK_LE_ZERO
63+
: [var] "+m" (r->refs.counter)
7664
: : "cc", "cx");
7765
}
7866

7967
static __always_inline __must_check
8068
bool refcount_sub_and_test(unsigned int i, refcount_t *r)
8169
{
82-
8370
return GEN_BINARY_SUFFIXED_RMWcc(LOCK_PREFIX "subl",
84-
"REFCOUNT_CHECK_LT_ZERO counter=\"%[var]\"",
71+
REFCOUNT_CHECK_LT_ZERO,
8572
r->refs.counter, e, "er", i, "cx");
8673
}
8774

8875
static __always_inline __must_check bool refcount_dec_and_test(refcount_t *r)
8976
{
9077
return GEN_UNARY_SUFFIXED_RMWcc(LOCK_PREFIX "decl",
91-
"REFCOUNT_CHECK_LT_ZERO counter=\"%[var]\"",
78+
REFCOUNT_CHECK_LT_ZERO,
9279
r->refs.counter, e, "cx");
9380
}
9481

@@ -106,8 +93,8 @@ bool refcount_add_not_zero(unsigned int i, refcount_t *r)
10693

10794
/* Did we try to increment from/to an undesirable state? */
10895
if (unlikely(c < 0 || c == INT_MAX || result < c)) {
109-
asm volatile("REFCOUNT_ERROR counter=\"%[counter]\""
110-
: : [counter] "m" (r->refs.counter)
96+
asm volatile(REFCOUNT_ERROR
97+
: : [var] "m" (r->refs.counter)
11198
: "cc", "cx");
11299
break;
113100
}
@@ -122,6 +109,4 @@ static __always_inline __must_check bool refcount_inc_not_zero(refcount_t *r)
122109
return refcount_add_not_zero(1, r);
123110
}
124111

125-
#endif /* __ASSEMBLY__ */
126-
127112
#endif

arch/x86/kernel/macros.S

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
*/
88

99
#include <linux/compiler.h>
10-
#include <asm/refcount.h>

0 commit comments

Comments
 (0)