From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10E093D9DD9; Mon, 8 Jun 2026 15:28:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780932529; cv=none; b=CwxJulK7kH3oo90x/PItxEwSuKbWrKMEr1+qtcK2+MOdIvl/tHgNZtZT7QaVzqoo2ddVZoFfu9rkJAAFl0hBzVkmSHTz1Z+apP/zNbSvpHGhbIvIBr9TxxPlJAxVReKzAVd/SvaCojOUQNw0fVh8YeW8uLT5nY2CJfGC/utoN2Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780932529; c=relaxed/simple; bh=BYNpDnA/rLNB4DFtvpxo3rixLpZtLcno2qtEUdBWlTs=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=oZkzqdP5gDoLxXnxjPv0y3sadxrgw1MxKZQVb1Nw6Pcj/Eptk7rYTqp6CwVdcNX15m1CbNCVj/p3NvbqGKpw9PbSeEJPgQx8OY25x2qLxLCUKtkpol/eZEFpJuHpLCOn4LOXMdjLCpLLeGOyZ+Xn6O3KR3Tyc6XhrLvMP9EROXE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EcUMvxka; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EcUMvxka" 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) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 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.