forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-09-20 cf4ce59b3b70238352c7f1729f0f7223214828ad
kernel/arch/x86/include/asm/msr.h
....@@ -60,22 +60,20 @@
6060 #define EAX_EDX_RET(val, low, high) "=A" (val)
6161 #endif
6262
63
-#ifdef CONFIG_TRACEPOINTS
6463 /*
6564 * Be very careful with includes. This header is prone to include loops.
6665 */
6766 #include <asm/atomic.h>
6867 #include <linux/tracepoint-defs.h>
6968
70
-extern struct tracepoint __tracepoint_read_msr;
71
-extern struct tracepoint __tracepoint_write_msr;
72
-extern struct tracepoint __tracepoint_rdpmc;
73
-#define msr_tracepoint_active(t) static_key_false(&(t).key)
69
+#ifdef CONFIG_TRACEPOINTS
70
+DECLARE_TRACEPOINT(read_msr);
71
+DECLARE_TRACEPOINT(write_msr);
72
+DECLARE_TRACEPOINT(rdpmc);
7473 extern void do_trace_write_msr(unsigned int msr, u64 val, int failed);
7574 extern void do_trace_read_msr(unsigned int msr, u64 val, int failed);
7675 extern void do_trace_rdpmc(unsigned int msr, u64 val, int failed);
7776 #else
78
-#define msr_tracepoint_active(t) false
7977 static inline void do_trace_write_msr(unsigned int msr, u64 val, int failed) {}
8078 static inline void do_trace_read_msr(unsigned int msr, u64 val, int failed) {}
8179 static inline void do_trace_rdpmc(unsigned int msr, u64 val, int failed) {}
....@@ -128,7 +126,7 @@
128126
129127 val = __rdmsr(msr);
130128
131
- if (msr_tracepoint_active(__tracepoint_read_msr))
129
+ if (tracepoint_enabled(read_msr))
132130 do_trace_read_msr(msr, val, 0);
133131
134132 return val;
....@@ -150,7 +148,7 @@
150148 _ASM_EXTABLE(2b, 3b)
151149 : [err] "=r" (*err), EAX_EDX_RET(val, low, high)
152150 : "c" (msr), [fault] "i" (-EIO));
153
- if (msr_tracepoint_active(__tracepoint_read_msr))
151
+ if (tracepoint_enabled(read_msr))
154152 do_trace_read_msr(msr, EAX_EDX_VAL(val, low, high), *err);
155153 return EAX_EDX_VAL(val, low, high);
156154 }
....@@ -161,7 +159,7 @@
161159 {
162160 __wrmsr(msr, low, high);
163161
164
- if (msr_tracepoint_active(__tracepoint_write_msr))
162
+ if (tracepoint_enabled(write_msr))
165163 do_trace_write_msr(msr, ((u64)high << 32 | low), 0);
166164 }
167165
....@@ -181,7 +179,7 @@
181179 : "c" (msr), "0" (low), "d" (high),
182180 [fault] "i" (-EIO)
183181 : "memory");
184
- if (msr_tracepoint_active(__tracepoint_write_msr))
182
+ if (tracepoint_enabled(write_msr))
185183 do_trace_write_msr(msr, ((u64)high << 32 | low), err);
186184 return err;
187185 }
....@@ -217,6 +215,8 @@
217215 */
218216 static __always_inline unsigned long long rdtsc_ordered(void)
219217 {
218
+ DECLARE_ARGS(val, low, high);
219
+
220220 /*
221221 * The RDTSC instruction is not ordered relative to memory
222222 * access. The Intel SDM and the AMD APM are both vague on this
....@@ -227,9 +227,18 @@
227227 * ordering guarantees as reading from a global memory location
228228 * that some other imaginary CPU is updating continuously with a
229229 * time stamp.
230
+ *
231
+ * Thus, use the preferred barrier on the respective CPU, aiming for
232
+ * RDTSCP as the default.
230233 */
231
- barrier_nospec();
232
- return rdtsc();
234
+ asm volatile(ALTERNATIVE_2("rdtsc",
235
+ "lfence; rdtsc", X86_FEATURE_LFENCE_RDTSC,
236
+ "rdtscp", X86_FEATURE_RDTSCP)
237
+ : EAX_EDX_RET(val, low, high)
238
+ /* RDTSCP clobbers ECX with MSR_TSC_AUX. */
239
+ :: "ecx");
240
+
241
+ return EAX_EDX_VAL(val, low, high);
233242 }
234243
235244 static inline unsigned long long native_read_pmc(int counter)
....@@ -237,12 +246,12 @@
237246 DECLARE_ARGS(val, low, high);
238247
239248 asm volatile("rdpmc" : EAX_EDX_RET(val, low, high) : "c" (counter));
240
- if (msr_tracepoint_active(__tracepoint_rdpmc))
249
+ if (tracepoint_enabled(rdpmc))
241250 do_trace_rdpmc(counter, EAX_EDX_VAL(val, low, high), 0);
242251 return EAX_EDX_VAL(val, low, high);
243252 }
244253
245
-#ifdef CONFIG_PARAVIRT
254
+#ifdef CONFIG_PARAVIRT_XXL
246255 #include <asm/paravirt.h>
247256 #else
248257 #include <linux/errno.h>
....@@ -305,7 +314,7 @@
305314
306315 #define rdpmcl(counter, val) ((val) = native_read_pmc(counter))
307316
308
-#endif /* !CONFIG_PARAVIRT */
317
+#endif /* !CONFIG_PARAVIRT_XXL */
309318
310319 /*
311320 * 64-bit version of wrmsr_safe():