@@ -418,6 +418,7 @@ struct kvm_arch{
unsigned long irq_sources_bitmap;
u64 vm_init_tsc;
s64 kvmclock_offset;
+ unsigned int tsc_mode;
unsigned int tsc_khz;
unsigned long tsc_multiplier;
int tsc_shift;
@@ -1727,7 +1727,7 @@ int kvm_dev_ioctl_check_extension(long ext)
case KVM_CAP_SET_IDENTITY_MAP_ADDR:
case KVM_CAP_XEN_HVM:
case KVM_CAP_ADJUST_CLOCK:
- case KVM_CAP_SET_TSC_RATE:
+ case KVM_CAP_SET_TSC_MODE:
r = 1;
break;
case KVM_CAP_COALESCED_MMIO:
@@ -3015,23 +3015,26 @@ long kvm_arch_vm_ioctl(struct file *filp,
break;
}
- case KVM_X86_GET_TSC_RATE: {
- u32 rate = kvm->arch.tsc_khz;
+ case KVM_X86_GET_TSC_MODE: {
+ struct kvm_tsc_state state;
+ state.rate = kvm->arch.tsc_khz;
+ state.mode = kvm->arch.tsc_mode;
r = -EFAULT;
- if (copy_to_user(argp, &rate, sizeof(rate)))
+ if (copy_to_user(argp, &state, sizeof(state)))
goto out;
r = 0;
break;
}
- case KVM_X86_SET_TSC_RATE: {
- u32 tsc_rate;
+ case KVM_X86_SET_TSC_MODE: {
+ struct kvm_tsc_state state;
r = -EFAULT;
- if (copy_from_user(&tsc_rate, argp, sizeof tsc_rate))
+ if (copy_from_user(&state, argp, sizeof(state)))
goto out;
r = -EINVAL;
- if (tsc_rate == 0 || tsc_rate > (1ULL << 30))
+ if (state.rate == 0 || state.rate > (1ULL << 30) ||
+ state.mode > KVM_TSC_MODE_HYBRID)
goto out;
- r = kvm_set_tsc_rate(kvm, tsc_rate);
+ r = kvm_set_tsc_rate(kvm, state.rate);
break;
}
@@ -440,7 +440,7 @@ struct kvm_ioeventfd {
#define KVM_CAP_XEN_HVM 38
#endif
#define KVM_CAP_ADJUST_CLOCK 39
-#define KVM_CAP_SET_TSC_RATE 40
+#define KVM_CAP_SET_TSC_MODE 40
#ifdef KVM_CAP_IRQ_ROUTING
@@ -520,6 +520,17 @@ struct kvm_clock_data {
__u32 pad[9];
};
+struct kvm_tsc_state {
+ __u32 rate;
+ __u32 mode;
+};
+
+enum {
+ KVM_TSC_MODE_PASSTHROUGH,
+ KVM_TSC_MODE_INTERCEPT,
+ KVM_TSC_MODE_HYBRID
+};
+
/*
* ioctls for VM fds
*/
@@ -620,8 +631,8 @@ struct kvm_clock_data {
#define KVM_X86_SETUP_MCE _IOW(KVMIO, 0x9c, __u64)
#define KVM_X86_GET_MCE_CAP_SUPPORTED _IOR(KVMIO, 0x9d, __u64)
#define KVM_X86_SET_MCE _IOW(KVMIO, 0x9e, struct kvm_x86_mce)
-#define KVM_X86_GET_TSC_RATE _IOR(KVMIO, 0x9f, __u64)
-#define KVM_X86_SET_TSC_RATE _IOW(KVMIO, 0xa0, __u64)
+#define KVM_X86_GET_TSC_MODE _IOR(KVMIO, 0x9f, struct kvm_tsc_state)
+#define KVM_X86_SET_TSC_MODE _IOW(KVMIO, 0xa0, struct kvm_tsc_state)
/*
* Deprecated interfaces