Re: [PATCH v3 net-next 10/12] net: bonding: ensure .ndo_get_stats64 can sleep
From: Eric Dumazet <edumazet@google.com>
Date: 2021-01-07 11:19:29
On Thu, Jan 7, 2021 at 10:51 AM Vladimir Oltean [off-list ref] wrote:
From: Vladimir Oltean <vladimir.oltean@nxp.com>
-
static void bond_get_stats(struct net_device *bond_dev,
struct rtnl_link_stats64 *stats)
{
struct bonding *bond = netdev_priv(bond_dev);
- struct rtnl_link_stats64 temp;
- struct list_head *iter;
- struct slave *slave;
- int nest_level = 0;
+ struct rtnl_link_stats64 *dev_stats;
+ struct net_device **slaves;
+ int i, res, num_slaves;
+ res = bond_get_slave_arr(bond, &slaves, &num_slaves);
+ if (res) {
+ netdev_err(bond->dev,
+ "failed to allocate memory for slave array\n");
+ return;
+ }What a mess really. You chose to keep the assumption that ndo_get_stats() would not fail, since we were providing the needed storage from callers. If ndo_get_stats() are now allowed to sleep, and presumably allocate memory, we need to make sure we report potential errors back to the user. I think your patch series is mostly good, but I would prefer not hiding errors and always report them to user space. And no, netdev_err() is not appropriate, we do not want tools to look at syslog to guess something went wrong. Last point about drivers having to go to slow path, talking to firmware : Make sure that malicious/innocent users reading /proc/net/dev from many threads in parallel wont brick these devices. Maybe they implicitly _relied_ on the fact that firmware was gently read every second and results were cached from a work queue or something. Thanks.