diff mbox series

[RFC,v3,4/6] kvm: gmem: add trace point for direct map state changes

Message ID 20241030134912.515725-5-roypat@amazon.co.uk (mailing list archive)
State New
Headers show
Series Direct Map Removal for guest_memfd | expand

Checks

Context Check Description
conchuod/vmtest-for-next-PR success PR summary
conchuod/patch-4-test-1 success .github/scripts/patches/tests/build_rv32_defconfig.sh took 106.34s
conchuod/patch-4-test-2 success .github/scripts/patches/tests/build_rv64_clang_allmodconfig.sh took 992.06s
conchuod/patch-4-test-3 success .github/scripts/patches/tests/build_rv64_gcc_allmodconfig.sh took 1169.79s
conchuod/patch-4-test-4 success .github/scripts/patches/tests/build_rv64_nommu_k210_defconfig.sh took 16.03s
conchuod/patch-4-test-5 success .github/scripts/patches/tests/build_rv64_nommu_virt_defconfig.sh took 17.64s
conchuod/patch-4-test-6 warning .github/scripts/patches/tests/checkpatch.sh took 0.54s
conchuod/patch-4-test-7 success .github/scripts/patches/tests/dtb_warn_rv64.sh took 35.88s
conchuod/patch-4-test-8 success .github/scripts/patches/tests/header_inline.sh took 0.00s
conchuod/patch-4-test-9 success .github/scripts/patches/tests/kdoc.sh took 0.44s
conchuod/patch-4-test-10 success .github/scripts/patches/tests/module_param.sh took 0.01s
conchuod/patch-4-test-11 success .github/scripts/patches/tests/verify_fixes.sh took 0.00s
conchuod/patch-4-test-12 success .github/scripts/patches/tests/verify_signedoff.sh took 0.02s

Commit Message

Patrick Roy Oct. 30, 2024, 1:49 p.m. UTC
Add tracepoints to kvm_gmem_set_direct_map and
kvm_gmem_folio_set_direct_map.

The above operations can cause folios to be insert/removed into/from the
direct map. We want to be able to make sure that only those gmem folios
that we expect KVM to access are ever reinserted into the direct map,
and that all folios that are temporarily reinserted are also removed
again at a later point. Processing ftrace output is one way to verify
this.

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
---
 include/trace/events/kvm.h | 22 ++++++++++++++++++++++
 virt/kvm/guest_memfd.c     |  5 +++++
 2 files changed, 27 insertions(+)
diff mbox series

Patch

diff --git a/include/trace/events/kvm.h b/include/trace/events/kvm.h
index 74e40d5d4af42..f3d852c18fa08 100644
--- a/include/trace/events/kvm.h
+++ b/include/trace/events/kvm.h
@@ -489,6 +489,28 @@  TRACE_EVENT(kvm_test_age_hva,
 	TP_printk("mmu notifier test age hva: %#016lx", __entry->hva)
 );
 
+#ifdef CONFIG_KVM_PRIVATE_MEM
+TRACE_EVENT(kvm_gmem_direct_map_state_change,
+	TP_PROTO(pgoff_t start, pgoff_t end, bool state),
+	TP_ARGS(start, end, state),
+
+	TP_STRUCT__entry(
+		__field(pgoff_t, start)
+		__field(pgoff_t, end)
+		__field(bool, state)
+	),
+
+	TP_fast_assign(
+		__entry->start = start;
+		__entry->end = end;
+		__entry->state = state;
+	),
+
+	TP_printk("changed direct map state of guest_memfd range %lu to %lu to %s",
+		  __entry->start, __entry->end, __entry->state ? "present" : "not present")
+);
+#endif
+
 #endif /* _TRACE_KVM_MAIN_H */
 
 /* This part must be outside protection */
diff --git a/virt/kvm/guest_memfd.c b/virt/kvm/guest_memfd.c
index 54387828dcc6a..a0b3b9cacd361 100644
--- a/virt/kvm/guest_memfd.c
+++ b/virt/kvm/guest_memfd.c
@@ -7,6 +7,7 @@ 
 #include <linux/set_memory.h>
 
 #include "kvm_mm.h"
+#include "trace/events/kvm.h"
 
 struct kvm_gmem {
 	struct kvm *kvm;
@@ -169,6 +170,8 @@  static __always_unused int kvm_gmem_folio_set_direct_map(struct folio *folio, pg
 	r = __kvm_gmem_folio_set_direct_map(folio, start, end, state);
 	folio_unlock(folio);
 
+	trace_kvm_gmem_direct_map_state_change(start, end, state);
+
 unlock_xa:
 	xa_unlock(&gmem_priv->direct_map_state);
 out:
@@ -216,6 +219,8 @@  static __always_unused int kvm_gmem_set_direct_map(struct inode *inode, pgoff_t
 		folio_batch_release(&fbatch);
 	}
 
+	trace_kvm_gmem_direct_map_state_change(start, end, state);
+
 	xa_unlock(&gmem_priv->direct_map_state);
 out:
 	return r;