Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 21 Jul 2012 13:05:34 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r238668 - head/sys/amd64/amd64
Message-ID:  <201207211305.q6LD5YiC035936@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Sat Jul 21 13:05:34 2012
New Revision: 238668
URL: http://svn.freebsd.org/changeset/base/238668

Log:
  Stop clearing x87 exceptions in the #MF handler on amd64. If user code
  understands FPU hardware enough to catch SIGFPE and unmask exceptions
  in control word, then it may as well properly handle return from
  SIGFPE without causing an infinite loop of #MF exceptions due to
  faulting instruction restart, when needed.
  
  Clearing exceptions causes information loss for handlers which do
  understand FPU hardware, and struct siginfo si_code member cannot be
  considered adequate replacement for en_sw content due to translation.
  
  Supposed reason for clearing the exceptions, which is IRQ13 handling
  oddities, were never applicable to amd64.
  
  Note: this change will be merged to i386 kernel as well, since we do
  not support IRQ13 delivery of #MF notifications for some time.
  
  Requested by:	bde
  MFC after:	1 week

Modified:
  head/sys/amd64/amd64/fpu.c

Modified: head/sys/amd64/amd64/fpu.c
==============================================================================
--- head/sys/amd64/amd64/fpu.c	Sat Jul 21 13:02:11 2012	(r238667)
+++ head/sys/amd64/amd64/fpu.c	Sat Jul 21 13:05:34 2012	(r238668)
@@ -513,25 +513,21 @@ static char fpetable[128] = {
 };
 
 /*
- * Preserve the FP status word, clear FP exceptions for x87, then
- * generate a SIGFPE.
+ * Read the FP status and control words, then generate si_code value
+ * for SIGFPE.  The error code chosen will be one of the
+ * FPE_... macros. It will be sent as the second argument to old
+ * BSD-style signal handlers and as "siginfo_t->si_code" (second
+ * argument) to SA_SIGINFO signal handlers.
  *
- * Clearing exceptions was necessary mainly to avoid IRQ13 bugs and is
- * engraved in our i386 ABI.  We now depend on longjmp() restoring a
- * usable state.  Restoring the state or examining it might fail if we
- * didn't clear exceptions.
+ * Some time ago, we cleared the x87 exceptions with FNCLEX there.
+ * Clearing exceptions was necessary mainly to avoid IRQ13 bugs.  The
+ * usermode code which understands the FPU hardware enough to enable
+ * the exceptions, can also handle clearing the exception state in the
+ * handler. The only consequence of not clearing the exception is the
+ * rethrow of the SIGFPE on return from the signal handler and
+ * reexecution of the corresponding instruction.
  *
- * For SSE exceptions, the exceptions are not cleared.
- *
- * The error code chosen will be one of the FPE_... macros. It will be
- * sent as the second argument to old BSD-style signal handlers and as
- * "siginfo_t->si_code" (second argument) to SA_SIGINFO signal handlers.
- *
- * XXX the FP state is not preserved across signal handlers.  So signal
- * handlers cannot afford to do FP unless they preserve the state or
- * longjmp() out.  Both preserving the state and longjmp()ing may be
- * destroyed by IRQ13 bugs.  Clearing FP exceptions is not an acceptable
- * solution for signals other than SIGFPE.
+ * For XMM traps, the exceptions were never cleared.
  */
 int
 fputrap_x87(void)
@@ -553,7 +549,6 @@ fputrap_x87(void)
 	} else {
 		fnstcw(&control);
 		fnstsw(&status);
-		fnclex();
 	}
 
 	critical_exit();



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