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

fib: use indirect call wrappers in the most common fib_rules_ops

This avoids another inderect call per RX packet which save us around
20-40 ns.

Changelog:

v1 -> v2:
- Move declaraions to fib_rules.h to remove warnings

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Brian Vazquez <brianvv@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Brian Vazquez and committed by
David S. Miller
b9aaec8f 608b4ada

+47 -11
+18
include/net/fib_rules.h
··· 10 10 #include <net/flow.h> 11 11 #include <net/rtnetlink.h> 12 12 #include <net/fib_notifier.h> 13 + #include <linux/indirect_call_wrapper.h> 13 14 14 15 struct fib_kuid_range { 15 16 kuid_t start; ··· 204 203 struct netlink_ext_ack *extack); 205 204 int fib_nl_delrule(struct sk_buff *skb, struct nlmsghdr *nlh, 206 205 struct netlink_ext_ack *extack); 206 + 207 + INDIRECT_CALLABLE_DECLARE(int fib6_rule_match(struct fib_rule *rule, 208 + struct flowi *fl, int flags)); 209 + INDIRECT_CALLABLE_DECLARE(int fib4_rule_match(struct fib_rule *rule, 210 + struct flowi *fl, int flags)); 211 + 212 + INDIRECT_CALLABLE_DECLARE(int fib6_rule_action(struct fib_rule *rule, 213 + struct flowi *flp, int flags, 214 + struct fib_lookup_arg *arg)); 215 + INDIRECT_CALLABLE_DECLARE(int fib4_rule_action(struct fib_rule *rule, 216 + struct flowi *flp, int flags, 217 + struct fib_lookup_arg *arg)); 218 + 219 + INDIRECT_CALLABLE_DECLARE(bool fib6_rule_suppress(struct fib_rule *rule, 220 + struct fib_lookup_arg *arg)); 221 + INDIRECT_CALLABLE_DECLARE(bool fib4_rule_suppress(struct fib_rule *rule, 222 + struct fib_lookup_arg *arg)); 207 223 #endif
+13 -3
net/core/fib_rules.c
··· 14 14 #include <net/sock.h> 15 15 #include <net/fib_rules.h> 16 16 #include <net/ip_tunnels.h> 17 + #include <linux/indirect_call_wrapper.h> 17 18 18 19 static const struct fib_kuid_range fib_kuid_range_unset = { 19 20 KUIDT_INIT(0), ··· 268 267 uid_gt(fl->flowi_uid, rule->uid_range.end)) 269 268 goto out; 270 269 271 - ret = ops->match(rule, fl, flags); 270 + ret = INDIRECT_CALL_INET(ops->match, 271 + fib6_rule_match, 272 + fib4_rule_match, 273 + rule, fl, flags); 272 274 out: 273 275 return (rule->flags & FIB_RULE_INVERT) ? !ret : ret; 274 276 } ··· 302 298 } else if (rule->action == FR_ACT_NOP) 303 299 continue; 304 300 else 305 - err = ops->action(rule, fl, flags, arg); 301 + err = INDIRECT_CALL_INET(ops->action, 302 + fib6_rule_action, 303 + fib4_rule_action, 304 + rule, fl, flags, arg); 306 305 307 - if (!err && ops->suppress && ops->suppress(rule, arg)) 306 + if (!err && ops->suppress && INDIRECT_CALL_INET(ops->suppress, 307 + fib6_rule_suppress, 308 + fib4_rule_suppress, 309 + rule, arg)) 308 310 continue; 309 311 310 312 if (err != -EAGAIN) {
+8 -4
net/ipv4/fib_rules.c
··· 29 29 #include <net/ip_fib.h> 30 30 #include <net/nexthop.h> 31 31 #include <net/fib_rules.h> 32 + #include <linux/indirect_call_wrapper.h> 32 33 33 34 struct fib4_rule { 34 35 struct fib_rule common; ··· 104 103 } 105 104 EXPORT_SYMBOL_GPL(__fib_lookup); 106 105 107 - static int fib4_rule_action(struct fib_rule *rule, struct flowi *flp, 108 - int flags, struct fib_lookup_arg *arg) 106 + INDIRECT_CALLABLE_SCOPE int fib4_rule_action(struct fib_rule *rule, 107 + struct flowi *flp, int flags, 108 + struct fib_lookup_arg *arg) 109 109 { 110 110 int err = -EAGAIN; 111 111 struct fib_table *tbl; ··· 140 138 return err; 141 139 } 142 140 143 - static bool fib4_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg) 141 + INDIRECT_CALLABLE_SCOPE bool fib4_rule_suppress(struct fib_rule *rule, 142 + struct fib_lookup_arg *arg) 144 143 { 145 144 struct fib_result *result = (struct fib_result *) arg->result; 146 145 struct net_device *dev = NULL; ··· 172 169 return true; 173 170 } 174 171 175 - static int fib4_rule_match(struct fib_rule *rule, struct flowi *fl, int flags) 172 + INDIRECT_CALLABLE_SCOPE int fib4_rule_match(struct fib_rule *rule, 173 + struct flowi *fl, int flags) 176 174 { 177 175 struct fib4_rule *r = (struct fib4_rule *) rule; 178 176 struct flowi4 *fl4 = &fl->u.ip4;
+8 -4
net/ipv6/fib6_rules.c
··· 13 13 #include <linux/netdevice.h> 14 14 #include <linux/notifier.h> 15 15 #include <linux/export.h> 16 + #include <linux/indirect_call_wrapper.h> 16 17 17 18 #include <net/fib_rules.h> 18 19 #include <net/ipv6.h> ··· 256 255 return err; 257 256 } 258 257 259 - static int fib6_rule_action(struct fib_rule *rule, struct flowi *flp, 260 - int flags, struct fib_lookup_arg *arg) 258 + INDIRECT_CALLABLE_SCOPE int fib6_rule_action(struct fib_rule *rule, 259 + struct flowi *flp, int flags, 260 + struct fib_lookup_arg *arg) 261 261 { 262 262 if (arg->lookup_ptr == fib6_table_lookup) 263 263 return fib6_rule_action_alt(rule, flp, flags, arg); ··· 266 264 return __fib6_rule_action(rule, flp, flags, arg); 267 265 } 268 266 269 - static bool fib6_rule_suppress(struct fib_rule *rule, struct fib_lookup_arg *arg) 267 + INDIRECT_CALLABLE_SCOPE bool fib6_rule_suppress(struct fib_rule *rule, 268 + struct fib_lookup_arg *arg) 270 269 { 271 270 struct fib6_result *res = arg->result; 272 271 struct rt6_info *rt = res->rt6; ··· 299 296 return true; 300 297 } 301 298 302 - static int fib6_rule_match(struct fib_rule *rule, struct flowi *fl, int flags) 299 + INDIRECT_CALLABLE_SCOPE int fib6_rule_match(struct fib_rule *rule, 300 + struct flowi *fl, int flags) 303 301 { 304 302 struct fib6_rule *r = (struct fib6_rule *) rule; 305 303 struct flowi6 *fl6 = &fl->u.ip6;