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 2AEF3D116F1 for ; Mon, 1 Dec 2025 09:19:24 +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=4dfcQcCLn3HlDZT7AZtD7gEB3R0pWtzWQrRv6n+I7VM=; b=fx3pJgQSbOOREXBWvvudCowQih Hrf/fj4t3svwBjSlHPXBL8Pupu1MhL2FiVG/NndI8q/dvuwD6zTcb03ZSgmtmFzqf7xWgiMWDkjkq LL49sV2Ph/4g1JJRd2ulOOHk8tAep2nza46dbFHymB+ZPXnwq2swSi3UL7P93VUSQpTWu2UCB94Po z+RNv/JNI6aUwJXmm41T54bWGRvyHPJydFZz0yEdu4xiaPJDjOSc8Dm2SF0KTI3KBUfKlon73uytC x9TuuKHC2l2VnyqI+sYi7lmFnfN5nEAOc+B94mIbHpE0H+hSUYuR2/HuX0LsJqvSVtngphl7UiWA7 +2hKLvvQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vQ041-00000003CaS-2zl1; Mon, 01 Dec 2025 09:19:21 +0000 Received: from tor.source.kernel.org ([2600:3c04:e001:324:0:1991:8:25]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vQ040-00000003Ca8-3MwL for linux-arm-kernel@lists.infradead.org; Mon, 01 Dec 2025 09:19:20 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by tor.source.kernel.org (Postfix) with ESMTP id E2E7C6013A; Mon, 1 Dec 2025 09:19:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 99489C4CEF1; Mon, 1 Dec 2025 09:19:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1764580759; bh=kiJoP+7/+HStSKRHTnqaa0QmmtBrTe1uce/EYrqIBBU=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=RQPzXm47YVt1+uqOu70tE87pYuSb+h/CI7wVv0ShYS4qSuF/VYyVIHeO4UVcJLQyd t48IEQY+Lc9LF1o17hrX/GBj1IsmgYaGVAVfqKkcMQ/YmJRWrh/8SWiM62MehuhRll JdnVeDVDCYJIy0tYqzSGrYGQyAU0ps+7C+LcWA2h2+AYYpP2h+Fszh8ZenOZUDplXt tjLzUD6jIPxaxC1UWdhtcWqu4Ni3IAcGDKSwxTZWZGUwY+GIuDWk1qjnxRIU4kQuvF dtPQHZwmbiBBs8ae5zK/xwokYLZCogZ/HnpmIkj9nTQ/lBVoqlXXhdxFVkayjVYiIk EjU7l8cwU+0xQ== 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 1vQ03x-00000009YAW-1aC6; Mon, 01 Dec 2025 09:19:17 +0000 Date: Mon, 01 Dec 2025 09:19:17 +0000 Message-ID: <86qztepnje.wl-maz@kernel.org> From: Marc Zyngier To: Alexandru Elisei Cc: oliver.upton@linux.dev, joey.gouly@arm.com, yuzenghui@huawei.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev Subject: Re: [PATCH 0/4] KVM: arm64: nv: HAF fixes In-Reply-To: <87a503fyw2.wl-maz@kernel.org> References: <20251128100946.74210-1-alexandru.elisei@arm.com> <87a503fyw2.wl-maz@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: alexandru.elisei@arm.com, oliver.upton@linux.dev, joey.gouly@arm.com, yuzenghui@huawei.com, suzuki.poulose@arm.com, linux-arm-kernel@lists.infradead.org, kvmarm@lists.linux.dev 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 Sun, 30 Nov 2025 13:11:57 +0000, Marc Zyngier wrote: > > On Fri, 28 Nov 2025 10:09:42 +0000, > Alexandru Elisei wrote: > > > > Based on kvmarm's next branch. > > > > HAF support for the software translation table walker was merged while I > > was in the process of reading the patches, so instead of comments I have > > these few fixes. > > > > One thing I didn't touch is this sequence in hyp_set_prot_attr(): > > > > if (prot & KVM_PGTABLE_PROT_X) { > > /* don't set the XN bit */ > > } else { > > attr |= KVM_PTE_LEAF_ATTR_HI_S1_XN; > > } > > > > If the caller is executing in nVHE mode, the translation regime is EL2, > > which has only PrivExecute permission. Since KVM_PGTABLE_PROT_X is now the > > union of PrivExecute and UnprivExecute, if the caller requests only the > > UnprivExecute permission, but no PrivExecute permission, the function does > > not return an error code and sets the PrivExecute permission. > > I don't think this is a huge problem *right now*, as long as we don't > have anything that looks like "hvhe hypervisor userspace" (yes, I > proposed that a while ago, and haven't completely dropped the > idea). But at the same time, the page-table code should probably be > built to the architecture and not to the use cases. > > But it also outlines a rather bad bug in the hVHE case, where we set > the UXN bit instead of the PXN bit... > > What I have in mind is something like this, untested. Thoughts? > > M. > > diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h > index d57c12f074a40..48305118ba3c5 100644 > --- a/arch/arm64/include/asm/kvm_pgtable.h > +++ b/arch/arm64/include/asm/kvm_pgtable.h > @@ -88,6 +88,8 @@ typedef u64 kvm_pte_t; > #define KVM_PTE_LEAF_ATTR_HI_SW GENMASK(58, 55) > > #define KVM_PTE_LEAF_ATTR_HI_S1_XN BIT(54) > +#define KVM_PTE_LEAF_ATTR_HI_S1_UXN BIT(54) > +#define KVM_PTE_LEAF_ATTR_HI_S1_PXN BIT(53) > > #define KVM_PTE_LEAF_ATTR_HI_S2_XN GENMASK(54, 53) > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > index e0bd6a0172729..cbf9b6b58e284 100644 > --- a/arch/arm64/kvm/hyp/pgtable.c > +++ b/arch/arm64/kvm/hyp/pgtable.c > @@ -330,6 +330,11 @@ struct hyp_map_data { > kvm_pte_t attr; > }; > > +static bool el2_nvhe(void) > +{ > + return !has_vhe() && !cpus_have_final_cap(ARM64_KVM_PROTECTED_MODE); Obviously, this should read ARM64_KVM_HVHE, not PROTECTED_MODE... M. -- Without deviation from the norm, progress is not possible.