]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commit
KVM: PPC: Book3S HV: Don't lose hardware R/C bit updates in H_PROTECT
authorPaul Mackerras <paulus@ozlabs.org>
Wed, 16 Nov 2016 05:43:28 +0000 (16:43 +1100)
committerPaul Mackerras <paulus@ozlabs.org>
Mon, 21 Nov 2016 04:29:20 +0000 (15:29 +1100)
commitf064a0de1579fabded8990bed93971e30deb9ecb
tree1f90c993aa09a3ab8e891633f7aee97bfa336c05
parent0d808df06a44200f52262b6eb72bcb6042f5a7c5
KVM: PPC: Book3S HV: Don't lose hardware R/C bit updates in H_PROTECT

The hashed page table MMU in POWER processors can update the R
(reference) and C (change) bits in a HPTE at any time until the
HPTE has been invalidated and the TLB invalidation sequence has
completed.  In kvmppc_h_protect, which implements the H_PROTECT
hypercall, we read the HPTE, modify the second doubleword,
invalidate the HPTE in memory, do the TLB invalidation sequence,
and then write the modified value of the second doubleword back
to memory.  In doing so we could overwrite an R/C bit update done
by hardware between when we read the HPTE and when the TLB
invalidation completed.  To fix this we re-read the second
doubleword after the TLB invalidation and OR in the (possibly)
new values of R and C.  We can use an OR since hardware only ever
sets R and C, never clears them.

This race was found by code inspection.  In principle this bug could
cause occasional guest memory corruption under host memory pressure.

Fixes: a8606e20e41a ("KVM: PPC: Handle some PAPR hcalls in the kernel", 2011-06-29)
Cc: stable@vger.kernel.org # v3.19+
Signed-off-by: Paul Mackerras <paulus@ozlabs.org>
arch/powerpc/kvm/book3s_hv_rm_mmu.c