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


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.


  24  */
  25 
  26 #ifndef _SYS_MACH_MMU_H
  27 #define _SYS_MACH_MMU_H
  28 
  29 #pragma ident   "%Z%%M% %I%     %E% SMI"
  30 
  31 #ifdef __cplusplus
  32 extern "C" {
  33 #endif
  34 
  35 #ifndef _ASM
  36 
  37 #include <sys/types.h>
  38 #include <sys/systm.h>
  39 
  40 /*
  41  * Platform-dependent MMU routines and types.
  42  *
  43  * WARNING: this header file is used by both dboot and i86pc, so don't go using
  44  * normal kernel headers.
  45  */
  46 
  47 #define TWO_MEG         (2 * 1024 * 1024)
  48 
  49 /*
  50  * This is:


 114 #define PT_PTPBITS      (PT_VALID | PT_USER | PT_WRITABLE | PT_REF)
 115 #define PT_FLAGBITS     (0xfff) /* for masking off flag bits */
 116 
 117 /*
 118  * The software bits are used by the HAT to track attributes.
 119  * Note that the attributes are inclusive as the values increase.
 120  *
 121  * PT_NOSYNC - The PT_REF/PT_MOD bits are not sync'd to page_t.
 122  *             The hat will install them as always set.
 123  *
 124  * PT_NOCONSIST - There is no hment entry for this mapping.
 125  *
 126  * PT_FOREIGN - used for the hypervisor, check via
 127  *              (pte & PT_SOFTWARE) >= PT_FOREIGN
 128  *              as it might set 0x800 for foreign grant table mappings.
 129  */
 130 #define PT_NOSYNC       (0x200) /* PTE was created with HAT_NOSYNC */
 131 #define PT_NOCONSIST    (0x400) /* PTE was created with HAT_LOAD_NOCONSIST */
 132 #define PT_FOREIGN      (0x600) /* MFN mapped on the hypervisor has no PFN */
 133 













 134 #ifdef __xpv
 135 #include <sys/xen_mmu.h>
 136 #else
 137 #include <sys/pc_mmu.h>
 138 #endif
 139 
 140 /*
 141  * The software extraction for a single Page Table Entry will always
 142  * be a 64 bit unsigned int. If running a non-PAE hat, the page table
 143  * access routines know to extend/shorten it to 32 bits.
 144  */
 145 typedef uint64_t x86pte_t;
 146 typedef uint32_t x86pte32_t;
 147 
 148 x86pte_t get_pteval(paddr_t, uint_t);
 149 void set_pteval(paddr_t, uint_t, uint_t, x86pte_t);
 150 paddr_t make_ptable(x86pte_t *, uint_t);
 151 x86pte_t *find_pte(uint64_t, paddr_t *, uint_t, uint_t);
 152 x86pte_t *map_pte(paddr_t, uint_t);
 153 
 154 #ifndef _BOOT
 155 ulong_t getcr3();
 156 #endif
 157 
 158 extern uint_t *shift_amt;
 159 extern uint_t ptes_per_table;
 160 extern paddr_t top_page_table;
 161 extern uint_t top_level;
 162 extern uint_t pte_size;
 163 extern uint_t shift_amt_nopae[];
 164 extern uint_t shift_amt_pae[];
 165 extern uint32_t lpagesize;
 166 
 167 #ifdef __cplusplus
 168 }
 169 #endif
 170 
 171 #endif /* _ASM */
 172 
 173 #endif  /* _SYS_MACH_MMU_H */


   4  * The contents of this file are subject to the terms of the
   5  * Common Development and Distribution License (the "License").
   6  * You may not use this file except in compliance with the License.
   7  *
   8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9  * or http://www.opensolaris.org/os/licensing.
  10  * See the License for the specific language governing permissions
  11  * and limitations under the License.
  12  *
  13  * When distributing Covered Code, include this CDDL HEADER in each
  14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15  * If applicable, add the following below this CDDL HEADER, with the
  16  * fields enclosed by brackets "[]" replaced with your own identifying
  17  * information: Portions Copyright [yyyy] [name of copyright owner]
  18  *
  19  * CDDL HEADER END
  20  */
  21 /*
  22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  23  * Use is subject to license terms.
  24  *
  25  * Copyright 2018 Joyent, Inc.
  26  */
  27 
  28 #ifndef _SYS_MACH_MMU_H
  29 #define _SYS_MACH_MMU_H
  30 


  31 #ifdef __cplusplus
  32 extern "C" {
  33 #endif
  34 
  35 #ifndef _ASM
  36 
  37 #include <sys/types.h>
  38 #include <sys/systm.h>
  39 
  40 /*
  41  * Platform-dependent MMU routines and types.
  42  *
  43  * WARNING: this header file is used by both dboot and i86pc, so don't go using
  44  * normal kernel headers.
  45  */
  46 
  47 #define TWO_MEG         (2 * 1024 * 1024)
  48 
  49 /*
  50  * This is:


 114 #define PT_PTPBITS      (PT_VALID | PT_USER | PT_WRITABLE | PT_REF)
 115 #define PT_FLAGBITS     (0xfff) /* for masking off flag bits */
 116 
 117 /*
 118  * The software bits are used by the HAT to track attributes.
 119  * Note that the attributes are inclusive as the values increase.
 120  *
 121  * PT_NOSYNC - The PT_REF/PT_MOD bits are not sync'd to page_t.
 122  *             The hat will install them as always set.
 123  *
 124  * PT_NOCONSIST - There is no hment entry for this mapping.
 125  *
 126  * PT_FOREIGN - used for the hypervisor, check via
 127  *              (pte & PT_SOFTWARE) >= PT_FOREIGN
 128  *              as it might set 0x800 for foreign grant table mappings.
 129  */
 130 #define PT_NOSYNC       (0x200) /* PTE was created with HAT_NOSYNC */
 131 #define PT_NOCONSIST    (0x400) /* PTE was created with HAT_LOAD_NOCONSIST */
 132 #define PT_FOREIGN      (0x600) /* MFN mapped on the hypervisor has no PFN */
 133 
 134 #ifndef _BOOT
 135 
 136 extern ulong_t getcr3(void);
 137 extern void setcr3(ulong_t);
 138 
 139 #define getcr3_pa() (getcr3() & MMU_PAGEMASK)
 140 #define getpcid() ((getcr4() & CR4_PCIDE) ? \
 141         (getcr3() & MMU_PAGEOFFSET) : PCID_NONE)
 142 
 143 extern void mmu_invlpg(caddr_t);
 144 
 145 #endif
 146 
 147 #ifdef __xpv
 148 #include <sys/xen_mmu.h>
 149 #else
 150 #include <sys/pc_mmu.h>
 151 #endif
 152 
 153 /*
 154  * The software extraction for a single Page Table Entry will always
 155  * be a 64 bit unsigned int. If running a non-PAE hat, the page table
 156  * access routines know to extend/shorten it to 32 bits.
 157  */
 158 typedef uint64_t x86pte_t;
 159 typedef uint32_t x86pte32_t;
 160 
 161 x86pte_t get_pteval(paddr_t, uint_t);
 162 void set_pteval(paddr_t, uint_t, uint_t, x86pte_t);
 163 paddr_t make_ptable(x86pte_t *, uint_t);
 164 x86pte_t *find_pte(uint64_t, paddr_t *, uint_t, uint_t);
 165 x86pte_t *map_pte(paddr_t, uint_t);
 166 




 167 extern uint_t *shift_amt;
 168 extern uint_t ptes_per_table;
 169 extern paddr_t top_page_table;
 170 extern uint_t top_level;
 171 extern uint_t pte_size;
 172 extern uint_t shift_amt_nopae[];
 173 extern uint_t shift_amt_pae[];
 174 extern uint32_t lpagesize;
 175 
 176 #ifdef __cplusplus
 177 }
 178 #endif
 179 
 180 #endif /* _ASM */
 181 
 182 #endif  /* _SYS_MACH_MMU_H */