aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDrew Schmitt <dasch@google.com>2018-08-20 13:32:15 -0400
committerPaolo Bonzini <pbonzini@redhat.com>2018-09-19 18:51:46 -0400
commit6fbbde9a1969dfb476467ebf69a475095ef3fd4d (patch)
tree39bdc75de08111b9b6a7a28e238eb8efca0841cc
parentd84f1cff9028c00ee870f0293b0c7a3866071dfa (diff)
KVM: x86: Control guest reads of MSR_PLATFORM_INFO
Add KVM_CAP_MSR_PLATFORM_INFO so that userspace can disable guest access to reads of MSR_PLATFORM_INFO. Disabling access to reads of this MSR gives userspace the control to "expose" this platform-dependent information to guests in a clear way. As it exists today, guests that read this MSR would get unpopulated information if userspace hadn't already set it (and prior to this patch series, only the CPUID faulting information could have been populated). This existing interface could be confusing if guests don't handle the potential for incorrect/incomplete information gracefully (e.g. zero reported for base frequency). Signed-off-by: Drew Schmitt <dasch@google.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r--Documentation/virtual/kvm/api.txt9
-rw-r--r--arch/x86/include/asm/kvm_host.h2
-rw-r--r--arch/x86/kvm/x86.c10
-rw-r--r--include/uapi/linux/kvm.h1
4 files changed, 22 insertions, 0 deletions
diff --git a/Documentation/virtual/kvm/api.txt b/Documentation/virtual/kvm/api.txt
index 8d8a372c8340..647f94128a85 100644
--- a/Documentation/virtual/kvm/api.txt
+++ b/Documentation/virtual/kvm/api.txt
@@ -4522,6 +4522,15 @@ hpage module parameter is not set to 1, -EINVAL is returned.
4522While it is generally possible to create a huge page backed VM without 4522While it is generally possible to create a huge page backed VM without
4523this capability, the VM will not be able to run. 4523this capability, the VM will not be able to run.
4524 4524
45257.14 KVM_CAP_MSR_PLATFORM_INFO
4526
4527Architectures: x86
4528Parameters: args[0] whether feature should be enabled or not
4529
4530With this capability, a guest may read the MSR_PLATFORM_INFO MSR. Otherwise,
4531a #GP would be raised when the guest tries to access. Currently, this
4532capability does not enable write permissions of this MSR for the guest.
4533
45258. Other capabilities. 45348. Other capabilities.
4526---------------------- 4535----------------------
4527 4536
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index af63c2ca1616..09b2e3e2cf1b 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -869,6 +869,8 @@ struct kvm_arch {
869 869
870 bool x2apic_format; 870 bool x2apic_format;
871 bool x2apic_broadcast_quirk_disabled; 871 bool x2apic_broadcast_quirk_disabled;
872
873 bool guest_can_read_msr_platform_info;
872}; 874};
873 875
874struct kvm_vm_stat { 876struct kvm_vm_stat {
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index e127703e277e..4c39ec5fc4fe 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -2779,6 +2779,9 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
2779 msr_info->data = vcpu->arch.osvw.status; 2779 msr_info->data = vcpu->arch.osvw.status;
2780 break; 2780 break;
2781 case MSR_PLATFORM_INFO: 2781 case MSR_PLATFORM_INFO:
2782 if (!msr_info->host_initiated &&
2783 !vcpu->kvm->arch.guest_can_read_msr_platform_info)
2784 return 1;
2782 msr_info->data = vcpu->arch.msr_platform_info; 2785 msr_info->data = vcpu->arch.msr_platform_info;
2783 break; 2786 break;
2784 case MSR_MISC_FEATURES_ENABLES: 2787 case MSR_MISC_FEATURES_ENABLES:
@@ -2926,6 +2929,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
2926 case KVM_CAP_SPLIT_IRQCHIP: 2929 case KVM_CAP_SPLIT_IRQCHIP:
2927 case KVM_CAP_IMMEDIATE_EXIT: 2930 case KVM_CAP_IMMEDIATE_EXIT:
2928 case KVM_CAP_GET_MSR_FEATURES: 2931 case KVM_CAP_GET_MSR_FEATURES:
2932 case KVM_CAP_MSR_PLATFORM_INFO:
2929 r = 1; 2933 r = 1;
2930 break; 2934 break;
2931 case KVM_CAP_SYNC_REGS: 2935 case KVM_CAP_SYNC_REGS:
@@ -4349,6 +4353,10 @@ split_irqchip_unlock:
4349 kvm->arch.pause_in_guest = true; 4353 kvm->arch.pause_in_guest = true;
4350 r = 0; 4354 r = 0;
4351 break; 4355 break;
4356 case KVM_CAP_MSR_PLATFORM_INFO:
4357 kvm->arch.guest_can_read_msr_platform_info = cap->args[0];
4358 r = 0;
4359 break;
4352 default: 4360 default:
4353 r = -EINVAL; 4361 r = -EINVAL;
4354 break; 4362 break;
@@ -8857,6 +8865,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
8857 kvm->arch.kvmclock_offset = -ktime_get_boot_ns(); 8865 kvm->arch.kvmclock_offset = -ktime_get_boot_ns();
8858 pvclock_update_vm_gtod_copy(kvm); 8866 pvclock_update_vm_gtod_copy(kvm);
8859 8867
8868 kvm->arch.guest_can_read_msr_platform_info = true;
8869
8860 INIT_DELAYED_WORK(&kvm->arch.kvmclock_update_work, kvmclock_update_fn); 8870 INIT_DELAYED_WORK(&kvm->arch.kvmclock_update_work, kvmclock_update_fn);
8861 INIT_DELAYED_WORK(&kvm->arch.kvmclock_sync_work, kvmclock_sync_fn); 8871 INIT_DELAYED_WORK(&kvm->arch.kvmclock_sync_work, kvmclock_sync_fn);
8862 8872
diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
index 07548de5c988..251be353f950 100644
--- a/include/uapi/linux/kvm.h
+++ b/include/uapi/linux/kvm.h
@@ -952,6 +952,7 @@ struct kvm_ppc_resize_hpt {
952#define KVM_CAP_S390_HPAGE_1M 156 952#define KVM_CAP_S390_HPAGE_1M 156
953#define KVM_CAP_NESTED_STATE 157 953#define KVM_CAP_NESTED_STATE 157
954#define KVM_CAP_ARM_INJECT_SERROR_ESR 158 954#define KVM_CAP_ARM_INJECT_SERROR_ESR 158
955#define KVM_CAP_MSR_PLATFORM_INFO 159
955 956
956#ifdef KVM_CAP_IRQ_ROUTING 957#ifdef KVM_CAP_IRQ_ROUTING
957 958