* [PATCH v2] KVM: arm/arm64: vgic-its: Add error handling in vgic_its_cache_translation
@ 2024-11-30 14:49 Keisuke Nishimura
2024-12-01 13:16 ` Marc Zyngier
2024-12-04 0:38 ` Oliver Upton
0 siblings, 2 replies; 3+ messages in thread
From: Keisuke Nishimura @ 2024-11-30 14:49 UTC (permalink / raw)
To: Marc Zyngier, Oliver Upton, Joey Gouly, Suzuki K Poulose,
Zenghui Yu
Cc: linux-arm-kernel, kvmarm, Keisuke Nishimura
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: 8201d1028caa ("KVM: arm64: vgic-its: Maintain a translation cache per ITS")
Signed-off-by: Keisuke Nishimura <keisuke.nishimura@inria.fr>
---
arch/arm64/kvm/vgic/vgic-its.c | 12 +++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)
diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c
index 198296933e7e..a08835d00aba 100644
--- a/arch/arm64/kvm/vgic/vgic-its.c
+++ b/arch/arm64/kvm/vgic/vgic-its.c
@@ -573,12 +573,22 @@ static void vgic_its_cache_translation(struct kvm *kvm, struct vgic_its *its,
lockdep_assert_held(&its->its_lock);
vgic_get_irq_kref(irq);
+ old = xa_store(&its->translation_cache, cache_key, irq, GFP_KERNEL_ACCOUNT);
+
+ /*
+ * Put the reference taken on @irq if the store fails. Intentionally do
+ * not return the error as the translation cache is best effort.
+ */
+ if (xa_is_err(old)) {
+ vgic_put_irq(kvm, irq);
+ return;
+ }
+
/*
* We could have raced with another CPU caching the same
* translation behind our back, ensure we don't leak a
* reference if that is the case.
*/
- old = xa_store(&its->translation_cache, cache_key, irq, GFP_KERNEL_ACCOUNT);
if (old)
vgic_put_irq(kvm, old);
}
--
2.34.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2] KVM: arm/arm64: vgic-its: Add error handling in vgic_its_cache_translation
2024-11-30 14:49 [PATCH v2] KVM: arm/arm64: vgic-its: Add error handling in vgic_its_cache_translation Keisuke Nishimura
@ 2024-12-01 13:16 ` Marc Zyngier
2024-12-04 0:38 ` Oliver Upton
1 sibling, 0 replies; 3+ messages in thread
From: Marc Zyngier @ 2024-12-01 13:16 UTC (permalink / raw)
To: Keisuke Nishimura
Cc: Oliver Upton, Joey Gouly, Suzuki K Poulose, Zenghui Yu,
linux-arm-kernel, kvmarm
On Sat, 30 Nov 2024 14:49:53 +0000,
Keisuke Nishimura <keisuke.nishimura@inria.fr> wrote:
>
> 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: 8201d1028caa ("KVM: arm64: vgic-its: Maintain a translation cache per ITS")
> Signed-off-by: Keisuke Nishimura <keisuke.nishimura@inria.fr>
> ---
> arch/arm64/kvm/vgic/vgic-its.c | 12 +++++++++++-
> 1 file changed, 11 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c
> index 198296933e7e..a08835d00aba 100644
> --- a/arch/arm64/kvm/vgic/vgic-its.c
> +++ b/arch/arm64/kvm/vgic/vgic-its.c
> @@ -573,12 +573,22 @@ static void vgic_its_cache_translation(struct kvm *kvm, struct vgic_its *its,
> lockdep_assert_held(&its->its_lock);
> vgic_get_irq_kref(irq);
>
> + old = xa_store(&its->translation_cache, cache_key, irq, GFP_KERNEL_ACCOUNT);
> +
> + /*
> + * Put the reference taken on @irq if the store fails. Intentionally do
> + * not return the error as the translation cache is best effort.
> + */
> + if (xa_is_err(old)) {
> + vgic_put_irq(kvm, irq);
> + return;
> + }
> +
> /*
> * We could have raced with another CPU caching the same
> * translation behind our back, ensure we don't leak a
> * reference if that is the case.
> */
> - old = xa_store(&its->translation_cache, cache_key, irq, GFP_KERNEL_ACCOUNT);
> if (old)
> vgic_put_irq(kvm, old);
> }
Suggested-by: Oliver Upton <oliver.upton@linux.dev>
Acked-by: Marc Zyngier <maz@kernel.org>
M.
--
Without deviation from the norm, progress is not possible.
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH v2] KVM: arm/arm64: vgic-its: Add error handling in vgic_its_cache_translation
2024-11-30 14:49 [PATCH v2] KVM: arm/arm64: vgic-its: Add error handling in vgic_its_cache_translation Keisuke Nishimura
2024-12-01 13:16 ` Marc Zyngier
@ 2024-12-04 0:38 ` Oliver Upton
1 sibling, 0 replies; 3+ messages in thread
From: Oliver Upton @ 2024-12-04 0:38 UTC (permalink / raw)
To: Marc Zyngier, Joey Gouly, Suzuki K Poulose, Zenghui Yu,
Keisuke Nishimura
Cc: Oliver Upton, linux-arm-kernel, kvmarm
On Sat, 30 Nov 2024 15:49:53 +0100, Keisuke Nishimura wrote:
> 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.
>
>
Applied to fixes, thanks!
[1/1] KVM: arm/arm64: vgic-its: Add error handling in vgic_its_cache_translation
https://git.kernel.org/kvmarm/kvmarm/c/be7e61127422
--
Best,
Oliver
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-12-04 0:39 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-30 14:49 [PATCH v2] KVM: arm/arm64: vgic-its: Add error handling in vgic_its_cache_translation Keisuke Nishimura
2024-12-01 13:16 ` Marc Zyngier
2024-12-04 0:38 ` Oliver Upton
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.