Skip to content

Commit cc45963

Browse files
author
Marc Zyngier
committed
KVM: arm64: nv: Publish emulated timer interrupt state in the in-memory state
With FEAT_NV2, the EL0 timer state is entirely stored in memory, meaning that the hypervisor can only provide a very poor emulation. The only thing we can really do is to publish the interrupt state in the guest view of CNT{P,V}_CTL_EL0, and defer everything else to the next exit. Only FEAT_ECV will allow us to fix it, at the cost of extra trapping. Suggested-by: Chase Conklin <[email protected]> Suggested-by: Ganapatrao Kulkarni <[email protected]> Acked-by: Oliver Upton <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Marc Zyngier <[email protected]>
1 parent 4bad306 commit cc45963

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

arch/arm64/kvm/arch_timer.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,30 @@ void kvm_timer_update_run(struct kvm_vcpu *vcpu)
441441
regs->device_irq_level |= KVM_ARM_DEV_EL1_PTIMER;
442442
}
443443

444+
static void kvm_timer_update_status(struct arch_timer_context *ctx, bool level)
445+
{
446+
/*
447+
* Paper over NV2 brokenness by publishing the interrupt status
448+
* bit. This still results in a poor quality of emulation (guest
449+
* writes will have no effect until the next exit).
450+
*
451+
* But hey, it's fast, right?
452+
*/
453+
if (is_hyp_ctxt(ctx->vcpu) &&
454+
(ctx == vcpu_vtimer(ctx->vcpu) || ctx == vcpu_ptimer(ctx->vcpu))) {
455+
unsigned long val = timer_get_ctl(ctx);
456+
__assign_bit(__ffs(ARCH_TIMER_CTRL_IT_STAT), &val, level);
457+
timer_set_ctl(ctx, val);
458+
}
459+
}
460+
444461
static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level,
445462
struct arch_timer_context *timer_ctx)
446463
{
447464
int ret;
448465

466+
kvm_timer_update_status(timer_ctx, new_level);
467+
449468
timer_ctx->irq.level = new_level;
450469
trace_kvm_timer_update_irq(vcpu->vcpu_id, timer_irq(timer_ctx),
451470
timer_ctx->irq.level);
@@ -471,6 +490,8 @@ static void timer_emulate(struct arch_timer_context *ctx)
471490
return;
472491
}
473492

493+
kvm_timer_update_status(ctx, should_fire);
494+
474495
/*
475496
* If the timer can fire now, we don't need to have a soft timer
476497
* scheduled for the future. If the timer cannot fire at all,

arch/arm64/kvm/arm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu)
12281228
if (unlikely(!irqchip_in_kernel(vcpu->kvm)))
12291229
kvm_timer_sync_user(vcpu);
12301230

1231-
if (vcpu_has_nv(vcpu))
1231+
if (is_hyp_ctxt(vcpu))
12321232
kvm_timer_sync_nested(vcpu);
12331233

12341234
kvm_arch_vcpu_ctxsync_fp(vcpu);

0 commit comments

Comments
 (0)