From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 614152BEC5A for ; Sun, 30 Nov 2025 19:26:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764530763; cv=none; b=qBNzaysjkREzcOBFNKZgQ+2YtWMLIZgKX4FGHLzb3r1Si0jIt3i6UAh9KUBO3QrtlIQoRhtJ0pVY53lG3fs0dSVS1oNrOVx2HhOKKgzJsCJLjHX4f5/y5GKao/VbhHDUG484BGwSLSXkIyW5A8OZvc0z1X5GI5EYXVfWww2OOH4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764530763; c=relaxed/simple; bh=GdPNc3PxxP9kLpHvuNn2P++e+FiMa66Ks5F/Mnz068c=; h=Date:Message-ID:From:To:Cc:Subject:In-Reply-To:References: MIME-Version:Content-Type; b=hrTIKZI3WL7qD+lMzx74+yY4nF2I+t+Z6T6OTpx2inwI23pmmbHRoroCAFlVVMe/+n/oAzxAtDGQMliMtbDHmvHHSRI9rxKghS908VmZEdBGInCBC+6ooTaqYKpnouxFxbCWPb+D4IeGZ2JYfqQOzPKgbXjBCkitLJrlanXWlOQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=rENTJxXv; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="rENTJxXv" 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) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev 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: 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 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.