From: Kuniyuki Iwashima <kuniyu@amazon.com>
To: "David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Kuniyuki Iwashima <kuniyu@amazon.com>,
Kuniyuki Iwashima <kuni1840@gmail.com>, <netdev@vger.kernel.org>
Subject: [PATCH v2 net-next 05/14] rtnetlink: Move rtnl_link_ops_get() and retry to rtnl_newlink().
Date: Wed, 16 Oct 2024 11:53:48 -0700 [thread overview]
Message-ID: <20241016185357.83849-6-kuniyu@amazon.com> (raw)
In-Reply-To: <20241016185357.83849-1-kuniyu@amazon.com>
Currently, if neither dev nor rtnl_link_ops is found in __rtnl_newlink(),
we release RTNL and redo the whole process after request_module(), which
complicates the logic.
The ops will be RTNL-independent later.
Let's move the ops lookup to rtnl_newlink() and do the retry earlier.
Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
---
net/core/rtnetlink.c | 42 ++++++++++++++++++------------------------
1 file changed, 18 insertions(+), 24 deletions(-)
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 97d6ad65647c..e708f0852602 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -3690,23 +3690,19 @@ static int rtnl_newlink_create(struct sk_buff *skb, struct ifinfomsg *ifm,
}
static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
+ const struct rtnl_link_ops *ops,
struct rtnl_newlink_tbs *tbs,
struct netlink_ext_ack *extack)
{
struct nlattr ** const linkinfo = tbs->linkinfo;
struct nlattr ** const tb = tbs->tb;
struct net *net = sock_net(skb->sk);
- const struct rtnl_link_ops *ops;
- char kind[MODULE_NAME_LEN];
struct net_device *dev;
struct ifinfomsg *ifm;
struct nlattr **data;
bool link_specified;
int err;
-#ifdef CONFIG_MODULES
-replay:
-#endif
ifm = nlmsg_data(nlh);
if (ifm->ifi_index > 0) {
link_specified = true;
@@ -3722,14 +3718,6 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
dev = NULL;
}
- if (linkinfo[IFLA_INFO_KIND]) {
- nla_strscpy(kind, linkinfo[IFLA_INFO_KIND], sizeof(kind));
- ops = rtnl_link_ops_get(kind);
- } else {
- kind[0] = '\0';
- ops = NULL;
- }
-
data = NULL;
if (ops) {
if (ops->maxtype > RTNL_MAX_TYPE)
@@ -3770,16 +3758,6 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
return -EOPNOTSUPP;
if (!ops) {
-#ifdef CONFIG_MODULES
- if (kind[0]) {
- __rtnl_unlock();
- request_module("rtnl-link-%s", kind);
- rtnl_lock();
- ops = rtnl_link_ops_get(kind);
- if (ops)
- goto replay;
- }
-#endif
NL_SET_ERR_MSG(extack, "Unknown device type");
return -EOPNOTSUPP;
}
@@ -3790,6 +3768,7 @@ static int __rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
struct netlink_ext_ack *extack)
{
+ const struct rtnl_link_ops *ops = NULL;
struct nlattr **tb, **linkinfo;
struct rtnl_newlink_tbs *tbs;
int ret;
@@ -3819,7 +3798,22 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh,
memset(linkinfo, 0, sizeof(tbs->linkinfo));
}
- ret = __rtnl_newlink(skb, nlh, tbs, extack);
+ if (linkinfo[IFLA_INFO_KIND]) {
+ char kind[MODULE_NAME_LEN];
+
+ nla_strscpy(kind, linkinfo[IFLA_INFO_KIND], sizeof(kind));
+ ops = rtnl_link_ops_get(kind);
+#ifdef CONFIG_MODULES
+ if (!ops) {
+ __rtnl_unlock();
+ request_module("rtnl-link-%s", kind);
+ rtnl_lock();
+ ops = rtnl_link_ops_get(kind);
+ }
+#endif
+ }
+
+ ret = __rtnl_newlink(skb, nlh, ops, tbs, extack);
free:
kfree(tbs);
--
2.39.5 (Apple Git-154)
next prev parent reply other threads:[~2024-10-16 18:55 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-16 18:53 [PATCH v2 net-next 00/14] rtnetlink: Refactor rtnl_{new,del,set}link() for per-netns RTNL Kuniyuki Iwashima
2024-10-16 18:53 ` [PATCH v2 net-next 01/14] rtnetlink: Allocate linkinfo[] as struct rtnl_newlink_tbs Kuniyuki Iwashima
2024-10-16 18:53 ` [PATCH v2 net-next 02/14] rtnetlink: Call validate_linkmsg() in do_setlink() Kuniyuki Iwashima
2024-10-16 18:53 ` [PATCH v2 net-next 03/14] rtnetlink: Factorise do_setlink() path from __rtnl_newlink() Kuniyuki Iwashima
2024-10-16 18:53 ` [PATCH v2 net-next 04/14] rtnetlink: Move simple validation from __rtnl_newlink() to rtnl_newlink() Kuniyuki Iwashima
2024-10-16 18:53 ` Kuniyuki Iwashima [this message]
2024-10-16 18:53 ` [PATCH v2 net-next 06/14] rtnetlink: Move ops->validate " Kuniyuki Iwashima
2024-10-16 18:53 ` [PATCH v2 net-next 07/14] rtnetlink: Protect struct rtnl_link_ops with SRCU Kuniyuki Iwashima
2024-10-22 8:35 ` Paolo Abeni
2024-10-22 8:42 ` Paolo Abeni
2024-10-16 18:53 ` [PATCH v2 net-next 08/14] rtnetlink: Call rtnl_link_get_net_capable() in rtnl_newlink() Kuniyuki Iwashima
2024-10-16 18:53 ` [PATCH v2 net-next 09/14] rtnetlink: Fetch IFLA_LINK_NETNSID " Kuniyuki Iwashima
2024-10-16 18:53 ` [PATCH v2 net-next 10/14] rtnetlink: Clean up rtnl_dellink() Kuniyuki Iwashima
2024-10-16 18:53 ` [PATCH v2 net-next 11/14] rtnetlink: Clean up rtnl_setlink() Kuniyuki Iwashima
2024-10-16 18:53 ` [PATCH v2 net-next 12/14] rtnetlink: Call rtnl_link_get_net_capable() in do_setlink() Kuniyuki Iwashima
2024-10-16 18:53 ` [PATCH v2 net-next 13/14] rtnetlink: Return int from rtnl_af_register() Kuniyuki Iwashima
2024-10-16 19:09 ` David Ahern
2024-10-16 23:11 ` Kuniyuki Iwashima
2024-10-18 4:10 ` Matt Johnston
2024-10-22 8:53 ` Paolo Abeni
2024-10-22 8:59 ` Simon Horman
2024-10-22 19:42 ` Kuniyuki Iwashima
2024-10-16 18:53 ` [PATCH v2 net-next 14/14] rtnetlink: Protect struct rtnl_af_ops with SRCU Kuniyuki Iwashima
2024-10-22 9:10 ` [PATCH v2 net-next 00/14] rtnetlink: Refactor rtnl_{new,del,set}link() for per-netns RTNL patchwork-bot+netdevbpf
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=20241016185357.83849-6-kuniyu@amazon.com \
--to=kuniyu@amazon.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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;
as well as URLs for NNTP newsgroup(s).