]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
KVM: PPC: Use READ_ONCE when dereferencing pte_t pointer
authorAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Mon, 30 Mar 2015 05:09:12 +0000 (10:39 +0530)
committerMichael Ellerman <mpe@ellerman.id.au>
Fri, 17 Apr 2015 01:23:24 +0000 (11:23 +1000)
pte can get updated from other CPUs as part of multiple activities
like THP split, huge page collapse, unmap. We need to make sure we
don't reload the pte value again and again for different checks.

Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
arch/powerpc/include/asm/kvm_book3s_64.h
arch/powerpc/kvm/e500_mmu_host.c

index 14619a59ec09b9ad93840803b9ff73e6b94ba53d..23b724c746e9deb1852a408acc03a8a10bd8e384 100644 (file)
@@ -290,7 +290,10 @@ static inline pte_t kvmppc_read_update_linux_pte(pte_t *ptep, int writing,
        pte_t old_pte, new_pte = __pte(0);
 
        while (1) {
-               old_pte = *ptep;
+               /*
+                * Make sure we don't reload from ptep
+                */
+               old_pte = READ_ONCE(*ptep);
                /*
                 * wait until _PAGE_BUSY is clear then set it atomically
                 */
index cc536d4a75eff6c19dfa44b8d20db1ebfa50b90c..5840d546aa031f543078441902ce74e05878fa94 100644 (file)
@@ -469,14 +469,18 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
 
        pgdir = vcpu_e500->vcpu.arch.pgdir;
        ptep = lookup_linux_ptep(pgdir, hva, &tsize_pages);
-       if (pte_present(*ptep))
-               wimg = (*ptep >> PTE_WIMGE_SHIFT) & MAS2_WIMGE_MASK;
-       else {
-               if (printk_ratelimit())
-                       pr_err("%s: pte not present: gfn %lx, pfn %lx\n",
-                               __func__, (long)gfn, pfn);
-               ret = -EINVAL;
-               goto out;
+       if (ptep) {
+               pte_t pte = READ_ONCE(*ptep);
+
+               if (pte_present(pte))
+                       wimg = (pte_val(pte) >> PTE_WIMGE_SHIFT) &
+                               MAS2_WIMGE_MASK;
+               else {
+                       pr_err_ratelimited("%s: pte not present: gfn %lx,pfn %lx\n",
+                                          __func__, (long)gfn, pfn);
+                       ret = -EINVAL;
+                       goto out;
+               }
        }
        kvmppc_e500_ref_setup(ref, gtlbe, pfn, wimg);