[PATCH v2 3/5] KVM: implement new perf interfaces
From: Tianyi Liu
Date: Sun Oct 08 2023 - 10:56:45 EST
This patch provides two KVM implementations for the following new perf
interfaces, just redirecting them to the arch-specific implementations:
- get_frame_pointer: Return the frame pointer of the running vm.
- read_virt: Read data from a virtual address of the running vm.
Signed-off-by: Tianyi Liu <i.pear@xxxxxxxxxxx>
---
virt/kvm/kvm_main.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 486800a70..6fd6ee6c0 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -6018,6 +6018,9 @@ static unsigned int kvm_guest_state(void)
if (!kvm_arch_vcpu_in_kernel(vcpu))
state |= PERF_GUEST_USER;
+ if (kvm_arch_vcpu_is_64bit(vcpu))
+ state |= PERF_GUEST_64BIT;
+
return state;
}
@@ -6032,9 +6035,31 @@ static unsigned long kvm_guest_get_ip(void)
return kvm_arch_vcpu_get_ip(vcpu);
}
+static unsigned long kvm_guest_get_frame_pointer(void)
+{
+ struct kvm_vcpu *vcpu = kvm_get_running_vcpu();
+
+ if (WARN_ON_ONCE(!kvm_arch_pmi_in_guest(vcpu)))
+ return 0;
+
+ return kvm_arch_vcpu_get_frame_pointer(vcpu);
+}
+
+static bool kvm_guest_read_virt(void *addr, void *dest, unsigned int length)
+{
+ struct kvm_vcpu *vcpu = kvm_get_running_vcpu();
+
+ if (WARN_ON_ONCE(!kvm_arch_pmi_in_guest(vcpu)))
+ return false;
+
+ return kvm_arch_vcpu_read_virt(vcpu, addr, dest, length);
+}
+
static struct perf_guest_info_callbacks kvm_guest_cbs = {
.state = kvm_guest_state,
.get_ip = kvm_guest_get_ip,
+ .get_frame_pointer = kvm_guest_get_frame_pointer,
+ .read_virt = kvm_guest_read_virt,
.handle_intel_pt_intr = NULL,
};
--
2.42.0