2018-09-01 20:27:37

by Samuel Neves

[permalink] [raw]
Subject: [PATCH] x86/vdso: fix lsl operand order

In the __getcpu function, lsl was using the wrong target
and destination registers. Luckily, the compiler tends to
choose %eax for both variables, so it has been working
so far.

Cc: [email protected]
Cc: [email protected]
Signed-off-by: Samuel Neves <[email protected]>
---
arch/x86/include/asm/vgtod.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h
index fb856c9f0449..53748541c487 100644
--- a/arch/x86/include/asm/vgtod.h
+++ b/arch/x86/include/asm/vgtod.h
@@ -93,7 +93,7 @@ static inline unsigned int __getcpu(void)
*
* If RDPID is available, use it.
*/
- alternative_io ("lsl %[p],%[seg]",
+ alternative_io ("lsl %[seg],%[p]",
".byte 0xf3,0x0f,0xc7,0xf8", /* RDPID %eax/rax */
X86_FEATURE_RDPID,
[p] "=a" (p), [seg] "r" (__PER_CPU_SEG));
--
2.17.1



2018-09-01 20:46:08

by Andy Lutomirski

[permalink] [raw]
Subject: Re: [PATCH] x86/vdso: fix lsl operand order

On Sat, Sep 1, 2018 at 1:14 PM, Samuel Neves <[email protected]> wrote:
> In the __getcpu function, lsl was using the wrong target
> and destination registers. Luckily, the compiler tends to
> choose %eax for both variables, so it has been working
> so far.
>
> Cc: [email protected]
> Cc: [email protected]
> Signed-off-by: Samuel Neves <[email protected]>

Acked-by: Andy Lutomirski <[email protected]>
Fixes: a582c540ac1b ("x86/vdso: Use RDPID in preference to LSL when available")

Whoops! I even wrote a selftest just for the offending commit, but,
of course, the selftest passes :( I tested this by giving gcc some
gentle encouragement to allocate different registers, and the existing
code is indeed wrong and the fix indeed fixes it.

--Andy

Subject: [tip:x86/urgent] x86/vdso: Fix lsl operand order

Commit-ID: e78e5a91456fcecaa2efbb3706572fe043766f4d
Gitweb: https://git.kernel.org/tip/e78e5a91456fcecaa2efbb3706572fe043766f4d
Author: Samuel Neves <[email protected]>
AuthorDate: Sat, 1 Sep 2018 21:14:52 +0100
Committer: Thomas Gleixner <[email protected]>
CommitDate: Sat, 1 Sep 2018 23:01:56 +0200

x86/vdso: Fix lsl operand order

In the __getcpu function, lsl is using the wrong target and destination
registers. Luckily, the compiler tends to choose %eax for both variables,
so it has been working so far.

Fixes: a582c540ac1b ("x86/vdso: Use RDPID in preference to LSL when available")
Signed-off-by: Samuel Neves <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Acked-by: Andy Lutomirski <[email protected]>
Cc: [email protected]
Link: https://lkml.kernel.org/r/[email protected]

---
arch/x86/include/asm/vgtod.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/include/asm/vgtod.h b/arch/x86/include/asm/vgtod.h
index fb856c9f0449..53748541c487 100644
--- a/arch/x86/include/asm/vgtod.h
+++ b/arch/x86/include/asm/vgtod.h
@@ -93,7 +93,7 @@ static inline unsigned int __getcpu(void)
*
* If RDPID is available, use it.
*/
- alternative_io ("lsl %[p],%[seg]",
+ alternative_io ("lsl %[seg],%[p]",
".byte 0xf3,0x0f,0xc7,0xf8", /* RDPID %eax/rax */
X86_FEATURE_RDPID,
[p] "=a" (p), [seg] "r" (__PER_CPU_SEG));