Module Name:    src
Committed By:   martin
Date:           Sat Mar 17 11:23:18 UTC 2018

Modified Files:
        src/sys/arch/amd64/amd64 [netbsd-8]: process_machdep.c
        src/sys/arch/amd64/include [netbsd-8]: cpu.h types.h
        src/sys/arch/x86/x86 [netbsd-8]: vm_machdep.c

Log Message:
Pull up the following revisions, requested by maxv in ticket #637:

        sys/arch/amd64/amd64/process_machdep.c  1.33,1.34,1.35 (patch)
        sys/arch/amd64/include/types.h          1.55 (patch)
        sys/arch/x86/x86/vm_machdep.c           1.33 (patch)

- Reduce the number of places where segment register faults can
  occur.
- Remove __HAVE_CPU_UAREA_ROUTINES.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.32.6.1 src/sys/arch/amd64/amd64/process_machdep.c
cvs rdiff -u -r1.60 -r1.60.40.1 src/sys/arch/amd64/include/cpu.h
cvs rdiff -u -r1.52.6.1 -r1.52.6.2 src/sys/arch/amd64/include/types.h
cvs rdiff -u -r1.28.6.1 -r1.28.6.2 src/sys/arch/x86/x86/vm_machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/amd64/amd64/process_machdep.c
diff -u src/sys/arch/amd64/amd64/process_machdep.c:1.32 src/sys/arch/amd64/amd64/process_machdep.c:1.32.6.1
--- src/sys/arch/amd64/amd64/process_machdep.c:1.32	Thu Feb 23 03:34:22 2017
+++ src/sys/arch/amd64/amd64/process_machdep.c	Sat Mar 17 11:23:18 2018
@@ -1,6 +1,6 @@
-/*	$NetBSD: process_machdep.c,v 1.32 2017/02/23 03:34:22 kamil Exp $	*/
+/*	$NetBSD: process_machdep.c,v 1.32.6.1 2018/03/17 11:23:18 martin Exp $	*/
 
-/*-
+/*
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
@@ -71,13 +71,13 @@
  *
  * process_set_pc(proc)
  *	Set the process's program counter.
- *
  */
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.32 2017/02/23 03:34:22 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: process_machdep.c,v 1.32.6.1 2018/03/17 11:23:18 martin Exp $");
 
