From: Felix Riemann <hidden> Date: 2023-02-10 12:37:44
From: Felix Riemann <redacted>
When converting net_device_stats to rtnl_link_stats64 sign extension
is triggered on ILP32 machines as 6c1c509778 changed the previous
"ulong -> u64" conversion to "long -> u64" by accessing the
net_device_stats fields through a (signed) atomic_long_t.
This causes for example the received bytes counter to jump to 16EiB after
having received 2^31 bytes. Casting the atomic value to "unsigned long"
beforehand converting it into u64 avoids this.
Fixes: 6c1c5097781f ("net: add atomic_long_t to net_device_stats fields")
Signed-off-by: Felix Riemann <redacted>
---
net/core/dev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
@@ -10375,7 +10375,7 @@ void netdev_stats_to_stats64(struct rtnl_link_stats64 *stats64,BUILD_BUG_ON(n>sizeof(*stats64)/sizeof(u64));for(i=0;i<n;i++)-dst[i]=atomic_long_read(&src[i]);+dst[i]=(unsignedlong)atomic_long_read(&src[i]);/* zero out counters that only exist in rtnl_link_stats64 */memset((char*)stats64+n*sizeof(u64),0,sizeof(*stats64)-n*sizeof(u64));
From: Eric Dumazet <edumazet@google.com> Date: 2023-02-10 15:13:40
On Fri, Feb 10, 2023 at 1:37 PM Felix Riemann [off-list ref] wrote:
From: Felix Riemann <redacted>
When converting net_device_stats to rtnl_link_stats64 sign extension
is triggered on ILP32 machines as 6c1c509778 changed the previous
"ulong -> u64" conversion to "long -> u64" by accessing the
net_device_stats fields through a (signed) atomic_long_t.
This causes for example the received bytes counter to jump to 16EiB after
having received 2^31 bytes. Casting the atomic value to "unsigned long"
beforehand converting it into u64 avoids this.
Fixes: 6c1c5097781f ("net: add atomic_long_t to net_device_stats fields")
Signed-off-by: Felix Riemann <redacted>
---
Thanks for the fix.
Reviewed-by: Eric Dumazet <edumazet@google.com>
Hello:
This patch was applied to netdev/net.git (master)
by David S. Miller [off-list ref]:
On Fri, 10 Feb 2023 13:36:44 +0100 you wrote:
From: Felix Riemann <redacted>
When converting net_device_stats to rtnl_link_stats64 sign extension
is triggered on ILP32 machines as 6c1c509778 changed the previous
"ulong -> u64" conversion to "long -> u64" by accessing the
net_device_stats fields through a (signed) atomic_long_t.
[...]