Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Jim Mattson <jmattson@google.com>
To: jmattson@google.com
Cc: amit.shah@amd.com, kvm@vger.kernel.org, pbonzini@redhat.com,
	 seanjc@google.com, venkateshs@google.com, yosry@kernel.org
Subject: [PATCH v2 3/3] KVM: x86: Flush guest TLB on MTRR MSR writes
Date: Fri, 17 Jul 2026 16:05:42 -0700	[thread overview]
Message-ID: <20260717230542.3555587-4-jmattson@google.com> (raw)
In-Reply-To: <20260717230542.3555587-1-jmattson@google.com>

Per both the AMD APM and the Intel SDM, writing to an MTRR with WRMSR is an
implicit TLB invalidation that invalidates all TLB entries (including
global entries). [The APM uses the word, "update," which could be construed
to mean "modify," but it is unclear.]

Previously, kvm_mtrr_set_msr() stored the updated MTRR state without
requesting a TLB flush. This broke x86 architectural compliance by leaving
existing TLB entries in hardware. Additionally, on AMD CPUs supporting
ERAPS, omitting the TLB flush request meant VCPU_REG_ERAPS was never
dirtied on MTRR writes, leaving the Return Address Predictor (RAP/RSB)
uncleared.

Issue a KVM_REQ_TLB_FLUSH_GUEST request on every MTRR MSR write to match
x86 architectural semantics.

Fixes: 9ba075a664df ("KVM: MTRR support")
Assisted-by: Gemini:Gemini-Next
Signed-off-by: Jim Mattson <jmattson@google.com>
---
 arch/x86/kvm/mtrr.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/x86/kvm/mtrr.c b/arch/x86/kvm/mtrr.c
index 6f74e2b27c1e..ca5e5c7f7022 100644
--- a/arch/x86/kvm/mtrr.c
+++ b/arch/x86/kvm/mtrr.c
@@ -105,6 +105,7 @@ int kvm_mtrr_set_msr(struct kvm_vcpu *vcpu, u32 msr, u64 data)
 		return 1;
 
 	*mtrr = data;
+	kvm_make_request(KVM_REQ_TLB_FLUSH_GUEST, vcpu);
 	return 0;
 }
 
-- 
2.55.0.229.g6434b31f56-goog


  parent reply	other threads:[~2026-07-17 23:05 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-17 23:05 [PATCH v2 0/3] KVM: x86/SVM: Fixes for AMD ERAPS virtualization Jim Mattson
2026-07-17 23:05 ` [PATCH v2 1/3] KVM: SVM: Configure ALLOW_LARGER_RAP in svm_vcpu_after_set_cpuid() Jim Mattson
2026-07-20 15:52   ` Sean Christopherson
2026-07-20 16:12     ` Sean Christopherson
2026-07-17 23:05 ` [PATCH v2 2/3] KVM: SVM: Dirty ERAPS register on all ASID TLB flushes Jim Mattson
2026-07-20 15:33   ` Sean Christopherson
2026-07-20 16:41     ` Jim Mattson
2026-07-17 23:05 ` Jim Mattson [this message]
2026-07-20 15:46   ` [PATCH v2 3/3] KVM: x86: Flush guest TLB on MTRR MSR writes 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=20260717230542.3555587-4-jmattson@google.com \
    --to=jmattson@google.com \
    --cc=amit.shah@amd.com \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@google.com \
    --cc=venkateshs@google.com \
    --cc=yosry@kernel.org \
    /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