blob: c474bf4971d976282c231ea96cae35185205a9f0 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_DESC_H
2#define _ASM_X86_DESC_H
Glauber de Oliveira Costa80fbb692008-01-30 13:31:13 +01003
Glauber de Oliveira Costa80fbb692008-01-30 13:31:13 +01004#include <asm/desc_defs.h>
5#include <asm/ldt.h>
Glauber de Oliveira Costa881c2972008-01-30 13:31:14 +01006#include <asm/mmu.h>
Thomas Garnier69218e42017-03-14 10:05:07 -07007#include <asm/fixmap.h>
Thomas Gleixner05161b92017-08-28 08:47:18 +02008#include <asm/irq_vectors.h>
Ingo Molnar9a3865b2011-05-27 09:29:32 +02009
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +010010#include <linux/smp.h>
Alex Shic6ae41e2012-05-11 15:35:27 +080011#include <linux/percpu.h>
Glauber de Oliveira Costa80fbb692008-01-30 13:31:13 +010012
Ingo Molnar9a3865b2011-05-27 09:29:32 +020013static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *info)
Glauber de Oliveira Costa80fbb692008-01-30 13:31:13 +010014{
Ingo Molnar9a3865b2011-05-27 09:29:32 +020015 desc->limit0 = info->limit & 0x0ffff;
Glauber de Oliveira Costa80fbb692008-01-30 13:31:13 +010016
Ingo Molnar9a3865b2011-05-27 09:29:32 +020017 desc->base0 = (info->base_addr & 0x0000ffff);
18 desc->base1 = (info->base_addr & 0x00ff0000) >> 16;
19
20 desc->type = (info->read_exec_only ^ 1) << 1;
21 desc->type |= info->contents << 2;
22
23 desc->s = 1;
24 desc->dpl = 0x3;
25 desc->p = info->seg_not_present ^ 1;
Thomas Gleixner38e9e812017-08-28 08:47:41 +020026 desc->limit1 = (info->limit & 0xf0000) >> 16;
Ingo Molnar9a3865b2011-05-27 09:29:32 +020027 desc->avl = info->useable;
28 desc->d = info->seg_32bit;
29 desc->g = info->limit_in_pages;
30
31 desc->base2 = (info->base_addr & 0xff000000) >> 24;
Jeremy Fitzhardinge64f53a02008-07-27 08:42:32 -070032 /*
Andy Lutomirski318f5a22011-08-03 09:31:53 -040033 * Don't allow setting of the lm bit. It would confuse
34 * user_64bit_mode and would get overridden by sysret anyway.
Jeremy Fitzhardinge64f53a02008-07-27 08:42:32 -070035 */
Ingo Molnar9a3865b2011-05-27 09:29:32 +020036 desc->l = 0;
Glauber de Oliveira Costa80fbb692008-01-30 13:31:13 +010037}
38
Glauber de Oliveira Costa881c2972008-01-30 13:31:14 +010039extern struct desc_ptr idt_descr;
40extern gate_desc idt_table[];
Kees Cook404f6aa2016-08-08 16:29:06 -070041extern const struct desc_ptr debug_idt_descr;
Seiji Aguchi629f4f92013-06-20 11:45:44 -040042extern gate_desc debug_idt_table[];
Glauber de Oliveira Costa80fbb692008-01-30 13:31:13 +010043
Glauber Costaa9390982008-05-28 16:19:53 -070044struct gdt_page {
45 struct desc_struct gdt[GDT_ENTRIES];
46} __attribute__((aligned(PAGE_SIZE)));
Ingo Molnar9a3865b2011-05-27 09:29:32 +020047
David Howells9b8de742009-04-21 23:00:24 +010048DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
Glauber Costaa9390982008-05-28 16:19:53 -070049
Thomas Garnier69218e42017-03-14 10:05:07 -070050/* Provide the original GDT */
51static inline struct desc_struct *get_cpu_gdt_rw(unsigned int cpu)
Glauber Costaa9390982008-05-28 16:19:53 -070052{
53 return per_cpu(gdt_page, cpu).gdt;
54}
55
Thomas Garnier69218e42017-03-14 10:05:07 -070056/* Provide the current original GDT */
57static inline struct desc_struct *get_current_gdt_rw(void)
58{
59 return this_cpu_ptr(&gdt_page)->gdt;
60}
61
Thomas Garnier69218e42017-03-14 10:05:07 -070062/* Get the fixmap index for a specific processor */
63static inline unsigned int get_cpu_gdt_ro_index(int cpu)
64{
65 return FIX_GDT_REMAP_BEGIN + cpu;
66}
67
68/* Provide the fixmap address of the remapped GDT */
69static inline struct desc_struct *get_cpu_gdt_ro(int cpu)
70{
71 unsigned int idx = get_cpu_gdt_ro_index(cpu);
72 return (struct desc_struct *)__fix_to_virt(idx);
73}
74
Thomas Garnier69218e42017-03-14 10:05:07 -070075/* Provide the current read-only GDT */
76static inline struct desc_struct *get_current_gdt_ro(void)
77{
78 return get_cpu_gdt_ro(smp_processor_id());
79}
80
Andy Lutomirskiaa4ea67552017-03-22 14:32:30 -070081/* Provide the physical address of the GDT page. */
82static inline phys_addr_t get_cpu_gdt_paddr(unsigned int cpu)
83{
84 return per_cpu_ptr_to_phys(get_cpu_gdt_rw(cpu));
85}
86
Glauber de Oliveira Costa507f90c2008-01-30 13:31:14 +010087static inline void pack_gate(gate_desc *gate, unsigned type, unsigned long func,
88 unsigned dpl, unsigned ist, unsigned seg)
89{
Thomas Gleixner64b163f2017-08-28 08:47:37 +020090 gate->offset_low = (u16) func;
91 gate->bits.p = 1;
92 gate->bits.dpl = dpl;
93 gate->bits.zero = 0;
94 gate->bits.type = type;
95 gate->offset_middle = (u16) (func >> 16);
96#ifdef CONFIG_X86_64
Ingo Molnar9a3865b2011-05-27 09:29:32 +020097 gate->segment = __KERNEL_CS;
Thomas Gleixner64b163f2017-08-28 08:47:37 +020098 gate->bits.ist = ist;
99 gate->reserved = 0;
100 gate->offset_high = (u32) (func >> 32);
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100101#else
Thomas Gleixner64b163f2017-08-28 08:47:37 +0200102 gate->segment = seg;
103 gate->bits.ist = 0;
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100104#endif
Thomas Gleixner64b163f2017-08-28 08:47:37 +0200105}
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100106
Glauber de Oliveira Costa746ff602008-01-30 13:31:27 +0100107static inline int desc_empty(const void *ptr)
108{
109 const u32 *desc = ptr;
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200110
Glauber de Oliveira Costa746ff602008-01-30 13:31:27 +0100111 return !(desc[0] | desc[1]);
112}
113
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100114#ifdef CONFIG_PARAVIRT
115#include <asm/paravirt.h>
116#else
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200117#define load_TR_desc() native_load_tr_desc()
118#define load_gdt(dtr) native_load_gdt(dtr)
119#define load_idt(dtr) native_load_idt(dtr)
120#define load_tr(tr) asm volatile("ltr %0"::"m" (tr))
121#define load_ldt(ldt) asm volatile("lldt %0"::"m" (ldt))
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100122
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200123#define store_gdt(dtr) native_store_gdt(dtr)
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200124#define store_tr(tr) (tr = native_store_tr())
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100125
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200126#define load_TLS(t, cpu) native_load_tls(t, cpu)
127#define set_ldt native_set_ldt
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100128
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200129#define write_ldt_entry(dt, entry, desc) native_write_ldt_entry(dt, entry, desc)
130#define write_gdt_entry(dt, entry, desc, type) native_write_gdt_entry(dt, entry, desc, type)
131#define write_idt_entry(dt, entry, g) native_write_idt_entry(dt, entry, g)
Jeremy Fitzhardinge38ffbe62008-07-23 14:21:18 -0700132
133static inline void paravirt_alloc_ldt(struct desc_struct *ldt, unsigned entries)
134{
135}
136
137static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
138{
139}
140#endif /* CONFIG_PARAVIRT */
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100141
Jaswinder Singh Rajput8229d752009-03-11 19:13:49 +0530142#define store_ldt(ldt) asm("sldt %0" : "=m"(ldt))
143
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200144static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100145{
146 memcpy(&idt[entry], gate, sizeof(*gate));
147}
148
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200149static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100150{
151 memcpy(&ldt[entry], desc, 8);
152}
153
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200154static inline void
155native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int type)
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100156{
157 unsigned int size;
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200158
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100159 switch (type) {
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200160 case DESC_TSS: size = sizeof(tss_desc); break;
161 case DESC_LDT: size = sizeof(ldt_desc); break;
162 default: size = sizeof(*gdt); break;
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100163 }
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200164
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100165 memcpy(&gdt[entry], desc, size);
166}
167
Thomas Gleixner64b163f2017-08-28 08:47:37 +0200168static inline void set_tssldt_descriptor(void *d, unsigned long addr,
169 unsigned type, unsigned size)
Glauber de Oliveira Costac81c6ca2008-01-30 13:31:14 +0100170{
Thomas Gleixner87cc0372017-08-28 08:47:42 +0200171 struct ldttss_desc *desc = d;
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200172
Glauber de Oliveira Costaf6e0eba2008-01-30 13:31:20 +0100173 memset(desc, 0, sizeof(*desc));
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200174
Thomas Gleixner87cc0372017-08-28 08:47:42 +0200175 desc->limit0 = (u16) size;
Thomas Gleixner64b163f2017-08-28 08:47:37 +0200176 desc->base0 = (u16) addr;
177 desc->base1 = (addr >> 16) & 0xFF;
Ingo Molnar9a3865b2011-05-27 09:29:32 +0200178 desc->type = type;
179 desc->p = 1;
180 desc->limit1 = (size >> 16) & 0xF;
Thomas Gleixner64b163f2017-08-28 08:47:37 +0200181 desc->base2 = (addr >> 24) & 0xFF;
Thomas Gleixner87cc0372017-08-28 08:47:42 +0200182#ifdef CONFIG_X86_64
Thomas Gleixner64b163f2017-08-28 08:47:37 +0200183 desc->base3 = (u32) (addr >> 32);
Glauber de Oliveira Costac81c6ca2008-01-30 13:31:14 +0100184#endif
185}
186
187static inline void __set_tss_desc(unsigned cpu, unsigned int entry, void *addr)
188{
Thomas Garnier69218e42017-03-14 10:05:07 -0700189 struct desc_struct *d = get_cpu_gdt_rw(cpu);
Glauber de Oliveira Costac81c6ca2008-01-30 13:31:14 +0100190 tss_desc tss;
191
Glauber de Oliveira Costaf6e0eba2008-01-30 13:31:20 +0100192 set_tssldt_descriptor(&tss, (unsigned long)addr, DESC_TSS,
Andy Lutomirski4f53ab12017-02-20 08:56:09 -0800193 __KERNEL_TSS_LIMIT);
Glauber de Oliveira Costac81c6ca2008-01-30 13:31:14 +0100194 write_gdt_entry(d, entry, &tss, DESC_TSS);
195}
196
197#define set_tss_desc(cpu, addr) __set_tss_desc(cpu, GDT_ENTRY_TSS, addr)
198
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100199static inline void native_set_ldt(const void *addr, unsigned int entries)
200{
201 if (likely(entries == 0))
Joe Perchesc1773a12008-03-23 01:01:58 -0700202 asm volatile("lldt %w0"::"q" (0));
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100203 else {
204 unsigned cpu = smp_processor_id();
205 ldt_desc ldt;
206
Michael Karcher5ac37f82008-07-11 18:04:46 +0200207 set_tssldt_descriptor(&ldt, (unsigned long)addr, DESC_LDT,
208 entries * LDT_ENTRY_SIZE - 1);
Thomas Garnier69218e42017-03-14 10:05:07 -0700209 write_gdt_entry(get_cpu_gdt_rw(cpu), GDT_ENTRY_LDT,
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100210 &ldt, DESC_LDT);
Joe Perchesc1773a12008-03-23 01:01:58 -0700211 asm volatile("lldt %w0"::"q" (GDT_ENTRY_LDT*8));
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100212 }
213}
214
Thomas Garnier45fc8752017-03-14 10:05:08 -0700215static inline void native_load_gdt(const struct desc_ptr *dtr)
216{
217 asm volatile("lgdt %0"::"m" (*dtr));
218}
219
220static inline void native_load_idt(const struct desc_ptr *dtr)
221{
222 asm volatile("lidt %0"::"m" (*dtr));
223}
224
225static inline void native_store_gdt(struct desc_ptr *dtr)
226{
227 asm volatile("sgdt %0":"=m" (*dtr));
228}
229
Juergen Gross87930012017-09-04 12:25:27 +0200230static inline void store_idt(struct desc_ptr *dtr)
Thomas Garnier45fc8752017-03-14 10:05:08 -0700231{
232 asm volatile("sidt %0":"=m" (*dtr));
233}
234
235/*
236 * The LTR instruction marks the TSS GDT entry as busy. On 64-bit, the GDT is
237 * a read-only remapping. To prevent a page fault, the GDT is switched to the
238 * original writeable version when needed.
239 */
240#ifdef CONFIG_X86_64
241static inline void native_load_tr_desc(void)
242{
243 struct desc_ptr gdt;
244 int cpu = raw_smp_processor_id();
245 bool restore = 0;
246 struct desc_struct *fixmap_gdt;
247
248 native_store_gdt(&gdt);
249 fixmap_gdt = get_cpu_gdt_ro(cpu);
250
251 /*
252 * If the current GDT is the read-only fixmap, swap to the original
253 * writeable version. Swap back at the end.
254 */
255 if (gdt.address == (unsigned long)fixmap_gdt) {
256 load_direct_gdt(cpu);
257 restore = 1;
258 }
259 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
260 if (restore)
261 load_fixmap_gdt(cpu);
262}
263#else
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100264static inline void native_load_tr_desc(void)
265{
266 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
267}
Thomas Garnier45fc8752017-03-14 10:05:08 -0700268#endif
269
270static inline unsigned long native_store_tr(void)
271{
272 unsigned long tr;
273
274 asm volatile("str %0":"=r" (tr));
275
276 return tr;
277}
278
279static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
280{
281 struct desc_struct *gdt = get_cpu_gdt_rw(cpu);
282 unsigned int i;
283
284 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
285 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
286}
Glauber de Oliveira Costa54cd0ea2008-01-30 13:31:14 +0100287
Andy Lutomirskib7ceaec2017-02-22 07:36:16 -0800288DECLARE_PER_CPU(bool, __tss_limit_invalid);
289
Andy Lutomirskib7ffc442017-02-20 08:56:14 -0800290static inline void force_reload_TR(void)
291{
Thomas Garnier69218e42017-03-14 10:05:07 -0700292 struct desc_struct *d = get_current_gdt_rw();
Andy Lutomirskib7ffc442017-02-20 08:56:14 -0800293 tss_desc tss;
294
295 memcpy(&tss, &d[GDT_ENTRY_TSS], sizeof(tss_desc));
296
297 /*
298 * LTR requires an available TSS, and the TSS is currently
299 * busy. Make it be available so that LTR will work.
300 */
301 tss.type = DESC_TSS;
302 write_gdt_entry(d, GDT_ENTRY_TSS, &tss, DESC_TSS);
303
304 load_TR_desc();
Andy Lutomirskib7ceaec2017-02-22 07:36:16 -0800305 this_cpu_write(__tss_limit_invalid, false);
Andy Lutomirskib7ffc442017-02-20 08:56:14 -0800306}
307
Andy Lutomirskib7ceaec2017-02-22 07:36:16 -0800308/*
309 * Call this if you need the TSS limit to be correct, which should be the case
310 * if and only if you have TIF_IO_BITMAP set or you're switching to a task
311 * with TIF_IO_BITMAP set.
312 */
313static inline void refresh_tss_limit(void)
Andy Lutomirskib7ffc442017-02-20 08:56:14 -0800314{
315 DEBUG_LOCKS_WARN_ON(preemptible());
316
Andy Lutomirskib7ceaec2017-02-22 07:36:16 -0800317 if (unlikely(this_cpu_read(__tss_limit_invalid)))
Andy Lutomirskib7ffc442017-02-20 08:56:14 -0800318 force_reload_TR();
Andy Lutomirskib7ffc442017-02-20 08:56:14 -0800319}
320
321/*
322 * If you do something evil that corrupts the cached TSS limit (I'm looking
323 * at you, VMX exits), call this function.
324 *
325 * The optimization here is that the TSS limit only matters for Linux if the
326 * IO bitmap is in use. If the TSS limit gets forced to its minimum value,
327 * everything works except that IO bitmap will be ignored and all CPL 3 IO
328 * instructions will #GP, which is exactly what we want for normal tasks.
329 */
330static inline void invalidate_tss_limit(void)
331{
332 DEBUG_LOCKS_WARN_ON(preemptible());
333
334 if (unlikely(test_thread_flag(TIF_IO_BITMAP)))
335 force_reload_TR();
336 else
Andy Lutomirskib7ceaec2017-02-22 07:36:16 -0800337 this_cpu_write(__tss_limit_invalid, true);
Andy Lutomirskib7ffc442017-02-20 08:56:14 -0800338}
339
Andy Lutomirskie30ab182015-01-22 11:27:58 -0800340/* This intentionally ignores lm, since 32-bit apps don't have that field. */
341#define LDT_empty(info) \
Joe Perchesc1773a12008-03-23 01:01:58 -0700342 ((info)->base_addr == 0 && \
343 (info)->limit == 0 && \
344 (info)->contents == 0 && \
345 (info)->read_exec_only == 1 && \
346 (info)->seg_32bit == 0 && \
347 (info)->limit_in_pages == 0 && \
348 (info)->seg_not_present == 1 && \
349 (info)->useable == 0)
Glauber de Oliveira Costa881c2972008-01-30 13:31:14 +0100350
Andy Lutomirski3669ef92015-01-22 11:27:59 -0800351/* Lots of programs expect an all-zero user_desc to mean "no segment at all". */
352static inline bool LDT_zero(const struct user_desc *info)
353{
354 return (info->base_addr == 0 &&
355 info->limit == 0 &&
356 info->contents == 0 &&
357 info->read_exec_only == 0 &&
358 info->seg_32bit == 0 &&
359 info->limit_in_pages == 0 &&
360 info->seg_not_present == 0 &&
361 info->useable == 0);
362}
363
Glauber de Oliveira Costa881c2972008-01-30 13:31:14 +0100364static inline void clear_LDT(void)
365{
366 set_ldt(NULL, 0);
367}
368
Roland McGrath1bd57182008-01-30 13:31:51 +0100369static inline unsigned long get_desc_base(const struct desc_struct *desc)
Glauber de Oliveira Costacc697852008-01-30 13:31:14 +0100370{
Chris Lalancette2c759102009-11-05 11:47:08 +0100371 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
Glauber de Oliveira Costacc697852008-01-30 13:31:14 +0100372}
Roland McGrath1bd57182008-01-30 13:31:51 +0100373
Akinobu Mita57594742009-07-19 00:11:06 +0900374static inline void set_desc_base(struct desc_struct *desc, unsigned long base)
375{
376 desc->base0 = base & 0xffff;
377 desc->base1 = (base >> 16) & 0xff;
378 desc->base2 = (base >> 24) & 0xff;
379}
380
Roland McGrath1bd57182008-01-30 13:31:51 +0100381static inline unsigned long get_desc_limit(const struct desc_struct *desc)
382{
Thomas Gleixner38e9e812017-08-28 08:47:41 +0200383 return desc->limit0 | (desc->limit1 << 16);
Roland McGrath1bd57182008-01-30 13:31:51 +0100384}
385
Akinobu Mita57594742009-07-19 00:11:06 +0900386static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
387{
388 desc->limit0 = limit & 0xffff;
Thomas Gleixner38e9e812017-08-28 08:47:41 +0200389 desc->limit1 = (limit >> 16) & 0xf;
Akinobu Mita57594742009-07-19 00:11:06 +0900390}
391
Thomas Gleixnerfacaa3e2017-08-28 08:47:59 +0200392void update_intr_gate(unsigned int n, const void *addr);
Thomas Gleixnerdb18da72017-08-28 08:47:57 +0200393void alloc_intr_gate(unsigned int n, const void *addr);
Glauber de Oliveira Costa507f90c2008-01-30 13:31:14 +0100394
Thomas Gleixner7854f822017-09-13 23:29:26 +0200395extern unsigned long system_vectors[];
Alan Mayer305b92a2008-04-15 15:36:56 -0500396
Seiji Aguchi629f4f92013-06-20 11:45:44 -0400397#ifdef CONFIG_X86_64
398DECLARE_PER_CPU(u32, debug_idt_ctr);
399static inline bool is_debug_idt_enabled(void)
400{
401 if (this_cpu_read(debug_idt_ctr))
402 return true;
403
404 return false;
405}
406
407static inline void load_debug_idt(void)
408{
409 load_idt((const struct desc_ptr *)&debug_idt_descr);
410}
411#else
412static inline bool is_debug_idt_enabled(void)
413{
414 return false;
415}
416
417static inline void load_debug_idt(void)
418{
419}
420#endif
421
422/*
Steven Rostedt (Red Hat)2b4bc782013-06-22 13:16:19 -0400423 * The load_current_idt() must be called with interrupts disabled
Seiji Aguchi629f4f92013-06-20 11:45:44 -0400424 * 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 -0400425 * descriptor. It's also called when a CPU is being initialized, and
426 * that doesn't need to disable interrupts, as nothing should be
427 * bothering the CPU then.
Seiji Aguchi629f4f92013-06-20 11:45:44 -0400428 */
429static inline void load_current_idt(void)
430{
Seiji Aguchi629f4f92013-06-20 11:45:44 -0400431 if (is_debug_idt_enabled())
432 load_debug_idt();
433 else
434 load_idt((const struct desc_ptr *)&idt_descr);
Seiji Aguchi629f4f92013-06-20 11:45:44 -0400435}
Thomas Gleixnere802a512017-08-28 08:47:46 +0200436
Thomas Gleixner588787f2017-08-28 08:47:47 +0200437extern void idt_setup_early_handler(void);
438extern void idt_setup_early_traps(void);
Thomas Gleixnerb70543a2017-08-28 08:47:53 +0200439extern void idt_setup_traps(void);
Thomas Gleixner636a7592017-08-28 08:47:54 +0200440extern void idt_setup_apic_and_irq_gates(void);
Thomas Gleixner588787f2017-08-28 08:47:47 +0200441
442#ifdef CONFIG_X86_64
443extern void idt_setup_early_pf(void);
Thomas Gleixner90f62252017-08-28 08:47:52 +0200444extern void idt_setup_ist_traps(void);
Thomas Gleixner0a309082017-08-28 08:47:51 +0200445extern void idt_setup_debugidt_traps(void);
Thomas Gleixner588787f2017-08-28 08:47:47 +0200446#else
447static inline void idt_setup_early_pf(void) { }
Thomas Gleixner90f62252017-08-28 08:47:52 +0200448static inline void idt_setup_ist_traps(void) { }
Thomas Gleixner0a309082017-08-28 08:47:51 +0200449static inline void idt_setup_debugidt_traps(void) { }
Thomas Gleixner588787f2017-08-28 08:47:47 +0200450#endif
451
Thomas Gleixnere802a512017-08-28 08:47:46 +0200452extern void idt_invalidate(void *addr);
453
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700454#endif /* _ASM_X86_DESC_H */