netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] ipv6: mc_forwarding changes
@ 2022-02-04 20:15 Eric Dumazet
  2022-02-04 20:15 ` [PATCH net-next 1/2] ipv6: make mc_forwarding atomic Eric Dumazet
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Eric Dumazet @ 2022-02-04 20:15 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski
  Cc: netdev, David Ahern, Eric Dumazet, Eric Dumazet

From: Eric Dumazet <edumazet@google.com>

First patch removes minor data-races, as mc_forwarding can
be locklessly read in fast path.

Second patch adds a short cut in ip6mr_sk_done()

Eric Dumazet (2):
  ipv6: make mc_forwarding atomic
  ip6mr: ip6mr_sk_done() can exit early in common cases

 include/linux/ipv6.h       |  2 +-
 net/batman-adv/multicast.c |  2 +-
 net/ipv6/addrconf.c        |  4 ++--
 net/ipv6/ip6_input.c       |  2 +-
 net/ipv6/ip6mr.c           | 11 +++++++----
 5 files changed, 12 insertions(+), 9 deletions(-)

-- 
2.35.0.263.gb82422642f-goog


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

* [PATCH net-next 1/2] ipv6: make mc_forwarding atomic
  2022-02-04 20:15 [PATCH net-next 0/2] ipv6: mc_forwarding changes Eric Dumazet
@ 2022-02-04 20:15 ` Eric Dumazet
  2022-02-04 20:15 ` [PATCH net-next 2/2] ip6mr: ip6mr_sk_done() can exit early in common cases Eric Dumazet
  2022-02-05 15:40 ` [PATCH net-next 0/2] ipv6: mc_forwarding changes patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2022-02-04 20:15 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski
  Cc: netdev, David Ahern, Eric Dumazet, Eric Dumazet

From: Eric Dumazet <edumazet@google.com>

This fixes minor data-races in ip6_mc_input() and
batadv_mcast_mla_rtr_flags_softif_get_ipv6()

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 include/linux/ipv6.h       | 2 +-
 net/batman-adv/multicast.c | 2 +-
 net/ipv6/addrconf.c        | 4 ++--
 net/ipv6/ip6_input.c       | 2 +-
 net/ipv6/ip6mr.c           | 8 ++++----
 5 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/include/linux/ipv6.h b/include/linux/ipv6.h
