Re: arch/x86/include/asm/cmpxchg_32.h:149:9: error: inline assembly requires more registers than available
From: Linus Torvalds
Date: Mon Jun 24 2024 - 10:18:19 EST
On Mon, 24 Jun 2024 at 09:59, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> On Mon, 24 Jun 2024 at 03:36, Uros Bizjak <ubizjak@xxxxxxxxx> wrote:
> >
> > A real fix, not only a workaround, is to rewrite asm arguments to
> > something like (untested, but "should work"TM):
>
> Sadly, I already tried that, and it didn't help.
Bah. I _had_ tried that, but I had tried it on __arch_cmpxchg64_emu(),
not on the "try" version.
And no, it hadn't helped.
But doing it *right*, and also doing __arch_try_cmpxchg64_emu() *does*
actually help.
Well, at least the attached patch compiles with the bad config and clang.
I'm not certain it does the right thing, because I did more than just
the %esi games to try to simplify it.
It's *ENTIRELY* possible that I screwed up. Just in this thread, I
have looked at the wrong inline asm at least twice now, so I'm not
feeling super-competent right now.
I'm sending the patch out in the hope that another set of eyes will
make it actually better.
Linus
arch/x86/include/asm/cmpxchg_32.h | 28 ++++++++++++----------------
1 file changed, 12 insertions(+), 16 deletions(-)
diff --git a/arch/x86/include/asm/cmpxchg_32.h b/arch/x86/include/asm/cmpxchg_32.h
index ed2797f132ce..b19985520f3c 100644
--- a/arch/x86/include/asm/cmpxchg_32.h
+++ b/arch/x86/include/asm/cmpxchg_32.h
@@ -88,18 +88,17 @@ static __always_inline bool __try_cmpxchg64_local(volatile u64 *ptr, u64 *oldp,
#define __arch_cmpxchg64_emu(_ptr, _old, _new, _lock_loc, _lock) \
({ \
- union __u64_halves o = { .full = (_old), }, \
- n = { .full = (_new), }; \
+ __u64 o = (_old); \
+ union __u64_halves n = { .full = (_new), }; \
\
asm volatile(ALTERNATIVE(_lock_loc \
"call cmpxchg8b_emu", \
- _lock "cmpxchg8b %[ptr]", X86_FEATURE_CX8) \
- : [ptr] "+m" (*(_ptr)), \
- "+a" (o.low), "+d" (o.high) \
- : "b" (n.low), "c" (n.high), "S" (_ptr) \
+ _lock "cmpxchg8b 0(%[ptr])", X86_FEATURE_CX8) \
+ : "+A" (o) \
+ : "b" (n.low), "c" (n.high), [ptr] "S" (_ptr) \
: "memory"); \
\
- o.full; \
+ o; \
})
static __always_inline u64 arch_cmpxchg64(volatile u64 *ptr, u64 old, u64 new)
@@ -116,22 +115,19 @@ static __always_inline u64 arch_cmpxchg64_local(volatile u64 *ptr, u64 old, u64
#define __arch_try_cmpxchg64_emu(_ptr, _oldp, _new, _lock_loc, _lock) \
({ \
- union __u64_halves o = { .full = *(_oldp), }, \
- n = { .full = (_new), }; \
+ __u64 o = *(_oldp); \
+ union __u64_halves n = { .full = (_new), }; \
bool ret; \
\
asm volatile(ALTERNATIVE(_lock_loc \
"call cmpxchg8b_emu", \
- _lock "cmpxchg8b %[ptr]", X86_FEATURE_CX8) \
+ _lock "cmpxchg8b 0(%[ptr])", X86_FEATURE_CX8) \
CC_SET(e) \
- : CC_OUT(e) (ret), \
- [ptr] "+m" (*(_ptr)), \
- "+a" (o.low), "+d" (o.high) \
- : "b" (n.low), "c" (n.high), "S" (_ptr) \
+ : CC_OUT(e) (ret), "+A" (o) \
+ : "b" (n.low), "c" (n.high), [ptr] "S" (_ptr) \
: "memory"); \
\
- if (unlikely(!ret)) \
- *(_oldp) = o.full; \
+ *(_oldp) = o; \
\
likely(ret); \
})