Re: [kvm-unit-tests PATCH v5 11/27] x86/pmu: Update rdpmc testcase to cover #GP path

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 24/11/2022 7:33 pm, Thomas Huth wrote:
On 02/11/2022 23.50, Sean Christopherson wrote:
From: Like Xu <likexu@xxxxxxxxxxx>

Specifying an unsupported PMC encoding will cause a #GP(0).

There are multiple reasons RDPMC can #GP, the one that is being relied
on to guarantee #GP is specifically that the PMC is invalid. The most
extensible solution is to provide a safe variant.

Suggested-by: Sean Christopherson <seanjc@xxxxxxxxxx>
Signed-off-by: Like Xu <likexu@xxxxxxxxxxx>
Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
  lib/x86/processor.h | 21 ++++++++++++++++++---
  x86/pmu.c           | 10 ++++++++++
  2 files changed, 28 insertions(+), 3 deletions(-)

diff --git a/lib/x86/processor.h b/lib/x86/processor.h
index f85abe36..ba14c7a0 100644
--- a/lib/x86/processor.h
+++ b/lib/x86/processor.h
@@ -438,11 +438,26 @@ static inline int wrmsr_safe(u32 index, u64 val)
      return exception_vector();
  }
+static inline int rdpmc_safe(u32 index, uint64_t *val)
+{
+    uint32_t a, d;
+
+    asm volatile (ASM_TRY("1f")
+              "rdpmc\n\t"
+              "1:"
+              : "=a"(a), "=d"(d) : "c"(index) : "memory");
+    *val = (uint64_t)a | ((uint64_t)d << 32);
+    return exception_vector();
+}
+
  static inline uint64_t rdpmc(uint32_t index)
  {
-    uint32_t a, d;
-    asm volatile ("rdpmc" : "=a"(a), "=d"(d) : "c"(index));
-    return a | ((uint64_t)d << 32);
+    uint64_t val;
+    int vector = rdpmc_safe(index, &val);
+
+    assert_msg(!vector, "Unexpected %s on RDPMC(%d)",
+           exception_mnemonic(vector), index);
+    return val;
  }

Seems like this is causing the CI to fail:

https://gitlab.com/kvm-unit-tests/kvm-unit-tests/-/jobs/3339274319#L1260

I just now noticed that KUT can be used to validate TCG or HVF accel on macOS.
I assume the functionality of the PMU counter on TCG seems to be a blank slate.


I guess you have to use PRId32 here? Could you please send a patch?
Sure, let me try it on the macOS.


  Thanks,
   Thomas






[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux