From: Daniel Jacobowitz <dan@debian.org>
To: linux-mips@linux-mips.org
Subject: ptrace and floating point related kernel crash
Date: Sat, 2 Apr 2005 17:23:53 -0500 [thread overview]
Message-ID: <20050402222353.GA18450@nevyn.them.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 1086 bytes --]
Here's a nasty little bug I encountered while debugging some related
problems in GDB.
Compile and run the attached program; I'm not sure if it will demonstrate
the problem on anything with hardware FPU, but at least it works on an SB-1
(using a 32-bit kernel). The program itself runs fine. Debug it with GDB,
and set a breakpoint on the ctc1 instruction. Before it executes, print out
$fsr; it will probably be 0. After trying to copy 0xf0102 into FSR, print
$fsr again; it will be 0x102. The program will still complete OK.
Now try again. After the ctc1 instruction, tell gdb "set $fsr = 0xf0102".
Then continue; the kernel locks up before the program is done.
The extra bits are two bits in the cause field, and two bits in the
reserved-write-as-zero field. I'm not sure whether setting the reserved
bits is to blame, or whether setting the cause bits raises a floating point
exception in the kernel during context switching. In any case, it looks
like we ought to be masking out some bits before saving the fcr31 value in
ptrace.
--
Daniel Jacobowitz
CodeSourcery, LLC
[-- Attachment #2: mips-crash.c --]
[-- Type: text/x-csrc, Size: 2431 bytes --]
/* This testcase is part of GDB, the GNU debugger.
Copyright 2004 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <sys/time.h>
#include <setjmp.h>
static volatile int done;
static jmp_buf env;
static void
handler (int sig)
{
done = 1;
/* NOTE: Don't try this at home; always use siglongjmp to leave
a signal handler. */
longjmp (env, 1);
} /* handler */
struct itimerval itime;
struct sigaction action;
/* The enum is so that GDB can easily see these macro values. */
enum {
itimer_real = ITIMER_REAL,
itimer_virtual = ITIMER_VIRTUAL
} itimer = ITIMER_VIRTUAL;
main ()
{
/* Set up the signal handler. */
memset (&action, 0, sizeof (action));
action.sa_handler = handler;
sigaction (SIGVTALRM, &action, NULL);
sigaction (SIGALRM, &action, NULL);
/* The values needed for the itimer. This needs to be at least long
enough for the setitimer() call to return. */
memset (&itime, 0, sizeof (itime));
itime.it_value.tv_usec = 250 * 1000;
while (setjmp (env) == 0)
{
/* Set up a one-off timer. A timer, rather than SIGSEGV, is
used as after a timer handler finishes the interrupted code
can safely resume. */
setitimer (itimer, &itime, NULL);
/* Wait. */
while (!done);
done = 0;
}
done = 0;
itimer = itimer_real;
asm volatile ("ctc1 %0, $31" : : "r" (0x000f0102));
while (setjmp (env) == 0)
{
/* Set up a one-off timer. A timer, rather than SIGSEGV, is
used as after a timer handler finishes the interrupted code
can safely resume. */
setitimer (itimer, &itime, NULL);
/* Wait. */
while (!done);
done = 0;
}
}
reply other threads:[~2005-04-02 22:24 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20050402222353.GA18450@nevyn.them.org \
--to=dan@debian.org \
--cc=linux-mips@linux-mips.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox