reset_segs() is overly complicated: we pass it the pcb address and new 
value of the fsbase, but all it does with those is set a field in the 
former with the latter.  It's simpler to just do the assignment in the 
(two) callers.

(If someone came up with use for making GS.base setable by userspace, that 
code path would need to call reset_segs() without changing FS.base.)

ok?

Philip Guenther


Index: amd64/machdep.c
===================================================================
RCS file: /data/src/openbsd/src/sys/arch/amd64/amd64/machdep.c,v
retrieving revision 1.217
diff -u -p -r1.217 machdep.c
--- amd64/machdep.c     21 Oct 2015 07:59:17 -0000      1.217
+++ amd64/machdep.c     3 Apr 2016 02:26:04 -0000
@@ -1003,10 +1003,12 @@ dumpsys(void)
 }
 
 /*
- * Set FS.base for userspace and reset %ds, %es, and %fs segment registers
+ * Force the userspace FS.base to be reloaded from the PCB on return from
+ * the kernel, and reset most the segment registers (%ds, %es, and %fs)
+ * to their expected userspace value.
  */
 void
-reset_segs(struct pcb *pcb, u_int64_t fsbase)
+reset_segs(void)
 {
        /*
         * Segment registers (%ds, %es, %fs, %gs) aren't in the trapframe.
@@ -1022,7 +1024,6 @@ reset_segs(struct pcb *pcb, u_int64_t fs
                    "movw %%ax,%%es\n\t"
                    "movw %%ax,%%fs" : : "a"(GSEL(GUDATA_SEL, SEL_UPL)));
        }
-       pcb->pcb_fsbase = fsbase;
 }
 
 /*
@@ -1040,7 +1041,8 @@ setregs(struct proc *p, struct exec_pack
        p->p_md.md_flags &= ~MDP_USEDFPU;
        p->p_md.md_flags |= MDP_IRET;
 
-       reset_segs(&p->p_addr->u_pcb, 0);
+       reset_segs();
+       p->p_addr->u_pcb.pcb_fsbase = 0;
 
        tf = p->p_md.md_regs;
        tf->tf_rdi = 0;
Index: amd64/vm_machdep.c
===================================================================
RCS file: /data/src/openbsd/src/sys/arch/amd64/amd64/vm_machdep.c,v
retrieving revision 1.33
diff -u -p -r1.33 vm_machdep.c
--- amd64/vm_machdep.c  28 Jun 2015 18:54:54 -0000      1.33
+++ amd64/vm_machdep.c  3 Apr 2016 02:23:24 -0000
@@ -231,5 +231,6 @@ void
 tcb_set(struct proc *p, void *tcb)
 {
        KASSERT(p == curproc);
-       reset_segs(&p->p_addr->u_pcb, (u_int64_t)tcb);
+       reset_segs();
+       p->p_addr->u_pcb.pcb_fsbase = (u_int64_t)tcb;
 }
Index: include/pcb.h
===================================================================
RCS file: /data/src/openbsd/src/sys/arch/amd64/include/pcb.h,v
retrieving revision 1.14
diff -u -p -r1.14 pcb.h
--- include/pcb.h       18 May 2015 19:59:27 -0000      1.14
+++ include/pcb.h       3 Apr 2016 02:07:56 -0000
@@ -90,7 +90,7 @@ struct pcb {
 };
 
 #ifdef _KERNEL
-void   reset_segs(struct pcb *_pcb, u_int64_t _fsbase);
+void   reset_segs(void);
 #endif
 
 #endif /* _MACHINE_PCB_H_ */

Reply via email to