arm64: Allow EL1 physical timer access when running VHE
authorMarc Zyngier <maz@kernel.org>
Fri, 9 Jun 2023 16:21:49 +0000 (17:21 +0100)
committerOliver Upton <oliver.upton@linux.dev>
Mon, 12 Jun 2023 23:17:23 +0000 (23:17 +0000)
To initialise the timer access from EL2 when HCR_EL2.E2H is set,
we must make use the CNTHCTL_EL2 formap used is appropriate.

This amounts to shifting the timer/counter enable bits by 10
to the left.

Signed-off-by: Marc Zyngier <maz@kernel.org>
Reviewed-by: Catalin Marinas <catalin.marinas@arm.com>
Link: https://lore.kernel.org/r/20230609162200.2024064-7-maz@kernel.org
Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
arch/arm64/include/asm/el2_setup.h
arch/arm64/kvm/hyp/nvhe/hyp-init.S

index 037724b..225bf1f 100644 (file)
  */
 .macro __init_el2_timers
        mov     x0, #3                          // Enable EL1 physical timers
+       mrs     x1, hcr_el2
+       and     x1, x1, #HCR_E2H
+       cbz     x1, .LnVHE_\@
+       lsl     x0, x0, #10
+.LnVHE_\@:
        msr     cnthctl_el2, x0
        msr     cntvoff_el2, xzr                // Clear virtual offset
 .endm
index a6d67c2..f9ee10e 100644 (file)
@@ -95,6 +95,15 @@ SYM_CODE_START_LOCAL(___kvm_hyp_init)
        ldr     x1, [x0, #NVHE_INIT_HCR_EL2]
        msr     hcr_el2, x1
 
+       mov     x2, #HCR_E2H
+       and     x2, x1, x2
+       cbz     x2, 1f
+
+       mrs     x1, cnthctl_el2
+       and     x1, x1, #~(BIT(0) | BIT(1))
+       orr     x1, x1, #(BIT(10) | BIT(11))
+       msr     cnthctl_el2, x1
+1:
        ldr     x1, [x0, #NVHE_INIT_VTTBR]
        msr     vttbr_el2, x1