fib: rules: Convert RTM_NEWRULE and RTM_DELRULE to per-netns RTNL.
Subsystems (4)
v2 cover fib: rules: Convert RTM_NEWRULE and RTM_DELRULE to per-netns RTNL.
Patch 1 ~ 2 are small cleanup, and patch 3 ~ 8 make fib_nl_newrule() and fib_nl_delrule() hold per-netns RTNL.
Changes:
v2:
* Add patch 4 & 5
* Don't use !!extack to check if RTNL is held
v1: https://lore.kernel.org/netdev/[email protected]/
Kuniyuki Iwashima (8):
net: fib_rules: Don't check net in rule_exists() and rule_find().
net: fib_rules: Pass net to fib_nl2rule() instead of skb.
net: fib_rules: Split fib_nl2rule().
ip: fib_rules: Fetch net from fib_rule in fib[46]_rule_configure().
net: fib_rules: Factorise fib_newrule() and fib_delrule().
net: fib_rules: Convert RTM_NEWRULE to per-netns RTNL.
net: fib_rules: Add error_free label in fib_delrule().
net: fib_rules: Convert RTM_DELRULE to per-netns RTNL.
drivers/net/vrf.c | 6 +- include/net/fib_rules.h | 8 +-- net/core/fib_rules.c | 151 ++++++++++++++++++++++++++-------------- net/ipv4/fib_rules.c | 4 +- net/ipv6/fib6_rules.c | 4 +- 5 files changed, 110 insertions(+), 63 deletions(-)
Signature · 1 line
2.39.5 (Apple Git-154)
PATCH v2 1/8 net: fib_rules: Don't check net in rule_exists() and rule_find().
fib_nl_newrule() / fib_nl_delrule() looks up struct fib_rules_ops in sock_net(skb->sk) and calls rule_exists() / rule_find() respectively.
fib_nl_newrule() creates a new rule and links it to the found ops, so struct fib_rule never belongs to a different netns's ops->rules_list.
Let's remove redundant netns check in rule_exists() and rule_find().
--- net/core/fib_rules.c | 6 ------ 1 file changed, 6 deletions(-)
net/core/fib_rules.c +0 -6
@@ -459,9 +459,6 @@ static struct fib_rule *rule_find(struct fib_rules_ops *ops,if (rule->tun_id && r->tun_id != rule->tun_id)continue ; -if (r->fr_net != rule->fr_net) -continue ; -if (rule->l3mdev && r->l3mdev != rule->l3mdev)continue ;
@@ -719,9 +716,6 @@ static int rule_exists(struct fib_rules_ops *ops, struct fib_rule_hdr *frh,if (r->tun_id != rule->tun_id)continue ; -if (r->fr_net != rule->fr_net) -continue ; -if (r->l3mdev != rule->l3mdev)continue ;
Signature · 1 line
2.39.5 (Apple Git-154)
PATCH v2 2/8 net: fib_rules: Pass net to fib_nl2rule() instead of skb.
In reply to Kuniyuki Iwashimaskb is not used in fib_nl2rule() other than sock_net(skb->sk), which is already available in callers, fib_nl_newrule() and fib_nl_delrule().
Let's pass net directly to fib_nl2rule().
--- net/core/fib_rules.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
net/core/fib_rules.c +3 -4
@@ -512,14 +512,13 @@ static int fib_nl2rule_l3mdev(struct nlattr *nla, struct fib_rule *nlrule, }#endif -static int fib_nl2rule (struct sk_buff *skb,struct nlmsghdr *nlh, +static int fib_nl2rule (struct net *net,struct nlmsghdr *nlh,struct netlink_ext_ack *extack,struct fib_rules_ops *ops,struct nlattr *tb[],struct fib_rule **rule,bool *user_priority) { -struct net *net =sock_net (skb->sk);struct fib_rule_hdr *frh =nlmsg_data (nlh);struct fib_rule *nlrule =NULL ;int err = -EINVAL ;
@@ -798,7 +797,7 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh, goto errout; } - err =fib_nl2rule (skb, nlh, extack, ops, tb, &rule, &user_priority); + err =fib_nl2rule (net, nlh, extack, ops, tb, &rule, &user_priority);if (err) goto errout;
@@ -906,7 +905,7 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, goto errout; } - err =fib_nl2rule (skb, nlh, extack, ops, tb, &nlrule, &user_priority); + err =fib_nl2rule (net, nlh, extack, ops, tb, &nlrule, &user_priority);if (err) goto errout;
Signature · 1 line
2.39.5 (Apple Git-154)
PATCH v2 3/8 net: fib_rules: Split fib_nl2rule().
In reply to Kuniyuki IwashimaWe will move RTNL down to fib_nl_newrule() and fib_nl_delrule().
Some operations in fib_nl2rule() require RTNL: fib_default_rule_pref() and __dev_get_by_name().
Let's split the RTNL parts as fib_nl2rule_rtnl().
--- net/core/fib_rules.c | 58 +++++++++++++++++++++++++++++++------------- 1 file changed, 41 insertions(+), 17 deletions(-)
net/core/fib_rules.c +41 -17
@@ -550,30 +550,18 @@ static int fib_nl2rule(struct net *net, struct nlmsghdr *nlh,if (tb[FRA_PRIORITY ]) { nlrule->pref =nla_get_u32 (tb[FRA_PRIORITY ]); *user_priority = true; - }else { - nlrule->pref =fib_default_rule_pref (ops); } nlrule->proto =nla_get_u8_default (tb[FRA_PROTOCOL ],RTPROT_UNSPEC );if (tb[FRA_IIFNAME ]) { -struct net_device *dev; - nlrule->iifindex =-1 ;nla_strscpy (nlrule->iifname, tb[FRA_IIFNAME ],IFNAMSIZ ); - dev =__dev_get_by_name (net, nlrule->iifname); -if (dev) - nlrule->iifindex = dev->ifindex; }if (tb[FRA_OIFNAME ]) { -struct net_device *dev; - nlrule->oifindex =-1 ;nla_strscpy (nlrule->oifname, tb[FRA_OIFNAME ],IFNAMSIZ ); - dev =__dev_get_by_name (net, nlrule->oifname); -if (dev) - nlrule->oifindex = dev->ifindex; }if (tb[FRA_FWMARK ]) {
@@ -615,11 +603,6 @@ static int fib_nl2rule(struct net *net, struct nlmsghdr *nlh, } nlrule->target =nla_get_u32 (tb[FRA_GOTO ]); -/* Backward jumps are prohibited to avoid endless loops */ -if (nlrule->target <= nlrule->pref) { -NL_SET_ERR_MSG (extack,"Backward goto not supported" ); - goto errout_free; - } }else if (nlrule->action ==FR_ACT_GOTO ) {NL_SET_ERR_MSG (extack,"Missing goto target for action goto" ); goto errout_free;
@@ -679,6 +662,39 @@ static int fib_nl2rule(struct net *net, struct nlmsghdr *nlh,return err; } +static int fib_nl2rule_rtnl (struct fib_rule *nlrule, +struct fib_rules_ops *ops, +struct nlattr *tb[], +struct netlink_ext_ack *extack) +{ +if (!tb[FRA_PRIORITY ]) + nlrule->pref =fib_default_rule_pref (ops); + +/* Backward jumps are prohibited to avoid endless loops */ +if (tb[FRA_GOTO ] && nlrule->target <= nlrule->pref) { +NL_SET_ERR_MSG (extack,"Backward goto not supported" ); +return -EINVAL ; + } + +if (tb[FRA_IIFNAME ]) { +struct net_device *dev; + + dev =__dev_get_by_name (nlrule->fr_net, nlrule->iifname); +if (dev) + nlrule->iifindex = dev->ifindex; + } + +if (tb[FRA_OIFNAME ]) { +struct net_device *dev; + + dev =__dev_get_by_name (nlrule->fr_net, nlrule->oifname); +if (dev) + nlrule->oifindex = dev->ifindex; + } + +return 0 ; +} +static int rule_exists (struct fib_rules_ops *ops,struct fib_rule_hdr *frh,struct nlattr **tb,struct fib_rule *rule) {
@@ -801,6 +817,10 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh,if (err) goto errout; + err =fib_nl2rule_rtnl (rule, ops, tb, extack); +if (err) + goto errout_free; +if ((nlh->nlmsg_flags &NLM_F_EXCL ) &&rule_exists (ops, frh, tb, rule)) { err = -EEXIST ;
@@ -909,6 +929,10 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh,if (err) goto errout; + err =fib_nl2rule_rtnl (nlrule, ops, tb, extack); +if (err) + goto errout; + rule =rule_find (ops, frh, tb, nlrule, user_priority);if (!rule) { err = -ENOENT ;
Signature · 1 line
2.39.5 (Apple Git-154)
PATCH v2 4/8 ip: fib_rules: Fetch net from fib_rule in fib[46]_rule_configure().
In reply to Kuniyuki IwashimaThe following patch will not set skb->sk from VRF path.
Let's fetch net from fib_rule->fr_net instead of sock_net(skb->sk) in fib[46]_rule_configure().
--- net/ipv4/fib_rules.c | 4 ++-- net/ipv6/fib6_rules.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)
net/ipv4/fib_rules.c +2 -2
@@ -245,9 +245,9 @@ static int fib4_rule_configure(struct fib_rule *rule, struct sk_buff *skb,struct nlattr **tb, struct netlink_ext_ack *extack) { - struct net *net = sock_net(skb->sk); + struct fib4_rule *rule4 = (struct fib4_rule *)rule; +struct net *net = rule->fr_net;int err = -EINVAL ; -struct fib4_rule *rule4 = (struct fib4_rule *) rule;if (tb[FRA_FLOWLABEL ] || tb[FRA_FLOWLABEL_MASK ]) { NL_SET_ERR_MSG(extack,
net/ipv6/fib6_rules.c +2 -2
@@ -399,9 +399,9 @@ static int fib6_rule_configure(struct fib_rule *rule, struct sk_buff *skb,struct nlattr **tb, struct netlink_ext_ack *extack) { + struct fib6_rule *rule6 = (struct fib6_rule *)rule; +struct net *net = rule->fr_net;int err = -EINVAL ; -struct net *net =sock_net (skb->sk); -struct fib6_rule *rule6 = (struct fib6_rule *) rule;if (!inet_validate_dscp (frh->tos)) { NL_SET_ERR_MSG(extack,
Signature · 1 line
2.39.5 (Apple Git-154)
PATCH v2 5/8 net: fib_rules: Factorise fib_newrule() and fib_delrule().
In reply to Kuniyuki Iwashimafib_nl_newrule() / fib_nl_delrule() is the doit() handler for RTM_NEWRULE / RTM_DELRULE but also called from vrf_newlink().
Currently, we hold RTNL on both paths but will not on the former.
Also, we set dev_net(dev)->rtnl to skb->sk in vrf_fib_rule() because fib_nl_newrule() / fib_nl_delrule() fetch net as sock_net(skb->sk).
Let's Factorise the two functions and pass net and rtnl_held flag.
--- drivers/net/vrf.c | 6 ++---- include/net/fib_rules.h | 8 ++++---- net/core/fib_rules.c | 36 +++++++++++++++++++++++------------- 3 files changed, 29 insertions(+), 21 deletions(-)
drivers/net/vrf.c +2 -4
@@ -1537,14 +1537,12 @@ static int vrf_fib_rule(const struct net_device *dev, __u8 family, bool add_it)nlmsg_end (skb, nlh); -/* fib_nl_{new,del}rule handling looks for net from skb->sk */ - skb->sk =dev_net (dev)->rtnl;if (add_it) { - err =fib_nl_newrule (skb, nlh,NULL ); + err =fib_newrule (dev_net (dev), skb, nlh,NULL , true);if (err == -EEXIST ) err =0 ; }else { - err =fib_nl_delrule (skb, nlh,NULL ); + err =fib_delrule (dev_net (dev), skb, nlh,NULL , true);if (err == -ENOENT ) err =0 ; }
include/net/fib_rules.h +4 -4
@@ -178,10 +178,10 @@ int fib_rules_dump(struct net *net, struct notifier_block *nb, int family, struct netlink_ext_ack *extack);unsigned int fib_rules_seq_read (const struct net *net,int family); -int fib_nl_newrule (struct sk_buff *skb,struct nlmsghdr *nlh, -struct netlink_ext_ack *extack); -int fib_nl_delrule (struct sk_buff *skb,struct nlmsghdr *nlh, -struct netlink_ext_ack *extack); +int fib_newrule (struct net *net,struct sk_buff *skb,struct nlmsghdr *nlh, +struct netlink_ext_ack *extack,bool rtnl_held); +int fib_delrule (struct net *net,struct sk_buff *skb,struct nlmsghdr *nlh, +struct netlink_ext_ack *extack,bool rtnl_held); INDIRECT_CALLABLE_DECLARE(int fib6_rule_match(struct fib_rule *rule,struct flowi *fl,int flags));
net/core/fib_rules.c +23 -13
@@ -783,15 +783,14 @@ static const struct nla_policy fib_rule_policy[FRA_MAX + 1] = { [FRA_FLOWLABEL_MASK] = { .type = NLA_BE32 }, }; -int fib_nl_newrule (struct sk_buff *skb,struct nlmsghdr *nlh, -struct netlink_ext_ack *extack) +int fib_newrule (struct net *net,struct sk_buff *skb,struct nlmsghdr *nlh, +struct netlink_ext_ack *extack,bool rtnl_held) { -struct net *net =sock_net (skb->sk); +struct fib_rule *rule =NULL , *r, *last =NULL ;struct fib_rule_hdr *frh =nlmsg_data (nlh); +int err = -EINVAL , unresolved =0 ;struct fib_rules_ops *ops =NULL ; -struct fib_rule *rule =NULL , *r, *last =NULL ;struct nlattr *tb[FRA_MAX +1 ]; -int err = -EINVAL , unresolved =0 ;bool user_priority = false;if (nlh->nlmsg_len <nlmsg_msg_size (sizeof (*frh))) {
@@ -893,18 +892,23 @@ int fib_nl_newrule(struct sk_buff *skb, struct nlmsghdr *nlh,rules_ops_put (ops);return err; } -EXPORT_SYMBOL_GPL (fib_nl_newrule); +EXPORT_SYMBOL_GPL (fib_newrule); -int fib_nl_delrule (struct sk_buff *skb,struct nlmsghdr *nlh, -struct netlink_ext_ack *extack) +static int fib_nl_newrule (struct sk_buff *skb,struct nlmsghdr *nlh, +struct netlink_ext_ack *extack) { -struct net *net =sock_net (skb->sk); +return fib_newrule (sock_net (skb->sk), skb, nlh, extack, true); +} + +int fib_delrule (struct net *net,struct sk_buff *skb,struct nlmsghdr *nlh, +struct netlink_ext_ack *extack,bool rtnl_held) +{ +struct fib_rule *rule =NULL , *nlrule =NULL ;struct fib_rule_hdr *frh =nlmsg_data (nlh);struct fib_rules_ops *ops =NULL ; -struct fib_rule *rule =NULL , *r, *nlrule =NULL ;struct nlattr *tb[FRA_MAX +1 ]; -int err = -EINVAL ;bool user_priority = false; +int err = -EINVAL ;if (nlh->nlmsg_len <nlmsg_msg_size (sizeof (*frh))) {NL_SET_ERR_MSG (extack,"Invalid msg length" );
@@ -969,7 +973,7 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh,* current if it is goto rule, have actually been added. */ if (ops->nr_goto_rules >0 ) { -struct fib_rule *n; +struct fib_rule *n, *r; n =list_next_entry (rule, list);if (&n->list == &ops->rules_list || n->pref != rule->pref)
@@ -998,7 +1002,13 @@ int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh,rules_ops_put (ops);return err; } -EXPORT_SYMBOL_GPL (fib_nl_delrule); +EXPORT_SYMBOL_GPL (fib_delrule); + +static int fib_nl_delrule (struct sk_buff *skb,struct nlmsghdr *nlh, +struct netlink_ext_ack *extack) +{ +return fib_delrule (sock_net (skb->sk), skb, nlh, extack, true); +}static inline size_t fib_rule_nlmsg_size (struct fib_rules_ops *ops,struct fib_rule *rule)
Signature · 1 line
2.39.5 (Apple Git-154)
PATCH v2 6/8 net: fib_rules: Convert RTM_NEWRULE to per-netns RTNL.
In reply to Kuniyuki Iwashimafib_nl_newrule() is the doit() handler for RTM_NEWRULE but also called from vrf_newlink().
In the latter case, RTNL is already held and the 4th arg is true.
Let's hold per-netns RTNL in fib_newrule() if rtnl_held is false.
Note that we call fib_rule_get() before releasing per-netns RTNL to call notify_rule_change() without RTNL and prevent freeing the new rule.
--- net/core/fib_rules.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
net/core/fib_rules.c +14 -2
@@ -816,6 +816,9 @@ int fib_newrule(struct net *net, struct sk_buff *skb, struct nlmsghdr *nlh,if (err) goto errout; +if (!rtnl_held) +rtnl_net_lock (net); + err =fib_nl2rule_rtnl (rule, ops, tb, extack);if (err) goto errout_free;
@@ -881,12 +884,20 @@ int fib_newrule(struct net *net, struct sk_buff *skb, struct nlmsghdr *nlh,if (rule->tun_id)ip_tunnel_need_metadata (); +fib_rule_get (rule); + +if (!rtnl_held) +rtnl_net_unlock (net); +notify_rule_change (RTM_NEWRULE , rule, ops, nlh,NETLINK_CB (skb).portid); +fib_rule_put (rule);flush_route_cache (ops);rules_ops_put (ops);return 0 ; errout_free: +if (!rtnl_held) +rtnl_net_unlock (net);kfree (rule); errout:rules_ops_put (ops);
@@ -897,7 +908,7 @@ EXPORT_SYMBOL_GPL(fib_newrule);static int fib_nl_newrule (struct sk_buff *skb,struct nlmsghdr *nlh,struct netlink_ext_ack *extack) { -return fib_newrule (sock_net (skb->sk), skb, nlh, extack, true); +return fib_newrule (sock_net (skb->sk), skb, nlh, extack, false); } int fib_delrule(struct net *net, struct sk_buff *skb, struct nlmsghdr *nlh,
@@ -1320,7 +1331,8 @@ static struct pernet_operations fib_rules_net_ops = { };static const struct rtnl_msg_handler fib_rules_rtnl_msg_handlers[]__initconst = { - {.msgtype =RTM_NEWRULE , .doit = fib_nl_newrule}, + {.msgtype =RTM_NEWRULE , .doit = fib_nl_newrule, + .flags =RTNL_FLAG_DOIT_PERNET }, {.msgtype =RTM_DELRULE , .doit = fib_nl_delrule}, {.msgtype =RTM_GETRULE , .dumpit = fib_nl_dumprule, .flags =RTNL_FLAG_DUMP_UNLOCKED },
Signature · 1 line
2.39.5 (Apple Git-154)
PATCH v2 7/8 net: fib_rules: Add error_free label in fib_delrule().
In reply to Kuniyuki IwashimaWe will hold RTNL just before calling fib_nl2rule_rtnl() in fib_delrule() and release it before kfree(nlrule).
Let's add a new rule to make the following change cleaner.
--- net/core/fib_rules.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
net/core/fib_rules.c +6 -5
@@ -946,23 +946,23 @@ int fib_delrule(struct net *net, struct sk_buff *skb, struct nlmsghdr *nlh, err =fib_nl2rule_rtnl (nlrule, ops, tb, extack);if (err) - goto errout; + goto errout_free; rule =rule_find (ops, frh, tb, nlrule, user_priority);if (!rule) { err = -ENOENT ; - goto errout; + goto errout_free; }if (rule->flags &FIB_RULE_PERMANENT ) { err = -EPERM ; - goto errout; + goto errout_free; }if (ops->delete) { err = ops->delete (rule);if (err) - goto errout; + goto errout_free; }if (rule->tun_id)
@@ -1008,8 +1008,9 @@ int fib_delrule(struct net *net, struct sk_buff *skb, struct nlmsghdr *nlh,kfree (nlrule);return 0 ; -errout: +errout_free:kfree (nlrule); +errout:rules_ops_put (ops);return err; }
Signature · 1 line
2.39.5 (Apple Git-154)
PATCH v2 8/8 net: fib_rules: Convert RTM_DELRULE to per-netns RTNL.
In reply to Kuniyuki Iwashimafib_nl_delrule() is the doit() handler for RTM_DELRULE but also called from vrf_newlink() in case something fails in vrf_add_fib_rules().
In the latter case, RTNL is already held and the 4th arg is true.
Let's hold per-netns RTNL in fib_delrule() if rtnl_held is false.
Now we can place ASSERT_RTNL_NET() in call_fib_rule_notifiers().
--- net/core/fib_rules.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-)
net/core/fib_rules.c +16 -7
@@ -371,7 +371,8 @@ static int call_fib_rule_notifiers(struct net *net, .rule = rule, }; -ASSERT_RTNL (); +ASSERT_RTNL_NET (net); +/* Paired with READ_ONCE() in fib_rules_seq() */ WRITE_ONCE (ops->fib_rules_seq, ops->fib_rules_seq +1 );return call_fib_notifiers (net, event_type, &info.info);
@@ -944,6 +945,9 @@ int fib_delrule(struct net *net, struct sk_buff *skb, struct nlmsghdr *nlh,if (err) goto errout; +if (!rtnl_held) +rtnl_net_lock (net); + err =fib_nl2rule_rtnl (nlrule, ops, tb, extack);if (err) goto errout_free;
@@ -998,10 +1002,12 @@ int fib_delrule(struct net *net, struct sk_buff *skb, struct nlmsghdr *nlh, } } -call_fib_rule_notifiers (net,FIB_EVENT_RULE_DEL , rule, ops, -NULL ); -notify_rule_change (RTM_DELRULE , rule, ops, nlh, -NETLINK_CB (skb).portid); +call_fib_rule_notifiers (net,FIB_EVENT_RULE_DEL , rule, ops,NULL ); + +if (!rtnl_held) +rtnl_net_unlock (net); + +notify_rule_change (RTM_DELRULE , rule, ops, nlh,NETLINK_CB (skb).portid);fib_rule_put (rule);flush_route_cache (ops);rules_ops_put (ops);
@@ -1009,6 +1015,8 @@ int fib_delrule(struct net *net, struct sk_buff *skb, struct nlmsghdr *nlh,return 0 ; errout_free: +if (!rtnl_held) +rtnl_net_unlock (net);kfree (nlrule); errout:rules_ops_put (ops);
@@ -1019,7 +1027,7 @@ EXPORT_SYMBOL_GPL(fib_delrule);static int fib_nl_delrule (struct sk_buff *skb,struct nlmsghdr *nlh,struct netlink_ext_ack *extack) { -return fib_delrule (sock_net (skb->sk), skb, nlh, extack, true); +return fib_delrule (sock_net (skb->sk), skb, nlh, extack, false); } static inline size_t fib_rule_nlmsg_size(struct fib_rules_ops *ops,
@@ -1334,7 +1342,8 @@ static struct pernet_operations fib_rules_net_ops = {static const struct rtnl_msg_handler fib_rules_rtnl_msg_handlers[]__initconst = { {.msgtype =RTM_NEWRULE , .doit = fib_nl_newrule, .flags =RTNL_FLAG_DOIT_PERNET }, - {.msgtype =RTM_DELRULE , .doit = fib_nl_delrule}, + {.msgtype =RTM_DELRULE , .doit = fib_nl_delrule, + .flags =RTNL_FLAG_DOIT_PERNET }, {.msgtype =RTM_GETRULE , .dumpit = fib_nl_dumprule, .flags =RTNL_FLAG_DUMP_UNLOCKED }, };
Signature · 1 line
2.39.5 (Apple Git-154)
Re: [PATCH v2 net-next 1/8] net: fib_rules: Don't check net in rule_exists() and rule_find().
In reply to Kuniyuki IwashimaQuoted 10 lines · Kuniyuki Iwashima
fib_nl_newrule()/fib_nl_delrule()looks up structfib_rules_opsinsock_net(skb->sk)and callsrule_exists()/rule_find()respectively.
fib_nl_newrule()creates a new rule and links it to the found ops, so structfib_rulenever belongs to a different netns'sops->rules_list.Let's remove redundant netns check in
rule_exists()andrule_find().Signed-off-by Kuniyuki Iwashima <[email protected]>
Re: [PATCH v2 net-next 2/8] net: fib_rules: Pass net to fib_nl2rule() instead of skb.
In reply to Kuniyuki IwashimaQuoted 8 lines · Kuniyuki Iwashima
skb is not used in
fib_nl2rule()other thansock_net(skb->sk), which is already available in callers,fib_nl_newrule()andfib_nl_delrule().Let's pass net directly to
fib_nl2rule().Signed-off-by Kuniyuki Iwashima <[email protected]>
Re: [PATCH v2 net-next 3/8] net: fib_rules: Split fib_nl2rule().
In reply to Kuniyuki IwashimaQuoted 9 lines · Kuniyuki Iwashima
We will move RTNL down to
fib_nl_newrule()andfib_nl_delrule().Some operations in
fib_nl2rule()require RTNL:fib_default_rule_pref()and__dev_get_by_name().Let's split the RTNL parts as
fib_nl2rule_rtnl().Signed-off-by Kuniyuki Iwashima <[email protected]>
Re: [PATCH v2 net-next 5/8] net: fib_rules: Factorise fib_newrule() and fib_delrule().
In reply to Kuniyuki IwashimaQuoted 4 lines · Kuniyuki Iwashima
fib_nl_newrule()/fib_nl_delrule()is thedoit()handler forRTM_NEWRULE/RTM_DELRULEbut also called fromvrf_newlink().
Quoted 8 lines
Currently, we hold RTNL on both paths but will not on the former.
Also, we set dev_net(dev)->rtnl to
skb->skinvrf_fib_rule()becausefib_nl_newrule()/fib_nl_delrule()fetch net assock_net(skb->sk).Let's Factorise the two functions and pass net and
rtnl_heldflag.Signed-off-by Kuniyuki Iwashima <[email protected]>
Much nicer, thanks !
Re: [PATCH v2 net-next 4/8] ip: fib_rules: Fetch net from fib_rule in fib[46]_rule_configure().
In reply to Kuniyuki IwashimaQuoted 7 lines · Kuniyuki Iwashima
The following patch will not set
skb->skfrom VRF path.Let's fetch net from
fib_rule->fr_netinstead ofsock_net(skb->sk)in fib[46]_rule_configure().Signed-off-by Kuniyuki Iwashima <[email protected]>
Re: [PATCH v2 net-next 6/8] net: fib_rules: Convert RTM_NEWRULE to per-netns RTNL.
In reply to Kuniyuki IwashimaQuoted 6 lines · Kuniyuki Iwashima
fib_nl_newrule()is thedoit()handler forRTM_NEWRULEbut also called fromvrf_newlink().In the latter case, RTNL is already held and the 4th arg is true.
Quoted 7 lines
Let's hold per-netns RTNL in
fib_newrule()ifrtnl_heldis false.Note that we call
fib_rule_get()before releasing per-netns RTNL to callnotify_rule_change()without RTNL and prevent freeing the new rule.Signed-off-by Kuniyuki Iwashima <[email protected]>---
Re: [PATCH v2 net-next 8/8] net: fib_rules: Convert RTM_DELRULE to per-netns RTNL.
In reply to Kuniyuki IwashimaQuoted 11 lines · Kuniyuki Iwashima
fib_nl_delrule()is thedoit()handler forRTM_DELRULEbut also called fromvrf_newlink()in case something fails invrf_add_fib_rules().In the latter case, RTNL is already held and the 4th arg is true.
Let's hold per-netns RTNL in
fib_delrule()ifrtnl_heldis false.Now we can place
ASSERT_RTNL_NET()incall_fib_rule_notifiers().Signed-off-by Kuniyuki Iwashima <[email protected]>
Re: [PATCH v2 net-next 7/8] net: fib_rules: Add error_free label in fib_delrule().
In reply to Kuniyuki IwashimaQuoted 7 lines · Kuniyuki Iwashima
We will hold RTNL just before calling
fib_nl2rule_rtnl()infib_delrule()and release it before kfree(nlrule).Let's add a new rule to make the following change cleaner.
Signed-off-by Kuniyuki Iwashima <[email protected]>
Quoted 5 lines · Kuniyuki Iwashima
Patch 1 ~ 2 are small cleanup, and patch 3 ~ 8 make
fib_nl_newrule()andfib_nl_delrule()hold per-netns RTNL.
Quoted 7 lines
Changes:
v2:
* Add patch 4 & 5
* Don't use !!extack to check if RTNL is held
Quoted 2 lines · Kuniyuki Iwashima
Patch 1 ~ 2 are small cleanup, and patch 3 ~ 8 make
fib_nl_newrule()andfib_nl_delrule()hold per-netns RTNL.
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Fri, 7 Feb 2025 16:24:54 +0900 you wrote:
Patch 1 ~ 2 are small cleanup, and patch 3 ~ 8 make
fib_nl_newrule()andfib_nl_delrule()hold per-netns RTNL.Changes:
v2:
* Add patch 4 & 5
* Don't use !!extack to check if RTNL is held[...]
Here is the summary with links:
- [v2,net-next,1/8] net: fib_rules: Don't check net in rule_exists() and rule_find().
https://git.kernel.org/netdev/net-next/c/7b7df666a233 - [v2,net-next,2/8] net: fib_rules: Pass net to fib_nl2rule() instead of skb. https://git.kernel.org/netdev/net-next/c/a9ffd24b5528 - [v2,net-next,3/8] net: fib_rules: Split fib_nl2rule(). https://git.kernel.org/netdev/net-next/c/8b498773c861 - [v2,net-next,4/8] ip: fib_rules: Fetch net from fib_rule in fib[46]_rule_configure(). https://git.kernel.org/netdev/net-next/c/5a1ccffd30a0 - [v2,net-next,5/8] net: fib_rules: Factorise fib_newrule() and fib_delrule(). https://git.kernel.org/netdev/net-next/c/a0596c2c63fc - [v2,net-next,6/8] net: fib_rules: Convert RTM_NEWRULE to per-netns RTNL. https://git.kernel.org/netdev/net-next/c/98d3a6f681ca - [v2,net-next,7/8] net: fib_rules: Add error_free label in fib_delrule(). https://git.kernel.org/netdev/net-next/c/1cf770da0112 - [v2,net-next,8/8] net: fib_rules: Convert RTM_DELRULE to per-netns RTNL. https://git.kernel.org/netdev/net-next/c/88b9cfca8d77
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html