From: jes@sgi.com Date: Wed, 25 Feb 2009 16:38:55 +0000 Subject: [patch 4/4] Drop in SN2 replacement of fast path ITC emulation fault handler Message-Id: <20090225164431.133179932@sgi.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable To: kvm-ia64@vger.kernel.org Copy in SN2 RTC based ITC emulation for fast exit. The two versions have the same size, so a dropin is simpler than patching the branch instruction to hit the SN2 version. Signed-off-by: Jes Sorensen --- arch/ia64/include/asm/kvm_host.h | 2 ++ arch/ia64/kvm/kvm-ia64.c | 32 +++++++++++++++++++++++++++++++- arch/ia64/kvm/optvfault.S | 30 ++++++++++++++++++++++++++++++ arch/ia64/kvm/vmm.c | 12 ++++++++---- 4 files changed, 71 insertions(+), 5 deletions(-) Index: linux-2.6.git/arch/ia64/include/asm/kvm_host.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D--- linux-2.6.git.orig/arch/ia64/include/asm/kvm_ho= st.h +++ linux-2.6.git/arch/ia64/include/asm/kvm_host.h @@ -599,6 +599,8 @@ kvm_vmm_entry *vmm_entry; kvm_tramp_entry *tramp_entry; unsigned long vmm_ivt; + unsigned long patch_mov_ar; + unsigned long patch_mov_ar_sn2; }; =20 int kvm_highest_pending_irq(struct kvm_vcpu *vcpu); Index: linux-2.6.git/arch/ia64/kvm/kvm-ia64.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D--- linux-2.6.git.orig/arch/ia64/kvm/kvm-ia64.c +++ linux-2.6.git/arch/ia64/kvm/kvm-ia64.c @@ -1591,8 +1591,37 @@ return 0; } =20 + +/* + * On SN2, the ITC isn't stable, so copy in fast path code to use the + * SN2 RTC, replacing the ITC based default verion. + */ +static void kvm_patch_vmm(struct kvm_vmm_info *vmm_info, + struct module *module) +{ + unsigned long new_ar, new_ar_sn2; + unsigned long module_base; + + if (!ia64_platform_is("sn2")) + return; + + module_base =3D (unsigned long)module->module_core; + + new_ar =3D kvm_vmm_base + vmm_info->patch_mov_ar - module_base; + new_ar_sn2 =3D kvm_vmm_base + vmm_info->patch_mov_ar_sn2 - module_base; + + printk(KERN_INFO "kvm: Patching ITC emulation to use SGI SN2 RTC " + "as source\n"); + + /* + * Copy the SN2 version of mov_ar into place. They are both + * the same size, so 6 bundles is sufficient (6 * 0x10). + */ + memcpy((void *)new_ar, (void *)new_ar_sn2, 0x60); +} + static int kvm_relocate_vmm(struct kvm_vmm_info *vmm_info, - struct module *module) + struct module *module) { unsigned long module_base; unsigned long vmm_size; @@ -1614,6 +1643,7 @@ return -EFAULT; =20 memcpy((void *)kvm_vmm_base, (void *)module_base, vmm_size); + kvm_patch_vmm(vmm_info, module); kvm_flush_icache(kvm_vmm_base, vmm_size); =20 /*Recalculate kvm_vmm_info based on new VMM*/ Index: linux-2.6.git/arch/ia64/kvm/optvfault.S =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D--- linux-2.6.git.orig/arch/ia64/kvm/optvfault.S +++ linux-2.6.git/arch/ia64/kvm/optvfault.S @@ -11,6 +11,7 @@ =20 #include #include +#include =20 #include "vti.h" #include "asm-offsets.h" @@ -140,6 +141,35 @@ ;; END(kvm_asm_mov_from_ar) =20 +/* + * Special SGI SN2 optimized version of mov_from_ar using the SN2 RTC + * clock as it's source for emulating the ITC. This version will be + * copied on top of the original version if the host is determined to + * be an SN2. + */ +GLOBAL_ENTRY(kvm_asm_mov_from_ar_sn2) + add r18=3DVMM_VCPU_ITC_OFS_OFFSET, r21 + movl r19 =3D (KVM_VMM_BASE+(1<