Skip to content

Commit ed85c06

Browse files
aprzywaravikivity
authored andcommitted
KVM: introduce module parameter for ignoring unknown MSRs accesses
KVM will inject a #GP into the guest if that tries to access unhandled MSRs. This will crash many guests. Although it would be the correct way to actually handle these MSRs, we introduce a runtime switchable module param called "ignore_msrs" (defaults to 0). If this is Y, unknown MSR reads will return 0, while MSR writes are simply dropped. In both cases we print a message to dmesg to inform the user about that. You can change the behaviour at any time by saying: # echo 1 > /sys/modules/kvm/parameters/ignore_msrs Signed-off-by: Andre Przywara <[email protected]> Signed-off-by: Avi Kivity <[email protected]>
1 parent 1fdbd48 commit ed85c06

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

arch/x86/kvm/x86.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ struct kvm_cpuid_entry2 *kvm_find_cpuid_entry(struct kvm_vcpu *vcpu,
8383
struct kvm_x86_ops *kvm_x86_ops;
8484
EXPORT_SYMBOL_GPL(kvm_x86_ops);
8585

86+
int ignore_msrs = 0;
87+
module_param_named(ignore_msrs, ignore_msrs, bool, S_IRUGO | S_IWUSR);
88+
8689
struct kvm_stats_debugfs_item debugfs_entries[] = {
8790
{ "pf_fixed", VCPU_STAT(pf_fixed) },
8891
{ "pf_guest", VCPU_STAT(pf_guest) },
@@ -930,8 +933,15 @@ int kvm_set_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 data)
930933
"0x%x data 0x%llx\n", msr, data);
931934
break;
932935
default:
933-
pr_unimpl(vcpu, "unhandled wrmsr: 0x%x data %llx\n", msr, data);
934-
return 1;
936+
if (!ignore_msrs) {
937+
pr_unimpl(vcpu, "unhandled wrmsr: 0x%x data %llx\n",
938+
msr, data);
939+
return 1;
940+
} else {
941+
pr_unimpl(vcpu, "ignored wrmsr: 0x%x data %llx\n",
942+
msr, data);
943+
break;
944+
}
935945
}
936946
return 0;
937947
}
@@ -1078,8 +1088,14 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, u32 msr, u64 *pdata)
10781088
case MSR_IA32_MC0_CTL ... MSR_IA32_MC0_CTL + 4 * KVM_MAX_MCE_BANKS - 1:
10791089
return get_msr_mce(vcpu, msr, pdata);
10801090
default:
1081-
pr_unimpl(vcpu, "unhandled rdmsr: 0x%x\n", msr);
1082-
return 1;
1091+
if (!ignore_msrs) {
1092+
pr_unimpl(vcpu, "unhandled rdmsr: 0x%x\n", msr);
1093+
return 1;
1094+
} else {
1095+
pr_unimpl(vcpu, "ignored rdmsr: 0x%x\n", msr);
1096+
data = 0;
1097+
}
1098+
break;
10831099
}
10841100
*pdata = data;
10851101
return 0;

0 commit comments

Comments
 (0)