From: Avi Kivity <avi@qumranet.com>
To: kvm-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org, Marcelo Tosatti <mtosatti@redhat.com>
Subject: [PATCH 22/35] x86: KVM guest: hypercall based pte updates and TLB flushes
Date: Thu, 3 Apr 2008 22:32:37 +0300 [thread overview]
Message-ID: <1207251170-5013-23-git-send-email-avi@qumranet.com> (raw)
In-Reply-To: <1207251170-5013-1-git-send-email-avi@qumranet.com>
From: Marcelo Tosatti <mtosatti@redhat.com>
Hypercall based pte updates are faster than faults, and also allow use
of the lazy MMU mode to batch operations.
Don't report the feature if two dimensional paging is enabled.
[avi:
- guest/host split
- fix 32-bit truncation issues
- adjust to mmu_op]
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Avi Kivity <avi@qumranet.com>
---
arch/x86/kernel/kvm.c | 137 +++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 137 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
index a8e36da..1bb6e97 100644
--- a/arch/x86/kernel/kvm.c
+++ b/arch/x86/kernel/kvm.c
@@ -25,6 +25,7 @@
#include <linux/kvm_para.h>
#include <linux/cpu.h>
#include <linux/mm.h>
+#include <linux/highmem.h>
/*
* No need for any "IO delay" on KVM
@@ -33,6 +34,122 @@ static void kvm_io_delay(void)
{
}
+static void kvm_mmu_op(void *buffer, unsigned len)
+{
+ int r;
+ unsigned long a1, a2;
+
+ do {
+ a1 = __pa(buffer);
+ a2 = 0; /* on i386 __pa() always returns <4G */
+ r = kvm_hypercall3(KVM_HC_MMU_OP, len, a1, a2);
+ buffer += r;
+ len -= r;
+ } while (len);
+}
+
+static void kvm_mmu_write(void *dest, u64 val)
+{
+ __u64 pte_phys;
+ struct kvm_mmu_op_write_pte wpte;
+
+#ifdef CONFIG_HIGHPTE
+ struct page *page;
+ unsigned long dst = (unsigned long) dest;
+
+ page = kmap_atomic_to_page(dest);
+ pte_phys = page_to_pfn(page);
+ pte_phys <<= PAGE_SHIFT;
+ pte_phys += (dst & ~(PAGE_MASK));
+#else
+ pte_phys = (unsigned long)__pa(dest);
+#endif
+ wpte.header.op = KVM_MMU_OP_WRITE_PTE;
+ wpte.pte_val = val;
+ wpte.pte_phys = pte_phys;
+
+ kvm_mmu_op(&wpte, sizeof wpte);
+}
+
+/*
+ * We only need to hook operations that are MMU writes. We hook these so that
+ * we can use lazy MMU mode to batch these operations. We could probably
+ * improve the performance of the host code if we used some of the information
+ * here to simplify processing of batched writes.
+ */
+static void kvm_set_pte(pte_t *ptep, pte_t pte)
+{
+ kvm_mmu_write(ptep, pte_val(pte));
+}
+
+static void kvm_set_pte_at(struct mm_struct *mm, unsigned long addr,
+ pte_t *ptep, pte_t pte)
+{
+ kvm_mmu_write(ptep, pte_val(pte));
+}
+
+static void kvm_set_pmd(pmd_t *pmdp, pmd_t pmd)
+{
+ kvm_mmu_write(pmdp, pmd_val(pmd));
+}
+
+#if PAGETABLE_LEVELS >= 3
+#ifdef CONFIG_X86_PAE
+static void kvm_set_pte_atomic(pte_t *ptep, pte_t pte)
+{
+ kvm_mmu_write(ptep, pte_val(pte));
+}
+
+static void kvm_set_pte_present(struct mm_struct *mm, unsigned long addr,
+ pte_t *ptep, pte_t pte)
+{
+ kvm_mmu_write(ptep, pte_val(pte));
+}
+
+static void kvm_pte_clear(struct mm_struct *mm,
+ unsigned long addr, pte_t *ptep)
+{
+ kvm_mmu_write(ptep, 0);
+}
+
+static void kvm_pmd_clear(pmd_t *pmdp)
+{
+ kvm_mmu_write(pmdp, 0);
+}
+#endif
+
+static void kvm_set_pud(pud_t *pudp, pud_t pud)
+{
+ kvm_mmu_write(pudp, pud_val(pud));
+}
+
+#if PAGETABLE_LEVELS == 4
+static void kvm_set_pgd(pgd_t *pgdp, pgd_t pgd)
+{
+ kvm_mmu_write(pgdp, pgd_val(pgd));
+}
+#endif
+#endif /* PAGETABLE_LEVELS >= 3 */
+
+static void kvm_flush_tlb(void)
+{
+ struct kvm_mmu_op_flush_tlb ftlb = {
+ .header.op = KVM_MMU_OP_FLUSH_TLB,
+ };
+
+ kvm_mmu_op(&ftlb, sizeof ftlb);
+}
+
+static void kvm_release_pt(u32 pfn)
+{
+ struct kvm_mmu_op_release_pt rpt = {
+ .header.op = KVM_MMU_OP_RELEASE_PT,
+ .pt_phys = (u64)pfn << PAGE_SHIFT,
+ };
+
+ kvm_mmu_op(&rpt, sizeof rpt);
+}
+
static void paravirt_ops_setup(void)
{
pv_info.name = "KVM";
@@ -41,6 +158,26 @@ static void paravirt_ops_setup(void)
if (kvm_para_has_feature(KVM_FEATURE_NOP_IO_DELAY))
pv_cpu_ops.io_delay = kvm_io_delay;
+ if (kvm_para_has_feature(KVM_FEATURE_MMU_OP)) {
+ pv_mmu_ops.set_pte = kvm_set_pte;
+ pv_mmu_ops.set_pte_at = kvm_set_pte_at;
+ pv_mmu_ops.set_pmd = kvm_set_pmd;
+#if PAGETABLE_LEVELS >= 3
+#ifdef CONFIG_X86_PAE
+ pv_mmu_ops.set_pte_atomic = kvm_set_pte_atomic;
+ pv_mmu_ops.set_pte_present = kvm_set_pte_present;
+ pv_mmu_ops.pte_clear = kvm_pte_clear;
+ pv_mmu_ops.pmd_clear = kvm_pmd_clear;
+#endif
+ pv_mmu_ops.set_pud = kvm_set_pud;
+#if PAGETABLE_LEVELS == 4
+ pv_mmu_ops.set_pgd = kvm_set_pgd;
+#endif
+#endif
+ pv_mmu_ops.flush_tlb_user = kvm_flush_tlb;
+ pv_mmu_ops.release_pt = kvm_release_pt;
+ pv_mmu_ops.release_pd = kvm_release_pt;
+ }
}
void __init kvm_guest_init(void)
--
1.5.4.5
next prev parent reply other threads:[~2008-04-03 19:39 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-04-03 19:32 [PATCH 00/35] KVM updates for the 2.6.26 merge window (part II) Avi Kivity
2008-04-03 19:32 ` [PATCH 01/35] KVM: Use x86's segment descriptor struct instead of private definition Avi Kivity
2008-04-03 19:32 ` [PATCH 02/35] KVM: Add stat counter for hypercalls Avi Kivity
2008-04-03 19:32 ` [PATCH 03/35] KVM: x86 emulator: fix sparse warnings in x86_emulate.c Avi Kivity
2008-04-03 19:32 ` [PATCH 04/35] KVM: SVM: make iopm_base static Avi Kivity
2008-04-03 19:32 ` [PATCH 05/35] KVM: sparse fixes for kvm/x86.c Avi Kivity
2008-04-03 19:32 ` [PATCH 06/35] KVM: Implement dummy values for MSR_PERF_STATUS Avi Kivity
2008-04-03 19:32 ` [PATCH 07/35] KVM: MMU: ignore zapped root pagetables Avi Kivity
2008-04-03 19:32 ` [PATCH 08/35] KVM: MMU: large page support Avi Kivity
2008-04-03 19:32 ` [PATCH 09/35] KVM: Prefix control register accessors with kvm_ to avoid namespace pollution Avi Kivity
2008-04-03 19:32 ` [PATCH 10/35] KVM: Use kzalloc to avoid allocating kvm_regs from kernel stack Avi Kivity
2008-04-03 19:32 ` [PATCH 11/35] KVM: detect if VCPU triple faults Avi Kivity
2008-04-03 19:32 ` [PATCH 12/35] KVM: replace remaining __FUNCTION__ occurances Avi Kivity
2008-04-03 19:32 ` [PATCH 13/35] KVM: VMX: Don't adjust tsc offset forward Avi Kivity
2008-04-03 19:32 ` [PATCH 14/35] KVM: Remove pointless desc_ptr #ifdef Avi Kivity
2008-04-03 19:32 ` [PATCH 15/35] KVM: In kernel PIT model Avi Kivity
2008-04-03 19:32 ` [PATCH 16/35] KVM: Add save/restore supporting of in kernel PIT Avi Kivity
2008-04-03 19:32 ` [PATCH 17/35] KVM: Add reset support for " Avi Kivity
2008-04-03 19:32 ` [PATCH 18/35] KVM: add basic paravirt support Avi Kivity
2008-04-03 19:32 ` [PATCH 19/35] x86: KVM guest: " Avi Kivity
2008-04-03 19:32 ` [PATCH 20/35] KVM: Provide unlocked version of emulator_write_phys() Avi Kivity
2008-04-03 19:32 ` [PATCH 21/35] KVM: MMU: hypercall based pte updates and TLB flushes Avi Kivity
2008-04-03 19:32 ` Avi Kivity [this message]
2008-04-03 19:32 ` [PATCH 23/35] x86: KVM guest: hypercall batching Avi Kivity
2008-04-03 19:32 ` [PATCH 24/35] x86: allow machine_crash_shutdown to be replaced Avi Kivity
2008-04-03 19:32 ` [PATCH 25/35] x86: make native_machine_shutdown non-static Avi Kivity
2008-04-03 19:32 ` [PATCH 26/35] x86: KVM guest: disable clock before rebooting Avi Kivity
2008-04-03 19:32 ` [PATCH 27/35] KVM: kvm.h: __user requires compiler.h Avi Kivity
2008-04-03 19:32 ` [PATCH 28/35] KVM: MMU: Set the accessed bit on non-speculative shadow ptes Avi Kivity
2008-04-03 19:32 ` [PATCH 29/35] KVM: Move some x86 specific constants and structures to include/asm-x86 Avi Kivity
2008-04-03 19:32 ` [PATCH 30/35] KVM: MMU: fix dirty bit setting when removing write permissions Avi Kivity
2008-04-03 19:32 ` [PATCH 31/35] KVM: MMU: Introduce and use spte_to_page() Avi Kivity
2008-04-03 19:32 ` [PATCH 32/35] KVM: no longer EXPERIMENTAL Avi Kivity
2008-04-03 19:32 ` [PATCH 33/35] KVM: VMX: Add module option to disable flexpriority Avi Kivity
2008-04-03 19:32 ` [PATCH 34/35] KVM: x86: add functions to get the cpl of vcpu Avi Kivity
2008-04-03 19:32 ` [PATCH 35/35] KVM: x86: hardware task switching support 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=1207251170-5013-23-git-send-email-avi@qumranet.com \
--to=avi@qumranet.com \
--cc=kvm-devel@lists.sourceforge.net \
--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®