Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

src: Pullup the following revisions via patch, requested by maxv...



details:   https://anonhg.NetBSD.org/src/rev/b3eb4d2a3ecd
branches:  netbsd-8
changeset: 318161:b3eb4d2a3ecd
user:      martin <martin%NetBSD.org@localhost>
date:      Sat Apr 14 10:11:49 2018 +0000
description:
Pullup the following revisions via patch, requested by maxv in ticket #748:

sys/arch/amd64/amd64/copy.S             1.29 (adapted, via patch)
sys/arch/amd64/amd64/amd64_trap.S       1.16,1.19 (partial) (via patch)
sys/arch/amd64/amd64/trap.c             1.102,1.106 (partial),1.110 (via patch)
sys/arch/amd64/include/frameasm.h       1.22,1.24 (via patch)
sys/arch/x86/x86/cpu.c                  1.137 (via patch)
sys/arch/x86/x86/patch.c                1.23,1.26 (partial) (via patch)

Backport of SMAP support.

diffstat:

 sys/arch/amd64/amd64/amd64_trap.S |   4 +++-
 sys/arch/amd64/amd64/copy.S       |  29 ++++++++++++++++++++++++++++-
 sys/arch/amd64/amd64/trap.c       |  13 +++++++++++--
 sys/arch/amd64/include/frameasm.h |  13 ++++++++++++-
 sys/arch/x86/x86/cpu.c            |  12 +++++++++---
 sys/arch/x86/x86/patch.c          |  25 +++++++++++++++++++++++--
 6 files changed, 86 insertions(+), 10 deletions(-)

diffs (truncated from 381 to 300 lines):

diff -r 63394e19a913 -r b3eb4d2a3ecd sys/arch/amd64/amd64/amd64_trap.S
--- a/sys/arch/amd64/amd64/amd64_trap.S Sat Apr 14 03:13:38 2018 +0000
+++ b/sys/arch/amd64/amd64/amd64_trap.S Sat Apr 14 10:11:49 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: amd64_trap.S,v 1.5.6.2 2018/03/22 16:59:03 martin Exp $        */
+/*     $NetBSD: amd64_trap.S,v 1.5.6.3 2018/04/14 10:11:49 martin Exp $        */
 
 /*
  * Copyright (c) 1998, 2007, 2008, 2017 The NetBSD Foundation, Inc.
@@ -136,6 +136,7 @@
        INTR_SAVE_GPRS
        SVS_ENTER_ALTSTACK
        cld
+       SMAP_ENABLE
        movw    %gs,TF_GS(%rsp)
        movw    %fs,TF_FS(%rsp)
        movw    %es,TF_ES(%rsp)
@@ -236,6 +237,7 @@
        swapgs
 1:
        cld
+       SMAP_ENABLE
        movw    %gs,TF_GS(%rsp)
        movw    %fs,TF_FS(%rsp)
        movw    %es,TF_ES(%rsp)
diff -r 63394e19a913 -r b3eb4d2a3ecd sys/arch/amd64/amd64/copy.S
--- a/sys/arch/amd64/amd64/copy.S       Sat Apr 14 03:13:38 2018 +0000
+++ b/sys/arch/amd64/amd64/copy.S       Sat Apr 14 10:11:49 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: copy.S,v 1.20.10.2 2018/02/26 00:49:48 snj Exp $       */
+/*     $NetBSD: copy.S,v 1.20.10.3 2018/04/14 10:11:49 martin Exp $    */
 
 /*
  * Copyright (c) 2001 Wasabi Systems, Inc.
@@ -187,6 +187,7 @@
        cmpq    %r8,%rdx
        ja      _C_LABEL(copy_efault)   /* jump if end in kernel space */
 
+       SMAP_DISABLE
 .Lcopyout_start:
        movq    %rax,%rcx               /* length */
        shrq    $3,%rcx                 /* count of 8-byte words */
@@ -197,6 +198,7 @@
        rep
        movsb                           /* copy remaining bytes */
 .Lcopyout_end:
+       SMAP_ENABLE
 
        xorl    %eax,%eax
        ret
@@ -215,6 +217,7 @@
        cmpq    %r8,%rdx
        ja      _C_LABEL(copy_efault)   /* j if end in kernel space */
 
+       SMAP_DISABLE
 .Lcopyin_start:
 3:     /* bcopy(%rsi, %rdi, %rax); */
        movq    %rax,%rcx
