From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 278B0C4338F for ; Fri, 30 Jul 2021 09:41:32 +0000 (UTC) Received: from mm01.cs.columbia.edu (mm01.cs.columbia.edu [128.59.11.253]) by mail.kernel.org (Postfix) with ESMTP id 972A060EFD for ; Fri, 30 Jul 2021 09:41:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 972A060EFD Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.cs.columbia.edu Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 24ACD49F6C; Fri, 30 Jul 2021 05:41:31 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RMXo5FsF47nz; Fri, 30 Jul 2021 05:41:30 -0400 (EDT) Received: from mm01.cs.columbia.edu (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 051B04B092; Fri, 30 Jul 2021 05:41:30 -0400 (EDT) Received: from localhost (localhost [127.0.0.1]) by mm01.cs.columbia.edu (Postfix) with ESMTP id 978C74B08F for ; Fri, 30 Jul 2021 05:41:28 -0400 (EDT) X-Virus-Scanned: at lists.cs.columbia.edu Received: from mm01.cs.columbia.edu ([127.0.0.1]) by localhost (mm01.cs.columbia.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id lDaoUYGXXaxo for ; Fri, 30 Jul 2021 05:41:27 -0400 (EDT) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by mm01.cs.columbia.edu (Postfix) with ESMTPS id 6AFED4B08D for ; Fri, 30 Jul 2021 05:41:27 -0400 (EDT) Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5191360EFD; Fri, 30 Jul 2021 09:41:26 +0000 (UTC) Received: from sofa.misterjones.org ([185.219.108.64] helo=why.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1m9P1A-001y8m-GX; Fri, 30 Jul 2021 10:41:24 +0100 Date: Fri, 30 Jul 2021 10:41:24 +0100 Message-ID: <878s1o2l6j.wl-maz@kernel.org> From: Marc Zyngier To: Oliver Upton Subject: Re: [PATCH v2 3/3] KVM: arm64: Use generic KVM xfer to guest work function In-Reply-To: <20210729220916.1672875-4-oupton@google.com> References: <20210729220916.1672875-1-oupton@google.com> <20210729220916.1672875-4-oupton@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: oupton@google.com, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, pbonzini@redhat.com, james.morse@arm.com, alexandru.elisei@arm.com, suzuki.poulose@arm.com, catalin.marinas@arm.com, will@kernel.org, tglx@linutronix.de, peterz@infradead.org, luto@kernel.org, linux-arm-kernel@lists.infradead.org, pshier@google.com, shakeelb@google.com, guangyus@google.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Cc: Shakeel Butt , kvm@vger.kernel.org, Peter Zijlstra , Catalin Marinas , Peter Shier , linux-kernel@vger.kernel.org, Guangyu Shi , Will Deacon , Andy Lutomirski , Paolo Bonzini , Thomas Gleixner , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org X-BeenThere: kvmarm@lists.cs.columbia.edu X-Mailman-Version: 2.1.14 Precedence: list List-Id: Where KVM/ARM decisions are made List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: kvmarm-bounces@lists.cs.columbia.edu Sender: kvmarm-bounces@lists.cs.columbia.edu Hi Oliver, On Thu, 29 Jul 2021 23:09:16 +0100, Oliver Upton wrote: > > Clean up handling of checks for pending work by switching to the generic > infrastructure to do so. > > We pick up handling for TIF_NOTIFY_RESUME from this switch, meaning that > task work will be correctly handled. > > Signed-off-by: Oliver Upton > --- > arch/arm64/kvm/Kconfig | 1 + > arch/arm64/kvm/arm.c | 27 ++++++++++++++------------- > 2 files changed, 15 insertions(+), 13 deletions(-) > > diff --git a/arch/arm64/kvm/Kconfig b/arch/arm64/kvm/Kconfig > index a4eba0908bfa..8bc1fac5fa26 100644 > --- a/arch/arm64/kvm/Kconfig > +++ b/arch/arm64/kvm/Kconfig > @@ -26,6 +26,7 @@ menuconfig KVM > select HAVE_KVM_ARCH_TLB_FLUSH_ALL > select KVM_MMIO > select KVM_GENERIC_DIRTYLOG_READ_PROTECT > + select KVM_XFER_TO_GUEST_WORK > select SRCU > select KVM_VFIO > select HAVE_KVM_EVENTFD > diff --git a/arch/arm64/kvm/arm.c b/arch/arm64/kvm/arm.c > index 60d0a546d7fd..9762e2129813 100644 > --- a/arch/arm64/kvm/arm.c > +++ b/arch/arm64/kvm/arm.c > @@ -6,6 +6,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -714,6 +715,13 @@ static bool vcpu_mode_is_bad_32bit(struct kvm_vcpu *vcpu) > static_branch_unlikely(&arm64_mismatched_32bit_el0); > } > > +static bool kvm_vcpu_exit_request(struct kvm_vcpu *vcpu) > +{ > + return kvm_request_pending(vcpu) || > + need_new_vmid_gen(&vcpu->arch.hw_mmu->vmid) || > + xfer_to_guest_mode_work_pending(); Here's what xfer_to_guest_mode_work_pending() says: * Has to be invoked with interrupts disabled before the transition to * guest mode. At the point where you call this, we already are in guest mode, at least in the KVM sense. > +} > + > /** > * kvm_arch_vcpu_ioctl_run - the main VCPU run function to execute guest code > * @vcpu: The VCPU pointer > @@ -757,7 +765,11 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > /* > * Check conditions before entering the guest > */ > - cond_resched(); > + if (__xfer_to_guest_mode_work_pending()) { > + ret = xfer_to_guest_mode_handle_work(vcpu); xfer_to_guest_mode_handle_work() already does the exact equivalent of __xfer_to_guest_mode_work_pending(). Why do we need to do it twice? > + if (!ret) > + ret = 1; > + } > > update_vmid(&vcpu->arch.hw_mmu->vmid); > > @@ -776,16 +788,6 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > > kvm_vgic_flush_hwstate(vcpu); > > - /* > - * 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; > - } > - > /* > * If we're using a userspace irqchip, then check if we need > * to tell a userspace irqchip about timer or PMU level > @@ -809,8 +811,7 @@ int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu) > */ > smp_store_mb(vcpu->mode, IN_GUEST_MODE); > > - if (ret <= 0 || need_new_vmid_gen(&vcpu->arch.hw_mmu->vmid) || > - kvm_request_pending(vcpu)) { > + if (ret <= 0 || kvm_vcpu_exit_request(vcpu)) { If you are doing this, please move the userspace irqchip handling into the helper as well, so that we have a single function dealing with collecting exit reasons. > vcpu->mode = OUTSIDE_GUEST_MODE; > isb(); /* Ensure work in x_flush_hwstate is committed */ > kvm_pmu_sync_hwstate(vcpu); Thanks, M. -- Without deviation from the norm, progress is not possible. _______________________________________________ kvmarm mailing list kvmarm@lists.cs.columbia.edu https://lists.cs.columbia.edu/mailman/listinfo/kvmarm