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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'vrf-a-few-cleanups'

Ido Schimmel says:

====================
vrf: A few cleanups

Perform a few cleanups in the VRF driver. Noticed these while reviewing
a recent patch [1]. See individual patches for more details.

[1] https://lore.kernel.org/netdev/20260310105331.2371-1-lirongqing@baidu.com/
====================

Link: https://patch.msgid.link/20260326203233.1128554-1-idosch@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+16 -66
+16 -66
drivers/net/vrf.c
··· 112 112 }; 113 113 114 114 struct net_vrf { 115 - struct rtable __rcu *rth; 116 - struct rt6_info __rcu *rt6; 115 + struct rtable *rth; 116 + struct rt6_info *rt6; 117 117 #if IS_ENABLED(CONFIG_IPV6) 118 118 struct fib6_table *fib6_table; 119 119 #endif ··· 648 648 struct sk_buff *skb) 649 649 { 650 650 struct net_vrf *vrf = netdev_priv(vrf_dev); 651 - struct dst_entry *dst = NULL; 652 651 struct rt6_info *rt6; 653 652 654 - rcu_read_lock(); 655 - 656 - rt6 = rcu_dereference(vrf->rt6); 657 - if (likely(rt6)) { 658 - dst = &rt6->dst; 659 - dst_hold(dst); 660 - } 661 - 662 - rcu_read_unlock(); 663 - 664 - if (unlikely(!dst)) { 665 - vrf_tx_error(vrf_dev, skb); 666 - return NULL; 667 - } 653 + rt6 = vrf->rt6; 654 + dst_hold(&rt6->dst); 668 655 669 656 skb_dst_drop(skb); 670 - skb_dst_set(skb, dst); 657 + skb_dst_set(skb, &rt6->dst); 671 658 672 659 return skb; 673 660 } ··· 737 750 /* holding rtnl */ 738 751 static void vrf_rt6_release(struct net_device *dev, struct net_vrf *vrf) 739 752 { 740 - struct rt6_info *rt6 = rtnl_dereference(vrf->rt6); 741 - struct net *net = dev_net(dev); 742 - struct dst_entry *dst; 753 + struct rt6_info *rt6 = vrf->rt6; 743 754 744 - RCU_INIT_POINTER(vrf->rt6, NULL); 745 - synchronize_rcu(); 746 - 747 - /* move dev in dst's to loopback so this VRF device can be deleted 748 - * - based on dst_ifdown 749 - */ 750 755 if (rt6) { 751 - dst = &rt6->dst; 752 - netdev_ref_replace(dst->dev, net->loopback_dev, 753 - &dst->dev_tracker, GFP_KERNEL); 754 - dst->dev = net->loopback_dev; 755 - dst_release(dst); 756 + dst_dev_put(&rt6->dst); 757 + dst_release(&rt6->dst); 756 758 } 757 759 } 758 760 ··· 768 792 769 793 rt6->dst.output = vrf_output6; 770 794 771 - rcu_assign_pointer(vrf->rt6, rt6); 795 + vrf->rt6 = rt6; 772 796 773 797 rc = 0; 774 798 out: ··· 854 878 struct sk_buff *skb) 855 879 { 856 880 struct net_vrf *vrf = netdev_priv(vrf_dev); 857 - struct dst_entry *dst = NULL; 858 881 struct rtable *rth; 859 882 860 - rcu_read_lock(); 861 - 862 - rth = rcu_dereference(vrf->rth); 863 - if (likely(rth)) { 864 - dst = &rth->dst; 865 - dst_hold(dst); 866 - } 867 - 868 - rcu_read_unlock(); 869 - 870 - if (unlikely(!dst)) { 871 - vrf_tx_error(vrf_dev, skb); 872 - return NULL; 873 - } 883 + rth = vrf->rth; 884 + dst_hold(&rth->dst); 874 885 875 886 skb_dst_drop(skb); 876 - skb_dst_set(skb, dst); 887 + skb_dst_set(skb, &rth->dst); 877 888 878 889 return skb; 879 890 } ··· 960 997 /* holding rtnl */ 961 998 static void vrf_rtable_release(struct net_device *dev, struct net_vrf *vrf) 962 999 { 963 - struct rtable *rth = rtnl_dereference(vrf->rth); 964 - struct net *net = dev_net(dev); 965 - struct dst_entry *dst; 1000 + struct rtable *rth = vrf->rth; 966 1001 967 - RCU_INIT_POINTER(vrf->rth, NULL); 968 - synchronize_rcu(); 969 - 970 - /* move dev in dst's to loopback so this VRF device can be deleted 971 - * - based on dst_ifdown 972 - */ 973 - if (rth) { 974 - dst = &rth->dst; 975 - netdev_ref_replace(dst->dev, net->loopback_dev, 976 - &dst->dev_tracker, GFP_KERNEL); 977 - dst->dev = net->loopback_dev; 978 - dst_release(dst); 979 - } 1002 + dst_dev_put(&rth->dst); 1003 + dst_release(&rth->dst); 980 1004 } 981 1005 982 1006 static int vrf_rtable_create(struct net_device *dev) ··· 981 1031 982 1032 rth->dst.output = vrf_output; 983 1033 984 - rcu_assign_pointer(vrf->rth, rth); 1034 + vrf->rth = rth; 985 1035 986 1036 return 0; 987 1037 }