public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH] x86/msr.c generalize to any input msr
@ 2021-08-10 14:31 yqwfh
  2021-09-23  9:11 ` Alexander Graf
  0 siblings, 1 reply; 11+ messages in thread
From: yqwfh @ 2021-08-10 14:31 UTC (permalink / raw)
  To: kvm; +Cc: yqwfh, Daniele Ahmed

If an MSR description is provided as input by the user,
run the test against that MSR. This allows the user to
run tests on custom MSR's.

Otherwise run all default tests.

Signed-off-by: Daniele Ahmed <ahmeddan@amazon.com>
---
 x86/msr.c | 48 ++++++++++++++++++++++++++++++++++--------------
 1 file changed, 34 insertions(+), 14 deletions(-)

diff --git a/x86/msr.c b/x86/msr.c
index 7a551c4..554014e 100644
--- a/x86/msr.c
+++ b/x86/msr.c
@@ -3,6 +3,7 @@
 #include "libcflat.h"
 #include "processor.h"
 #include "msr.h"
+#include <stdlib.h>
 
 struct msr_info {
 	int index;
@@ -77,25 +78,44 @@ static void test_rdmsr_fault(struct msr_info *msr)
 	       "Expected #GP on RDSMR(%s), got vector %d", msr->name, vector);
 }
 
+static void test_msr(struct msr_info *msr, bool is_64bit_host)
+{
+	if (is_64bit_host || !msr->is_64bit_only) {
+		test_msr_rw(msr, msr->value);
+
+		/*
+		 * The 64-bit only MSRs that take an address always perform
+		 * canonical checks on both Intel and AMD.
+		 */
+		if (msr->is_64bit_only &&
+		    msr->value == addr_64)
+			test_wrmsr_fault(msr, NONCANONICAL);
+	} else {
+		test_wrmsr_fault(msr, msr->value);
+		test_rdmsr_fault(msr);
+	}
+}
+
 int main(int ac, char **av)
 {
 	bool is_64bit_host = this_cpu_has(X86_FEATURE_LM);
 	int i;
 
-	for (i = 0 ; i < ARRAY_SIZE(msr_info); i++) {
-		if (is_64bit_host || !msr_info[i].is_64bit_only) {
-			test_msr_rw(&msr_info[i], msr_info[i].value);
-
-			/*
-			 * The 64-bit only MSRs that take an address always perform
-			 * canonical checks on both Intel and AMD.
-			 */
-			if (msr_info[i].is_64bit_only &&
-			    msr_info[i].value == addr_64)
-				test_wrmsr_fault(&msr_info[i], NONCANONICAL);
-		} else {
-			test_wrmsr_fault(&msr_info[i], msr_info[i].value);
-			test_rdmsr_fault(&msr_info[i]);
+	if (ac == 4) {
+		char msr_name[16];
+		int index = strtoul(av[1], NULL, 0x10);
+		snprintf(msr_name, sizeof(msr_name), "MSR:0x%x", index);
+
+		struct msr_info msr = {
+			.index = index,
+			.name = msr_name,
+			.is_64bit_only = !strcmp(av[3], "0"),
+			.value = strtoul(av[2], NULL, 0x10)
+		};
+		test_msr(&msr, is_64bit_host);
+	} else {
+		for (i = 0 ; i < ARRAY_SIZE(msr_info); i++) {
+			test_msr(&msr_info[i], is_64bit_host);
 		}
 	}
 
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-10-15 15:57 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-10 14:31 [kvm-unit-tests PATCH] x86/msr.c generalize to any input msr yqwfh
2021-09-23  9:11 ` Alexander Graf
2021-09-23  9:32   ` Paolo Bonzini
2021-09-27 15:30   ` [kvm-unit-tests PATCH v2 1/3] lib/string: Add stroull and strtoll ahmeddan
2021-09-27 15:30     ` [kvm-unit-tests PATCH v2 2/3] [kvm-unit-tests PATCH] x86/msr.c refactor out generic test logic ahmeddan
2021-09-27 15:38       ` Alexander Graf
2021-09-27 15:30     ` [kvm-unit-tests PATCH v2 3/3] x86/msr.c generalize to any input msr ahmeddan
2021-09-28 15:36       ` Paolo Bonzini
2021-10-01 14:14         ` Ahmed, Daniele
2021-10-15 15:57       ` Paolo Bonzini
2021-10-13 16:44     ` [kvm-unit-tests PATCH v2 1/3] lib/string: Add stroull and strtoll Andrew Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox