aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/x86.c
diff options
context:
space:
mode:
authorJoerg Roedel <joerg.roedel@amd.com>2011-03-25 04:44:51 -0400
committerAvi Kivity <avi@redhat.com>2011-05-11 07:57:06 -0400
commit92a1f12d2598f429bd8639e21d89305e787115c5 (patch)
tree48a6b7d6c50b5583b5163185dd097db100a471c6 /arch/x86/kvm/x86.c
parent857e40999e35906baa367a79137019912cfb5434 (diff)
KVM: X86: Implement userspace interface to set virtual_tsc_khz
This patch implements two new vm-ioctls to get and set the virtual_tsc_khz if the machine supports tsc-scaling. Setting the tsc-frequency is only possible before userspace creates any vcpu. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r--arch/x86/kvm/x86.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 579ce34e7904..1d5a7f418795 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -87,6 +87,11 @@ EXPORT_SYMBOL_GPL(kvm_x86_ops);
87int ignore_msrs = 0; 87int ignore_msrs = 0;
88module_param_named(ignore_msrs, ignore_msrs, bool, S_IRUGO | S_IWUSR); 88module_param_named(ignore_msrs, ignore_msrs, bool, S_IRUGO | S_IWUSR);
89 89
90bool kvm_has_tsc_control;
91EXPORT_SYMBOL_GPL(kvm_has_tsc_control);
92u32 kvm_max_guest_tsc_khz;
93EXPORT_SYMBOL_GPL(kvm_max_guest_tsc_khz);
94
90#define KVM_NR_SHARED_MSRS 16 95#define KVM_NR_SHARED_MSRS 16
91 96
92struct kvm_shared_msrs_global { 97struct kvm_shared_msrs_global {
@@ -1986,6 +1991,7 @@ int kvm_dev_ioctl_check_extension(long ext)
1986 case KVM_CAP_X86_ROBUST_SINGLESTEP: 1991 case KVM_CAP_X86_ROBUST_SINGLESTEP:
1987 case KVM_CAP_XSAVE: 1992 case KVM_CAP_XSAVE:
1988 case KVM_CAP_ASYNC_PF: 1993 case KVM_CAP_ASYNC_PF:
1994 case KVM_CAP_GET_TSC_KHZ:
1989 r = 1; 1995 r = 1;
1990 break; 1996 break;
1991 case KVM_CAP_COALESCED_MMIO: 1997 case KVM_CAP_COALESCED_MMIO:
@@ -2012,6 +2018,9 @@ int kvm_dev_ioctl_check_extension(long ext)
2012 case KVM_CAP_XCRS: 2018 case KVM_CAP_XCRS:
2013 r = cpu_has_xsave; 2019 r = cpu_has_xsave;
2014 break; 2020 break;
2021 case KVM_CAP_TSC_CONTROL:
2022 r = kvm_has_tsc_control;
2023 break;
2015 default: 2024 default:
2016 r = 0; 2025 r = 0;
2017 break; 2026 break;
@@ -3045,6 +3054,32 @@ long kvm_arch_vcpu_ioctl(struct file *filp,
3045 r = kvm_vcpu_ioctl_x86_set_xcrs(vcpu, u.xcrs); 3054 r = kvm_vcpu_ioctl_x86_set_xcrs(vcpu, u.xcrs);
3046 break; 3055 break;
3047 } 3056 }
3057 case KVM_SET_TSC_KHZ: {
3058 u32 user_tsc_khz;
3059
3060 r = -EINVAL;
3061 if (!kvm_has_tsc_control)
3062 break;
3063
3064 user_tsc_khz = (u32)arg;
3065
3066 if (user_tsc_khz >= kvm_max_guest_tsc_khz)
3067 goto out;
3068
3069 kvm_x86_ops->set_tsc_khz(vcpu, user_tsc_khz);
3070
3071 r = 0;
3072 goto out;
3073 }
3074 case KVM_GET_TSC_KHZ: {
3075 r = -EIO;
3076 if (check_tsc_unstable())
3077 goto out;
3078
3079 r = vcpu_tsc_khz(vcpu);
3080
3081 goto out;
3082 }
3048 default: 3083 default:
3049 r = -EINVAL; 3084 r = -EINVAL;
3050 } 3085 }