From patchwork Sun Sep 25 16:23:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12988039 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 F26EDC6FA8E for ; Sun, 25 Sep 2022 16:33:53 +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=NmtBobFiH7r+ProJaW79McZXMAzF1c91qTAisFHeB9o=; b=dSINCYmjeqCEGA /VfRk4+wgycUEzeypKTE+pMRMRcd5Tz8JXhMvnIAKyu/TVNYGY1bsYdr0+kN051hnbRBqi6t0dAuX bL4xFp3A2yZuV030si5FQArQ+8v2wetvZKtdwhHkM7xqT1uxi186J3NEqIA7AgDVUE78if6+fvYtD qJsdboO/yfEte6dZxkNqhqq3BZN4eTDl/SxWRnWABQz8UF0t0yJ5+vvemo5ntI+3e3lSHzIWld3vj S4B8EyD5K+mWIR57RioxflNZ125LP6fJfTjjxzmlyViASq+3fWDns/VxZHs0dkHsF5JQkdMEE52zK xEE4dmechR07iYlYAy2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ocUZX-00EwSK-Ms; Sun, 25 Sep 2022 16:33:39 +0000 Received: from ams.source.kernel.org ([2604:1380:4601:e00::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ocUZR-00EwNf-PA; Sun, 25 Sep 2022 16:33:35 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id D5A49B8075E; Sun, 25 Sep 2022 16:33:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A38BCC433D6; Sun, 25 Sep 2022 16:33:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664123610; bh=X2tPBwFu7XVmB6phIN9skedNXoCQvadtocOI5Ou7AtQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TPdRfvFtW0WRhW9C4udt05mWeCWMspx7nilWZiXVlW7y31giIEBECAHp1NmrSnOcI u1b0R0S6CmsbijTb4AJBolW0v6gjmwjCELmXkr/169bervoD2kUf/qrk4Ezlyd0sdj rlyx5Q/5TUP3I1D5Qgiq/Pa9XZCSkGWITBXIIbZTbTxLZKXSUYCqNz6+UdX02D7hU+ NlwHtkPRUzkTtXQUHlK0qrP+fFYoO7n479+nnBbn+tWp3hHH1xnnw/xf+mFe5CvF+n TF1oXM+GP94ECdFAWSgasVpSsKUtMd3+D++TeScxKoDJPu5NS97pAOmSa7qDTPxfXL mxGW5mEfWrZjg== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Subject: [PATCH v3 1/3] RISC-V: KVM: Record number of signal exits as a vCPU stat Date: Mon, 26 Sep 2022 00:23:58 +0800 Message-Id: <20220925162400.1606-2-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220925162400.1606-1-jszhang@kernel.org> References: <20220925162400.1606-1-jszhang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220925_093333_979986_3CDDE0C9 X-CRM114-Status: GOOD ( 10.15 ) 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 Record a statistic indicating the number of times a vCPU has exited due to a pending signal. Signed-off-by: Jisheng Zhang Reviewed-by: Guo Ren --- arch/riscv/include/asm/kvm_host.h | 1 + arch/riscv/kvm/vcpu.c | 2 ++ 2 files changed, 3 insertions(+) diff --git a/arch/riscv/include/asm/kvm_host.h b/arch/riscv/include/asm/kvm_host.h index 60c517e4d576..dbbf43d52623 100644 --- a/arch/riscv/include/asm/kvm_host.h +++ b/arch/riscv/include/asm/kvm_host.h @@ -67,6 +67,7 @@ struct kvm_vcpu_stat { u64 mmio_exit_kernel; u64 csr_exit_user; u64 csr_exit_kernel; + u64 signal_exits; u64 exits; }; diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index d0f08d5b4282..3da459fedc28 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -28,6 +28,7 @@ const struct _kvm_stats_desc kvm_vcpu_stats_desc[] = { STATS_DESC_COUNTER(VCPU, mmio_exit_kernel), STATS_DESC_COUNTER(VCPU, csr_exit_user), STATS_DESC_COUNTER(VCPU, csr_exit_kernel), + STATS_DESC_COUNTER(VCPU, signal_exits), STATS_DESC_COUNTER(VCPU, exits) }; @@ -973,6 +974,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) if (signal_pending(current)) { ret = -EINTR; run->exit_reason = KVM_EXIT_INTR; + ++vcpu->stat.signal_exits; } /* From patchwork Sun Sep 25 16:23:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12988040 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 2FAA9C6FA82 for ; Sun, 25 Sep 2022 16:33:53 +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=abbvMNr5jBzNZJhx2zMqpfx5BiGJuX9cAreRE+bYyfA=; b=E6lPxij2cj6fi6 IAVunrkVQnXXemgXYKfpZUL4BcUe3IR7N6rSAcqFy+6/L8XGxhQrHoAIFAEyWIoGqzGQmy84KzSSV uPRnN4wYJKsrYv/36kEjZHGlVboZvl6bx+8X9yTfQ5z/kskxWXWMpsKEpPctZVYHH4FgEoU8clk5h MILtln3QL7Hyd702m6C90EzKE8znP1hnLytRFbhJTq3MS/ZLOa98P0RT19HH2A1b6upDwMmrMoZmO h19MZQVoOnSkDbDPrBI40hJlS62bQIjf6AEw4Iub7uPh5YTfR1W1n36haEMbKhwbT5tIM/mO/+HLc syMtnrfFrlN8bNR4iNRA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ocUZb-00EwVB-2l; Sun, 25 Sep 2022 16:33:43 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ocUZT-00EwOj-7w; Sun, 25 Sep 2022 16:33:36 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A14AE6103C; Sun, 25 Sep 2022 16:33:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 196BCC433C1; Sun, 25 Sep 2022 16:33:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664123613; bh=gEVSZo6IZOnVd4BVQuHJHN2F00a6Y7EMFpgV8m6o8aI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WIdEn7WYr3y/rpGD9loAckzLSySmgfgp9dyLicUsMfjjwdn40cLuN6zLLj/LOV9Nt w7+0SOOs6WSK8DMfhBCdUEZxebtKCMKrVB5goKF1Kb8XEiPr+NwjkgijP9GjQF3l7C WyHw1FOIynVG+LrVeAgZu8sC73ZZ+13s/gGI0an6PJKx2ACr7p9QeLDjlO2adlyJQE OZ9DMtTFSyq7GsfuNfX1jtojKvTksuDbkOx0AKUxBaE4u9RhaEjyaNrF0KVYtL/Hnb 4tk8/VMxL0skJxsU6cEywngiUcasms2wim1spP3albK3bob826eHX0WIcy1uGM9LNO L4aeTag7IZXcw== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Subject: [PATCH v3 2/3] RISC-V: KVM: Use generic guest entry infrastructure Date: Mon, 26 Sep 2022 00:23:59 +0800 Message-Id: <20220925162400.1606-3-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220925162400.1606-1-jszhang@kernel.org> References: <20220925162400.1606-1-jszhang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220925_093335_395424_98BF7410 X-CRM114-Status: GOOD ( 12.65 ) 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 generic guest entry infrastructure to properly handle TIF_NOTIFY_RESUME. Signed-off-by: Jisheng Zhang --- arch/riscv/kvm/Kconfig | 1 + arch/riscv/kvm/vcpu.c | 18 ++++++------------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/arch/riscv/kvm/Kconfig b/arch/riscv/kvm/Kconfig index f5a342fa1b1d..f36a737d5f96 100644 --- a/arch/riscv/kvm/Kconfig +++ b/arch/riscv/kvm/Kconfig @@ -24,6 +24,7 @@ config KVM select PREEMPT_NOTIFIERS select KVM_MMIO select KVM_GENERIC_DIRTYLOG_READ_PROTECT + select KVM_XFER_TO_GUEST_WORK select HAVE_KVM_VCPU_ASYNC_IOCTL select HAVE_KVM_EVENTFD select SRCU diff --git a/arch/riscv/kvm/vcpu.c b/arch/riscv/kvm/vcpu.c index 3da459fedc28..e3e6b8608288 100644 --- a/arch/riscv/kvm/vcpu.c +++ b/arch/riscv/kvm/vcpu.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -959,7 +960,9 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) run->exit_reason = KVM_EXIT_UNKNOWN; while (ret > 0) { /* Check conditions before entering the guest */ - cond_resched(); + ret = xfer_to_guest_mode_handle_work(vcpu); + if (!ret) + ret = 1; kvm_riscv_gstage_vmid_update(vcpu); @@ -967,16 +970,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) local_irq_disable(); - /* - * Exit if we have a signal pending so that we can deliver - * the signal to user space. - */ - if (signal_pending(current)) { - ret = -EINTR; - run->exit_reason = KVM_EXIT_INTR; - ++vcpu->stat.signal_exits; - } - /* * Ensure we set mode to IN_GUEST_MODE after we disable * interrupts and before the final VCPU requests check. @@ -999,7 +992,8 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) if (ret <= 0 || kvm_riscv_gstage_vmid_ver_changed(&vcpu->kvm->arch.vmid) || - kvm_request_pending(vcpu)) { + kvm_request_pending(vcpu) || + xfer_to_guest_mode_work_pending()) { vcpu->mode = OUTSIDE_GUEST_MODE; local_irq_enable(); kvm_vcpu_srcu_read_lock(vcpu); From patchwork Sun Sep 25 16:24:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 12988041 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 19B22C04A95 for ; Sun, 25 Sep 2022 16:33:58 +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=zLA8E7Q/vVuvXayHapXg3ztCFPrsHQ2pIpoB1tujQXs=; b=LYNDsMuMVQq7ar cA5oRr2FMecOvHhQN2K2s1K77dhXKeK1ST+lFbMtYit0uvUMsiYT8OreaihdShMmmupsrwa2y3vwE 963lO4BT+J2EDD+WxBwLl/3Ne7FslQ8FjsiSEk8hUq/k3QzGSVsSORTXSKc7+XM/mbUVertAhEHCa EXjB8fMUhMSZbl+Lqw6P0qDKHfTm9Ae205gD4/r5kKgGATONAiYZ+zn33bq3sZ1YSXn6WuCnqmk14 +hPmCnaZWXOYWaFht36bPEeuvIfCBGWX9oa5YV8255zdvnqSx4rvNBPzz2LdHevmSiFgOLIxJPN77 IdNRpiBw30xjMLlDBD/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ocUZf-00EwZ4-Sl; Sun, 25 Sep 2022 16:33:48 +0000 Received: from dfw.source.kernel.org ([2604:1380:4641:c500::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1ocUZV-00EwQa-Nq; Sun, 25 Sep 2022 16:33:39 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2762B6132F; Sun, 25 Sep 2022 16:33:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 837F4C433D6; Sun, 25 Sep 2022 16:33:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664123615; bh=RRltkuwJX7LP5kK/3k3rhHeIM5Hot3r7Dzu5sm7vQRo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sjlJCcJV0QLRS/2I5WmZcRYy+Fq+ZGX664xoh7M7CFkrLCN2vCY45z/EooBFQ0YHV u3Q29Vpvh/y/bGaGHTl3lEjVDZHm9SM9um6UV9VFdQX+M+x+7a2pWsRcHVcGmX2NWZ tAQKB71huoS7KtZZGo55h0YFq0jgkE4fSbCL65Ult0LCuQUsBdWQnuxqmY6FBTlQ60 vyqHgyrCjH+LFlBCESK/PdDWZGw8TdMaJNx3WdCYjdglkV0dFYnQbjjeLnRRHwr812 5R1Fn1oGFDtim8kl0vRLzsK/bcwb1GxaVZ5dZRF9YlLR3jKZq4Y7tjt7O0lBMVAoDm IDpCNxrnrIBEg== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Subject: [PATCH v3 3/3] riscv: select HAVE_POSIX_CPU_TIMERS_TASK_WORK Date: Mon, 26 Sep 2022 00:24:00 +0800 Message-Id: <20220925162400.1606-4-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220925162400.1606-1-jszhang@kernel.org> References: <20220925162400.1606-1-jszhang@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220925_093337_867518_36A00686 X-CRM114-Status: UNSURE ( 8.44 ) X-CRM114-Notice: Please train this message. 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 Move POSIX CPU timer expiry and signal delivery into task context to allow PREEMPT_RT setups to coexist with KVM. Signed-off-by: Jisheng Zhang --- arch/riscv/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig index 79e52441e18b..7a8134fd7ec9 100644 --- a/arch/riscv/Kconfig +++ b/arch/riscv/Kconfig @@ -104,6 +104,7 @@ config RISCV select HAVE_PERF_EVENTS select HAVE_PERF_REGS select HAVE_PERF_USER_STACK_DUMP + select HAVE_POSIX_CPU_TIMERS_TASK_WORK select HAVE_REGS_AND_STACK_ACCESS_API select HAVE_FUNCTION_ARG_ACCESS_API select HAVE_STACKPROTECTOR