1 From 45240b53fb037012a86613150fd5dc7e151fb7d1 Mon Sep 17 00:00:00 2001
2 From: Michael Jeanson <mjeanson@efficios.com>
3 Date: Mon, 4 Apr 2022 16:28:26 -0400
4 Subject: [PATCH 12/13] fix: KVM: x86: Unexport kvm_x86_ops (v5.18)
8 commit dfc4e6ca041135217c07ebcd102b6694cea22856
9 Author: Sean Christopherson <seanjc@google.com>
10 Date: Fri Jan 28 00:51:56 2022 +0000
12 KVM: x86: Unexport kvm_x86_ops
14 Drop the export of kvm_x86_ops now it is no longer referenced by SVM or
15 VMX. Disallowing access to kvm_x86_ops is very desirable as it prevents
16 vendor code from incorrectly modifying hooks after they have been set by
17 kvm_arch_hardware_setup(), and more importantly after each function's
18 associated static_call key has been updated.
20 No functional change intended.
22 Change-Id: Icee959a984570f95ab9b71354225b5aeecea7da0
23 Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
24 Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
26 .../events/arch/x86/kvm/trace.h | 47 +++++++++++-
27 include/wrapper/kvm-x86.h | 72 +++++++++++++++++++
28 2 files changed, 117 insertions(+), 2 deletions(-)
29 create mode 100644 include/wrapper/kvm-x86.h
31 diff --git a/include/instrumentation/events/arch/x86/kvm/trace.h b/include/instrumentation/events/arch/x86/kvm/trace.h
32 index 42e5b94d..0d6c4e33 100644
33 --- a/include/instrumentation/events/arch/x86/kvm/trace.h
34 +++ b/include/instrumentation/events/arch/x86/kvm/trace.h
36 #include <asm/clocksource.h>
38 #include <lttng/kernel-version.h>
39 +#include <wrapper/kvm-x86.h>
40 #include <../arch/x86/kvm/lapic.h>
41 #include <../arch/x86/kvm/kvm_cache_regs.h>
43 @@ -115,7 +116,40 @@ LTTNG_TRACEPOINT_EVENT_MAP(kvm_apic, kvm_x86_apic,
45 * Tracepoint for kvm guest exit:
47 -#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,16,0))
48 +#if (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,18,0))
49 +LTTNG_TRACEPOINT_EVENT_CODE_MAP(kvm_exit, kvm_x86_exit,
50 + TP_PROTO(struct kvm_vcpu *vcpu, u32 isa),
56 + u32 intr_info, error_code;
60 + lttng_kvm_x86_get_exit_info(vcpu,
61 + &tp_locvar->exit_reason,
64 + &tp_locvar->intr_info,
65 + &tp_locvar->error_code);
69 + ctf_integer(unsigned int, exit_reason, tp_locvar->exit_reason)
70 + ctf_integer(unsigned long, guest_rip, kvm_rip_read(vcpu))
71 + ctf_integer(u32, isa, isa)
72 + ctf_integer(u64, info1, tp_locvar->info1)
73 + ctf_integer(u64, info2, tp_locvar->info2)
74 + ctf_integer(u32, intr_info, tp_locvar->intr_info)
75 + ctf_integer(u32, error_code, tp_locvar->error_code)
76 + ctf_integer(unsigned int, vcpu_id, vcpu->vcpu_id)
81 +#elif (LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,16,0))
82 LTTNG_TRACEPOINT_EVENT_CODE_MAP(kvm_exit, kvm_x86_exit,
83 TP_PROTO(struct kvm_vcpu *vcpu, u32 isa),
85 @@ -535,7 +569,7 @@ LTTNG_TRACEPOINT_EVENT_MAP(kvm_emulate_insn, kvm_x86_emulate_insn,
86 vcpu->arch.emulate_ctxt.fetch.data)
87 ctf_array(__u8, insn, vcpu->arch.emulate_ctxt.fetch.data, 15)
88 ctf_integer(__u8, flags, kei_decode_mode(vcpu->arch.emulate_ctxt.mode))
90 +#elif (LTTNG_LINUX_VERSION_CODE < LTTNG_KERNEL_VERSION(5,18,0))
91 ctf_integer(__u64, rip, vcpu->arch.emulate_ctxt->_eip -
92 (vcpu->arch.emulate_ctxt->fetch.ptr -
93 vcpu->arch.emulate_ctxt->fetch.data))
94 @@ -544,6 +578,15 @@ LTTNG_TRACEPOINT_EVENT_MAP(kvm_emulate_insn, kvm_x86_emulate_insn,
95 vcpu->arch.emulate_ctxt->fetch.data)
96 ctf_array(__u8, insn, vcpu->arch.emulate_ctxt->fetch.data, 15)
97 ctf_integer(__u8, flags, kei_decode_mode(vcpu->arch.emulate_ctxt->mode))
99 + ctf_integer(__u64, rip, vcpu->arch.emulate_ctxt->_eip -
100 + (vcpu->arch.emulate_ctxt->fetch.ptr -
101 + vcpu->arch.emulate_ctxt->fetch.data))
102 + ctf_integer(__u32, csbase, lttng_kvm_x86_get_segment_base(vcpu, VCPU_SREG_CS))
103 + ctf_integer(__u8, len, vcpu->arch.emulate_ctxt->fetch.ptr -
104 + vcpu->arch.emulate_ctxt->fetch.data)
105 + ctf_array(__u8, insn, vcpu->arch.emulate_ctxt->fetch.data, 15)
106 + ctf_integer(__u8, flags, kei_decode_mode(vcpu->arch.emulate_ctxt->mode))
108 ctf_integer(__u8, failed, failed)
110 diff --git a/include/wrapper/kvm-x86.h b/include/wrapper/kvm-x86.h
112 index 00000000..2007aebd
114 +++ b/include/wrapper/kvm-x86.h
116 +/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
118 + * wrapper/kvm-x86.h
120 + * Copyright (C) 2022 Michael Jeanson <mjeanson@efficios.com>
123 +#ifndef _LTTNG_WRAPPER_KVM_X86_H
124 +#define _LTTNG_WRAPPER_KVM_X86_H
126 +#include <linux/kvm_host.h>
127 +#include <lttng/kernel-version.h>
129 +#if LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,18,0)
131 +#ifdef CONFIG_KALLSYMS_ALL
132 +#include <linux/kallsyms.h>
133 +#include <wrapper/kallsyms.h>
135 +static struct kvm_x86_ops *kvm_x86_ops_sym;
138 +void lttng_kvm_x86_get_exit_info(
139 + struct kvm_vcpu *vcpu, u32 *reason,
140 + u64 *info1, u64 *info2,
141 + u32 *exit_int_info, u32 *exit_int_info_err_code)
143 + if (!kvm_x86_ops_sym)
145 + (void *) kallsyms_lookup_dataptr("kvm_x86_ops");
147 + if (kvm_x86_ops_sym) {
148 + kvm_x86_ops_sym->get_exit_info(vcpu, reason, info1, info2,
149 + exit_int_info, exit_int_info_err_code);
151 + printk_once(KERN_WARNING "LTTng: kvm_x86_ops symbol lookup failed.\n");
156 +u64 lttng_kvm_x86_get_segment_base(struct kvm_vcpu *vcpu, int seg)
158 + if (!kvm_x86_ops_sym)
160 + (void *) kallsyms_lookup_dataptr("kvm_x86_ops");
162 + if (kvm_x86_ops_sym) {
163 + return kvm_x86_ops_sym->get_segment_base(vcpu, seg);
165 + printk_once(KERN_WARNING "LTTng: kvm_x86_ops symbol lookup failed.\n");
171 + * Canary function to check for 'kvm_x86_ops' at compile time.
173 + * From 'arch/x86/include/asm/kvm_host.h':
175 + * extern struct kvm_x86_ops kvm_x86_ops;;
178 +unsigned int __canary__kvm_x86_ops(void)
180 + return kvm_x86_ops.vm_size;
183 +#endif /* CONFIG_KALLSYMS_ALL */
187 +#endif /* _LTTNG_WRAPPER_KVM_X86_H */