Re: [PATCH 2/3] KVM: x86: Control guest reads of MSR_PLATFORM_INFO

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Aug 10, 2018 at 02:26:03PM -0700, Drew Schmitt wrote:
> Add KVM_CAP_MSR_PLATFORM_INFO so that userspace can disable guest access
> to reads of MSR_PLATFORM_INFO.

Or enable it - by default it is enabled. Perhaps by default it should
be disabled?

Also shouldn't there be an update to the API docs?
> 
> Signed-off-by: Drew Schmitt <dasch@xxxxxxxxxx>
> ---
>  arch/x86/include/asm/kvm_host.h |  2 ++
>  arch/x86/kvm/x86.c              | 10 ++++++++++
>  include/uapi/linux/kvm.h        |  1 +
>  3 files changed, 13 insertions(+)
> 
> diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> index c13cd28d9d1be..c0497c7a4869f 100644
> --- a/arch/x86/include/asm/kvm_host.h
> +++ b/arch/x86/include/asm/kvm_host.h
> @@ -853,6 +853,8 @@ struct kvm_arch {
>  
>  	bool x2apic_format;
>  	bool x2apic_broadcast_quirk_disabled;
> +
> +	bool guest_can_read_msr_platform_info;
>  };
>  
>  struct kvm_vm_stat {
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 0278cde1893ca..b27d88fc6eb8f 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -2743,6 +2743,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:
> @@ -2890,6 +2893,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:
> @@ -4259,6 +4263,10 @@ static int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
>  			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;
> @@ -8724,6 +8732,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);
>  
> diff --git a/include/uapi/linux/kvm.h b/include/uapi/linux/kvm.h
> index b6270a3b38e9f..f3367041b609b 100644
> --- a/include/uapi/linux/kvm.h
> +++ b/include/uapi/linux/kvm.h
> @@ -949,6 +949,7 @@ struct kvm_ppc_resize_hpt {
>  #define KVM_CAP_GET_MSR_FEATURES 153
>  #define KVM_CAP_HYPERV_EVENTFD 154
>  #define KVM_CAP_HYPERV_TLBFLUSH 155
> +#define KVM_CAP_MSR_PLATFORM_INFO 156
>  
>  #ifdef KVM_CAP_IRQ_ROUTING
>  
> -- 
> 2.18.0.597.ga71716f1ad-goog
> 



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux