History

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).

Drew Schmitt committed 8 years ago

Commit 6fbbde91 parent d84f1cf4 files · +22 −0Browse files

Unified · Split

4 files
  1. Documentation/virtual/kvm/api.txt +9 −0
  2. arch/x86/include/asm/kvm_host.h +2 −0
  3. arch/x86/kvm/x86.c +10 −0
  4. include/uapi/linux/kvm.h +1 −0
Documentation/virtual/kvm/api.txt+9−0
@@ -4522,6 +4522,15 @@ hpage module parameter is not set to 1, -EINVAL is returned. · 4521 unmodified lines
4522While it is generally possible to create a huge page backed VM without4522While 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
arch/x86/include/asm/kvm_host.h+2−0
@@ -869,6 +869,8 @@ struct kvm_arch { · 868 unmodified lines
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 {
arch/x86/kvm/x86.c+10−0
@@ -2779,6 +2779,9 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info) · 2778 unmodified lines
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) · 141 unmodified lines
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: · 1417 unmodified lines
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) · 4502 unmodified lines
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
include/uapi/linux/kvm.h+1−0
@@ -952,6 +952,7 @@ struct kvm_ppc_resize_hpt { · 951 unmodified lines
952#define KVM_CAP_S390_HPAGE_1M 156952#define KVM_CAP_S390_HPAGE_1M 156
953#define KVM_CAP_NESTED_STATE 157953#define KVM_CAP_NESTED_STATE 157
954#define KVM_CAP_ARM_INJECT_SERROR_ESR 158954#define KVM_CAP_ARM_INJECT_SERROR_ESR 158
955#define KVM_CAP_MSR_PLATFORM_INFO 159
955 956
956#ifdef KVM_CAP_IRQ_ROUTING957#ifdef KVM_CAP_IRQ_ROUTING
957 958

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t