Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 4 Jun 2014 14:42:50 GMT
From:      op@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r269064 - soc2014/op/freebsd-base/sys/amd64/amd64
Message-ID:  <201406041442.s54EgoEr061706@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: op
Date: Wed Jun  4 14:42:50 2014
New Revision: 269064
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=269064

Log:
  SMAP AMD64: added stac and clac to funtions which live in support.S and interacted with user-space
  
  git: https://github.com/opntr/opBSD/tree/op/gsoc2014/smap
  
  Signed-off-by: Oliver Pinter <oliver.pntr@gmail.com>
  

Modified:
  soc2014/op/freebsd-base/sys/amd64/amd64/support.S

Modified: soc2014/op/freebsd-base/sys/amd64/amd64/support.S
==============================================================================
--- soc2014/op/freebsd-base/sys/amd64/amd64/support.S	Wed Jun  4 14:42:13 2014	(r269063)
+++ soc2014/op/freebsd-base/sys/amd64/amd64/support.S	Wed Jun  4 14:42:50 2014	(r269064)
@@ -203,6 +203,9 @@
  * These routines set curpcb->pcb_onfault for the time they execute. When a
  * protection violation occurs inside the functions, the trap handler
  * returns to *curpcb->pcb_onfault instead of the function.
+ *
+ * Warning: when Intel SMAP are enabled on CPU, the EFLAGS.AC bit gets
+ * cleared before reaches the fault handler.
  */
 
 /*
@@ -244,12 +247,16 @@
 
 	shrq	$3,%rcx
 	cld
+	stac					/* open user-space */
 	rep
 	movsq
+	clac					/* close user-space */
 	movb	%dl,%cl
 	andb	$7,%cl
+	stac					/* open user-space */
 	rep
 	movsb
+	clac					/* close user-space */
 
 done_copyout:
 	xorl	%eax,%eax
@@ -259,6 +266,9 @@
 
 	ALIGN_TEXT
 copyout_fault:
+	/*
+	 * WARNING: on fault EFLAGS.AC gets cleared by Intel SMAP if available
+	 */
 	movq	PCPU(CURPCB),%rdx
 	movq	$0,PCB_ONFAULT(%rdx)
 	movq	$EFAULT,%rax
@@ -290,12 +300,16 @@
 	movb	%cl,%al
 	shrq	$3,%rcx				/* copy longword-wise */
 	cld
+	stac					/* open user-space */
 	rep
 	movsq
+	clac					/* close user-space */
 	movb	%al,%cl
 	andb	$7,%cl				/* copy remaining bytes */
+	stac					/* open user-space */
 	rep
 	movsb
+	clac					/* close user-space */
 
 done_copyin:
 	xorl	%eax,%eax
@@ -305,6 +319,9 @@
 
 	ALIGN_TEXT
 copyin_fault:
+	/*
+	 * WARNING: on fault EFLAGS.AC gets cleared by Intel SMAP if available
+	 */
 	movq	PCPU(CURPCB),%rdx
 	movq	$0,PCB_ONFAULT(%rdx)
 	movq	$EFAULT,%rax
@@ -324,10 +341,12 @@
 	ja	fusufault
 
 	movl	%esi,%eax			/* old */
+	stac					/* open user-space */
 #ifdef SMP
 	lock
 #endif
 	cmpxchgl %edx,(%rdi)			/* new = %edx */
+	clac					/* close user-space */
 
 	/*
 	 * The old value is in %eax.  If the store succeeded it will be the
@@ -353,10 +372,12 @@
 	ja	fusufault
 
 	movq	%rsi,%rax			/* old */
+	stac					/* open user-space */
 #ifdef SMP
 	lock
 #endif
 	cmpxchgq %rdx,(%rdi)			/* new = %rdx */
+	clac					/* close user-space */
 
 	/*
 	 * The old value is in %eax.  If the store succeeded it will be the
@@ -385,7 +406,9 @@
 	cmpq	%rax,%rdi			/* verify address is valid */
 	ja	fusufault
 
+	stac					/* open user-space */
 	movq	(%rdi),%rax
+	clac					/* close user-space */
 	movq	$0,PCB_ONFAULT(%rcx)
 	ret
 END(fuword64)
@@ -399,7 +422,9 @@
 	cmpq	%rax,%rdi			/* verify address is valid */
 	ja	fusufault
 
+	stac					/* open user-space */
 	movl	(%rdi),%eax
+	clac					/* close user-space */
 	movq	$0,PCB_ONFAULT(%rcx)
 	ret
 END(fuword32)
@@ -426,7 +451,9 @@
 	cmpq	%rax,%rdi
 	ja	fusufault
 
+	stac					/* open user-space */
 	movzwl	(%rdi),%eax
+	clac					/* close user-space */
 	movq	$0,PCB_ONFAULT(%rcx)
 	ret
 END(fuword16)
@@ -439,13 +466,18 @@
 	cmpq	%rax,%rdi
 	ja	fusufault
 
+	stac					/* open user-space */
 	movzbl	(%rdi),%eax
+	clac					/* close user-space */
 	movq	$0,PCB_ONFAULT(%rcx)
 	ret
 END(fubyte)
 
 	ALIGN_TEXT
 fusufault:
+	/*
+	 * WARNING: on fault EFLAGS.AC gets cleared by Intel SMAP if available
+	 */
 	movq	PCPU(CURPCB),%rcx
 	xorl	%eax,%eax
 	movq	%rax,PCB_ONFAULT(%rcx)
@@ -466,7 +498,9 @@
 	cmpq	%rax,%rdi			/* verify address validity */
 	ja	fusufault
 
+	stac					/* open user-space */
 	movq	%rsi,(%rdi)
+	clac					/* close user-space */
 	xorl	%eax,%eax
 	movq	PCPU(CURPCB),%rcx
 	movq	%rax,PCB_ONFAULT(%rcx)
@@ -482,7 +516,9 @@
 	cmpq	%rax,%rdi			/* verify address validity */
 	ja	fusufault
 
+	stac					/* open user-space */
 	movl	%esi,(%rdi)
+	clac					/* close user-space */
 	xorl	%eax,%eax
 	movq	PCPU(CURPCB),%rcx
 	movq	%rax,PCB_ONFAULT(%rcx)
@@ -497,7 +533,9 @@
 	cmpq	%rax,%rdi			/* verify address validity */
 	ja	fusufault
 
+	stac					/* open user-space */
 	movw	%si,(%rdi)
+	clac					/* close user-space */
 	xorl	%eax,%eax
 	movq	PCPU(CURPCB),%rcx		/* restore trashed register */
 	movq	%rax,PCB_ONFAULT(%rcx)
@@ -513,7 +551,9 @@
 	ja	fusufault
 
 	movl	%esi,%eax
+	stac					/* open user-space */
 	movb	%al,(%rdi)
+	clac					/* close user-space */
 	xorl	%eax,%eax
 	movq	PCPU(CURPCB),%rcx		/* restore trashed register */
 	movq	%rax,PCB_ONFAULT(%rcx)
@@ -555,7 +595,9 @@
 	decq	%rdx
 	jz	3f
 
+	stac					/* open user-space */
 	lodsb
+	clac					/* close user-space */
 	stosb
 	orb	%al,%al
 	jnz	2b
@@ -584,7 +626,9 @@
 	testq	%r9,%r9
 	jz	1f
 	subq	%rdx,%r8
+	stac					/* open user-space */
 	movq	%r8,(%r9)
+	clac					/* close user-space */
 1:
 	ret
 END(copyinstr)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201406041442.s54EgoEr061706>