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 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 F38C5CD8C92 for ; Mon, 8 Jun 2026 15:28:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Type:MIME-Version: References:In-Reply-To:Subject:Cc:To:From:Message-ID:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hctmouS3Oa1zQsA8OfIPu6NlW/Bf5FQLselaT1XAaWQ=; b=vtxRVoB1U4oOtLH2jgW47NiMow 8hqSPy9htZPLlOnYENr6au1F6CizYPylMaNOsMW/LS10rSw0sOY7tYLXC4kXzIGRWC4LuZhXXbEEF YTszjf8hbz3edrEWG47MOcOCsO+X0uCH7OfQHA73/KedtCGvpPISt9DmJumknjqjMgz3pq2O8mnTg Di1Z1QTGtcIFTOKxAaDkWy20AY/hso22/0CRW9W5mjtW2dKqS4Jhq48bRobi8YPNl/dDMTZ6IaRaW 70OVghgBWx6uAQSa6QmZtgxd8bBPYS2wGg2fmui392X3rSqQaWE47R2Su3b7uyB6NgxY/hveKWrYQ RgjyRpcg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wWbuF-00000003xpE-1ICq; Mon, 08 Jun 2026 15:28:51 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wWbuD-00000003xp0-0Bq4 for linux-arm-kernel@lists.infradead.org; Mon, 08 Jun 2026 15:28:49 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 42012601D8; Mon, 8 Jun 2026 15:28:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E99C41F00893; Mon, 8 Jun 2026 15:28:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1780932528; bh=hctmouS3Oa1zQsA8OfIPu6NlW/Bf5FQLselaT1XAaWQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=EcUMvxkaY4O1FldyBxtKNcGT+VLsCmOxbm/MZRJi8k+ial78uBS0B/bUb2NQ5mfxi ig/f5pjIoH+IFyCDnRLQ0Ay6cN5MKXi/wjrvlrtepUgJCuKrLykz3TU/tgBtOYuLyR ERJcdef+ZONjKIkCoLbpU+TeW5rgl9lTYW8a75cqGPSOpMmgccdFZaMGPdmh7U+WkB 6vE6vhRDGeNRWu6Q/ggXbnIUW3vF8l+HH2M2gj2TTqN20ZRqT6mDQwQVWUpo5yrufO nHoVr46xRmSkI+UQgMBCpb514MDG1oSg2ROx7eIuBKn7RkKS0AaSPAN0L48uO/13lD dXXkT7RTZiEgg== Received: from sofa.misterjones.org ([185.219.108.64] helo=goblin-girl.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wWbu9-0000000AYTW-3ofg; Mon, 08 Jun 2026 15:28:46 +0000 Date: Mon, 08 Jun 2026 16:28:45 +0100 Message-ID: <86o6hlt5jm.wl-maz@kernel.org> From: Marc Zyngier To: Jia He Cc: Oliver Upton , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Catalin Marinas , Will Deacon , linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/1] KVM: arm64: Make kvm_s2_fault_pin_pfn() fault-in interruptible In-Reply-To: <20260608104336.2405384-2-justin.he@arm.com> References: <20260608104336.2405384-1-justin.he@arm.com> <20260608104336.2405384-2-justin.he@arm.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/30.1 (aarch64-unknown-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: justin.he@arm.com, oupton@kernel.org, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, catalin.marinas@arm.com, will@kernel.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev, linux-kernel@vger.kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 08 Jun 2026 11:43:36 +0100, Jia He wrote: > > arm64 KVM faults guest memory into the host in kvm_s2_fault_pin_pfn() via > __kvm_faultin_pfn(). Today this request is made non-interruptible, so if > the host fault-in path blocks for a long time, a vCPU thread that already > has a pending signal cannot leave the fault-in path until GUP eventually > completes. > > This is particularly painful during VM teardown, where userspace may > signal vCPU threads while they are blocked faulting in guest memory. In > that case there is no benefit in continuing to wait for the fault to > complete; the vCPU should return to userspace and let the pending signal > be handled. > > Ask the generic KVM fault-in helper to use FOLL_INTERRUPTIBLE. When GUP > reports a pending signal it returns KVM_PFN_ERR_SIGPENDING; handle it by > calling kvm_handle_signal_exit() and returning -EINTR. This matches the > behaviour expected by the generic KVM fault-in path and mirrors the > signal-exit handling already done by the arm64 run loop, which sets > run->exit_reason = KVM_EXIT_INTR before returning to userspace. It is > also consistent with architectures such as x86 that already allow the > fault-in to be interrupted by pending signals. Only x86, AFAICT. s390 handles signals, but doesn't set GUP as interruptible. > > The interrupted fault does not install a partial stage-2 mapping: the > -EINTR is returned before any mapping is created, so the fault is simply > retried on a subsequent vCPU entry once userspace re-enters KVM_RUN. The > only observable effect in the absence of a pending signal is none; this This sentence reads bizarrely. Do you mean to say "there is no observable effect in the absence of a pending signal"? > does not make ordinary stage-2 faults abortable. > > Signed-off-by: Jia He > --- > arch/arm64/kvm/mmu.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index 4da9281312eb..dfb779e6d792 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -1872,19 +1872,27 @@ static int kvm_s2_fault_pin_pfn(const struct kvm_s2_fault_desc *s2fd, > struct kvm_s2_fault_vma_info *s2vi) > { > int ret; > + unsigned int flags = FOLL_INTERRUPTIBLE; > > ret = kvm_s2_fault_get_vma_info(s2fd, s2vi); > if (ret) > return ret; > > + if (kvm_is_write_fault(s2fd->vcpu)) > + flags |= FOLL_WRITE; > + nit: you might as well keep the assignment and the update together. > s2vi->pfn = __kvm_faultin_pfn(s2fd->memslot, get_canonical_gfn(s2fd, s2vi), > - kvm_is_write_fault(s2fd->vcpu) ? FOLL_WRITE : 0, > + flags, > &s2vi->map_writable, &s2vi->page); > if (unlikely(is_error_noslot_pfn(s2vi->pfn))) { > if (s2vi->pfn == KVM_PFN_ERR_HWPOISON) { > kvm_send_hwpoison_signal(s2fd->hva, __ffs(s2vi->vma_pagesize)); > return 0; > } > + if (is_sigpending_pfn(s2vi->pfn)) { > + kvm_handle_signal_exit(s2fd->vcpu); > + return -EINTR; > + } > return -EFAULT; > } > The VNCR handling code also uses __kvm_faultin_pfn(). Why isn't it similarly updated, given that you are specifically singling out NV as an area of concern? Similarly. pkvm_mem_abort() is using FOLL* flags and could benefit from the same optimisation. Thanks, M. -- Without deviation from the norm, progress is not possible.