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 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 302F0C432BE for ; Fri, 30 Jul 2021 09:41:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 11DD160EFD for ; Fri, 30 Jul 2021 09:41:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238251AbhG3Jld (ORCPT ); Fri, 30 Jul 2021 05:41:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:53456 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231159AbhG3Jla (ORCPT ); Fri, 30 Jul 2021 05:41:30 -0400 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 Cc: kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Paolo Bonzini , James Morse , Alexandru Elisei , Suzuki K Poulose , Catalin Marinas , Will Deacon , Thomas Gleixner , Peter Zijlstra , Andy Lutomirski , linux-arm-kernel@lists.infradead.org, Peter Shier , Shakeel Butt , Guangyu Shi 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") Content-Type: text/plain; charset=US-ASCII 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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.