Skip to contentSkip to conversation

remove all kernel bugs

PATCH In review Matt Mackall 4 participants 6 messages Apr 1, 2005 – Apr 2, 2005

Subsystems (8)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 remove all kernel bugs

I've been sitting on this patch for a while, figured it's high time I shared it with the world. This patch eliminates all kernel bugs, trims about 35k off the typical kernel, and makes the system slightly faster. The patch is against the latest bk snapshot, please apply.

include/asm-i386/bug.h +3 -2
Index: af/include/asm-i386/bug.h
===================================================================
@@ -9,6 +9,8 @@
  * undefined" opcode for parsing in the trap handler.
  */
 
+#ifdef CONFIG_BUG
+#define HAVE_ARCH_BUG
 #ifdef CONFIG_DEBUG_BUGVERBOSE
 #define BUG()				\
  __asm__ __volatile__(	"ud2\n"		\
@@ -18,8 +20,7 @@
 #else
 #define BUG() __asm__ __volatile__("ud2\n")
 #endif
+#endif
 
-#define HAVE_ARCH_BUG
 #include <asm-generic/bug.h>
-
 #endif
include/asm-x86_64/bug.h +3 -0
Index: af/include/asm-x86_64/bug.h
===================================================================
@@ -15,11 +15,14 @@ struct bug_frame {
 	unsigned short line;
 } __attribute__((packed));
 
+#ifdef CONFIG_BUG
 #define HAVE_ARCH_BUG
 #define BUG() \
 	asm volatile("ud2 ; .quad %c1 ; .short %c0" :: \
 		     "i"(__LINE__), "i" (__stringify(KBUILD_BASENAME)))
 void out_of_line_bug(void);
+#endif
+
 #include <asm-generic/bug.h>
 
 #endif
include/asm-sparc64/bug.h +3 -0
Index: af/include/asm-sparc64/bug.h
===================================================================
@@ -1,6 +1,7 @@
 #ifndef _SPARC64_BUG_H
 #define _SPARC64_BUG_H
 
+#ifdef CONFIG_BUG
 #include <linux/compiler.h>
 
 #ifdef CONFIG_DEBUG_BUGVERBOSE
@@ -14,6 +15,8 @@ extern void do_BUG(const char *file, int
 #endif
 
 #define HAVE_ARCH_BUG
+#endif
+
 #include <asm-generic/bug.h>
 
 #endif
include/asm-m68k/bug.h +3 -0
Index: af/include/asm-m68k/bug.h
===================================================================
@@ -3,6 +3,7 @@
 
 #include <linux/config.h>
 
+#ifdef CONFIG_BUG
 #ifdef CONFIG_DEBUG_BUGVERBOSE
 #ifndef CONFIG_SUN3
 #define BUG() do { \
@@ -22,6 +23,8 @@
 #endif
 
 #define HAVE_ARCH_BUG
+#endif
+
 #include <asm-generic/bug.h>
 
 #endif
include/asm-generic/bug.h +19 -0
Index: af/include/asm-generic/bug.h
===================================================================
@@ -4,6 +4,7 @@
 #include <linux/compiler.h>
 #include <linux/config.h>
 
+#ifdef CONFIG_BUG
 #ifndef HAVE_ARCH_BUG
 #define BUG() do { \
 	printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
@@ -31,4 +32,22 @@
 } while (0)
 #endif
 
+#else /* !CONFIG_BUG */
+#ifndef HAVE_ARCH_BUG
+#define BUG()
+#endif
+
+#ifndef HAVE_ARCH_PAGE_BUG
+#define PAGE_BUG(page) do { if (page) ; } while (0)
+#endif
+
+#ifndef HAVE_ARCH_BUG_ON
+#define BUG_ON(condition) do { if (condition) ; } while(0)
+#endif
+
+#ifndef HAVE_ARCH_WARN_ON
+#define WARN_ON(condition) do { if (condition) ; } while(0)
+#endif
+#endif
+
 #endif
include/asm-s390/bug.h +3 -0
Index: af/include/asm-s390/bug.h
===================================================================
@@ -3,12 +3,15 @@
 
 #include <linux/kernel.h>
 
+#ifdef CONFIG_BUG
 #define BUG() do { \
         printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
         __asm__ __volatile__(".long 0"); \
 } while (0)
 
 #define HAVE_ARCH_BUG
+#endif
+
 #include <asm-generic/bug.h>
 
 #endif
include/asm-arm/bug.h +3 -0
Index: af/include/asm-arm/bug.h
===================================================================
@@ -3,6 +3,7 @@
 
 #include <linux/config.h>
 
