From: Marcelo Tosatti <mtosatti@redhat.com>
To: Zachary Amsden <zamsden@gmail.com>, Joerg Roedel <joerg.roedel@amd.com>
Cc: "Nadav Har'El" <nyh@il.ibm.com>,
kvm@vger.kernel.org, Bandan Das <bandan.das@stratus.com>,
avi@redhat.com
Subject: Re: [PATCH 3/3] Fix TSC MSR read in nested SVM
Date: Fri, 5 Aug 2011 12:32:24 -0300 [thread overview]
Message-ID: <20110805153224.GB16953@amt.cnet> (raw)
In-Reply-To: <20110803210052.GB31923@amt.cnet>
On Wed, Aug 03, 2011 at 06:00:52PM -0300, Marcelo Tosatti wrote:
> On Wed, Aug 03, 2011 at 01:34:58AM -0700, Zachary Amsden wrote:
> > Caution: this requires more care.
> >
> > Pretty sure this breaks userspace suspend at the cost of supporting a
> > not-so-reasonable hardware feature.
> >
> > On Tue, Aug 2, 2011 at 5:55 AM, Nadav Har'El <nyh@il.ibm.com> wrote:
> > > When the TSC MSR is read by an L2 guest (when L1 allowed this MSR to be
> > > read without exit), we need to return L2's notion of the TSC, not L1's.
> > >
> > > The current code incorrectly returned L1 TSC, because svm_get_msr() was also
> > > used in x86.c where this was assumed, but now that these places call the new
> > > svm_read_l1_tsc(), the MSR read can be fixed.
> > >
> > > Signed-off-by: Nadav Har'El <nyh@il.ibm.com>
> > > ---
> > > arch/x86/kvm/svm.c | 4 +---
> > > 1 file changed, 1 insertion(+), 3 deletions(-)
> > >
> > > --- .before/arch/x86/kvm/svm.c 2011-08-02 15:51:02.000000000 +0300
> > > +++ .after/arch/x86/kvm/svm.c 2011-08-02 15:51:02.000000000 +0300
> > > @@ -2907,9 +2907,7 @@ static int svm_get_msr(struct kvm_vcpu *
> > >
> > > switch (ecx) {
> > > case MSR_IA32_TSC: {
> > > - struct vmcb *vmcb = get_host_vmcb(svm);
> > > -
> > > - *data = vmcb->control.tsc_offset +
> > > + *data = svm->vmcb->control.tsc_offset +
> > > svm_scale_tsc(vcpu, native_read_tsc());
> > >
> > > break;
> > >
> >
> >
> > This is correct. Now you properly return the correct MSR value for
> > the TSC to the guest in all cases.
> >
> > However, there is a BIG PROBLEM (yes, it is that bad). Sorry I did
> > not think of it before.
> >
> > When the guest gets suspended and frozen by userspace, to be restarted
> > later, what qemu is going to do is come along and read all of the MSRs
> > as part of the saved state. One of those happens to be the TSC MSR.
> >
> > Since you can't guarantee suspend will take place when only L1 is
> > running, you may have mixed L1/L2 TSC MSRs now being returned to
> > userspace. Now, when you resume this guest, you will have mixed L1/L2
> > TSC values written into the MSRs.
> >
> > Those will almost certainly fail to be matched by the TSC offset
> > matching code, and thus, with multiple VCPUs, you will end up with
> > slightly unsynchronized TSCs, and with that, all the problems
> > associated with unstable TSC come back to haunt you again. Basically,
> > all bets for stability are off.
>
> TSC synchronization is the least of your problems if you attempt to
> save/restore state a guest while any vcpu is in L2 mode.
>
> So to keep consistency between the remaining MSRs, i agree with Nadav's
> patch. Apparently SVM's original patches to return L1 TSC were aimed at
> fixing the problem VMX is facing now, which is fixed by introduction
> read_l1_tsc helpers.
Joerg, can you review and ack Nadav's SVM patch? TIA
next prev parent reply other threads:[~2011-08-05 17:11 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-02 12:53 [PATCH 0/3] Nested TSC handling Nadav Har'El
2011-08-02 12:54 ` [PATCH 1/3] L1 " Nadav Har'El
2011-08-03 7:54 ` Zachary Amsden
2011-08-02 12:54 ` [PATCH 2/3] Fix nested VMX TSC emulation Nadav Har'El
2011-08-03 8:19 ` Zachary Amsden
2011-08-03 8:35 ` Nadav Har'El
2011-08-02 12:55 ` [PATCH 3/3] Fix TSC MSR read in nested SVM Nadav Har'El
2011-08-03 8:34 ` Zachary Amsden
2011-08-03 11:29 ` Nadav Har'El
2011-08-03 21:00 ` Marcelo Tosatti
2011-08-05 15:32 ` Marcelo Tosatti [this message]
2011-08-06 12:16 ` Joerg Roedel
2011-08-07 12:04 ` Joerg Roedel
2011-08-10 12:35 ` Nadav Har'El
2011-08-10 13:02 ` Joerg Roedel
2011-08-02 19:24 ` [PATCH 0/3] Nested TSC handling Bandan Das
2011-08-02 19:54 ` Matt McGill
2011-08-10 15:40 ` Avi Kivity
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=20110805153224.GB16953@amt.cnet \
--to=mtosatti@redhat.com \
--cc=avi@redhat.com \
--cc=bandan.das@stratus.com \
--cc=joerg.roedel@amd.com \
--cc=kvm@vger.kernel.org \
--cc=nyh@il.ibm.com \
--cc=zamsden@gmail.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