Skip to content

Commit 8625a67

Browse files
author
Marc Zyngier
committed
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>
1 parent aa68975 commit 8625a67

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

arch/arm64/kvm/arch_timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ static void timer_set_cval(struct arch_timer_context *ctxt, u64 cval)
149149
static void timer_set_offset(struct arch_timer_context *ctxt, u64 offset)
150150
{
151151
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));
153153
return;
154154
}
155155

@@ -1064,7 +1064,7 @@ static void timer_context_init(struct kvm_vcpu *vcpu, int timerid)
10641064
struct arch_timer_context *ctxt = vcpu_get_timer(vcpu, timerid);
10651065
struct kvm *kvm = vcpu->kvm;
10661066

1067-
ctxt->vcpu = vcpu;
1067+
ctxt->timer_id = timerid;
10681068

10691069
if (timerid == TIMER_VTIMER)
10701070
ctxt->offset.vm_offset = &kvm->arch.timer_data.voffset;

include/kvm/arm_arch_timer.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ struct arch_timer_vm_data {
5151
};
5252

5353
struct arch_timer_context {
54-
struct kvm_vcpu *vcpu;
55-
5654
/* Emulated Timer (may be unused) */
5755
struct hrtimer hrtimer;
5856
u64 ns_frac;
@@ -71,6 +69,9 @@ struct arch_timer_context {
7169
bool level;
7270
} irq;
7371

72+
/* Who am I? */
73+
enum kvm_arch_timers timer_id;
74+
7475
/* Duplicated state from arch_timer.c for convenience */
7576
u32 host_timer_irq;
7677
};
@@ -127,9 +128,9 @@ void kvm_timer_init_vhe(void);
127128
#define vcpu_hvtimer(v) (&(v)->arch.timer_cpu.timers[TIMER_HVTIMER])
128129
#define vcpu_hptimer(v) (&(v)->arch.timer_cpu.timers[TIMER_HPTIMER])
129130

130-
#define arch_timer_ctx_index(ctx) ((ctx) - vcpu_timer((ctx)->vcpu)->timers)
131-
#define timer_context_to_vcpu(ctx) ((ctx)->vcpu)
132-
#define timer_vm_data(ctx) (&(ctx)->vcpu->kvm->arch.timer_data)
131+
#define arch_timer_ctx_index(ctx) ((ctx)->timer_id)
132+
#define timer_context_to_vcpu(ctx) container_of((ctx), struct kvm_vcpu, arch.timer_cpu.timers[(ctx)->timer_id])
133+
#define timer_vm_data(ctx) (&(timer_context_to_vcpu(ctx)->kvm->arch.timer_data))
133134
#define timer_irq(ctx) (timer_vm_data(ctx)->ppi[arch_timer_ctx_index(ctx)])
134135

135136
u64 kvm_arm_timer_read_sysreg(struct kvm_vcpu *vcpu,

0 commit comments

Comments
 (0)