From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 815BAC4167B for ; Thu, 7 Dec 2023 15:12:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2yGWyE+U9wORcTW3iNevc7caO6M9Gvq7ceJGlohDfag=; b=Q8Oj2esIanb+Ry Ca7ZDG3RZSohtBn6EcgRIPee9lJdsIY5zcFSHAmCl1d1Pu8anNGWGY0uZ/jjyeMKwlRIFuzo99lBN C1fjFYohDUQQq4J/5mCzTK09DjxWan5XVV25s4aYp2IQaQXmY9+cY9Edm8dx30OVgOPydEfNp69yo AxiaDUHzSwOn04T+vIKi0BfrzZsLaF7HZjgQx+7e4MR8i/DgzViOwirb5zPBwv2oL7EyyGX1QmdBE JQdpgadDIIpPg9DXdtS1+QqOUEn5aSPnD29MoiVsA3H6KR9dp2INoXyrx4GYfaJk+AExWhI/VZAFs BUstDQ/T9CRH8I52yM6Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rBG36-00D9K4-1V; Thu, 07 Dec 2023 15:12:24 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rBG31-00D9Fu-0g for linux-arm-kernel@lists.infradead.org; Thu, 07 Dec 2023 15:12:20 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id A2DF8CE246A; Thu, 7 Dec 2023 15:12:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB0A1C433C8; Thu, 7 Dec 2023 15:12:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1701961935; bh=bjw4PEa9SjpvxQmxru54wXvwdGXfNeLhwFsEcpsXAT8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hAphyFtZfO1h8SVG0nkPBfxunKZZHNRrYx9jUY5GVgEZCC/PWS4frBkwVvhKTaZW6 u761SZ3lpAqh/aDUKLKe1444yi2HdqD1WgzQqBjhpPwEOOj/m87Y3061vY0cTIq+cQ IzhOr09EvZm2pGlGlg2S9q8q+KccZsOuFAx86WuRXeTCPVSWdcRrgQlLHLbXUAPGwb ZZA78tzNLtFK1v2Uz0mUds4c7EYi3Q1vdMaZF9jYvd15wz8noaM00LHxe69PcjsZST XDzVtD5K7QjJQciJ5VOiyzRFyWbeOqeZTbxpVyhGmglGvaOsJ2v2fAlsrPNkFZvEkA BVscdhDS0AFMw== Received: from sofa.misterjones.org ([185.219.108.64] helo=valley-girl.lan) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1rBG2v-002FcG-Ev; Thu, 07 Dec 2023 15:12:13 +0000 From: Marc Zyngier To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Cc: James Morse , Suzuki K Poulose , Oliver Upton , Zenghui Yu , Will Deacon , vdonnefort@google.com, stable@vger.kernel.org Subject: [PATCH 1/5] KVM: arm64: vgic: Simplify kvm_vgic_destroy() Date: Thu, 7 Dec 2023 15:11:57 +0000 Message-Id: <20231207151201.3028710-2-maz@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231207151201.3028710-1-maz@kernel.org> References: <20231207151201.3028710-1-maz@kernel.org> MIME-Version: 1.0 X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, suzuki.poulose@arm.com, oliver.upton@linux.dev, yuzenghui@huawei.com, will@kernel.org, vdonnefort@google.com, stable@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231207_071219_716659_93BBFA90 X-CRM114-Status: GOOD ( 13.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When destroying a vgic, we have rather cumbersome rules about when slots_lock and config_lock are held, resulting in fun buglets. The first port of call is to simplify kvm_vgic_map_resources() so that there is only one call to kvm_vgic_destroy() instead of two, with the second only holding half of the locks. For that, we kill the non-locking primitive and move the call outside of the locking altogether. This doesn't change anything (we re-acquire the locks and teardown the whole vgic), and simplifies the code significantly. Cc: stable@vger.kernel.org Signed-off-by: Marc Zyngier --- arch/arm64/kvm/vgic/vgic-init.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/arch/arm64/kvm/vgic/vgic-init.c b/arch/arm64/kvm/vgic/vgic-init.c index c8c3cb812783..ad7e86879eb9 100644 --- a/arch/arm64/kvm/vgic/vgic-init.c +++ b/arch/arm64/kvm/vgic/vgic-init.c @@ -382,26 +382,24 @@ void kvm_vgic_vcpu_destroy(struct kvm_vcpu *vcpu) vgic_cpu->rd_iodev.base_addr = VGIC_ADDR_UNDEF; } -static void __kvm_vgic_destroy(struct kvm *kvm) +void kvm_vgic_destroy(struct kvm *kvm) { struct kvm_vcpu *vcpu; unsigned long i; - lockdep_assert_held(&kvm->arch.config_lock); + mutex_lock(&kvm->slots_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); -} -void kvm_vgic_destroy(struct kvm *kvm) -{ - mutex_lock(&kvm->arch.config_lock); - __kvm_vgic_destroy(kvm); mutex_unlock(&kvm->arch.config_lock); + mutex_unlock(&kvm->slots_lock); } /** @@ -469,25 +467,26 @@ int kvm_vgic_map_resources(struct kvm *kvm) type = VGIC_V3; } - if (ret) { - __kvm_vgic_destroy(kvm); + if (ret) goto out; - } + dist->ready = true; dist_base = dist->vgic_dist_base; mutex_unlock(&kvm->arch.config_lock); ret = vgic_register_dist_iodev(kvm, dist_base, type); - if (ret) { + if (ret) kvm_err("Unable to register VGIC dist MMIO regions\n"); - kvm_vgic_destroy(kvm); - } - mutex_unlock(&kvm->slots_lock); - return ret; + goto out_slots; out: mutex_unlock(&kvm->arch.config_lock); +out_slots: mutex_unlock(&kvm->slots_lock); + + if (ret) + kvm_vgic_destroy(kvm); + return ret; } -- 2.39.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel