public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] KVM: x86: enrich kvm_fast_mmio trace event fields
@ 2026-04-24  6:05 zhanghao
  2026-04-27 18:37 ` Sean Christopherson
  0 siblings, 1 reply; 2+ messages in thread
From: zhanghao @ 2026-04-24  6:05 UTC (permalink / raw)
  To: Sean Christopherson; +Cc: Paolo Bonzini, kvm, linux-kernel

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] KVM: x86: enrich kvm_fast_mmio trace event fields
  2026-04-24  6:05 [PATCH] KVM: x86: enrich kvm_fast_mmio trace event fields zhanghao
@ 2026-04-27 18:37 ` Sean Christopherson
  0 siblings, 0 replies; 2+ messages in thread
From: Sean Christopherson @ 2026-04-27 18:37 UTC (permalink / raw)
  To: zhanghao; +Cc: Paolo Bonzini, kvm, linux-kernel

On Fri, Apr 24, 2026, zhanghao wrote:
> kvm_fast_mmio currently logs only the GPA, which makes fast-MMIO traces
> less useful when diagnosing access patterns.

What's the overall use case / motivation?  Fast MMIO doesn't consume the value,
length, or type.  Why trace something that KVM ignores by design?

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-27 18:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-24  6:05 [PATCH] KVM: x86: enrich kvm_fast_mmio trace event fields zhanghao
2026-04-27 18:37 ` Sean Christopherson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox