Skip to contentSkip to conversation

x86: Fixes for rdpid test

PATCH Applied David Matlack 4 participants 6 messages Mar 7, 2023 – Apr 5, 2023 KVM

lore
Share & tools
lore
#0 lore raw

cover x86: Fixes for rdpid test

Fix 2 small issues with the rdpid test that is a part of x86/tsc.c. Notably, the test is not currently running since qemu is not configured to advertise RDPID support and fixing that uncovers a bug in the test when compiling with Clang.

David Matlack (2):
x86: Run the tsc test with -cpu max
x86: Mark RDPID asm volatile to avoid dropping instructions

 x86/tsc.c         | 2 +-
 x86/unittests.cfg | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

base-commit: e3c5c3ef2524c58023073c0fadde2e8ae3c04ec6

Signature · 1 line
2.40.0.rc0.216.gc4246ad0f0-goog
#1 lore raw

PATCH 1/2 x86: Run the tsc test with -cpu max

Run the tsc test with -cpu max to enable RDPID testing. The current configuration (-cpu kvm64,+rdtscp) does not include RDPID even if the host supports. In effect, test_rdpid() never runs.

Use max instead of adding +rdpid to the existing configuration to avoid this biting someone in the future if they add a test for a new feature.

Fixes 10631a5bebd8 ("x86: tsc: add rdpid test")
---
 x86/unittests.cfg | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
x86/unittests.cfg +1 -1
index f324e32d60ef..c4eaa8ef9bab 100644
@@ -247,7 +247,7 @@ extra_params = -cpu Opteron_G1,vendor=AuthenticAMD
 
 [tsc]
 file = tsc.flat
-extra_params = -cpu kvm64,+rdtscp
+extra_params = -cpu max
 
 [tsc_adjust]
 file = tsc_adjust.flat
Signature · 1 line
2.40.0.rc0.216.gc4246ad0f0-goog
#2 lore raw

PATCH 2/2 x86: Mark RDPID asm volatile to avoid dropping instructions

In reply to David Matlack

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")
---
 x86/tsc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
x86/tsc.c +1 -1
index bc403fc78461..b3bb120291ec 100644
@@ -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);
 }
 
Signature · 1 line
2.40.0.rc0.216.gc4246ad0f0-goog
Reviewed-by on v1 2/2
#3 lore raw

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

Quoted 5 lines · David Matlack

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.

Quoted 7 lines

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

Fixes 10631a5bebd8 ("x86: tsc: add rdpid test")
maintainer Applied
#4 lore raw
In reply to David Matlack
Quoted 9 lines · David Matlack

Fix 2 small issues with the rdpid test that is a part of x86/tsc.c. Notably, the test is not currently running since qemu is not configured to advertise RDPID support and fixing that uncovers a bug in the test when compiling with Clang.

David Matlack (2):
x86: Run the tsc test with -cpu max
x86: Mark RDPID asm volatile to avoid dropping instructions

Quoted 6 lines
  x86/tsc.c         | 2 +-
  x86/unittests.cfg | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

base-commit: e3c5c3ef2524c58023073c0fadde2e8ae3c04ec6

Queued, thanks.

Paolo

reviewer Applied
#5 lore raw
In reply to David Matlack
Quoted 10 lines · David Matlack

Fix 2 small issues with the rdpid test that is a part of x86/tsc.c. Notably, the test is not currently running since qemu is not configured to advertise RDPID support and fixing that uncovers a bug in the test when compiling with Clang.

David Matlack (2):
x86: Run the tsc test with -cpu max
x86: Mark RDPID asm volatile to avoid dropping instructions

[...]

Applied to kvm-x86 next, thanks! Paolo's "Queued, thanks" showed up, but I don't see these in upstream.

[1/2] x86: Run the tsc test with -cpu max

      https://github.com/kvm-x86/kvm-unit-tests/commit/572fb7097fa7
[2/2] x86: Mark RDPID asm volatile to avoid dropping instructions
      https://github.com/kvm-x86/kvm-unit-tests/commit/a467f7679c7f

--
https://github.com/kvm-x86/kvm-unit-tests/tree/next