public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Yosry Ahmed <yosry@kernel.org>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	Venkatesh Srinivas <venkateshs@google.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	Venkatesh Srinivas <venkateshs@chromium.org>,
	Yosry Ahmed <yosry@kernel.org>
Subject: [PATCH v2 3/3] KVM: SVM: Advertise Translation Cache Extensions to userspace
Date: Sat,  7 Mar 2026 01:16:19 +0000	[thread overview]
Message-ID: <20260307011619.2324234-4-yosry@kernel.org> (raw)
In-Reply-To: <20260307011619.2324234-1-yosry@kernel.org>

From: Venkatesh Srinivas <venkateshs@chromium.org>

TCE augments the behavior of TLB invalidating instructions (INVLPG,
INVLPGB, and INVPCID) to only invalidate translations for relevant
intermediate mappings to the address range, rather than ALL intermdiate
translations.

The Linux kernel has been setting EFER.TCE if supported by the CPU since
commit 440a65b7d25f ("x86/mm: Enable AMD translation cache extensions"),
as it may improve performance.

KVM does not need to do anything to virtualize the feature, only
advertise it and allow setting EFER.TCE. If a TLB invalidating
instruction is not intercepted, it will behave according to the guest's
setting of EFER.TCE as the value will be loaded on VM-Enter. Otherwise,
KVM's emulation may invalidate more TLB entries, which is perfectly fine
as the CPU is allowed to invalidate more TLB entries that it strictly
needs to.

Advertise X86_FEATURE_TCE to userspace, and allow the guest to set
EFER.TCE if available.

Signed-off-by: Venkatesh Srinivas <venkateshs@chromium.org>
Co-developed-by: Yosry Ahmed <yosry@kernel.org>
Signed-off-by: Yosry Ahmed <yosry@kernel.org>
---
 arch/x86/kvm/cpuid.c | 1 +
 arch/x86/kvm/x86.c   | 6 ++++++
 2 files changed, 7 insertions(+)

diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
index fffbf087937d4..4f810f23b1d9b 100644
--- a/arch/x86/kvm/cpuid.c
+++ b/arch/x86/kvm/cpuid.c
@@ -1112,6 +1112,7 @@ void kvm_initialize_cpu_caps(void)
 		F(XOP),
 		/* SKINIT, WDT, LWP */
 		F(FMA4),
+		F(TCE),
 		F(TBM),
 		F(TOPOEXT),
 		VENDOR_F(PERFCTR_CORE),
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 0b5d48e75b657..f12da9e92475e 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -1743,6 +1743,9 @@ static bool __kvm_valid_efer(struct kvm_vcpu *vcpu, u64 efer)
 	if (efer & EFER_NX && !guest_cpu_cap_has(vcpu, X86_FEATURE_NX))
 		return false;
 
+	if (efer & EFER_TCE && !guest_cpu_cap_has(vcpu, X86_FEATURE_TCE))
+		return false;
+
 	return true;
 
 }
@@ -10035,6 +10038,9 @@ static void kvm_setup_efer_caps(void)
 
 	if (kvm_cpu_cap_has(X86_FEATURE_AUTOIBRS))
 		kvm_enable_efer_bits(EFER_AUTOIBRS);
+
+	if (kvm_cpu_cap_has(X86_FEATURE_TCE))
+		kvm_enable_efer_bits(EFER_TCE);
 }
 
 static inline void kvm_ops_update(struct kvm_x86_init_ops *ops)
-- 
2.53.0.473.g4a7958ca14-goog


  parent reply	other threads:[~2026-03-07  1:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-07  1:16 [PATCH v2 0/3] KVM: SVM: Advertise TCE to userspace Yosry Ahmed
2026-03-07  1:16 ` [PATCH v2 1/3] KVM: x86: Move some EFER bits enablement to common code Yosry Ahmed
2026-03-07  1:16 ` [PATCH v2 2/3] KVM: x86: Use kvm_cpu_cap_has() for EFER bits enablement checks Yosry Ahmed
2026-03-07  1:16 ` Yosry Ahmed [this message]
2026-03-07  1:54   ` [PATCH v2 3/3] KVM: SVM: Advertise Translation Cache Extensions to userspace Andrew Cooper
2026-03-09 13:53     ` Yosry Ahmed
2026-03-09 15:06       ` Sean Christopherson
2026-03-09 15:10         ` Yosry Ahmed
2026-03-09 22:53     ` Venkatesh Srinivas
2026-04-03 15:13 ` [PATCH v2 0/3] KVM: SVM: Advertise TCE " Sean Christopherson

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=20260307011619.2324234-4-yosry@kernel.org \
    --to=yosry@kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=venkateshs@chromium.org \
    --cc=venkateshs@google.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