From: Ben Horgan <ben.horgan@arm.com>
To: Fuad Tabba <tabba@google.com>,
kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org
Cc: maz@kernel.org, oliver.upton@linux.dev, will@kernel.org,
joey.gouly@arm.com, suzuki.poulose@arm.com, yuzenghui@huawei.com,
catalin.marinas@arm.com, vladimir.murzin@arm.com
Subject: Re: [PATCH v3 3/8] KVM: arm64: Fix MTE flag initialization for protected VMs
Date: Mon, 10 Nov 2025 14:51:47 +0000 [thread overview]
Message-ID: <bc25a11a-d5b7-45de-bb99-c78100e5055d@arm.com> (raw)
In-Reply-To: <20251110134525.3768197-4-tabba@google.com>
Hi Fuad,
On 11/10/25 13:45, Fuad Tabba wrote:
> The function pkvm_init_features_from_host() initializes guest
> features, propagating them from the host. The logic to propagate
> KVM_ARCH_FLAG_MTE_ENABLED (Memory Tagging Extension)
> has a couple of issues.
>
> First, the check was in the common path, before the divergence for
> protected and non-protected VMs. For non-protected VMs, this was
> unnecessary, as 'kvm->arch.flags' is completely overwritten by
> host_arch_flags immediately after, which already contains the MTE flag.
> For protected VMs, this was setting the flag even if the feature is not
> allowed.
>
> Second, the check was reading 'host_kvm->arch.flags' instead of using
> the local 'host_arch_flags', which is read once from the host flags.
>
> Fix these by moving the MTE flag check inside the protected-VM-only
> path, checking if the feature is allowed, and changing it to use the
> correct host_arch_flags local variable. This ensures non-protected VMs
> get the flag via the bulk copy, and protected VMs get it via an explicit
> check.
>
> Fixes: b7f345fbc32a ("KVM: arm64: Fix FEAT_MTE in pKVM")
> Signed-off-by: Fuad Tabba <tabba@google.com>
> ---
> arch/arm64/kvm/hyp/nvhe/pkvm.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm64/kvm/hyp/nvhe/pkvm.c b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> index f6f8996c4f97..7e370e31260d 100644
> --- a/arch/arm64/kvm/hyp/nvhe/pkvm.c
> +++ b/arch/arm64/kvm/hyp/nvhe/pkvm.c
> @@ -337,9 +337,6 @@ static void pkvm_init_features_from_host(struct pkvm_hyp_vm *hyp_vm, const struc
> /* CTR_EL0 is always under host control, even for protected VMs. */
> hyp_vm->kvm.arch.ctr_el0 = host_kvm->arch.ctr_el0;
>
> - if (test_bit(KVM_ARCH_FLAG_MTE_ENABLED, &host_kvm->arch.flags))
> - set_bit(KVM_ARCH_FLAG_MTE_ENABLED, &kvm->arch.flags);
> -
> /* No restrictions for non-protected VMs. */
> if (!kvm_vm_is_protected(kvm)) {
> hyp_vm->kvm.arch.flags = host_arch_flags;
> @@ -372,6 +369,11 @@ static void pkvm_init_features_from_host(struct pkvm_hyp_vm *hyp_vm, const struc
> kvm->arch.flags |= host_arch_flags & BIT(KVM_ARCH_FLAG_GUEST_HAS_SVE);
> }
>
> + if (kvm_pvm_ext_allowed(KVM_CAP_ARM_MTE)) {
> + set_bit(KVM_CAP_ARM_MTE, allowed_features);
Isn't allowed_features a bitmap for the KVM_ARCH_VCPU_ defines? I think
MTE is treated as a property of the VM.
> + kvm->arch.flags |= host_arch_flags & BIT(KVM_ARCH_FLAG_MTE_ENABLED);
> + }
> +
> bitmap_and(kvm->arch.vcpu_features, host_kvm->arch.vcpu_features,
> allowed_features, KVM_VCPU_MAX_FEATURES);
> }
Thanks,
Ben
next prev parent reply other threads:[~2025-11-10 14:51 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-10 13:45 [PATCH v3 0/8] KVM: arm64: Fixes for guest CPU feature trapping and enabling Fuad Tabba
2025-11-10 13:45 ` [PATCH v3 1/8] KVM: arm64: Fix Trace Buffer trapping for protected VMs Fuad Tabba
2025-11-10 13:45 ` [PATCH v3 2/8] KVM: arm64: Fix Trace Buffer trap polarity " Fuad Tabba
2025-11-10 13:45 ` [PATCH v3 3/8] KVM: arm64: Fix MTE flag initialization " Fuad Tabba
2025-11-10 14:51 ` Ben Horgan [this message]
2025-11-10 15:03 ` Fuad Tabba
2025-11-10 13:45 ` [PATCH v3 4/8] KVM: arm64: Introduce helper to calculate fault IPA offset Fuad Tabba
2025-11-10 13:45 ` [PATCH v3 5/8] KVM: arm64: Include VM type when checking VM capabilities in pKVM Fuad Tabba
2025-11-10 13:45 ` [PATCH v3 6/8] KVM: arm64: Do not allow KVM_CAP_ARM_MTE for any guest " Fuad Tabba
2025-11-10 13:45 ` [PATCH v3 7/8] KVM: arm64: Check whether a VM IOCTL is allowed " Fuad Tabba
2025-11-10 13:45 ` [PATCH v3 8/8] KVM: arm64: Prevent host from managing timer offsets for protected VMs 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=bc25a11a-d5b7-45de-bb99-c78100e5055d@arm.com \
--to=ben.horgan@arm.com \
--cc=catalin.marinas@arm.com \
--cc=joey.gouly@arm.com \
--cc=kvmarm@lists.linux.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=maz@kernel.org \
--cc=oliver.upton@linux.dev \
--cc=suzuki.poulose@arm.com \
--cc=tabba@google.com \
--cc=vladimir.murzin@arm.com \
--cc=will@kernel.org \
--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