Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next] net: optimize netif_is_l3_master() and netif_is_l3_slave()
@ 2026-08-31 15:41 Eric Dumazet
  2026-09-03  1:40 ` patchwork-bot+netdevbpf
  0 siblings, 1 reply; 2+ messages in thread
From: Eric Dumazet @ 2026-08-31 15:41 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski, Paolo Abeni
  Cc: Simon Horman, netdev, eric.dumazet, Eric Dumazet

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH net-next] net: optimize netif_is_l3_master() and netif_is_l3_slave()
  2026-08-31 15:41 [PATCH net-next] net: optimize netif_is_l3_master() and netif_is_l3_slave() Eric Dumazet
@ 2026-09-03  1:40 ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-09-03  1:40 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: davem, kuba, pabeni, horms, netdev, eric.dumazet

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Mon, 31 Aug 2026 15:41:29 +0000 you wrote:
> 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.).
> 
> [...]

Here is the summary with links:
  - [net-next] net: optimize netif_is_l3_master() and netif_is_l3_slave()
    https://git.kernel.org/netdev/net-next/c/4187c29c2abd

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-03  1:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-31 15:41 [PATCH net-next] net: optimize netif_is_l3_master() and netif_is_l3_slave() Eric Dumazet
2026-09-03  1:40 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox