Source-Changes-HG archive

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

[src/netbsd-6-0]: src/sys/arch Pull up following revision(s) (requested by ma...



details:   https://anonhg.NetBSD.org/src/rev/d3e6a29b09f6
branches:  netbsd-6-0
changeset: 775217:d3e6a29b09f6
user:      martin <martin%NetBSD.org@localhost>
date:      Tue Aug 08 11:55:20 2017 +0000

description:
Pull up following revision(s) (requested by maxv in ticket #1464):

        sys/arch/i386/i386/trap.c:     revision 1.288           (patch)
        sys/arch/i386/i386/machdep.c:  revision 1.783           (patch)
        sys/arch/i386/i386/locore.S:   revision 1.146           (patch)
        sys/arch/amd64/amd64/locore.S: revision 1.122,1.124     (patch)
        sys/arch/amd64/amd64/machdep.c revision 1.254           (patch)
        sys/arch/amd64/amd64/trap.c:   revision 1.95-1.96       (patch)

Remove the osyscall call gate and emulate it. There is a
one-instruction race in it that could panic the kernel.

Restore the ability to run netbsd 1.0 32-bit executables by checking
for the relevant lcall instruction in the trap handler and treating it
as a syscall.

diffstat:

 sys/arch/amd64/amd64/locore.S  |  23 +----------------------
 sys/arch/amd64/amd64/machdep.c |  20 +++-----------------
 sys/arch/amd64/amd64/trap.c    |  36 +++++++++++++++++++++++++++++++-----
 sys/arch/i386/i386/locore.S    |  22 ++--------------------
 sys/arch/i386/i386/machdep.c   |   9 ++-------
 sys/arch/i386/i386/trap.c      |  34 +++++++++++++++++++++++-----------
 6 files changed, 62 insertions(+), 82 deletions(-)

diffs (truncated from 340 to 300 lines):

diff -r 0e2cc0f45de2 -r d3e6a29b09f6 sys/arch/amd64/amd64/locore.S
--- a/sys/arch/amd64/amd64/locore.S     Fri Jul 21 05:04:08 2017 +0000
+++ b/sys/arch/amd64/amd64/locore.S     Tue Aug 08 11:55:20 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.66.2.1 2012/04/20 23:32:14 riz Exp $      */
+/*     $NetBSD: locore.S,v 1.66.2.1.4.1 2017/08/08 11:55:20 martin Exp $       */
 
 /*
  * Copyright-o-rama!
@@ -1209,26 +1209,6 @@
        .globl  _C_LABEL(osyscall_return)
 
 /*
- * oosyscall()
- *
- * Old call gate entry for syscall. only needed if we're
- * going to support running old i386 NetBSD 1.0 or ibcs2 binaries, etc,
- * on NetBSD/amd64.
- * The 64bit call gate can't request that arguments be copied from the
- * user stack (which the i386 code uses to get a gap for the flags).
- * push/pop are <read>:<modify_sp>:<write> cycles.
- */
-IDTVEC(oosyscall)
-       /* Set rflags in trap frame. */
-       pushq   (%rsp)          # move user's %eip
-       pushq   16(%rsp)        # and %cs
-       popq    8(%rsp)
-       pushfq
-       popq    16(%rsp)
-       pushq   $7              # size of instruction for restart
-       jmp     osyscall1
-
-/*
  * osyscall()
  *
  * Trap gate entry for int $80 syscall, also used by sigreturn.
@@ -1240,7 +1220,6 @@
        addq $0x10,%rsp
 #endif
        pushq   $2              # size of instruction for restart
-osyscall1:
        pushq   $T_ASTFLT       # trap # for doing ASTs
        INTRENTRY
        STI(si)
diff -r 0e2cc0f45de2 -r d3e6a29b09f6 sys/arch/amd64/amd64/machdep.c
--- a/sys/arch/amd64/amd64/machdep.c    Fri Jul 21 05:04:08 2017 +0000
+++ b/sys/arch/amd64/amd64/machdep.c    Tue Aug 08 11:55:20 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.175.2.7.2.1 2013/04/20 10:00:58 bouyer Exp $     */
+/*     $NetBSD: machdep.c,v 1.175.2.7.2.2 2017/08/08 11:55:20 martin Exp $     */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2006, 2007, 2008, 2011
@@ -111,7 +111,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.175.2.7.2.1 2013/04/20 10:00:58 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.175.2.7.2.2 2017/08/08 11:55:20 martin Exp $");
 
 /* #define XENDEBUG_LOW  */
 
@@ -1575,7 +1575,6 @@
 extern vector IDTVEC(syscall);
 extern vector IDTVEC(syscall32);
 extern vector IDTVEC(osyscall);
-extern vector IDTVEC(oosyscall);
 extern vector *IDTVEC(exceptions)[];
 
 static void
@@ -1838,10 +1837,7 @@
        set_mem_segment(GDT_ADDR_MEM(gdtstore, GUDATA_SEL), 0,
            x86_btop(VM_MAXUSER_ADDRESS) - 1, SDT_MEMRWA, SEL_UPL, 1, 0, 1);
 
-       /* make ldt gates and memory segments */
-       setgate((struct gate_descriptor *)(ldtstore + LSYS5CALLS_SEL),
-           &IDTVEC(oosyscall), 0, SDT_SYS386CGT, SEL_UPL,
-           GSEL(GCODE_SEL, SEL_KPL));
+       /* make ldt memory segments */
        *(struct mem_segment_descriptor *)(ldtstore + LUCODE_SEL) =
            *GDT_ADDR_MEM(gdtstore, GUCODE_SEL);
        *(struct mem_segment_descriptor *)(ldtstore + LUDATA_SEL) =
@@ -1873,16 +1869,6 @@
        set_mem_segment(ldt_segp, 0, x86_btop(VM_MAXUSER_ADDRESS32) - 1,
            SDT_MEMRWA, SEL_UPL, 1, 1, 0);
 
-       /*
-        * Other entries.
-        */
-       memcpy((struct gate_descriptor *)(ldtstore + LSOL26CALLS_SEL),
-           (struct gate_descriptor *)(ldtstore + LSYS5CALLS_SEL),
-           sizeof (struct gate_descriptor));
-       memcpy((struct gate_descriptor *)(ldtstore + LBSDICALLS_SEL),
-           (struct gate_descriptor *)(ldtstore + LSYS5CALLS_SEL),
-           sizeof (struct gate_descriptor));
-
        /* exceptions */
        for (x = 0; x < 32; x++) {
 #ifndef XEN
diff -r 0e2cc0f45de2 -r d3e6a29b09f6 sys/arch/amd64/amd64/trap.c
--- a/sys/arch/amd64/amd64/trap.c       Fri Jul 21 05:04:08 2017 +0000
+++ b/sys/arch/amd64/amd64/trap.c       Tue Aug 08 11:55:20 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.69.2.1.4.1 2017/03/25 17:20:07 snj Exp $    */
+/*     $NetBSD: trap.c,v 1.69.2.1.4.2 2017/08/08 11:55:20 martin Exp $ */
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -68,12 +68,14 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.69.2.1.4.1 2017/03/25 17:20:07 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.69.2.1.4.2 2017/08/08 11:55:20 martin Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
 #include "opt_xen.h"
 #include "opt_dtrace.h"
+#include "opt_compat_netbsd.h"
+#include "opt_compat_netbsd32.h"
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -92,6 +94,11 @@
 
 #include <uvm/uvm_extern.h>
 
+#ifdef COMPAT_NETBSD32
+#include <sys/exec.h>
+#include <compat/netbsd32/netbsd32_exec.h>
+#endif
+
 #include <machine/cpufunc.h>
 #include <machine/fpu.h>
 #include <machine/psl.h>
@@ -202,7 +209,6 @@
        struct proc *p;
        struct pcb *pcb;
        extern char fusuintrfailure[], kcopy_fault[];
-       extern char IDTVEC(oosyscall)[];
        extern char IDTVEC(osyscall)[];
        extern char IDTVEC(syscall32)[];
 #ifndef XEN
@@ -383,6 +389,27 @@
 #endif
 
        case T_PROTFLT|T_USER:          /* protection fault */
+#if defined(COMPAT_NETBSD32) && defined(COMPAT_10)
+       {
+               static const char lcall[7] = { 0x9a, 0, 0, 0, 0, 7, 0 };
+               const size_t sz = sizeof(lcall);
+               char tmp[sz];
+
+               /* Check for the oosyscall lcall instruction. */
+               if (p->p_emul == &emul_netbsd32 &&
+                   frame->tf_rip < VM_MAXUSER_ADDRESS32 - sz &&
+                   copyin((void *)frame->tf_rip, tmp, sz) == 0 &&
+                   memcmp(tmp, lcall, sz) == 0) {
+
+                       /* Advance past the lcall. */
+                       frame->tf_rip += sz;
+
+                       /* Do the syscall. */
+                       p->p_md.md_syscall(frame);
+                       goto out;
+               }
+       }
+#endif
        case T_TSSFLT|T_USER:
        case T_SEGNPFLT|T_USER:
        case T_STKFLT|T_USER:
@@ -661,8 +688,7 @@
 
        case T_TRCTRAP:
                /* Check whether they single-stepped into a lcall. */
-               if (frame->tf_rip == (uint64_t)IDTVEC(oosyscall) ||
-                   frame->tf_rip == (uint64_t)IDTVEC(osyscall) ||
+               if (frame->tf_rip == (uint64_t)IDTVEC(osyscall) ||
                    frame->tf_rip == (uint64_t)IDTVEC(syscall32)) {
                        frame->tf_rflags &= ~PSL_T;
                        return;
diff -r 0e2cc0f45de2 -r d3e6a29b09f6 sys/arch/i386/i386/locore.S
--- a/sys/arch/i386/i386/locore.S       Fri Jul 21 05:04:08 2017 +0000
+++ b/sys/arch/i386/i386/locore.S       Tue Aug 08 11:55:20 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: locore.S,v 1.95.10.2 2012/04/20 23:32:14 riz Exp $     */
+/*     $NetBSD: locore.S,v 1.95.10.2.4.1 2017/08/08 11:55:20 martin Exp $      */
 
 /*
  * Copyright-o-rama!
@@ -129,7 +129,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.95.10.2 2012/04/20 23:32:14 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.95.10.2.4.1 2017/08/08 11:55:20 martin Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_ddb.h"
@@ -1112,30 +1112,12 @@
 END(savectx)
 
 /*
- * osyscall()
- *
- * Old call gate entry for syscall
- */
-IDTVEC(osyscall)
-#ifndef XEN
-       /* XXX we are in trouble! interrupts be off here. */
-       cli                     # must be first instruction
-#endif
-       pushfl                  # set eflags in trap frame
-       popl    8(%esp)
-       orl     $PSL_I,(%esp)   # re-enable ints on return to user
-       pushl   $7              # size of instruction for restart
-       jmp     syscall1
-IDTVEC_END(osyscall)
-
-/*
  * syscall()
  *
  * Trap gate entry for syscall
  */
 IDTVEC(syscall)
        pushl   $2              # size of instruction for restart
-syscall1:
        pushl   $T_ASTFLT       # trap # for doing ASTs
        INTRENTRY
        STI(%eax)
diff -r 0e2cc0f45de2 -r d3e6a29b09f6 sys/arch/i386/i386/machdep.c
--- a/sys/arch/i386/i386/machdep.c      Fri Jul 21 05:04:08 2017 +0000
+++ b/sys/arch/i386/i386/machdep.c      Tue Aug 08 11:55:20 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.717.2.7 2012/05/21 15:25:58 riz Exp $    */
+/*     $NetBSD: machdep.c,v 1.717.2.7.4.1 2017/08/08 11:55:20 martin Exp $     */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.717.2.7 2012/05/21 15:25:58 riz Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.717.2.7.4.1 2017/08/08 11:55:20 martin Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -1121,7 +1121,6 @@
 #define        IDTVEC(name)    __CONCAT(X, name)
 typedef void (vector)(void);
 extern vector IDTVEC(syscall);
-extern vector IDTVEC(osyscall);
 extern vector *IDTVEC(exceptions)[];
 extern vector IDTVEC(svr4_fasttrap);
 void (*svr4_fasttrap_vec)(void) = (void (*)(void))nullop;
@@ -1525,13 +1524,9 @@
 #endif /* XEN */
 
        /* make ldt gates and memory segments */
-       setgate(&ldt[LSYS5CALLS_SEL].gd, &IDTVEC(osyscall), 1,
-           SDT_SYS386CGT, SEL_UPL, GSEL(GCODE_SEL, SEL_KPL));
-
        ldt[LUCODE_SEL] = gdt[GUCODE_SEL];
        ldt[LUCODEBIG_SEL] = gdt[GUCODEBIG_SEL];
        ldt[LUDATA_SEL] = gdt[GUDATA_SEL];
-       ldt[LSOL26CALLS_SEL] = ldt[LBSDICALLS_SEL] = ldt[LSYS5CALLS_SEL];
 
 #ifndef XEN
        /* exceptions */
diff -r 0e2cc0f45de2 -r d3e6a29b09f6 sys/arch/i386/i386/trap.c
--- a/sys/arch/i386/i386/trap.c Fri Jul 21 05:04:08 2017 +0000
+++ b/sys/arch/i386/i386/trap.c Tue Aug 08 11:55:20 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: trap.c,v 1.262.12.1 2017/03/25 17:20:07 snj Exp $      */
+/*     $NetBSD: trap.c,v 1.262.12.2 2017/08/08 11:55:20 martin Exp $   */
 
 /*-
  * Copyright (c) 1998, 2000, 2005, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.262.12.1 2017/03/25 17:20:07 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: trap.c,v 1.262.12.2 2017/08/08 11:55:20 martin Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -308,8 +308,7 @@
        struct lwp *l = curlwp;
        struct proc *p;
        struct pcb *pcb;
-       extern char fusubail[], kcopy_fault[], return_address_fault[],
-           IDTVEC(osyscall)[];
+       extern char fusubail[], kcopy_fault[], return_address_fault[];
        struct trapframe *vframe;
        ksiginfo_t ksi;
        void *onfault;
@@ -495,6 +494,26 @@



Home | Main Index | Thread Index | Old Index