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. 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.7 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 83154C4338F for ; Fri, 30 Jul 2021 09:43:13 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 4EDFC60F00 for ; Fri, 30 Jul 2021 09:43:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 4EDFC60F00 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org 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: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=R72JQ4NbsAbeQR2rCCWKD/ZxBxlt8NvDExI7coKsgL8=; b=HITZh1t6gV+bD2 ETphaEC3bzEFuxADxR4Hou16MLNLzh0BXwoQeCsO6SjPmCA1VrNsfaHUd0ebDbbpOQjKXCu2lh6oN HxCqrbdPJ0GbkBN4bpHPBa2sg8oQqSWWQ6XbeDV1qZk0tYIQwozf96rZtxri0kFIGBpvAS9dp527K qyVGWck3w+QDbGhflRCjy0ztWQHelmcbx1WAL0013ArACJwJYzgVsrNrBFMztSbc8yov+MH53hY6g VSzIPCSePQ10JG25Y1+1s/xIHn1Eprfrg/F9XIjXPYYS8Q5XImjzl3HhTd97rx2oTybuN6un6BPxz sru1JexxZ10JTczGAMGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m9P1K-007xPM-Js; Fri, 30 Jul 2021 09:41:35 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m9P1C-007xOH-Hw for linux-arm-kernel@lists.infradead.org; Fri, 30 Jul 2021 09:41:28 +0000 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") 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210730_024126_674942_F9503AE4 X-CRM114-Status: GOOD ( 32.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel 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