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


   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 (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 /*
  26  * Copyright (c) 2016, Joyent, Inc. All rights reserved.
  27  */
  28 
  29 /*      Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
  30 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T       */
  31 /*        All Rights Reserved                                   */
  32 
  33 /*      Copyright (c) 1987, 1988 Microsoft Corporation          */
  34 /*        All Rights Reserved                                   */
  35 
  36 
  37 #include <sys/asm_linkage.h>
  38 #include <sys/asm_misc.h>
  39 #include <sys/regset.h>
  40 #include <sys/privregs.h>
  41 #include <sys/psw.h>
  42 #include <sys/reboot.h>
  43 #include <sys/x86_archext.h>
  44 #include <sys/machparam.h>
  45 
  46 #if defined(__lint)


1169          * If we've taken a GPF, we don't (unfortunately) have the address that
1170          * induced the fault.  So instead of setting the fault to BADADDR,
1171          * we'll set the fault to ILLOP.
1172          */
1173 0:
1174         orw     $CPU_DTRACE_ILLOP, %cx
1175         movw    %cx, CPUC_DTRACE_FLAGS(%rax)
1176         jmp     2f
1177 1:
1178         orw     $CPU_DTRACE_BADADDR, %cx
1179         movw    %cx, CPUC_DTRACE_FLAGS(%rax)    /* set fault to bad addr */
1180         movq    %r15, CPUC_DTRACE_ILLVAL(%rax)
1181                                             /* fault addr is illegal value */
1182 2:
1183         movq    REGOFF_RIP(%rbp), %rdi
1184         movq    %rdi, %r12
1185         call    dtrace_instr_size
1186         addq    %rax, %r12
1187         movq    %r12, REGOFF_RIP(%rbp)
1188         INTR_POP
1189         IRET
1190         /*NOTREACHED*/
1191 3:
1192         leaq    dtrace_badflags(%rip), %rdi
1193         xorl    %eax, %eax
1194         call    panic
1195 4:
1196         leaq    dtrace_badtrap(%rip), %rdi
1197         xorl    %eax, %eax
1198         call    panic
1199         SET_SIZE(cmntrap)
1200         SET_SIZE(_cmntrap)
1201 
1202 #elif defined(__i386)
1203 
1204 
1205         ENTRY_NP2(cmntrap, _cmntrap)
1206 
1207         INTR_PUSH
1208 
1209         ALTENTRY(cmntrap_pushed)


1582         ALTENTRY(_sys_rtt)
1583         CLI(%rax)                       /* disable interrupts */
1584         ALTENTRY(_sys_rtt_ints_disabled)
1585         movq    %rsp, %rdi              /* pass rp to sys_rtt_common */
1586         call    sys_rtt_common          /* do common sys_rtt tasks */
1587         testq   %rax, %rax              /* returning to userland? */
1588         jz      sr_sup
1589 
1590         /*
1591          * Return to user
1592          */
1593         ASSERT_UPCALL_MASK_IS_SET
1594         cmpw    $UCS_SEL, REGOFF_CS(%rsp) /* test for native (64-bit) lwp? */
1595         je      sys_rtt_syscall
1596 
1597         /*
1598          * Return to 32-bit userland
1599          */
1600         ALTENTRY(sys_rtt_syscall32)
1601         USER32_POP
1602         IRET
1603         /*NOTREACHED*/
1604 
1605         ALTENTRY(sys_rtt_syscall)
1606         /*
1607          * Return to 64-bit userland
1608          */
1609         USER_POP
1610         ALTENTRY(nopop_sys_rtt_syscall)
1611         IRET
1612         /*NOTREACHED*/
1613         SET_SIZE(nopop_sys_rtt_syscall)
1614 
1615         /*
1616          * Return to supervisor
1617          * NOTE: to make the check in trap() that tests if we are executing
1618          * segment register fixup/restore code work properly, sr_sup MUST be
1619          * after _sys_rtt .
1620          */
1621         ALTENTRY(sr_sup)
1622         /*
1623          * Restore regs before doing iretq to kernel mode
1624          */
1625         INTR_POP
1626         IRET
1627         .globl  _sys_rtt_end
1628 _sys_rtt_end:
1629         /*NOTREACHED*/
1630         SET_SIZE(sr_sup)
1631         SET_SIZE(_sys_rtt_end)
1632         SET_SIZE(lwp_rtt)
1633         SET_SIZE(lwp_rtt_initial)
1634         SET_SIZE(_sys_rtt_ints_disabled)
1635         SET_SIZE(_sys_rtt)
1636         SET_SIZE(sys_rtt_syscall)
1637         SET_SIZE(sys_rtt_syscall32)
1638 
1639 #elif defined(__i386)
1640 
1641         ENTRY_NP(lwp_rtt_initial)
1642         movl    %gs:CPU_THREAD, %eax
1643         movl    T_STACK(%eax), %esp     /* switch to the thread stack */
1644         movl    %esp, %ebp
1645         call    __dtrace_probe___proc_start
1646         jmp     _lwp_rtt




   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 (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
  24  */
  25 /*
  26  * Copyright (c) 2018 Joyent, Inc.
  27  */
  28 
  29 /*      Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. */
  30 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989, 1990 AT&T       */
  31 /*        All Rights Reserved                                   */
  32 
  33 /*      Copyright (c) 1987, 1988 Microsoft Corporation          */
  34 /*        All Rights Reserved                                   */
  35 
  36 
  37 #include <sys/asm_linkage.h>
  38 #include <sys/asm_misc.h>
  39 #include <sys/regset.h>
  40 #include <sys/privregs.h>
  41 #include <sys/psw.h>
  42 #include <sys/reboot.h>
  43 #include <sys/x86_archext.h>
  44 #include <sys/machparam.h>
  45 
  46 #if defined(__lint)


1169          * If we've taken a GPF, we don't (unfortunately) have the address that
1170          * induced the fault.  So instead of setting the fault to BADADDR,
1171          * we'll set the fault to ILLOP.
1172          */
1173 0:
1174         orw     $CPU_DTRACE_ILLOP, %cx
1175         movw    %cx, CPUC_DTRACE_FLAGS(%rax)
1176         jmp     2f
1177 1:
1178         orw     $CPU_DTRACE_BADADDR, %cx
1179         movw    %cx, CPUC_DTRACE_FLAGS(%rax)    /* set fault to bad addr */
1180         movq    %r15, CPUC_DTRACE_ILLVAL(%rax)
1181                                             /* fault addr is illegal value */
1182 2:
1183         movq    REGOFF_RIP(%rbp), %rdi
1184         movq    %rdi, %r12
1185         call    dtrace_instr_size
1186         addq    %rax, %r12
1187         movq    %r12, REGOFF_RIP(%rbp)
1188         INTR_POP
1189         jmp     tr_iret_auto
1190         /*NOTREACHED*/
1191 3:
1192         leaq    dtrace_badflags(%rip), %rdi
1193         xorl    %eax, %eax
1194         call    panic
1195 4:
1196         leaq    dtrace_badtrap(%rip), %rdi
1197         xorl    %eax, %eax
1198         call    panic
1199         SET_SIZE(cmntrap)
1200         SET_SIZE(_cmntrap)
1201 
1202 #elif defined(__i386)
1203 
1204 
1205         ENTRY_NP2(cmntrap, _cmntrap)
1206 
1207         INTR_PUSH
1208 
1209         ALTENTRY(cmntrap_pushed)


1582         ALTENTRY(_sys_rtt)
1583         CLI(%rax)                       /* disable interrupts */
1584         ALTENTRY(_sys_rtt_ints_disabled)
1585         movq    %rsp, %rdi              /* pass rp to sys_rtt_common */
1586         call    sys_rtt_common          /* do common sys_rtt tasks */
1587         testq   %rax, %rax              /* returning to userland? */
1588         jz      sr_sup
1589 
1590         /*
1591          * Return to user
1592          */
1593         ASSERT_UPCALL_MASK_IS_SET
1594         cmpw    $UCS_SEL, REGOFF_CS(%rsp) /* test for native (64-bit) lwp? */
1595         je      sys_rtt_syscall
1596 
1597         /*
1598          * Return to 32-bit userland
1599          */
1600         ALTENTRY(sys_rtt_syscall32)
1601         USER32_POP
1602         jmp     tr_iret_user
1603         /*NOTREACHED*/
1604 
1605         ALTENTRY(sys_rtt_syscall)
1606         /*
1607          * Return to 64-bit userland
1608          */
1609         USER_POP
1610         ALTENTRY(nopop_sys_rtt_syscall)
1611         jmp     tr_iret_user
1612         /*NOTREACHED*/
1613         SET_SIZE(nopop_sys_rtt_syscall)
1614 
1615         /*
1616          * Return to supervisor
1617          * NOTE: to make the check in trap() that tests if we are executing
1618          * segment register fixup/restore code work properly, sr_sup MUST be
1619          * after _sys_rtt .
1620          */
1621         ALTENTRY(sr_sup)
1622         /*
1623          * Restore regs before doing iretq to kernel mode
1624          */
1625         INTR_POP
1626         jmp     tr_iret_kernel
1627         .globl  _sys_rtt_end
1628 _sys_rtt_end:
1629         /*NOTREACHED*/
1630         SET_SIZE(sr_sup)
1631         SET_SIZE(_sys_rtt_end)
1632         SET_SIZE(lwp_rtt)
1633         SET_SIZE(lwp_rtt_initial)
1634         SET_SIZE(_sys_rtt_ints_disabled)
1635         SET_SIZE(_sys_rtt)
1636         SET_SIZE(sys_rtt_syscall)
1637         SET_SIZE(sys_rtt_syscall32)
1638 
1639 #elif defined(__i386)
1640 
1641         ENTRY_NP(lwp_rtt_initial)
1642         movl    %gs:CPU_THREAD, %eax
1643         movl    T_STACK(%eax), %esp     /* switch to the thread stack */
1644         movl    %esp, %ebp
1645         call    __dtrace_probe___proc_start
1646         jmp     _lwp_rtt