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 3D650C369D9 for ; Wed, 30 Apr 2025 21:31:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=BS8KXzrmvGXfGPLTK0QPoSu9Lo1T2ypTVK/CISvD5is=; b=ecLRB6UQlUZ/MZ6Py/sgv9zm9d 63ympEa4htf9AjzVl+BQpn34xkg7aKyWYEJove95aUBFBhbSGYlvidN4AsEunmL5aio1DmiKxip6E 0678jwPK0JJgRdqtGGIhnltQgjdBgfIrEKJT5z2zz4/4C8PXUFsR3V1d7MGubVIJDSmH2Mr7M9Alx gXC379uIsHaxCU755gcne/fFlQ5Ck9TnEPw/3uKcCHuRjqx9GgPb6WvbRnOKpEXLBe2KNdwigmKWS 1vJztsR/ZK+RqpkmMVrok9iaHVEy7/OmARPd/YC8qTJZLApcGTY5tqRl1mrX42HgPzcdcSwbqckyv WJY04yTg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1uAF1c-0000000E4jb-2PFM; Wed, 30 Apr 2025 21:31:28 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1uADy6-0000000Du3E-2NWQ for linux-arm-kernel@lists.infradead.org; Wed, 30 Apr 2025 20:23:48 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1746044625; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BS8KXzrmvGXfGPLTK0QPoSu9Lo1T2ypTVK/CISvD5is=; b=IcN7RMt/JbPgiyckKSK8W1RbkcTDM0MlYmhLJsxab/J6IpnHWOjzRszK6u/wkSqbSNElbb IfWHAvjUVXnMC720FdP6XplD4J+5GovI2uXuKSJZE6eRHRC60kjEXBiqOX1Wndyud4oqUf pv+Pbby1enkadYrgH/lkpzz6wfXmgv8= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-256-KSV1yo6aOLK_dziPEOyoDQ-1; Wed, 30 Apr 2025 16:23:42 -0400 X-MC-Unique: KSV1yo6aOLK_dziPEOyoDQ-1 X-Mimecast-MFC-AGG-ID: KSV1yo6aOLK_dziPEOyoDQ_1746044617 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 65AB71800368; Wed, 30 Apr 2025 20:23:36 +0000 (UTC) Received: from intellaptop.lan (unknown [10.22.80.5]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 10DA51800878; Wed, 30 Apr 2025 20:23:29 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: "H. Peter Anvin" , x86@kernel.org, Maxim Levitsky , Randy Dunlap , Paolo Bonzini , Will Deacon , Oliver Upton , Kunkun Jiang , Jing Zhang , Albert Ou , Keisuke Nishimura , Anup Patel , Catalin Marinas , Atish Patra , kvmarm@lists.linux.dev, Waiman Long , Boqun Feng , linux-arm-kernel@lists.infradead.org, Peter Zijlstra , Dave Hansen , Paul Walmsley , Suzuki K Poulose , Zenghui Yu , Sebastian Ott , Andre Przywara , Ingo Molnar , Alexandre Ghiti , Bjorn Helgaas , Palmer Dabbelt , Joey Gouly , Borislav Petkov , Sean Christopherson , Marc Zyngier , Alexander Potapenko , Thomas Gleixner , linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, Shusen Li , kvm-riscv@lists.infradead.org Subject: [PATCH v3 2/4] RISC-V: KVM: switch to kvm_lock/unlock_all_vcpus Date: Wed, 30 Apr 2025 16:23:09 -0400 Message-ID: <20250430202311.364641-3-mlevitsk@redhat.com> In-Reply-To: <20250430202311.364641-1-mlevitsk@redhat.com> References: <20250430202311.364641-1-mlevitsk@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250430_132346_713186_A09780C0 X-CRM114-Status: GOOD ( 13.98 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Use the kvm_trylock_all_vcpus()/unlock_all_vcpus() instead of riscv's own implementation, to avoid triggering a lockdep warning, if the VM is configured to have more than MAX_LOCK_DEPTH vCPUs. Compile tested only. Suggested-by: Paolo Bonzini Signed-off-by: Maxim Levitsky --- arch/riscv/kvm/aia_device.c | 34 ++-------------------------------- 1 file changed, 2 insertions(+), 32 deletions(-) diff --git a/arch/riscv/kvm/aia_device.c b/arch/riscv/kvm/aia_device.c index 39cd26af5a69..6315821f0d69 100644 --- a/arch/riscv/kvm/aia_device.c +++ b/arch/riscv/kvm/aia_device.c @@ -12,36 +12,6 @@ #include #include -static void unlock_vcpus(struct kvm *kvm, int vcpu_lock_idx) -{ - struct kvm_vcpu *tmp_vcpu; - - for (; vcpu_lock_idx >= 0; vcpu_lock_idx--) { - tmp_vcpu = kvm_get_vcpu(kvm, vcpu_lock_idx); - mutex_unlock(&tmp_vcpu->mutex); - } -} - -static void unlock_all_vcpus(struct kvm *kvm) -{ - unlock_vcpus(kvm, atomic_read(&kvm->online_vcpus) - 1); -} - -static bool lock_all_vcpus(struct kvm *kvm) -{ - struct kvm_vcpu *tmp_vcpu; - unsigned long c; - - kvm_for_each_vcpu(c, tmp_vcpu, kvm) { - if (!mutex_trylock(&tmp_vcpu->mutex)) { - unlock_vcpus(kvm, c - 1); - return false; - } - } - - return true; -} - static int aia_create(struct kvm_device *dev, u32 type) { int ret; @@ -53,7 +23,7 @@ static int aia_create(struct kvm_device *dev, u32 type) return -EEXIST; ret = -EBUSY; - if (!lock_all_vcpus(kvm)) + if (kvm_trylock_all_vcpus(kvm)) return ret; kvm_for_each_vcpu(i, vcpu, kvm) { @@ -65,7 +35,7 @@ static int aia_create(struct kvm_device *dev, u32 type) kvm->arch.aia.in_kernel = true; out_unlock: - unlock_all_vcpus(kvm); + kvm_unlock_all_vcpus(kvm); return ret; } -- 2.46.0