]> git.baikalelectronics.ru Git - kernel.git/commit
powerpc/kvm: Save and restore host AMR/IAMR/UAMOR
authorMichael Ellerman <mpe@ellerman.id.au>
Fri, 22 Feb 2019 02:22:08 +0000 (13:22 +1100)
committerMichael Ellerman <mpe@ellerman.id.au>
Fri, 22 Feb 2019 02:41:13 +0000 (13:41 +1100)
commit0dce762ce5a9f18173dc683d66f482c0cd668ab7
tree7600bc038316c979526f3e74e2c52cb5292b84c5
parent32365660f0d3b1663bc0de23e8e68df4e23010a7
powerpc/kvm: Save and restore host AMR/IAMR/UAMOR

When the hash MMU is active the AMR, IAMR and UAMOR are used for
pkeys. The AMR is directly writable by user space, and the UAMOR masks
those writes, meaning both registers are effectively user register
state. The IAMR is used to create an execute only key.

Also we must maintain the value of at least the AMR when running in
process context, so that any memory accesses done by the kernel on
behalf of the process are correctly controlled by the AMR.

Although we are correctly switching all registers when going into a
guest, on returning to the host we just write 0 into all regs, except
on Power9 where we restore the IAMR correctly.

This could be observed by a user process if it writes the AMR, then
runs a guest and we then return immediately to it without
rescheduling. Because we have written 0 to the AMR that would have the
effect of granting read/write permission to pages that the process was
trying to protect.

In addition, when using the Radix MMU, the AMR can prevent inadvertent
kernel access to userspace data, writing 0 to the AMR disables that
protection.

So save and restore AMR, IAMR and UAMOR.

Fixes: d8330fab59d5 ("powerpc: Enable pkey subsystem")
Cc: stable@vger.kernel.org # v4.16+
Signed-off-by: Russell Currey <ruscur@russell.cc>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Acked-by: Paul Mackerras <paulus@ozlabs.org>
arch/powerpc/kvm/book3s_hv_rmhandlers.S