]> www.infradead.org Git - users/jedix/linux-maple.git/commit
KVM: arm64: Get rid of __kvm_get_mdcr_el2() and related warts
authorOliver Upton <oliver.upton@linux.dev>
Thu, 19 Dec 2024 22:40:59 +0000 (14:40 -0800)
committerMarc Zyngier <maz@kernel.org>
Fri, 20 Dec 2024 08:49:08 +0000 (08:49 +0000)
commit2417218f2f234fd7880fb193ebf3ae5fcccfa29b
tree321b7e9ce4c17f988fa9157429b6bf211aa008ac
parent8ca19c40c47d80af369c222662445bbf593666b1
KVM: arm64: Get rid of __kvm_get_mdcr_el2() and related warts

KVM caches MDCR_EL2 on a per-CPU basis in order to preserve the
configuration of MDCR_EL2.HPMN while running a guest. This is a bit
gross, since we're relying on some baked configuration rather than the
hardware definition of implemented counters.

Discover the number of implemented counters by reading PMCR_EL0.N
instead. This works because:

 - In VHE the kernel runs at EL2, and N always returns the number of
   counters implemented in hardware

 - In {n,h}VHE, the EL2 setup code programs MDCR_EL2.HPMN with the EL2
   view of PMCR_EL0.N for the host

Lastly, avoid traps under nested virtualization by saving PMCR_EL0.N in
host data.

Tested-by: James Clark <james.clark@linaro.org>
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
Link: https://lore.kernel.org/r/20241219224116.3941496-3-oliver.upton@linux.dev
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/include/asm/kvm_asm.h
arch/arm64/include/asm/kvm_host.h
arch/arm64/kvm/arm.c
arch/arm64/kvm/debug.c
arch/arm64/kvm/hyp/nvhe/debug-sr.c
arch/arm64/kvm/hyp/nvhe/hyp-main.c
arch/arm64/kvm/hyp/vhe/debug-sr.c