Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

KVM: arm64: Replace timer context vcpu pointer with timer_id

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>

+8 -7
+2 -2
arch/arm64/kvm/arch_timer.c
··· 149 149 static void timer_set_offset(struct arch_timer_context *ctxt, u64 offset) 150 150 { 151 151 if (!ctxt->offset.vm_offset) { 152 - WARN(offset, "timer %ld\n", arch_timer_ctx_index(ctxt)); 152 + WARN(offset, "timer %d\n", arch_timer_ctx_index(ctxt)); 153 153 return; 154 154 } 155 155 ··· 1064 1064 struct arch_timer_context *ctxt = vcpu_get_timer(vcpu, timerid); 1065 1065 struct kvm *kvm = vcpu->kvm; 1066 1066 1067 - ctxt->vcpu = vcpu; 1067 + ctxt->timer_id = timerid; 1068 1068 1069 1069 if (timerid == TIMER_VTIMER) 1070 1070 ctxt->offset.vm_offset = &kvm->arch.timer_data.voffset;
+6 -5
include/kvm/arm_arch_timer.h
··· 51 51 }; 52 52 53 53 struct arch_timer_context { 54 - struct kvm_vcpu *vcpu; 55 - 56 54 /* Emulated Timer (may be unused) */ 57 55 struct hrtimer hrtimer; 58 56 u64 ns_frac; ··· 68 70 struct { 69 71 bool level; 70 72 } irq; 73 + 74 + /* Who am I? */ 75 + enum kvm_arch_timers timer_id; 71 76 72 77 /* Duplicated state from arch_timer.c for convenience */ 73 78 u32 host_timer_irq; ··· 128 127 #define vcpu_hvtimer(v) (&(v)->arch.timer_cpu.timers[TIMER_HVTIMER]) 129 128 #define vcpu_hptimer(v) (&(v)->arch.timer_cpu.timers[TIMER_HPTIMER]) 130 129 131 - #define arch_timer_ctx_index(ctx) ((ctx) - vcpu_timer((ctx)->vcpu)->timers) 132 - #define timer_context_to_vcpu(ctx) ((ctx)->vcpu) 133 - #define timer_vm_data(ctx) (&(ctx)->vcpu->kvm->arch.timer_data) 130 + #define arch_timer_ctx_index(ctx) ((ctx)->timer_id) 131 + #define timer_context_to_vcpu(ctx) container_of((ctx), struct kvm_vcpu, arch.timer_cpu.timers[(ctx)->timer_id]) 132 + #define timer_vm_data(ctx) (&(timer_context_to_vcpu(ctx)->kvm->arch.timer_data)) 134 133 #define timer_irq(ctx) (timer_vm_data(ctx)->ppi[arch_timer_ctx_index(ctx)]) 135 134 136 135 u64 kvm_arm_timer_read_sysreg(struct kvm_vcpu *vcpu,