[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20250211000917.166856-4-mlevitsk@redhat.com>
Date: Mon, 10 Feb 2025 19:09:17 -0500
From: Maxim Levitsky <mlevitsk@...hat.com>
To: kvm@...r.kernel.org
Cc: Paolo Bonzini <pbonzini@...hat.com>,
Jing Zhang <jingzhangos@...gle.com>,
Oliver Upton <oliver.upton@...ux.dev>,
linux-arm-kernel@...ts.infradead.org,
Marc Zyngier <maz@...nel.org>,
linux-kernel@...r.kernel.org,
Randy Dunlap <rdunlap@...radead.org>,
Suzuki K Poulose <suzuki.poulose@....com>,
Palmer Dabbelt <palmer@...belt.com>,
Zenghui Yu <yuzenghui@...wei.com>,
kvm-riscv@...ts.infradead.org,
Ingo Molnar <mingo@...hat.com>,
linux-riscv@...ts.infradead.org,
Joey Gouly <joey.gouly@....com>,
Paul Walmsley <paul.walmsley@...ive.com>,
Maxim Levitsky <mlevitsk@...hat.com>,
Thomas Gleixner <tglx@...utronix.de>,
Bjorn Helgaas <bhelgaas@...gle.com>,
Albert Ou <aou@...s.berkeley.edu>,
kvmarm@...ts.linux.dev,
Alexander Potapenko <glider@...gle.com>,
x86@...nel.org,
Sean Christopherson <seanjc@...gle.com>,
Anup Patel <anup@...infault.org>,
Kunkun Jiang <jiangkunkun@...wei.com>,
Atish Patra <atishp@...shpatra.org>,
Catalin Marinas <catalin.marinas@....com>,
Will Deacon <will@...nel.org>,
Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>,
"H. Peter Anvin" <hpa@...or.com>
Subject: [PATCH 3/3] RISC-V: KVM: switch to kvm_lock/unlock_all_vcpus
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 <pbonzini@...hat.com>
Signed-off-by: Maxim Levitsky <mlevitsk@...hat.com>
---
arch/riscv/kvm/aia_device.c | 36 +++---------------------------------
1 file changed, 3 insertions(+), 33 deletions(-)
diff --git a/arch/riscv/kvm/aia_device.c b/arch/riscv/kvm/aia_device.c
index 39cd26af5a69..32354e47c7d8 100644
--- a/arch/riscv/kvm/aia_device.c
+++ b/arch/riscv/kvm/aia_device.c
@@ -12,36 +12,6 @@
#include <linux/kvm_host.h>
#include <linux/uaccess.h>
-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;
@@ -52,8 +22,8 @@ static int aia_create(struct kvm_device *dev, u32 type)
if (irqchip_in_kernel(kvm))
return -EEXIST;
- ret = -EBUSY;
- if (!lock_all_vcpus(kvm))
+ ret = kvm_lock_all_vcpus(kvm);
+ if (ret)
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.26.3
Powered by blists - more mailing lists