All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <edumazet@google.com>
To: "David S . Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	 Paolo Abeni <pabeni@redhat.com>
Cc: Simon Horman <horms@kernel.org>,
	netdev@vger.kernel.org, eric.dumazet@gmail.com,
	 Eric Dumazet <edumazet@google.com>
Subject: [PATCH net-next] net: optimize netif_is_l3_master() and netif_is_l3_slave()
Date: Mon, 31 Aug 2026 15:41:29 +0000	[thread overview]
Message-ID: <20260831154129.4048178-1-edumazet@google.com> (raw)

IFF_L3MDEV_MASTER and IFF_L3MDEV_SLAVE flags are only set and used
by the VRF driver (CONFIG_NET_VRF).

netif_is_l3_master() and netif_is_l3_slave() are called in multiple
performance-critical fast paths (such as GRO, IP routing/FIB lookups,
TCP/UDP processing, etc.).

When CONFIG_NET_VRF is disabled, neither flag can ever be set on any
net_device.

Adding IS_ENABLED(CONFIG_NET_VRF) allows the compiler to optimize
these checks away as false at compile time, eliminating unnecessary
conditional branches in the fast path when VRF is not enabled.

scripts/bloat-o-meter shows a nice code size reduction on a kernel
built with CONFIG_NET_VRF=n (and CONFIG_NET_L3_MASTER_DEV=y):

