Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

inet: Remove rtnl_is_held arg of lwtunnel_valid_encap_type(_attr)?().

Commit f130a0cc1b4f ("inet: fix lwtunnel_valid_encap_type() lock
imbalance") added the rtnl_is_held argument as a temporary fix while
I'm converting nexthop and IPv6 routing table to per-netns RTNL or RCU.

Now all callers of lwtunnel_valid_encap_type() do not hold RTNL.

Let's remove the argument.

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Link: https://patch.msgid.link/20250516022759.44392-3-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Kuniyuki Iwashima and committed by
Jakub Kicinski
f0a56c17 f1a8d107

+13 -28
+5 -8
include/net/lwtunnel.h
··· 116 116 int lwtunnel_encap_del_ops(const struct lwtunnel_encap_ops *op, 117 117 unsigned int num); 118 118 int lwtunnel_valid_encap_type(u16 encap_type, 119 - struct netlink_ext_ack *extack, 120 - bool rtnl_is_held); 119 + struct netlink_ext_ack *extack); 121 120 int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int len, 122 - struct netlink_ext_ack *extack, 123 - bool rtnl_is_held); 121 + struct netlink_ext_ack *extack); 124 122 int lwtunnel_build_state(struct net *net, u16 encap_type, 125 123 struct nlattr *encap, 126 124 unsigned int family, const void *cfg, ··· 201 203 } 202 204 203 205 static inline int lwtunnel_valid_encap_type(u16 encap_type, 204 - struct netlink_ext_ack *extack, 205 - bool rtnl_is_held) 206 + struct netlink_ext_ack *extack) 206 207 { 207 208 NL_SET_ERR_MSG(extack, "CONFIG_LWTUNNEL is not enabled in this kernel"); 208 209 return -EOPNOTSUPP; 209 210 } 211 + 210 212 static inline int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int len, 211 - struct netlink_ext_ack *extack, 212 - bool rtnl_is_held) 213 + struct netlink_ext_ack *extack) 213 214 { 214 215 /* return 0 since we are not walking attr looking for 215 216 * RTA_ENCAP_TYPE attribute on nexthops.
+3 -12
net/core/lwtunnel.c
··· 149 149 } 150 150 EXPORT_SYMBOL_GPL(lwtunnel_build_state); 151 151 152 - int lwtunnel_valid_encap_type(u16 encap_type, struct netlink_ext_ack *extack, 153 - bool rtnl_is_held) 152 + int lwtunnel_valid_encap_type(u16 encap_type, struct netlink_ext_ack *extack) 154 153 { 155 154 const struct lwtunnel_encap_ops *ops; 156 155 int ret = -EINVAL; ··· 166 167 const char *encap_type_str = lwtunnel_encap_str(encap_type); 167 168 168 169 if (encap_type_str) { 169 - if (rtnl_is_held) 170 - __rtnl_unlock(); 171 170 request_module("rtnl-lwt-%s", encap_type_str); 172 - if (rtnl_is_held) 173 - rtnl_lock(); 174 - 175 171 ops = rcu_access_pointer(lwtun_encaps[encap_type]); 176 172 } 177 173 } ··· 180 186 EXPORT_SYMBOL_GPL(lwtunnel_valid_encap_type); 181 187 182 188 int lwtunnel_valid_encap_type_attr(struct nlattr *attr, int remaining, 183 - struct netlink_ext_ack *extack, 184 - bool rtnl_is_held) 189 + struct netlink_ext_ack *extack) 185 190 { 186 191 struct rtnexthop *rtnh = (struct rtnexthop *)attr; 187 192 struct nlattr *nla_entype; ··· 201 208 } 202 209 encap_type = nla_get_u16(nla_entype); 203 210 204 - if (lwtunnel_valid_encap_type(encap_type, 205 - extack, 206 - rtnl_is_held) != 0) 211 + if (lwtunnel_valid_encap_type(encap_type, extack)) 207 212 return -EOPNOTSUPP; 208 213 } 209 214 }
+2 -2
net/ipv4/fib_frontend.c
··· 807 807 case RTA_MULTIPATH: 808 808 err = lwtunnel_valid_encap_type_attr(nla_data(attr), 809 809 nla_len(attr), 810 - extack, false); 810 + extack); 811 811 if (err < 0) 812 812 goto errout; 813 813 cfg->fc_mp = nla_data(attr); ··· 825 825 case RTA_ENCAP_TYPE: 826 826 cfg->fc_encap_type = nla_get_u16(attr); 827 827 err = lwtunnel_valid_encap_type(cfg->fc_encap_type, 828 - extack, false); 828 + extack); 829 829 if (err < 0) 830 830 goto errout; 831 831 break;
+1 -2
net/ipv4/nexthop.c
··· 3180 3180 } 3181 3181 3182 3182 cfg->nh_encap_type = nla_get_u16(tb[NHA_ENCAP_TYPE]); 3183 - err = lwtunnel_valid_encap_type(cfg->nh_encap_type, 3184 - extack, false); 3183 + err = lwtunnel_valid_encap_type(cfg->nh_encap_type, extack); 3185 3184 if (err < 0) 3186 3185 goto out; 3187 3186
+2 -4
net/ipv6/route.c
··· 5172 5172 rtnh = rtnh_next(rtnh, &remaining); 5173 5173 } while (rtnh_ok(rtnh, remaining)); 5174 5174 5175 - return lwtunnel_valid_encap_type_attr(cfg->fc_mp, cfg->fc_mp_len, 5176 - extack, false); 5175 + return lwtunnel_valid_encap_type_attr(cfg->fc_mp, cfg->fc_mp_len, extack); 5177 5176 } 5178 5177 5179 5178 static int rtm_to_fib6_config(struct sk_buff *skb, struct nlmsghdr *nlh, ··· 5309 5310 if (tb[RTA_ENCAP_TYPE]) { 5310 5311 cfg->fc_encap_type = nla_get_u16(tb[RTA_ENCAP_TYPE]); 5311 5312 5312 - err = lwtunnel_valid_encap_type(cfg->fc_encap_type, 5313 - extack, false); 5313 + err = lwtunnel_valid_encap_type(cfg->fc_encap_type, extack); 5314 5314 if (err < 0) 5315 5315 goto errout; 5316 5316 }