@@ -226,6 +229,7 @@
        rep
        movsb
 .Lcopyin_end:
+       SMAP_ENABLE
 
        xorl    %eax,%eax
        ret
@@ -242,6 +246,7 @@
 END(kcopy_fault)
 
 NENTRY(copy_fault)
+       SMAP_ENABLE
        ret
 END(copy_fault)
 
@@ -263,6 +268,7 @@
        movq    %rax,%r8
 1:     incq    %rdx
 
+       SMAP_DISABLE
 .Lcopyoutstr_start:
 1:     decq    %rdx
        jz      2f
@@ -271,6 +277,7 @@
        testb   %al,%al
        jnz     1b
 .Lcopyoutstr_end:
+       SMAP_ENABLE
 
        /* Success -- 0 byte reached. */
        decq    %rdx
@@ -278,6 +285,7 @@
        jmp     copystr_return
 
 2:     /* rdx is zero -- return EFAULT or ENAMETOOLONG. */
+       SMAP_ENABLE
        movq    $VM_MAXUSER_ADDRESS,%r11
        cmpq    %r11,%rdi
        jae     _C_LABEL(copystr_efault)
@@ -304,6 +312,7 @@
        movq    %rax,%r8
 1:     incq    %rdx
 
+       SMAP_DISABLE
 .Lcopyinstr_start:
 1:     decq    %rdx
        jz      2f
@@ -312,6 +321,7 @@
        testb   %al,%al
        jnz     1b
 .Lcopyinstr_end:
+       SMAP_ENABLE
 
        /* Success -- 0 byte reached. */
        decq    %rdx
@@ -319,6 +329,7 @@
        jmp     copystr_return
 
 2:     /* rdx is zero -- return EFAULT or ENAMETOOLONG. */
+       SMAP_ENABLE
        movq    $VM_MAXUSER_ADDRESS,%r11
        cmpq    %r11,%rsi
        jae     _C_LABEL(copystr_efault)
@@ -333,6 +344,7 @@
 END(copystr_efault)
 
 ENTRY(copystr_fault)
+       SMAP_ENABLE
 copystr_return:
        /* Set *lencopied and return %eax. */
        testq   %r9,%r9
@@ -382,7 +394,9 @@
        leaq    _C_LABEL(fusuintrfailure)(%rip),%r11
        movq    %r11,PCB_ONFAULT(%rcx)
 
+       SMAP_DISABLE
        movzwl  (%rdi),%eax
+       SMAP_ENABLE
 
        movq    $0,PCB_ONFAULT(%rcx)
        ret
@@ -397,7 +411,9 @@
        leaq    _C_LABEL(fusufailure)(%rip),%r11
        movq    %r11,PCB_ONFAULT(%rcx)
 
+       SMAP_DISABLE
        movzbl  (%rdi),%eax
+       SMAP_ENABLE
 
        movq    $0,PCB_ONFAULT(%rcx)
        ret
@@ -414,7 +430,9 @@
        leaq    _C_LABEL(fusuintrfailure)(%rip),%r11
        movq    %r11,PCB_ONFAULT(%rcx)
 
+       SMAP_DISABLE
        movw    %si,(%rdi)
+       SMAP_ENABLE
 
        xorq    %rax,%rax
        movq    %rax,PCB_ONFAULT(%rcx)
@@ -431,7 +449,9 @@
        leaq    _C_LABEL(fusufailure)(%rip),%r11
        movq    %r11,PCB_ONFAULT(%rcx)
 
+       SMAP_DISABLE
        movb    %sil,(%rdi)
+       SMAP_ENABLE
 
        xorq    %rax,%rax
        movq    %rax,PCB_ONFAULT(%rcx)
@@ -444,12 +464,14 @@
  * because trap.c checks for them.
  */
 ENTRY(fusuintrfailure)
+       SMAP_ENABLE
        movq    $0,PCB_ONFAULT(%rcx)
        movl    $-1,%eax
        ret
 END(fusuintrfailure)
 
 ENTRY(fusufailure)
+       SMAP_ENABLE
        movq    $0,PCB_ONFAULT(%rcx)
        movl    $-1,%eax
        ret
@@ -473,11 +495,13 @@
        ja      _C_LABEL(ucas_efault)
        movq    %rsi,%rax
 