add/remove: 2/5 grow/shrink: 18/71 up/down: 1593/-5642 (-4049)
Function                                     old     new   delta
ipip6_tunnel_lookup.constprop                  -     931    +931
tcp_v6_parse_md5_keys                       1607    1742    +135
ipip6_err                                    617     738    +121
bpf_lwt_xmit_reroute                        1492    1555     +63
ip6_pol_route                               1810    1843     +33
rt6_multipath_rebalance.part                1448    1480     +32
bpf_msg_pull_data                           1255    1287     +32
__unlikely_text_end                         3092    3124     +32
ipv6_add_addr                               2257    2287     +30
__ip4_datagram_connect                      1131    1158     +27
ip6_rt_cache_alloc                           476     500     +24
fib6_clean_tohost                            308     328     +20
sit_exit_rtnl_net                            461     477     +16
nf_nat_register_fn                           581     597     +16
ip6_forward                                 4573    4589     +16
inet_rtm_getroute                           2906    2922     +16
__pfx_ipip6_tunnel_lookup.constprop            -      16     +16
__ip_do_redirect                            2005    2021     +16
__bpf_skc_lookup                             449     464     +15
addrconf_add_dev                             134     136      +2
ip6_rcv_finish                               203     201      -2
icmp6_dev                                    159     153      -6
ipip6_tunnel_bind_dev                        419     409     -10
bpf_xdp_skc_lookup_tcp                       122     107     -15
bpf_tc_skc_lookup_tcp                        125     110     -15
rt6_nh_dump_exceptions                       243     227     -16
ip_mc_source                                1385    1369     -16
ip6_fragment                                2450    2434     -16
input_action_end_x                           278     262     -16
fib6_nh_age_exceptions.part                  822     806     -16
__pfx_ipip6_tunnel_lookup                     16       -     -16
__pfx_ip6_rt_get_dev_rcu                      16       -     -16
__addrconf_sysctl_register                   365     349     -16
bpf_xdp_sk_lookup_udp                        155     138     -17
bpf_xdp_sk_lookup_tcp                        155     138     -17
bpf_tc_sk_lookup_udp                         158     141     -17
bpf_tc_sk_lookup_tcp                         158     141     -17
addrconf_addr_gen                            339     322     -17
ip6_rcv_core                                2084    2066     -18
fib_nl2rule_locked                           517     499     -18
l3mdev_master_upper_ifindex_by_index_rcu      61      42     -19
ipip6_rcv                                   1960    1941     -19
addrconf_notify                             2563    2543     -20
l3mdev_fib_table_by_index                    304     282     -22
nf_nat_inet_fn                               777     754     -23
attach_rules                                 176     150     -26
ipv6_rcv                                     867     840     -27
ip_sublist_rcv                              1342    1315     -27
ip6_sublist_rcv                             1528    1501     -27
sit_tunnel_rcv                               498     470     -28
ndisc_send_redirect                         1474    1445     -29
ip_mr_input                                 1175    1143     -32
ip6_mr_input                                 627     595     -32
tcp_ao_add_cmd.cold                           33       -     -33
ip_error                                    1059    1023     -36
raw_sendmsg                                 5291    5253     -38
end_dt_vrf_core                              466     426     -40
ip_rcv                                       886     844     -42
ip_send_unicast_reply                       1487    1443     -44
udp_sendmsg                                 4135    4089     -46
delete_tempaddrs                             259     211     -48
udp6_gro_receive                            1142    1092     -50
udp4_lib_lookup_skb                          259     208     -51
l3mdev_fib_rule_match                        337     286     -51
ping_v4_sendmsg                             2692    2640     -52
tcp6_check_fraglist_gro                      341     288     -53
l3mdev_master_ifindex_rcu                     69      16     -53
ip6_dst_lookup_tail.constprop               1533    1480     -53
udp4_gro_receive                            1139    1085     -54
igmp_rcv                                    3215    3160     -55
ndisc_recv_ns                               1699    1642     -57
fib_netdev_event                             771     714     -57
l3mdev_link_scope_lookup                     124      65     -59
udp6_lib_lookup_skb                          173     113     -60
__ip_local_out                              1182    1120     -62
ipv6_frag_rcv                               3670    3601     -69
ip_route_output_key_hash_rcu                3024    2951     -73
__ip6_local_out                             1164    1091     -73
tcp_v6_send_response                        3056    2982     -74
rt6_fill_node                               4103    4027     -76
rawv6_sendmsg                               6225    6149     -76
l3mdev_fib_table_rcu                          92      16     -76
tcp4_gro_receive                            1375    1295     -80
ip6_xmit                                    2771    2690     -81
fib_select_path                             2190    2105     -85
tcp_v4_parse_md5_keys                       1160    1058    -102
ip_route_input_slow                         4471    4354    -117
ip6_pkt_drop.isra                            572     453    -119
l3mdev_update_flow                           516     360    -156
ip6_rt_get_dev_rcu                           182       -    -182
__ipv6_chk_addr_and_flags                    750     568    -182
ip_route_input_rcu.part                      941     743    -198
nf_confirm                                  1222     960    -262
ipv6_dev_get_saddr                          1321     918    -403
tcp_ao_add_cmd                              2643    2211    -432
ipip6_tunnel_lookup                         1004       -   -1004
Total: Before=33195512, After=33191463, chg -0.01%

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 include/linux/netdevice.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index 87cafc932e9e6584405821a87be0e31e0fc65b77..8454646d6a4548a63fef1c29b8119ba94c36bc71 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -5606,12 +5606,12 @@ static inline bool netif_has_l3_rx_handler(const struct net_device *dev)
 
 static inline bool netif_is_l3_master(const struct net_device *dev)
 {
-	return dev->priv_flags & IFF_L3MDEV_MASTER;
+	return IS_ENABLED(CONFIG_NET_VRF) && (dev->priv_flags & IFF_L3MDEV_MASTER);
 }
 
 static inline bool netif_is_l3_slave(const struct net_device *dev)
 {
-	return dev->priv_flags & IFF_L3MDEV_SLAVE;
+	return IS_ENABLED(CONFIG_NET_VRF) && (dev->priv_flags & IFF_L3MDEV_SLAVE);
 }
 
 static inline int dev_sdif(const struct net_device *dev)
-- 
2.55.0.897.gb25b4bd76c-goog


             reply	other threads:[~2026-08-31 15:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 15:41 Eric Dumazet [this message]
2026-09-03  1:40 ` [PATCH net-next] net: optimize netif_is_l3_master() and netif_is_l3_slave() 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=20260831154129.4048178-1-edumazet@google.com \
    --to=edumazet@google.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --cc=horms@kernel.org \
    --cc=kuba@kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.