hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/include/linux/context_tracking.h
....@@ -5,6 +5,8 @@
55 #include <linux/sched.h>
66 #include <linux/vtime.h>
77 #include <linux/context_tracking_state.h>
8
+#include <linux/instrumentation.h>
9
+
810 #include <asm/ptrace.h>
911
1012
....@@ -22,26 +24,26 @@
2224
2325 static inline void user_enter(void)
2426 {
25
- if (context_tracking_is_enabled())
27
+ if (context_tracking_enabled())
2628 context_tracking_enter(CONTEXT_USER);
2729
2830 }
2931 static inline void user_exit(void)
3032 {
31
- if (context_tracking_is_enabled())
33
+ if (context_tracking_enabled())
3234 context_tracking_exit(CONTEXT_USER);
3335 }
3436
3537 /* Called with interrupts disabled. */
36
-static inline void user_enter_irqoff(void)
38
+static __always_inline void user_enter_irqoff(void)
3739 {
38
- if (context_tracking_is_enabled())
40
+ if (context_tracking_enabled())
3941 __context_tracking_enter(CONTEXT_USER);
4042
4143 }
42
-static inline void user_exit_irqoff(void)
44
+static __always_inline void user_exit_irqoff(void)
4345 {
44
- if (context_tracking_is_enabled())
46
+ if (context_tracking_enabled())
4547 __context_tracking_exit(CONTEXT_USER);
4648 }
4749
....@@ -49,7 +51,7 @@
4951 {
5052 enum ctx_state prev_ctx;
5153
52
- if (!context_tracking_is_enabled())
54
+ if (!context_tracking_enabled())
5355 return 0;
5456
5557 prev_ctx = this_cpu_read(context_tracking.state);
....@@ -61,7 +63,7 @@
6163
6264 static inline void exception_exit(enum ctx_state prev_ctx)
6365 {
64
- if (context_tracking_is_enabled()) {
66
+ if (context_tracking_enabled()) {
6567 if (prev_ctx != CONTEXT_KERNEL)
6668 context_tracking_enter(prev_ctx);
6769 }
....@@ -75,9 +77,9 @@
7577 * is enabled. If context tracking is disabled, returns
7678 * CONTEXT_DISABLED. This should be used primarily for debugging.
7779 */
78
-static inline enum ctx_state ct_state(void)
80
+static __always_inline enum ctx_state ct_state(void)
7981 {
80
- return context_tracking_is_enabled() ?
82
+ return context_tracking_enabled() ?
8183 this_cpu_read(context_tracking.state) : CONTEXT_DISABLED;
8284 }
8385 #else
....@@ -90,7 +92,7 @@
9092 static inline enum ctx_state ct_state(void) { return CONTEXT_DISABLED; }
9193 #endif /* !CONFIG_CONTEXT_TRACKING */
9294
93
-#define CT_WARN_ON(cond) WARN_ON(context_tracking_is_enabled() && (cond))
95
+#define CT_WARN_ON(cond) WARN_ON(context_tracking_enabled() && (cond))
9496
9597 #ifdef CONFIG_CONTEXT_TRACKING_FORCE
9698 extern void context_tracking_init(void);
....@@ -101,14 +103,16 @@
101103
102104 #ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN
103105 /* must be called with irqs disabled */
104
-static inline void guest_enter_irqoff(void)
106
+static __always_inline void guest_enter_irqoff(void)
105107 {
106
- if (vtime_accounting_cpu_enabled())
108
+ instrumentation_begin();
109
+ if (vtime_accounting_enabled_this_cpu())
107110 vtime_guest_enter(current);
108111 else
109112 current->flags |= PF_VCPU;
113
+ instrumentation_end();
110114
111
- if (context_tracking_is_enabled())
115
+ if (context_tracking_enabled())
112116 __context_tracking_enter(CONTEXT_GUEST);
113117
114118 /* KVM does not hold any references to rcu protected data when it
....@@ -118,50 +122,67 @@
118122 * one time slice). Lets treat guest mode as quiescent state, just like
119123 * we do with user-mode execution.
120124 */
121
- if (!context_tracking_cpu_is_enabled())
125
+ if (!context_tracking_enabled_this_cpu()) {
126
+ instrumentation_begin();
122127 rcu_virt_note_context_switch(smp_processor_id());
128
+ instrumentation_end();
129
+ }
123130 }
124131
125
-static inline void guest_exit_irqoff(void)
132
+static __always_inline void context_tracking_guest_exit(void)
126133 {
127
- if (context_tracking_is_enabled())
134
+ if (context_tracking_enabled())
128135 __context_tracking_exit(CONTEXT_GUEST);
136
+}
129137
130
- if (vtime_accounting_cpu_enabled())
138
+static __always_inline void vtime_account_guest_exit(void)
139
+{
140
+ if (vtime_accounting_enabled_this_cpu())
131141 vtime_guest_exit(current);
132142 else
133143 current->flags &= ~PF_VCPU;
134144 }
135145
146
+static __always_inline void guest_exit_irqoff(void)
147
+{
148
+ context_tracking_guest_exit();
149
+
150
+ instrumentation_begin();
151
+ vtime_account_guest_exit();
152
+ instrumentation_end();
153
+}
154
+
136155 #else
137
-static inline void guest_enter_irqoff(void)
156
+static __always_inline void guest_enter_irqoff(void)
138157 {
139158 /*
140159 * This is running in ioctl context so its safe
141160 * to assume that it's the stime pending cputime
142161 * to flush.
143162 */
144
- vtime_account_system(current);
163
+ instrumentation_begin();
164
+ vtime_account_kernel(current);
145165 current->flags |= PF_VCPU;
146166 rcu_virt_note_context_switch(smp_processor_id());
167
+ instrumentation_end();
147168 }
148169
149
-static inline void guest_exit_irqoff(void)
170
+static __always_inline void context_tracking_guest_exit(void) { }
171
+
172
+static __always_inline void vtime_account_guest_exit(void)
150173 {
151
- /* Flush the guest cputime we spent on the guest */
152
- vtime_account_system(current);
174
+ vtime_account_kernel(current);
153175 current->flags &= ~PF_VCPU;
154176 }
155
-#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
156177
157
-static inline void guest_enter(void)
178
+static __always_inline void guest_exit_irqoff(void)
158179 {
159
- unsigned long flags;
160
-
161
- local_irq_save(flags);
162
- guest_enter_irqoff();
163
- local_irq_restore(flags);
180
+ instrumentation_begin();
181
+ /* Flush the guest cputime we spent on the guest */
182
+ vtime_account_guest_exit();
183
+ instrumentation_end();
164184 }
185
+#endif /* CONFIG_VIRT_CPU_ACCOUNTING_GEN */
165186
166187 static inline void guest_exit(void)
167188 {