Subject: Re: [PATCH 2/4] KVM: arm64: timer: Kill the per-timer level cache

From: Marc Zyngier <[email-masked]>
Date: Fri, 17 Apr 2026 16:56:35 +0100

On Fri, 17 Apr 2026 13:46:10 +0100,
Marc Zyngier <[email-masked]> wrote:
> 
> The timer code makes use of a per-timer irq level cache, which
> looks like a very minor optimisation to avoid taking a lock upon
> updating the GIC view of the interrupt when it is unchanged from
> the previous state.
> 
> This is coming in the way of more important correctness issues,
> so get rid of the cache, which simplifies a couple of minor things.
> 
> Signed-off-by: Marc Zyngier <[email-masked]>
> ---
>  arch/arm64/kvm/arch_timer.c  | 18 +++++++++---------
>  include/kvm/arm_arch_timer.h |  5 -----
>  2 files changed, 9 insertions(+), 14 deletions(-)
> 
> diff --git a/arch/arm64/kvm/arch_timer.c b/arch/arm64/kvm/arch_timer.c
> index d6802fc87e085..fdc1afff06340 100644
> --- a/arch/arm64/kvm/arch_timer.c
> +++ b/arch/arm64/kvm/arch_timer.c
> @@ -446,9 +446,8 @@ static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level,
>  {
>  	kvm_timer_update_status(timer_ctx, new_level);
>  
> -	timer_ctx->irq.level = new_level;
>  	trace_kvm_timer_update_irq(vcpu->vcpu_id, timer_irq(timer_ctx),
> -				   timer_ctx->irq.level);
> +				   new_level);
>  
>  	if (userspace_irqchip(vcpu->kvm))
>  		return;
> @@ -466,7 +465,7 @@ static void kvm_timer_update_irq(struct kvm_vcpu *vcpu, bool new_level,
>  
>  	kvm_vgic_inject_irq(vcpu->kvm, vcpu,
>  			    timer_irq(timer_ctx),
> -			    timer_ctx->irq.level,
> +			    new_level,
>  			    timer_ctx);
>  }
>  
> @@ -477,8 +476,7 @@ static void timer_emulate(struct arch_timer_context *ctx)
>  
>  	trace_kvm_timer_emulate(ctx, pending);
>  
> -	if (pending != ctx->irq.level)
> -		kvm_timer_update_irq(timer_context_to_vcpu(ctx), pending, ctx);
> +	kvm_timer_update_irq(timer_context_to_vcpu(ctx), pending, ctx);
>  
>  	kvm_timer_update_status(ctx, pending);

As my new best mate Sashiko pointed out, kvm_timer_update_status()
here becomes redundant, as the unconditional call to
kvm_timer_update_irq() already contains that.

I'll drop it from the patch when applying, unless there are more
comments.

Thanks,

	M.

-- 
Without deviation from the norm, progress is not possible.