+#include "opt_xen.h"
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/time.h>
@@ -93,33 +93,39 @@ __KERNEL_RCSID(0, "$NetBSD: process_mach
 #include <x86/fpu.h>
 
 static inline struct trapframe *process_frame(struct lwp *);
-#if 0
-static inline int verr_gdt(struct pmap *, int sel);
-static inline int verr_ldt(struct pmap *, int sel);
-#endif
 
 static inline struct trapframe *
 process_frame(struct lwp *l)
 {
 
-	return (l->l_md.md_regs);
+	return l->l_md.md_regs;
 }
 
 int
 process_read_regs(struct lwp *l, struct reg *regs)
 {
 	struct trapframe *tf = process_frame(l);
+	struct proc *p = l->l_proc;
+
+	if (p->p_flag & PK_32) {
+		return EINVAL;
+	}
 
 #define copy_to_reg(reg, REG, idx) regs->regs[_REG_##REG] = tf->tf_##reg;
 	_FRAME_GREG(copy_to_reg)
 #undef copy_to_reg
 
-	return (0);
+	return 0;
 }
 
 int
 process_read_fpregs(struct lwp *l, struct fpreg *regs, size_t *sz)
 {
+	struct proc *p = l->l_proc;
+
+	if (p->p_flag & PK_32) {
+		return EINVAL;
+	}
 
 	process_read_fpregs_xmm(l, &regs->fxstate);
 
@@ -129,6 +135,11 @@ process_read_fpregs(struct lwp *l, struc
 int
 process_read_dbregs(struct lwp *l, struct dbreg *regs, size_t *sz)
 {
+	struct proc *p = l->l_proc;
+
+	if (p->p_flag & PK_32) {
+		return EINVAL;
+	}
 
 	x86_dbregs_read(l, regs);
 
@@ -139,8 +150,14 @@ int
 process_write_regs(struct lwp *l, const struct reg *regp)
 {
 	struct trapframe *tf = process_frame(l);
+	struct proc *p = l->l_proc;
 	int error;
 	const long *regs = regp->regs;
+	int err, trapno;
+
+	if (p->p_flag & PK_32) {
+		return EINVAL;
+	}
 
 	/*
 	 * Check for security violations.
@@ -151,16 +168,33 @@ process_write_regs(struct lwp *l, const 
 	if (error != 0)
 		return error;
 
+	err = tf->tf_err;
+	trapno = tf->tf_trapno;
+
 #define copy_to_frame(reg, REG, idx) tf->tf_##reg = regs[_REG_##REG];
 	_FRAME_GREG(copy_to_frame)
 #undef copy_to_frame
 
-	return (0);
+	tf->tf_err = err;
+	tf->tf_trapno = trapno;
+
+#ifdef XEN
+	/* see comment in cpu_setmcontext */
+	tf->tf_ss = GSEL(GUDATA_SEL, SEL_UPL);
+	tf->tf_cs = GSEL(GUCODE_SEL, SEL_UPL);
+#endif
+
+	return 0;
 }
 
 int
 process_write_fpregs(struct lwp *l, const struct fpreg *regs, size_t sz)
 {
+	struct proc *p = l->l_proc;
+
+	if (p->p_flag & PK_32) {
+		return EINVAL;
+	}
 
 	process_write_fpregs_xmm(l, &regs->fxstate);
 	return 0;
@@ -169,8 +203,13 @@ process_write_fpregs(struct lwp *l, cons
 int
 process_write_dbregs(struct lwp *l, const struct dbreg *regs, size_t sz)
 {
+	struct proc *p = l->l_proc;
 	int error;
 
+	if (p->p_flag & PK_32) {
+		return EINVAL;
+	}
+
 	/*
 	 * Check for security violations.
 	 */
@@ -193,17 +232,22 @@ process_sstep(struct lwp *l, int sstep)
 	else
 		tf->tf_rflags &= ~PSL_T;
 	
-	return (0);
+	return 0;
 }
 
 int
 process_set_pc(struct lwp *l, void *addr)
 {
 	struct trapframe *tf = process_frame(l);
+	struct proc *p = l->l_proc;
 
-	if ((uint64_t)addr > VM_MAXUSER_ADDRESS)
+	if (p->p_flag & PK_32) {
+		return EINVAL;
+	}
+
+	if ((uint64_t)addr >= VM_MAXUSER_ADDRESS)
 		return EINVAL;
 	tf->tf_rip = (uint64_t)addr;
 
-	return (0);
+	return 0;
 }

Index: src/sys/arch/amd64/include/cpu.h
diff -u src/sys/arch/amd64/include/cpu.h:1.60 src/sys/arch/amd64/include/cpu.h:1.60.40.1
--- src/sys/arch/amd64/include/cpu.h:1.60	Sat Jan 21 16:48:56 2012
+++ src/sys/arch/amd64/include/cpu.h	Sat Mar 17 11:23:18 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: cpu.h,v 1.60 2012/01/21 16:48:56 chs Exp $	*/
+/*	$NetBSD: cpu.h,v 1.60.40.1 2018/03/17 11:23:18 martin Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -89,9 +89,6 @@ cpu_set_curpri(int pri)
 #define CLKF_INTR(frame)	(curcpu()->ci_idepth > 0)
 #define LWP_PC(l)		((l)->l_md.md_regs->tf_rip)
 
-void	*cpu_uarea_alloc(bool);
-bool	cpu_uarea_free(void *);
-
 #endif	/* _KERNEL */
 
 #else	/*	__x86_64__	*/

Index: src/sys/arch/amd64/include/types.h
diff -u src/sys/arch/amd64/include/types.h:1.52.6.1 src/sys/arch/amd64/include/types.h:1.52.6.2
--- src/sys/arch/amd64/include/types.h:1.52.6.1	Fri Mar 16 13:17:56 2018
+++ src/sys/arch/amd64/include/types.h	Sat Mar 17 11:23:18 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: types.h,v 1.52.6.1 2018/03/16 13:17:56 martin Exp $	*/
+/*	$NetBSD: types.h,v 1.52.6.2 2018/03/17 11:23:18 martin Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -106,7 +106,6 @@ typedef	unsigned char		__cpu_simple_lock
 #define	__HAVE_DIRECT_MAP 1
 #define	__HAVE_MM_MD_DIRECT_MAPPED_IO
 #define	__HAVE_MM_MD_DIRECT_MAPPED_PHYS
-#define	__HAVE_CPU_UAREA_ROUTINES
 #if !defined(NO_PCI_MSI_MSIX)
 #define	__HAVE_PCI_MSI_MSIX
 #endif

Index: src/sys/arch/x86/x86/vm_machdep.c
diff -u src/sys/arch/x86/x86/vm_machdep.c:1.28.6.1 src/sys/arch/x86/x86/vm_machdep.c:1.28.6.2
--- src/sys/arch/x86/x86/vm_machdep.c:1.28.6.1	Mon Jan  1 19:09:04 2018
+++ src/sys/arch/x86/x86/vm_machdep.c	Sat Mar 17 11:23:18 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: vm_machdep.c,v 1.28.6.1 2018/01/01 19:09:04 snj Exp $	*/
+/*	$NetBSD: vm_machdep.c,v 1.28.6.2 2018/03/17 11:23:18 martin Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986 The Regents of the University of California.
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.28.6.1 2018/01/01 19:09:04 snj Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vm_machdep.c,v 1.28.6.2 2018/03/17 11:23:18 martin Exp $");
 
 #include "opt_mtrr.h"
 
@@ -360,58 +360,3 @@ vunmapbuf(struct buf *bp, vsize_t len)
 	bp->b_data = bp->b_saveaddr;
 	bp->b_saveaddr = 0;
 }
-
-#ifdef __HAVE_CPU_UAREA_ROUTINES
-void *
-cpu_uarea_alloc(bool system)
-{
-	struct pglist pglist;
-	int error;
-
-	/*
-	 * Allocate a new physically contiguous uarea which can be
-	 * direct-mapped.
-	 */
-	error = uvm_pglistalloc(USPACE, 0, ptoa(physmem), 0, 0, &pglist, 1, 1);
-	if (error) {
-		return NULL;
-	}
-
-	/*
-	 * Get the physical address from the first page.
-	 */
-	const struct vm_page * const pg = TAILQ_FIRST(&pglist);
-	KASSERT(pg != NULL);
-	const paddr_t pa = VM_PAGE_TO_PHYS(pg);
-
-	/*
-	 * We need to return a direct-mapped VA for the pa.
-	 */
-
-	return (void *)PMAP_MAP_POOLPAGE(pa);
-}
-
-/*
- * Return true if we freed it, false if we didn't.
- */
-bool
-cpu_uarea_free(void *vva)
-{
-	vaddr_t va = (vaddr_t) vva;
-
-	if (va >= VM_MIN_KERNEL_ADDRESS && va < VM_MAX_KERNEL_ADDRESS) {
-		return false;
-	}
-
-	/*
-	 * Since the pages are physically contiguous, the vm_page structures
-	 * will be as well.
-	 */
-	struct vm_page *pg = PHYS_TO_VM_PAGE(PMAP_UNMAP_POOLPAGE(va));
-	KASSERT(pg != NULL);
-	for (size_t i = 0; i < UPAGES; i++, pg++) {
-		uvm_pagefree(pg);
-	}
-	return true;
-}
-#endif /* __HAVE_CPU_UAREA_ROUTINES */

Reply via email to