From: Daniele Ahmed <ahmeddan@xxxxxxxxxx> 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. This is to validate custom MSR handling in user space with an easy-to-use tool. This kvm-unit-test submodule is a perfect fit. I'm extending it with a mode that takes an MSR index and a value to test arbitrary MSR accesses. Signed-off-by: Daniele Ahmed <ahmeddan@xxxxxxxxxx> --- x86/msr.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/x86/msr.c b/x86/msr.c index 8931f59..1a2d791 100644 --- a/x86/msr.c +++ b/x86/msr.c @@ -3,6 +3,17 @@ #include "libcflat.h" #include "processor.h" #include "msr.h" +#include <stdlib.h> + +/** + * This test allows two modes: + * 1. Default: the `msr_info' array contains the default test configurations + * 2. Custom: by providing command line arguments it is possible to test any MSR and value + * Parameters order: + * 1. msr index as a base 16 number + * 2. value as a base 16 number + * 3. "0" if the msr is available only in 64b hosts, any other string otherwise + */ struct msr_info { int index; @@ -100,8 +111,22 @@ 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++) { - test_msr(&msr_info[i], is_64bit_host); + 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 = strtoull(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); + } } return report_summary(); -- 2.32.0 Amazon Development Center Germany GmbH Krausenstr. 38 10117 Berlin Geschaeftsfuehrung: Christian Schlaeger, Jonathan Weiss Eingetragen am Amtsgericht Charlottenburg unter HRB 149173 B Sitz: Berlin Ust-ID: DE 289 237 879