Print this page
8956 Implement KPTI
Reviewed by: Jerry Jelinek <jerry.jelinek@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/intel/sys/segments.h
          +++ new/usr/src/uts/intel/sys/segments.h
   1    1  /*
   2    2   * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
   3    3   */
   4    4  /*
   5      - * Copyright 2016 Joyent, Inc.
        5 + * Copyright 2018 Joyent, Inc.
   6    6   */
   7    7  
   8    8  #ifndef _SYS_SEGMENTS_H
   9    9  #define _SYS_SEGMENTS_H
  10   10  
  11   11  #ifdef  __cplusplus
  12   12  extern "C" {
  13   13  #endif
  14   14  
  15   15  /*
↓ open down ↓ 75 lines elided ↑ open up ↑
  91   91   * 64-bit hypervisor. Both guest kernel and user run in ring 3 and the
  92   92   * hypervisor runs in ring 0. When the kernel creates its trap and
  93   93   * interrupt gates it needs a way to prevent any arbitrary int $n
  94   94   * instruction from entering a gate that is not expected. The hypervisor
  95   95   * allows these gates to have a DPL from 1 to 3. By creating gates
  96   96   * with a DPL below user (ring 3) the int $n will generate a #gp fault
  97   97   * which the hypervisor catches and forwards to the guest.
  98   98   */
  99   99  #if defined(__xpv)
 100  100  
 101      -#if defined(__amd64)
 102      -
 103  101  #define SEL_XPL         0               /* hypervisor privilege level */
 104  102  #define SEL_KPL         3               /* both kernel and user in ring 3 */
 105  103  #define TRP_KPL         1               /* system gate priv (user blocked) */
 106      -
 107      -#elif defined(__i386)
 108      -
 109      -#define SEL_XPL         0               /* hypervisor privilege level */
 110      -#define SEL_KPL         1               /* kernel privilege level */
 111      -#define TRP_KPL         SEL_KPL         /* system gate priv (user blocked) */
 112      -
 113      -#endif  /* __i386 */
 114      -
 115  104  #define TRP_XPL         0               /* system gate priv (hypervisor) */
 116  105  
      106 +#define IST_DBG         0
      107 +
 117  108  #else   /* __xpv */
 118  109  
 119  110  #define SEL_KPL         0               /* kernel privilege level on metal */
 120  111  #define TRP_KPL         SEL_KPL         /* system gate priv (user blocked) */
 121  112  
      113 +
      114 +#define IST_DF          1
      115 +#define IST_NMI         2
      116 +#define IST_MCE         3
      117 +#define IST_DBG         4
      118 +#define IST_NESTABLE    5
      119 +#define IST_DEFAULT     6
      120 +
 122  121  #endif  /* __xpv */
 123  122  
      123 +#define IST_NONE        0
      124 +
 124  125  #define SEL_UPL         3               /* user priority level */
 125  126  #define TRP_UPL         3               /* system gate priv (user allowed) */
 126  127  #define SEL_TI_LDT      4               /* local descriptor table */
 127  128  #define SEL_LDT(s)      (IDXTOSEL(s) | SEL_TI_LDT | SEL_UPL)    /* local sel */
 128  129  #define CPL_MASK        3               /* RPL mask for selector */
 129  130  #define SELISLDT(s)     (((s) & SEL_TI_LDT) == SEL_TI_LDT)
 130  131  #define SELISUPL(s)     (((s) & CPL_MASK) == SEL_UPL)
 131  132  
 132  133  #ifndef _ASM
 133  134  
↓ open down ↓ 260 lines elided ↑ open up ↑
 394  395  extern void set_usegd(user_desc_t *, uint_t, void *, size_t, uint_t, uint_t,
 395  396      uint_t, uint_t);
 396  397  
 397  398  #elif defined(__i386)
 398  399  
 399  400  extern void set_usegd(user_desc_t *, void *, size_t, uint_t, uint_t,
 400  401      uint_t, uint_t);
 401  402  
 402  403  #endif  /* __i386 */
 403  404  
      405 +extern uint_t idt_vector_to_ist(uint_t);
      406 +
 404  407  extern void set_gatesegd(gate_desc_t *, void (*)(void), selector_t,
 405  408      uint_t, uint_t, uint_t);
 406  409  
 407  410  extern void set_syssegd(system_desc_t *, void *, size_t, uint_t, uint_t);
 408  411  
 409  412  extern void *get_ssd_base(system_desc_t *);
 410  413  
 411  414  extern void gdt_update_usegd(uint_t, user_desc_t *);
 412  415  
 413  416  extern int ldt_update_segd(user_desc_t *, user_desc_t *);
↓ open down ↓ 225 lines elided ↑ open up ↑
 639  642  #define LDT_SYSCALL     0       /* call gate for libc.a (obsolete) */
 640  643  #define LDT_SIGCALL     1       /* EOL me, call gate for static sigreturn */
 641  644  #define LDT_RESVD1      2       /* old user %cs */
 642  645  #define LDT_RESVD2      3       /* old user %ds */
 643  646  #define LDT_ALTSYSCALL  4       /* alternate call gate for system calls */
 644  647  #define LDT_ALTSIGCALL  5       /* EOL me, alternate call gate for sigreturn */
 645  648  #define LDT_UDBASE      6       /* user descriptor base index */
 646  649  #define MINNLDT         512     /* Current min solaris ldt size (1 4K page) */
 647  650  #define MAXNLDT         8192    /* max solaris ldt size (16 4K pages) */
 648  651  
      652 +#ifdef _KERNEL
      653 +#define LDT_CPU_SIZE    (16 * 4096)     /* Size of kernel per-CPU allocation */
      654 +#endif
      655 +
 649  656  #ifndef _ASM
 650  657  
 651  658  extern  gate_desc_t     *idt0;
 652  659  extern  desctbr_t       idt0_default_reg;
 653  660  extern  user_desc_t     *gdt0;
 654  661  
 655  662  extern user_desc_t      zero_udesc;
 656  663  extern user_desc_t      null_udesc;
 657  664  extern system_desc_t    null_sdesc;
 658  665  
↓ open down ↓ 20 lines elided ↑ open up ↑
 679  686  #endif
 680  687  extern void invaltrap(), invtsstrap(), segnptrap(), stktrap();
 681  688  extern void gptrap(), pftrap(), ndperr();
 682  689  extern void overrun(), resvtrap();
 683  690  extern void _start(), cmnint();
 684  691  extern void achktrap(), mcetrap();
 685  692  extern void xmtrap();
 686  693  extern void fasttrap();
 687  694  extern void dtrace_ret();
 688  695  
      696 +/* KPTI trampolines */
      697 +extern void tr_invaltrap();
      698 +extern void tr_div0trap(), tr_dbgtrap(), tr_nmiint(), tr_brktrap();
      699 +extern void tr_ovflotrap(), tr_boundstrap(), tr_invoptrap(), tr_ndptrap();
      700 +#if !defined(__xpv)
      701 +extern void tr_syserrtrap();
      702 +#endif
      703 +extern void tr_invaltrap(), tr_invtsstrap(), tr_segnptrap(), tr_stktrap();
      704 +extern void tr_gptrap(), tr_pftrap(), tr_ndperr();
      705 +extern void tr_overrun(), tr_resvtrap();
      706 +extern void tr_achktrap(), tr_mcetrap();
      707 +extern void tr_xmtrap();
      708 +extern void tr_fasttrap();
      709 +extern void tr_dtrace_ret();
      710 +
 689  711  #if !defined(__amd64)
 690  712  extern void pentium_pftrap();
 691  713  #endif
 692  714  
      715 +extern uint64_t kpti_enable;
      716 +
 693  717  #endif /* _ASM */
 694  718  
 695  719  #ifdef  __cplusplus
 696  720  }
 697  721  #endif
 698  722  
 699  723  #endif /* _SYS_SEGMENTS_H */
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX