Skip to contentSkip to conversation

ndo_get_stats and rtnl_netlink

DISCUSSION Shlomo Pongartz 3 participants 4 messages Sep 9, 2012 – Sep 10, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

Just realized that dev_get_stats which calls into a netdevice ndo_get_stats64/ndo_get_stats can be called with or without RTNL lock protection. If called from rtnl_fill_ifinfo e.g as of invocation of "ip link show <interface>, there IS locking, however if called from dev_seq_printf_stats e.g as of invocation of reading the /sys/class/net/<interface>/statistics/ entries, etc more cases -- no locking.

This turned to be problematic when implementing the ethtool "set_channels" directive which changes the number of **rings**, since we stepped on a bug where the rings data structure was changed by the ethtool flow in the same time a statistics call was done into the driver, etc.

What would be the way to continue here, per driver lock sounds non generic...

Regards
Shlomo Pongratz

#1 lore raw
Quoted 18 lines · Shlomo Pongartz

Hi,

Just realized that dev_get_stats which calls into a netdevice ndo_get_stats64/ndo_get_stats can be
called with or without RTNL lock protection. If called from rtnl_fill_ifinfo e.g as of invocation of
"ip link show <interface>, there IS locking, however if called from dev_seq_printf_stats e.g as of
invocation of reading the /sys/class/net/<interface>/statistics/ entries, etc more cases -- no locking.

This turned to be problematic when implementing the ethtool "set_channels" directive which
changes the number of **rings**, since we stepped on a bug where the rings data structure was
changed by the ethtool flow in the same time a statistics call was done into the driver, etc.

Quoted 2 lines

What would be the way to continue here, per driver lock sounds non generic...

RTNL locking is not needed to fetch stats, and would be overkill.

Each driver has its own way to protect/gather its stats.

#2 lore raw
Quoted 2 lines · Eric Dumazet

RTNL locking is not needed to fetch stats, and would be overkill. Each driver has its own way to protect/gather its stats.

FWIW, again, when dev_get_stats is called from rtnl_fill_ifinfo e.g as of invocation
of "ip link show <interface>, there IS RTNL locking, is that a problem?

Or.

#3 lore raw
Quoted 10 lines · Or Gerlitz
Quoted 2 lines · Eric Dumazet

RTNL locking is not needed to fetch stats, and would be overkill. Each driver has its own way to protect/gather its stats.

FWIW, again, when dev_get_stats is called from rtnl_fill_ifinfo e.g as of invocation
of "ip link show <interface>, there IS RTNL locking, is that a problem?

Or.

Why should it be a problem ?

A dev_get_stats() is not allowed to sleep, so its not allowed to use RTNL by itself.

So caller might use RTNL, we dont care at all.