From: Joerg Roedel <joerg.roedel@amd.com>
To: Avi Kivity <avi@redhat.com>, Marcelo Tosatti <mtosatti@redhat.com>
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Joerg Roedel <joerg.roedel@amd.com>
Subject: [PATCH 02/29] KVM: MMU: Make tdp_enabled a mmu-context parameter
Date: Fri, 10 Sep 2010 17:30:39 +0200 [thread overview]
Message-ID: <1284132667-18620-3-git-send-email-joerg.roedel@amd.com> (raw)
In-Reply-To: <1284132667-18620-1-git-send-email-joerg.roedel@amd.com>
This patch changes the tdp_enabled flag from its global
meaning to the mmu-context and renames it to direct_map
there. This is necessary for Nested SVM with emulation of
Nested Paging where we need an extra MMU context to shadow
the Nested Nested Page Table.
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
---
arch/x86/include/asm/kvm_host.h | 1 +
arch/x86/kvm/mmu.c | 22 ++++++++++++++--------
2 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
index 9b30285..53cdf39 100644
--- a/arch/x86/include/asm/kvm_host.h
+++ b/arch/x86/include/asm/kvm_host.h
@@ -249,6 +249,7 @@ struct kvm_mmu {
int root_level;
int shadow_root_level;
union kvm_mmu_page_role base_role;
+ bool direct_map;
u64 *pae_root;
u64 rsvd_bits_mask[2][4];
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c
index b2136f9..5c28e97 100644
--- a/arch/x86/kvm/mmu.c
+++ b/arch/x86/kvm/mmu.c
@@ -1448,7 +1448,8 @@ static struct kvm_mmu_page *kvm_mmu_get_page(struct kvm_vcpu *vcpu,
if (role.direct)
role.cr4_pae = 0;
role.access = access;
- if (!tdp_enabled && vcpu->arch.mmu.root_level <= PT32_ROOT_LEVEL) {
+ if (!vcpu->arch.mmu.direct_map
+ && vcpu->arch.mmu.root_level <= PT32_ROOT_LEVEL) {
quadrant = gaddr >> (PAGE_SHIFT + (PT64_PT_BITS * level));
quadrant &= (1 << ((PT32_PT_BITS - PT64_PT_BITS) * level)) - 1;
role.quadrant = quadrant;
@@ -1973,7 +1974,7 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
spte |= shadow_user_mask;
if (level > PT_PAGE_TABLE_LEVEL)
spte |= PT_PAGE_SIZE_MASK;
- if (tdp_enabled)
+ if (vcpu->arch.mmu.direct_map)
spte |= kvm_x86_ops->get_mt_mask(vcpu, gfn,
kvm_is_mmio_pfn(pfn));
@@ -1983,8 +1984,8 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
spte |= (u64)pfn << PAGE_SHIFT;
if ((pte_access & ACC_WRITE_MASK)
- || (!tdp_enabled && write_fault && !is_write_protection(vcpu)
- && !user_fault)) {
+ || (!vcpu->arch.mmu.direct_map && write_fault
+ && !is_write_protection(vcpu) && !user_fault)) {
if (level > PT_PAGE_TABLE_LEVEL &&
has_wrprotected_page(vcpu->kvm, gfn, level)) {
@@ -1995,7 +1996,8 @@ static int set_spte(struct kvm_vcpu *vcpu, u64 *sptep,
spte |= PT_WRITABLE_MASK;
- if (!tdp_enabled && !(pte_access & ACC_WRITE_MASK))
+ if (!vcpu->arch.mmu.direct_map
+ && !(pte_access & ACC_WRITE_MASK))
spte &= ~PT_USER_MASK;
/*
@@ -2371,7 +2373,7 @@ static int mmu_alloc_roots(struct kvm_vcpu *vcpu)
ASSERT(!VALID_PAGE(root));
if (mmu_check_root(vcpu, root_gfn))
return 1;
- if (tdp_enabled) {
+ if (vcpu->arch.mmu.direct_map) {
direct = 1;
root_gfn = 0;
}
@@ -2406,7 +2408,7 @@ static int mmu_alloc_roots(struct kvm_vcpu *vcpu)
return 1;
} else if (vcpu->arch.mmu.root_level == 0)
root_gfn = 0;
- if (tdp_enabled) {
+ if (vcpu->arch.mmu.direct_map) {
direct = 1;
root_gfn = i << 30;
}
@@ -2544,6 +2546,7 @@ static int nonpaging_init_context(struct kvm_vcpu *vcpu)
context->root_level = 0;
context->shadow_root_level = PT32E_ROOT_LEVEL;
context->root_hpa = INVALID_PAGE;
+ context->direct_map = true;
return 0;
}
@@ -2663,6 +2666,7 @@ static int paging64_init_context_common(struct kvm_vcpu *vcpu, int level)
context->root_level = level;
context->shadow_root_level = level;
context->root_hpa = INVALID_PAGE;
+ context->direct_map = false;
return 0;
}
@@ -2687,6 +2691,7 @@ static int paging32_init_context(struct kvm_vcpu *vcpu)
context->root_level = PT32_ROOT_LEVEL;
context->shadow_root_level = PT32E_ROOT_LEVEL;
context->root_hpa = INVALID_PAGE;
+ context->direct_map = false;
return 0;
}
@@ -2708,6 +2713,7 @@ static int init_kvm_tdp_mmu(struct kvm_vcpu *vcpu)
context->invlpg = nonpaging_invlpg;
context->shadow_root_level = kvm_x86_ops->get_tdp_level();
context->root_hpa = INVALID_PAGE;
+ context->direct_map = true;
if (!is_paging(vcpu)) {
context->gva_to_gpa = nonpaging_gva_to_gpa;
@@ -3060,7 +3066,7 @@ int kvm_mmu_unprotect_page_virt(struct kvm_vcpu *vcpu, gva_t gva)
gpa_t gpa;
int r;
- if (tdp_enabled)
+ if (vcpu->arch.mmu.direct_map)
return 0;
gpa = kvm_mmu_gva_to_gpa_read(vcpu, gva, NULL);
--
1.7.0.4
next prev parent reply other threads:[~2010-09-10 15:32 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-10 15:30 [PATCH 0/29] Nested Paging Virtualization for KVM v4 Joerg Roedel
2010-09-10 15:30 ` [PATCH 01/29] KVM: MMU: Check for root_level instead of long mode Joerg Roedel
2010-09-10 15:30 ` Joerg Roedel [this message]
2010-09-10 15:30 ` [PATCH 03/29] KVM: MMU: Make set_cr3 a function pointer in kvm_mmu Joerg Roedel
2010-09-10 15:30 ` [PATCH 04/29] KVM: X86: Introduce a tdp_set_cr3 function Joerg Roedel
2010-09-10 15:30 ` [PATCH 05/29] KVM: MMU: Introduce get_cr3 function pointer Joerg Roedel
2010-09-10 15:30 ` [PATCH 06/29] KVM: MMU: Introduce inject_page_fault " Joerg Roedel
2010-09-10 15:30 ` [PATCH 07/29] KVM: MMU: Introduce kvm_init_shadow_mmu helper function Joerg Roedel
2010-09-10 15:30 ` [PATCH 08/29] KVM: MMU: Let is_rsvd_bits_set take mmu context instead of vcpu Joerg Roedel
2010-09-10 15:30 ` [PATCH 09/29] KVM: MMU: Track page fault data in struct vcpu Joerg Roedel
2010-09-10 15:30 ` [PATCH 10/29] KVM: MMU: Introduce generic walk_addr function Joerg Roedel
2010-09-10 15:30 ` [PATCH 11/29] KVM: MMU: Add infrastructure for two-level page walker Joerg Roedel
2010-09-10 15:30 ` [PATCH 12/29] KVM: X86: Introduce pointer to mmu context used for gva_to_gpa Joerg Roedel
2010-09-10 15:30 ` [PATCH 13/29] KVM: MMU: Implement nested gva_to_gpa functions Joerg Roedel
2010-09-10 15:30 ` [PATCH 14/29] KVM: X86: Add kvm_read_guest_page_mmu function Joerg Roedel
2010-09-10 15:30 ` [PATCH 15/29] KVM: MMU: Make walk_addr_generic capable for two-level walking Joerg Roedel
2010-09-10 15:30 ` [PATCH 16/29] KVM: MMU: Introduce kvm_read_nested_guest_page() Joerg Roedel
2010-09-10 15:30 ` [PATCH 17/29] KVM: MMU: Introduce init_kvm_nested_mmu() Joerg Roedel
2010-09-10 15:30 ` [PATCH 18/29] KVM: MMU: Propagate the right fault back to the guest after gva_to_gpa Joerg Roedel
2010-09-12 8:50 ` Avi Kivity
2010-09-10 15:30 ` [PATCH 19/29] KVM: X86: Propagate fetch faults Joerg Roedel
2010-09-10 15:30 ` [PATCH 20/29] KVM: MMU: Add kvm_mmu parameter to load_pdptrs function Joerg Roedel
2010-09-10 15:30 ` [PATCH 21/29] KVM: MMU: Introduce kvm_pdptr_read_mmu Joerg Roedel
2010-09-10 15:30 ` [PATCH 22/29] KVM: MMU: Refactor mmu_alloc_roots function Joerg Roedel
2010-09-10 15:31 ` [PATCH 23/29] KVM: MMU: Allow long mode shadows for legacy page tables Joerg Roedel
2010-09-10 15:31 ` [PATCH 24/29] KVM: MMU: Track NX state in struct kvm_mmu Joerg Roedel
2010-09-12 8:06 ` Avi Kivity
2010-09-10 15:31 ` [PATCH 25/29] KVM: SVM: Implement MMU helper functions for Nested Nested Paging Joerg Roedel
2010-09-10 15:31 ` [PATCH 26/29] KVM: SVM: Initialize Nested Nested MMU context on VMRUN Joerg Roedel
2010-09-10 15:31 ` [PATCH 27/29] KVM: SVM: Expect two more candiates for exit_int_info Joerg Roedel
2010-09-10 15:31 ` [PATCH 28/29] KVM: SVM: Report Nested Paging support to userspace Joerg Roedel
2010-09-10 15:31 ` [PATCH 29/29] KVM: X86: Report SVM bit to userspace only when supported Joerg Roedel
2010-09-12 8:56 ` [PATCH 0/29] Nested Paging Virtualization for KVM v4 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=1284132667-18620-3-git-send-email-joerg.roedel@amd.com \
--to=joerg.roedel@amd.com \
--cc=avi@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@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
all inboxes | Powered by JetHome®