From: Joerg Roedel <joerg.roedel@amd.com>
To: Avi Kivity <avi@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: <kvm@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
Zachary Amsden <zamsden@redhat.com>,
Joerg Roedel <joerg.roedel@amd.com>
Subject: [PATCH 6/6] KVM: X86: Implement userspace interface to set virtual_tsc_khz
Date: Wed, 9 Feb 2011 18:29:44 +0100 [thread overview]
Message-ID: <1297272584-22689-7-git-send-email-joerg.roedel@amd.com> (raw)
In-Reply-To: <1297272584-22689-1-git-send-email-joerg.roedel@amd.com>
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>
---
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/svm.c | 3 +++
arch/x86/kvm/x86.c | 38 ++++++++++++++++++++++++++++++++++++++
include/linux/kvm.h | 4 ++++
4 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 8c40425..dfdd0aa 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -633,6 +633,7 @@ int kvm_pv_mmu_op(struct kvm_vcpu *vcpu, unsigned long bytes,
u8 kvm_get_guest_memory_type(struct kvm_vcpu *vcpu, gfn_t gfn);
extern bool tdp_enabled;
+extern int kvm_has_tsc_control;
enum emulation_result {
EMULATE_DONE, /* no further processing */
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index f938585..0b8f4f7 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -797,6 +797,9 @@ static __init int svm_hardware_setup(void)
if (boot_cpu_has(X86_FEATURE_FXSR_OPT))
kvm_enable_efer_bits(EFER_FFXSR);
+ if (boot_cpu_has(X86_FEATURE_TSCRATEMSR))
+ kvm_has_tsc_control = 1;
+
if (nested) {
printk(KERN_INFO "kvm: Nested Virtualization enabled\n");
kvm_enable_efer_bits(EFER_SVME | EFER_LMSLE);
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 6caaf4b..1ac94cc 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -99,6 +99,9 @@ EXPORT_SYMBOL_GPL(kvm_x86_ops);
int ignore_msrs = 0;
module_param_named(ignore_msrs, ignore_msrs, bool, S_IRUGO | S_IWUSR);
+int kvm_has_tsc_control;
+EXPORT_SYMBOL_GPL(kvm_has_tsc_control);
+
#define KVM_NR_SHARED_MSRS 16
struct kvm_shared_msrs_global {
@@ -2024,6 +2027,9 @@ int kvm_dev_ioctl_check_extension(long ext)
case KVM_CAP_XCRS:
r = cpu_has_xsave;
break;
+ case KVM_CAP_TSC_CONTROL:
+ r = kvm_has_tsc_control;
+ break;
default:
r = 0;
break;
@@ -3575,6 +3581,38 @@ long kvm_arch_vm_ioctl(struct file *filp,
r = 0;
break;
}
+ case KVM_SET_TSC_KHZ: {
+ u32 user_tsc_khz;
+
+ if (!kvm_has_tsc_control)
+ break;
+
+ /*
+ * We force the tsc frequency to be set before any
+ * vcpu is created
+ */
+ if (atomic_read(&kvm->online_vcpus) > 0)
+ goto out;
+
+ user_tsc_khz = arg;
+
+ kvm_arch_set_tsc_khz(kvm, user_tsc_khz);
+
+ r = 0;
+ goto out;
+ }
+ case KVM_GET_TSC_KHZ: {
+
+ if (!kvm_has_tsc_control)
+ break;
+
+ r = -EFAULT;
+ if (copy_to_user(argp, &kvm->arch.virtual_tsc_khz, sizeof(__u32)))
+ goto out;
+
+ r = 0;
+ goto out;
+ }
default:
;
diff --git a/include/linux/kvm.h b/include/linux/kvm.h
index ea2dc1a..a96ff92 100644
--- a/include/linux/kvm.h
+++ b/include/linux/kvm.h
@@ -541,6 +541,7 @@ struct kvm_ppc_pvinfo {
#define KVM_CAP_PPC_GET_PVINFO 57
#define KVM_CAP_PPC_IRQ_LEVEL 58
#define KVM_CAP_ASYNC_PF 59
+#define KVM_CAP_TSC_CONTROL 60
#ifdef KVM_CAP_IRQ_ROUTING
@@ -677,6 +678,9 @@ struct kvm_clock_data {
#define KVM_SET_PIT2 _IOW(KVMIO, 0xa0, struct kvm_pit_state2)
/* Available with KVM_CAP_PPC_GET_PVINFO */
#define KVM_PPC_GET_PVINFO _IOW(KVMIO, 0xa1, struct kvm_ppc_pvinfo)
+/* Available with KVM_CAP_TSC_CONTROL */
+#define KVM_SET_TSC_KHZ _IOW(KVMIO, 0xa2, __u32)
+#define KVM_GET_TSC_KHZ _IOR(KVMIO, 0xa3, __u32)
/*
* ioctls for vcpu fds
--
1.7.1
next prev parent reply other threads:[~2011-02-09 17:29 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-09 17:29 [PATCH 0/6] KVM support for TSC scaling Joerg Roedel
2011-02-09 17:29 ` [PATCH 1/6] KVM: SVM: Advance instruction pointer in dr_intercept Joerg Roedel
2011-02-22 11:14 ` Roedel, Joerg
2011-02-22 14:01 ` Avi Kivity
2011-02-22 14:33 ` Roedel, Joerg
2011-02-09 17:29 ` [PATCH 2/6] KVM: SVM: Implement infrastructure for TSC_RATE_MSR Joerg Roedel
2011-02-09 17:29 ` [PATCH 3/6] KVM: X86: Let kvm-clock report the right tsc frequency Joerg Roedel
2011-02-09 17:29 ` [PATCH 4/6] KVM: SVM: Propagate requested TSC frequency on vcpu init Joerg Roedel
2011-02-09 17:29 ` [PATCH 5/6] KVM: X86: Delegate tsc-offset calculation to architecture code Joerg Roedel
2011-02-11 22:12 ` Zachary Amsden
2011-02-21 17:16 ` Roedel, Joerg
2011-02-09 17:29 ` Joerg Roedel [this message]
2011-02-13 15:12 ` [PATCH 6/6] KVM: X86: Implement userspace interface to set virtual_tsc_khz Avi Kivity
2011-02-21 17:17 ` Roedel, Joerg
2011-02-13 15:19 ` [PATCH 0/6] KVM support for TSC scaling Avi Kivity
2011-02-21 17:28 ` Roedel, Joerg
2011-02-21 21:25 ` Zachary Amsden
2011-02-22 10:11 ` Avi Kivity
2011-02-22 10:35 ` Roedel, Joerg
2011-02-22 10:41 ` Avi Kivity
2011-02-22 11:11 ` Roedel, Joerg
2011-02-22 14:11 ` Avi Kivity
-- strict thread matches above, loose matches on Subject: below --
2011-03-15 9:36 [PATCH 0/6] TSC scaling support for KVM v2 Joerg Roedel
2011-03-15 9:36 ` [PATCH 6/6] KVM: X86: Implement userspace interface to set virtual_tsc_khz Joerg Roedel
2011-03-24 7:40 [PATCH 0/6][RESEND] TSC scaling support for KVM v2 Joerg Roedel
2011-03-24 7:40 ` [PATCH 6/6] KVM: X86: Implement userspace interface to set virtual_tsc_khz Joerg Roedel
2011-03-24 10:14 ` Avi Kivity
2011-03-24 10:41 ` Joerg Roedel
2011-03-24 10:44 ` Avi Kivity
2011-03-24 10:47 ` Joerg Roedel
2011-03-25 8:44 [PATCH 0/6] TSC scaling support for KVM v3 Joerg Roedel
2011-03-25 8:44 ` [PATCH 6/6] KVM: X86: Implement userspace interface to set virtual_tsc_khz Joerg Roedel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1297272584-22689-7-git-send-email-joerg.roedel@amd.com \
--to=joerg.roedel@amd.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mtosatti@redhat.com \
--cc=zamsden@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox