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 C7211C79F9F for ; Thu, 10 Sep 2026 08:49:20 +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=VfSkPLpOWWd+VItdFa754M+oss4bxhyEVWaKllCEoR8=; b=aY7XHi9KYns2+2Rfp14jy9sGFz weP27k1+XZMzBvIyoI3auH06HfRj9kJr5UtDQFh/jxrarRYzcA+PmerNawClw6QaJFbwoDF9VLW/G voa9z+n3MuV+eM/Eh7hPTGyQMdXdh2u3g0cZZL1SlhBdQzijx+CERdZ5R6LVFNbRXOPbVypK7Z6ep Ad1IHM7iRvosqilNOY1tOJ4s1yhKt3ZHH8EhBicWqZY9J2nhJxp/Bza0ctscz3AuIeCETdljgH0N6 6gr7bE3zd888bmEv/V2fxVAPh6rwvr2z0iMnu9zoKFK2BlKRrx1XzfxtrYy3puOo3LJNU2ccWKBJx Q/HkmXkw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1x4aT4-0000000DnLX-0Zx3; Thu, 10 Sep 2026 08:49:14 +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 1x4aT2-0000000DnL4-1YwH for linux-arm-kernel@lists.infradead.org; Thu, 10 Sep 2026 08:49:12 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by tor.source.kernel.org (Postfix) with ESMTP id 95011600CB; Thu, 10 Sep 2026 08:49:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 464D61F000FF; Thu, 10 Sep 2026 08:49:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1789030151; bh=VfSkPLpOWWd+VItdFa754M+oss4bxhyEVWaKllCEoR8=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=fCv/DXz2GkQ2jYCc7xWf/313wM6aqpMIKwHxF8glPgcMfbPMnyliOsMgk0eNk5TvB K2aAyl+mZ3uWjtAjaZxgMntiIelsMcMAV3PO3WbsqEYt8btVzE4hwLjoRho8NPTFCp ylUV3Vy11jQ16dTdv92dh9HXaccFqbBzIJXPRkRlaUkjAJU+FicEpBKbX9yH6sMlan ThjNz2rS7OHvSRrSP3iFzVAemCxMztIOdmabPmru+XPPuqZZnfLWfLGSYzGh6eaGpD mLDzImom5ri+WCsBPA/q1DHXzbpP0WyPnqld7JKpsmQfHDsHU4XLfhUs+xwXvZt+yK 7Y19Sv23+VcSQ== 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 1x4aSy-00000007AGx-3Og4; Thu, 10 Sep 2026 08:49:08 +0000 Date: Thu, 10 Sep 2026 09:49:08 +0100 Message-ID: <86v78d7apn.wl-maz@kernel.org> From: Marc Zyngier To: "Lorenzo Stoakes (ARM)" Cc: Catalin Marinas , Will Deacon , Oliver Upton , Fuad Tabba , Joey Gouly , Steffen Eiden , Suzuki K Poulose , Zenghui Yu , Paolo Bonzini , Jonathan Corbet , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, Jack Thomson , Jack Thomson , Alexandru Elisei , Vincent Donnefort , "Aneesh Kumar K.V" , Sean Christopherson , Claudio Imbrenda , Leo Soares Passos Subject: Re: [PATCH 3/8] KVM: arm64: Propagate and use kvm_s2_fault_result on S2 fault In-Reply-To: <20260825-kvm-arm-prefault-v1-3-befe8947702e@kernel.org> References: <20260825-kvm-arm-prefault-v1-0-befe8947702e@kernel.org> <20260825-kvm-arm-prefault-v1-3-befe8947702e@kernel.org> 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: ljs@kernel.org, catalin.marinas@arm.com, will@kernel.org, oupton@kernel.org, tabba@google.com, joey.gouly@arm.com, seiden@linux.ibm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com, pbonzini@redhat.com, corbet@lwn.net, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, jackabt@amazon.com, jackabt.amazon@gmail.com, alexandru.elisei@arm.com, vdonnefort@google.com, aneesh.kumar@kernel.org, seanjc@google.com, imbrenda@linux.ibm.com, Leo.Bras@arm.com 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 Tue, 25 Aug 2026 17:00:37 +0100, "Lorenzo Stoakes (ARM)" wrote: > > When stage 2 page tables fault the net result may either be that a page is > mapped, an error occurred or the fault should be retried (-EAGAIN). > > When a fault succeeds it may be upgraded to a PMD size via > transparent_hugepage_adjust(). > > In order to support KVM pre-faulting the outcome of the fault and the > mapping size must be recorded. > > Track this in the new kvm_s2_fault_result struct, which is threaded through > gmem_abort(), user_mem_abort() and kvm_s2_fault_map(). > > PKVM and SEA aren't relevant to synthetic pre-faulting so neither > kvm_inject_sea() nor pkvm_mem_abort() are altered. > > Actual hardware faulting doesn't require this information, so > kvm_handle_guest_abort() simply passes NULL kvm_s2_fault_result to > gmem_abort() and user_mem_abort(). > > Faults are necessarily ephemeral and pre-faulting can't guarantee what may > happen in parallel, so do not store the GFN or PFN in > kvm_s2_fault_result. Pre-faulting only needs to know what was mapped in at > the point of the fault. > > This struct could be replaced with a pointer to an unsigned long, however > it's clearer to separate out the mapped flag and having a struct allows us > to easily add additional fields in future as needed. > > No functional change intended. > > Suggested-by: Vincent Donnefort > Signed-off-by: Lorenzo Stoakes (ARM) > --- > arch/arm64/kvm/mmu.c | 33 +++++++++++++++++++++++++++------ > 1 file changed, 27 insertions(+), 6 deletions(-) > > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index 80cb520e25b9..da15da4e40e6 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -1607,6 +1607,11 @@ struct kvm_s2_fault_desc { > struct kvm_s2_mmu *mmu; > }; > > +struct kvm_s2_fault_result { > + unsigned long mapping_size; > + bool mapped; > +}; > + > static bool kvm_s2_fault_is_perm(const struct kvm_s2_fault_desc *s2fd) > { > return esr_fsc_is_permission_fault(s2fd->esr); > @@ -1632,7 +1637,17 @@ static u64 kvm_s2_perm_fault_granule(const struct kvm_s2_fault_desc *s2fd) > return BIT(ARM64_HW_PGTABLE_LEVEL_SHIFT(level)); > } > > -static int gmem_abort(const struct kvm_s2_fault_desc *s2fd) > +static void populate_fault_result(struct kvm_s2_fault_result *result, > + unsigned long mapping_size) > +{ > + /* A THP upgrade may have altered mapping size. */ > + result->mapping_size = mapping_size; > + /* -EAGAIN is swallowed so be explicit when we actually map. */ > + result->mapped = true; I'm not sold on this boolean. I'd rather we use the fact that the fault handler has passed a result pointer to return -EAGAIN rather than turning into a 0, because that's a clear sign that the fault hasn't been generated by a vcpu. M. -- Without deviation from the norm, progress is not possible.