Re: [PATCH v2 net-next 11/26] sf100, sfx: implement generic XDP stats callbacks
From: Edward Cree <ecree.xilinx@gmail.com>
Date: 2021-11-24 10:00:09
Also in:
bpf, netdev
From: Edward Cree <ecree.xilinx@gmail.com>
Date: 2021-11-24 10:00:09
Also in:
bpf, netdev
On 23/11/2021 16:39, Alexander Lobakin wrote:
Export 4 per-channel XDP counters for both sf100 and sfx drivers using generic XDP stats infra. Signed-off-by: Alexander Lobakin <redacted> Reviewed-by: Jesse Brandeburg <redacted>
The usual Subject: prefix for these drivers is sfc: (or occasionally sfc_ef100: for ef100-specific stuff).
+int efx_get_xdp_stats_nch(const struct net_device *net_dev, u32 attr_id)
+{
+ const struct efx_nic *efx = netdev_priv(net_dev);
+
+ switch (attr_id) {
+ case IFLA_XDP_XSTATS_TYPE_XDP:
+ return efx->n_channels;
+ default:
+ return -EOPNOTSUPP;
+ }
+}
+
+int efx_get_xdp_stats(const struct net_device *net_dev, u32 attr_id,
+ void *attr_data)
+{
+ struct ifla_xdp_stats *xdp_stats = attr_data;
+ struct efx_nic *efx = netdev_priv(net_dev);
+ const struct efx_channel *channel;
+
+ switch (attr_id) {
+ case IFLA_XDP_XSTATS_TYPE_XDP:
+ break;
+ default:
+ return -EOPNOTSUPP;
+ }
+
+ spin_lock_bh(&efx->stats_lock);
+
+ efx_for_each_channel(channel, efx) {
+ xdp_stats->drop = channel->n_rx_xdp_drops;
+ xdp_stats->errors = channel->n_rx_xdp_bad_drops;
+ xdp_stats->redirect = channel->n_rx_xdp_redirect;
+ xdp_stats->tx = channel->n_rx_xdp_tx;
+
+ xdp_stats++;
+ }What guarantees that efx->n_channels won't change between these twocalls, potentially overrunning the buffer? -ed