]> git.pld-linux.org Git - packages/lttng-modules.git/blob - 0012-fix-KVM-x86-Unexport-kvm_x86_ops-v5.18.patch
- upstream fixes for kernel 5.18 compatibility, rel 2
[packages/lttng-modules.git] / 0012-fix-KVM-x86-Unexport-kvm_x86_ops-v5.18.patch
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)
5
6 See upstream commit :
7
8   commit dfc4e6ca041135217c07ebcd102b6694cea22856
9   Author: Sean Christopherson <seanjc@google.com>
10   Date:   Fri Jan 28 00:51:56 2022 +0000
11
12     KVM: x86: Unexport kvm_x86_ops
13
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.
19
20     No functional change intended.
21
22 Change-Id: Icee959a984570f95ab9b71354225b5aeecea7da0
23 Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
24 Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
25 ---
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
30
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
35 @@ -9,6 +9,7 @@
36  #include <asm/clocksource.h>
37  #endif
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>
42  
43 @@ -115,7 +116,40 @@ LTTNG_TRACEPOINT_EVENT_MAP(kvm_apic, kvm_x86_apic,
44  /*
45   * Tracepoint for kvm guest exit:
46   */
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),
51 +       TP_ARGS(vcpu, isa),
52 +
53 +       TP_locvar(
54 +               u32 exit_reason;
55 +               u64 info1, info2;
56 +               u32 intr_info, error_code;
57 +       ),
58 +
59 +       TP_code_pre(
60 +               lttng_kvm_x86_get_exit_info(vcpu,
61 +                               &tp_locvar->exit_reason,
62 +                               &tp_locvar->info1,
63 +                               &tp_locvar->info2,
64 +                               &tp_locvar->intr_info,
65 +                               &tp_locvar->error_code);
66 +       ),
67 +
68 +       TP_FIELDS(
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)
77 +       ),
78 +
79 +       TP_code_post()
80 +)
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),
84         TP_ARGS(vcpu, 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))
89 -#else
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))
98 +#else
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))
107  #endif
108                 ctf_integer(__u8, failed, failed)
109         )
110 diff --git a/include/wrapper/kvm-x86.h b/include/wrapper/kvm-x86.h
111 new file mode 100644
112 index 00000000..2007aebd
113 --- /dev/null
114 +++ b/include/wrapper/kvm-x86.h
115 @@ -0,0 +1,72 @@
116 +/* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
117 + *
118 + * wrapper/kvm-x86.h
119 + *
120 + * Copyright (C) 2022 Michael Jeanson <mjeanson@efficios.com>
121 + */
122 +
123 +#ifndef _LTTNG_WRAPPER_KVM_X86_H
124 +#define _LTTNG_WRAPPER_KVM_X86_H
125 +
126 +#include <linux/kvm_host.h>
127 +#include <lttng/kernel-version.h>
128 +
129 +#if LTTNG_LINUX_VERSION_CODE >= LTTNG_KERNEL_VERSION(5,18,0)
130 +
131 +#ifdef CONFIG_KALLSYMS_ALL
132 +#include <linux/kallsyms.h>
133 +#include <wrapper/kallsyms.h>
134 +
135 +static struct kvm_x86_ops *kvm_x86_ops_sym;
136 +
137 +static inline
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)
142 +{
143 +       if (!kvm_x86_ops_sym)
144 +               kvm_x86_ops_sym =
145 +                       (void *) kallsyms_lookup_dataptr("kvm_x86_ops");
146 +
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);
150 +       } else {
151 +               printk_once(KERN_WARNING "LTTng: kvm_x86_ops symbol lookup failed.\n");
152 +       }
153 +}
154 +
155 +static inline
156 +u64 lttng_kvm_x86_get_segment_base(struct kvm_vcpu *vcpu, int seg)
157 +{
158 +       if (!kvm_x86_ops_sym)
159 +               kvm_x86_ops_sym =
160 +                       (void *) kallsyms_lookup_dataptr("kvm_x86_ops");
161 +
162 +       if (kvm_x86_ops_sym) {
163 +               return kvm_x86_ops_sym->get_segment_base(vcpu, seg);
164 +       } else {
165 +               printk_once(KERN_WARNING "LTTng: kvm_x86_ops symbol lookup failed.\n");
166 +               return 0;
167 +       }
168 +}
169 +
170 +/*
171 + * Canary function to check for 'kvm_x86_ops' at compile time.
172 + *
173 + * From 'arch/x86/include/asm/kvm_host.h':
174 + *
175 + *   extern struct kvm_x86_ops kvm_x86_ops;;
176 + */
177 +static inline
178 +unsigned int __canary__kvm_x86_ops(void)
179 +{
180 +       return kvm_x86_ops.vm_size;
181 +}
182 +
183 +#endif /* CONFIG_KALLSYMS_ALL */
184 +
185 +#endif
186 +
187 +#endif /* _LTTNG_WRAPPER_KVM_X86_H */
188 -- 
189 2.36.1
190
This page took 1.954453 seconds and 3 git commands to generate.