Skip to content

Commit 65729da

Browse files
author
Marc Zyngier
committed
KVM: arm64: Convert timer offset VA when accessed in HYP code
Now that EL2 has gained some early timer emulation, it accesses the offsets pointed to by the timer structure, both of which live in the KVM structure. Of course, these are *kernel* pointers, so the dereferencing of these pointers in non-kernel code must be itself be offset. Given switch.h its own version of timer_get_offset() and use that instead. Fixes: b86fc21 ("KVM: arm64: Handle counter access early in non-HYP context") Reported-by: Linux Kernel Functional Testing <lkft@linaro.org> Reviewed-by: Oliver Upton <oliver.upton@linux.dev> Tested-by: Anders Roxell <anders.roxell@linaro.org> Link: https://lore.kernel.org/r/20250212173454.2864462-1-maz@kernel.org Signed-off-by: Marc Zyngier <maz@kernel.org>
1 parent 332b7e6 commit 65729da

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

arch/arm64/kvm/hyp/include/hyp/switch.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,22 @@ static inline bool handle_tx2_tvm(struct kvm_vcpu *vcpu)
581581
return true;
582582
}
583583

584+
/* Open-coded version of timer_get_offset() to allow for kern_hyp_va() */
585+
static inline u64 hyp_timer_get_offset(struct arch_timer_context *ctxt)
586+
{
587+
u64 offset = 0;
588+
589+
if (ctxt->offset.vm_offset)
590+
offset += *kern_hyp_va(ctxt->offset.vm_offset);
591+
if (ctxt->offset.vcpu_offset)
592+
offset += *kern_hyp_va(ctxt->offset.vcpu_offset);
593+
594+
return offset;
595+
}
596+
584597
static inline u64 compute_counter_value(struct arch_timer_context *ctxt)
585598
{
586-
return arch_timer_read_cntpct_el0() - timer_get_offset(ctxt);
599+
return arch_timer_read_cntpct_el0() - hyp_timer_get_offset(ctxt);
587600
}
588601

589602
static bool kvm_handle_cntxct(struct kvm_vcpu *vcpu)

0 commit comments

Comments
 (0)