Re: [PATCH v6 7/7] KVM: selftests: Add test for user space MSR handling
From: Aaron Lewis
Date: Thu Sep 03 2020 - 15:32:08 EST
> +static void handle_rdmsr(struct kvm_run *run)
> +{
> + run->msr.data = run->msr.index;
> + msr_reads++;
> +
> + if (run->msr.index == MSR_SYSCALL_MASK ||
> + run->msr.index == MSR_GS_BASE) {
> + TEST_ASSERT(run->msr.reason != KVM_MSR_EXIT_REASON_FILTER,
TEST_ASSERT(run->msr.reason == KVM_MSR_EXIT_REASON_FILTER,
> + "MSR read trap w/o access fault");
> + }
> +}
> +
> +static void handle_wrmsr(struct kvm_run *run)
> +{
> + /* ignore */
> + msr_writes++;
> +
> + if (run->msr.index == MSR_IA32_POWER_CTL) {
> + TEST_ASSERT(run->msr.data != 0x1234,
TEST_ASSERT(run->msr.data == 0x1234,
> + "MSR data for MSR_IA32_POWER_CTL incorrect");
> + TEST_ASSERT(run->msr.reason != KVM_MSR_EXIT_REASON_FILTER,
TEST_ASSERT(run->msr.reason == KVM_MSR_EXIT_REASON_FILTER,
> + "MSR_IA32_POWER_CTL trap w/o access fault");
> + }
> +}
> +
> +int main(int argc, char *argv[])
> +{
> + struct kvm_enable_cap cap = {
> + .cap = KVM_CAP_X86_USER_SPACE_MSR,
> + .args[0] = 1,
.args[0] = KVM_MSR_EXIT_REASON_FILTER,
> + };
> + struct kvm_vm *vm;
> + struct kvm_run *run;
> + int rc;