public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Nadav Har'El <nyh@math.technion.ac.il>
To: Jan Kiszka <jan.kiszka@siemens.com>
Cc: Gleb Natapov <gleb@redhat.com>,
	Marcelo Tosatti <mtosatti@redhat.com>, kvm <kvm@vger.kernel.org>,
	"Nakajima, Jun" <jun.nakajima@intel.com>
Subject: Re: [PATCH] KVM: nVMX: Fix setting of CR0 and CR4 in guest mode
Date: Mon, 4 Mar 2013 17:30:38 +0200	[thread overview]
Message-ID: <20130304153038.GA16279@fermat.math.technion.ac.il> (raw)
In-Reply-To: <5134AEEB.9020600@siemens.com>

On Mon, Mar 04, 2013, Jan Kiszka wrote about "Re: [PATCH] KVM: nVMX: Fix setting of CR0 and CR4 in guest mode":
> >>>>  	if (is_guest_mode(vcpu)) {
> >>>> -		/*
> >>>> -		 * We get here when L2 changed cr0 in a way that did not change
> >>>> -		 * any of L1's shadowed bits (see nested_vmx_exit_handled_cr),
> >>>> -		 * but did change L0 shadowed bits. This can currently happen
> >>>> -		 * with the TS bit: L0 may want to leave TS on (for lazy fpu
> >>>> -		 * loading) while pretending to allow the guest to change it.
> >>>> -		 */
> >>> Can't say I understand this patch yet, but it looks like the comment is
> >>> still valid. Why have you removed it?
> >>
> >> L0 allows L1 or L2 at most to own TS, the rest is host-owned. I think
> >> the comment was always misleading.
> >>
> > I do not see how it is misleading. For everything but TS we will not get
> > here (if L1 is kvm). For TS we will get here if L1 allows L2 to change
> > it, but L0 does not.
> 
> For everything *but guest-owned* we will get here, thus for most CR0
> accesses (bit-wise, not regarding frequency).

For most CR0 bits, L1 (at least, a KVM one) will shadow (trap) them, so
we won't get to this point you modified at all... Instead,
nested_vmx_exit_handled_cr() would notice that a shadowed-by-L1 bit
was modified so an exit to L1 is required. We only get to that code
you changed if a bit was modified that L1 did *not* want to trap, but L0 did.
This is definitely not the bit-wise majority of the cases - unless you
have an L1 that does not trap most of the CR0 bits.

But I'm more worried about the actual code change :-) I didn't
understand if there's a situation where the existing code did something
wrong, or why it was wrong. Did you check the lazy-FPU-loading (TS bit)
aspect of your new code? To effectively check this, what I had to do
is to run on all of L0, L1, and L2, long runs of parallel "make" (make -j3) -
concurrently. Even code which doesn't do floating-point calculations uses
the FPU sometimes for its wide registers, so all these processes, guests
and guest's guests, compete for the FPU, exercising very well this code
path. If the TS bit is handled wrongly, some of these make processes
will die, when one of the compilations dies of SIGSEGV (forgetting to
set the FPU registers leads to some uninitialized pointers being used),
so it's quite easy to exercise this.

-- 
Nadav Har'El                        |         Monday, Mar 4 2013, 22 Adar 5773
nyh@math.technion.ac.il             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |"A witty saying proves nothing." --
http://nadav.harel.org.il           |Voltaire

  reply	other threads:[~2013-03-04 15:32 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-28  9:44 [PATCH] KVM: nVMX: Fix setting of CR0 and CR4 in guest mode Jan Kiszka
2013-03-04 13:22 ` Gleb Natapov
2013-03-04 14:09   ` Jan Kiszka
2013-03-04 14:15     ` Gleb Natapov
2013-03-04 14:25       ` Jan Kiszka
2013-03-04 15:30         ` Nadav Har'El [this message]
2013-03-04 16:01           ` Jan Kiszka
2013-03-04 17:56         ` Gleb Natapov
2013-03-04 18:08           ` Jan Kiszka
2013-03-04 18:39             ` Gleb Natapov
2013-03-04 19:23               ` Jan Kiszka
2013-03-04 19:33                 ` Gleb Natapov
2013-03-04 19:37                   ` Jan Kiszka
2013-03-04 20:00                     ` Gleb Natapov
2013-03-04 20:12                       ` Jan Kiszka
2013-03-04 20:24                         ` Gleb Natapov
2013-03-04 20:37                           ` Jan Kiszka
2013-03-04 21:00                             ` Gleb Natapov
2013-03-04 21:09                               ` Jan Kiszka
2013-03-05  6:25                                 ` Gleb Natapov

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=20130304153038.GA16279@fermat.math.technion.ac.il \
    --to=nyh@math.technion.ac.il \
    --cc=gleb@redhat.com \
    --cc=jan.kiszka@siemens.com \
    --cc=jun.nakajima@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@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