]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
net: add atomic_long_t to net_device_stats fields
authorEric Dumazet <edumazet@google.com>
Tue, 15 Nov 2022 08:53:55 +0000 (08:53 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 10 Oct 2023 19:44:57 +0000 (21:44 +0200)
commit2b601fcacd30ea9b3f777490e7c788b548389991
treecc15d687b18106809897c40cd934dc1fc7c06284
parent57fb8b599ec66c3dfa5467473994e663036db82a
net: add atomic_long_t to net_device_stats fields

[ Upstream commit 6c1c5097781f563b70a81683ea6fdac21637573b ]

Long standing KCSAN issues are caused by data-race around
some dev->stats changes.

Most performance critical paths already use per-cpu
variables, or per-queue ones.

It is reasonable (and more correct) to use atomic operations
for the slow paths.

This patch adds an union for each field of net_device_stats,
so that we can convert paths that are not yet protected
by a spinlock or a mutex.

netdev_stats_to_stats64() no longer has an #if BITS_PER_LONG==64

Note that the memcpy() we were using on 64bit arches
had no provision to avoid load-tearing,
while atomic_long_read() is providing the needed protection
at no cost.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Stable-dep-of: 44bdb313da57 ("net: bridge: use DEV_STATS_INC()")
Signed-off-by: Sasha Levin <sashal@kernel.org>
include/linux/netdevice.h
include/net/dst.h
net/core/dev.c