Skip to contentSkip to conversation

Adding the interrupt checker

PATCH In review Christopher Li 2 participants 2 messages Feb 10, 2007 – Mar 1, 2007

Subsystems (2)
lore
Share & tools
lore

Christopher Li

author maintainer
#0 lore raw

PATCH 1/1 Adding the interrupt checker

Changelog:
- Using the new inline function calling annotation to find out the irq related call. It now works both inline and external functions. Bonus is no more x86 asm any more.
- The noise level of interrupt check drop considerably. I think it is less nosier than the context checking.

lib.c +2 -0
Index: sparse/lib.c
===================================================================
@@ -191,6 +191,7 @@ int Wenum_mismatch = 1;
 int Wdo_while = 1;
 int Wuninitialized = 1;
 int Wmalloc = 1;
+int Winterrupt = 1;
 
 int dbg_entry = 0;
 int dbg_dead = 0;
@@ -341,6 +342,7 @@ static const struct warning {
 	{ "do-while", &Wdo_while },
 	{ "uninitialized", &Wuninitialized },
 	{ "malloc", &Wmalloc},
+	{ "interrupt", &Winterrupt},
 };
 
 enum {
Makefile +2 -1
Index: sparse/Makefile
===================================================================
@@ -34,7 +34,7 @@ LIB_OBJS= target.o parse.o tokenize.o pr
 	  expression.o show-parse.o evaluate.o expand.o inline.o linearize.o \
 	  sort.o allocate.o compat-$(OS).o ptrlist.o \
 	  flow.o cse.o simplify.o memops.o liveness.o storage.o unssa.o dissect.o \
-	  blobhash.o check-nullptr.o
+	  blobhash.o check-nullptr.o check-interrupt.o
 
 LIB_FILE= libsparse.a
 SLIB_FILE= libsparse.so
@@ -139,6 +139,7 @@ dissect.o: $(LIB_H)
 graph.o: $(LIB_H)
 blobstate.o: $(LIB_H)
 check-nullptr.o: $(LIB_H)
+check-interrupt.o: $(LIB_H)
 
 compat-linux.o: compat/strtold.c compat/mmap-blob.c \
 	$(LIB_H)
checker.h +2 -0
Index: sparse/checker.h
===================================================================
@@ -137,6 +137,8 @@ static inline int match_call_function(st
 
 extern void check_null_ptr_init(void);
 extern void check_null_ptr(struct entrypoint *ep);
+extern void check_interrupt(struct entrypoint *ep);
+extern void check_interrupt_init(void);
 
 #endif
 
lib.h +1 -0
Index: sparse/lib.h
===================================================================
@@ -97,6 +97,7 @@ extern int Wcast_truncate;
 extern int Wdo_while;
 extern int Wuninitialized;
 extern int Wmalloc;
+extern int Winterrupt;
 
 extern int dbg_entry;
 extern int dbg_dead;
sparse.c +2 -0
Index: sparse/sparse.c
===================================================================
@@ -273,6 +273,8 @@ static void check_symbols(struct symbol_
 			check_context(ep);
 			if (Wmalloc)
 				check_null_ptr(ep);
+			if (Winterrupt)
+				check_interrupt(ep);
 		}
 	} END_FOR_EACH_PTR(sym);
 }
check-interrupt.c +210 -0

210 lines not on this page · raw message

#1 lore raw

Hello!

Quoted 8 lines · Christopher Li

Changelog:
- Using the new inline function calling annotation to find out the irq related call. It now works both inline and external functions. Bonus is no more x86 asm any more.
- The noise level of interrupt check drop considerably. I think it is less nosier than the context checking.

[skip]

check-interrupt.c line 172

Quoted 8 lines
check-interrupt.c +8 -0
+	static const char *enable[] = {
+		"raw_local_irq_enable",
+		"raw_safe_halt",
+		"_spin_unlock_irq",
+		"_read_unlock_irq",
+		"_write_unlock_irq",
+		"schedule",		// XXX: is it always true?
+	};

Sorry for late comments. I actually applied the series to my copy of sparse, and I found today that it catches schedule() for no reason.

"schedule" doesn't belong here. It doesn't enable or disable interrupts. However, it requires interrupts to be enabled. Annotating functions requiring a specific context is not covered by your patch, so I think it would be better to drop "schedule" from this list.

This patch helped me find some places where interrupts were disabled and enabled twice. But the output is confusing:

/home/proski/src/madwifi/net80211/ieee80211_node.c:1631:2: warning:
checker function ieee80211_timeout_stations double enable

It's not even clear that the message is about interrupts. And the "checker function" part is quite useless. See other sparse warnings to compare the style.

I think the patch is mildly useful, but shouldn't be applied as is.

Moreover, I think that incorrect use of locking is a remaining major issue not covered by sparse. Runtime checks only cover the code that is executed. Besides, the don't enforce better coding style.

I think all functions capable of supporting atomic contexts should be annotated as such, and sparse should be always aware of the allowed locking contexts for the code.

This would be a major, major change, perhaps more intrusive than the endianess annotation. But I think it would be worth the trouble. It would probably catch hundreds of bugs capable of hosing a working system.

Another nice feature would be to annotate data so that it can be accessed with certain locks held. That would catch even more bugs, but first sparse should be made lock aware.

Signature · 2 lines
Regards,
Pavel Roskin