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: netdev@vger.kernel.org, eric.dumazet@gmail.com,
	Eric Dumazet <edumazet@google.com>
Subject: [PATCH v2 net-next 06/19] ipmr: do not acquire mrt_lock in ioctl(SIOCGETVIFCNT)
Date: Thu, 23 Jun 2022 04:34:36 +0000	[thread overview]
Message-ID: <20220623043449.1217288-7-edumazet@google.com> (raw)
In-Reply-To: <20220623043449.1217288-1-edumazet@google.com>

rcu_read_lock() protection is good enough.

Signed-off-by: Eric Dumazet <edumazet@google.com>
---
 net/ipv4/ipmr.c | 42 ++++++++++++++++++++++--------------------
 1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/net/ipv4/ipmr.c b/net/ipv4/ipmr.c
index 8a94f9a459cd077d74b5e38c3d2f248620d4ecfc..bc8b7504fde6ec3aadd6c0962f23e59c0aac702a 100644
--- a/net/ipv4/ipmr.c
+++ b/net/ipv4/ipmr.c
@@ -1611,20 +1611,20 @@ int ipmr_ioctl(struct sock *sk, int cmd, void __user *arg)
 		if (vr.vifi >= mrt->maxvif)
 			return -EINVAL;
 		vr.vifi = array_index_nospec(vr.vifi, mrt->maxvif);
-		read_lock(&mrt_lock);
+		rcu_read_lock();
 		vif = &mrt->vif_table[vr.vifi];
 		if (VIF_EXISTS(mrt, vr.vifi)) {
-			vr.icount = vif->pkt_in;
-			vr.ocount = vif->pkt_out;
-			vr.ibytes = vif->bytes_in;
-			vr.obytes = vif->bytes_out;
-			read_unlock(&mrt_lock);
+			vr.icount = READ_ONCE(vif->pkt_in);
+			vr.ocount = READ_ONCE(vif->pkt_out);
+			vr.ibytes = READ_ONCE(vif->bytes_in);
+			vr.obytes = READ_ONCE(vif->bytes_out);
+			rcu_read_unlock();
 
 			if (copy_to_user(arg, &vr, sizeof(vr)))
 				return -EFAULT;
 			return 0;
 		}
-		read_unlock(&mrt_lock);
+		rcu_read_unlock();
 		return -EADDRNOTAVAIL;
 	case SIOCGETSGCNT:
 		if (copy_from_user(&sr, arg, sizeof(sr)))
@@ -1686,20 +1686,20 @@ int ipmr_compat_ioctl(struct sock *sk, unsigned int cmd, void __user *arg)
 		if (vr.vifi >= mrt->maxvif)
 			return -EINVAL;
 		vr.vifi = array_index_nospec(vr.vifi, mrt->maxvif);
-		read_lock(&mrt_lock);
+		rcu_read_lock();
 		vif = &mrt->vif_table[vr.vifi];
 		if (VIF_EXISTS(mrt, vr.vifi)) {
-			vr.icount = vif->pkt_in;
-			vr.ocount = vif->pkt_out;
-			vr.ibytes = vif->bytes_in;
-			vr.obytes = vif->bytes_out;
-			read_unlock(&mrt_lock);
+			vr.icount = READ_ONCE(vif->pkt_in);
+			vr.ocount = READ_ONCE(vif->pkt_out);
+			vr.ibytes = READ_ONCE(vif->bytes_in);
+			vr.obytes = READ_ONCE(vif->bytes_out);
+			rcu_read_unlock();
 
 			if (copy_to_user(arg, &vr, sizeof(vr)))
 				return -EFAULT;
 			return 0;
 		}
-		read_unlock(&mrt_lock);
+		rcu_read_unlock();
 		return -EADDRNOTAVAIL;
 	case SIOCGETSGCNT:
 		if (copy_from_user(&sr, arg, sizeof(sr)))
