Skip to contentSkip to conversation

generic-ipi: add lock context annotations

PATCH Superseded Namhyung Kim 4 participants 10 messages Nov 22, 2010 – Nov 24, 2010

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 generic-ipi: add lock context annotations

The ipi_call_[un]lock[_irq] functions grab/release a spin lock but were missing proper annotations. Add it.

---
 kernel/smp.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
kernel/smp.c +4 -0
index 12ed8b0..5a62f1f 100644
@@ -511,21 +511,25 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
 EXPORT_SYMBOL(smp_call_function);
 
 void ipi_call_lock(void)
+	__acquires(call_function.lock)
 {
 	raw_spin_lock(&call_function.lock);
 }
 
 void ipi_call_unlock(void)
+	__releases(call_function.lock)
 {
 	raw_spin_unlock(&call_function.lock);
 }
 
 void ipi_call_lock_irq(void)
+	__acquires(call_function.lock)
 {
 	raw_spin_lock_irq(&call_function.lock);
 }
 
 void ipi_call_unlock_irq(void)
+	__releases(call_function.lock)
 {
 	raw_spin_unlock_irq(&call_function.lock);
 }
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 2 lines · Namhyung Kim

The ipi_call_[un]lock[_irq] functions grab/release a spin lock but were missing proper annotations. Add it.

I really have to ask why bother? Why not add some smarts to whatever uses these annotations?

Quoted 35 lines
---
 kernel/smp.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
kernel/smp.c +4 -0
index 12ed8b0..5a62f1f 100644
@@ -511,21 +511,25 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
 EXPORT_SYMBOL(smp_call_function);
 
 void ipi_call_lock(void)
+	__acquires(call_function.lock)
 {
 	raw_spin_lock(&call_function.lock);
 }
 
 void ipi_call_unlock(void)
+	__releases(call_function.lock)
 {
 	raw_spin_unlock(&call_function.lock);
 }
 
 void ipi_call_lock_irq(void)
+	__acquires(call_function.lock)
 {
 	raw_spin_lock_irq(&call_function.lock);
 }
 
 void ipi_call_unlock_irq(void)
+	__releases(call_function.lock)
 {
 	raw_spin_unlock_irq(&call_function.lock);
 }
#2 lore raw

2010-11-22 (월), 13:46 +0100, Peter Zijlstra:

Quoted 6 lines · Namhyung Kim
Quoted 2 lines

The ipi_call_[un]lock[_irq] functions grab/release a spin lock but were missing proper annotations. Add it.

I really have to ask why bother? Why not add some smarts to whatever uses these annotations?

