diff mbox series

[kvm-unit-tests,2/2] x86: Mark RDPID asm volatile to avoid dropping instructions

Message ID 20230307005547.607353-3-dmatlack@google.com (mailing list archive)
State New, archived
Headers show
Series x86: Fixes for rdpid test | expand

Commit Message

David Matlack March 7, 2023, 12:55 a.m. UTC
Mark the asm statement that generates the RDPID instruction volatile.
The compiler within its rights to drop subsequent RDPID asm statements
(after the first) since the inputs never change.

This fixes the tsc test on hardware that supports rdpid when built with
the latest Clang compiler.

Fixes: 10631a5bebd8 ("x86: tsc: add rdpid test")
Reported-by: Greg Thelen <gthelen@google.com>
Suggested-by: Greg Thelen <gthelen@google.com>
Signed-off-by: David Matlack <dmatlack@google.com>
---
 x86/tsc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jim Mattson March 7, 2023, 1:04 a.m. UTC | #1
On Mon, Mar 6, 2023 at 4:56 PM David Matlack <dmatlack@google.com> wrote:
>
> Mark the asm statement that generates the RDPID instruction volatile.
> The compiler within its rights to drop subsequent RDPID asm statements
> (after the first) since the inputs never change.
>
> This fixes the tsc test on hardware that supports rdpid when built with
> the latest Clang compiler.
>
> Fixes: 10631a5bebd8 ("x86: tsc: add rdpid test")
> Reported-by: Greg Thelen <gthelen@google.com>
> Suggested-by: Greg Thelen <gthelen@google.com>
> Signed-off-by: David Matlack <dmatlack@google.com>
Reviewed-by: Jim Mattson <jmattson@google.com>
diff mbox series

Patch

diff --git a/x86/tsc.c b/x86/tsc.c
index bc403fc78461..b3bb120291ec 100644
--- a/x86/tsc.c
+++ b/x86/tsc.c
@@ -24,7 +24,7 @@  static void test_rdpid(u64 aux)
        u32 eax;
 
        wrmsr(MSR_TSC_AUX, aux);
-       asm (".byte 0xf3, 0x0f, 0xc7, 0xf8" : "=a" (eax));
+       asm volatile (".byte 0xf3, 0x0f, 0xc7, 0xf8" : "=a" (eax));
        report(eax == aux, "Test rdpid %%eax %" PRId64, aux);
 }