nexthop: Convert RTM_{NEW,DEL}NEXTHOP to per-netns RTNL.
Subsystems (3)
v2 cover nexthop: Convert RTM_{NEW,DEL}NEXTHOP to per-netns RTNL.
Patch 1 - 5 move some validation for RTM_NEWNEXTHOP so that it can be called without RTNL.
Patch 6 & 7 converts RTM_NEWNEXTHOP and RTM_DELNEXTHOP to per-netns RTNL.
Note that RTM_GETNEXTHOP and RTM_GETNEXTHOPBUCKET are not touched in this series.
rtm_get_nexthop() can be easily converted to RCU, but rtm_dump_nexthop() needs more work due to the left-to-right rbtree walk, which looks prone to node deletion and tree rotation without a retry mechanism.
Changes:
v2:
* Patch 2
* Correct err check in rtm_new_nexthop()
v1: https://lore.kernel.org/netdev/[email protected]/
Kuniyuki Iwashima (7):
nexthop: Move nlmsg_parse() in rtm_to_nh_config() to
rtm_new_nexthop().
nexthop: Split nh_check_attr_group().
nexthop: Move NHA_OIF validation to rtm_to_nh_config_rtnl().
nexthop: Check NLM_F_REPLACE and NHA_ID in rtm_new_nexthop().
nexthop: Remove redundant group len check in nexthop_create_group().
nexthop: Convert RTM_NEWNEXTHOP to per-netns RTNL.
nexthop: Convert RTM_DELNEXTHOP to per-netns RTNL.
net/ipv4/nexthop.c | 183 +++++++++++++++++++++++++++------------------ 1 file changed, 112 insertions(+), 71 deletions(-)
Signature · 1 line
2.48.1
PATCH v2 1/7 nexthop: Move nlmsg_parse() in rtm_to_nh_config() to rtm_new_nexthop().
We will split rtm_to_nh_config() into non-RTNL and RTNL parts, and then the latter also needs tb.
As a prep, let's move nlmsg_parse() to rtm_new_nexthop().
--- net/ipv4/nexthop.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-)
net/ipv4/nexthop.c +18 -15
@@ -3016,19 +3016,13 @@ static int rtm_to_nh_config_grp_res(struct nlattr *res, struct nh_config *cfg, }static int rtm_to_nh_config (struct net *net,struct sk_buff *skb, -struct nlmsghdr *nlh,struct nh_config *cfg, +struct nlmsghdr *nlh,struct nlattr **tb, +struct nh_config *cfg,struct netlink_ext_ack *extack) {struct nhmsg *nhm =nlmsg_data (nlh); -struct nlattr *tb[ARRAY_SIZE (rtm_nh_policy_new)];int err; - err =nlmsg_parse (nlh,sizeof (*nhm), tb, -ARRAY_SIZE (rtm_nh_policy_new) -1 , - rtm_nh_policy_new, extack); -if (err <0 ) -return err; - err = -EINVAL ;if (nhm->resvd || nhm->nh_scope) {NL_SET_ERR_MSG (extack,"Invalid values in ancillary header" );
@@ -3093,7 +3087,8 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb,NL_SET_ERR_MSG (extack,"Invalid group type" ); goto out; } - err =nh_check_attr_group (net, tb,ARRAY_SIZE (tb), + + err =nh_check_attr_group (net, tb,ARRAY_SIZE (rtm_nh_policy_new), cfg->nh_grp_type, extack);if (err) goto out;
@@ -3211,18 +3206,26 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb,static int rtm_new_nexthop (struct sk_buff *skb,struct nlmsghdr *nlh,struct netlink_ext_ack *extack) { +struct nlattr *tb[ARRAY_SIZE (rtm_nh_policy_new)];struct net *net =sock_net (skb->sk);struct nh_config cfg;struct nexthop *nh;int err; - err =rtm_to_nh_config (net, skb, nlh, &cfg, extack); -if (!err) { - nh =nexthop_add (net, &cfg, extack); -if (IS_ERR (nh)) - err =PTR_ERR (nh); - } + err =nlmsg_parse (nlh,sizeof (struct nhmsg ), tb, +ARRAY_SIZE (rtm_nh_policy_new) -1 , + rtm_nh_policy_new, extack); +if (err <0 ) + goto out; + err =rtm_to_nh_config (net, skb, nlh, tb, &cfg, extack); +if (err) + goto out; + + nh =nexthop_add (net, &cfg, extack); +if (IS_ERR (nh)) + err =PTR_ERR (nh); +out:return err; }
Signature · 1 line
2.48.1
Re: [PATCH v2 net-next 1/7] nexthop: Move nlmsg_parse() in rtm_to_nh_config() to rtm_new_nexthop().
Quoted 10 lines · Kuniyuki Iwashima
We will split
rtm_to_nh_config()into non-RTNL and RTNL parts, and then the latter also needs tb.As a prep, let's move
nlmsg_parse()tortm_new_nexthop().Signed-off-by Kuniyuki Iwashima <[email protected]>--- net/ipv4/nexthop.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-)
Re: [PATCH v2 net-next 1/7] nexthop: Move nlmsg_parse() in rtm_to_nh_config() to rtm_new_nexthop().
In reply to Kuniyuki IwashimaQuoted 7 lines · Kuniyuki Iwashima
We will split
rtm_to_nh_config()into non-RTNL and RTNL parts, and then the latter also needs tb.As a prep, let's move
nlmsg_parse()tortm_new_nexthop().Signed-off-by Kuniyuki Iwashima <[email protected]>
PATCH v2 2/7 nexthop: Split nh_check_attr_group().
In reply to Kuniyuki IwashimaWe will push RTNL down to rtm_new_nexthop(), and then we want to move non-RTNL operations out of the scope.
nh_check_attr_group() validates NHA_GROUP attributes, and nexthop_find_by_id() and some validation requires RTNL.
Let's factorise such parts as nh_check_attr_group_rtnl() and call it from rtm_to_nh_config_rtnl().
--- net/ipv4/nexthop.c | 68 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 21 deletions(-)
net/ipv4/nexthop.c +47 -21
@@ -1272,10 +1272,8 @@ static int nh_check_attr_group(struct net *net, u16 nh_grp_type, struct netlink_ext_ack *extack) { unsigned int len = nla_len(tb[NHA_GROUP]); -u8 nh_family =AF_UNSPEC ;struct nexthop_grp *nhg;unsigned int i, j; -u8 nhg_fdb =0 ;if (!len || len & (sizeof (struct nexthop_grp ) -1 )) { NL_SET_ERR_MSG(extack,
@@ -1307,10 +1305,41 @@ static int nh_check_attr_group(struct net *net, } } -if (tb[NHA_FDB ]) - nhg_fdb =1 ; nhg =nla_data (tb[NHA_GROUP ]); -for (i =0 ; i < len; ++i) { +for (i =NHA_GROUP_TYPE +1 ; i < tb_size; ++i) { +if (!tb[i]) +continue ; +switch (i) { +case NHA_HW_STATS_ENABLE : +case NHA_FDB : +continue ; +case NHA_RES_GROUP : +if (nh_grp_type ==NEXTHOP_GRP_TYPE_RES ) +continue ; +break ; + } +NL_SET_ERR_MSG (extack, +"No other attributes can be set in nexthop groups" ); +return -EINVAL ; + } + +return 0 ; +} + +static int nh_check_attr_group_rtnl (struct net *net,struct nlattr *tb[], +struct netlink_ext_ack *extack) +{ +u8 nh_family =AF_UNSPEC ; +struct nexthop_grp *nhg; +unsigned int len; +unsigned int i; +u8 nhg_fdb; + + len =nla_len (tb[NHA_GROUP ]) /sizeof (*nhg); + nhg =nla_data (tb[NHA_GROUP ]); + nhg_fdb = !!tb[NHA_FDB ]; + +for (i =0 ; i < len; i++) {struct nexthop *nh;bool is_fdb_nh;
@@ -1330,22 +1359,6 @@ static int nh_check_attr_group(struct net *net,return -EINVAL ; } } -for (i =NHA_GROUP_TYPE +1 ; i < tb_size; ++i) { -if (!tb[i]) -continue ; -switch (i) { -case NHA_HW_STATS_ENABLE : -case NHA_FDB : -continue ; -case NHA_RES_GROUP : -if (nh_grp_type ==NEXTHOP_GRP_TYPE_RES ) -continue ; -break ; - } -NL_SET_ERR_MSG (extack, -"No other attributes can be set in nexthop groups" ); -return -EINVAL ; - }return 0 ; }
@@ -3202,6 +3215,15 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb,return err; } +static int rtm_to_nh_config_rtnl (struct net *net,struct nlattr **tb, +struct netlink_ext_ack *extack) +{ +if (tb[NHA_GROUP ]) +return nh_check_attr_group_rtnl (net, tb, extack); + +return 0 ; +} +/* rtnl */ static int rtm_new_nexthop (struct sk_buff *skb,struct nlmsghdr *nlh,struct netlink_ext_ack *extack)
@@ -3222,6 +3244,10 @@ static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh,if (err) goto out; + err =rtm_to_nh_config_rtnl (net, tb, extack); +if (err) + goto out; + nh =nexthop_add (net, &cfg, extack);if (IS_ERR (nh)) err =PTR_ERR (nh);
Signature · 1 line
2.48.1
Re: [PATCH v2 net-next 2/7] nexthop: Split nh_check_attr_group().
Quoted 11 lines · Kuniyuki Iwashima
We will push RTNL down to
rtm_new_nexthop(), and then we want to move non-RTNL operations out of the scope.
nh_check_attr_group()validatesNHA_GROUPattributes, andnexthop_find_by_id()and some validation requires RTNL.Let's factorise such parts as
nh_check_attr_group_rtnl()and call it fromrtm_to_nh_config_rtnl().Signed-off-by Kuniyuki Iwashima <[email protected]>
Re: [PATCH v2 net-next 2/7] nexthop: Split nh_check_attr_group().
In reply to Kuniyuki IwashimaQuoted 6 lines · Kuniyuki Iwashima
We will push RTNL down to
rtm_new_nexthop(), and then we want to move non-RTNL operations out of the scope.
nh_check_attr_group()validatesNHA_GROUPattributes, andnexthop_find_by_id()and some validation requires RTNL.
Quoted 8 lines
Let's factorise such parts as
nh_check_attr_group_rtnl()and call it fromrtm_to_nh_config_rtnl().Signed-off-by Kuniyuki Iwashima <[email protected]>--- net/ipv4/nexthop.c | 68 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 21 deletions(-)
PATCH v2 3/7 nexthop: Move NHA_OIF validation to rtm_to_nh_config_rtnl().
In reply to Kuniyuki IwashimaNHA_OIF needs to look up a device by __dev_get_by_index(), which requires RTNL.
Let's move NHA_OIF validation to rtm_to_nh_config_rtnl().
Note that the proceeding checks made the original !cfg->nh_fdb check redundant.
NHA_FDB is set -> NHA_OIF cannot be set
NHA_FDB is set but false -> NHA_OIF must be set
NHA_FDB is not set -> NHA_OIF must be set
--- net/ipv4/nexthop.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-)
net/ipv4/nexthop.c +23 -20
@@ -3134,25 +3134,6 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, goto out; } -if (!cfg->nh_fdb && tb[NHA_OIF ]) { - cfg->nh_ifindex =nla_get_u32 (tb[NHA_OIF ]); -if (cfg->nh_ifindex) - cfg->dev =__dev_get_by_index (net, cfg->nh_ifindex); - -if (!cfg->dev) { -NL_SET_ERR_MSG (extack,"Invalid device index" ); - goto out; - }else if (!(cfg->dev->flags &IFF_UP )) { -NL_SET_ERR_MSG (extack,"Nexthop device is not up" ); - err = -ENETDOWN ; - goto out; - }else if (!netif_carrier_ok (cfg->dev)) { -NL_SET_ERR_MSG (extack,"Carrier for nexthop device is down" ); - err = -ENETDOWN ; - goto out; - } - } - err = -EINVAL ;if (tb[NHA_GATEWAY ]) {struct nlattr *gwa = tb[NHA_GATEWAY ];
@@ -3216,11 +3197,33 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, }static int rtm_to_nh_config_rtnl (struct net *net,struct nlattr **tb, +struct nh_config *cfg,struct netlink_ext_ack *extack) {if (tb[NHA_GROUP ])return nh_check_attr_group_rtnl (net, tb, extack); +if (tb[NHA_OIF ]) { + cfg->nh_ifindex =nla_get_u32 (tb[NHA_OIF ]); +if (cfg->nh_ifindex) + cfg->dev =__dev_get_by_index (net, cfg->nh_ifindex); + +if (!cfg->dev) { +NL_SET_ERR_MSG (extack,"Invalid device index" ); +return -EINVAL ; + } + +if (!(cfg->dev->flags &IFF_UP )) { +NL_SET_ERR_MSG (extack,"Nexthop device is not up" ); +return -ENETDOWN ; + } + +if (!netif_carrier_ok (cfg->dev)) { +NL_SET_ERR_MSG (extack,"Carrier for nexthop device is down" ); +return -ENETDOWN ; + } + } +return 0 ; }
@@ -3244,7 +3247,7 @@ static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh,if (err) goto out; - err =rtm_to_nh_config_rtnl (net, tb, extack); + err =rtm_to_nh_config_rtnl (net, tb, &cfg, extack);if (err) goto out;
Signature · 1 line
2.48.1
Re: [PATCH v2 net-next 3/7] nexthop: Move NHA_OIF validation to rtm_to_nh_config_rtnl().
Quoted 6 lines · Kuniyuki Iwashima
NHA_OIFneeds to look up a device by__dev_get_by_index(), which requires RTNL.Let's move
NHA_OIFvalidation tortm_to_nh_config_rtnl().
Quoted 8 lines
Note that the proceeding checks made the original !cfg->nh_fdb check redundant.
NHA_FDBis set ->NHA_OIFcannot be set
NHA_FDBis set but false ->NHA_OIFmust be set
NHA_FDBis not set ->NHA_OIFmust be setSigned-off-by Kuniyuki Iwashima <[email protected]>
Re: [PATCH v2 net-next 3/7] nexthop: Move NHA_OIF validation to rtm_to_nh_config_rtnl().
In reply to Kuniyuki IwashimaQuoted 8 lines · Kuniyuki Iwashima
NHA_OIFneeds to look up a device by__dev_get_by_index(), which requires RTNL.Let's move
NHA_OIFvalidation tortm_to_nh_config_rtnl().Note that the proceeding checks made the original !cfg->nh_fdb check redundant.
Quoted 9 lines
NHA_FDBis set ->NHA_OIFcannot be set
NHA_FDBis set but false ->NHA_OIFmust be set
NHA_FDBis not set ->NHA_OIFmust be setSigned-off-by Kuniyuki Iwashima <[email protected]>--- net/ipv4/nexthop.c | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-)
PATCH v2 4/7 nexthop: Check NLM_F_REPLACE and NHA_ID in rtm_new_nexthop().
In reply to Kuniyuki Iwashimanexthop_add() checks if NLM_F_REPLACE is specified without non-zero NHA_ID, which does not require RTNL.
Let's move the check to rtm_new_nexthop().
--- net/ipv4/nexthop.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
net/ipv4/nexthop.c +6 -5
@@ -2928,11 +2928,6 @@ static struct nexthop *nexthop_add(struct net *net, struct nh_config *cfg,struct nexthop *nh;int err; -if (cfg->nlflags &NLM_F_REPLACE && !cfg->nh_id) { -NL_SET_ERR_MSG (extack,"Replace requires nexthop id" ); -return ERR_PTR (-EINVAL ); - } -if (!cfg->nh_id) { cfg->nh_id =nh_find_unused_id (net);if (!cfg->nh_id) {
@@ -3247,6 +3242,12 @@ static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh,if (err) goto out; +if (cfg.nlflags &NLM_F_REPLACE && !cfg.nh_id) { +NL_SET_ERR_MSG (extack,"Replace requires nexthop id" ); + err = -EINVAL ; + goto out; + } + err =rtm_to_nh_config_rtnl (net, tb, &cfg, extack);if (err) goto out;
Signature · 1 line
2.48.1
Re: [PATCH v2 net-next 4/7] nexthop: Check NLM_F_REPLACE and NHA_ID in rtm_new_nexthop().
Quoted 7 lines · Kuniyuki Iwashima
nexthop_add()checks ifNLM_F_REPLACEis specified without non-zeroNHA_ID, which does not require RTNL.Let's move the check to
rtm_new_nexthop().Signed-off-by Kuniyuki Iwashima <[email protected]>
Re: [PATCH v2 net-next 4/7] nexthop: Check NLM_F_REPLACE and NHA_ID in rtm_new_nexthop().
In reply to Kuniyuki IwashimaQuoted 10 lines · Kuniyuki Iwashima
nexthop_add()checks ifNLM_F_REPLACEis specified without non-zeroNHA_ID, which does not require RTNL.Let's move the check to
rtm_new_nexthop().Signed-off-by Kuniyuki Iwashima <[email protected]>--- net/ipv4/nexthop.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-)
PATCH v2 5/7 nexthop: Remove redundant group len check in nexthop_create_group().
In reply to Kuniyuki IwashimaThe number of NHA_GROUP entries is guaranteed to be non-zero in nh_check_attr_group().
Let's remove the redundant check in nexthop_create_group().
--- net/ipv4/nexthop.c | 3 --- 1 file changed, 3 deletions(-)
net/ipv4/nexthop.c +0 -3
@@ -2692,9 +2692,6 @@ static struct nexthop *nexthop_create_group(struct net *net,int err;int i; -if (WARN_ON (!num_nh)) -return ERR_PTR (-EINVAL ); - nh =nexthop_alloc ();if (!nh)return ERR_PTR (-ENOMEM );
Signature · 1 line
2.48.1
Re: [PATCH v2 net-next 5/7] nexthop: Remove redundant group len check in nexthop_create_group().
Quoted 7 lines · Kuniyuki Iwashima
The number of
NHA_GROUPentries is guaranteed to be non-zero innh_check_attr_group().Let's remove the redundant check in
nexthop_create_group().Signed-off-by Kuniyuki Iwashima <[email protected]>
Re: [PATCH v2 net-next 5/7] nexthop: Remove redundant group len check in nexthop_create_group().
In reply to Kuniyuki IwashimaQuoted 10 lines · Kuniyuki Iwashima
The number of
NHA_GROUPentries is guaranteed to be non-zero innh_check_attr_group().Let's remove the redundant check in
nexthop_create_group().Signed-off-by Kuniyuki Iwashima <[email protected]>--- net/ipv4/nexthop.c | 3 --- 1 file changed, 3 deletions(-)
PATCH v2 6/7 nexthop: Convert RTM_NEWNEXTHOP to per-netns RTNL.
In reply to Kuniyuki IwashimaIf we pass false to the rtnl_held param of lwtunnel_valid_encap_type(), we can move RTNL down before rtm_to_nh_config_rtnl().
Let's use rtnl_net_lock() in rtm_new_nexthop().
--- net/ipv4/nexthop.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
net/ipv4/nexthop.c +11 -5
@@ -3169,7 +3169,7 @@ static int rtm_to_nh_config(struct net *net, struct sk_buff *skb, cfg->nh_encap_type =nla_get_u16 (tb[NHA_ENCAP_TYPE ]); err =lwtunnel_valid_encap_type (cfg->nh_encap_type, - extack, true); + extack, false);if (err <0 ) goto out;
@@ -3245,13 +3245,18 @@ static int rtm_new_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh, goto out; } +rtnl_net_lock (net); + err =rtm_to_nh_config_rtnl (net, tb, &cfg, extack);if (err) - goto out; + goto unlock; nh =nexthop_add (net, &cfg, extack);if (IS_ERR (nh)) err =PTR_ERR (nh); + +unlock: +rtnl_net_unlock (net); out:return err; }
@@ -4067,18 +4072,19 @@ static struct pernet_operations nexthop_net_ops = { };static const struct rtnl_msg_handler nexthop_rtnl_msg_handlers[]__initconst = { - {.msgtype =RTM_NEWNEXTHOP , .doit = rtm_new_nexthop}, + {.msgtype =RTM_NEWNEXTHOP , .doit = rtm_new_nexthop, + .flags =RTNL_FLAG_DOIT_PERNET }, {.msgtype =RTM_DELNEXTHOP , .doit = rtm_del_nexthop}, {.msgtype =RTM_GETNEXTHOP , .doit = rtm_get_nexthop, .dumpit = rtm_dump_nexthop}, {.msgtype =RTM_GETNEXTHOPBUCKET , .doit = rtm_get_nexthop_bucket, .dumpit = rtm_dump_nexthop_bucket}, {.protocol =PF_INET , .msgtype =RTM_NEWNEXTHOP , - .doit = rtm_new_nexthop}, + .doit = rtm_new_nexthop, .flags =RTNL_FLAG_DOIT_PERNET }, {.protocol =PF_INET , .msgtype =RTM_GETNEXTHOP , .dumpit = rtm_dump_nexthop}, {.protocol =PF_INET6 , .msgtype =RTM_NEWNEXTHOP , - .doit = rtm_new_nexthop}, + .doit = rtm_new_nexthop, .flags =RTNL_FLAG_DOIT_PERNET }, {.protocol =PF_INET6 , .msgtype =RTM_GETNEXTHOP , .dumpit = rtm_dump_nexthop}, };
Signature · 1 line
2.48.1
Re: [PATCH v2 net-next 6/7] nexthop: Convert RTM_NEWNEXTHOP to per-netns RTNL.
Quoted 7 lines · Kuniyuki Iwashima
If we pass false to the
rtnl_heldparam oflwtunnel_valid_encap_type(), we can move RTNL down beforertm_to_nh_config_rtnl().Let's use
rtnl_net_lock()inrtm_new_nexthop().Signed-off-by Kuniyuki Iwashima <[email protected]>
Re: [PATCH v2 net-next 6/7] nexthop: Convert RTM_NEWNEXTHOP to per-netns RTNL.
In reply to Kuniyuki IwashimaQuoted 10 lines · Kuniyuki Iwashima
If we pass false to the
rtnl_heldparam oflwtunnel_valid_encap_type(), we can move RTNL down beforertm_to_nh_config_rtnl().Let's use
rtnl_net_lock()inrtm_new_nexthop().Signed-off-by Kuniyuki Iwashima <[email protected]>--- net/ipv4/nexthop.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-)
PATCH v2 7/7 nexthop: Convert RTM_DELNEXTHOP to per-netns RTNL.
In reply to Kuniyuki IwashimaIn rtm_del_nexthop(), only nexthop_find_by_id() and remove_nexthop() require RTNL as they touch net->nexthop.rb_root.
Let's move RTNL down as rtnl_net_lock() before nexthop_find_by_id().
--- net/ipv4/nexthop.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
net/ipv4/nexthop.c +10 -5
@@ -3314,13 +3314,17 @@ static int rtm_del_nexthop(struct sk_buff *skb, struct nlmsghdr *nlh,if (err)return err; +rtnl_net_lock (net); + nh =nexthop_find_by_id (net, id); -if (!nh) -return -ENOENT ; +if (nh) +remove_nexthop (net, nh, &nlinfo); +else + err = -ENOENT ; -remove_nexthop (net, nh, &nlinfo); +rtnl_net_unlock (net); -return 0 ; +return err; }/* rtnl */
@@ -4074,7 +4078,8 @@ static struct pernet_operations nexthop_net_ops = {static const struct rtnl_msg_handler nexthop_rtnl_msg_handlers[]__initconst = { {.msgtype =RTM_NEWNEXTHOP , .doit = rtm_new_nexthop, .flags =RTNL_FLAG_DOIT_PERNET }, - {.msgtype =RTM_DELNEXTHOP , .doit = rtm_del_nexthop}, + {.msgtype =RTM_DELNEXTHOP , .doit = rtm_del_nexthop, + .flags =RTNL_FLAG_DOIT_PERNET }, {.msgtype =RTM_GETNEXTHOP , .doit = rtm_get_nexthop, .dumpit = rtm_dump_nexthop}, {.msgtype =RTM_GETNEXTHOPBUCKET , .doit = rtm_get_nexthop_bucket,
Signature · 1 line
2.48.1
Re: [PATCH v2 net-next 7/7] nexthop: Convert RTM_DELNEXTHOP to per-netns RTNL.
Quoted 7 lines · Kuniyuki Iwashima
In
rtm_del_nexthop(), onlynexthop_find_by_id()andremove_nexthop()require RTNL as they touchnet->nexthop.rb_root.Let's move RTNL down as
rtnl_net_lock()beforenexthop_find_by_id().Signed-off-by Kuniyuki Iwashima <[email protected]>
Re: [PATCH v2 net-next 7/7] nexthop: Convert RTM_DELNEXTHOP to per-netns RTNL.
In reply to Kuniyuki IwashimaQuoted 10 lines · Kuniyuki Iwashima
In
rtm_del_nexthop(), onlynexthop_find_by_id()andremove_nexthop()require RTNL as they touchnet->nexthop.rb_root.Let's move RTNL down as
rtnl_net_lock()beforenexthop_find_by_id().Signed-off-by Kuniyuki Iwashima <[email protected]>--- net/ipv4/nexthop.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
Quoted 11 lines · Kuniyuki Iwashima
Patch 1 - 5 move some validation for
RTM_NEWNEXTHOPso that it can be called without RTNL.Patch 6 & 7 converts
RTM_NEWNEXTHOPandRTM_DELNEXTHOPto per-netns RTNL.Note that
RTM_GETNEXTHOPandRTM_GETNEXTHOPBUCKETare not touched in this series.
rtm_get_nexthop()can be easily converted to RCU, butrtm_dump_nexthop()needs more work due to the left-to-right rbtree walk, which looks prone to node deletion and tree rotation without a retry mechanism.
Thanks for the series, looks good, but note that dump/get can block when fetching hardware statistics:
rtm_get_nexthop
nh_fill_node
nla_put_nh_group
nla_put_nh_group_stats
nh_grp_hw_stats_update
blocking_notifier_call_chain
From: Ido Schimmel <[email protected]>
Date: Mon, 24 Mar 2025 11:35:04 +0200
Quoted 9 lines · Kuniyuki Iwashima
Quoted 8 lines
Patch 1 - 5 move some validation for
RTM_NEWNEXTHOPso that it can be called without RTNL.Patch 6 & 7 converts
RTM_NEWNEXTHOPandRTM_DELNEXTHOPto per-netns RTNL.Note that
RTM_GETNEXTHOPandRTM_GETNEXTHOPBUCKETare not touched in this series.
Quoted 6 lines
Quoted 3 lines
rtm_get_nexthop()can be easily converted to RCU, butrtm_dump_nexthop()needs more work due to the left-to-right rbtree walk, which looks prone to node deletion and tree rotation without a retry mechanism.Thanks for the series, looks good, but note that dump/get can block when fetching hardware statistics:
Oh thanks!
I was puzzled by the left-right rbtree iteration under RCU and wondering if I should try harder, but converting the notifier to non-blocking one is not worth that, and I can simply use per-netns RTNL :)
Quoted 7 lines
rtm_get_nexthop
nh_fill_node
nla_put_nh_group
nla_put_nh_group_stats
nh_grp_hw_stats_update
blocking_notifier_call_chain
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 9 lines · On Wed, 19 Mar 2025 16:06:45 -0700 you wrote:
Patch 1 - 5 move some validation for
RTM_NEWNEXTHOPso that it can be called without RTNL.Patch 6 & 7 converts
RTM_NEWNEXTHOPandRTM_DELNEXTHOPto per-netns RTNL.Note that
RTM_GETNEXTHOPandRTM_GETNEXTHOPBUCKETare not touched in this series.[...]
Here is the summary with links:
- [v2,net-next,1/7] nexthop: Move nlmsg_parse() in rtm_to_nh_config() to rtm_new_nexthop().
https://git.kernel.org/netdev/net-next/c/ec8de7544778 - [v2,net-next,2/7] nexthop: Split nh_check_attr_group(). https://git.kernel.org/netdev/net-next/c/9b9674f3e73a - [v2,net-next,3/7] nexthop: Move NHA_OIF validation to rtm_to_nh_config_rtnl(). https://git.kernel.org/netdev/net-next/c/caa074573ca0 - [v2,net-next,4/7] nexthop: Check NLM_F_REPLACE and NHA_ID in rtm_new_nexthop(). https://git.kernel.org/netdev/net-next/c/53b18aa998b7 - [v2,net-next,5/7] nexthop: Remove redundant group len check in nexthop_create_group(). https://git.kernel.org/netdev/net-next/c/b6af3890574a - [v2,net-next,6/7] nexthop: Convert RTM_NEWNEXTHOP to per-netns RTNL. https://git.kernel.org/netdev/net-next/c/f5fabaff86cb - [v2,net-next,7/7] nexthop: Convert RTM_DELNEXTHOP to per-netns RTNL. https://git.kernel.org/netdev/net-next/c/29c8e323320f
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html