+#ifdef CONFIG_BUG
 #ifdef CONFIG_DEBUG_BUGVERBOSE
 extern volatile void __bug(const char *file, int line, void *data);
 
@@ -17,6 +18,8 @@ extern volatile void __bug(const char *f
 #endif
 
 #define HAVE_ARCH_BUG
+#endif
+
 #include <asm-generic/bug.h>
 
 #endif
include/asm-arm26/bug.h +3 -0
Index: af/include/asm-arm26/bug.h
===================================================================
@@ -3,6 +3,7 @@
 
 #include <linux/config.h>
 
+#ifdef CONFIG_BUG
 #ifdef CONFIG_DEBUG_BUGVERBOSE
 extern volatile void __bug(const char *file, int line, void *data);
 /* give file/line information */
@@ -12,6 +13,8 @@ extern volatile void __bug(const char *f
 #endif
 
 #define HAVE_ARCH_BUG
+#endif
+
 #include <asm-generic/bug.h>
 
 #endif
include/asm-ia64/bug.h +4 -1
Index: af/include/asm-ia64/bug.h
===================================================================
@@ -1,6 +1,7 @@
 #ifndef _ASM_IA64_BUG_H
 #define _ASM_IA64_BUG_H
 
+#ifdef CONFIG_BUG
 #if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)
 # define ia64_abort()	__builtin_trap()
 #else
@@ -8,8 +9,10 @@
 #endif
 #define BUG() do { printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); ia64_abort(); } while (0)
 
-/* should this BUG should be made generic? */
+/* should this BUG be made generic? */
 #define HAVE_ARCH_BUG
+#endif
+
 #include <asm-generic/bug.h>
 
 #endif
include/asm-v850/bug.h +3 -0
Index: af/include/asm-v850/bug.h
===================================================================
@@ -14,9 +14,12 @@
 #ifndef __V850_BUG_H__
 #define __V850_BUG_H__
 
+#ifdef CONFIG_BUG
 extern void __bug (void) __attribute__ ((noreturn));
 #define BUG()		__bug()
 #define HAVE_ARCH_BUG
+#endif
+
 #include <asm-generic/bug.h>
 
 #endif /* __V850_BUG_H__ */
include/asm-alpha/bug.h +3 -0
Index: af/include/asm-alpha/bug.h
===================================================================
@@ -1,6 +1,7 @@
 #ifndef _ALPHA_BUG_H
 #define _ALPHA_BUG_H
 
+#ifdef CONFIG_BUG
 #include <asm/pal.h>
 
 /* ??? Would be nice to use .gprel32 here, but we can't be sure that the
@@ -10,6 +11,8 @@
 		       : : "i" (PAL_bugchk), "i"(__LINE__), "i"(__FILE__))
 
 #define HAVE_ARCH_BUG
+#endif
+
 #include <asm-generic/bug.h>
 
 #endif
include/asm-ppc/bug.h +3 -0
Index: af/include/asm-ppc/bug.h
===================================================================
@@ -14,6 +14,7 @@ struct bug_entry {
  */
 #define BUG_WARNING_TRAP	0x1000000
 
+#ifdef CONFIG_BUG
 #define BUG() do {							 \
 	__asm__ __volatile__(						 \
 		"1:	twi 31,0,0\n"					 \
@@ -50,6 +51,8 @@ struct bug_entry {
 #define HAVE_ARCH_BUG
 #define HAVE_ARCH_BUG_ON
 #define HAVE_ARCH_WARN_ON
+#endif
+
 #include <asm-generic/bug.h>
 
 #endif
include/asm-frv/bug.h +2 -0
Index: af/include/asm-frv/bug.h
===================================================================
@@ -13,6 +13,7 @@
 
 #include <linux/config.h>
 
+#ifdef CONFIG_BUG
 /*
  * Tell the user there is some problem.
  */
@@ -45,6 +46,7 @@ do {						\
 #define HAVE_ARCH_KGDB_BAD_PAGE
 #define kgdb_bad_page(page) do { kgdb_raise(SIGABRT); } while(0)
 #endif
+#endif
 
 #include <asm-generic/bug.h>
 
include/asm-ppc64/bug.h +5 -2
Index: af/include/asm-ppc64/bug.h
===================================================================
@@ -26,6 +26,8 @@ struct bug_entry *find_bug(unsigned long
  */
 #define BUG_WARNING_TRAP	0x1000000
 
+#ifdef CONFIG_BUG
+
 #define BUG() do {							 \
 	__asm__ __volatile__(						 \
 		"1:	twi 31,0,0\n"					 \
@@ -55,11 +57,12 @@ struct bug_entry *find_bug(unsigned long
 		    "i" (__FILE__), "i" (__FUNCTION__));	\
 } while (0)
 
-#endif
-
 #define HAVE_ARCH_BUG
 #define HAVE_ARCH_BUG_ON
 #define HAVE_ARCH_WARN_ON
+#endif
+#endif
+
 #include <asm-generic/bug.h>
 
 #endif
include/asm-sh/bug.h +3 -0
Index: af/include/asm-sh/bug.h
===================================================================
@@ -3,6 +3,7 @@
 
 #include <linux/config.h>
 
+#ifdef CONFIG_BUG
 /*
  * Tell the user there is some problem.
  */
@@ -12,6 +13,8 @@
 } while (0)
 
 #define HAVE_ARCH_BUG
+#endif
+
 #include <asm-generic/bug.h>
 
 #endif
include/asm-sparc/bug.h +3 -0
Index: af/include/asm-sparc/bug.h
===================================================================
@@ -1,6 +1,7 @@
 #ifndef _SPARC_BUG_H
 #define _SPARC_BUG_H
 
+#ifdef CONFIG_BUG
 /* Only use the inline asm until a gcc release that can handle __builtin_trap
  * -rob 2003-06-25
  *
@@ -26,6 +27,8 @@ extern void do_BUG(const char *file, int
 #endif
 
 #define HAVE_ARCH_BUG
+#endif
+
 #include <asm-generic/bug.h>
 
 #endif
include/asm-mips/bug.h +3 -1
Index: af/include/asm-mips/bug.h
===================================================================
@@ -3,12 +3,14 @@
 
 #include <asm/break.h>
 
+#ifdef CONFIG_BUG
+#define HAVE_ARCH_BUG
 #define BUG()								\
 do {									\
 	__asm__ __volatile__("break %0" : : "i" (BRK_BUG));		\
 } while (0)
+#endif
 
-#define HAVE_ARCH_BUG
 #include <asm-generic/bug.h>
 
 #endif
include/asm-parisc/bug.h +2 -0
Index: af/include/asm-parisc/bug.h
===================================================================
@@ -1,12 +1,14 @@
 #ifndef _PARISC_BUG_H
 #define _PARISC_BUG_H
 
+#ifdef CONFIG_BUG
 #define HAVE_ARCH_BUG
 #define BUG() do { \
 	printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
 	dump_stack(); \
 	panic("BUG!"); \
 } while (0)
+#endif
 
 #include <asm-generic/bug.h>
 #endif
lib/Kconfig.debug +1 -0
Index: af/lib/Kconfig.debug
===================================================================
@@ -108,6 +108,7 @@ config DEBUG_HIGHMEM
 
 config DEBUG_BUGVERBOSE
 	bool "Verbose BUG() reporting (adds 70K)" if DEBUG_KERNEL && EMBEDDED
+	depends on BUG
 	depends on ARM || ARM26 || M32R || M68K || SPARC32 || SPARC64 || (X86 && !X86_64) || FRV
 	default !EMBEDDED
 	help
init/Kconfig +10 -0
Index: af/init/Kconfig
===================================================================
@@ -275,6 +275,16 @@ config KALLSYMS_EXTRA_PASS
 	   reported.  KALLSYMS_EXTRA_PASS is only a temporary workaround while
 	   you wait for kallsyms to be fixed.
 
+config BUG
+	bool "BUG() support" if EMBEDDED
+	default y
+	help
+          Disabling this option eliminates support for BUG and WARN, reducing
+          the size of your kernel image and potentially quietly ignoring
+          numerous fatal conditions. You should only consider disabling this
+          option for embedded systems with no facilities for reporting errors.
+          Just say Y.
+
 config BASE_FULL
 	default y
 	bool "Enable full-sized data structures for core" if EMBEDDED
Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#1 lore raw

On Fri, 2005-04-01 01:07:44 -0800, Matt Mackall <[email protected]> wrote in message <[email protected]>:

Quoted 6 lines

I've been sitting on this patch for a while, figured it's high time I shared it with the world. This patch eliminates all kernel bugs, trims about 35k off the typical kernel, and makes the system slightly faster. The patch is against the latest bk snapshot, please apply.

Well, the patch looks fine, but you forgot to also do the VAX-specific part. Withoug the BUGs, maybe the VAX kernel would be even faster?

:-), JBG

Signature · 4 lines
Jan-Benedict Glaw       [email protected]    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));
#4 lore raw
In reply to Matt Mackall
Quoted 5 lines · Matt Mackall

I've been sitting on this patch for a while, figured it's high time I
shared it with the world. This patch eliminates all kernel bugs, trims about 35k off the typical kernel, and makes the system slightly faster. The patch is against the latest bk snapshot, please apply.

ho-hum, more ifdefs.

How's about you nuke PAGE_BUG first? Just replace it with BUG() everywhere.

Or do it as a later patch - doesn't matter much I guess.

Or tell me to naff off and don't do it at all ;)

#5 lore raw
Quoted 7 lines · Andrew Morton
Quoted 5 lines · Matt Mackall

I've been sitting on this patch for a while, figured it's high time I
shared it with the world. This patch eliminates all kernel bugs, trims about 35k off the typical kernel, and makes the system slightly faster. The patch is against the latest bk snapshot, please apply.

Quoted 5 lines

ho-hum, more ifdefs.

How's about you nuke PAGE_BUG first? Just replace it with BUG() everywhere.

Or do it as a later patch - doesn't matter much I guess.

With pleasure.

Exterminate PAGE_BUG.

include/asm-sh64/bug.h +0 -4
Index: af/include/asm-sh64/bug.h
===================================================================
@@ -17,10 +17,6 @@
 		BUG(); \
 } while(0)
 
-#define PAGE_BUG(page) do { \
-	BUG(); \
-} while (0)
-
 #define WARN_ON(condition) do { \
 	if (unlikely((condition)!=0)) { \
 		printk("Badness in %s at %s:%d\n", __FUNCTION__, __FILE__, __LINE__); \
fs/buffer.c +1 -2
Index: af/fs/buffer.c
===================================================================
@@ -2078,8 +2078,7 @@ int block_read_full_page(struct page *pa
 	int nr, i;
 	int fully_mapped = 1;
 
-	if (!PageLocked(page))
-		PAGE_BUG(page);
+	BUG_ON(!PageLocked(page));
 	blocksize = 1 << inode->i_blkbits;
 	if (!page_has_buffers(page))
 		create_empty_buffers(page, blocksize, 0);
fs/afs/file.c +1 -2
Index: af/fs/afs/file.c
===================================================================
@@ -131,8 +131,7 @@ static int afs_file_readpage(struct file
 
 	vnode = AFS_FS_I(inode);
 
-	if (!PageLocked(page))
-		PAGE_BUG(page);
+	BUG_ON(!PageLocked(page));
 
 	ret = -ESTALE;
 	if (vnode->flags & AFS_VNODE_DELETED)
include/asm-generic/bug.h +0 -11
Index: af/include/asm-generic/bug.h
===================================================================
@@ -12,13 +12,6 @@
 } while (0)
 #endif
 
-#ifndef HAVE_ARCH_PAGE_BUG
-#define PAGE_BUG(page) do { \
-	printk("page BUG for page at %p\n", page); \
-	BUG(); \
-} while (0)
-#endif
-
 #ifndef HAVE_ARCH_BUG_ON
 #define BUG_ON(condition) do { if (unlikely((condition)!=0)) BUG(); } while(0)
 #endif
@@ -37,10 +30,6 @@
 #define BUG()
 #endif
 
-#ifndef HAVE_ARCH_PAGE_BUG
-#define PAGE_BUG(page) do { if (page) ; } while (0)
-#endif
-
 #ifndef HAVE_ARCH_BUG_ON
 #define BUG_ON(condition) do { if (condition) ; } while(0)
 #endif
fs/jffs2/file.c +1 -2
Index: af/fs/jffs2/file.c
===================================================================
@@ -79,8 +79,7 @@ static int jffs2_do_readpage_nolock (str
 
 	D2(printk(KERN_DEBUG "jffs2_do_readpage_nolock(): ino #%lu, page at offset 0x%lx\n", inode->i_ino, pg->index << PAGE_CACHE_SHIFT));
 
-	if (!PageLocked(pg))
-                PAGE_BUG(pg);
+	BUG_ON(!PageLocked(pg));
 
 	pg_buf = kmap(pg);
 	/* FIXME: Can kmap fail? */
include/asm-cris/page.h +0 -4
Index: af/include/asm-cris/page.h
===================================================================
@@ -77,10 +77,6 @@ typedef struct { unsigned long pgprot; }
   printk("kernel BUG at %s:%d!\n", __FILE__, __LINE__); \
 } while (0)
 
-#define PAGE_BUG(page) do { \
-         BUG(); \
-} while (0)
-
 /* Pure 2^n version of get_order */
 static inline int get_order(unsigned long size)
 {
fs/udf/file.c +2 -4
Index: af/fs/udf/file.c
===================================================================
@@ -49,8 +49,7 @@ static int udf_adinicb_readpage(struct f
 	struct inode *inode = page->mapping->host;
 	char *kaddr;
 
-	if (!PageLocked(page))
-		PAGE_BUG(page);
+	BUG_ON(!PageLocked(page));
 
 	kaddr = kmap(page);
 	memset(kaddr, 0, PAGE_CACHE_SIZE);
@@ -67,8 +66,7 @@ static int udf_adinicb_writepage(struct 
 	struct inode *inode = page->mapping->host;
 	char *kaddr;
 
-	if (!PageLocked(page))
-		PAGE_BUG(page);
+	BUG_ON(!PageLocked(page));
 
 	kaddr = kmap(page);
 	memcpy(UDF_I_DATA(inode) + UDF_I_LENEATTR(inode), kaddr, inode->i_size);
fs/udf/inode.c +2 -2
Index: af/fs/udf/inode.c
===================================================================
@@ -167,8 +167,8 @@ void udf_expand_file_adinicb(struct inod
 	}
 
 	page = grab_cache_page(inode->i_mapping, 0);
-	if (!PageLocked(page))
-		PAGE_BUG(page);
+	BUG_ON(!PageLocked(page));
+
 	if (!PageUptodate(page))
 	{
 		kaddr = kmap(page);
arch/arm26/mm/small_page.c +2 -4
Index: af/arch/arm26/mm/small_page.c
===================================================================
@@ -92,8 +92,7 @@ static unsigned long __get_small_page(in
 		page = list_entry(order->queue.next, struct page, lru);
 again:
 #ifdef PEDANTIC
-		if (USED_MAP(page) & ~order->all_used)
-			PAGE_BUG(page);
+		BUG_ON(USED_MAP(page) & ~order->all_used);
 #endif
 		offset = ffz(USED_MAP(page));
 		SET_USED(page, offset);
@@ -141,8 +140,7 @@ static void __free_small_page(unsigned l
 			goto non_small;
 
 #ifdef PEDANTIC
-		if (USED_MAP(page) & ~order->all_used)
-			PAGE_BUG(page);
+		BUG_ON(USED_MAP(page) & ~order->all_used);
 #endif
 
 		spage = spage >> order->shift;
mm/filemap.c +1 -2
Index: af/mm/filemap.c
===================================================================
@@ -123,8 +123,7 @@ void remove_from_page_cache(struct page 
 {
 	struct address_space *mapping = page->mapping;
 
-	if (unlikely(!PageLocked(page)))
-		PAGE_BUG(page);
+	BUG_ON(!PageLocked(page));
 
 	write_lock_irq(&mapping->tree_lock);
 	__remove_from_page_cache(page);
Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#2 lore raw
In reply to Jan-Benedict Glaw
Quoted 11 lines · Jan-Benedict Glaw

On Fri, 2005-04-01 01:07:44 -0800, Matt Mackall <[email protected]> wrote in message <[email protected]>:

Quoted 6 lines

I've been sitting on this patch for a while, figured it's high time I shared it with the world. This patch eliminates all kernel bugs, trims about 35k off the typical kernel, and makes the system slightly faster. The patch is against the latest bk snapshot, please apply.

Well, the patch looks fine, but you forgot to also do the VAX-specific part. Withoug the BUGs, maybe the VAX kernel would be even faster?

Perhaps it's a good idea to get Linux/VAX merged in mainline first? After that people will start fixing all your bugs automagically ;-)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#3 lore raw

On Sat, 2005-04-02 23:03:14 +0200, Geert Uytterhoeven <[email protected]> wrote in message <[email protected]>:

Quoted 6 lines · Jan-Benedict Glaw
Quoted 2 lines

Well, the patch looks fine, but you forgot to also do the VAX-specific part. Withoug the BUGs, maybe the VAX kernel would be even faster?

Perhaps it's a good idea to get Linux/VAX merged in mainline first? After that people will start fixing all your bugs automagically ;-)

Maybe we'll work on that, but first we need to get real, up-to-date userspace and not all this old stuff with uClibc. But we're working on this. (Currently tracking down an ICE. GCC is fun. A lot of fun and black magic...)

MfG, JBG

Signature · 4 lines
Jan-Benedict Glaw       [email protected]    . +49-172-7608481             _ O _
"Eine Freie Meinung in  einem Freien Kopf    | Gegen Zensur | Gegen Krieg  _ _ O
 fuer einen Freien Staat voll Freier Bürger" | im Internet! |   im Irak!   O O O
ret = do_actions((curr | FREE_SPEECH) & ~(NEW_COPYRIGHT_LAW | DRM | TCPA));