From: Florian Westphal <fw@strlen•de>
To: <netdev@vger•kernel.org>
Cc: Florian Westphal <fw@strlen•de>
Subject: [PATCH v2 net-next 6/7] rtnetlink: add RTNL_FLAG_DOIT_UNLOCKED
Date: Wed, 9 Aug 2017 20:41:52 +0200 [thread overview]
Message-ID: <20170809184153.16700-7-fw@strlen.de> (raw)
In-Reply-To: <20170809184153.16700-1-fw@strlen.de>
Allow callers to tell rtnetlink core that its doit callback
should be invoked without holding rtnl mutex.
Signed-off-by: Florian Westphal <fw@strlen•de>
Reviewed-by: Hannes Frederic Sowa <hannes@stressinduktion•org>
---
change since v1: don't make ipv6 route rtnl handlers lockless
include/net/rtnetlink.h | 4 ++++
net/core/rtnetlink.c | 15 +++++++++++++++
2 files changed, 19 insertions(+)
diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
index ac32460a0adb..21837ca68ecc 100644
--- a/include/net/rtnetlink.h
+++ b/include/net/rtnetlink.h
@@ -8,6 +8,10 @@ typedef int (*rtnl_doit_func)(struct sk_buff *, struct nlmsghdr *,
struct netlink_ext_ack *);
typedef int (*rtnl_dumpit_func)(struct sk_buff *, struct netlink_callback *);
+enum rtnl_link_flags {
+ RTNL_FLAG_DOIT_UNLOCKED = 1,
+};
+
int __rtnl_register(int protocol, int msgtype,
rtnl_doit_func, rtnl_dumpit_func, unsigned int flags);
void rtnl_register(int protocol, int msgtype,
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index d45946177bc8..dd4e50dfa248 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -62,6 +62,7 @@
struct rtnl_link {
rtnl_doit_func doit;
rtnl_dumpit_func dumpit;
+ unsigned int flags;
};
static DEFINE_MUTEX(rtnl_mutex);
@@ -184,6 +185,7 @@ int __rtnl_register(int protocol, int msgtype,
tab[msgindex].doit = doit;
if (dumpit)
tab[msgindex].dumpit = dumpit;
+ tab[msgindex].flags |= flags;
return 0;
}
@@ -233,6 +235,7 @@ int rtnl_unregister(int protocol, int msgtype)
handlers[msgindex].doit = NULL;
handlers[msgindex].dumpit = NULL;
+ handlers[msgindex].flags = 0;
rtnl_unlock();
return 0;
@@ -4143,6 +4146,7 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
struct rtnl_link *handlers;
int err = -EOPNOTSUPP;
rtnl_doit_func doit;
+ unsigned int flags;
int kind;
int family;
int type;
@@ -4209,6 +4213,17 @@ static int rtnetlink_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh,
return err;
}
+ flags = READ_ONCE(handlers[type].flags);
+ if (flags & RTNL_FLAG_DOIT_UNLOCKED) {
+ refcount_inc(&rtnl_msg_handlers_ref[family]);
+ doit = READ_ONCE(handlers[type].doit);
+ rcu_read_unlock();
+ if (doit)
+ err = doit(skb, nlh, extack);
+ refcount_dec(&rtnl_msg_handlers_ref[family]);
+ return err;
+ }
+
rcu_read_unlock();
rtnl_lock();
--
2.13.0
next prev parent reply other threads:[~2017-08-09 18:42 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-09 18:41 [PATCH v2 net-next 0/7] rtnetlink: allow selected handlers to run without rtnl Florian Westphal
2017-08-09 18:41 ` [PATCH v2 net-next 1/7] rtnetlink: call rtnl_calcit directly Florian Westphal
2017-08-09 18:41 ` [PATCH v2 net-next 2/7] rtnetlink: make rtnl_register accept a flags parameter Florian Westphal
2017-08-09 18:41 ` [PATCH v2 net-next 3/7] rtnetlink: add reference counting to prevent module unload while dump is in progress Florian Westphal
2017-08-09 18:41 ` [PATCH v2 net-next 4/7] rtnetlink: small rtnl lock pushdown Florian Westphal
2017-08-09 18:41 ` [PATCH v2 net-next 5/7] rtnetlink: protect handler table with rcu Florian Westphal
2017-08-10 8:26 ` Ido Schimmel
2017-08-09 18:41 ` Florian Westphal [this message]
2017-08-09 18:41 ` [PATCH v2 net-next 7/7] net: call newid/getid without rtnl mutex held Florian Westphal
2017-08-10 0:21 ` [PATCH v2 net-next 0/7] rtnetlink: allow selected handlers to run without rtnl David Miller
2017-08-10 1:27 ` David Ahern
2017-08-10 11:29 ` Florian Westphal
2017-08-10 16:23 ` David Ahern
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=20170809184153.16700-7-fw@strlen.de \
--to=fw@strlen$(echo .)de \
--cc=netdev@vger$(echo .)kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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