index 1e0f8a31f3de175659dca9ecee9f97d8b01e2b68..16870f86c74d3d1f5dfb7edac1e7db85f1ef6755 100644
--- a/include/linux/ipv6.h
+++ b/include/linux/ipv6.h
@@ -51,7 +51,7 @@ struct ipv6_devconf {
 	__s32		use_optimistic;
 #endif
 #ifdef CONFIG_IPV6_MROUTE
-	__s32		mc_forwarding;
+	atomic_t	mc_forwarding;
 #endif
 	__s32		disable_ipv6;
 	__s32		drop_unicast_in_l2_multicast;
diff --git a/net/batman-adv/multicast.c b/net/batman-adv/multicast.c
index f4004cf0ff6fbf8f586d68f33ff63d3192bc5ca9..9f311fddfaf9aa6d35cd1039699203b7aaccbfdf 100644
--- a/net/batman-adv/multicast.c
+++ b/net/batman-adv/multicast.c
@@ -134,7 +134,7 @@ static u8 batadv_mcast_mla_rtr_flags_softif_get_ipv6(struct net_device *dev)
 {
 	struct inet6_dev *in6_dev = __in6_dev_get(dev);
 
-	if (in6_dev && in6_dev->cnf.mc_forwarding)
+	if (in6_dev && atomic_read(&in6_dev->cnf.mc_forwarding))
 		return BATADV_NO_FLAGS;
 	else
 		return BATADV_MCAST_WANT_NO_RTR6;
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index f927c199a93c3ed1124be02eb32a20900980f337..ff1b2484b8ed8638e4d37eb21c67de4e5ac43dae 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -554,7 +554,7 @@ static int inet6_netconf_fill_devconf(struct sk_buff *skb, int ifindex,
 #ifdef CONFIG_IPV6_MROUTE
 	if ((all || type == NETCONFA_MC_FORWARDING) &&
 	    nla_put_s32(skb, NETCONFA_MC_FORWARDING,
-			devconf->mc_forwarding) < 0)
+			atomic_read(&devconf->mc_forwarding)) < 0)
 		goto nla_put_failure;
 #endif
 	if ((all || type == NETCONFA_PROXY_NEIGH) &&
@@ -5533,7 +5533,7 @@ static inline void ipv6_store_devconf(struct ipv6_devconf *cnf,
 	array[DEVCONF_USE_OPTIMISTIC] = cnf->use_optimistic;
 #endif
 #ifdef CONFIG_IPV6_MROUTE
-	array[DEVCONF_MC_FORWARDING] = cnf->mc_forwarding;
+	array[DEVCONF_MC_FORWARDING] = atomic_read(&cnf->mc_forwarding);
 #endif
 	array[DEVCONF_DISABLE_IPV6] = cnf->disable_ipv6;
 	array[DEVCONF_ACCEPT_DAD] = cnf->accept_dad;
diff --git a/net/ipv6/ip6_input.c b/net/ipv6/ip6_input.c
index 80256717868e69766acb3b590680f34a4ed1c0e9..d4b1e2c5aa76dd09efc6c48bf7e281447fdf10c1 100644
--- a/net/ipv6/ip6_input.c
+++ b/net/ipv6/ip6_input.c
@@ -508,7 +508,7 @@ int ip6_mc_input(struct sk_buff *skb)
 	/*
 	 *      IPv6 multicast router mode is now supported ;)
 	 */
-	if (dev_net(skb->dev)->ipv6.devconf_all->mc_forwarding &&
+	if (atomic_read(&dev_net(skb->dev)->ipv6.devconf_all->mc_forwarding) &&
 	    !(ipv6_addr_type(&hdr->daddr) &
 	      (IPV6_ADDR_LOOPBACK|IPV6_ADDR_LINKLOCAL)) &&
 	    likely(!(IP6CB(skb)->flags & IP6SKB_FORWARDED))) {
diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 7cf73e60e619ba92ea1eccc90c181ba7150225dd..541cd08871293eb5702e47e0645ea16394621e97 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -732,7 +732,7 @@ static int mif6_delete(struct mr_table *mrt, int vifi, int notify,
 
 	in6_dev = __in6_dev_get(dev);
 	if (in6_dev) {
-		in6_dev->cnf.mc_forwarding--;
+		atomic_dec(&in6_dev->cnf.mc_forwarding);
 		inet6_netconf_notify_devconf(dev_net(dev), RTM_NEWNETCONF,
 					     NETCONFA_MC_FORWARDING,
 					     dev->ifindex, &in6_dev->cnf);
@@ -900,7 +900,7 @@ static int mif6_add(struct net *net, struct mr_table *mrt,
 
 	in6_dev = __in6_dev_get(dev);
 	if (in6_dev) {
-		in6_dev->cnf.mc_forwarding++;
+		atomic_inc(&in6_dev->cnf.mc_forwarding);
 		inet6_netconf_notify_devconf(dev_net(dev), RTM_NEWNETCONF,
 					     NETCONFA_MC_FORWARDING,
 					     dev->ifindex, &in6_dev->cnf);
@@ -1551,7 +1551,7 @@ static int ip6mr_sk_init(struct mr_table *mrt, struct sock *sk)
 	} else {
 		rcu_assign_pointer(mrt->mroute_sk, sk);
 		sock_set_flag(sk, SOCK_RCU_FREE);
-		net->ipv6.devconf_all->mc_forwarding++;
+		atomic_inc(&net->ipv6.devconf_all->mc_forwarding);
 	}
 	write_unlock_bh(&mrt_lock);
 
@@ -1584,7 +1584,7 @@ int ip6mr_sk_done(struct sock *sk)
 			 * so the RCU grace period before sk freeing
 			 * is guaranteed by sk_destruct()
 			 */
-			net->ipv6.devconf_all->mc_forwarding--;
+			atomic_dec(&net->ipv6.devconf_all->mc_forwarding);
 			write_unlock_bh(&mrt_lock);
 			inet6_netconf_notify_devconf(net, RTM_NEWNETCONF,
 						     NETCONFA_MC_FORWARDING,
-- 
2.35.0.263.gb82422642f-goog


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

* [PATCH net-next 2/2] ip6mr: ip6mr_sk_done() can exit early in common cases
  2022-02-04 20:15 [PATCH net-next 0/2] ipv6: mc_forwarding changes Eric Dumazet
  2022-02-04 20:15 ` [PATCH net-next 1/2] ipv6: make mc_forwarding atomic Eric Dumazet
@ 2022-02-04 20:15 ` Eric Dumazet
  2022-02-05 15:40 ` [PATCH net-next 0/2] ipv6: mc_forwarding changes patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2022-02-04 20:15 UTC (permalink / raw)
  To: David S . Miller, Jakub Kicinski
  Cc: netdev, David Ahern, Eric Dumazet, Eric Dumazet

From: Eric Dumazet <edumazet@google.com>

In many cases, ip6mr_sk_done() is called while no ipmr socket
has been registered.

This removes 4 rtnl acquisitions per netns dismantle,
with following callers:

igmp6_net_exit(), tcpv6_net_exit(), ndisc_net_exit()

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/ipv6/ip6mr.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/ipv6/ip6mr.c b/net/ipv6/ip6mr.c
index 541cd08871293eb5702e47e0645ea16394621e97..8e483e14b5709b1b8a6e9dfd6616a5bde5c273ee 100644
--- a/net/ipv6/ip6mr.c
+++ b/net/ipv6/ip6mr.c
@@ -1575,6 +1575,9 @@ int ip6mr_sk_done(struct sock *sk)
 	    inet_sk(sk)->inet_num != IPPROTO_ICMPV6)
 		return err;
 
+	if (!atomic_read(&net->ipv6.devconf_all->mc_forwarding))
+		return err;
+
 	rtnl_lock();
 	ip6mr_for_each_table(mrt, net) {
 		if (sk == rtnl_dereference(mrt->mroute_sk)) {
-- 
2.35.0.263.gb82422642f-goog


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

* Re: [PATCH net-next 0/2] ipv6: mc_forwarding changes
  2022-02-04 20:15 [PATCH net-next 0/2] ipv6: mc_forwarding changes Eric Dumazet
  2022-02-04 20:15 ` [PATCH net-next 1/2] ipv6: make mc_forwarding atomic Eric Dumazet
  2022-02-04 20:15 ` [PATCH net-next 2/2] ip6mr: ip6mr_sk_done() can exit early in common cases Eric Dumazet
@ 2022-02-05 15:40 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-02-05 15:40 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: davem, kuba, netdev, dsahern, edumazet

Hello:

This series was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Fri,  4 Feb 2022 12:15:44 -0800 you wrote:
> From: Eric Dumazet <edumazet@google.com>
> 
> First patch removes minor data-races, as mc_forwarding can
> be locklessly read in fast path.
> 
> Second patch adds a short cut in ip6mr_sk_done()
> 
> [...]

Here is the summary with links:
  - [net-next,1/2] ipv6: make mc_forwarding atomic
    https://git.kernel.org/netdev/net-next/c/145c7a793838
  - [net-next,2/2] ip6mr: ip6mr_sk_done() can exit early in common cases
    https://git.kernel.org/netdev/net-next/c/f2f2325ec799

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] 4+ messages in thread

end of thread, other threads:[~2022-02-05 15:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-04 20:15 [PATCH net-next 0/2] ipv6: mc_forwarding changes Eric Dumazet
2022-02-04 20:15 ` [PATCH net-next 1/2] ipv6: make mc_forwarding atomic Eric Dumazet
2022-02-04 20:15 ` [PATCH net-next 2/2] ip6mr: ip6mr_sk_done() can exit early in common cases Eric Dumazet
2022-02-05 15:40 ` [PATCH net-next 0/2] ipv6: mc_forwarding changes 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;
as well as URLs for NNTP newsgroup(s).