From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 696A41CBA0D for ; Sun, 1 Dec 2024 13:16:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733058997; cv=none; b=Tm7Map4lHLXzOGRWyPX4A+sLHZ1Razdi5VyM7XDoqcPFxo96YXSI0XlkTLLzb7jHTvdy6E+xYGEfIJcVZSRhUK2o/DinGb/yr+srkJRG4lluihojK+c0tfu911FtoIGCle1mMNEek2FVc1cU3uVluF1A64nDPt4cHlUSQbyJTYM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733058997; c=relaxed/simple; bh=D/tMuGcuiny7dzl2GtTl+VJFpMy2gJYiFwvnFSRHGr0=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=jeXiLI0AI63QSWgon98QaJwNuiGwvZmf7b8vD+eoVtYxQBe2c3HiNN+NRmwknntiifoP/nuOhOaBSKfLutF5Kc8PI+znJvPSur8R5cqIRxdqc5l8b6JJQq8LAHLQRp5xb9ltpQPzNVLCiTbyjRaVKUUkAeSoPI2iJHa5CV8gL5o= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DeMbfrle; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DeMbfrle" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46683C4CECF; Sun, 1 Dec 2024 13:16:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1733058997; bh=D/tMuGcuiny7dzl2GtTl+VJFpMy2gJYiFwvnFSRHGr0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=DeMbfrle9NTkWZ3ejSj0oFeAXRDJo9xeGchHORzDhM8AebCoOHUtdq7+t1e0z1QKb DBj5JAXwNOSpd8AXR1jJ0jA6DW75dDBa/XuCY/3yTpmP9CQxWE737VD0VOwkNm7r4A Ha8KIOCCWkIOd2mzbbySTo3eB5bEpboyBEZRTlbdcj+leZ2fQXjwAHE4EZysueMPRQ EnW3DW0f0+DQhd3EB1UXt61N83MeJVG89n/H0A9yLekNUhuDeWe/VbgOegv/1/LDK5 R3o48Wbv1INHF+6iK/3q4MkzX4UNJ98j0NIljLbl2+dVoSF8iCdgTQ6GOX6ryCzZrF xG5t++u3vU0Eg== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tHjoR-00H5oO-5g; Sun, 01 Dec 2024 13:16:35 +0000 Date: Sun, 01 Dec 2024 13:16:34 +0000 Message-ID: <861pyrv8zx.wl-maz@kernel.org> From: Marc Zyngier To: Keisuke Nishimura Cc: Oliver Upton , Joey Gouly , Suzuki K Poulose , Zenghui Yu , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Subject: Re: [PATCH v2] KVM: arm/arm64: vgic-its: Add error handling in vgic_its_cache_translation In-Reply-To: <20241130144952.23729-1-keisuke.nishimura@inria.fr> References: <20241130144952.23729-1-keisuke.nishimura@inria.fr> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/29.4 (aarch64-unknown-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: keisuke.nishimura@inria.fr, oliver.upton@linux.dev, joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Sat, 30 Nov 2024 14:49:53 +0000, 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. > > Fixes: 8201d1028caa ("KVM: arm64: vgic-its: Maintain a translation cache per ITS") > Signed-off-by: Keisuke Nishimura > --- > 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 Acked-by: Marc Zyngier M. -- Without deviation from the norm, progress is not possible.