public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Vladimir Oltean <olteanv@gmail.com>
To: Andrew Lunn <andrew@lunn.ch>
Cc: Jakub Kicinski <kuba@kernel.org>,
	George McCollister <george.mccollister@gmail.com>,
	Vivien Didelot <vivien.didelot@gmail.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	"David S . Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org,
	"open list:OPEN FIRMWARE AND..." <devicetree@vger.kernel.org>
Subject: Re: [PATCH net-next v2 2/3] net: dsa: add Arrow SpeedChips XRS700x driver
Date: Sat, 28 Nov 2020 03:41:06 +0200	[thread overview]
Message-ID: <20201128014106.lcqi6btkudbnj3mc@skbuf> (raw)
In-Reply-To: <20201128003912.GA2191767@lunn.ch>

On Sat, Nov 28, 2020 at 01:39:12AM +0100, Andrew Lunn wrote:
> > This means, as far as I understand, 2 things:
> > 1. call_netdevice_notifiers_info doesn't help, since our problem is the
> >    same
> > 2. I think that holding the RTNL should also be a valid way to iterate
> >    through the net devices in the current netns, and doing just that
> >    could be the simplest way out. It certainly worked when I tried it.
> >    But those could also be famous last words...
>
> DSA makes the assumption it can block in a notifier change event.  For
> example, NETDEV_CHANGEUPPER calls dsa_slave_changeupper() which calls
> into the driver. We have not seen any warnings about sleeping while
> atomic. So maybe see how NETDEV_CHANGEUPPER is issued.

Yes, this is in line with what I said. Even though we are pure readers,
it is still sufficient (albeit not necessary) to hold rtnl in order to
safely iterate through net->dev_base_head (or in this case, through its
hashmaps per name and per ifindex). However, rtnl is the only one that
offers sleepable context, since it is the only one that is a mutex.

So the patch could simply look like this, no notifiers needed:

-----------------------------[cut here]-----------------------------
diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
index c714e6a9dad4..1429e8c066d8 100644
--- a/net/core/net-procfs.c
+++ b/net/core/net-procfs.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/netdevice.h>
 #include <linux/proc_fs.h>
+#include <linux/rtnetlink.h>
 #include <linux/seq_file.h>
 #include <net/wext.h>
 
