Regards, Anthony Liguori
Subject: [PATCH][PARAVIRT] Eliminate unnecessary CR3 read in TLB flush This patch eliminates the CR3 read (which would cause a VM exit) in the TLB flush path. The patch is based on Ingo Molnar's paravirt series. Signed-off-by: Anthony Liguori <aliguori@xxxxxxxxxx> Index: kvm/arch/i386/kernel/kvm.c =================================================================== --- kvm.orig/arch/i386/kernel/kvm.c 2007-05-30 09:13:48.000000000 -0500 +++ kvm/arch/i386/kernel/kvm.c 2007-05-30 09:14:24.000000000 -0500 @@ -24,11 +24,35 @@ #include <linux/kernel.h> #include <linux/kvm_para.h> #include <linux/cpu.h> +#include <linux/mm.h> +#include <asm/processor.h> +#include <asm/tlbflush.h> static DEFINE_PER_CPU(struct kvm_vcpu_para_state, para_state); extern unsigned char hypercall_addr[4]; /* + * Avoid the VM exit upon cr3 load by using the cached + * ->active_mm->pgd value: + */ +static void kvm_flush_tlb_user(void) +{ + write_cr3(__pa(current->active_mm->pgd)); +} + +/* + * Avoid VM exit for cr3 read by calling into kvm_flush_tlb_user + */ +static fastcall void kvm_flush_tlb_kernel(void) +{ + unsigned long orig_cr4 = read_cr4(); + + write_cr4(orig_cr4 & ~X86_CR4_PGE); + kvm_flush_tlb_user(); + write_cr4(orig_cr4); +} + +/* * No need for any "IO delay" on KVM */ static void kvm_io_delay(void) @@ -38,6 +62,8 @@ static void kvm_guest_setup(void) { paravirt_ops.name = "KVM"; + paravirt_ops.flush_tlb_user = kvm_flush_tlb_user; + paravirt_ops.flush_tlb_kernel = kvm_flush_tlb_kernel; paravirt_ops.io_delay = kvm_io_delay; paravirt_ops.paravirt_enabled = 1; }
_______________________________________________ Virtualization mailing list Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linux-foundation.org/mailman/listinfo/virtualization