KVM: PPC: Book3S HV P9: Demand fault PMU SPRs when marked not inuse
authorNicholas Piggin <npiggin@gmail.com>
Tue, 23 Nov 2021 09:51:53 +0000 (19:51 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Wed, 24 Nov 2021 10:08:58 +0000 (21:08 +1100)
commit9d3ddb86d96d9f0314f3baaf0e37f987b40d3eee
tree845bdf2c6d784cd8a02af947d55404eb5fcf8c36
parent401e1ae372673664465d45a86975c006dc6a488d
KVM: PPC: Book3S HV P9: Demand fault PMU SPRs when marked not inuse

The pmcregs_in_use field in the guest VPA can not be trusted to reflect
what the guest is doing with PMU SPRs, so the PMU must always be managed
(stopped) when exiting the guest, and SPR values set when entering the
guest to ensure it can't cause a covert channel or otherwise cause other
guests or the host to misbehave.

So prevent guest access to the PMU with HFSCR[PM] if pmcregs_in_use is
clear, and avoid the PMU SPR access on every partition switch. Guests
that set pmcregs_in_use incorrectly or when first setting it and using
the PMU will take a hypervisor facility unavailable interrupt that will
bring in the PMU SPRs.

Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Reviewed-by: Athira Jajeev <atrajeev@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/20211123095231.1036501-16-npiggin@gmail.com
arch/powerpc/kvm/book3s_hv.c