All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kvm@vger.kernel.org, Sean Christopherson <seanjc@google.com>
Subject: [kvm-unit-tests PATCH 05/10] x86: Provide result of RDMSR from "safe" variant
Date: Wed,  8 Jun 2022 23:52:33 +0000	[thread overview]
Message-ID: <20220608235238.3881916-6-seanjc@google.com> (raw)
In-Reply-To: <20220608235238.3881916-1-seanjc@google.com>

Provide the result of RDMSR from rdmsr_safe() so that it can be used by
tests that are unsure whether or not RDMSR will fault, but want the value
if it doesn't fault.

Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 lib/x86/processor.h | 9 +++++++--
 x86/msr.c           | 3 ++-
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/x86/processor.h b/lib/x86/processor.h
index bc6c8d94..82f8df58 100644
--- a/lib/x86/processor.h
+++ b/lib/x86/processor.h
@@ -360,12 +360,17 @@ static inline void wrmsr(u32 index, u64 val)
 	asm volatile ("wrmsr" : : "a"(a), "d"(d), "c"(index) : "memory");
 }
 
-static inline int rdmsr_safe(u32 index)
+static inline int rdmsr_safe(u32 index, uint64_t *val)
 {
+	uint32_t a, d;
+
 	asm volatile (ASM_TRY("1f")
 		      "rdmsr\n\t"
 		      "1:"
-		      : : "c"(index) : "memory", "eax", "edx");
+		      : "=a"(a), "=d"(d)
+		      : "c"(index) : "memory");
+
+	*val = (uint64_t)a | ((uint64_t)d << 32);
 	return exception_vector();
 }
 
diff --git a/x86/msr.c b/x86/msr.c
index eaca19ed..ee1d3984 100644
--- a/x86/msr.c
+++ b/x86/msr.c
@@ -81,7 +81,8 @@ static void test_wrmsr_fault(struct msr_info *msr, unsigned long long val)
 
 static void test_rdmsr_fault(struct msr_info *msr)
 {
-	unsigned char vector = rdmsr_safe(msr->index);
+	uint64_t ignored;
+	unsigned char vector = rdmsr_safe(msr->index, &ignored);
 
 	report(vector == GP_VECTOR,
 	       "Expected #GP on RDSMR(%s), got vector %d", msr->name, vector);
-- 
2.36.1.255.ge46751e96f-goog


  parent reply	other threads:[~2022-06-08 23:52 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-08 23:52 [kvm-unit-tests PATCH 00/10] x86: nVMX: Add VMXON #UD test Sean Christopherson
2022-06-08 23:52 ` [kvm-unit-tests PATCH 01/10] x86: Use BIT() to define architectural bits Sean Christopherson
2022-06-08 23:52 ` [kvm-unit-tests PATCH 02/10] x86: Replace spaces with tables in processor.h Sean Christopherson
2022-06-08 23:52 ` [kvm-unit-tests PATCH 03/10] x86: Use "safe" terminology instead of "checking" Sean Christopherson
2023-08-22  8:09   ` Like Xu
2022-06-08 23:52 ` [kvm-unit-tests PATCH 04/10] x86: Use "safe" helpers to implement unsafe CRs accessors Sean Christopherson
2022-06-08 23:52 ` Sean Christopherson [this message]
2022-06-08 23:52 ` [kvm-unit-tests PATCH 06/10] nVMX: Check the results of VMXON/VMXOFF in feature control test Sean Christopherson
2022-06-08 23:52 ` [kvm-unit-tests PATCH 07/10] nVMX: Check result of VMXON in INIT/SIPI tests Sean Christopherson
2022-06-08 23:52 ` [kvm-unit-tests PATCH 08/10] nVMX: Wrap VMXON in ASM_TRY(), a.k.a. in exception fixup Sean Christopherson
2022-06-08 23:52 ` [kvm-unit-tests PATCH 09/10] nVMX: Simplify test_vmxon() by returning directly on failure Sean Christopherson
2022-06-08 23:52 ` [kvm-unit-tests PATCH 10/10] nVMX: Add subtest to verify VMXON succeeds/#UDs on good/bad CR0/CR4 Sean Christopherson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220608235238.3881916-6-seanjc@google.com \
    --to=seanjc@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.