Skip to content

Commit a91d185

Browse files
soccertackMarc Zyngier
authored andcommitted
KVM: arm/arm64: Initialize the emulated EL1 physical timer
Initialize the emulated EL1 physical timer with the default irq number. Signed-off-by: Jintack Lim <jintack@cs.columbia.edu> Reviewed-by: Christoffer Dall <christoffer.dall@linaro.org> Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
1 parent 009a570 commit a91d185

4 files changed

Lines changed: 25 additions & 5 deletions

File tree

‎arch/arm/kvm/reset.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ static struct kvm_regs cortexa_regs_reset = {
3737
.usr_regs.ARM_cpsr = SVC_MODE | PSR_A_BIT | PSR_I_BIT | PSR_F_BIT,
3838
};
3939

40+
static const struct kvm_irq_level cortexa_ptimer_irq = {
41+
{ .irq = 30 },
42+
.level = 1,
43+
};
44+
4045
static const struct kvm_irq_level cortexa_vtimer_irq = {
4146
{ .irq = 27 },
4247
.level = 1,
@@ -58,13 +63,15 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
5863
{
5964
struct kvm_regs *reset_regs;
6065
const struct kvm_irq_level *cpu_vtimer_irq;
66+
const struct kvm_irq_level *cpu_ptimer_irq;
6167

6268
switch (vcpu->arch.target) {
6369
case KVM_ARM_TARGET_CORTEX_A7:
6470
case KVM_ARM_TARGET_CORTEX_A15:
6571
reset_regs = &cortexa_regs_reset;
6672
vcpu->arch.midr = read_cpuid_id();
6773
cpu_vtimer_irq = &cortexa_vtimer_irq;
74+
cpu_ptimer_irq = &cortexa_ptimer_irq;
6875
break;
6976
default:
7077
return -ENODEV;
@@ -77,5 +84,5 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
7784
kvm_reset_coprocs(vcpu);
7885

7986
/* Reset arch_timer context */
80-
return kvm_timer_vcpu_reset(vcpu, cpu_vtimer_irq);
87+
return kvm_timer_vcpu_reset(vcpu, cpu_vtimer_irq, cpu_ptimer_irq);
8188
}

‎arch/arm64/kvm/reset.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ static const struct kvm_regs default_regs_reset32 = {
4646
COMPAT_PSR_I_BIT | COMPAT_PSR_F_BIT),
4747
};
4848

49+
static const struct kvm_irq_level default_ptimer_irq = {
50+
.irq = 30,
51+
.level = 1,
52+
};
53+
4954
static const struct kvm_irq_level default_vtimer_irq = {
5055
.irq = 27,
5156
.level = 1,
@@ -104,6 +109,7 @@ int kvm_arch_dev_ioctl_check_extension(struct kvm *kvm, long ext)
104109
int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
105110
{
106111
const struct kvm_irq_level *cpu_vtimer_irq;
112+
const struct kvm_irq_level *cpu_ptimer_irq;
107113
const struct kvm_regs *cpu_reset;
108114

109115
switch (vcpu->arch.target) {
@@ -117,6 +123,7 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
117123
}
118124

119125
cpu_vtimer_irq = &default_vtimer_irq;
126+
cpu_ptimer_irq = &default_ptimer_irq;
120127
break;
121128
}
122129

@@ -130,5 +137,5 @@ int kvm_reset_vcpu(struct kvm_vcpu *vcpu)
130137
kvm_pmu_vcpu_reset(vcpu);
131138

132139
/* Reset timer */
133-
return kvm_timer_vcpu_reset(vcpu, cpu_vtimer_irq);
140+
return kvm_timer_vcpu_reset(vcpu, cpu_vtimer_irq, cpu_ptimer_irq);
134141
}

‎include/kvm/arm_arch_timer.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ struct arch_timer_cpu {
5858
int kvm_timer_hyp_init(void);
5959
int kvm_timer_enable(struct kvm_vcpu *vcpu);
6060
int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu,
61-
const struct kvm_irq_level *irq);
61+
const struct kvm_irq_level *virt_irq,
62+
const struct kvm_irq_level *phys_irq);
6263
void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu);
6364
void kvm_timer_flush_hwstate(struct kvm_vcpu *vcpu);
6465
void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu);

‎virt/kvm/arm/arch_timer.c‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,17 +327,20 @@ void kvm_timer_sync_hwstate(struct kvm_vcpu *vcpu)
327327
}
328328

329329
int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu,
330-
const struct kvm_irq_level *irq)
330+
const struct kvm_irq_level *virt_irq,
331+
const struct kvm_irq_level *phys_irq)
331332
{
332333
struct arch_timer_context *vtimer = vcpu_vtimer(vcpu);
334+
struct arch_timer_context *ptimer = vcpu_ptimer(vcpu);
333335

334336
/*
335337
* The vcpu timer irq number cannot be determined in
336338
* kvm_timer_vcpu_init() because it is called much before
337339
* kvm_vcpu_set_target(). To handle this, we determine
338340
* vcpu timer irq number when the vcpu is reset.
339341
*/
340-
vtimer->irq.irq = irq->irq;
342+
vtimer->irq.irq = virt_irq->irq;
343+
ptimer->irq.irq = phys_irq->irq;
341344

342345
/*
343346
* The bits in CNTV_CTL are architecturally reset to UNKNOWN for ARMv8
@@ -346,6 +349,7 @@ int kvm_timer_vcpu_reset(struct kvm_vcpu *vcpu,
346349
* the ARMv7 architecture.
347350
*/
348351
vtimer->cnt_ctl = 0;
352+
ptimer->cnt_ctl = 0;
349353
kvm_timer_update_state(vcpu);
350354

351355
return 0;
@@ -376,6 +380,7 @@ void kvm_timer_vcpu_init(struct kvm_vcpu *vcpu)
376380

377381
/* Synchronize cntvoff across all vtimers of a VM. */
378382
update_vtimer_cntvoff(vcpu, kvm_phys_timer_read());
383+
vcpu_ptimer(vcpu)->cntvoff = 0;
379384

380385
INIT_WORK(&timer->expired, kvm_timer_inject_irq_work);
381386
hrtimer_init(&timer->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);

0 commit comments

Comments
 (0)