+       SMAP_DISABLE
 .Lucas64_start:
        /* Perform the CAS */
        lock
        cmpxchgq %rdx,(%rdi)
 .Lucas64_end:
+       SMAP_ENABLE
 
        /*
         * Note: %rax is "old" value.
@@ -500,11 +524,13 @@
        ja      _C_LABEL(ucas_efault)
        movl    %esi,%eax
 
+       SMAP_DISABLE
 .Lucas32_start:
        /* Perform the CAS */
        lock
        cmpxchgl %edx,(%rdi)
 .Lucas32_end:
+       SMAP_ENABLE
 
        /*
         * Note: %eax is "old" value.
@@ -522,6 +548,7 @@
 END(ucas_efault)
 
 NENTRY(ucas_fault)
+       SMAP_ENABLE
        ret
 END(ucas_fault)
 
diff -r 63394e19a913 -r b3eb4d2a3ecd sys/arch/amd64/amd64/trap.c
--- a/sys/arch/amd64/amd64/trap.c       Sat Apr 14 03:13:38 2018 +0000
+++ b/sys/arch/amd64/amd64/trap.c       Sat Apr 14 10:11:49 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.96.4.3 2018/04/08 06:14:18 snj Exp $        */
+/*     $NetBSD: trap.c,v 1.96.4.4 2018/04/14 10:11:49 martin Exp $     */
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.96.4.3 2018/04/08 06:14:18 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.96.4.4 2018/04/14 10:11:49 martin Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -502,6 +502,15 @@
                                    (void *)cr2);
                }
 
+               if ((frame->tf_err & PGEX_P) &&
+                   cr2 < VM_MAXUSER_ADDRESS) {
+                       /* SMAP might have brought us here */
+                       if (onfault_handler(pcb, frame) == NULL) {
+                               panic("prevented access to %p (SMAP)",
+                                   (void *)cr2);
+                       }
+               }
+
                goto faultcommon;
 
        case T_PAGEFLT|T_USER: {        /* page fault */
diff -r 63394e19a913 -r b3eb4d2a3ecd sys/arch/amd64/include/frameasm.h
--- a/sys/arch/amd64/include/frameasm.h Sat Apr 14 03:13:38 2018 +0000
+++ b/sys/arch/amd64/include/frameasm.h Sat Apr 14 10:11:49 2018 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: frameasm.h,v 1.20.32.2 2018/03/22 16:59:03 martin Exp $        */
+/*     $NetBSD: frameasm.h,v 1.20.32.3 2018/04/14 10:11:49 martin Exp $        */
 
 #ifndef _AMD64_MACHINE_FRAMEASM_H
 #define _AMD64_MACHINE_FRAMEASM_H
@@ -36,6 +36,8 @@
 #define STI(temp_reg) sti
 #endif /* XEN */
 
+#define HP_NAME_CLAC           1
+#define HP_NAME_STAC           2
 #define HP_NAME_SVS_ENTER      5
 #define HP_NAME_SVS_LEAVE      6
 #define HP_NAME_SVS_ENTER_ALT  7
@@ -49,6 +51,14 @@
        .quad           123b                    ; \
        .popsection
 
+#define SMAP_ENABLE \
+       HOTPATCH(HP_NAME_CLAC, 3)               ; \
+       .byte 0x0F, 0x1F, 0x00                  ; \
+
+#define SMAP_DISABLE \
+       HOTPATCH(HP_NAME_STAC, 3)               ; \
+       .byte 0x0F, 0x1F, 0x00                  ; \
+
 #define        SWAPGS  NOT_XEN(swapgs)
 
 /*
@@ -142,6 +152,7 @@
        subq    $TF_REGSIZE,%rsp        ; \
        INTR_SAVE_GPRS                  ; \
        cld                             ; \
+       SMAP_ENABLE                     ; \
        testb   $SEL_UPL,TF_CS(%rsp)    ; \
        je      98f                     ; \
        SWAPGS                          ; \
diff -r 63394e19a913 -r b3eb4d2a3ecd sys/arch/x86/x86/cpu.c
--- a/sys/arch/x86/x86/cpu.c    Sat Apr 14 03:13:38 2018 +0000
+++ b/sys/arch/x86/x86/cpu.c    Sat Apr 14 10:11:49 2018 +0000
@@ -1,4 +1,4 @@



Home | Main Index | Thread Index | Old Index