Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp830130rwe; Wed, 31 Aug 2022 11:47:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR4HYyCH/9R+e8xNdobYOzM9MRXPk/Hjp1crtLqs30jaHLItaliV2L9fZwoJcbvwJRJQhLIf X-Received: by 2002:a17:90b:2c11:b0:1fd:e56c:79de with SMTP id rv17-20020a17090b2c1100b001fde56c79demr4491680pjb.201.1661971641468; Wed, 31 Aug 2022 11:47:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661971641; cv=none; d=google.com; s=arc-20160816; b=SFD6/ydiVQTEbpO/mocG7AoeKoSVqjna9q21eC0gIMnK0m7d9fSac725cmeRiVZkTs vrt4two6Qp99xVk1WUe791bXe8OEv+yreLjCngb5kGKpmzQjxWzrQUW8XkP62+UEPJnd 5pmaywXYkNT5X2YBFDLI7yzZxkCRpzuubIssRXs6ARrAe0zKk4oxDwJynZQO05gOAghE 3BiNyG3IMwseE//bIVrcoAAhYBhoQqAYKrKdhrgAv4ldkvsbVpDQgA3/ySC0uuZIgYw7 yi+kmMFVfwO89zS6VElh26uXcqwZUr2m8aFXYhdOcXx/1PlTzVQtxaoAARtgb5U/kIkp oCBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=4JtJVe8W/B1ITPvbwkYVs5PifKDTVOAcSUITUOtgqWk=; b=YtiXxhJtEKHRVOk306D9gGUUz4cb45BPaXs3xdsDDFIEhTGnl0H7sazaBQ+YAfgnqK 5xD9KwE3rZzatKFokmgt0L9+XosYsNBNfR4l0V2VMwxvYzVnIEGmP9HOxQGOj+osuuKw KfQuDj186HzpdUUjmXPpxqJeZ6cw//e+QYg9Z2Gv36qN5vLLDiJL9JbHINbFbNbbJHRk lK5P3WTi7KB6uYMVOczuN7NSJPG7OhIB1tpdmwG4tGV1dp5bYeU8m7BkGC2f1Dt1l714 qwaABhK91/idekVLEq1RkfVDq+jj6kJ2l2N/HZ3DFiiio2iVv8ZTLhEA4/jQ4NRv20h8 K+vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XEyi+M96; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g4-20020a056a0023c400b0052fac3954e9si14370530pfc.227.2022.08.31.11.47.08; Wed, 31 Aug 2022 11:47:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=XEyi+M96; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232363AbiHaSJi (ORCPT + 99 others); Wed, 31 Aug 2022 14:09:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43874 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232479AbiHaSIq (ORCPT ); Wed, 31 Aug 2022 14:08:46 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE01EE68A4; Wed, 31 Aug 2022 11:08:43 -0700 (PDT) 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 38E7DB82221; Wed, 31 Aug 2022 18:08:42 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AA6F7C433D6; Wed, 31 Aug 2022 18:08:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1661969321; bh=gEVSZo6IZOnVd4BVQuHJHN2F00a6Y7EMFpgV8m6o8aI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XEyi+M9675/fqQ6aKfd9KGILK7DLDHCOgs9bTXSikr3xdjgLsrV5fGBAvEZgvVW3S VlOQL2ce8OkX6h04S0yF7a8Ca/yw4bnv6RRQbc1qr0lB4SmNGmKBB8Lpf663SMZSMT dSaj/d/XuWy9RfQAC5vhG3rQ1B9AeYKvQTHDBKVomodgjc+KGG6eaaXkkrsVYjuFxF tUl8ECG68p+LifunrHPRwB7djV9kHCgtm1fId/qgAe89+d1Bn/8crYTOu3c//e0Q36 8ocBeeB453p3xTGU9VkyE5TLW8YOIFERaAJ2rSrbUjTWkJr1JbjM0ET8x8aPIe0x7m An5qEgUXOjrvg== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Anup Patel , Atish Patra , Sebastian Andrzej Siewior , Thomas Gleixner , Steven Rostedt Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Subject: [PATCH v2 2/5] RISC-V: KVM: Use generic guest entry infrastructure Date: Thu, 1 Sep 2022 01:59:17 +0800 Message-Id: <20220831175920.2806-3-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220831175920.2806-1-jszhang@kernel.org> References: <20220831175920.2806-1-jszhang@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.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); -- 2.34.1