Commit 5e1d44ae authored by Aneesh Kumar K.V's avatar Aneesh Kumar K.V Committed by Michael Ellerman

KVM: PPC: Use READ_ONCE when dereferencing pte_t pointer

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: default avatarAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent 1cbee462
...@@ -290,7 +290,10 @@ static inline pte_t kvmppc_read_update_linux_pte(pte_t *ptep, int writing, ...@@ -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); pte_t old_pte, new_pte = __pte(0);
while (1) { 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 * wait until _PAGE_BUSY is clear then set it atomically
*/ */
......
...@@ -469,14 +469,18 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500, ...@@ -469,14 +469,18 @@ static inline int kvmppc_e500_shadow_map(struct kvmppc_vcpu_e500 *vcpu_e500,
pgdir = vcpu_e500->vcpu.arch.pgdir; pgdir = vcpu_e500->vcpu.arch.pgdir;
ptep = lookup_linux_ptep(pgdir, hva, &tsize_pages); ptep = lookup_linux_ptep(pgdir, hva, &tsize_pages);
if (pte_present(*ptep)) if (ptep) {
wimg = (*ptep >> PTE_WIMGE_SHIFT) & MAS2_WIMGE_MASK; pte_t pte = READ_ONCE(*ptep);
else {
if (printk_ratelimit()) if (pte_present(pte))
pr_err("%s: pte not present: gfn %lx, pfn %lx\n", wimg = (pte_val(pte) >> PTE_WIMGE_SHIFT) &
__func__, (long)gfn, pfn); MAS2_WIMGE_MASK;
ret = -EINVAL; else {
goto out; 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); kvmppc_e500_ref_setup(ref, gtlbe, pfn, wimg);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment