Skip to content

Commit be7e611

Browse files
mu-mu-muoupton
authored andcommitted
KVM: arm64: vgic-its: Add error handling in vgic_its_cache_translation
The return value of xa_store() needs to be checked. This fix adds an error handling path that resolves the kref inconsistency on failure. As suggested by Oliver Upton, this function does not return the error code intentionally because the translation cache is best effort. Fixes: 8201d10 ("KVM: arm64: vgic-its: Maintain a translation cache per ITS") Signed-off-by: Keisuke Nishimura <keisuke.nishimura@inria.fr> Suggested-by: Oliver Upton <oliver.upton@linux.dev> Acked-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20241130144952.23729-1-keisuke.nishimura@inria.fr Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
1 parent 03c7527 commit be7e611

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

arch/arm64/kvm/vgic/vgic-its.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,12 +608,22 @@ static void vgic_its_cache_translation(struct kvm *kvm, struct vgic_its *its,
608608
lockdep_assert_held(&its->its_lock);
609609
vgic_get_irq_kref(irq);
610610

611+
old = xa_store(&its->translation_cache, cache_key, irq, GFP_KERNEL_ACCOUNT);
612+
613+
/*
614+
* Put the reference taken on @irq if the store fails. Intentionally do
615+
* not return the error as the translation cache is best effort.
616+
*/
617+
if (xa_is_err(old)) {
618+
vgic_put_irq(kvm, irq);
619+
return;
620+
}
621+
611622
/*
612623
* We could have raced with another CPU caching the same
613624
* translation behind our back, ensure we don't leak a
614625
* reference if that is the case.
615626
*/
616-
old = xa_store(&its->translation_cache, cache_key, irq, GFP_KERNEL_ACCOUNT);
617627
if (old)
618628
vgic_put_irq(kvm, old);
619629
}

0 commit comments

Comments
 (0)