Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Jun 2014 00:40:48 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r267083 - stable/10/sys/amd64/amd64
Message-ID:  <201406050040.s550empA014274@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Thu Jun  5 00:40:48 2014
New Revision: 267083
URL: http://svnweb.freebsd.org/changeset/base/267083

Log:
  MFC r266846:
  When usermode loaded non-default segment selector into the %gs,
  correctly prepare KGSBASE msr to restore the user descriptor base on
  the last swapgs during return to usermode.

Modified:
  stable/10/sys/amd64/amd64/exception.S
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/amd64/amd64/exception.S
==============================================================================
--- stable/10/sys/amd64/amd64/exception.S	Thu Jun  5 00:38:32 2014	(r267082)
+++ stable/10/sys/amd64/amd64/exception.S	Thu Jun  5 00:40:48 2014	(r267083)
@@ -722,21 +722,38 @@ ld_fsbase:
 	pushfq
 	cli
 	movl	$MSR_GSBASE,%ecx
+	/* Save current kernel %gs base into %r12d:%r13d */
 	rdmsr
+	movl	%eax,%r12d
+	movl	%edx,%r13d
 	.globl	ld_gs
 ld_gs:
 	movw	%si,%gs
+	/* Save user %gs base into %r14d:%r15d */
+	rdmsr
+	movl	%eax,%r14d
+	movl	%edx,%r15d
+	/* Restore kernel %gs base */
+	movl	%r12d,%eax
+	movl	%r13d,%edx
 	wrmsr
 	popfq
+	/*
+	 * Restore user %gs base, either from PCB if used for TLS, or
+	 * from the previously saved msr read.
+	 */
+	movl	$MSR_KGSBASE,%ecx
 	cmpw	$KUG32SEL,%si
 	jne	1f
-	movl	$MSR_KGSBASE,%ecx
 	movl	PCB_GSBASE(%r8),%eax
 	movl	PCB_GSBASE+4(%r8),%edx
+	jmp	ld_gsbase
+1:
+	movl	%r14d,%eax
+	movl	%r15d,%edx
 	.globl	ld_gsbase
 ld_gsbase:
-	wrmsr
-1:
+	wrmsr	/* May trap if non-canonical, but only for TLS. */
 	.globl	ld_es
 ld_es:
 	movw	TF_ES(%rsp),%es



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