From: Joerg Roedel <joerg.roedel@amd.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Alexander Graf <agraf@suse.de>,
Joerg Roedel <joerg.roedel@amd.com>
Subject: [PATCH 4/5] KVM: SVM: Handle tsc in svm_get_msr/svm_set_msr correctly
Date: Wed, 16 Sep 2009 15:24:18 +0200 [thread overview]
Message-ID: <1253107459-8967-5-git-send-email-joerg.roedel@amd.com> (raw)
In-Reply-To: <1253107459-8967-1-git-send-email-joerg.roedel@amd.com>
When running nested we need to touch the l1 guests
tsc_offset. Otherwise changes will be lost or a wrong value
be read.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
arch/x86/kvm/svm.c | 23 +++++++++++++++++------
1 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
index 84c2c78..e193cf9 100644
--- a/arch/x86/kvm/svm.c
+++ b/arch/x86/kvm/svm.c
@@ -2059,10 +2059,14 @@ static int svm_get_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 *data)
switch (ecx) {
case MSR_IA32_TSC: {
- u64 tsc;
+ u64 tsc_offset;
- rdtscll(tsc);
- *data = svm->vmcb->control.tsc_offset + tsc;
+ if (is_nested(svm))
+ tsc_offset = svm->nested.hsave->control.tsc_offset;
+ else
+ tsc_offset = svm->vmcb->control.tsc_offset;
+
+ *data = tsc_offset + native_read_tsc();
break;
}
case MSR_K6_STAR:
@@ -2148,10 +2152,17 @@ static int svm_set_msr(struct kvm_vcpu *vcpu, unsigned ecx, u64 data)
switch (ecx) {
case MSR_IA32_TSC: {
- u64 tsc;
+ u64 tsc_offset = data - native_read_tsc();
+ u64 g_tsc_offset = 0;
+
+ if (is_nested(svm)) {
+ g_tsc_offset = svm->vmcb->control.tsc_offset -
+ svm->nested.hsave->control.tsc_offset;
+ svm->nested.hsave->control.tsc_offset = tsc_offset;
+ }
+
+ svm->vmcb->control.tsc_offset = tsc_offset + g_tsc_offset;
- rdtscll(tsc);
- svm->vmcb->control.tsc_offset = data - tsc;
break;
}
case MSR_K6_STAR:
--
1.6.3.3
next prev parent reply other threads:[~2009-09-16 13:27 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-09-16 13:24 [PATCH 0/5] Another set of Nested SVM fixes and cleanups Joerg Roedel
2009-09-16 13:24 ` [PATCH 1/5] KVM: SVM: reorganize svm_interrupt_allowed Joerg Roedel
2009-09-16 13:24 ` [PATCH 2/5] KVM: SVM: don't copy exit_int_info on nested vmrun Joerg Roedel
2009-09-16 13:24 ` [PATCH 3/5] KVM: SVM: Fix tsc offset adjustment when running nested Joerg Roedel
2009-09-16 13:24 ` Joerg Roedel [this message]
2009-09-16 13:24 ` [PATCH 5/5] KVM: SVM: Remove remaining occurences of rdtscll Joerg Roedel
2009-09-16 14:02 ` [PATCH 0/5] Another set of Nested SVM fixes and cleanups Avi Kivity
2009-09-16 14:18 ` Joerg Roedel
2009-09-18 6:53 ` Marcelo Tosatti
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=1253107459-8967-5-git-send-email-joerg.roedel@amd.com \
--to=joerg.roedel@amd.com \
--cc=agraf@suse.de \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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
Powered by JetHome