@@ -21,7 +22,7 @@ static inline struct net_device *dev_from_same_bucket(struct seq_file *seq, loff
 	unsigned int count = 0, offset = get_offset(*pos);
 
 	h = &net->dev_index_head[get_bucket(*pos)];
-	hlist_for_each_entry_rcu(dev, h, index_hlist) {
+	hlist_for_each_entry(dev, h, index_hlist) {
 		if (++count == offset)
 			return dev;
 	}
@@ -51,9 +52,9 @@ static inline struct net_device *dev_from_bucket(struct seq_file *seq, loff_t *p
  *	in detail.
  */
 static void *dev_seq_start(struct seq_file *seq, loff_t *pos)
-	__acquires(RCU)
+	__acquires(rtnl_mutex)
 {
-	rcu_read_lock();
+	rtnl_lock();
 	if (!*pos)
 		return SEQ_START_TOKEN;
 
@@ -70,9 +71,9 @@ static void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
 }
 
 static void dev_seq_stop(struct seq_file *seq, void *v)
-	__releases(RCU)
+	__releases(rtnl_mutex)
 {
-	rcu_read_unlock();
+	rtnl_unlock();
 }
 
 static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
-----------------------------[cut here]-----------------------------

The advantage is that it can now sleep.

The disadvantage is that now it can sleep. It is a writer, so other
writers can block it out, and it can block out other writers. More
contention. Speaking of, here's an interesting patch from someone who
seems to enjoy running ifconfig:

commit f04565ddf52e401880f8ba51de0dff8ba51c99fd
Author: Mihai Maruseac <mihai.maruseac@gmail.com>
Date:   Thu Oct 20 20:45:10 2011 +0000

    dev: use name hash for dev_seq_ops

    Instead of using the dev->next chain and trying to resync at each call to
    dev_seq_start, use the name hash, keeping the bucket and the offset in
    seq->private field.

    Tests revealed the following results for ifconfig > /dev/null
            * 1000 interfaces:
                    * 0.114s without patch
                    * 0.089s with patch
            * 3000 interfaces:
                    * 0.489s without patch
                    * 0.110s with patch
            * 5000 interfaces:
                    * 1.363s without patch
                    * 0.250s with patch
            * 128000 interfaces (other setup):
                    * ~100s without patch
                    * ~30s with patch

    Signed-off-by: Mihai Maruseac <mmaruseac@ixiacom.com>
    Signed-off-by: Eric Dumazet <eric.dumazet@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Jakub, I would like to hear more from you. I would still like to try
this patch out. You clearly have a lot more background with the code.
You said in an earlier reply that you should have also documented that
ndo_get_stats64 is one of the few NDOs that does not take the RTNL. Is
there a particular reason for that being so, and a reason why it can't
change?

  reply	other threads:[~2020-11-28  1:43 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-25 19:37 [PATCH net-next v2 0/3] Arrow SpeedChips XRS700x DSA Driver George McCollister
2020-11-25 19:37 ` [PATCH net-next v2 1/3] dsa: add support for Arrow XRS700x tag trailer George McCollister
2020-11-25 20:34   ` Andrew Lunn
2020-11-26 13:50     ` Vladimir Oltean
2020-11-26 14:01       ` Andrew Lunn
2020-11-26 14:28         ` Vladimir Oltean
2020-11-25 20:34   ` Andrew Lunn
2020-11-26  1:31   ` Florian Fainelli
2020-11-25 19:37 ` [PATCH net-next v2 2/3] net: dsa: add Arrow SpeedChips XRS700x driver George McCollister
2020-11-26  1:42   ` Jakub Kicinski
2020-11-26  2:25     ` George McCollister
2020-11-26 13:24       ` Vladimir Oltean
2020-11-26 17:56         ` Vladimir Oltean
2020-11-26 19:07           ` George McCollister
2020-11-26 22:05             ` Vladimir Oltean
2020-11-27 18:35               ` Jakub Kicinski
     [not found]                 ` <CAFSKS=MAdnR2jzmkQfTnSQZ7GY5x5KJE=oeqPCQdbZdf5n=4ZQ@mail.gmail.com>
2020-11-27 19:50                   ` Vladimir Oltean
2020-11-27 20:58                     ` George McCollister
2020-11-27 21:37                       ` Jakub Kicinski
2020-11-27 22:42                         ` Vladimir Oltean
2020-11-27 23:21                         ` Vladimir Oltean
2020-11-27 23:51                           ` Jakub Kicinski
2020-11-27 23:30                         ` Andrew Lunn
2020-11-27 23:39                           ` Vladimir Oltean
2020-11-27 23:56                             ` Jakub Kicinski
2020-11-28  1:45                               ` Vladimir Oltean
2020-11-28  0:02                             ` Vladimir Oltean
2020-11-28  0:39                               ` Andrew Lunn
2020-11-28  1:41                                 ` Vladimir Oltean [this message]
2020-11-28  2:15                                   ` Jakub Kicinski
2020-11-30 16:52                                     ` George McCollister
2020-11-30 23:50                                       ` Vladimir Oltean
2020-11-30 23:58                                         ` George McCollister
2020-12-01  0:19                                           ` Vladimir Oltean
2020-11-27 20:47                 ` Andrew Lunn
2020-11-27 21:13                   ` Jakub Kicinski
2020-11-27 21:23                     ` Vladimir Oltean
2020-11-27 21:36                       ` Andrew Lunn
2020-12-02  0:28                         ` Vladimir Oltean
2020-12-02  0:54                           ` Jakub Kicinski
2020-11-27 22:03                       ` Jakub Kicinski
2020-11-27 21:32                     ` Andrew Lunn
2020-11-27 22:14                       ` Jakub Kicinski
2020-11-27 22:46                         ` Andrew Lunn
2020-11-25 19:37 ` [PATCH net-next v2 3/3] dt-bindings: net: dsa: add bindings for xrs700x switches George McCollister
2020-11-26  1:30   ` Florian Fainelli

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=20201128014106.lcqi6btkudbnj3mc@skbuf \
    --to=olteanv@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=f.fainelli@gmail.com \
    --cc=george.mccollister@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=vivien.didelot@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox