blob: 2ace1f90d1383049f20563b7dfe74e60cadff9ac [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
H. Peter Anvin1965aae2008-10-22 22:26:29 -07002#ifndef _ASM_X86_DESC_H
3#define _ASM_X86_DESC_H
Glauber de Oliveira Costa80fbb692008-01-30 13:31:13 +01004
Glauber de Oliveira Costa80fbb692008-01-30 13:31:13 +01005#include <asm/desc_defs.h>
6#include <asm/ldt.h>
Glauber de Oliveira Costa881c2972008-01-30 13:31:14 +01007#include <asm/mmu.h>
Thomas Garnier69218e42017-03-14 10:05:07 -07008#include <asm/fixmap.h>
Thomas Gleixner05161b92017-08-28 08:47:18 +02009#include <asm/irq_vectors.h>
Ingo Molnar9a3865b2011-05-27 09:29:32 +020010
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +010011#include <linux/smp.h>
Alex Shic6ae41e2012-05-11 15:35:27 +080012#include <linux/percpu.h>
Glauber de Oliveira Costa80fbb692008-01-30 13:31:13 +010013
Ingo Molnar9a3865b2011-05-27 09:29:32 +020014static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *info)
Glauber de Oliveira Costa80fbb692008-01-30 13:31:13 +010015{
Ingo Molnar9a3865b2011-05-27 09:29:32 +020016 desc->limit0 = info->limit & 0x0ffff;
Glauber de Oliveira Costa80fbb692008-01-30 13:31:13 +010017
Ingo Molnar9a3865b2011-05-27 09:29:32 +020018 desc->base0 = (info->base_addr & 0x0000ffff);
19 desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
20
21 desc->type = (info->read_exec_only ^ 1) << 1;
22 desc->type |= info->contents << 2;
23
24 desc->s = 1;
25 desc->dpl = 0x3;
26 desc->p = info->seg_not_present ^ 1;
Thomas Gleixner38e9e812017-08-28 08:47:41 +020027 desc->limit1 = (info->limit & 0xf0000) >> 16;
Ingo Molnar9a3865b2011-05-27 09:29:32 +020028 desc->avl = info->useable;
29 desc->d = info->seg_32bit;
30 desc->g = info->limit_in_pages;
31
32 desc->base2 = (info->base_addr & 0xff000000) >> 24;
Jeremy Fitzhardinge64f53a02008-07-27 08:42:32 -070033 /*
Andy Lutomirski318f5a22011-08-03 09:31:53 -040034 * Don't allow setting of the lm bit. It would confuse
35 * user_64bit_mode and would get overridden by sysret anyway.
Jeremy Fitzhardinge64f53a02008-07-27 08:42:32 -070036 */
Ingo Molnar9a3865b2011-05-27 09:29:32 +020037 desc->l = 0;
Glauber de Oliveira Costa80fbb692008-01-30 13:31:13 +010038}
39
Glauber de Oliveira Costa881c2972008-01-30 13:31:14 +010040extern struct desc_ptr idt_descr;
41extern gate_desc idt_table[];
Kees Cook404f6aa2016-08-08 16:29:06 -070042extern const struct desc_ptr debug_idt_descr;
Seiji Aguchi629f4f92013-06-20 11:45:44 -040043extern gate_desc debug_idt_table[];
Glauber de Oliveira Costa80fbb692008-01-30 13:31:13 +010044
Glauber Costaa9390982008-05-28 16:19:53 -070045struct gdt_page {
46 struct desc_struct gdt[GDT_ENTRIES];
47} __attribute__((aligned(PAGE_SIZE)));
Ingo Molnar9a3865b2011-05-27 09:29:32 +020048
David Howells9b8de742009-04-21 23:00:24 +010049DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
Glauber Costaa9390982008-05-28 16:19:53 -070050
Thomas Garnier69218e42017-03-14 10:05:07 -070051/* Provide the original GDT */
52static inline struct desc_struct *get_cpu_gdt_rw(unsigned int cpu)
Glauber Costaa9390982008-05-28 16:19:53 -070053{
54 return per_cpu(gdt_page, cpu).gdt;
55}
56
Thomas Garnier69218e42017-03-14 10:05:07 -070057/* Provide the current original GDT */
58static inline struct desc_struct *get_current_gdt_rw(void)
59{
60 return this_cpu_ptr(&gdt_page)->gdt;
61}
62
Thomas Garnier69218e42017-03-14 10:05:07 -070063/* Provide the fixmap address of the remapped GDT */
64static inline struct desc_struct *get_cpu_gdt_ro(int cpu)
65{
Andy Lutomirskief8813a2017-12-04 15:07:15 +010066 return (struct desc_struct *)&get_cpu_entry_area(cpu)->gdt;
Thomas Garnier69218e42017-03-14 10:05:07 -070067}
68
Thomas Garnier69218e42017-03-14 10:05:07 -070069/* Provide the current read-only GDT */
70static inline struct desc_struct *get_current_gdt_ro(void)
71{
72 return get_cpu_gdt_ro(smp_processor_id());
73}
74
Andy Lutomirskiaa4ea67552017-03-22 14:32:30 -070075/* Provide the physical address of the GDT page. */
76static inline phys_addr_t get_cpu_gdt_paddr(unsigned int cpu)
77{
78 return per_cpu_ptr_to_phys(get_cpu_gdt_rw(cpu));
79}
80
Glauber de Oliveira Costa507f90c2008-01-30 13:31:14 +010081static inline void pack_gate(gate_desc *gate, unsigned type, unsigned long func,
82 unsigned dpl, unsigned ist, unsigned seg)
83{
Thomas Gleixner64b163f2017-08-28 08:47:37 +020084 gate->offset_low = (u16) func;
85 gate->bits.p = 1;
86 gate->bits.dpl = dpl;
87 gate->bits.zero = 0;
88 gate->bits.type = type;
89 gate->offset_middle = (u16) (func >> 16);
90#ifdef CONFIG_X86_64
Ingo Molnar9a3865b2011-05-27 09:29:32 +020091 gate->segment = __KERNEL_CS;
Thomas Gleixner64b163f2017-08-28 08:47:37 +020092 gate->bits.ist = ist;
93 gate->reserved = 0;
94 gate->offset_high = (u32) (func >> 32);
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +010095#else
Thomas Gleixner64b163f2017-08-28 08:47:37 +020096 gate->segment = seg;
97 gate->bits.ist = 0;
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +010098#endif
Thomas Gleixner64b163f2017-08-28 08:47:37 +020099}
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100100
Glauber de Oliveira Costa746ff602008-01-30 13:31:27 +0100101static inline int desc_empty(const void *ptr)
102{
103 const u32 *desc = ptr;
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200104
Glauber de Oliveira Costa746ff602008-01-30 13:31:27 +0100105 return !(desc[0] | desc[1]);
106}
107
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100108#ifdef CONFIG_PARAVIRT
109#include <asm/paravirt.h>
110#else
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200111#define load_TR_desc() native_load_tr_desc()
112#define load_gdt(dtr) native_load_gdt(dtr)
113#define load_idt(dtr) native_load_idt(dtr)
114#define load_tr(tr) asm volatile("ltr %0"::"m" (tr))
115#define load_ldt(ldt) asm volatile("lldt %0"::"m" (ldt))
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100116
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200117#define store_gdt(dtr) native_store_gdt(dtr)
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200118#define store_tr(tr) (tr = native_store_tr())
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100119
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200120#define load_TLS(t, cpu) native_load_tls(t, cpu)
121#define set_ldt native_set_ldt
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100122
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200123#define write_ldt_entry(dt, entry, desc) native_write_ldt_entry(dt, entry, desc)
124#define write_gdt_entry(dt, entry, desc, type) native_write_gdt_entry(dt, entry, desc, type)
125#define write_idt_entry(dt, entry, g) native_write_idt_entry(dt, entry, g)
Jeremy Fitzhardinge38ffbe62008-07-23 14:21:18 -0700126
127static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned entries)
128{
129}
130
131static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
132{
133}
134#endif /* CONFIG_PARAVIRT */
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100135
Jaswinder Singh Rajput8229d752009-03-11 19:13:49 +0530136#define store_ldt(ldt) asm("sldt %0" : "=m"(ldt))
137
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200138static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100139{
140 memcpy(&idt[entry], gate, sizeof(*gate));
141}
142
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200143static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100144{
145 memcpy(&ldt[entry], desc, 8);
146}
147
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200148static inline void
149native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int type)
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100150{
151 unsigned int size;
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200152
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100153 switch (type) {
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200154 case DESC_TSS: size = sizeof(tss_desc); break;
155 case DESC_LDT: size = sizeof(ldt_desc); break;
156 default: size = sizeof(*gdt); break;
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100157 }
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200158
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100159 memcpy(&gdt[entry], desc, size);
160}
161
Thomas Gleixner64b163f2017-08-28 08:47:37 +0200162static inline void set_tssldt_descriptor(void *d, unsigned long addr,
163 unsigned type, unsigned size)
Glauber de Oliveira Costac81c6ca2008-01-30 13:31:14 +0100164{
Thomas Gleixner87cc0372017-08-28 08:47:42 +0200165 struct ldttss_desc *desc = d;
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200166
Glauber de Oliveira Costaf6e0eba2008-01-30 13:31:20 +0100167 memset(desc, 0, sizeof(*desc));
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200168
Thomas Gleixner87cc0372017-08-28 08:47:42 +0200169 desc->limit0 = (u16) size;
Thomas Gleixner64b163f2017-08-28 08:47:37 +0200170 desc->base0 = (u16) addr;
171 desc->base1 = (addr >> 16) & 0xFF;
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200172 desc->type = type;
173 desc->p = 1;
174 desc->limit1 = (size >> 16) & 0xF;
Thomas Gleixner64b163f2017-08-28 08:47:37 +0200175 desc->base2 = (addr >> 24) & 0xFF;
Thomas Gleixner87cc0372017-08-28 08:47:42 +0200176#ifdef CONFIG_X86_64
Thomas Gleixner64b163f2017-08-28 08:47:37 +0200177 desc->base3 = (u32) (addr >> 32);
Glauber de Oliveira Costac81c6ca2008-01-30 13:31:14 +0100178#endif
179}
180
Andy Lutomirski7fb983b2017-12-04 15:07:17 +0100181static inline void __set_tss_desc(unsigned cpu, unsigned int entry, struct x86_hw_tss *addr)
Glauber de Oliveira Costac81c6ca2008-01-30 13:31:14 +0100182{
Thomas Garnier69218e42017-03-14 10:05:07 -0700183 struct desc_struct *d = get_cpu_gdt_rw(cpu);
Glauber de Oliveira Costac81c6ca2008-01-30 13:31:14 +0100184 tss_desc tss;
185
Glauber de Oliveira Costaf6e0eba2008-01-30 13:31:20 +0100186 set_tssldt_descriptor(&tss, (unsigned long)addr, DESC_TSS,
Andy Lutomirski4f53ab12017-02-20 08:56:09 -0800187 __KERNEL_TSS_LIMIT);
Glauber de Oliveira Costac81c6ca2008-01-30 13:31:14 +0100188 write_gdt_entry(d, entry, &tss, DESC_TSS);
189}
190
191#define set_tss_desc(cpu, addr) __set_tss_desc(cpu, GDT_ENTRY_TSS, addr)
192
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100193static inline void native_set_ldt(const void *addr, unsigned int entries)
194{
195 if (likely(entries == 0))
Joe Perchesc1773a12008-03-23 01:01:58 -0700196 asm volatile("lldt %w0"::"q" (0));
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100197 else {
198 unsigned cpu = smp_processor_id();
199 ldt_desc ldt;
200
Michael Karcher5ac37f82008-07-11 18:04:46 +0200201 set_tssldt_descriptor(&ldt, (unsigned long)addr, DESC_LDT,
202 entries * LDT_ENTRY_SIZE - 1);
Thomas Garnier69218e42017-03-14 10:05:07 -0700203 write_gdt_entry(get_cpu_gdt_rw(cpu), GDT_ENTRY_LDT,
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100204 &ldt, DESC_LDT);
Joe Perchesc1773a12008-03-23 01:01:58 -0700205 asm volatile("lldt %w0"::"q" (GDT_ENTRY_LDT*8));
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100206 }
207}
208
Thomas Garnier45fc8752017-03-14 10:05:08 -0700209static inline void native_load_gdt(const struct desc_ptr *dtr)
210{
211 asm volatile("lgdt %0"::"m" (*dtr));
212}
213
214static inline void native_load_idt(const struct desc_ptr *dtr)
215{
216 asm volatile("lidt %0"::"m" (*dtr));
217}
218
219static inline void native_store_gdt(struct desc_ptr *dtr)
220{
221 asm volatile("sgdt %0":"=m" (*dtr));
222}
223
Juergen Gross87930012017-09-04 12:25:27 +0200224static inline void store_idt(struct desc_ptr *dtr)
Thomas Garnier45fc8752017-03-14 10:05:08 -0700225{
226 asm volatile("sidt %0":"=m" (*dtr));
227}
228
229/*
230 * The LTR instruction marks the TSS GDT entry as busy. On 64-bit, the GDT is
231 * a read-only remapping. To prevent a page fault, the GDT is switched to the
232 * original writeable version when needed.
233 */
234#ifdef CONFIG_X86_64
235static inline void native_load_tr_desc(void)
236{
237 struct desc_ptr gdt;
238 int cpu = raw_smp_processor_id();
239 bool restore = 0;
240 struct desc_struct *fixmap_gdt;
241
242 native_store_gdt(&gdt);
243 fixmap_gdt = get_cpu_gdt_ro(cpu);
244
245 /*
246 * If the current GDT is the read-only fixmap, swap to the original
247 * writeable version. Swap back at the end.
248 */
249 if (gdt.address == (unsigned long)fixmap_gdt) {
250 load_direct_gdt(cpu);
251 restore = 1;
252 }
253 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
254 if (restore)
255 load_fixmap_gdt(cpu);
256}
257#else
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100258static inline void native_load_tr_desc(void)
259{
260 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
261}
Thomas Garnier45fc8752017-03-14 10:05:08 -0700262#endif
263
264static inline unsigned long native_store_tr(void)
265{
266 unsigned long tr;
267
268 asm volatile("str %0":"=r" (tr));
269
270 return tr;
271}
272
273static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
274{
275 struct desc_struct *gdt = get_cpu_gdt_rw(cpu);
276 unsigned int i;
277
278 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
279 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
280}
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100281
Andy Lutomirskib7ceaec2017-02-22 07:36:16 -0800282DECLARE_PER_CPU(bool, __tss_limit_invalid);
283
Andy Lutomirskib7ffc442017-02-20 08:56:14 -0800284static inline void force_reload_TR(void)
285{
Thomas Garnier69218e42017-03-14 10:05:07 -0700286 struct desc_struct *d = get_current_gdt_rw();
Andy Lutomirskib7ffc442017-02-20 08:56:14 -0800287 tss_desc tss;
288
289 memcpy(&tss, &d[GDT_ENTRY_TSS], sizeof(tss_desc));
290
291 /*
292 * LTR requires an available TSS, and the TSS is currently
293 * busy. Make it be available so that LTR will work.
294 */
295 tss.type = DESC_TSS;
296 write_gdt_entry(d, GDT_ENTRY_TSS, &tss, DESC_TSS);
297
298 load_TR_desc();
Andy Lutomirskib7ceaec2017-02-22 07:36:16 -0800299 this_cpu_write(__tss_limit_invalid, false);
Andy Lutomirskib7ffc442017-02-20 08:56:14 -0800300}
301
Andy Lutomirskib7ceaec2017-02-22 07:36:16 -0800302/*
303 * Call this if you need the TSS limit to be correct, which should be the case
304 * if and only if you have TIF_IO_BITMAP set or you're switching to a task
305 * with TIF_IO_BITMAP set.
306 */
307static inline void refresh_tss_limit(void)
Andy Lutomirskib7ffc442017-02-20 08:56:14 -0800308{
309 DEBUG_LOCKS_WARN_ON(preemptible());
310
Andy Lutomirskib7ceaec2017-02-22 07:36:16 -0800311 if (unlikely(this_cpu_read(__tss_limit_invalid)))
Andy Lutomirskib7ffc442017-02-20 08:56:14 -0800312 force_reload_TR();
Andy Lutomirskib7ffc442017-02-20 08:56:14 -0800313}
314
315/*
316 * If you do something evil that corrupts the cached TSS limit (I'm looking
317 * at you, VMX exits), call this function.
318 *
319 * The optimization here is that the TSS limit only matters for Linux if the
320 * IO bitmap is in use. If the TSS limit gets forced to its minimum value,
321 * everything works except that IO bitmap will be ignored and all CPL 3 IO
322 * instructions will #GP, which is exactly what we want for normal tasks.
323 */
324static inline void invalidate_tss_limit(void)
325{
326 DEBUG_LOCKS_WARN_ON(preemptible());
327
328 if (unlikely(test_thread_flag(TIF_IO_BITMAP)))
329 force_reload_TR();
330 else
Andy Lutomirskib7ceaec2017-02-22 07:36:16 -0800331 this_cpu_write(__tss_limit_invalid, true);
Andy Lutomirskib7ffc442017-02-20 08:56:14 -0800332}
333
Andy Lutomirskie30ab182015-01-22 11:27:58 -0800334/* This intentionally ignores lm, since 32-bit apps don't have that field. */
335#define LDT_empty(info) \
Joe Perchesc1773a12008-03-23 01:01:58 -0700336 ((info)->base_addr == 0 && \
337 (info)->limit == 0 && \
338 (info)->contents == 0 && \
339 (info)->read_exec_only == 1 && \
340 (info)->seg_32bit == 0 && \
341 (info)->limit_in_pages == 0 && \
342 (info)->seg_not_present == 1 && \
343 (info)->useable == 0)
Glauber de Oliveira Costa881c2972008-01-30 13:31:14 +0100344
Andy Lutomirski3669ef92015-01-22 11:27:59 -0800345/* Lots of programs expect an all-zero user_desc to mean "no segment at all". */
346static inline bool LDT_zero(const struct user_desc *info)
347{
348 return (info->base_addr == 0 &&
349 info->limit == 0 &&
350 info->contents == 0 &&
351 info->read_exec_only == 0 &&
352 info->seg_32bit == 0 &&
353 info->limit_in_pages == 0 &&
354 info->seg_not_present == 0 &&
355 info->useable == 0);
356}
357
Glauber de Oliveira Costa881c2972008-01-30 13:31:14 +0100358static inline void clear_LDT(void)
359{
360 set_ldt(NULL, 0);
361}
362
Roland McGrath1bd57182008-01-30 13:31:51 +0100363static inline unsigned long get_desc_base(const struct desc_struct *desc)
Glauber de Oliveira Costacc697852008-01-30 13:31:14 +0100364{
Chris Lalancette2c759102009-11-05 11:47:08 +0100365 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
Glauber de Oliveira Costacc697852008-01-30 13:31:14 +0100366}
Roland McGrath1bd57182008-01-30 13:31:51 +0100367
Akinobu Mita57594742009-07-19 00:11:06 +0900368static inline void set_desc_base(struct desc_struct *desc, unsigned long base)
369{
370 desc->base0 = base & 0xffff;
371 desc->base1 = (base >> 16) & 0xff;
372 desc->base2 = (base >> 24) & 0xff;
373}
374
Roland McGrath1bd57182008-01-30 13:31:51 +0100375static inline unsigned long get_desc_limit(const struct desc_struct *desc)
376{
Thomas Gleixner38e9e812017-08-28 08:47:41 +0200377 return desc->limit0 | (desc->limit1 << 16);
Roland McGrath1bd57182008-01-30 13:31:51 +0100378}
379
Akinobu Mita57594742009-07-19 00:11:06 +0900380static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
381{
382 desc->limit0 = limit & 0xffff;
Thomas Gleixner38e9e812017-08-28 08:47:41 +0200383 desc->limit1 = (limit >> 16) & 0xf;
Akinobu Mita57594742009-07-19 00:11:06 +0900384}
385
Thomas Gleixnerfacaa3e2017-08-28 08:47:59 +0200386void update_intr_gate(unsigned int n, const void *addr);
Thomas Gleixnerdb18da72017-08-28 08:47:57 +0200387void alloc_intr_gate(unsigned int n, const void *addr);
Glauber de Oliveira Costa507f90c2008-01-30 13:31:14 +0100388
Yinghai Lub77b8812008-12-19 15:23:44 -0800389extern unsigned long used_vectors[];
Alan Mayer305b92a2008-04-15 15:36:56 -0500390
Seiji Aguchi629f4f92013-06-20 11:45:44 -0400391#ifdef CONFIG_X86_64
392DECLARE_PER_CPU(u32, debug_idt_ctr);
393static inline bool is_debug_idt_enabled(void)
394{
395 if (this_cpu_read(debug_idt_ctr))
396 return true;
397
398 return false;
399}
400
401static inline void load_debug_idt(void)
402{
403 load_idt((const struct desc_ptr *)&debug_idt_descr);
404}
405#else
406static inline bool is_debug_idt_enabled(void)
407{
408 return false;
409}
410
411static inline void load_debug_idt(void)
412{
413}
414#endif
415
416/*
Steven Rostedt (Red Hat)2b4bc782013-06-22 13:16:19 -0400417 * The load_current_idt() must be called with interrupts disabled
Seiji Aguchi629f4f92013-06-20 11:45:44 -0400418 * to avoid races. That way the IDT will always be set back to the expected
Steven Rostedt (Red Hat)2b4bc782013-06-22 13:16:19 -0400419 * descriptor. It's also called when a CPU is being initialized, and
420 * that doesn't need to disable interrupts, as nothing should be
421 * bothering the CPU then.
Seiji Aguchi629f4f92013-06-20 11:45:44 -0400422 */
423static inline void load_current_idt(void)
424{
Seiji Aguchi629f4f92013-06-20 11:45:44 -0400425 if (is_debug_idt_enabled())
426 load_debug_idt();
427 else
428 load_idt((const struct desc_ptr *)&idt_descr);
Seiji Aguchi629f4f92013-06-20 11:45:44 -0400429}
Thomas Gleixnere802a512017-08-28 08:47:46 +0200430
Thomas Gleixner588787f2017-08-28 08:47:47 +0200431extern void idt_setup_early_handler(void);
432extern void idt_setup_early_traps(void);
Thomas Gleixnerb70543a2017-08-28 08:47:53 +0200433extern void idt_setup_traps(void);
Thomas Gleixner636a7592017-08-28 08:47:54 +0200434extern void idt_setup_apic_and_irq_gates(void);
Thomas Gleixner588787f2017-08-28 08:47:47 +0200435
436#ifdef CONFIG_X86_64
437extern void idt_setup_early_pf(void);
Thomas Gleixner90f62252017-08-28 08:47:52 +0200438extern void idt_setup_ist_traps(void);
Thomas Gleixner0a309082017-08-28 08:47:51 +0200439extern void idt_setup_debugidt_traps(void);
Thomas Gleixner588787f2017-08-28 08:47:47 +0200440#else
441static inline void idt_setup_early_pf(void) { }
Thomas Gleixner90f62252017-08-28 08:47:52 +0200442static inline void idt_setup_ist_traps(void) { }
Thomas Gleixner0a309082017-08-28 08:47:51 +0200443static inline void idt_setup_debugidt_traps(void) { }
Thomas Gleixner588787f2017-08-28 08:47:47 +0200444#endif
445
Thomas Gleixnere802a512017-08-28 08:47:46 +0200446extern void idt_invalidate(void *addr);
447
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700448#endif /* _ASM_X86_DESC_H */