I just thought that removing bogus warnings from sparse helps us focus on real issues when using it. Currently sparse emits too many messages and some (many?) of them might be removed trivially (or by adding bit of ugliness. :( )

BTW, I didn't get what you mean about "some smarts". Could you explain them little more?

Thanks.

Signature · 2 lines
Regards,
Namhyung Kim
#3 lore raw
Quoted 5 lines · Namhyung Kim

2010-11-22 (월), 13:46 +0100, Peter Zijlstra:

Quoted 4 lines · Namhyung Kim
Quoted 2 lines

The ipi_call_[un]lock[_irq] functions grab/release a spin lock but were missing proper annotations. Add it.

Quoted 7 lines
Quoted 2 lines

I really have to ask why bother? Why not add some smarts to whatever uses these annotations?

I just thought that removing bogus warnings from sparse helps us focus on real issues when using it. Currently sparse emits too many messages and some (many?) of them might be removed trivially (or by adding bit of ugliness. :( )

It's not too big a deal, I have no problem adding the annotation.

Quoted 2 lines

BTW, I didn't get what you mean about "some smarts". Could you explain them little more?

I guess what Peter means is that the fact that the function grabs the lock is apparent in the code, if sparse was a bit "smarter", it would see and note this itself.

Signature · 1 line
Jens Axboe
#4 lore raw
Quoted 3 lines · Jens Axboe

I guess what Peter means is that the fact that the function grabs the lock is apparent in the code, if sparse was a bit "smarter", it would see and note this itself.

The sparse warning messages should have been included in the commit message. Here they are:

kernel/smp.c:513:6: warning: context imbalance in 'ipi_call_lock' - wrong count at exit kernel/smp.c:518:6: warning: context imbalance in 'ipi_call_unlock' - unexpected unlock kernel/smp.c:523:6: warning: context imbalance in 'ipi_call_lock_irq' - wrong count at exit kernel/smp.c:528:6: warning: context imbalance in 'ipi_call_unlock_irq' - unexpected unlock

What happens is that sparse *does* see that the locks are unlocked and that's what it complains about.

Sparse works before the code is linked so this change doesn't affect anything outside kernel/smp.c. If we added these annotations to include/linux/smp.h then they would be used for checking kernel/smpboot.c

regards,
dan carpenter

#5 lore raw

2010-11-23 (화), 12:40 +0300, Dan Carpenter:

Quoted 16 lines · Jens Axboe
Quoted 3 lines

I guess what Peter means is that the fact that the function grabs the lock is apparent in the code, if sparse was a bit "smarter", it would see and note this itself.

The sparse warning messages should have been included in the commit message. Here they are:

kernel/smp.c:513:6: warning: context imbalance in 'ipi_call_lock' - wrong count at exit kernel/smp.c:518:6: warning: context imbalance in 'ipi_call_unlock' - unexpected unlock kernel/smp.c:523:6: warning: context imbalance in 'ipi_call_lock_irq' - wrong count at exit kernel/smp.c:528:6: warning: context imbalance in 'ipi_call_unlock_irq' - unexpected unlock

What happens is that sparse *does* see that the locks are unlocked and that's what it complains about.

Quoted 8 lines

Sparse works before the code is linked so this change doesn't affect anything outside kernel/smp.c. If we added these annotations to include/linux/smp.h then they would be used for checking kernel/smpboot.c

regards,
dan carpenter

I tried to annotate declations in include/linux/smp.h but it didn't work well. Maybe that's what we need to fix the sparse?

Anyway, Jens, do you want new patch which includes above warnings?

Thanks.

Signature · 2 lines
Regards,
Namhyung Kim
#6 lore raw
Quoted 6 lines · Namhyung Kim

2010-11-23 (화), 12:40 +0300, Dan Carpenter:

Quoted 1 line · Jens Axboe

I tried to annotate declations in include/linux/smp.h but it didn't work well. Maybe that's what we need to fix the sparse?

It worked for me earlier when I tested it. Just add the exact same annotations that you added to the .c file.

regards,
dan carpenter

#7 lore raw

2010-11-24 (수), 08:43 +0300, Dan Carpenter:

Quoted 8 lines · Namhyung Kim
Quoted 6 lines

2010-11-23 (화), 12:40 +0300, Dan Carpenter:

Quoted 1 line · Jens Axboe

I tried to annotate declations in include/linux/smp.h but it didn't work well. Maybe that's what we need to fix the sparse?

Quoted 6 lines

It worked for me earlier when I tested it. Just add the exact same annotations that you added to the .c file.

regards,
dan carpenter

OK. You mean annotating both .c and .h, right? Will send v2 soon.

Thanks.

Signature · 2 lines
Regards,
Namhyung Kim
#8 lore raw
Quoted 9 lines · Namhyung Kim

2010-11-24 (수), 08:43 +0300, Dan Carpenter:

Quoted 8 lines · Namhyung Kim
Quoted 6 lines

2010-11-23 (화), 12:40 +0300, Dan Carpenter:

Quoted 1 line · Jens Axboe

I tried to annotate declations in include/linux/smp.h but it didn't work well. Maybe that's what we need to fix the sparse?

Quoted 8 lines
Quoted 6 lines

It worked for me earlier when I tested it. Just add the exact same annotations that you added to the .c file.

regards,
dan carpenter

OK. You mean annotating both .c and .h, right? Will send v2 soon.

Aside from complain, do these sparse annotations ever catch a bug?

I don't particularly like the __acquire() and __release() tags, but could possibly live with them when they only need to be in headers, but the __cond_lock() crap is just revolting.

#9 lore raw

2010-11-24 (수), 15:33 +0100, Peter Zijlstra:

Quoted 2 lines

Aside from complain, do these sparse annotations ever catch a bug?

Dunno, sorry. I only have very limited experience of kernel development.

Quoted 3 lines

I don't particularly like the __acquire() and __release() tags, but could possibly live with them when they only need to be in headers, but the __cond_lock() crap is just revolting.

Yes, it's very ugly. But some people told me it's a better way to describe conditional lock acquisition from complicated functions. It helped sparse recognize normal usage of such functions and suppress warnings but only warn themselves.

Signature · 2 lines
Regards,
Namhyung Kim