Re: [PATCH 09/15] KVM: arm64: vgic: Ensure the irq refcount is nonzero when taking a ref

Marc Zyngier
2024-01-25T10:08:31Z

On Wed, 24 Jan 2024 20:49:03 +0000,
Oliver Upton <oliver.upton@linux.dev> wrote:
>
> It will soon be possible for get() and put() calls to happen in
> parallel, which means in most cases we must ensure the refcount is
> nonzero when taking a new reference. Switch to using
> vgic_try_get_irq_kref() where necessary, and document the few conditions
> where an IRQ's refcount is guaranteed to be nonzero.
>
> Signed-off-by: Oliver Upton <oliver.upton@linux.dev>
> ---
> arch/arm64/kvm/vgic/vgic-its.c | 18 ++++++++----------
> arch/arm64/kvm/vgic/vgic.c | 3 ++-
> 2 files changed, 10 insertions(+), 11 deletions(-)
>
> diff --git a/arch/arm64/kvm/vgic/vgic-its.c b/arch/arm64/kvm/vgic/vgic-its.c
> index 1d912a595b71..7219f4a0a93d 100644
> --- a/arch/arm64/kvm/vgic/vgic-its.c
> +++ b/arch/arm64/kvm/vgic/vgic-its.c
> @@ -75,18 +75,11 @@ static struct vgic_irq *vgic_add_lpi(struct kvm *kvm, u32 intid,
> * check that we don't add a second list entry with the same LPI.
> */
> oldirq = xa_load(&dist->lpi_xa, intid);
> - if (oldirq) {
> + if (oldirq && vgic_try_get_irq_kref(oldirq)) {

nit: move the NULL-check inside the helper, since you always have to
do it.

Thanks,

M.

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