All of lore.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Avi Kivity <avi@redhat.com>
Cc: kvm@vger.kernel.org
Subject: Re: [PATCH 2/2] KVM: Make CR4 reloads also reload CR3 if paging is enabled
Date: Mon, 25 May 2009 08:58:42 -0300	[thread overview]
Message-ID: <20090525115842.GA3417@amt.cnet> (raw)
In-Reply-To: <1243241244-25953-3-git-send-email-avi@redhat.com>

On Mon, May 25, 2009 at 11:47:24AM +0300, Avi Kivity wrote:
> The processor is documented to reload the PDPTRs while in PAE mode if any
> of the CR4 bits PSE, PGE, or PAE change.  Linux relies on this
> behaviour when zapping the low mappings of PAE kernels during boot.
> 
> The code already handled changes to CR4.PAE; augment it to also notice changes
> to PSE and PGE.
> 
> This triggered while booting an F11 PAE kernel; the futex initialization code
> runs before any CR3 reloads and writes to a NULL pointer; the futex subsystem
> ended up uninitialized, killing PI futexes and pulseaudio which uses them.

One comment regarding set_cr0. Section 8.1 of the TLB doc says:

* The processor does not maintain a PDP cache as described in
Section 4. The processor always caches information from the four
page-directory-pointer-table entries. These entries are not cached at
the time of address translation. Instead, they are always cached as part
of the execution of the following instructions:

* A MOV to CR0 that modifies CR0.PG and that occurs with IA32_EFER.LMA = 0
and CR4.PAE = 1.

However kvm_set_cr0 only caches the PDPTRs if CR0.PG changed from 0->1.
Can't see a problem there though.

Also, the checks in kvm_arch_vcpu_ioctl_set_sregs should probably be unified
with kvm_set_crX, to avoid future mistakes.

Otherwise, ACK.

> 
> Signed-off-by: Avi Kivity <avi@redhat.com>
> ---
>  arch/x86/kvm/x86.c |    6 +++++-
>  1 files changed, 5 insertions(+), 1 deletions(-)
> 
> diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
> index 8b5d1e5..6d44dd5 100644
> --- a/arch/x86/kvm/x86.c
> +++ b/arch/x86/kvm/x86.c
> @@ -341,6 +341,9 @@ EXPORT_SYMBOL_GPL(kvm_lmsw);
>  
>  void kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
>  {
> +	unsigned long old_cr4 = vcpu->arch.cr4;
> +	unsigned long pdptr_bits = X86_CR4_PGE | X86_CR4_PSE | X86_CR4_PAE;
> +
>  	if (cr4 & CR4_RESERVED_BITS) {
>  		printk(KERN_DEBUG "set_cr4: #GP, reserved bits\n");
>  		kvm_inject_gp(vcpu, 0);
> @@ -354,7 +357,8 @@ void kvm_set_cr4(struct kvm_vcpu *vcpu, unsigned long cr4)
>  			kvm_inject_gp(vcpu, 0);
>  			return;
>  		}
> -	} else if (is_paging(vcpu) && !is_pae(vcpu) && (cr4 & X86_CR4_PAE)
> +	} else if (is_paging(vcpu) && (cr4 & X86_CR4_PAE)
> +		   && ((cr4 ^ old_cr4) & pdptr_bits)
>  		   && !load_pdptrs(vcpu, vcpu->arch.cr3)) {
>  		printk(KERN_DEBUG "set_cr4: #GP, pdptrs reserved bits\n");
>  		kvm_inject_gp(vcpu, 0);
> -- 
> 1.6.0.6

  reply	other threads:[~2009-05-25 15:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-25  8:47 [PATCH 0/2] KVM PDPTR reload fixes review Avi Kivity
2009-05-25  8:47 ` [PATCH 1/2] KVM: Make paravirt tlb flush also reload PAE PDPTEs Avi Kivity
2009-05-25 11:59   ` Marcelo Tosatti
2009-05-25 15:09     ` Avi Kivity
2009-05-25  8:47 ` [PATCH 2/2] KVM: Make CR4 reloads also reload CR3 if paging is enabled Avi Kivity
2009-05-25 11:58   ` Marcelo Tosatti [this message]
2009-05-25 15:08     ` 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=20090525115842.GA3417@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=avi@redhat.com \
    --cc=kvm@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.