From nobody Sun Feb 8 17:42:54 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 06A0E18A93C for ; Wed, 9 Apr 2025 01:42:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744162938; cv=none; b=NfUo0Enl3Eaq+8iBxtVi7prZdbbkjOCdIeFv9d0y1Ob/RQRdb4PIs7nZScDz75+sMa9tGBXbeP27s+iWdR2KZ7Wvu7+5ncTJC2BNeV299IRLCIYp8YtOPNSRUnno1MhPWgJfyQ4FHNIyGvvoCHpFp6Jrz85ILwijgsDLkZv2gU0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744162938; c=relaxed/simple; bh=riqkQ1t8/h7MsJZAxC/eXgF19eg6YzSjLsP+88GFCKQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=A14gwGHpkAgje3F7e0+wrvdaD2fBK51I4bQsRuNOd3kEBMIsS84Fgt06ozGTPZ+kdq0Prye1krLoflmIVEgZQ6LgnYfJ50pbcXsFbV8eIegKjBjGgqLwVwEy5blg8jN+Y8Ub0i9fUYXi1LiT71XXytEBz8Irt3UoczHhPFnokWU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=MXdwDC6U; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="MXdwDC6U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1744162936; 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=z1kcoAyb5oE1yadCC0yo8lvxmOIeYp6wUMScV/KBS/Y=; b=MXdwDC6Ulg6qjIqg9eLPJf+A4oSBMnpSqELop/OAIrcxWmPRQ88plNAJ7etL3Yi+PTYirH 1k7wDPxqtgWv9kd1ZLRSv5IUnOjccBI9AUdZGntwOAygGL+BWv/WbgjO2CcOe38H5nKrZk QiAPts5G4HItx3v006PRQ/dP1uGD0qI= 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-204-FfZk7JGCPmS8NemWl-m-0g-1; Tue, 08 Apr 2025 21:42:14 -0400 X-MC-Unique: FfZk7JGCPmS8NemWl-m-0g-1 X-Mimecast-MFC-AGG-ID: FfZk7JGCPmS8NemWl-m-0g_1744162930 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 E85E0180899B; Wed, 9 Apr 2025 01:42:09 +0000 (UTC) Received: from starship.lan (unknown [10.22.65.191]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C53151801766; Wed, 9 Apr 2025 01:42:04 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Alexander Potapenko , "H. Peter Anvin" , Suzuki K Poulose , kvm-riscv@lists.infradead.org, Oliver Upton , Dave Hansen , Jing Zhang , Waiman Long , x86@kernel.org, Kunkun Jiang , Boqun Feng , Anup Patel , Albert Ou , kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org, Zenghui Yu , Borislav Petkov , Alexandre Ghiti , Keisuke Nishimura , Sebastian Ott , Paolo Bonzini , Atish Patra , Paul Walmsley , Randy Dunlap , Will Deacon , Palmer Dabbelt , linux-riscv@lists.infradead.org, Marc Zyngier , linux-arm-kernel@lists.infradead.org, Joey Gouly , Peter Zijlstra , Ingo Molnar , Andre Przywara , Thomas Gleixner , Sean Christopherson , Catalin Marinas , Maxim Levitsky , Bjorn Helgaas Subject: [PATCH v2 4/4] RISC-V: KVM: switch to kvm_lock/unlock_all_vcpus Date: Tue, 8 Apr 2025 21:41:36 -0400 Message-Id: <20250409014136.2816971-5-mlevitsk@redhat.com> In-Reply-To: <20250409014136.2816971-1-mlevitsk@redhat.com> References: <20250409014136.2816971-1-mlevitsk@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Type: text/plain; charset="utf-8" use kvm_lock/unlock_all_vcpus instead of riscv's own implementation. Note that this does introduce a slight functional change - now vCPUs are unlocked in the same order they were locked and not in the opposite order. 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..a4599de98c6b 100644 --- a/arch/riscv/kvm/aia_device.c +++ b/arch/riscv/kvm/aia_device.c @@ -12,36 +12,6 @@ #include #include =20 -static void unlock_vcpus(struct kvm *kvm, int vcpu_lock_idx) -{ - struct kvm_vcpu *tmp_vcpu; - - for (; vcpu_lock_idx >=3D 0; vcpu_lock_idx--) { - tmp_vcpu =3D 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; =20 ret =3D -EBUSY; - if (!lock_all_vcpus(kvm)) + if (kvm_lock_all_vcpus(kvm, true)) return ret; =20 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 =3D true; =20 out_unlock: - unlock_all_vcpus(kvm); + kvm_unlock_all_vcpus(kvm); return ret; } =20 --=20 2.26.3