Skip to content

Commit 6fbbde9

Browse files
dasch-1bonzini
authored andcommitted
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>
1 parent d84f1cf commit 6fbbde9

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

Documentation/virtual/kvm/api.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4522,6 +4522,15 @@ hpage module parameter is not set to 1, -EINVAL is returned.
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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,8 @@ struct kvm_arch {
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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2779,6 +2779,9 @@ int kvm_get_msr_common(struct kvm_vcpu *vcpu, struct msr_data *msr_info)
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)
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 @@ static int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
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)
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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,7 @@ struct kvm_ppc_resize_hpt {
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

0 commit comments

Comments
 (0)