From: Avi Kivity <avi@qumranet.com>
To: linux-kernel@vger.kernel.org, kvm-devel@lists.sourceforge.net
Subject: [PATCH 51/54] KVM: MMU: Use mmu_set_spte() for real-mode shadows
Date: Tue, 1 Jan 2008 17:36:17 +0200 [thread overview]
Message-ID: <1199201780-14001-52-git-send-email-avi@qumranet.com> (raw)
In-Reply-To: <1199201780-14001-1-git-send-email-avi@qumranet.com>
In addition to removing some duplicated code, this also handles the unlikely
case of real-mode code updating a guest page table. This can happen when
one vcpu (in real mode) touches a second vcpu's (in protected mode) page
tables, or if a vcpu switches to real mode, touches page tables, and switches
back.
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
drivers/kvm/mmu.c | 41 ++++++++++-------------------------------
1 files changed, 10 insertions(+), 31 deletions(-)
diff --git a/drivers/kvm/mmu.c b/drivers/kvm/mmu.c
index b4dd726..ba71e8d 100644
--- a/drivers/kvm/mmu.c
+++ b/drivers/kvm/mmu.c
@@ -966,40 +966,23 @@ static void nonpaging_new_cr3(struct kvm_vcpu *vcpu)
{
}
-static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, struct page *page)
+static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, int write, gfn_t gfn)
{
int level = PT32E_ROOT_LEVEL;
hpa_t table_addr = vcpu->mmu.root_hpa;
+ int pt_write = 0;
for (; ; level--) {
u32 index = PT64_INDEX(v, level);
u64 *table;
- u64 pte;
ASSERT(VALID_PAGE(table_addr));
table = __va(table_addr);
if (level == 1) {
- int was_rmapped;
-
- pte = table[index];
- was_rmapped = is_rmap_pte(pte);
- if (is_shadow_present_pte(pte) && is_writeble_pte(pte)) {
- kvm_release_page_clean(page);
- return 0;
- }
- mark_page_dirty(vcpu->kvm, v >> PAGE_SHIFT);
- page_header_update_slot(vcpu->kvm, table,
- v >> PAGE_SHIFT);
- table[index] = page_to_phys(page)
- | PT_PRESENT_MASK | PT_WRITABLE_MASK
- | PT_USER_MASK;
- if (!was_rmapped)
- rmap_add(vcpu, &table[index], v >> PAGE_SHIFT);
- else
- kvm_release_page_clean(page);
-
- return 0;
+ mmu_set_spte(vcpu, &table[index], ACC_ALL, ACC_ALL,
+ 0, write, 1, &pt_write, gfn);
+ return pt_write || is_io_pte(table[index]);
}
if (table[index] == shadow_trap_nonpresent_pte) {
@@ -1013,7 +996,6 @@ static int nonpaging_map(struct kvm_vcpu *vcpu, gva_t v, struct page *page)
1, ACC_ALL, &table[index]);
if (!new_table) {
pgprintk("nonpaging_map: ENOMEM\n");
- kvm_release_page_clean(page);
return -ENOMEM;
}
@@ -1114,9 +1096,10 @@ static gpa_t nonpaging_gva_to_gpa(struct kvm_vcpu *vcpu, gva_t vaddr)
static int nonpaging_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
u32 error_code)
{
- struct page *page;
+ gfn_t gfn;
int r;
+ pgprintk("%s: gva %lx error %x\n", __FUNCTION__, gva, error_code);
r = mmu_topup_memory_caches(vcpu);
if (r)
return r;
@@ -1124,14 +1107,10 @@ static int nonpaging_page_fault(struct kvm_vcpu *vcpu, gva_t gva,
ASSERT(vcpu);
ASSERT(VALID_PAGE(vcpu->mmu.root_hpa));
- page = gfn_to_page(vcpu->kvm, gva >> PAGE_SHIFT);
-
- if (is_error_page(page)) {
- kvm_release_page_clean(page);
- return 1;
- }
+ gfn = gva >> PAGE_SHIFT;
- return nonpaging_map(vcpu, gva & PAGE_MASK, page);
+ return nonpaging_map(vcpu, gva & PAGE_MASK,
+ error_code & PFERR_WRITE_MASK, gfn);
}
static void nonpaging_free(struct kvm_vcpu *vcpu)
--
1.5.3.7
next prev parent reply other threads:[~2008-01-01 15:50 UTC|newest]
Thread overview: 57+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-01-01 15:35 [PATCH 00/54] KVM patch queue review for 2.6.25 merge window (part IV) Avi Kivity
2008-01-01 15:35 ` [PATCH 01/54] KVM: MMU: Remove gva_to_hpa() Avi Kivity
2008-01-01 15:35 ` [PATCH 02/54] KVM: Remove gpa_to_hpa() Avi Kivity
2008-01-01 15:35 ` [PATCH 03/54] KVM: MMU: Rename variables of type 'struct kvm_mmu_page *' Avi Kivity
2008-01-01 15:35 ` [PATCH 04/54] KVM: MMU: Rename 'release_page' Avi Kivity
2008-01-01 15:35 ` [PATCH 05/54] KVM: Disallow fork() and similar games when using a VM Avi Kivity
2008-01-01 15:35 ` [PATCH 06/54] KVM: Enhance guest cpuid management Avi Kivity
2008-01-01 15:35 ` [PATCH 07/54] KVM: VMX: Remove the secondary execute control dependency on irqchip Avi Kivity
2008-01-01 15:35 ` [PATCH 08/54] KVM: Portability: Move unalias_gfn to arch dependent file Avi Kivity
2008-01-01 15:35 ` [PATCH 09/54] KVM: x86 emulator: Make a distinction between repeat prefixes F3 and F2 Avi Kivity
2008-01-01 15:35 ` [PATCH 10/54] KVM: x86 emulator: address size and operand size overrides are sticky Avi Kivity
2008-01-01 15:35 ` [PATCH 11/54] KVM: Remove misleading check for mmio during event injection Avi Kivity
2008-01-01 15:35 ` [PATCH 12/54] KVM: MMU: mark pages that were inserted to the shadow pages table as accessed Avi Kivity
2008-01-01 15:35 ` [PATCH 13/54] KVM: x86 emulator: Rename 'cr2' to 'memop' Avi Kivity
2008-01-01 15:35 ` [PATCH 14/54] KVM: x86 emulator: cmps instruction Avi Kivity
2008-01-01 15:35 ` [PATCH 15/54] KVM: Add ifdef in irqchip struct for x86 only structures Avi Kivity
2008-01-01 15:35 ` [PATCH 16/54] KVM: x86 emulator: Move rep processing before instruction execution Avi Kivity
2008-01-01 15:35 ` [PATCH 17/54] KVM: x86 emulator: unify two switches Avi Kivity
2008-01-01 15:35 ` [PATCH 18/54] KVM: x86 emulator: unify four switch statements into two Avi Kivity
2008-01-01 15:35 ` [PATCH 19/54] KVM: Portability: Move KVM_INTERRUPT vcpu ioctl to x86.c Avi Kivity
2008-01-01 15:35 ` [PATCH 20/54] KVM: Correct kvm_init() error paths not freeing bad_pge Avi Kivity
2008-01-01 15:35 ` [PATCH 21/54] KVM: Export include/linux/kvm.h only if $ARCH actually supports KVM Avi Kivity
2008-01-01 16:22 ` Sam Ravnborg
2008-01-01 16:35 ` Avi Kivity
2008-01-01 15:35 ` [PATCH 22/54] KVM: SVM: Remove KVM specific defines for MSR_EFER Avi Kivity
2008-01-01 15:35 ` [PATCH 23/54] KVM: Replace kvm_lapic with kvm_vcpu in ioapic/lapic interface Avi Kivity
2008-01-01 15:35 ` [PATCH 24/54] KVM: Replace dest_Lowest_Prio and dest_Fixed with self-defined macros Avi Kivity
2008-01-01 15:35 ` [PATCH 25/54] KVM: Extend ioapic code to support iosapic Avi Kivity
2008-01-01 15:35 ` [PATCH 26/54] KVM: Portability: Move address types to their own header file Avi Kivity
2008-01-01 15:35 ` [PATCH 27/54] KVM: Portability: Move IO device definitions to its " Avi Kivity
2008-01-01 15:35 ` [PATCH 28/54] KVM: Portability: Stop including x86-specific headers in kvm_main.c Avi Kivity
2008-01-01 15:35 ` [PATCH 29/54] KVM: Portability: Create kvm_arch_vcpu_runnable() function Avi Kivity
2008-01-01 15:35 ` [PATCH 30/54] KVM: Convert KVM from ->nopage() to ->fault() Avi Kivity
2008-01-01 15:35 ` [PATCH 31/54] KVM: MMU: Remove unused prev_shadow_ent variable from fetch() Avi Kivity
2008-01-01 15:35 ` [PATCH 32/54] KVM: Generalize exception injection mechanism Avi Kivity
2008-01-01 15:35 ` [PATCH 33/54] KVM: Replace page fault injection by the generalized exception queue Avi Kivity
2008-01-01 15:36 ` [PATCH 34/54] KVM: Replace #GP " Avi Kivity
2008-01-01 15:36 ` [PATCH 35/54] KVM: Use generalized exception queue for injecting #UD Avi Kivity
2008-01-01 15:36 ` [PATCH 36/54] KVM: x86 emulator: fix eflags preparation for emulation Avi Kivity
2008-01-01 15:36 ` [PATCH 37/54] KVM: VMX: Avoid exit when setting cr8 if the local apic is in the kernel Avi Kivity
2008-01-01 15:36 ` [PATCH 38/54] KVM: SVM: Emulate read/write access to cr8 Avi Kivity
2008-01-01 15:36 ` [PATCH 39/54] KVM: x86 emulator: Fix stack instructions on 64-bit mode Avi Kivity
2008-01-01 15:36 ` [PATCH 40/54] KVM: SVM: Trap access to the cr8 register Avi Kivity
2008-01-01 15:36 ` [PATCH 41/54] KVM: MMU: Use cmpxchg for pte updates on walk_addr() Avi Kivity
2008-01-01 15:36 ` [PATCH 42/54] KVM: MMU: Simplify calculation of pte access Avi Kivity
2008-01-01 15:36 ` [PATCH 43/54] KVM: MMU: Set nx bit correctly on shadow ptes Avi Kivity
2008-01-01 15:36 ` [PATCH 44/54] KVM: MMU: Move pte access calculation into a helper function Avi Kivity
2008-01-01 15:36 ` [PATCH 45/54] KVM: MMU: Fix inherited permissions for emulated guest pte updates Avi Kivity
2008-01-01 15:36 ` [PATCH 46/54] KVM: MMU: No need to pick up nx bit from guest pte Avi Kivity
2008-01-01 15:36 ` [PATCH 47/54] KVM: MMU: Pass pte dirty flag to set_pte() instead of calculating it on-site Avi Kivity
2008-01-01 15:36 ` [PATCH 48/54] KVM: MMU: Remove walker argument to set_pte() Avi Kivity
2008-01-01 15:36 ` [PATCH 49/54] KVM: MMU: Move set_pte() into guest paging mode independent code Avi Kivity
2008-01-01 15:36 ` [PATCH 50/54] KVM: MMU: Adjust mmu_set_spte() debug code for gpte removal Avi Kivity
2008-01-01 15:36 ` Avi Kivity [this message]
2008-01-01 15:36 ` [PATCH 52/54] KVM: SVM: Exit to userspace if write to cr8 and not using in-kernel apic Avi Kivity
2008-01-01 15:36 ` [PATCH 53/54] KVM: MMU: Fix SMP shadow instantiation race Avi Kivity
2008-01-01 15:36 ` [PATCH 54/54] KVM: LAPIC: minor debugging compile fix 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=1199201780-14001-52-git-send-email-avi@qumranet.com \
--to=avi@qumranet.com \
--cc=kvm-devel@lists.sourceforge.net \
--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
all inboxes | Powered by JetHome®