]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
KVM: arm64: Replace timer context vcpu pointer with timer_id
authorMarc Zyngier <maz@kernel.org>
Mon, 29 Sep 2025 16:04:47 +0000 (17:04 +0100)
committerMarc Zyngier <maz@kernel.org>
Mon, 13 Oct 2025 13:42:40 +0000 (14:42 +0100)
Having to follow a pointer to a vcpu is pretty dumb, when the timers
are are a fixed offset in the vcpu structure itself.

Trade the vcpu pointer for a timer_id, which can then be used to
compute the vcpu address as needed.

Reviewed-by: Joey Gouly <joey.gouly@arm.com>
Signed-off-by: Marc Zyngier <maz@kernel.org>
arch/arm64/kvm/arch_timer.c
include/kvm/arm_arch_timer.h

index e5a25e743f5be1c7facb39d74ee0c3a3b58e907c..c832c293676a32ebf06293d1856dd191f5758f19 100644 (file)
@@ -149,7 +149,7 @@ static void timer_set_cval(struct arch_timer_context *ctxt, u64 cval)
 static void timer_set_offset(struct arch_timer_context *ctxt, u64 offset)
 {
        if (!ctxt->offset.vm_offset) {
-               WARN(offset, "timer %ld\n", arch_timer_ctx_index(ctxt));
+               WARN(offset, "timer %d\n", arch_timer_ctx_index(ctxt));
                return;
        }
 
@@ -1064,7 +1064,7 @@ static void timer_context_init(struct kvm_vcpu *vcpu, int timerid)
        struct arch_timer_context *ctxt = vcpu_get_timer(vcpu, timerid);
        struct kvm *kvm = vcpu->kvm;
 
-       ctxt->vcpu = vcpu;
+       ctxt->timer_id = timerid;
 
        if (timerid == TIMER_VTIMER)
                ctxt->offset.vm_offset = &kvm->arch.timer_data.voffset;
index d188c716d03cb493b163b79b42fd94ee5cc0f197..d8e400cb2bfff40aa8beb404fb4833680fc62794 100644 (file)
@@ -51,8 +51,6 @@ struct arch_timer_vm_data {
 };
 
 struct arch_timer_context {
-       struct kvm_vcpu                 *vcpu;
-
        /* Emulated Timer (may be unused) */
        struct hrtimer                  hrtimer;
        u64                             ns_frac;
@@ -71,6 +69,9 @@ struct arch_timer_context {
                bool                    level;
        } irq;
 
+       /* Who am I? */
+       enum kvm_arch_timers            timer_id;
+
        /* Duplicated state from arch_timer.c for convenience */
        u32                             host_timer_irq;
 };
@@ -127,9 +128,9 @@ void kvm_timer_init_vhe(void);
 #define vcpu_hvtimer(v)        (&(v)->arch.timer_cpu.timers[TIMER_HVTIMER])
 #define vcpu_hptimer(v)        (&(v)->arch.timer_cpu.timers[TIMER_HPTIMER])
 
-#define arch_timer_ctx_index(ctx)      ((ctx) - vcpu_timer((ctx)->vcpu)->timers)
-#define timer_context_to_vcpu(ctx)     ((ctx)->vcpu)
-#define timer_vm_data(ctx)             (&(ctx)->vcpu->kvm->arch.timer_data)
+#define arch_timer_ctx_index(ctx)      ((ctx)->timer_id)
+#define timer_context_to_vcpu(ctx)     container_of((ctx), struct kvm_vcpu, arch.timer_cpu.timers[(ctx)->timer_id])
+#define timer_vm_data(ctx)             (&(timer_context_to_vcpu(ctx)->kvm->arch.timer_data))
 #define timer_irq(ctx)                 (timer_vm_data(ctx)->ppi[arch_timer_ctx_index(ctx)])
 
 u64 kvm_arm_timer_read_sysreg(struct kvm_vcpu *vcpu,