@@ -1835,8 +1835,8 @@ static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt,
 		goto out_free;
 
 	if (vif->flags & VIFF_REGISTER) {
-		vif->pkt_out++;
-		vif->bytes_out += skb->len;
+		WRITE_ONCE(vif->pkt_out, vif->pkt_out + 1);
+		WRITE_ONCE(vif->bytes_out, vif->bytes_out + skb->len);
 		vif_dev->stats.tx_bytes += skb->len;
 		vif_dev->stats.tx_packets++;
 		rcu_read_lock();
@@ -1885,8 +1885,8 @@ static void ipmr_queue_xmit(struct net *net, struct mr_table *mrt,
 		goto out_free;
 	}
 
-	vif->pkt_out++;
-	vif->bytes_out += skb->len;
+	WRITE_ONCE(vif->pkt_out, vif->pkt_out + 1);
+	WRITE_ONCE(vif->bytes_out, vif->bytes_out + skb->len);
 
 	skb_dst_drop(skb);
 	skb_dst_set(skb, &rt->dst);
@@ -2002,8 +2002,10 @@ static void ip_mr_forward(struct net *net, struct mr_table *mrt,
 	}
 
 forward:
-	mrt->vif_table[vif].pkt_in++;
-	mrt->vif_table[vif].bytes_in += skb->len;
+	WRITE_ONCE(mrt->vif_table[vif].pkt_in,
+		   mrt->vif_table[vif].pkt_in + 1);
+	WRITE_ONCE(mrt->vif_table[vif].bytes_in,
+		   mrt->vif_table[vif].bytes_in + skb->len);
 
 	/* Forward the frame */
 	if (c->mfc_origin == htonl(INADDR_ANY) &&
-- 
2.37.0.rc0.104.g0611611a94-goog


  parent reply	other threads:[~2022-06-23  4:41 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-23  4:34 [PATCH v2 net-next 00/19] ipmr: get rid of rwlocks Eric Dumazet
2022-06-23  4:34 ` [PATCH v2 net-next 01/19] ip6mr: do not get a device reference in pim6_rcv() Eric Dumazet
2022-06-23  4:34 ` [PATCH v2 net-next 02/19] ipmr: add rcu protection over (struct vif_device)->dev Eric Dumazet
2022-06-23  4:34 ` [PATCH v2 net-next 03/19] ipmr: change igmpmsg_netlink_event() prototype Eric Dumazet
2022-06-23  4:34 ` [PATCH v2 net-next 04/19] ipmr: ipmr_cache_report() changes Eric Dumazet
2022-06-23  4:34 ` [PATCH v2 net-next 05/19] ipmr: do not acquire mrt_lock in __pim_rcv() Eric Dumazet
2022-06-23  4:34 ` Eric Dumazet [this message]
2022-06-23  4:34 ` [PATCH v2 net-next 07/19] ipmr: do not acquire mrt_lock before calling ipmr_cache_unresolved() Eric Dumazet
2022-06-23  4:34 ` [PATCH v2 net-next 08/19] ipmr: do not acquire mrt_lock while calling ip_mr_forward() Eric Dumazet
2022-07-22 19:34   ` Vladimir Oltean
2022-07-22 20:37     ` Eric Dumazet
2022-07-22 21:10       ` Vladimir Oltean
2022-07-22 21:15         ` Vladimir Oltean
2022-06-23  4:34 ` [PATCH v2 net-next 09/19] ipmr: do not acquire mrt_lock in ipmr_get_route() Eric Dumazet
2022-06-23  4:34 ` [PATCH v2 net-next 10/19] ip6mr: ip6mr_cache_report() changes Eric Dumazet
2022-06-23  4:34 ` [PATCH v2 net-next 11/19] ip6mr: do not acquire mrt_lock in pim6_rcv() Eric Dumazet
2022-06-23  4:34 ` [PATCH v2 net-next 12/19] ip6mr: do not acquire mrt_lock in ioctl(SIOCGETMIFCNT_IN6) Eric Dumazet
2022-06-23  4:34 ` [PATCH v2 net-next 13/19] ip6mr: do not acquire mrt_lock before calling ip6mr_cache_unresolved Eric Dumazet
2022-06-23  4:34 ` [PATCH v2 net-next 14/19] ip6mr: do not acquire mrt_lock while calling ip6_mr_forward() Eric Dumazet
2022-06-23  4:34 ` [PATCH v2 net-next 15/19] ip6mr: switch ip6mr_get_route() to rcu_read_lock() Eric Dumazet
2022-06-23  4:34 ` [PATCH v2 net-next 16/19] ipmr: adopt rcu_read_lock() in mr_dump() Eric Dumazet
2022-06-23  4:34 ` [PATCH v2 net-next 17/19] ipmr: convert /proc handlers to rcu_read_lock() Eric Dumazet
2022-06-23  4:34 ` [PATCH v2 net-next 18/19] ipmr: convert mrt_lock to a spinlock Eric Dumazet
2022-06-23  4:34 ` [PATCH v2 net-next 19/19] ip6mr: " Eric Dumazet
2022-06-24 10:50 ` [PATCH v2 net-next 00/19] ipmr: get rid of rwlocks 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=20220623043449.1217288-7-edumazet@google.com \
    --to=edumazet@google.com \
    --cc=davem@davemloft.net \
    --cc=eric.dumazet@gmail.com \
    --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.