public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@zip.com.au>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>,
	Hugh Dickins <hugh@veritas.com>,
	Marcelo Tosatti <marcelo@conectiva.com.br>,
	"H. Peter Anvin" <hpa@zytor.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] BUG preserve registers
Date: Sat, 09 Feb 2002 22:28:14 -0800	[thread overview]
Message-ID: <3C6612FE.3AD035E@zip.com.au> (raw)
In-Reply-To: <3C660517.AAA7FA8@zip.com.au> <Pine.LNX.4.33.0202092322310.11734-100000@home.transmeta.com>

Linus Torvalds wrote:
> 
> On Sat, 9 Feb 2002, Andrew Morton wrote:
> >
> > This is the cue for Keith to pop up and say "fixed in kbuild 2.5".
> 
> Nope.
> 
> > __BASE_FILE__ seems to have been supported for a sufficiently long time.
> 
> __BASE_FILE__ is not useful.
> 
> Remember: when we have a BUG in a header file, we need to get the HEADER
> file, not the base file.
> 
> __BASE_FILE__ only works for .c files.
> 

Oh so that's what __BASE_FILE__ does :(

I looked at cccp.c - there doesn't seem to be a way.  Best
I can come up with is, in each directory, to do

	ln -s $(TOPDIR)/include/linux i
and
	gcc -Ii ...

which seems like a good way to get one's linux kernel license taken
away.  Better off feeding the asm through sed(1).


No magic bullets.   I think it's sufficient to go and individually
address the BUG-in-inline instances.  But that's a separate patch.

Macrelo, here's the "Don't trash registers in BUG()" patch.

I tried hpa's `for ( ; ; );' suggestion - the kernel got bigger.
And I couldn't find a way of declaring BUG() to be noreturn, so
I think I'm done with this now.

BTW: it has been noted that I'm not doing 2.5 patches.  All the stuff
I'm working on at present tends to be small, nasty, needed for 2.4 and
not critical for 2.5 at this time.  I shall forward port anything which
falls through Dave's cracks, but not for a while yet.



--- linux-2.4.18-pre9/include/asm-i386/page.h	Thu Feb  7 13:04:22 2002
+++ linux-akpm/include/asm-i386/page.h	Sat Feb  9 22:01:01 2002
@@ -91,16 +91,18 @@ typedef struct { unsigned long pgprot; }
 /*
  * Tell the user there is some problem. Beep too, so we can
  * see^H^H^Hhear bugs in early bootup as well!
+ * The offending file and line are encoded after the "officially
+ * undefined" opcode for parsing in the trap handler.
  */
 
-#ifdef CONFIG_DEBUG_BUGVERBOSE
-extern void do_BUG(const char *file, int line);
-#define BUG() do {					\
-	do_BUG(__FILE__, __LINE__);			\
-	__asm__ __volatile__("ud2");			\
-} while (0)
+#if 1	/* Set to zero for a slightly smaller kernel */
+#define BUG()				\
+ __asm__ __volatile__(	"ud2\n"		\
+			"\t.word %c0\n"	\
+			"\t.long %c1\n"	\
+			 : : "i" (__LINE__), "i" (__FILE__))
 #else
-#define BUG() __asm__ __volatile__(".byte 0x0f,0x0b")
+#define BUG() __asm__ __volatile__("ud2\n")
 #endif
 
 #define PAGE_BUG(page) do { \
--- linux-2.4.18-pre9/arch/i386/kernel/traps.c	Sun Sep 30 12:26:08 2001
+++ linux-akpm/arch/i386/kernel/traps.c	Sat Feb  9 21:30:06 2002
@@ -237,6 +237,42 @@ bad:
 	printk("\n");
 }	
 
+static void handle_BUG(struct pt_regs *regs)
+{
+	unsigned short ud2;
+	unsigned short line;
+	char *file;
+	char c;
+	unsigned long eip;
+
+	if (regs->xcs & 3)
+		goto no_bug;		/* Not in kernel */
+
+	eip = regs->eip;
+
+	if (eip < PAGE_OFFSET)
+		goto no_bug;
+	if (__get_user(ud2, (unsigned short *)eip))
+		goto no_bug;
+	if (ud2 != 0x0b0f)
+		goto no_bug;
+	if (__get_user(line, (unsigned short *)(eip + 2)))
+		goto bug;
+	if (__get_user(file, (char **)(eip + 4)))
+		goto bug;
+	if ((unsigned long)file < PAGE_OFFSET || __get_user(c, file))
+		file = "<bad filename>";
+
+	printk("Kernel BUG at %s:%d\n", file, line);
+
+no_bug:
+	return;
+
+	/* Here we know it was a BUG but file-n-line is unavailable */
+bug:
+	printk("Kernel BUG\n");
+}
+
 spinlock_t die_lock = SPIN_LOCK_UNLOCKED;
 
 void die(const char * str, struct pt_regs * regs, long err)
