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 0600416B753 for ; Mon, 19 Aug 2024 12:48:41 +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=1724071722; cv=none; b=uAPAl8wQVtvQ/eJX96GEFmcSayikOWIJClr3Dv4fZEU8PbZXh13pqsn3flPo35b3zaxK6BMZYT0iCPDl19mWLWDlhdKMzOgc4I1ySnjTVb7RLO9bn7yo7KfbMgwyJNQaAj5PbqsvKV9wMoDcJYliC3nB3YFBQ+JJHUugyArkJf4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1724071722; c=relaxed/simple; bh=rJ00fmlX3u2TZClBGgRz2pCSLIEUy/YzfF3e903e8yk=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=aZsqVsjocuZzQCQDksQLEh40Q5m1mrfZP+A/NL0YEWj+mfXskVcLIeWaLbGJAs4z+2UDyYGAHoNavrU9a5Pfz3Cnz3usaYup03SLjspwJLrqSbJB700Bs9smxB2q6YLATzysQaQov7/Qt5hl7G+hBYdQHhfSKSWtTUeNZV6pwr0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=WlqT2UHV; 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="WlqT2UHV" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 820E4C4AF11; Mon, 19 Aug 2024 12:48:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1724071721; bh=rJ00fmlX3u2TZClBGgRz2pCSLIEUy/YzfF3e903e8yk=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=WlqT2UHVJ11bw9efaSi7HxgJLTWhqxkIFhqsx9WYw5Q/hOW5hsDTYsFPICwt6HP92 2G3wt/bYWIKkTFB7Ee/gKPFy0wKYUtfEUMIkv4CAoLpo3SqBR08Fu9vuWqRQh9bI+1 EmtoufYqKz4fu71fDrVB2hCBacwtJfmZjJn0FtcMkddnNyvaPXeB0t4gbihgC3QPwn O/EY2mvKRnPdQiH3YEsBlpefXW5RX9vb+CGpMIGU3jhglhy0EmvZuSyv5tOGGwCw+D r4ejylHd8UWIbrV/TDFs2V5CZ5hhTTZyYh6BAXQfqqwPEserpB+T4jYKKmHkPOzzl8 6NIa3IMzVZshg== 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 1sg1oN-004uuX-41; Mon, 19 Aug 2024 13:48:39 +0100 Date: Mon, 19 Aug 2024 13:48:38 +0100 Message-ID: <861q2kznix.wl-maz@kernel.org> From: Marc Zyngier To: Zenghui Yu Cc: , , James Morse , Suzuki K Poulose , Oliver Upton , Alexander Potapenko Subject: Re: [PATCH] KVM: arm64: vgic: Hold config_lock while tearing down a CPU interface In-Reply-To: <40d0a14b-b501-aef6-a168-1c1acd5448e7@huawei.com> References: <20240808091546.3262111-1-maz@kernel.org> <8634n0zsu0.wl-maz@kernel.org> <40d0a14b-b501-aef6-a168-1c1acd5448e7@huawei.com> 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: yuzenghui@huawei.com, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, glider@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Mon, 19 Aug 2024 13:31:59 +0100, Zenghui Yu wrote: > > On 2024/8/19 18:53, Marc Zyngier wrote: > > On Mon, 19 Aug 2024 10:39:50 +0100, > > Zenghui Yu wrote: > > > > > > Hi Marc, > > > > > > On 2024/8/8 17:15, Marc Zyngier wrote: > > > > Tearing down a vcpu CPU interface involves freeing the private interrupt > > > > array. If we don't hold the lock, we may race against another thread > > > > trying to configure it. Yeah, fuzzers do wonderful things... > > > > > > > > Taking the lock early solves this particular problem. > > > > > > > > Fixes: 03b3d00a70b5 ("KVM: arm64: vgic: Allocate private interrupts on demand") > > > > Reported-by: Alexander Potapenko > > > > Tested-by: Alexander Potapenko > > > > Signed-off-by: Marc Zyngier > > > > --- > > > > arch/arm64/kvm/vgic/vgic-init.c | 3 +-- > > > > 1 file changed, 1 insertion(+), 2 deletions(-) > > > > > > > > diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-init.c > > > > index 7f68cf58b978..41feb858ff9a 100644 > > > > --- a/arch/arm64/kvm/vgic/vgic-init.c > > > > +++ b/arch/arm64/kvm/vgic/vgic-init.c > > > > @@ -438,14 +438,13 @@ void kvm_vgic_destroy(struct kvm *kvm) > > > > unsigned long i; > > > > > > > > mutex_lock(&kvm->slots_lock); > > > > + mutex_lock(&kvm->arch.config_lock); > > > > > > > > vgic_debug_destroy(kvm); > > > > > > > > kvm_for_each_vcpu(i, vcpu, kvm) > > > > __kvm_vgic_vcpu_destroy(vcpu); > > > > > > > > - mutex_lock(&kvm->arch.config_lock); > > > > - > > > > kvm_vgic_dist_destroy(kvm); > > > > > > > > mutex_unlock(&kvm->arch.config_lock); > > > > > > The following splat was triggered when running the vgic_init selftest on > > > a lockdep kernel (I use rc4, with defconfig + PROVE_LOCKING). > > > > > > I'm not entirely sure that the splat is related to this change. Just > > > haven't got time to dig further so post it out early for record. > > > > Arghh. Thanks for reporting this. Can you try the following patch? It > > does the trick for me, but I don't trust myself anymore... > > I tested it with defconfig+PROVE_LOCKING and my own config, both worked > for me (the WARNING disappeared). I think the locking order should be > correct now. Awesome. Let me post a proper patch right away. Thanks again, M. -- Without deviation from the norm, progress is not possible.