netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtnl: Simplify ASSERT_RTNL
@ 2007-09-29  0:59 Eric W. Biederman
  2007-09-29  4:31 ` Herbert Xu
  2007-10-11  4:16 ` David Miller
  0 siblings, 2 replies; 20+ messages in thread
From: Eric W. Biederman @ 2007-09-29  0:59 UTC (permalink / raw)
  To: David Miller; +Cc: netdev


Currently we have the call path:
macvlan_open -> dev_unicast_add -> __dev_set_rx_mode ->
	__dev_set_promiscuity -> ASSERT_RTNL -> mutex_trylock

When mutex debugging is on taking a mutex complains if we are not
allowed to sleep.  At that point we have called netif_tx_lock_bh
so we are clearly not allowed to sleep.  Arguably this is not a
problem for mutex_trylock.

However we can avoid the complaint and make the ASSERT_RTNL code
cheaper, faster and more obvious by simply calling mutex_is_locked.

So this patch adds rtnl_is_locked (which does mutex_is_locked on
the rtnl_mutex) and changes ASSERT_RTNL to use that.

Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
 include/linux/rtnetlink.h |    4 ++--
 net/core/rtnetlink.c      |    5 +++++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
index dff3192..9c21e45 100644
--- a/include/linux/rtnetlink.h
+++ b/include/linux/rtnetlink.h
@@ -714,13 +714,13 @@ extern void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change);
 extern void rtnl_lock(void);
 extern void rtnl_unlock(void);
 extern int rtnl_trylock(void);
+extern int rtnl_is_locked(void);
 
 extern void rtnetlink_init(void);
 extern void __rtnl_unlock(void);
 
 #define ASSERT_RTNL() do { \
-	if (unlikely(rtnl_trylock())) { \
-		rtnl_unlock(); \
+	if (unlikely(!rtnl_is_locked())) { \
 		printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \
 		       __FILE__,  __LINE__); \
 		dump_stack(); \
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 739fbad..8bc68e6 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -85,6 +85,11 @@ int rtnl_trylock(void)
 	return mutex_trylock(&rtnl_mutex);
 }
 
+int rtnl_is_locked(void)
+{
+	return mutex_is_locked(&rtnl_mutex);
+}
+
 int rtattr_parse(struct rtattr *tb[], int maxattr, struct rtattr *rta, int len)
 {
 	memset(tb, 0, sizeof(struct rtattr*)*maxattr);
-- 
1.5.3.rc6.17.g1911


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2007-10-12  3:16 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-09-29  0:59 [PATCH] rtnl: Simplify ASSERT_RTNL Eric W. Biederman
2007-09-29  4:31 ` Herbert Xu
2007-09-29 15:32   ` Patrick McHardy
2007-09-30  0:24     ` Herbert Xu
2007-09-30 15:47       ` Patrick McHardy
2007-10-02  9:28         ` Herbert Xu
2007-10-02 15:29           ` Patrick McHardy
2007-10-03  6:06             ` Herbert Xu
2007-10-08  4:40               ` Patrick McHardy
2007-09-29 17:18   ` Eric W. Biederman
2007-09-29 17:51     ` Patrick McHardy
2007-09-30  0:28     ` Herbert Xu
2007-10-11  4:16 ` David Miller
2007-10-11  6:57   ` Eric W. Biederman
2007-10-11  7:12     ` Herbert Xu
2007-10-11  8:23       ` Eric W. Biederman
2007-10-11  8:28         ` Herbert Xu
2007-10-11 16:33           ` Eric W. Biederman
2007-10-12  0:30             ` David Miller
2007-10-12  3:15               ` Eric W. Biederman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).