]> git.openfabrics.org - ~emulex/infiniband.git/commitdiff
KVM: PPC: Book3S: Make magic page properly 4k mappable
authorAlexander Graf <agraf@suse.de>
Sun, 13 Jul 2014 14:37:12 +0000 (16:37 +0200)
committerAlexander Graf <agraf@suse.de>
Mon, 28 Jul 2014 13:23:11 +0000 (15:23 +0200)
The magic page is defined as a 4k page of per-vCPU data that is shared
between the guest and the host to accelerate accesses to privileged
registers.

However, when the host is using 64k page size granularity we weren't quite
as strict about that rule anymore. Instead, we partially treated all of the
upper 64k as magic page and mapped only the uppermost 4k with the actual
magic contents.

This works well enough for Linux which doesn't use any memory in kernel
space in the upper 64k, but Mac OS X got upset. So this patch makes magic
page actually stay in a 4k range even on 64k page size hosts.

This patch fixes magic page usage with Mac OS X (using MOL) on 64k PAGE_SIZE
hosts for me.

Signed-off-by: Alexander Graf <agraf@suse.de>
arch/powerpc/include/asm/kvm_book3s.h
arch/powerpc/kvm/book3s.c
arch/powerpc/kvm/book3s_32_mmu_host.c
arch/powerpc/kvm/book3s_64_mmu_host.c
arch/powerpc/kvm/book3s_pr.c
arch/powerpc/kvm/powerpc.c

index b1cf18de9a1d3f4ef61d71079f92c47d592a6a58..20fb6f2890a0a2596eddead9f5138477039b2dff 100644 (file)
@@ -158,7 +158,7 @@ extern void kvmppc_set_bat(struct kvm_vcpu *vcpu, struct kvmppc_bat *bat,
                           bool upper, u32 val);
 extern void kvmppc_giveup_ext(struct kvm_vcpu *vcpu, ulong msr);
 extern int kvmppc_emulate_paired_single(struct kvm_run *run, struct kvm_vcpu *vcpu);
-extern pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, bool writing,
+extern pfn_t kvmppc_gpa_to_pfn(struct kvm_vcpu *vcpu, gpa_t gpa, bool writing,
                        bool *writable);
 extern void kvmppc_add_revmap_chain(struct kvm *kvm, struct revmap_entry *rev,
                        unsigned long *rmap, long pte_index, int realmode);
index 1d137642f1a23166d8bebff2877b90f0e9bb528b..31facfc1314bad6b0e66b1296f3d8e0ccc653414 100644 (file)
@@ -354,18 +354,18 @@ int kvmppc_core_prepare_to_enter(struct kvm_vcpu *vcpu)
 }
 EXPORT_SYMBOL_GPL(kvmppc_core_prepare_to_enter);
 
-pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, bool writing,
+pfn_t kvmppc_gpa_to_pfn(struct kvm_vcpu *vcpu, gpa_t gpa, bool writing,
                        bool *writable)
 {
-       ulong mp_pa = vcpu->arch.magic_page_pa;
+       ulong mp_pa = vcpu->arch.magic_page_pa & KVM_PAM;
+       gfn_t gfn = gpa >> PAGE_SHIFT;
 
        if (!(kvmppc_get_msr(vcpu) & MSR_SF))
                mp_pa = (uint32_t)mp_pa;
 
        /* Magic page override */
-       if (unlikely(mp_pa) &&
-           unlikely(((gfn << PAGE_SHIFT) & KVM_PAM) ==
-                    ((mp_pa & PAGE_MASK) & KVM_PAM))) {
+       gpa &= ~0xFFFULL;
+       if (unlikely(mp_pa) && unlikely((gpa & KVM_PAM) == mp_pa)) {
                ulong shared_page = ((ulong)vcpu->arch.shared) & PAGE_MASK;
                pfn_t pfn;
 
@@ -378,7 +378,7 @@ pfn_t kvmppc_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, bool writing,
 
        return gfn_to_pfn_prot(vcpu->kvm, gfn, writing, writable);
 }
-EXPORT_SYMBOL_GPL(kvmppc_gfn_to_pfn);
+EXPORT_SYMBOL_GPL(kvmppc_gpa_to_pfn);
 
 static int kvmppc_xlate(struct kvm_vcpu *vcpu, ulong eaddr, bool data,
                        bool iswrite, struct kvmppc_pte *pte)
index 678e753704959775d85054293f10280843dd2339..2035d16a9262ac5e547bacc0cbcb4fc862706aa5 100644 (file)
@@ -156,11 +156,10 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte,
        bool writable;
 
        /* Get host physical address for gpa */
-       hpaddr = kvmppc_gfn_to_pfn(vcpu, orig_pte->raddr >> PAGE_SHIFT,
-                                  iswrite, &writable);
+       hpaddr = kvmppc_gpa_to_pfn(vcpu, orig_pte->raddr, iswrite, &writable);
        if (is_error_noslot_pfn(hpaddr)) {
-               printk(KERN_INFO "Couldn't get guest page for gfn %lx!\n",
-                                orig_pte->eaddr);
+               printk(KERN_INFO "Couldn't get guest page for gpa %lx!\n",
+                                orig_pte->raddr);
                r = -EINVAL;
                goto out;
        }
index 0ac98392f3635f82152405f48af891a3ce27b3dc..b982d925c7105f910003ed3e53b5a595558f67ef 100644 (file)
@@ -104,9 +104,10 @@ int kvmppc_mmu_map_page(struct kvm_vcpu *vcpu, struct kvmppc_pte *orig_pte,
        smp_rmb();
 
        /* Get host physical address for gpa */
-       pfn = kvmppc_gfn_to_pfn(vcpu, gfn, iswrite, &writable);
+       pfn = kvmppc_gpa_to_pfn(vcpu, orig_pte->raddr, iswrite, &writable);
        if (is_error_noslot_pfn(pfn)) {
-               printk(KERN_INFO "Couldn't get guest page for gfn %lx!\n", gfn);
+               printk(KERN_INFO "Couldn't get guest page for gpa %lx!\n",
+                      orig_pte->raddr);
                r = -EINVAL;
                goto out;
        }
index 6125f60a68f890b0a0cd24620250d50d99042261..e40765f8cbad4edc8cd9c3b2930f5ae03aa34e6c 100644 (file)
@@ -511,19 +511,19 @@ static void kvmppc_patch_dcbz(struct kvm_vcpu *vcpu, struct kvmppc_pte *pte)
        put_page(hpage);
 }
 
-static int kvmppc_visible_gfn(struct kvm_vcpu *vcpu, gfn_t gfn)
+static int kvmppc_visible_gpa(struct kvm_vcpu *vcpu, gpa_t gpa)
 {
        ulong mp_pa = vcpu->arch.magic_page_pa;
 
        if (!(kvmppc_get_msr(vcpu) & MSR_SF))
                mp_pa = (uint32_t)mp_pa;
 
-       if (unlikely(mp_pa) &&
-           unlikely((mp_pa & KVM_PAM) >> PAGE_SHIFT == gfn)) {
+       gpa &= ~0xFFFULL;
+       if (unlikely(mp_pa) && unlikely((mp_pa & KVM_PAM) == (gpa & KVM_PAM))) {
                return 1;
        }
 
-       return kvm_is_visible_gfn(vcpu->kvm, gfn);
+       return kvm_is_visible_gfn(vcpu->kvm, gpa >> PAGE_SHIFT);
 }
 
 int kvmppc_handle_pagefault(struct kvm_run *run, struct kvm_vcpu *vcpu,
@@ -614,7 +614,7 @@ int kvmppc_handle_pagefault(struct kvm_run *run, struct kvm_vcpu *vcpu,
                kvmppc_set_dar(vcpu, kvmppc_get_fault_dar(vcpu));
                kvmppc_book3s_queue_irqprio(vcpu, vec + 0x80);
        } else if (!is_mmio &&
-                  kvmppc_visible_gfn(vcpu, pte.raddr >> PAGE_SHIFT)) {
+                  kvmppc_visible_gpa(vcpu, pte.raddr)) {
                if (data && !(vcpu->arch.fault_dsisr & DSISR_NOHPTE)) {
                        /*
                         * There is already a host HPTE there, presumably
@@ -1387,8 +1387,7 @@ static struct kvm_vcpu *kvmppc_core_vcpu_create_pr(struct kvm *kvm,
        p = __get_free_page(GFP_KERNEL|__GFP_ZERO);
        if (!p)
                goto uninit_vcpu;
-       /* the real shared page fills the last 4k of our page */
-       vcpu->arch.shared = (void *)(p + PAGE_SIZE - 4096);
+       vcpu->arch.shared = (void *)p;
 #ifdef CONFIG_PPC_BOOK3S_64
        /* Always start the shared struct in native endian mode */
 #ifdef __BIG_ENDIAN__
index 7efc2b71140404b9da1c5f289a10914899058847..fe0257a8e3351d7e63ad27452ecbf3979d5cd795 100644 (file)
@@ -190,6 +190,25 @@ int kvmppc_kvm_pv(struct kvm_vcpu *vcpu)
                vcpu->arch.magic_page_pa = param1 & ~0xfffULL;
                vcpu->arch.magic_page_ea = param2 & ~0xfffULL;
 
+#ifdef CONFIG_PPC_64K_PAGES
+               /*
+                * Make sure our 4k magic page is in the same window of a 64k
+                * page within the guest and within the host's page.
+                */
+               if ((vcpu->arch.magic_page_pa & 0xf000) !=
+                   ((ulong)vcpu->arch.shared & 0xf000)) {
+                       void *old_shared = vcpu->arch.shared;
+                       ulong shared = (ulong)vcpu->arch.shared;
+                       void *new_shared;
+
+                       shared &= PAGE_MASK;
+                       shared |= vcpu->arch.magic_page_pa & 0xf000;
+                       new_shared = (void*)shared;
+                       memcpy(new_shared, old_shared, 0x1000);
+                       vcpu->arch.shared = new_shared;
+               }
+#endif
+
                r2 = KVM_MAGIC_FEAT_SR | KVM_MAGIC_FEAT_MAS0_TO_SPRG7;
 
                r = EV_SUCCESS;