Module Name:    src
Committed By:   maxv
Date:           Mon Jul  4 07:56:07 UTC 2016

Modified Files:
        src/sys/arch/amd64/amd64: locore.S
        src/sys/arch/i386/i386: locore.S
        src/sys/kern: kern_ras.c

Log Message:
Make the execution flow canonical instead of jumping back and forth, and
complete the userland check.


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/arch/amd64/amd64/locore.S
cvs rdiff -u -r1.132 -r1.133 src/sys/arch/i386/i386/locore.S
cvs rdiff -u -r1.37 -r1.38 src/sys/kern/kern_ras.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/locore.S
diff -u src/sys/arch/amd64/amd64/locore.S:1.103 src/sys/arch/amd64/amd64/locore.S:1.104
--- src/sys/arch/amd64/amd64/locore.S:1.103	Fri Jul  1 13:11:21 2016
+++ src/sys/arch/amd64/amd64/locore.S	Mon Jul  4 07:56:07 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.103 2016/07/01 13:11:21 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.104 2016/07/04 07:56:07 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -1138,13 +1138,21 @@ skip_save:
 	/* Is this process using RAS (restartable atomic sequences)? */
 	movq	L_PROC(%r12),%rdi
 	cmpq	$0,P_RASLIST(%rdi)
-	jne	5f
+	je	no_RAS
+
+	/* Handle restartable atomic sequences (RAS). */
+	movq	L_MD_REGS(%r12),%rbx
+	movq	TF_RIP(%rbx),%rsi
+	call	_C_LABEL(ras_lookup)
+	cmpq	$-1,%rax
+	je	no_RAS
+	movq	%rax,TF_RIP(%rbx)
+no_RAS:
 
 	/*
 	 * Restore cr0 including FPU state (may have CR0_TS set).  Note that
 	 * IPL_SCHED prevents from FPU interrupt altering the LWP's saved cr0.
 	 */
-2:
 #ifndef XEN
 	movl	$IPL_HIGH,CPUVAR(ILEVEL)
 	movl	PCB_CR0(%r14),%ecx	/* has CR0_TS clear */
@@ -1223,15 +1231,6 @@ switch_return:
 	popq	%r12
 	popq	%rbx
 	ret
-
-	/* Check for restartable atomic sequences (RAS). */
-5:	movq	L_MD_REGS(%r12),%rbx
-	movq	TF_RIP(%rbx),%rsi
-	call	_C_LABEL(ras_lookup)
-	cmpq	$-1,%rax
-	je	2b
-	movq	%rax,TF_RIP(%rbx)
-	jmp	2b
 END(cpu_switchto)
 
 /*

Index: src/sys/arch/i386/i386/locore.S
diff -u src/sys/arch/i386/i386/locore.S:1.132 src/sys/arch/i386/i386/locore.S:1.133
--- src/sys/arch/i386/i386/locore.S:1.132	Fri Jul  1 13:11:21 2016
+++ src/sys/arch/i386/i386/locore.S	Mon Jul  4 07:56:07 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: locore.S,v 1.132 2016/07/01 13:11:21 maxv Exp $	*/
+/*	$NetBSD: locore.S,v 1.133 2016/07/04 07:56:07 maxv Exp $	*/
 
 /*
  * Copyright-o-rama!
@@ -128,7 +128,7 @@
  */
 
 #include <machine/asm.h>
-__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.132 2016/07/01 13:11:21 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: locore.S,v 1.133 2016/07/04 07:56:07 maxv Exp $");
 
 #include "opt_compat_oldboot.h"
 #include "opt_copy_symtab.h"
@@ -1191,14 +1191,25 @@ skip_save:
 	/* Is this process using RAS (restartable atomic sequences)? */
 	movl	L_PROC(%edi),%eax
 	cmpl	$0,P_RASLIST(%eax)
-	jne	5f
+	je	no_RAS
+
+	/* Handle restartable atomic sequences (RAS). */
+	movl	L_MD_REGS(%edi),%ecx
+	pushl	TF_EIP(%ecx)
+	pushl	%eax
+	call	_C_LABEL(ras_lookup)
+	addl	$8,%esp
+	cmpl	$-1,%eax
+	je	no_RAS
+	movl	L_MD_REGS(%edi),%ecx
+	movl	%eax,TF_EIP(%ecx)
+no_RAS:
 
 	/*
 	 * Restore cr0 (including FPU state).  Raise the IPL to IPL_HIGH.
 	 * FPU IPIs can alter the LWP's saved cr0.  Dropping the priority
 	 * is deferred until mi_switch(), when cpu_switchto() returns.
 	 */
-2:
 #ifdef XEN
 	pushl	%edi
 	call	_C_LABEL(i386_tls_switch)
@@ -1231,18 +1242,6 @@ switch_return:
 	popl	%ebx
 	ret
 
-	/* Check for restartable atomic sequences (RAS). */
-5:	movl	L_MD_REGS(%edi),%ecx
-	pushl	TF_EIP(%ecx)
-	pushl	%eax
-	call	_C_LABEL(ras_lookup)
-	addl	$8,%esp
-	cmpl	$-1,%eax
-	je	2b
-	movl	L_MD_REGS(%edi),%ecx
-	movl	%eax,TF_EIP(%ecx)
-	jmp	2b
-
 .Lcopy_iobitmap:
 	/* Copy I/O bitmap. */
 	incl	_C_LABEL(pmap_iobmp_evcnt)+EV_COUNT

Index: src/sys/kern/kern_ras.c
diff -u src/sys/kern/kern_ras.c:1.37 src/sys/kern/kern_ras.c:1.38
--- src/sys/kern/kern_ras.c:1.37	Fri Jul  1 12:49:22 2016
+++ src/sys/kern/kern_ras.c	Mon Jul  4 07:56:07 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: kern_ras.c,v 1.37 2016/07/01 12:49:22 maxv Exp $	*/
+/*	$NetBSD: kern_ras.c,v 1.38 2016/07/04 07:56:07 maxv Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_ras.c,v 1.37 2016/07/01 12:49:22 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ras.c,v 1.38 2016/07/04 07:56:07 maxv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -206,6 +206,8 @@ ras_install(void *addr, size_t len)
 	__WARNING_PUSH_LESS_NULL_PTR
 	if (addr < (void *)VM_MIN_ADDRESS || addr > (void *)VM_MAXUSER_ADDRESS)
 		return EINVAL;
+	if (endaddr > (void *)VM_MAXUSER_ADDRESS)
+		return EINVAL;
 	if (endaddr < addr)
 		return EINVAL;
 	__WARNING_POP_LESS_NULL_PTR

Reply via email to