Thomas Gleixner | 53aaf26 | 2020-02-25 23:16:12 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | #ifndef _ASM_X86_IDTENTRY_H |
| 3 | #define _ASM_X86_IDTENTRY_H |
| 4 | |
| 5 | /* Interrupts/Exceptions */ |
| 6 | #include <asm/trapnr.h> |
| 7 | |
| 8 | #ifndef __ASSEMBLY__ |
Thomas Gleixner | 6368558 | 2020-05-21 22:05:38 +0200 | [diff] [blame] | 9 | #include <linux/hardirq.h> |
| 10 | |
| 11 | #include <asm/irq_stack.h> |
Thomas Gleixner | 53aaf26 | 2020-02-25 23:16:12 +0100 | [diff] [blame] | 12 | |
Thomas Gleixner | 9f9781b | 2020-05-21 22:05:18 +0200 | [diff] [blame] | 13 | void idtentry_enter_user(struct pt_regs *regs); |
| 14 | void idtentry_exit_user(struct pt_regs *regs); |
| 15 | |
Thomas Gleixner | 9ee01e0 | 2020-05-21 22:05:20 +0200 | [diff] [blame] | 16 | bool idtentry_enter_cond_rcu(struct pt_regs *regs); |
Thomas Gleixner | 3eeec38 | 2020-05-21 22:05:17 +0200 | [diff] [blame] | 17 | void idtentry_exit_cond_rcu(struct pt_regs *regs, bool rcu_exit); |
| 18 | |
Thomas Gleixner | 53aaf26 | 2020-02-25 23:16:12 +0100 | [diff] [blame] | 19 | /** |
| 20 | * DECLARE_IDTENTRY - Declare functions for simple IDT entry points |
| 21 | * No error code pushed by hardware |
| 22 | * @vector: Vector number (ignored for C) |
| 23 | * @func: Function name of the entry point |
| 24 | * |
| 25 | * Declares three functions: |
| 26 | * - The ASM entry point: asm_##func |
| 27 | * - The XEN PV trap entry point: xen_##func (maybe unused) |
| 28 | * - The C handler called from the ASM entry point |
| 29 | * |
| 30 | * Note: This is the C variant of DECLARE_IDTENTRY(). As the name says it |
| 31 | * declares the entry points for usage in C code. There is an ASM variant |
| 32 | * as well which is used to emit the entry stubs in entry_32/64.S. |
| 33 | */ |
| 34 | #define DECLARE_IDTENTRY(vector, func) \ |
| 35 | asmlinkage void asm_##func(void); \ |
| 36 | asmlinkage void xen_asm_##func(void); \ |
| 37 | __visible void func(struct pt_regs *regs) |
| 38 | |
| 39 | /** |
| 40 | * DEFINE_IDTENTRY - Emit code for simple IDT entry points |
| 41 | * @func: Function name of the entry point |
| 42 | * |
| 43 | * @func is called from ASM entry code with interrupts disabled. |
| 44 | * |
| 45 | * The macro is written so it acts as function definition. Append the |
| 46 | * body with a pair of curly brackets. |
| 47 | * |
| 48 | * idtentry_enter() contains common code which has to be invoked before |
| 49 | * arbitrary code in the body. idtentry_exit() contains common code |
| 50 | * which has to run before returning to the low level assembly code. |
| 51 | */ |
| 52 | #define DEFINE_IDTENTRY(func) \ |
| 53 | static __always_inline void __##func(struct pt_regs *regs); \ |
| 54 | \ |
| 55 | __visible noinstr void func(struct pt_regs *regs) \ |
| 56 | { \ |
Thomas Gleixner | fa95d7d | 2020-05-21 22:05:19 +0200 | [diff] [blame] | 57 | bool rcu_exit = idtentry_enter_cond_rcu(regs); \ |
| 58 | \ |
Thomas Gleixner | 53aaf26 | 2020-02-25 23:16:12 +0100 | [diff] [blame] | 59 | instrumentation_begin(); \ |
| 60 | __##func (regs); \ |
| 61 | instrumentation_end(); \ |
Thomas Gleixner | fa95d7d | 2020-05-21 22:05:19 +0200 | [diff] [blame] | 62 | idtentry_exit_cond_rcu(regs, rcu_exit); \ |
Thomas Gleixner | 53aaf26 | 2020-02-25 23:16:12 +0100 | [diff] [blame] | 63 | } \ |
| 64 | \ |
| 65 | static __always_inline void __##func(struct pt_regs *regs) |
| 66 | |
Thomas Gleixner | d772905 | 2020-02-25 23:16:30 +0100 | [diff] [blame] | 67 | /* Special case for 32bit IRET 'trap' */ |
| 68 | #define DECLARE_IDTENTRY_SW DECLARE_IDTENTRY |
| 69 | #define DEFINE_IDTENTRY_SW DEFINE_IDTENTRY |
| 70 | |
Thomas Gleixner | aabfe53 | 2020-02-25 23:16:21 +0100 | [diff] [blame] | 71 | /** |
| 72 | * DECLARE_IDTENTRY_ERRORCODE - Declare functions for simple IDT entry points |
| 73 | * Error code pushed by hardware |
| 74 | * @vector: Vector number (ignored for C) |
| 75 | * @func: Function name of the entry point |
| 76 | * |
| 77 | * Declares three functions: |
| 78 | * - The ASM entry point: asm_##func |
| 79 | * - The XEN PV trap entry point: xen_##func (maybe unused) |
| 80 | * - The C handler called from the ASM entry point |
| 81 | * |
| 82 | * Same as DECLARE_IDTENTRY, but has an extra error_code argument for the |
| 83 | * C-handler. |
| 84 | */ |
| 85 | #define DECLARE_IDTENTRY_ERRORCODE(vector, func) \ |
| 86 | asmlinkage void asm_##func(void); \ |
| 87 | asmlinkage void xen_asm_##func(void); \ |
| 88 | __visible void func(struct pt_regs *regs, unsigned long error_code) |
| 89 | |
| 90 | /** |
| 91 | * DEFINE_IDTENTRY_ERRORCODE - Emit code for simple IDT entry points |
| 92 | * Error code pushed by hardware |
| 93 | * @func: Function name of the entry point |
| 94 | * |
| 95 | * Same as DEFINE_IDTENTRY, but has an extra error_code argument |
| 96 | */ |
| 97 | #define DEFINE_IDTENTRY_ERRORCODE(func) \ |
| 98 | static __always_inline void __##func(struct pt_regs *regs, \ |
| 99 | unsigned long error_code); \ |
| 100 | \ |
| 101 | __visible noinstr void func(struct pt_regs *regs, \ |
| 102 | unsigned long error_code) \ |
| 103 | { \ |
Thomas Gleixner | fa95d7d | 2020-05-21 22:05:19 +0200 | [diff] [blame] | 104 | bool rcu_exit = idtentry_enter_cond_rcu(regs); \ |
| 105 | \ |
Thomas Gleixner | aabfe53 | 2020-02-25 23:16:21 +0100 | [diff] [blame] | 106 | instrumentation_begin(); \ |
| 107 | __##func (regs, error_code); \ |
| 108 | instrumentation_end(); \ |
Thomas Gleixner | fa95d7d | 2020-05-21 22:05:19 +0200 | [diff] [blame] | 109 | idtentry_exit_cond_rcu(regs, rcu_exit); \ |
Thomas Gleixner | aabfe53 | 2020-02-25 23:16:21 +0100 | [diff] [blame] | 110 | } \ |
| 111 | \ |
| 112 | static __always_inline void __##func(struct pt_regs *regs, \ |
| 113 | unsigned long error_code) |
| 114 | |
Thomas Gleixner | 0dc6cdc | 2020-03-04 15:22:09 +0100 | [diff] [blame] | 115 | /** |
| 116 | * DECLARE_IDTENTRY_RAW - Declare functions for raw IDT entry points |
| 117 | * No error code pushed by hardware |
| 118 | * @vector: Vector number (ignored for C) |
| 119 | * @func: Function name of the entry point |
| 120 | * |
| 121 | * Maps to DECLARE_IDTENTRY(). |
| 122 | */ |
| 123 | #define DECLARE_IDTENTRY_RAW(vector, func) \ |
| 124 | DECLARE_IDTENTRY(vector, func) |
| 125 | |
| 126 | /** |
| 127 | * DEFINE_IDTENTRY_RAW - Emit code for raw IDT entry points |
| 128 | * @func: Function name of the entry point |
| 129 | * |
| 130 | * @func is called from ASM entry code with interrupts disabled. |
| 131 | * |
| 132 | * The macro is written so it acts as function definition. Append the |
| 133 | * body with a pair of curly brackets. |
| 134 | * |
| 135 | * Contrary to DEFINE_IDTENTRY() this does not invoke the |
| 136 | * idtentry_enter/exit() helpers before and after the body invocation. This |
| 137 | * needs to be done in the body itself if applicable. Use if extra work |
| 138 | * is required before the enter/exit() helpers are invoked. |
| 139 | */ |
| 140 | #define DEFINE_IDTENTRY_RAW(func) \ |
| 141 | __visible noinstr void func(struct pt_regs *regs) |
| 142 | |
Thomas Gleixner | 6a8dfa8 | 2020-02-25 23:33:30 +0100 | [diff] [blame] | 143 | /** |
| 144 | * DECLARE_IDTENTRY_RAW_ERRORCODE - Declare functions for raw IDT entry points |
| 145 | * Error code pushed by hardware |
| 146 | * @vector: Vector number (ignored for C) |
| 147 | * @func: Function name of the entry point |
| 148 | * |
| 149 | * Maps to DECLARE_IDTENTRY_ERRORCODE() |
| 150 | */ |
| 151 | #define DECLARE_IDTENTRY_RAW_ERRORCODE(vector, func) \ |
| 152 | DECLARE_IDTENTRY_ERRORCODE(vector, func) |
| 153 | |
| 154 | /** |
| 155 | * DEFINE_IDTENTRY_RAW_ERRORCODE - Emit code for raw IDT entry points |
| 156 | * @func: Function name of the entry point |
| 157 | * |
| 158 | * @func is called from ASM entry code with interrupts disabled. |
| 159 | * |
| 160 | * The macro is written so it acts as function definition. Append the |
| 161 | * body with a pair of curly brackets. |
| 162 | * |
| 163 | * Contrary to DEFINE_IDTENTRY_ERRORCODE() this does not invoke the |
| 164 | * idtentry_enter/exit() helpers before and after the body invocation. This |
| 165 | * needs to be done in the body itself if applicable. Use if extra work |
| 166 | * is required before the enter/exit() helpers are invoked. |
| 167 | */ |
| 168 | #define DEFINE_IDTENTRY_RAW_ERRORCODE(func) \ |
| 169 | __visible noinstr void func(struct pt_regs *regs, unsigned long error_code) |
| 170 | |
Thomas Gleixner | 2f6474e | 2020-05-21 22:05:26 +0200 | [diff] [blame] | 171 | /** |
Thomas Gleixner | 0bf7c31 | 2020-05-21 22:05:36 +0200 | [diff] [blame] | 172 | * DECLARE_IDTENTRY_IRQ - Declare functions for device interrupt IDT entry |
| 173 | * points (common/spurious) |
| 174 | * @vector: Vector number (ignored for C) |
| 175 | * @func: Function name of the entry point |
| 176 | * |
| 177 | * Maps to DECLARE_IDTENTRY_ERRORCODE() |
| 178 | */ |
| 179 | #define DECLARE_IDTENTRY_IRQ(vector, func) \ |
| 180 | DECLARE_IDTENTRY_ERRORCODE(vector, func) |
| 181 | |
| 182 | /** |
| 183 | * DEFINE_IDTENTRY_IRQ - Emit code for device interrupt IDT entry points |
| 184 | * @func: Function name of the entry point |
| 185 | * |
| 186 | * The vector number is pushed by the low level entry stub and handed |
| 187 | * to the function as error_code argument which needs to be truncated |
| 188 | * to an u8 because the push is sign extending. |
| 189 | * |
| 190 | * On 64-bit idtentry_enter/exit() are invoked in the ASM entry code before |
| 191 | * and after switching to the interrupt stack. On 32-bit this happens in C. |
| 192 | * |
| 193 | * irq_enter/exit_rcu() are invoked before the function body and the |
| 194 | * KVM L1D flush request is set. |
| 195 | */ |
| 196 | #define DEFINE_IDTENTRY_IRQ(func) \ |
| 197 | static __always_inline void __##func(struct pt_regs *regs, u8 vector); \ |
| 198 | \ |
| 199 | __visible noinstr void func(struct pt_regs *regs, \ |
| 200 | unsigned long error_code) \ |
| 201 | { \ |
| 202 | bool rcu_exit = idtentry_enter_cond_rcu(regs); \ |
| 203 | \ |
| 204 | instrumentation_begin(); \ |
| 205 | irq_enter_rcu(); \ |
| 206 | kvm_set_cpu_l1tf_flush_l1d(); \ |
| 207 | __##func (regs, (u8)error_code); \ |
| 208 | irq_exit_rcu(); \ |
Thomas Gleixner | 0bf7c31 | 2020-05-21 22:05:36 +0200 | [diff] [blame] | 209 | instrumentation_end(); \ |
| 210 | idtentry_exit_cond_rcu(regs, rcu_exit); \ |
| 211 | } \ |
| 212 | \ |
| 213 | static __always_inline void __##func(struct pt_regs *regs, u8 vector) |
| 214 | |
| 215 | /** |
Thomas Gleixner | 6368558 | 2020-05-21 22:05:38 +0200 | [diff] [blame] | 216 | * DECLARE_IDTENTRY_SYSVEC - Declare functions for system vector entry points |
| 217 | * @vector: Vector number (ignored for C) |
| 218 | * @func: Function name of the entry point |
| 219 | * |
| 220 | * Declares three functions: |
| 221 | * - The ASM entry point: asm_##func |
| 222 | * - The XEN PV trap entry point: xen_##func (maybe unused) |
| 223 | * - The C handler called from the ASM entry point |
| 224 | * |
| 225 | * Maps to DECLARE_IDTENTRY(). |
| 226 | */ |
| 227 | #define DECLARE_IDTENTRY_SYSVEC(vector, func) \ |
| 228 | DECLARE_IDTENTRY(vector, func) |
| 229 | |
| 230 | /** |
| 231 | * DEFINE_IDTENTRY_SYSVEC - Emit code for system vector IDT entry points |
| 232 | * @func: Function name of the entry point |
| 233 | * |
| 234 | * idtentry_enter/exit() and irq_enter/exit_rcu() are invoked before the |
| 235 | * function body. KVM L1D flush request is set. |
| 236 | * |
| 237 | * Runs the function on the interrupt stack if the entry hit kernel mode |
| 238 | */ |
| 239 | #define DEFINE_IDTENTRY_SYSVEC(func) \ |
| 240 | static void __##func(struct pt_regs *regs); \ |
| 241 | \ |
| 242 | __visible noinstr void func(struct pt_regs *regs) \ |
| 243 | { \ |
| 244 | bool rcu_exit = idtentry_enter_cond_rcu(regs); \ |
| 245 | \ |
| 246 | instrumentation_begin(); \ |
| 247 | irq_enter_rcu(); \ |
| 248 | kvm_set_cpu_l1tf_flush_l1d(); \ |
| 249 | run_on_irqstack_cond(__##func, regs, regs); \ |
| 250 | irq_exit_rcu(); \ |
Thomas Gleixner | 6368558 | 2020-05-21 22:05:38 +0200 | [diff] [blame] | 251 | instrumentation_end(); \ |
| 252 | idtentry_exit_cond_rcu(regs, rcu_exit); \ |
| 253 | } \ |
| 254 | \ |
| 255 | static noinline void __##func(struct pt_regs *regs) |
| 256 | |
| 257 | /** |
| 258 | * DEFINE_IDTENTRY_SYSVEC_SIMPLE - Emit code for simple system vector IDT |
| 259 | * entry points |
| 260 | * @func: Function name of the entry point |
| 261 | * |
| 262 | * Runs the function on the interrupted stack. No switch to IRQ stack and |
| 263 | * only the minimal __irq_enter/exit() handling. |
| 264 | * |
| 265 | * Only use for 'empty' vectors like reschedule IPI and KVM posted |
| 266 | * interrupt vectors. |
| 267 | */ |
| 268 | #define DEFINE_IDTENTRY_SYSVEC_SIMPLE(func) \ |
| 269 | static __always_inline void __##func(struct pt_regs *regs); \ |
| 270 | \ |
| 271 | __visible noinstr void func(struct pt_regs *regs) \ |
| 272 | { \ |
| 273 | bool rcu_exit = idtentry_enter_cond_rcu(regs); \ |
| 274 | \ |
| 275 | instrumentation_begin(); \ |
| 276 | __irq_enter_raw(); \ |
| 277 | kvm_set_cpu_l1tf_flush_l1d(); \ |
| 278 | __##func (regs); \ |
| 279 | __irq_exit_raw(); \ |
| 280 | instrumentation_end(); \ |
| 281 | idtentry_exit_cond_rcu(regs, rcu_exit); \ |
| 282 | } \ |
| 283 | \ |
| 284 | static __always_inline void __##func(struct pt_regs *regs) |
| 285 | |
| 286 | /** |
Thomas Gleixner | 2f6474e | 2020-05-21 22:05:26 +0200 | [diff] [blame] | 287 | * DECLARE_IDTENTRY_XENCB - Declare functions for XEN HV callback entry point |
| 288 | * @vector: Vector number (ignored for C) |
| 289 | * @func: Function name of the entry point |
| 290 | * |
| 291 | * Declares three functions: |
| 292 | * - The ASM entry point: asm_##func |
| 293 | * - The XEN PV trap entry point: xen_##func (maybe unused) |
| 294 | * - The C handler called from the ASM entry point |
| 295 | * |
| 296 | * Maps to DECLARE_IDTENTRY(). Distinct entry point to handle the 32/64-bit |
| 297 | * difference |
| 298 | */ |
| 299 | #define DECLARE_IDTENTRY_XENCB(vector, func) \ |
| 300 | DECLARE_IDTENTRY(vector, func) |
Thomas Gleixner | 6a8dfa8 | 2020-02-25 23:33:30 +0100 | [diff] [blame] | 301 | |
Thomas Gleixner | 2c058b0 | 2020-02-25 23:33:22 +0100 | [diff] [blame] | 302 | #ifdef CONFIG_X86_64 |
| 303 | /** |
| 304 | * DECLARE_IDTENTRY_IST - Declare functions for IST handling IDT entry points |
| 305 | * @vector: Vector number (ignored for C) |
| 306 | * @func: Function name of the entry point |
| 307 | * |
Thomas Gleixner | f08e32e | 2020-02-25 23:33:28 +0100 | [diff] [blame] | 308 | * Maps to DECLARE_IDTENTRY_RAW, but declares also the NOIST C handler |
| 309 | * which is called from the ASM entry point on user mode entry |
Thomas Gleixner | 2c058b0 | 2020-02-25 23:33:22 +0100 | [diff] [blame] | 310 | */ |
| 311 | #define DECLARE_IDTENTRY_IST(vector, func) \ |
Thomas Gleixner | f08e32e | 2020-02-25 23:33:28 +0100 | [diff] [blame] | 312 | DECLARE_IDTENTRY_RAW(vector, func); \ |
| 313 | __visible void noist_##func(struct pt_regs *regs) |
Thomas Gleixner | 2c058b0 | 2020-02-25 23:33:22 +0100 | [diff] [blame] | 314 | |
| 315 | /** |
| 316 | * DEFINE_IDTENTRY_IST - Emit code for IST entry points |
| 317 | * @func: Function name of the entry point |
| 318 | * |
| 319 | * Maps to DEFINE_IDTENTRY_RAW |
| 320 | */ |
| 321 | #define DEFINE_IDTENTRY_IST(func) \ |
| 322 | DEFINE_IDTENTRY_RAW(func) |
| 323 | |
Thomas Gleixner | f08e32e | 2020-02-25 23:33:28 +0100 | [diff] [blame] | 324 | /** |
| 325 | * DEFINE_IDTENTRY_NOIST - Emit code for NOIST entry points which |
| 326 | * belong to a IST entry point (MCE, DB) |
| 327 | * @func: Function name of the entry point. Must be the same as |
| 328 | * the function name of the corresponding IST variant |
| 329 | * |
| 330 | * Maps to DEFINE_IDTENTRY_RAW(). |
| 331 | */ |
| 332 | #define DEFINE_IDTENTRY_NOIST(func) \ |
| 333 | DEFINE_IDTENTRY_RAW(noist_##func) |
| 334 | |
Thomas Gleixner | 6a8dfa8 | 2020-02-25 23:33:30 +0100 | [diff] [blame] | 335 | /** |
| 336 | * DECLARE_IDTENTRY_DF - Declare functions for double fault |
| 337 | * @vector: Vector number (ignored for C) |
| 338 | * @func: Function name of the entry point |
| 339 | * |
| 340 | * Maps to DECLARE_IDTENTRY_RAW_ERRORCODE |
| 341 | */ |
| 342 | #define DECLARE_IDTENTRY_DF(vector, func) \ |
| 343 | DECLARE_IDTENTRY_RAW_ERRORCODE(vector, func) |
| 344 | |
| 345 | /** |
| 346 | * DEFINE_IDTENTRY_DF - Emit code for double fault |
| 347 | * @func: Function name of the entry point |
| 348 | * |
| 349 | * Maps to DEFINE_IDTENTRY_RAW_ERRORCODE |
| 350 | */ |
| 351 | #define DEFINE_IDTENTRY_DF(func) \ |
| 352 | DEFINE_IDTENTRY_RAW_ERRORCODE(func) |
| 353 | |
Thomas Gleixner | 2c058b0 | 2020-02-25 23:33:22 +0100 | [diff] [blame] | 354 | #else /* CONFIG_X86_64 */ |
Thomas Gleixner | 6a8dfa8 | 2020-02-25 23:33:30 +0100 | [diff] [blame] | 355 | |
Thomas Gleixner | 2c058b0 | 2020-02-25 23:33:22 +0100 | [diff] [blame] | 356 | /* Maps to a regular IDTENTRY on 32bit for now */ |
| 357 | # define DECLARE_IDTENTRY_IST DECLARE_IDTENTRY |
| 358 | # define DEFINE_IDTENTRY_IST DEFINE_IDTENTRY |
Thomas Gleixner | 6a8dfa8 | 2020-02-25 23:33:30 +0100 | [diff] [blame] | 359 | |
| 360 | /** |
| 361 | * DECLARE_IDTENTRY_DF - Declare functions for double fault 32bit variant |
| 362 | * @vector: Vector number (ignored for C) |
| 363 | * @func: Function name of the entry point |
| 364 | * |
| 365 | * Declares two functions: |
| 366 | * - The ASM entry point: asm_##func |
| 367 | * - The C handler called from the C shim |
| 368 | */ |
| 369 | #define DECLARE_IDTENTRY_DF(vector, func) \ |
| 370 | asmlinkage void asm_##func(void); \ |
| 371 | __visible void func(struct pt_regs *regs, \ |
| 372 | unsigned long error_code, \ |
| 373 | unsigned long address) |
| 374 | |
| 375 | /** |
| 376 | * DEFINE_IDTENTRY_DF - Emit code for double fault on 32bit |
| 377 | * @func: Function name of the entry point |
| 378 | * |
| 379 | * This is called through the doublefault shim which already provides |
| 380 | * cr2 in the address argument. |
| 381 | */ |
| 382 | #define DEFINE_IDTENTRY_DF(func) \ |
| 383 | __visible noinstr void func(struct pt_regs *regs, \ |
| 384 | unsigned long error_code, \ |
| 385 | unsigned long address) |
| 386 | |
Thomas Gleixner | 2c058b0 | 2020-02-25 23:33:22 +0100 | [diff] [blame] | 387 | #endif /* !CONFIG_X86_64 */ |
| 388 | |
| 389 | /* C-Code mapping */ |
| 390 | #define DECLARE_IDTENTRY_MCE DECLARE_IDTENTRY_IST |
| 391 | #define DEFINE_IDTENTRY_MCE DEFINE_IDTENTRY_IST |
Thomas Gleixner | f08e32e | 2020-02-25 23:33:28 +0100 | [diff] [blame] | 392 | #define DEFINE_IDTENTRY_MCE_USER DEFINE_IDTENTRY_NOIST |
Thomas Gleixner | 2c058b0 | 2020-02-25 23:33:22 +0100 | [diff] [blame] | 393 | |
Thomas Gleixner | 71ed49d8 | 2020-06-12 14:02:27 +0200 | [diff] [blame] | 394 | #define DECLARE_IDTENTRY_NMI DECLARE_IDTENTRY_RAW |
| 395 | #define DEFINE_IDTENTRY_NMI DEFINE_IDTENTRY_RAW |
Thomas Gleixner | 2c058b0 | 2020-02-25 23:33:22 +0100 | [diff] [blame] | 396 | |
| 397 | #define DECLARE_IDTENTRY_DEBUG DECLARE_IDTENTRY_IST |
| 398 | #define DEFINE_IDTENTRY_DEBUG DEFINE_IDTENTRY_IST |
Thomas Gleixner | f08e32e | 2020-02-25 23:33:28 +0100 | [diff] [blame] | 399 | #define DEFINE_IDTENTRY_DEBUG_USER DEFINE_IDTENTRY_NOIST |
Thomas Gleixner | 2c058b0 | 2020-02-25 23:33:22 +0100 | [diff] [blame] | 400 | |
Thomas Gleixner | 53aaf26 | 2020-02-25 23:16:12 +0100 | [diff] [blame] | 401 | #else /* !__ASSEMBLY__ */ |
| 402 | |
| 403 | /* |
| 404 | * The ASM variants for DECLARE_IDTENTRY*() which emit the ASM entry stubs. |
| 405 | */ |
| 406 | #define DECLARE_IDTENTRY(vector, func) \ |
Thomas Gleixner | e2dcb5f | 2020-05-21 22:05:29 +0200 | [diff] [blame] | 407 | idtentry vector asm_##func func has_error_code=0 |
Thomas Gleixner | 53aaf26 | 2020-02-25 23:16:12 +0100 | [diff] [blame] | 408 | |
Thomas Gleixner | aabfe53 | 2020-02-25 23:16:21 +0100 | [diff] [blame] | 409 | #define DECLARE_IDTENTRY_ERRORCODE(vector, func) \ |
Thomas Gleixner | e2dcb5f | 2020-05-21 22:05:29 +0200 | [diff] [blame] | 410 | idtentry vector asm_##func func has_error_code=1 |
Thomas Gleixner | aabfe53 | 2020-02-25 23:16:21 +0100 | [diff] [blame] | 411 | |
Thomas Gleixner | d772905 | 2020-02-25 23:16:30 +0100 | [diff] [blame] | 412 | /* Special case for 32bit IRET 'trap'. Do not emit ASM code */ |
| 413 | #define DECLARE_IDTENTRY_SW(vector, func) |
| 414 | |
Thomas Gleixner | 0dc6cdc | 2020-03-04 15:22:09 +0100 | [diff] [blame] | 415 | #define DECLARE_IDTENTRY_RAW(vector, func) \ |
| 416 | DECLARE_IDTENTRY(vector, func) |
| 417 | |
Thomas Gleixner | 6a8dfa8 | 2020-02-25 23:33:30 +0100 | [diff] [blame] | 418 | #define DECLARE_IDTENTRY_RAW_ERRORCODE(vector, func) \ |
| 419 | DECLARE_IDTENTRY_ERRORCODE(vector, func) |
| 420 | |
Thomas Gleixner | 0bf7c31 | 2020-05-21 22:05:36 +0200 | [diff] [blame] | 421 | /* Entries for common/spurious (device) interrupts */ |
| 422 | #define DECLARE_IDTENTRY_IRQ(vector, func) \ |
| 423 | idtentry_irq vector func |
| 424 | |
Thomas Gleixner | 6368558 | 2020-05-21 22:05:38 +0200 | [diff] [blame] | 425 | /* System vector entries */ |
| 426 | #define DECLARE_IDTENTRY_SYSVEC(vector, func) \ |
| 427 | idtentry_sysvec vector func |
| 428 | |
Thomas Gleixner | 2c058b0 | 2020-02-25 23:33:22 +0100 | [diff] [blame] | 429 | #ifdef CONFIG_X86_64 |
| 430 | # define DECLARE_IDTENTRY_MCE(vector, func) \ |
| 431 | idtentry_mce_db vector asm_##func func |
| 432 | |
| 433 | # define DECLARE_IDTENTRY_DEBUG(vector, func) \ |
| 434 | idtentry_mce_db vector asm_##func func |
| 435 | |
Thomas Gleixner | 6a8dfa8 | 2020-02-25 23:33:30 +0100 | [diff] [blame] | 436 | # define DECLARE_IDTENTRY_DF(vector, func) \ |
| 437 | idtentry_df vector asm_##func func |
| 438 | |
Thomas Gleixner | 2f6474e | 2020-05-21 22:05:26 +0200 | [diff] [blame] | 439 | # define DECLARE_IDTENTRY_XENCB(vector, func) \ |
| 440 | DECLARE_IDTENTRY(vector, func) |
| 441 | |
Thomas Gleixner | 2c058b0 | 2020-02-25 23:33:22 +0100 | [diff] [blame] | 442 | #else |
| 443 | # define DECLARE_IDTENTRY_MCE(vector, func) \ |
| 444 | DECLARE_IDTENTRY(vector, func) |
| 445 | |
| 446 | # define DECLARE_IDTENTRY_DEBUG(vector, func) \ |
| 447 | DECLARE_IDTENTRY(vector, func) |
Thomas Gleixner | 6a8dfa8 | 2020-02-25 23:33:30 +0100 | [diff] [blame] | 448 | |
| 449 | /* No ASM emitted for DF as this goes through a C shim */ |
| 450 | # define DECLARE_IDTENTRY_DF(vector, func) |
| 451 | |
Thomas Gleixner | 2f6474e | 2020-05-21 22:05:26 +0200 | [diff] [blame] | 452 | /* No ASM emitted for XEN hypervisor callback */ |
| 453 | # define DECLARE_IDTENTRY_XENCB(vector, func) |
| 454 | |
Thomas Gleixner | 2c058b0 | 2020-02-25 23:33:22 +0100 | [diff] [blame] | 455 | #endif |
| 456 | |
| 457 | /* No ASM code emitted for NMI */ |
| 458 | #define DECLARE_IDTENTRY_NMI(vector, func) |
| 459 | |
Thomas Gleixner | 633260f | 2020-05-21 22:05:34 +0200 | [diff] [blame] | 460 | /* |
| 461 | * ASM code to emit the common vector entry stubs where each stub is |
| 462 | * packed into 8 bytes. |
| 463 | * |
| 464 | * Note, that the 'pushq imm8' is emitted via '.byte 0x6a, vector' because |
| 465 | * GCC treats the local vector variable as unsigned int and would expand |
| 466 | * all vectors above 0x7F to a 5 byte push. The original code did an |
| 467 | * adjustment of the vector number to be in the signed byte range to avoid |
| 468 | * this. While clever it's mindboggling counterintuitive and requires the |
| 469 | * odd conversion back to a real vector number in the C entry points. Using |
| 470 | * .byte achieves the same thing and the only fixup needed in the C entry |
| 471 | * point is to mask off the bits above bit 7 because the push is sign |
| 472 | * extending. |
| 473 | */ |
| 474 | .align 8 |
| 475 | SYM_CODE_START(irq_entries_start) |
| 476 | vector=FIRST_EXTERNAL_VECTOR |
| 477 | pos = . |
| 478 | .rept (FIRST_SYSTEM_VECTOR - FIRST_EXTERNAL_VECTOR) |
| 479 | UNWIND_HINT_IRET_REGS |
| 480 | .byte 0x6a, vector |
Thomas Gleixner | fa5e5c4 | 2020-05-21 22:05:37 +0200 | [diff] [blame] | 481 | jmp asm_common_interrupt |
Thomas Gleixner | 633260f | 2020-05-21 22:05:34 +0200 | [diff] [blame] | 482 | nop |
| 483 | /* Ensure that the above is 8 bytes max */ |
| 484 | . = pos + 8 |
| 485 | pos=pos+8 |
| 486 | vector=vector+1 |
| 487 | .endr |
| 488 | SYM_CODE_END(irq_entries_start) |
| 489 | |
| 490 | #ifdef CONFIG_X86_LOCAL_APIC |
| 491 | .align 8 |
| 492 | SYM_CODE_START(spurious_entries_start) |
| 493 | vector=FIRST_SYSTEM_VECTOR |
| 494 | pos = . |
| 495 | .rept (NR_VECTORS - FIRST_SYSTEM_VECTOR) |
| 496 | UNWIND_HINT_IRET_REGS |
| 497 | .byte 0x6a, vector |
Thomas Gleixner | fa5e5c4 | 2020-05-21 22:05:37 +0200 | [diff] [blame] | 498 | jmp asm_spurious_interrupt |
Thomas Gleixner | 633260f | 2020-05-21 22:05:34 +0200 | [diff] [blame] | 499 | nop |
| 500 | /* Ensure that the above is 8 bytes max */ |
| 501 | . = pos + 8 |
| 502 | pos=pos+8 |
| 503 | vector=vector+1 |
| 504 | .endr |
| 505 | SYM_CODE_END(spurious_entries_start) |
| 506 | #endif |
| 507 | |
Thomas Gleixner | 53aaf26 | 2020-02-25 23:16:12 +0100 | [diff] [blame] | 508 | #endif /* __ASSEMBLY__ */ |
| 509 | |
Thomas Gleixner | 9d06c40 | 2020-02-25 23:16:14 +0100 | [diff] [blame] | 510 | /* |
| 511 | * The actual entry points. Note that DECLARE_IDTENTRY*() serves two |
| 512 | * purposes: |
| 513 | * - provide the function declarations when included from C-Code |
| 514 | * - emit the ASM stubs when included from entry_32/64.S |
| 515 | * |
| 516 | * This avoids duplicate defines and ensures that everything is consistent. |
| 517 | */ |
| 518 | |
Thomas Gleixner | 2f6474e | 2020-05-21 22:05:26 +0200 | [diff] [blame] | 519 | /* |
| 520 | * Dummy trap number so the low level ASM macro vector number checks do not |
| 521 | * match which results in emitting plain IDTENTRY stubs without bells and |
| 522 | * whistels. |
| 523 | */ |
| 524 | #define X86_TRAP_OTHER 0xFFFF |
| 525 | |
Thomas Gleixner | 9d06c40 | 2020-02-25 23:16:14 +0100 | [diff] [blame] | 526 | /* Simple exception entry points. No hardware error code */ |
| 527 | DECLARE_IDTENTRY(X86_TRAP_DE, exc_divide_error); |
Thomas Gleixner | 4b6b911 | 2020-02-25 23:16:15 +0100 | [diff] [blame] | 528 | DECLARE_IDTENTRY(X86_TRAP_OF, exc_overflow); |
Thomas Gleixner | 58d9c81 | 2020-02-25 23:16:17 +0100 | [diff] [blame] | 529 | DECLARE_IDTENTRY(X86_TRAP_BR, exc_bounds); |
Thomas Gleixner | 866ae2c | 2020-02-25 23:16:19 +0100 | [diff] [blame] | 530 | DECLARE_IDTENTRY(X86_TRAP_NM, exc_device_not_available); |
Thomas Gleixner | f95658f | 2020-02-25 23:16:20 +0100 | [diff] [blame] | 531 | DECLARE_IDTENTRY(X86_TRAP_OLD_MF, exc_coproc_segment_overrun); |
Thomas Gleixner | dad7106 | 2020-02-25 23:16:26 +0100 | [diff] [blame] | 532 | DECLARE_IDTENTRY(X86_TRAP_SPURIOUS, exc_spurious_interrupt_bug); |
Thomas Gleixner | 14a8bd2 | 2020-02-25 23:16:27 +0100 | [diff] [blame] | 533 | DECLARE_IDTENTRY(X86_TRAP_MF, exc_coprocessor_error); |
Thomas Gleixner | 48227e2 | 2020-02-25 23:16:29 +0100 | [diff] [blame] | 534 | DECLARE_IDTENTRY(X86_TRAP_XF, exc_simd_coprocessor_error); |
Thomas Gleixner | 9d06c40 | 2020-02-25 23:16:14 +0100 | [diff] [blame] | 535 | |
Thomas Gleixner | d772905 | 2020-02-25 23:16:30 +0100 | [diff] [blame] | 536 | /* 32bit software IRET trap. Do not emit ASM code */ |
| 537 | DECLARE_IDTENTRY_SW(X86_TRAP_IRET, iret_error); |
| 538 | |
Thomas Gleixner | 97b3d29 | 2020-02-25 23:16:22 +0100 | [diff] [blame] | 539 | /* Simple exception entries with error code pushed by hardware */ |
| 540 | DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_TS, exc_invalid_tss); |
Thomas Gleixner | 99a3fb8 | 2020-02-25 23:16:23 +0100 | [diff] [blame] | 541 | DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_NP, exc_segment_not_present); |
Thomas Gleixner | fd9689b | 2020-02-25 23:16:24 +0100 | [diff] [blame] | 542 | DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_SS, exc_stack_segment); |
Thomas Gleixner | be4c11a | 2020-02-25 23:16:25 +0100 | [diff] [blame] | 543 | DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_GP, exc_general_protection); |
Thomas Gleixner | 436608b | 2020-02-25 23:16:28 +0100 | [diff] [blame] | 544 | DECLARE_IDTENTRY_ERRORCODE(X86_TRAP_AC, exc_alignment_check); |
Thomas Gleixner | 97b3d29 | 2020-02-25 23:16:22 +0100 | [diff] [blame] | 545 | |
Thomas Gleixner | 8edd7e3 | 2020-02-25 23:16:16 +0100 | [diff] [blame] | 546 | /* Raw exception entries which need extra work */ |
Andy Lutomirski | 15a416e | 2020-06-11 20:26:38 -0700 | [diff] [blame] | 547 | DECLARE_IDTENTRY_RAW(X86_TRAP_UD, exc_invalid_op); |
Thomas Gleixner | 91eeafe | 2020-05-21 22:05:28 +0200 | [diff] [blame] | 548 | DECLARE_IDTENTRY_RAW(X86_TRAP_BP, exc_int3); |
| 549 | DECLARE_IDTENTRY_RAW_ERRORCODE(X86_TRAP_PF, exc_page_fault); |
Thomas Gleixner | 8edd7e3 | 2020-02-25 23:16:16 +0100 | [diff] [blame] | 550 | |
Thomas Gleixner | 8cd501c | 2020-02-25 23:33:23 +0100 | [diff] [blame] | 551 | #ifdef CONFIG_X86_MCE |
| 552 | DECLARE_IDTENTRY_MCE(X86_TRAP_MC, exc_machine_check); |
| 553 | #endif |
| 554 | |
Thomas Gleixner | 6271fef | 2020-02-25 23:33:25 +0100 | [diff] [blame] | 555 | /* NMI */ |
| 556 | DECLARE_IDTENTRY_NMI(X86_TRAP_NMI, exc_nmi); |
Andy Lutomirski | f41f082 | 2020-07-03 10:02:55 -0700 | [diff] [blame^] | 557 | #ifdef CONFIG_XEN_PV |
| 558 | DECLARE_IDTENTRY_RAW(X86_TRAP_NMI, xenpv_exc_nmi); |
| 559 | #endif |
Thomas Gleixner | 6271fef | 2020-02-25 23:33:25 +0100 | [diff] [blame] | 560 | |
Thomas Gleixner | 2bbc68f | 2020-02-25 23:33:26 +0100 | [diff] [blame] | 561 | /* #DB */ |
| 562 | DECLARE_IDTENTRY_DEBUG(X86_TRAP_DB, exc_debug); |
Andy Lutomirski | f41f082 | 2020-07-03 10:02:55 -0700 | [diff] [blame^] | 563 | #ifdef CONFIG_XEN_PV |
| 564 | DECLARE_IDTENTRY_RAW(X86_TRAP_DB, xenpv_exc_debug); |
| 565 | #endif |
Thomas Gleixner | 2bbc68f | 2020-02-25 23:33:26 +0100 | [diff] [blame] | 566 | |
Thomas Gleixner | c29c775 | 2020-02-25 23:33:31 +0100 | [diff] [blame] | 567 | /* #DF */ |
| 568 | DECLARE_IDTENTRY_DF(X86_TRAP_DF, exc_double_fault); |
| 569 | |
Thomas Gleixner | 2f6474e | 2020-05-21 22:05:26 +0200 | [diff] [blame] | 570 | #ifdef CONFIG_XEN_PV |
| 571 | DECLARE_IDTENTRY_XENCB(X86_TRAP_OTHER, exc_xen_hypervisor_callback); |
| 572 | #endif |
| 573 | |
Thomas Gleixner | fa5e5c4 | 2020-05-21 22:05:37 +0200 | [diff] [blame] | 574 | /* Device interrupts common/spurious */ |
| 575 | DECLARE_IDTENTRY_IRQ(X86_TRAP_OTHER, common_interrupt); |
| 576 | #ifdef CONFIG_X86_LOCAL_APIC |
| 577 | DECLARE_IDTENTRY_IRQ(X86_TRAP_OTHER, spurious_interrupt); |
| 578 | #endif |
| 579 | |
Thomas Gleixner | db0338e | 2020-05-21 22:05:39 +0200 | [diff] [blame] | 580 | /* System vector entry points */ |
| 581 | #ifdef CONFIG_X86_LOCAL_APIC |
| 582 | DECLARE_IDTENTRY_SYSVEC(ERROR_APIC_VECTOR, sysvec_error_interrupt); |
| 583 | DECLARE_IDTENTRY_SYSVEC(SPURIOUS_APIC_VECTOR, sysvec_spurious_apic_interrupt); |
| 584 | DECLARE_IDTENTRY_SYSVEC(LOCAL_TIMER_VECTOR, sysvec_apic_timer_interrupt); |
| 585 | DECLARE_IDTENTRY_SYSVEC(X86_PLATFORM_IPI_VECTOR, sysvec_x86_platform_ipi); |
| 586 | #endif |
| 587 | |
Thomas Gleixner | 582f919 | 2020-05-21 22:05:40 +0200 | [diff] [blame] | 588 | #ifdef CONFIG_SMP |
Thomas Gleixner | 13cad985 | 2020-05-21 22:05:45 +0200 | [diff] [blame] | 589 | DECLARE_IDTENTRY(RESCHEDULE_VECTOR, sysvec_reschedule_ipi); |
Thomas Gleixner | 582f919 | 2020-05-21 22:05:40 +0200 | [diff] [blame] | 590 | DECLARE_IDTENTRY_SYSVEC(IRQ_MOVE_CLEANUP_VECTOR, sysvec_irq_move_cleanup); |
| 591 | DECLARE_IDTENTRY_SYSVEC(REBOOT_VECTOR, sysvec_reboot); |
| 592 | DECLARE_IDTENTRY_SYSVEC(CALL_FUNCTION_SINGLE_VECTOR, sysvec_call_function_single); |
| 593 | DECLARE_IDTENTRY_SYSVEC(CALL_FUNCTION_VECTOR, sysvec_call_function); |
| 594 | #endif |
| 595 | |
Thomas Gleixner | 720909a | 2020-05-21 22:05:41 +0200 | [diff] [blame] | 596 | #ifdef CONFIG_X86_LOCAL_APIC |
| 597 | # ifdef CONFIG_X86_UV |
| 598 | DECLARE_IDTENTRY_SYSVEC(UV_BAU_MESSAGE, sysvec_uv_bau_message); |
| 599 | # endif |
| 600 | |
| 601 | # ifdef CONFIG_X86_MCE_THRESHOLD |
| 602 | DECLARE_IDTENTRY_SYSVEC(THRESHOLD_APIC_VECTOR, sysvec_threshold); |
| 603 | # endif |
| 604 | |
| 605 | # ifdef CONFIG_X86_MCE_AMD |
| 606 | DECLARE_IDTENTRY_SYSVEC(DEFERRED_ERROR_VECTOR, sysvec_deferred_error); |
| 607 | # endif |
| 608 | |
| 609 | # ifdef CONFIG_X86_THERMAL_VECTOR |
| 610 | DECLARE_IDTENTRY_SYSVEC(THERMAL_APIC_VECTOR, sysvec_thermal); |
| 611 | # endif |
| 612 | |
| 613 | # ifdef CONFIG_IRQ_WORK |
| 614 | DECLARE_IDTENTRY_SYSVEC(IRQ_WORK_VECTOR, sysvec_irq_work); |
| 615 | # endif |
| 616 | #endif |
| 617 | |
Thomas Gleixner | 9c3b1f4 | 2020-05-21 22:05:42 +0200 | [diff] [blame] | 618 | #ifdef CONFIG_HAVE_KVM |
| 619 | DECLARE_IDTENTRY_SYSVEC(POSTED_INTR_VECTOR, sysvec_kvm_posted_intr_ipi); |
| 620 | DECLARE_IDTENTRY_SYSVEC(POSTED_INTR_WAKEUP_VECTOR, sysvec_kvm_posted_intr_wakeup_ipi); |
| 621 | DECLARE_IDTENTRY_SYSVEC(POSTED_INTR_NESTED_VECTOR, sysvec_kvm_posted_intr_nested_ipi); |
| 622 | #endif |
| 623 | |
Thomas Gleixner | a16be36 | 2020-05-21 22:05:43 +0200 | [diff] [blame] | 624 | #if IS_ENABLED(CONFIG_HYPERV) |
| 625 | DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_CALLBACK_VECTOR, sysvec_hyperv_callback); |
| 626 | DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_REENLIGHTENMENT_VECTOR, sysvec_hyperv_reenlightenment); |
| 627 | DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_STIMER0_VECTOR, sysvec_hyperv_stimer0); |
| 628 | #endif |
| 629 | |
| 630 | #if IS_ENABLED(CONFIG_ACRN_GUEST) |
| 631 | DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_CALLBACK_VECTOR, sysvec_acrn_hv_callback); |
| 632 | #endif |
| 633 | |
Thomas Gleixner | cb09ea2 | 2020-05-21 22:05:44 +0200 | [diff] [blame] | 634 | #ifdef CONFIG_XEN_PVHVM |
| 635 | DECLARE_IDTENTRY_SYSVEC(HYPERVISOR_CALLBACK_VECTOR, sysvec_xen_hvm_callback); |
| 636 | #endif |
| 637 | |
Thomas Gleixner | 2f6474e | 2020-05-21 22:05:26 +0200 | [diff] [blame] | 638 | #undef X86_TRAP_OTHER |
| 639 | |
Thomas Gleixner | 53aaf26 | 2020-02-25 23:16:12 +0100 | [diff] [blame] | 640 | #endif |