From patchwork Tue Feb 11 00:09:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Levitsky X-Patchwork-Id: 13969392 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 6BD89C021A5 for ; Tue, 11 Feb 2025 02:41:00 +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=Pb2F1q7Ej/HYhvWWvl4zLv60lvgzzL+xFHN1k+Ixx4Y=; b=lPk6O1DwPfNuVX TSpYDy1r7VvuSc/QoEUcOoogEpFA218KSHKbW47UDsB/L+gxW0XRhl2JBDtBMzJgASto8L96U0ed1 GrdnL30LIPurf4S8+KcrIBtv3xvKmIGuP0sFLCSLrxCBx+mq77ze5LytXzqGYJbH9sll2cO+NOgHX /9EcxUjpqJ14EEe20crqV5o4X/VWCXlbQcYSePX1s98ZbDtyFrMfIDIOUkLn4dopDDBtrVWf/iSAZ eUX8QCY9pG3pupLEjC4SfKlxibPCAYQVSSYnfd2sjDG7SQNQodet8T+WgvIKAMY/8/51ucpVyTJIT LRjL/3meZVy6TD0NSOdw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1thgCl-00000002ITp-41vN; Tue, 11 Feb 2025 02:40:55 +0000 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1thdrz-00000001wWA-1zE0 for linux-riscv@lists.infradead.org; Tue, 11 Feb 2025 00:11:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1739232678; 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=yzGbC0ypbw1NU4jMljSKqdqWfQ9LORCBGxC9rZKevfg=; b=YToedk+Lg/Tg9bH/6JEBqbLTbj9DrBY6Kth9aQqAWs9Dc0yH6xMIWf2bHbBtmlBF1gUX+X daV6U8JV13eEwCMPopizcLWPbt8aXbmyVYTgUPqQFEzhlTjRBLhGUXEJ3MzkKJWC3UasOG TTcHwnbFNh68gQFGgpcfb0AQRnvrfPY= Received: from mx-prod-mc-06.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-556-rxU9z2ZwPoCLLQlMQjJc6g-1; Mon, 10 Feb 2025 19:09:48 -0500 X-MC-Unique: rxU9z2ZwPoCLLQlMQjJc6g-1 X-Mimecast-MFC-AGG-ID: rxU9z2ZwPoCLLQlMQjJc6g Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BECC31800983; Tue, 11 Feb 2025 00:09:44 +0000 (UTC) Received: from starship.lan (unknown [10.22.65.174]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 006BA19560A3; Tue, 11 Feb 2025 00:09:38 +0000 (UTC) From: Maxim Levitsky To: kvm@vger.kernel.org Cc: Paolo Bonzini , Jing Zhang , Oliver Upton , linux-arm-kernel@lists.infradead.org, Marc Zyngier , linux-kernel@vger.kernel.org, Randy Dunlap , Suzuki K Poulose , Palmer Dabbelt , Zenghui Yu , kvm-riscv@lists.infradead.org, Ingo Molnar , linux-riscv@lists.infradead.org, Joey Gouly , Paul Walmsley , Maxim Levitsky , Thomas Gleixner , Bjorn Helgaas , Albert Ou , kvmarm@lists.linux.dev, Alexander Potapenko , x86@kernel.org, Sean Christopherson , Anup Patel , Kunkun Jiang , Atish Patra , Catalin Marinas , Will Deacon , Borislav Petkov , Dave Hansen , "H. Peter Anvin" Subject: [PATCH 3/3] RISC-V: KVM: switch to kvm_lock/unlock_all_vcpus Date: Mon, 10 Feb 2025 19:09:17 -0500 Message-Id: <20250211000917.166856-4-mlevitsk@redhat.com> In-Reply-To: <20250211000917.166856-1-mlevitsk@redhat.com> References: <20250211000917.166856-1-mlevitsk@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250210_161119_656313_8674E704 X-CRM114-Status: GOOD ( 11.87 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org 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 | 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 #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; @@ -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; }