[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <YmGLkz+dIBb5JjFF@linutronix.de>
Date: Thu, 21 Apr 2022 18:51:31 +0200
From: Sebastian Andrzej Siewior <bigeasy@...utronix.de>
To: Eric Dumazet <edumazet@...gle.com>
Cc: netdev <netdev@...r.kernel.org>,
"David S. Miller" <davem@...emloft.net>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Thomas Gleixner <tglx@...utronix.de>,
Peter Zijlstra <peterz@...radead.org>
Subject: Re: [PATCH net] net: Use this_cpu_inc() to increment net->core_stats
On 2022-04-21 09:06:05 [-0700], Eric Dumazet wrote:
> On Thu, Apr 21, 2022 at 7:00 AM Sebastian Andrzej Siewior
> <bigeasy@...utronix.de> wrote:
> >
>
> > for_each_possible_cpu(i) {
> > core_stats = per_cpu_ptr(p, i);
> > - storage->rx_dropped += local_read(&core_stats->rx_dropped);
> > - storage->tx_dropped += local_read(&core_stats->tx_dropped);
> > - storage->rx_nohandler += local_read(&core_stats->rx_nohandler);
> > + storage->rx_dropped += core_stats->rx_dropped;
> > + storage->tx_dropped += core_stats->tx_dropped;
> > + storage->rx_nohandler += core_stats->rx_nohandler;
>
> I think that one of the reasons for me to use local_read() was that
> it provided what was needed to avoid future syzbot reports.
syzbot report due a plain read of a per-CPU variable which might be
modified?
> Perhaps use READ_ONCE() here ?
>
> Yes, we have many similar folding loops that are simply assuming
> compiler won't do stupid things.
I wasn't sure about that and added PeterZ to do some yelling here just
in case. And yes, we have other sites doing exactly that. In
Documentation/core-api/this_cpu_ops.rst
there is nothing about remote-READ-access (only that there should be no
writes (due to parallel this_cpu_inc() on the local CPU)). I know that a
32bit write can be optimized in two 16bit writes in certain cases but a
read is a read.
PeterZ? :)
Sebastian
Powered by blists - more mailing lists