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
45224522 While it is generally possible to create a huge page backed VM without
45234523 this capability, the VM will not be able to run.
45244524
4525+7.14 KVM_CAP_MSR_PLATFORM_INFO
4526+
4527+Architectures: x86
4528+Parameters: args[0] whether feature should be enabled or not
4529+
4530+With this capability, a guest may read the MSR_PLATFORM_INFO MSR. Otherwise,
4531+a #GP would be raised when the guest tries to access. Currently, this
4532+capability does not enable write permissions of this MSR for the guest.
4533+
45254534 8. Other capabilities.
45264535 ----------------------
45274536
arch/x86/include/asm/kvm_host.h+2−0
@@ -869,6 +869,8 @@ struct kvm_arch { · 868 unmodified lines
869869
870870 bool x2apic_format;
871871 bool x2apic_broadcast_quirk_disabled;
872+
873+ bool guest_can_read_msr_platform_info;
872874 };
873875
874876 struct 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
27792779 msr_info->data = vcpu->arch.osvw.status;
27802780 break;
27812781 case MSR_PLATFORM_INFO:
2782+ if (!msr_info->host_initiated &&
2783+ !vcpu->kvm->arch.guest_can_read_msr_platform_info)
2784+ return 1;
27822785 msr_info->data = vcpu->arch.msr_platform_info;
27832786 break;
27842787 case MSR_MISC_FEATURES_ENABLES:
@@ -2926,6 +2929,7 @@ int kvm_vm_ioctl_check_extension(struct kvm *kvm, long ext) · 141 unmodified lines
29262929 case KVM_CAP_SPLIT_IRQCHIP:
29272930 case KVM_CAP_IMMEDIATE_EXIT:
29282931 case KVM_CAP_GET_MSR_FEATURES:
2932+ case KVM_CAP_MSR_PLATFORM_INFO:
29292933 r = 1;
29302934 break;
29312935 case KVM_CAP_SYNC_REGS:
@@ -4349,6 +4353,10 @@ split_irqchip_unlock: · 1417 unmodified lines
43494353 kvm->arch.pause_in_guest = true;
43504354 r = 0;
43514355 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;
43524360 default:
43534361 r = -EINVAL;
43544362 break;
@@ -8857,6 +8865,8 @@ int kvm_arch_init_vm(struct kvm *kvm, unsigned long type) · 4502 unmodified lines
88578865 kvm->arch.kvmclock_offset = -ktime_get_boot_ns();
88588866 pvclock_update_vm_gtod_copy(kvm);
88598867
8868+ kvm->arch.guest_can_read_msr_platform_info = true;
8869+
88608870 INIT_DELAYED_WORK(&kvm->arch.kvmclock_update_work, kvmclock_update_fn);
88618871 INIT_DELAYED_WORK(&kvm->arch.kvmclock_sync_work, kvmclock_sync_fn);
88628872
include/uapi/linux/kvm.h+1−0
@@ -952,6 +952,7 @@ struct kvm_ppc_resize_hpt { · 951 unmodified lines
952952 #define KVM_CAP_S390_HPAGE_1M 156
953953 #define KVM_CAP_NESTED_STATE 157
954954 #define KVM_CAP_ARM_INJECT_SERROR_ESR 158
955+#define KVM_CAP_MSR_PLATFORM_INFO 159
955956
956957 #ifdef KVM_CAP_IRQ_ROUTING
957958

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