mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: zhanghao <76824143@qq.com>
To: Sean Christopherson <seanjc@google.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
	kvm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] KVM: x86: enrich kvm_fast_mmio trace event fields
Date: Fri, 24 Apr 2026 14:05:30 +0800	[thread overview]
Message-ID: <tencent_DB120129B359660BBBD7CCC9681F507C0105@qq.com> (raw)

kvm_fast_mmio currently logs only the GPA, which makes fast-MMIO traces
less useful when diagnosing access patterns.

Extend kvm_fast_mmio to carry access metadata:
  - access direction (read/write)
  - access length
  - access value

Update all x86 call sites to the new tracepoint signature. For VMX/SVM
reserved-bit MMIO paths, keep length/value as 0 where detailed payload
is not readily available. For TDX MMIO write path, pass through size/value
that are already available in context.

This improves observability while keeping existing fast-MMIO behavior
unchanged.

Signed-off-by: Hao Zhang <zhanghao1@kylinos.cn>
---
 arch/x86/kvm/svm/svm.c |  2 +-
 arch/x86/kvm/trace.h   | 22 +++++++++++++++++++---
 arch/x86/kvm/vmx/tdx.c |  2 +-
 arch/x86/kvm/vmx/vmx.c |  2 +-
 4 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index e7fdd7a9c280..1820a78d3e70 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -1981,7 +1981,7 @@ static int npf_interception(struct kvm_vcpu *vcpu)
 
 		if (nrips && svm->vmcb->control.next_rip &&
 		    !kvm_io_bus_write(vcpu, KVM_FAST_MMIO_BUS, gpa, 0, NULL)) {
-			trace_kvm_fast_mmio(gpa);
+			trace_kvm_fast_mmio(gpa, KVM_TRACE_FAST_MMIO_WRITE, 0, 0);
 			return kvm_skip_emulated_instruction(vcpu);
 		}
 	}
diff --git a/arch/x86/kvm/trace.h b/arch/x86/kvm/trace.h
index e7fdbe9efc90..d04d05d17d77 100644
--- a/arch/x86/kvm/trace.h
+++ b/arch/x86/kvm/trace.h
@@ -207,19 +207,35 @@ TRACE_EVENT(kvm_pio,
 /*
  * Tracepoint for fast mmio.
  */
+#define KVM_TRACE_FAST_MMIO_READ	0
+#define KVM_TRACE_FAST_MMIO_WRITE	1
+
+#define kvm_trace_symbol_fast_mmio \
+	{ KVM_TRACE_FAST_MMIO_READ, "read" }, \
+	{ KVM_TRACE_FAST_MMIO_WRITE, "write" }
+
 TRACE_EVENT(kvm_fast_mmio,
-	TP_PROTO(u64 gpa),
-	TP_ARGS(gpa),
+	TP_PROTO(u64 gpa, u32 type, u32 len, u64 val),
+	TP_ARGS(gpa, type, len, val),
 
 	TP_STRUCT__entry(
 		__field(u64,	gpa)
+		__field(u32,	type)
+		__field(u32,	len)
+		__field(u64,	val)
 	),
 
 	TP_fast_assign(
 		__entry->gpa		= gpa;
+		__entry->type		= type;
+		__entry->len		= len;
+		__entry->val		= val;
 	),
 
-	TP_printk("fast mmio at gpa 0x%llx", __entry->gpa)
+	TP_printk("fast mmio %s len %u gpa 0x%llx val 0x%llx",
+		  __print_symbolic(__entry->type, kvm_trace_symbol_fast_mmio),
+		  __entry->len,
+		  __entry->gpa, __entry->val)
 );
 
 /*
diff --git a/arch/x86/kvm/vmx/tdx.c b/arch/x86/kvm/vmx/tdx.c
index 04ce321ebdf3..2b4acead3d0a 100644
--- a/arch/x86/kvm/vmx/tdx.c
+++ b/arch/x86/kvm/vmx/tdx.c
@@ -1403,7 +1403,7 @@ static inline int tdx_mmio_write(struct kvm_vcpu *vcpu, gpa_t gpa, int size,
 				 unsigned long val)
 {
 	if (!kvm_io_bus_write(vcpu, KVM_FAST_MMIO_BUS, gpa, 0, NULL)) {
-		trace_kvm_fast_mmio(gpa);
+		trace_kvm_fast_mmio(gpa, KVM_TRACE_FAST_MMIO_WRITE, size, val);
 		return 0;
 	}
 
diff --git a/arch/x86/kvm/vmx/vmx.c b/arch/x86/kvm/vmx/vmx.c
index a29896a9ef14..af26b895f267 100644
--- a/arch/x86/kvm/vmx/vmx.c
+++ b/arch/x86/kvm/vmx/vmx.c
@@ -5970,7 +5970,7 @@ static int handle_ept_misconfig(struct kvm_vcpu *vcpu)
 	gpa = vmcs_read64(GUEST_PHYSICAL_ADDRESS);
 	if (!is_guest_mode(vcpu) &&
 	    !kvm_io_bus_write(vcpu, KVM_FAST_MMIO_BUS, gpa, 0, NULL)) {
-		trace_kvm_fast_mmio(gpa);
+		trace_kvm_fast_mmio(gpa, KVM_TRACE_FAST_MMIO_WRITE, 0, 0);
 		return kvm_skip_emulated_instruction(vcpu);
 	}
 

base-commit: dd6c438c3e64a5ff0b5d7e78f7f9be547803ef1b
-- 
2.25.1


             reply	other threads:[~2026-04-24  6:05 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-24  6:05 zhanghao [this message]
2026-04-27 18:37 ` 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=tencent_DB120129B359660BBBD7CCC9681F507C0105@qq.com \
    --to=76824143@qq.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=seanjc@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

all inboxes | Powered by JetHome®