forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-08 01573e231f18eb2d99162747186f59511f56b64d
kernel/arch/x86/include/asm/debugreg.h
....@@ -8,7 +8,7 @@
88
99 DECLARE_PER_CPU(unsigned long, cpu_dr7);
1010
11
-#ifndef CONFIG_PARAVIRT
11
+#ifndef CONFIG_PARAVIRT_XXL
1212 /*
1313 * These special macros can be used to get or set a debugging register
1414 */
....@@ -18,7 +18,7 @@
1818 native_set_debugreg(register, value)
1919 #endif
2020
21
-static inline unsigned long native_get_debugreg(int regno)
21
+static __always_inline unsigned long native_get_debugreg(int regno)
2222 {
2323 unsigned long val = 0; /* Damn you, gcc! */
2424
....@@ -47,7 +47,7 @@
4747 return val;
4848 }
4949
50
-static inline void native_set_debugreg(int regno, unsigned long value)
50
+static __always_inline void native_set_debugreg(int regno, unsigned long value)
5151 {
5252 switch (regno) {
5353 case 0:
....@@ -85,35 +85,45 @@
8585 set_debugreg(0UL, 3);
8686 }
8787
88
-static inline int hw_breakpoint_active(void)
88
+static __always_inline bool hw_breakpoint_active(void)
8989 {
9090 return __this_cpu_read(cpu_dr7) & DR_GLOBAL_ENABLE_MASK;
9191 }
9292
93
-extern void aout_dump_debugregs(struct user *dump);
94
-
9593 extern void hw_breakpoint_restore(void);
9694
97
-#ifdef CONFIG_X86_64
98
-DECLARE_PER_CPU(int, debug_stack_usage);
99
-static inline void debug_stack_usage_inc(void)
95
+static __always_inline unsigned long local_db_save(void)
10096 {
101
- __this_cpu_inc(debug_stack_usage);
97
+ unsigned long dr7;
98
+
99
+ if (static_cpu_has(X86_FEATURE_HYPERVISOR) && !hw_breakpoint_active())
100
+ return 0;
101
+
102
+ get_debugreg(dr7, 7);
103
+ dr7 &= ~0x400; /* architecturally set bit */
104
+ if (dr7)
105
+ set_debugreg(0, 7);
106
+ /*
107
+ * Ensure the compiler doesn't lower the above statements into
108
+ * the critical section; disabling breakpoints late would not
109
+ * be good.
110
+ */
111
+ barrier();
112
+
113
+ return dr7;
102114 }
103
-static inline void debug_stack_usage_dec(void)
115
+
116
+static __always_inline void local_db_restore(unsigned long dr7)
104117 {
105
- __this_cpu_dec(debug_stack_usage);
118
+ /*
119
+ * Ensure the compiler doesn't raise this statement into
120
+ * the critical section; enabling breakpoints early would
121
+ * not be good.
122
+ */
123
+ barrier();
124
+ if (dr7)
125
+ set_debugreg(dr7, 7);
106126 }
107
-int is_debug_stack(unsigned long addr);
108
-void debug_stack_set_zero(void);
109
-void debug_stack_reset(void);
110
-#else /* !X86_64 */
111
-static inline int is_debug_stack(unsigned long addr) { return 0; }
112
-static inline void debug_stack_set_zero(void) { }
113
-static inline void debug_stack_reset(void) { }
114
-static inline void debug_stack_usage_inc(void) { }
115
-static inline void debug_stack_usage_dec(void) { }
116
-#endif /* X86_64 */
117127
118128 #ifdef CONFIG_CPU_SUP_AMD
119129 extern void set_dr_addr_mask(unsigned long mask, int dr);