@@ -244,6 +280,7 @@ void die(const char * str, struct pt_reg
 	console_verbose();
 	spin_lock_irq(&die_lock);
 	bust_spinlocks(1);
+	handle_BUG(regs);
 	printk("%s: %04lx\n", str, err & 0xffff);
 	show_registers(regs);
 	bust_spinlocks(0);
--- linux-2.4.18-pre9/arch/i386/kernel/i386_ksyms.c	Thu Feb  7 13:04:11 2002
+++ linux-akpm/arch/i386/kernel/i386_ksyms.c	Sat Feb  9 19:49:38 2002
@@ -168,9 +168,5 @@ EXPORT_SYMBOL_NOVERS(memset);
 EXPORT_SYMBOL(atomic_dec_and_lock);
 #endif
 
-#ifdef CONFIG_DEBUG_BUGVERBOSE
-EXPORT_SYMBOL(do_BUG);
-#endif
-
 extern int is_sony_vaio_laptop;
 EXPORT_SYMBOL(is_sony_vaio_laptop);
--- linux-2.4.18-pre9/arch/i386/config.in	Thu Feb  7 13:04:11 2002
+++ linux-akpm/arch/i386/config.in	Sat Feb  9 19:49:38 2002
@@ -421,7 +421,6 @@ if [ "$CONFIG_DEBUG_KERNEL" != "n" ]; th
    bool '  Memory mapped I/O debugging' CONFIG_DEBUG_IOVIRT
    bool '  Magic SysRq key' CONFIG_MAGIC_SYSRQ
    bool '  Spinlock debugging' CONFIG_DEBUG_SPINLOCK
-   bool '  Verbose BUG() reporting (adds 70K)' CONFIG_DEBUG_BUGVERBOSE
 fi
 
 endmenu
--- linux-2.4.18-pre9/arch/i386/mm/fault.c	Thu Feb  7 13:04:11 2002
+++ linux-akpm/arch/i386/mm/fault.c	Sat Feb  9 19:49:38 2002
@@ -125,12 +125,6 @@ void bust_spinlocks(int yes)
 	}
 }
 
-void do_BUG(const char *file, int line)
-{
-	bust_spinlocks(1);
-	printk("kernel BUG at %s:%d!\n", file, line);
-}
-
 asmlinkage void do_invalid_op(struct pt_regs *, unsigned long);
 extern unsigned long idt;

  reply	other threads:[~2002-02-10  6:29 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-02-09  8:13 [PATCH] BUG preserve registers Hugh Dickins
2002-02-09  8:32 ` Andrew Morton
2002-02-09 10:33   ` Hugh Dickins
2002-02-09 19:30 ` Linus Torvalds
2002-02-09 19:34   ` Andrew Morton
2002-02-09 21:37     ` Linus Torvalds
2002-02-09 20:00       ` H. Peter Anvin
2002-02-09 21:49         ` Linus Torvalds
2002-02-09 20:24           ` H. Peter Anvin
2002-02-09 20:11       ` Andrew Morton
2002-02-09 20:15         ` Linus Torvalds
2002-02-09 22:07           ` Andrew Morton
2002-02-10  2:41             ` Alan Cox
2002-02-10  4:20               ` Andrew Morton
2002-02-10  4:23                 ` H. Peter Anvin
2002-02-10  4:28                   ` Andrew Morton
2002-02-10  6:16                 ` Linus Torvalds
2002-02-10  5:28                   ` Andrew Morton
2002-02-10  7:23                     ` Linus Torvalds
2002-02-10  6:28                       ` Andrew Morton [this message]
2002-02-10  9:05                         ` Andrew Morton
     [not found]                           ` <200202110710.g1B7A5t28328@Port.imtp.ilyichevsk.odessa.ua>
2002-02-11  7:22                             ` Andrew Morton
2002-02-11 17:19                           ` Hugh Dickins
2002-02-11 19:48                             ` Andrew Morton
2002-02-11 20:52                               ` Hugh Dickins
2002-02-10  7:13                       ` H. Peter Anvin
2002-02-10  8:53                         ` arjan
2002-02-11 15:26                     ` Jamie Lokier
2002-02-10  6:23                   ` Eric W. Biederman
2002-02-10  6:50                     ` Andrew Morton
2002-02-10 15:40                       ` Eric W. Biederman
2002-02-10  7:08                     ` Stevie O
2002-02-10 14:35                   ` Olaf Dietsche
2002-02-10  4:55               ` Linus Torvalds
2002-02-10  5:03               ` Linus Torvalds
2002-02-10  4:21       ` Brian Gerst

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=3C6612FE.3AD035E@zip.com.au \
    --to=akpm@zip.com.au \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=hpa@zytor.com \
    --cc=hugh@veritas.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo@conectiva.com.br \
    --cc=torvalds@transmeta.com \
    /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