]> git.baikalelectronics.ru Git - kernel.git/commitdiff
KVM: x86: Control guest reads of MSR_PLATFORM_INFO
authorDrew Schmitt <dasch@google.com>
Mon, 20 Aug 2018 17:32:15 +0000 (10:32 -0700)
committerPaolo Bonzini <pbonzini@redhat.com>
Wed, 19 Sep 2018 22:51:46 +0000 (00:51 +0200)
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>
Documentation/virtual/kvm/api.txt
arch/x86/include/asm/kvm_host.h
arch/x86/kvm/x86.c
include/uapi/linux/kvm.h

index 8d8a372c834014dd0f6b40fae0892e0958e88a59..647f94128a85e47183f0ba7ffd6cbfc90fe1e6f5 100644 (file)
@@ -4522,6 +4522,15 @@ hpage module parameter is not set to 1, -EINVAL is returned.
 While it is generally possible to create a huge page backed VM without
 this capability, the VM will not be able to run.
 
+7.14 KVM_CAP_MSR_PLATFORM_INFO
+
+Architectures: x86
+Parameters: args[0] whether feature should be enabled or not
+
+With this capability, a guest may read the MSR_PLATFORM_INFO MSR. Otherwise,
+a #GP would be raised when the guest tries to access. Currently, this
+capability does not enable write permissions of this MSR for the guest.
+
 8. Other capabilities.
 ----------------------
 
index af63c2ca1616525850bd94a3122cd4b524c1d190..09b2e3e2cf1bec5f7b745590b187521c8576eacc 100644 (file)
@@ -869,6 +869,8 @@ struct kvm_arch {
 
        bool x2apic_format;
        bool x2apic_broadcast_quirk_disabled;
+
+       bool guest_can_read_msr_platform_info;
 };
 
 struct kvm_vm_stat {
index e127703e277e6b23f524c402daca9c10840bdeb9..4c39ec5fc4fe6f0dbf7b22fe9340d7fb11d4a928 100644 (file)
@@ -2779,6 +2779,9 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
                msr_info->data = vcpu->arch.osvw.status;
                break;
        case MSR_PLATFORM_INFO:
+               if (!msr_info->host_initiated &&
+                   !vcpu->kvm->arch.guest_can_read_msr_platform_info)
+                       return 1;
                msr_info->data = vcpu->arch.msr_platform_info;
                break;
        case MSR_MISC_FEATURES_ENABLES:
@@ -2926,6 +2929,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext)
        case KVM_CAP_SPLIT_IRQCHIP:
        case KVM_CAP_IMMEDIATE_EXIT:
        case KVM_CAP_GET_MSR_FEATURES:
+       case KVM_CAP_MSR_PLATFORM_INFO:
                r = 1;
                break;
        case KVM_CAP_SYNC_REGS:
@@ -4349,6 +4353,10 @@ split_irqchip_unlock:
                        kvm->arch.pause_in_guest = true;
                r = 0;
                break;
+       case KVM_CAP_MSR_PLATFORM_INFO:
+               kvm->arch.guest_can_read_msr_platform_info = cap->args[0];
+               r = 0;
+               break;
        default:
                r = -EINVAL;
                break;
@@ -8857,6 +8865,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type)
        kvm->arch.kvmclock_offset = -ktime_get_boot_ns();
        pvclock_update_vm_gtod_copy(kvm);
 
+       kvm->arch.guest_can_read_msr_platform_info = true;
+
        INIT_DELAYED_WORK(&kvm->arch.kvmclock_update_work, kvmclock_update_fn);
        INIT_DELAYED_WORK(&kvm->arch.kvmclock_sync_work, kvmclock_sync_fn);
 
index 07548de5c9889f5bcd425a7273b2732003bf3c30..251be353f950b35082eff384a97028f64ff593e5 100644 (file)
@@ -952,6 +952,7 @@ struct kvm_ppc_resize_hpt {
 #define KVM_CAP_S390_HPAGE_1M 156
 #define KVM_CAP_NESTED_STATE 157
 #define KVM_CAP_ARM_INJECT_SERROR_ESR 158
+#define KVM_CAP_MSR_PLATFORM_INFO 159
 
 #ifdef KVM_CAP_IRQ_ROUTING