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 CAF33D111A8 for ; Sun, 30 Nov 2025 19:26:08 +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=CjGQ8/HfgzpPTjRiMX2FwQ6y1e+rfvgkiEuSdMPPINA=; b=lNw9J9mBrsQXGgsvmva2ANbRaL +Gi/05L8upJVtVurNSIci5GBlHdKsbxdStBCJp1NqzDjspy0IojbE5OxGmA1p08+CUBFIsh3ACvci 32+cwZ/9Lc4QlVz1p+pISU0Ic8C1ACPxAuv/t7WiCbAkThx8fJ+r5/meBIOYmvf4GjzRiVEWHmM14 8MrHPVwQbbByN/4SupLsrlknoNWfNfXPuuVEs29UCCkLMLAa2l2qW7IFLj2JCsnDIQWpfpMaXJP+J LUu/5e8WVpb0WNf9pgrpFXpU82B3paq1zbUh8iu4tF0InZV8hpsWxypYJWP2gOe/DLPxsMU0AIxRX T04cRsKg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vPn3d-00000002VrV-12Sb; Sun, 30 Nov 2025 19:26:05 +0000 Received: from tor.source.kernel.org ([172.105.4.254]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vPn3c-00000002VrP-072I for linux-arm-kernel@lists.infradead.org; Sun, 30 Nov 2025 19:26:04 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id 2E2F06011F; Sun, 30 Nov 2025 19:26:03 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D49D9C116B1; Sun, 30 Nov 2025 19:26:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764530762; bh=GdPNc3PxxP9kLpHvuNn2P++e+FiMa66Ks5F/Mnz068c=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=rENTJxXv3cbOf3BXmLNJ2psBgRg2OQ+vGLKQuQBnkiSN4yHXJiKGC6vCjJeTqH6+1 IaHdDe1N7SrvZSv/TQoY2wNDrftXfFWeVxi0ImgAIX5us96OvU0+ULMfEHxHfF/3Yb xbU7hD6ejaBxwm3Uk7XCZuEOSXyvAyTRCKdy80YfouIRI6a1s+t6KPIvhKHRL0arDR fEq05T4sE7bJZ+vtd85K8jC4coxhuwsGPf31G290MOcOsheO0XrsYN+FrUTP7gS2Sm oJWl0qvsIO+/ZcNkjIlSVW1br94HX2EJraUozV41dwys4WVfdt7muS5rnR64Mwko0g arOysGb3IWOLQ== Received: from sofa.misterjones.org ([185.219.108.64] helo=lobster-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 1vPn3Y-00000009Rlh-29ew; Sun, 30 Nov 2025 19:26:00 +0000 Date: Sun, 30 Nov 2025 19:25:59 +0000 Message-ID: <871plffhko.wl-maz@kernel.org> From: Marc Zyngier To: Will Deacon Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, Fuad Tabba , Quentin Perret , Oliver Upton Subject: Re: [PATCH] KVM: arm64: Invert KVM_PGTABLE_WALK_HANDLE_FAULT to fix pKVM walkers In-Reply-To: <20251128141710.19472-1-will@kernel.org> References: <20251128141710.19472-1-will@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: will@kernel.org, kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, tabba@google.com, qperret@google.com, oupton@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 Fri, 28 Nov 2025 14:17:10 +0000, Will Deacon wrote: > > Commit ddcadb297ce5 ("KVM: arm64: Ignore EAGAIN for walks outside of a > fault") introduced a new walker flag ('KVM_PGTABLE_WALK_HANDLE_FAULT') > to KVM's page-table code. When set, the walk logic maintains its > previous behaviour of terminating a walk as soon as the visitor callback > returns an error. However, when the flag is clear, the walk will > continue if the visitor returns -EAGAIN and the error is then suppressed > and returned as zero to the caller. > > Clearing the flag is beneficial when write-protecting a range of IPAs > with kvm_pgtable_stage2_wrprotect() but is not useful in any other > cases, either because we are operating on a single page (e.g. > kvm_pgtable_stage2_mkyoung() or kvm_phys_addr_ioremap()) or because the > early termination is desirable (e.g. when mapping pages from a fault in > user_mem_abort()). > > Subsequently, commit e912efed485a ("KVM: arm64: Introduce the EL1 pKVM > MMU") hooked up pKVM's hypercall interface to the MMU code at EL1 but > failed to propagate any of the walker flags. As a result, page-table > walks at EL2 fail to set KVM_PGTABLE_WALK_HANDLE_FAULT even when the > early termination semantics are desirable on the fault handling path. > > Rather than complicate the pKVM hypercall interface, invert the flag so > that the whole thing can be simplified and only pass the new flag > ('KVM_PGTABLE_WALK_IGNORE_EAGAIN') from the wrprotect code. > > Cc: Fuad Tabba > Cc: Quentin Perret > Cc: Marc Zyngier > Cc: Oliver Upton > Fixes: fce886a60207 ("KVM: arm64: Plumb the pKVM MMU in KVM") > Signed-off-by: Will Deacon > --- > > I found this by inspection and it's a bit fiddly to see what could > actually go wrong in practice because the 'mappings' tree will return > -EAGAIN if it finds a pre-existing entry. The permission relaxing path > looks more problematic, as we'll return 0 instead of -EAGAIN and I > think we can mark the page dirty twice etc. I don't really like the new name of the flag, but unsurprisingly, I also can't come up with anything better. I otherwise quite like the fact that it becomes a buy-in behaviour. Reviewed-by: Marc Zyngier M. -- Jazz isn't dead. It just smells funny.