Skip to content

Commit 8409a06

Browse files
Christoffer Dallchazy
authored andcommitted
KVM: arm/arm64: Make timer_arm and timer_disarm helpers more generic
We are about to add an additional soft timer to the arch timer state for a VCPU and would like to be able to reuse the functions to program and cancel a timer, so we make them slightly more generic and rename to make it more clear that these functions work on soft timers and not the hardware resource that this code is managing. The armed flag on the timer state is only used to assert a condition, and we don't rely on this assertion in any meaningful way, so we can simply get rid of this flack and slightly reduce complexity. Acked-by: Marc Zyngier <marc.zyngier@arm.com> Signed-off-by: Christoffer Dall <cdall@linaro.org>
1 parent d33a3c8 commit 8409a06

2 files changed

Lines changed: 11 additions & 25 deletions

File tree

‎include/kvm/arm_arch_timer.h‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@ struct arch_timer_cpu {
4848
/* Work queued with the above timer expires */
4949
struct work_struct expired;
5050

51-
/* Background timer active */
52-
bool armed;
53-
5451
/* Is the timer enabled */
5552
bool enabled;
5653
};

‎virt/kvm/arm/arch_timer.c‎

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,16 @@ u64 kvm_phys_timer_read(void)
5656
return timecounter->cc->read(timecounter->cc);
5757
}
5858

59-
static bool timer_is_armed(struct arch_timer_cpu *timer)
59+
static void soft_timer_start(struct hrtimer *hrt, u64 ns)
6060
{
61-
return timer->armed;
62-
}
63-
64-
/* timer_arm: as in "arm the timer", not as in ARM the company */
65-
static void timer_arm(struct arch_timer_cpu *timer, u64 ns)
66-
{
67-
timer->armed = true;
68-
hrtimer_start(&timer->timer, ktime_add_ns(ktime_get(), ns),
61+
hrtimer_start(hrt, ktime_add_ns(ktime_get(), ns),
6962
HRTIMER_MODE_ABS);
7063
}
7164

72-
static void timer_disarm(struct arch_timer_cpu *timer)
65+
static void soft_timer_cancel(struct hrtimer *hrt, struct work_struct *work)
7366
{
74-
if (timer_is_armed(timer)) {
75-
hrtimer_cancel(&timer->timer);
76-
cancel_work_sync(&timer->expired);
77-
timer->armed = false;
78-
}
67+
hrtimer_cancel(hrt);
68+
cancel_work_sync(work);
7969
}
8070

8171
static irqreturn_t kvm_arch_timer_handler(int irq, void *dev_id)
@@ -271,7 +261,7 @@ static void kvm_timer_emulate(struct kvm_vcpu *vcpu,
271261
return;
272262

273263
/* The timer has not yet expired, schedule a background timer */
274-
timer_arm(timer, kvm_timer_compute_delta(timer_ctx));
264+
soft_timer_start(&timer->timer, kvm_timer_compute_delta(timer_ctx));
275265
}
276266

277267
/*
@@ -285,8 +275,6 @@ void kvm_timer_schedule(struct kvm_vcpu *vcpu)
285275
struct arch_timer_context *vtimer = vcpu_vtimer(vcpu);
286276
struct arch_timer_context *ptimer = vcpu_ptimer(vcpu);
287277

288-
BUG_ON(timer_is_armed(timer));
289-
290278
/*
291279
* No need to schedule a background timer if any guest timer has
292280
* already expired, because kvm_vcpu_block will return before putting
@@ -306,13 +294,14 @@ void kvm_timer_schedule(struct kvm_vcpu *vcpu)
306294
* The guest timers have not yet expired, schedule a background timer.
307295
* Set the earliest expiration time among the guest timers.
308296
*/
309-
timer_arm(timer, kvm_timer_earliest_exp(vcpu));
297+
soft_timer_start(&timer->timer, kvm_timer_earliest_exp(vcpu));
310298
}
311299

312300
void kvm_timer_unschedule(struct kvm_vcpu *vcpu)
313301
{
314302
struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
315-
timer_disarm(timer);
303+
304+
soft_timer_cancel(&timer->timer, &timer->expired);
316305
}
317306

318307
static void kvm_timer_flush_hwstate_vgic(struct kvm_vcpu *vcpu)
@@ -448,7 +437,7 @@ void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu)
448437
* This is to cancel the background timer for the physical timer
449438
* emulation if it is set.
450439
*/
451-
timer_disarm(timer);
440+
soft_timer_cancel(&timer->timer, &timer->expired);
452441

453442
/*
454443
* The guest could have modified the timer registers or the timer
@@ -615,7 +604,7 @@ void kvm_timer_vcpu_terminate(struct kvm_vcpu *vcpu)
615604
struct arch_timer_cpu *timer = &vcpu->arch.timer_cpu;
616605
struct arch_timer_context *vtimer = vcpu_vtimer(vcpu);
617606

618-
timer_disarm(timer);
607+
soft_timer_cancel(&timer->timer, &timer->expired);
619608
kvm_vgic_unmap_phys_irq(vcpu, vtimer->irq.irq);
620609
}
621610

0 commit comments

Comments
 (0)