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 7F927CCFA08 for ; Tue, 4 Nov 2025 12:59:25 +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:Cc:To:From: Subject:Message-ID:References:Mime-Version:In-Reply-To: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=4BR5h4rv9IbD76eW/W7JHUUha6GHsVyE9JD4/DnaUVM=; b=ixxV1LBQzDKHo5A6TbEecU/g2E BvN3u4RsJPEcLSuLZdxp/7qJsyO5EGDIycsFZ9QYN0mVNy7iA1AcEQqO4Zo8VUo5CoeEttwP3sUXN 9QA1wK5a8Ri6FouOl7hxejHGLfZZrTGnL5+Aq9/FmacpbX7/AcnZiso2mSkfEdAIXDEPOPdEUbain OBC6Vhk5ZQwKznS7mIIfWJAoR3QltuGF/M1rMi80wwo7XDOQKVbN5OUnZ46Ism2eW43+gC+/9y6Xm S8XqmZvKnevaTPi6xN/rrxXcixvc5uUmsrdr9w/4AMr9ipb/pks+oxrNn3Bld1bAgA7GRfSi9z7kl YYtYuCBQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux)) id 1vGGd5-0000000BpAe-22OB; Tue, 04 Nov 2025 12:59:19 +0000 Received: from mail-wm1-x34a.google.com ([2a00:1450:4864:20::34a]) by bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux)) id 1vGGd0-0000000Bp5A-3hhK for linux-arm-kernel@lists.infradead.org; Tue, 04 Nov 2025 12:59:16 +0000 Received: by mail-wm1-x34a.google.com with SMTP id 5b1f17b1804b1-46e39567579so29904575e9.0 for ; Tue, 04 Nov 2025 04:59:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1762261153; x=1762865953; darn=lists.infradead.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=4BR5h4rv9IbD76eW/W7JHUUha6GHsVyE9JD4/DnaUVM=; b=LG0LesBGLbb8Se12Jgfd8Obuu4EciNf2JJ+ndW0+n3sKYPSVPLasmqyx5vQaZXUW3K IqvcY630vhXtgO6+VfW7C+QinzsgpiSN9fyjEI642k/KHGxmRI9h/+w4ChL9YddfZu8u peIqBbFzNQI8usSCDwvAwsnjEHSZK2jqQfBnwiOUn0r8qLKl6ohzV5fXpqG3+F7+WoQ0 U2ILBQXERaj3fZurMaSGTuClkX3xktmP//2yz3Ce5w+8Bt6eaD1c24EVU5EYD074TiNf JUHaggn/t9Y0rO9UEP985JlXCYLY9S3j5KDdBqy+3tmBPAltt9tHqEIntvhiGBCT9kl3 k7Tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762261153; x=1762865953; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=4BR5h4rv9IbD76eW/W7JHUUha6GHsVyE9JD4/DnaUVM=; b=ARsmG3YFS+McL3OZjfNzrKdEYeJk5zv1DfUcMgjCPVuAr89VwhWVeGzTUaHASSqIeM ZsKfIBOc0FyLHSDnip8Xwfep4fU7nwt1SDl/RsSRhqFuz1BNcamqobL2m44DI32+Gdxp qzTLdbf35XcMeavNhYMi+R7XdWUFeu529acxEkvYzSUOakKSobQHw+PSffNx0RoVnPk7 sjTfRn0gcRevGvd7PRJjtVV6xFwQnUhH7h2G63mBCfGFVQR4Cdfs3ndH5trCtzlI3ARI l+CN9/Pf1NCjf1KSa8PVoiowUvT1dNIkQrQjBaSYLu9BQLlAUdVOwHKA/ejkcjb5PRjD DBYg== X-Forwarded-Encrypted: i=1; AJvYcCVBmYOR1g1D+LOBpcv2EsAyBp1xkmpJ5YKV7ZiiR6vkpMz4hcc5Mz0BnICXBWM5BzI/ptqEg1FH0G6VYKBhS1so@lists.infradead.org X-Gm-Message-State: AOJu0Yyyz8dCU0OhJmDolRh0z8Y0uZu31/+bXuIj8kZHohc0gPl1oQ6Y 3Ae7HrTywlCb62KWtgmUxCkdcMjh7xzo3j0ZmHyeQOLBLxjHp7TRnUM5FkEtqAvLJG7eN7gge2g pZQ== X-Google-Smtp-Source: AGHT+IHl6ePYvtMGFmBbMfWw54avkTlJ99i1th7vS7xvpsh0YXj+5bwujqI3mK986VA/yTsKBNzoJS8MFQ== X-Received: from wmd16.prod.google.com ([2002:a05:600c:6050:b0:46e:37d6:c1a6]) (user=tabba job=prod-delivery.src-stubby-dispatcher) by 2002:a05:600c:3149:b0:477:942:7521 with SMTP id 5b1f17b1804b1-477307e285dmr143199215e9.14.1762261152816; Tue, 04 Nov 2025 04:59:12 -0800 (PST) Date: Tue, 4 Nov 2025 12:59:04 +0000 In-Reply-To: <20251104125906.1919426-1-tabba@google.com> Mime-Version: 1.0 References: <20251104125906.1919426-1-tabba@google.com> X-Mailer: git-send-email 2.51.2.997.g839fc31de9-goog Message-ID: <20251104125906.1919426-7-tabba@google.com> Subject: [PATCH v1 6/8] KVM: arm64: Fix MTE flag initialization for protected VMs From: Fuad Tabba To: 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, tabba@google.com Content-Type: text/plain; charset="UTF-8" X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20251104_045914_936365_33BC7F9F X-CRM114-Status: GOOD ( 16.13 ) 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 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. This patch fixes these issues by moving the MTE flag check to be 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 --- 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 df0c59a29b35..b64f278ac8cc 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); + 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); } -- 2.51.2.997.g839fc31de9-goog