[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241030134912.515725-5-roypat@amazon.co.uk>
Date: Wed, 30 Oct 2024 13:49:08 +0000
From: Patrick Roy <roypat@...zon.co.uk>
To: <tabba@...gle.com>, <quic_eberman@...cinc.com>, <david@...hat.com>,
<seanjc@...gle.com>, <pbonzini@...hat.com>, <jthoughton@...gle.com>,
<ackerleytng@...gle.com>, <vannapurve@...gle.com>, <rppt@...nel.org>
CC: Patrick Roy <roypat@...zon.co.uk>, <graf@...zon.com>,
<jgowans@...zon.com>, <derekmn@...zon.com>, <kalyazin@...zon.com>,
<xmarcalx@...zon.com>, <linux-mm@...ck.org>, <corbet@....net>,
<catalin.marinas@....com>, <will@...nel.org>, <chenhuacai@...nel.org>,
<kernel@...0n.name>, <paul.walmsley@...ive.com>, <palmer@...belt.com>,
<aou@...s.berkeley.edu>, <hca@...ux.ibm.com>, <gor@...ux.ibm.com>,
<agordeev@...ux.ibm.com>, <borntraeger@...ux.ibm.com>, <svens@...ux.ibm.com>,
<gerald.schaefer@...ux.ibm.com>, <tglx@...utronix.de>, <mingo@...hat.com>,
<bp@...en8.de>, <dave.hansen@...ux.intel.com>, <x86@...nel.org>,
<hpa@...or.com>, <luto@...nel.org>, <peterz@...radead.org>,
<rostedt@...dmis.org>, <mhiramat@...nel.org>,
<mathieu.desnoyers@...icios.com>, <shuah@...nel.org>, <kvm@...r.kernel.org>,
<linux-doc@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
<linux-arm-kernel@...ts.infradead.org>, <loongarch@...ts.linux.dev>,
<linux-riscv@...ts.infradead.org>, <linux-s390@...r.kernel.org>,
<linux-trace-kernel@...r.kernel.org>, <linux-kselftest@...r.kernel.org>
Subject: [RFC PATCH v3 4/6] kvm: gmem: add trace point for direct map state changes
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@...zon.co.uk>
---
include/trace/events/kvm.h | 22 ++++++++++++++++++++++
virt/kvm/guest_memfd.c | 5 +++++
2 files changed, 27 insertions(+)
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;
--
2.47.0
Powered by blists - more mailing lists