From: Marc Zyngier <maz@kernel.org>
To: Joey Gouly <joey.gouly@arm.com>
Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
kvm@vger.kernel.org, Suzuki K Poulose <suzuki.poulose@arm.com>,
Oliver Upton <oupton@kernel.org>,
Zenghui Yu <yuzenghui@huawei.com>,
Alexandru Elisei <alexandru.elisei@arm.com>,
Sascha Bischoff <Sascha.Bischoff@arm.com>,
Quentin Perret <qperret@google.com>,
Fuad Tabba <tabba@google.com>,
Sebastian Ene <sebastianene@google.com>
Subject: Re: [PATCH v2 6/6] KVM: arm64: Honor UX/PX attributes for EL2 S1 mappings
Date: Thu, 11 Dec 2025 16:21:20 +0000 [thread overview]
Message-ID: <86tsxxng5b.wl-maz@kernel.org> (raw)
In-Reply-To: <20251211151810.GA867614@e124191.cambridge.arm.com>
On Thu, 11 Dec 2025 15:18:51 +0000,
Joey Gouly <joey.gouly@arm.com> wrote:
>
> Question,
>
> On Wed, Dec 10, 2025 at 05:30:24PM +0000, Marc Zyngier wrote:
> > Now that we potentially have two bits to deal with when setting
> > execution permissions, make sure we correctly handle them when both
> > when building the page tables and when reading back from them.
> >
> > Reported-by: Alexandru Elisei <alexandru.elisei@arm.com>
> > Signed-off-by: Marc Zyngier <maz@kernel.org>
> > ---
> > arch/arm64/include/asm/kvm_pgtable.h | 12 +++---------
> > arch/arm64/kvm/hyp/pgtable.c | 24 +++++++++++++++++++++---
> > 2 files changed, 24 insertions(+), 12 deletions(-)
> >
> > diff --git a/arch/arm64/include/asm/kvm_pgtable.h b/arch/arm64/include/asm/kvm_pgtable.h
> > index be68b89692065..095e6b73740a6 100644
> > --- a/arch/arm64/include/asm/kvm_pgtable.h
> > +++ b/arch/arm64/include/asm/kvm_pgtable.h
> > @@ -87,15 +87,9 @@ 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_S1_XN \
> > - ({ cpus_have_final_cap(ARM64_KVM_HVHE) ? \
> > - (__KVM_PTE_LEAF_ATTR_HI_S1_UXN | \
> > - __KVM_PTE_LEAF_ATTR_HI_S1_PXN) : \
> > - __KVM_PTE_LEAF_ATTR_HI_S1_XN; })
> > +#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..97c0835d25590 100644
> > --- a/arch/arm64/kvm/hyp/pgtable.c
> > +++ b/arch/arm64/kvm/hyp/pgtable.c
> > @@ -342,6 +342,9 @@ static int hyp_set_prot_attr(enum kvm_pgtable_prot prot, kvm_pte_t *ptep)
> > if (!(prot & KVM_PGTABLE_PROT_R))
> > return -EINVAL;
> >
> > + if (!cpus_have_final_cap(ARM64_KVM_HVHE))
> > + prot &= ~KVM_PGTABLE_PROT_UX;
>
> Trying to understand this part. We don't consider KVM_PGTABLE_PROT_UX below
> when !HVHE, and we don't set it in kvm_pgtable_hyp_pte_prot() when !HVHE
> either, so can it ever actually be set?
Because KVM_PGTABLE_PROT_X, which is directly passed by the high-level
code, is defined as such:
KVM_PGTABLE_PROT_X = KVM_PGTABLE_PROT_PX |
KVM_PGTABLE_PROT_UX,
We *could* make that value dependent on HVHE, but since that's in an
enum, it is pretty ugly to do (not impossible though).
But it is in the following code that this becomes useful...
>
> Otherwise LGTM!
>
> Thanks,
> Joey
>
> > +
> > if (prot & KVM_PGTABLE_PROT_X) {
> > if (prot & KVM_PGTABLE_PROT_W)
> > return -EINVAL;
... here. If you were passed UX (and only that), and that you're
!HVHE, you won't have execution at all, and can allow writes.
Does that make sense?
M.
--
Without deviation from the norm, progress is not possible.
next prev parent reply other threads:[~2025-12-11 16:21 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-10 17:30 [PATCH v2 0/6] KVM: arm64: VTCR_EL2 conversion to feature dependency framework Marc Zyngier
2025-12-10 17:30 ` [PATCH v2 1/6] KVM: arm64: Fix EL2 S1 XN handling for hVHE setups Marc Zyngier
2025-12-11 13:37 ` Fuad Tabba
2025-12-11 14:30 ` Marc Zyngier
2025-12-19 13:38 ` Leonardo Bras
2025-12-19 14:13 ` Marc Zyngier
2025-12-10 17:30 ` [PATCH v2 2/6] arm64: Convert ID_AA64MMFR0_EL1.TGRAN{4,16,64}_2 to UnsignedEnum Marc Zyngier
2025-12-11 13:38 ` Fuad Tabba
2025-12-10 17:30 ` [PATCH v2 3/6] arm64: Convert VTCR_EL2 to sysreg infratructure Marc Zyngier
2025-12-11 14:13 ` Fuad Tabba
2025-12-10 17:30 ` [PATCH v2 4/6] KVM: arm64: Account for RES1 bits in DECLARE_FEAT_MAP() and co Marc Zyngier
2025-12-11 14:30 ` Fuad Tabba
2025-12-11 17:23 ` Sascha Bischoff
2025-12-10 17:30 ` [PATCH v2 5/6] KVM: arm64: Convert VTCR_EL2 to config-driven sanitisation Marc Zyngier
2025-12-11 14:44 ` Fuad Tabba
2025-12-10 17:30 ` [PATCH v2 6/6] KVM: arm64: Honor UX/PX attributes for EL2 S1 mappings Marc Zyngier
2025-12-11 14:51 ` Fuad Tabba
2025-12-11 15:18 ` Joey Gouly
2025-12-11 16:21 ` Marc Zyngier [this message]
2025-12-12 16:00 ` Joey Gouly
2025-12-11 14:55 ` [PATCH v2 0/6] KVM: arm64: VTCR_EL2 conversion to feature dependency framework Fuad Tabba
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=86tsxxng5b.wl-maz@kernel.org \
--to=maz@kernel.org \
--cc=Sascha.Bischoff@arm.com \
--cc=alexandru.elisei@arm.com \
--cc=joey.gouly@arm.com \
--cc=kvm@vger.kernel.org \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=oupton@kernel.org \
--cc=qperret@google.com \
--cc=sebastianene@google.com \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=yuzenghui@huawei.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).