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


   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 /*
  23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.


  25  */
  26 
  27 #include <sys/debug.h>
  28 #include <sys/types.h>
  29 #include <sys/param.h>
  30 #include <sys/time.h>
  31 #include <sys/buf.h>
  32 #include <sys/errno.h>
  33 #include <sys/systm.h>
  34 #include <sys/conf.h>
  35 #include <sys/signal.h>
  36 #include <sys/file.h>
  37 #include <sys/uio.h>
  38 #include <sys/ioctl.h>
  39 #include <sys/map.h>
  40 #include <sys/proc.h>
  41 #include <sys/user.h>
  42 #include <sys/mman.h>
  43 #include <sys/cred.h>
  44 #include <sys/open.h>


  82  */
  83 gfxp_kva_t
  84 gfxp_map_kernel_space(uint64_t start, size_t size, uint32_t mode)
  85 {
  86         uint_t pgoffset;
  87         uint64_t base;
  88         pgcnt_t npages;
  89         caddr_t cvaddr;
  90         int hat_flags;
  91         uint_t hat_attr;
  92         pfn_t pfn;
  93 
  94         if (size == 0)
  95                 return (0);
  96 
  97 #ifdef __xpv
  98         /*
  99          * The hypervisor doesn't allow r/w mappings to some pages, such as
 100          * page tables, gdt, etc. Detect %cr3 to notify users of this interface.
 101          */
 102         if (start == mmu_ptob(mmu_btop(getcr3())))
 103                 return (0);
 104 #endif
 105 
 106         if (mode == GFXP_MEMORY_CACHED)
 107                 hat_attr = HAT_STORECACHING_OK;
 108         else if (mode == GFXP_MEMORY_WRITECOMBINED)
 109                 hat_attr = HAT_MERGING_OK | HAT_PLAT_NOCACHE;
 110         else    /* GFXP_MEMORY_UNCACHED */
 111                 hat_attr = HAT_STRICTORDER | HAT_PLAT_NOCACHE;
 112         hat_flags = HAT_LOAD_LOCK;
 113         pgoffset = start & PAGEOFFSET;
 114         base = start - pgoffset;
 115         npages = btopr(size + pgoffset);
 116         cvaddr = vmem_alloc(heap_arena, ptob(npages), VM_NOSLEEP);
 117         if (cvaddr == NULL)
 118                 return (NULL);
 119 
 120 #ifdef __xpv
 121         ASSERT(DOMAIN_IS_INITDOMAIN(xen_info));
 122         pfn = xen_assign_pfn(mmu_btop(base));


 301  */
 302 void
 303 gfxp_load_kernel_space(uint64_t start, size_t size,
 304     uint32_t mode, caddr_t cvaddr)
 305 {
 306         uint_t pgoffset;
 307         uint64_t base;
 308         pgcnt_t npages;
 309         int hat_flags;
 310         uint_t hat_attr;
 311         pfn_t pfn;
 312 
 313         if (size == 0)
 314                 return;
 315 
 316 #ifdef __xpv
 317         /*
 318          * The hypervisor doesn't allow r/w mappings to some pages, such as
 319          * page tables, gdt, etc. Detect %cr3 to notify users of this interface.
 320          */
 321         if (start == mmu_ptob(mmu_btop(getcr3())))
 322                 return;
 323 #endif
 324 
 325         if (mode == GFXP_MEMORY_CACHED)
 326                 hat_attr = HAT_STORECACHING_OK;
 327         else if (mode == GFXP_MEMORY_WRITECOMBINED)
 328                 hat_attr = HAT_MERGING_OK | HAT_PLAT_NOCACHE;
 329         else    /* GFXP_MEMORY_UNCACHED */
 330                 hat_attr = HAT_STRICTORDER | HAT_PLAT_NOCACHE;
 331         hat_flags = HAT_LOAD_LOCK;
 332 
 333         pgoffset = start & PAGEOFFSET;
 334         base = start - pgoffset;
 335         npages = btopr(size + pgoffset);
 336 
 337 #ifdef __xpv
 338         ASSERT(DOMAIN_IS_INITDOMAIN(xen_info));
 339         pfn = xen_assign_pfn(mmu_btop(base));
 340 #else
 341         pfn = btop(base);




   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 /*
  23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  24  * Use is subject to license terms.
  25  *
  26  * Copyright 2018 Joyent, Inc.
  27  */
  28 
  29 #include <sys/debug.h>
  30 #include <sys/types.h>
  31 #include <sys/param.h>
  32 #include <sys/time.h>
  33 #include <sys/buf.h>
  34 #include <sys/errno.h>
  35 #include <sys/systm.h>
  36 #include <sys/conf.h>
  37 #include <sys/signal.h>
  38 #include <sys/file.h>
  39 #include <sys/uio.h>
  40 #include <sys/ioctl.h>
  41 #include <sys/map.h>
  42 #include <sys/proc.h>
  43 #include <sys/user.h>
  44 #include <sys/mman.h>
  45 #include <sys/cred.h>
  46 #include <sys/open.h>


  84  */
  85 gfxp_kva_t
  86 gfxp_map_kernel_space(uint64_t start, size_t size, uint32_t mode)
  87 {
  88         uint_t pgoffset;
  89         uint64_t base;
  90         pgcnt_t npages;
  91         caddr_t cvaddr;
  92         int hat_flags;
  93         uint_t hat_attr;
  94         pfn_t pfn;
  95 
  96         if (size == 0)
  97                 return (0);
  98 
  99 #ifdef __xpv
 100         /*
 101          * The hypervisor doesn't allow r/w mappings to some pages, such as
 102          * page tables, gdt, etc. Detect %cr3 to notify users of this interface.
 103          */
 104         if (start == mmu_ptob(mmu_btop(getcr3_pa())))
 105                 return (0);
 106 #endif
 107 
 108         if (mode == GFXP_MEMORY_CACHED)
 109                 hat_attr = HAT_STORECACHING_OK;
 110         else if (mode == GFXP_MEMORY_WRITECOMBINED)
 111                 hat_attr = HAT_MERGING_OK | HAT_PLAT_NOCACHE;
 112         else    /* GFXP_MEMORY_UNCACHED */
 113                 hat_attr = HAT_STRICTORDER | HAT_PLAT_NOCACHE;
 114         hat_flags = HAT_LOAD_LOCK;
 115         pgoffset = start & PAGEOFFSET;
 116         base = start - pgoffset;
 117         npages = btopr(size + pgoffset);
 118         cvaddr = vmem_alloc(heap_arena, ptob(npages), VM_NOSLEEP);
 119         if (cvaddr == NULL)
 120                 return (NULL);
 121 
 122 #ifdef __xpv
 123         ASSERT(DOMAIN_IS_INITDOMAIN(xen_info));
 124         pfn = xen_assign_pfn(mmu_btop(base));


 303  */
 304 void
 305 gfxp_load_kernel_space(uint64_t start, size_t size,
 306     uint32_t mode, caddr_t cvaddr)
 307 {
 308         uint_t pgoffset;
 309         uint64_t base;
 310         pgcnt_t npages;
 311         int hat_flags;
 312         uint_t hat_attr;
 313         pfn_t pfn;
 314 
 315         if (size == 0)
 316                 return;
 317 
 318 #ifdef __xpv
 319         /*
 320          * The hypervisor doesn't allow r/w mappings to some pages, such as
 321          * page tables, gdt, etc. Detect %cr3 to notify users of this interface.
 322          */
 323         if (start == mmu_ptob(mmu_btop(getcr3_pa())))
 324                 return;
 325 #endif
 326 
 327         if (mode == GFXP_MEMORY_CACHED)
 328                 hat_attr = HAT_STORECACHING_OK;
 329         else if (mode == GFXP_MEMORY_WRITECOMBINED)
 330                 hat_attr = HAT_MERGING_OK | HAT_PLAT_NOCACHE;
 331         else    /* GFXP_MEMORY_UNCACHED */
 332                 hat_attr = HAT_STRICTORDER | HAT_PLAT_NOCACHE;
 333         hat_flags = HAT_LOAD_LOCK;
 334 
 335         pgoffset = start & PAGEOFFSET;
 336         base = start - pgoffset;
 337         npages = btopr(size + pgoffset);
 338 
 339 #ifdef __xpv
 340         ASSERT(DOMAIN_IS_INITDOMAIN(xen_info));
 341         pfn = xen_assign_pfn(mmu_btop(base));
 342 #else
 343         pfn = btop(base);