public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Marcelo Tosatti <mtosatti@redhat.com>
To: Joerg Roedel <joerg.roedel@amd.com>
Cc: Avi Kivity <avi@redhat.com>, Alexander Graf <agraf@suse.de>,
	joro@8bytes.org, kvm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 22/27] KVM: MMU: Refactor mmu_alloc_roots function
Date: Tue, 7 Sep 2010 17:39:52 -0300	[thread overview]
Message-ID: <20100907203952.GA14489@amt.cnet> (raw)
In-Reply-To: <1283788566-29186-23-git-send-email-joerg.roedel@amd.com>

On Mon, Sep 06, 2010 at 05:56:01PM +0200, Joerg Roedel wrote:
> This patch factors out the direct-mapping paths of the
> mmu_alloc_roots function into a seperate function. This
> makes it a lot easier to avoid all the unnecessary checks
> done in the shadow path which may break when running direct.
> In fact, this patch already fixes a problem when running PAE
> guests on a PAE shadow page table.
> 
> Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
> ---
>  arch/x86/kvm/mmu.c |   82 ++++++++++++++++++++++++++++++++++++++--------------
>  1 files changed, 60 insertions(+), 22 deletions(-)
> 
> diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
> index 3663d1c..e7e5527 100644
> --- a/arch/x86/kvm/mmu.c
> +++ b/arch/x86/kvm/mmu.c

> +
> +static int mmu_alloc_shadow_roots(struct kvm_vcpu *vcpu)
>  {
>  	int i;
>  	gfn_t root_gfn;
>  	struct kvm_mmu_page *sp;
> -	int direct = 0;
>  	u64 pdptr;
>  
>  	root_gfn = vcpu->arch.mmu.get_cr3(vcpu) >> PAGE_SHIFT;
>  
> -	if (vcpu->arch.mmu.shadow_root_level == PT64_ROOT_LEVEL) {
> +	if (mmu_check_root(vcpu, root_gfn))
> +		return 1;
> +
> +	/*
> +	 * Do we shadow a long mode page table? If so we need to
> +	 * write-protect the guests page table root.
> +	 */
> +	if (vcpu->arch.mmu.root_level == PT64_ROOT_LEVEL) {
>  		hpa_t root = vcpu->arch.mmu.root_hpa;
>  
>  		ASSERT(!VALID_PAGE(root));
> -		if (mmu_check_root(vcpu, root_gfn))
> -			return 1;
> -		if (vcpu->arch.mmu.direct_map) {
> -			direct = 1;
> -			root_gfn = 0;
> -		}
> +
>  		spin_lock(&vcpu->kvm->mmu_lock);
>  		kvm_mmu_free_some_pages(vcpu);
> -		sp = kvm_mmu_get_page(vcpu, root_gfn, 0,
> -				      PT64_ROOT_LEVEL, direct,
> -				      ACC_ALL, NULL);
> +		sp = kvm_mmu_get_page(vcpu, root_gfn, 0, PT64_ROOT_LEVEL,
> +				      0, ACC_ALL, NULL);
>  		root = __pa(sp->spt);
>  		++sp->root_count;
>  		spin_unlock(&vcpu->kvm->mmu_lock);
>  		vcpu->arch.mmu.root_hpa = root;
>  		return 0;
>  	}
> -	direct = !is_paging(vcpu);
> -
> -	if (mmu_check_root(vcpu, root_gfn))
> -		return 1;
>  
> +	/*
> +	 * We shadow a 32 bit page table. This may be a legacy 2-level
> +	 * or a PAE 3-level page table.
> +	 */
>  	for (i = 0; i < 4; ++i) {
>  		hpa_t root = vcpu->arch.mmu.pae_root[i];
>  
> @@ -2406,16 +2441,11 @@ static int mmu_alloc_roots(struct kvm_vcpu *vcpu)
>  			root_gfn = pdptr >> PAGE_SHIFT;
>  			if (mmu_check_root(vcpu, root_gfn))
>  				return 1;
> -		} else if (vcpu->arch.mmu.root_level == 0)
> -			root_gfn = 0;
> -		if (vcpu->arch.mmu.direct_map) {
> -			direct = 1;
> -			root_gfn = i << 30;
>  		}
>  		spin_lock(&vcpu->kvm->mmu_lock);
>  		kvm_mmu_free_some_pages(vcpu);
>  		sp = kvm_mmu_get_page(vcpu, root_gfn, i << 30,
> -				      PT32_ROOT_LEVEL, direct,
> +				      PT32_ROOT_LEVEL, 0,
>  				      ACC_ALL, NULL);

Should not write protect the gfn for nonpaging mode.


  reply	other threads:[~2010-09-07 21:34 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-06 15:55 [PATCH 0/27] Nested Paging Virtualization for KVM v3 (now with fixed Cc-List) Joerg Roedel
2010-09-06 15:55 ` [PATCH 01/27] KVM: MMU: Check for root_level instead of long mode Joerg Roedel
2010-09-06 15:55 ` [PATCH 02/27] KVM: MMU: Make tdp_enabled a mmu-context parameter Joerg Roedel
2010-09-06 15:55 ` [PATCH 03/27] KVM: MMU: Make set_cr3 a function pointer in kvm_mmu Joerg Roedel
2010-09-06 15:55 ` [PATCH 04/27] KVM: X86: Introduce a tdp_set_cr3 function Joerg Roedel
2010-09-06 15:55 ` [PATCH 05/27] KVM: MMU: Introduce get_cr3 function pointer Joerg Roedel
2010-09-06 15:55 ` [PATCH 06/27] KVM: MMU: Introduce inject_page_fault " Joerg Roedel
2010-09-06 15:55 ` [PATCH 07/27] KVM: MMU: Introduce kvm_init_shadow_mmu helper function Joerg Roedel
2010-09-06 15:55 ` [PATCH 08/27] KVM: MMU: Let is_rsvd_bits_set take mmu context instead of vcpu Joerg Roedel
2010-09-06 15:55 ` [PATCH 09/27] KVM: MMU: Introduce generic walk_addr function Joerg Roedel
2010-09-06 15:55 ` [PATCH 10/27] KVM: MMU: Add infrastructure for two-level page walker Joerg Roedel
2010-09-06 18:05   ` Avi Kivity
2010-09-08  9:20     ` Roedel, Joerg
2010-09-06 15:55 ` [PATCH 11/27] KVM: X86: Introduce pointer to mmu context used for gva_to_gpa Joerg Roedel
2010-09-06 15:55 ` [PATCH 12/27] KVM: MMU: Implement nested gva_to_gpa functions Joerg Roedel
2010-09-06 15:55 ` [PATCH 13/27] KVM: X86: Add kvm_read_guest_page_tdp function Joerg Roedel
2010-09-06 15:55 ` [PATCH 14/27] KVM: MMU: Make walk_addr_generic capable for two-level walking Joerg Roedel
2010-09-07 17:48   ` Marcelo Tosatti
2010-09-08  9:12     ` Roedel, Joerg
2010-09-06 15:55 ` [PATCH 15/27] KVM: MMU: Introduce kvm_read_guest_page_x86() Joerg Roedel
2010-09-06 15:55 ` [PATCH 16/27] KVM: MMU: Introduce init_kvm_nested_mmu() Joerg Roedel
2010-09-06 15:55 ` [PATCH 17/27] KVM: MMU: Track page fault data in struct vcpu Joerg Roedel
2010-09-06 18:17   ` Avi Kivity
2010-09-06 15:55 ` [PATCH 18/27] KVM: MMU: Propagate the right fault back to the guest after gva_to_gpa Joerg Roedel
2010-09-06 15:55 ` [PATCH 19/27] KVM: X86: Propagate fetch faults Joerg Roedel
2010-09-07 18:43   ` Marcelo Tosatti
2010-09-08  9:18     ` Roedel, Joerg
2010-09-06 15:55 ` [PATCH 20/27] KVM: MMU: Add kvm_mmu parameter to load_pdptrs function Joerg Roedel
2010-09-06 15:56 ` [PATCH 21/27] KVM: MMU: Introduce kvm_pdptr_read_mmu Joerg Roedel
2010-09-06 15:56 ` [PATCH 22/27] KVM: MMU: Refactor mmu_alloc_roots function Joerg Roedel
2010-09-07 20:39   ` Marcelo Tosatti [this message]
2010-09-08  7:16     ` Avi Kivity
2010-09-08  9:16       ` Roedel, Joerg
2010-09-06 15:56 ` [PATCH 23/27] KVM: MMU: Allow long mode shadows for legacy page tables Joerg Roedel
2010-09-06 15:56 ` [PATCH 24/27] KVM: SVM: Implement MMU helper functions for Nested Nested Paging Joerg Roedel
2010-09-06 15:56 ` [PATCH 25/27] KVM: SVM: Initialize Nested Nested MMU context on VMRUN Joerg Roedel
2010-09-06 15:56 ` [PATCH 26/27] KVM: SVM: Expect two more candiates for exit_int_info Joerg Roedel
2010-09-06 15:56 ` [PATCH 27/27] KVM: SVM: Report Nested Paging support to userspace Joerg Roedel
2010-09-06 18:37 ` [PATCH 0/27] Nested Paging Virtualization for KVM v3 (now with fixed Cc-List) Avi Kivity
2010-09-07 16:35   ` Roedel, Joerg
  -- strict thread matches above, loose matches on Subject: below --
2010-09-06 15:01 [PATCH 0/27] Nested Paging Virtualization for KVM v3 Joerg Roedel
2010-09-06 15:01 ` [PATCH 22/27] KVM: MMU: Refactor mmu_alloc_roots function 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=20100907203952.GA14489@amt.cnet \
    --to=mtosatti@redhat.com \
    --cc=agraf@suse.de \
    --cc=avi@redhat.com \
    --cc=joerg.roedel@amd.com \
    --cc=joro@8bytes.org \
    --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