Skip to content

Commit befc7a3

Browse files
committed
Merge branch 'nfp-fix-ethtool-stats-and-page-allocation'
Jakub Kicinski says: ==================== nfp: fix ethtool stats and page allocation Two fixes for net. First one makes sure we handle gather of stats on 32bit machines correctly (ouch). The second fix solves a potential NULL-deref if we fail to allocate a page with XDP running. I used Fixes: tags pointing to where the bug was introduced, but for patch 1 it has been in the driver "for ever" and fix won't backport cleanly beyond commit 325945e ("nfp: split software and hardware vNIC statistics") which is in net. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 3668bb8 + 5f0ca2f commit befc7a3

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

drivers/net/ethernet/netronome/nfp/nfp_net_common.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,10 +1180,14 @@ static void *nfp_net_rx_alloc_one(struct nfp_net_dp *dp, dma_addr_t *dma_addr)
11801180
{
11811181
void *frag;
11821182

1183-
if (!dp->xdp_prog)
1183+
if (!dp->xdp_prog) {
11841184
frag = netdev_alloc_frag(dp->fl_bufsz);
1185-
else
1186-
frag = page_address(alloc_page(GFP_KERNEL | __GFP_COLD));
1185+
} else {
1186+
struct page *page;
1187+
1188+
page = alloc_page(GFP_KERNEL | __GFP_COLD);
1189+
frag = page ? page_address(page) : NULL;
1190+
}
11871191
if (!frag) {
11881192
nn_dp_warn(dp, "Failed to alloc receive page frag\n");
11891193
return NULL;
@@ -1203,10 +1207,14 @@ static void *nfp_net_napi_alloc_one(struct nfp_net_dp *dp, dma_addr_t *dma_addr)
12031207
{
12041208
void *frag;
12051209

1206-
if (!dp->xdp_prog)
1210+
if (!dp->xdp_prog) {
12071211
frag = napi_alloc_frag(dp->fl_bufsz);
1208-
else
1209-
frag = page_address(alloc_page(GFP_ATOMIC | __GFP_COLD));
1212+
} else {
1213+
struct page *page;
1214+
1215+
page = alloc_page(GFP_ATOMIC | __GFP_COLD);
1216+
frag = page ? page_address(page) : NULL;
1217+
}
12101218
if (!frag) {
12111219
nn_dp_warn(dp, "Failed to alloc receive page frag\n");
12121220
return NULL;

drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,22 +464,24 @@ static u64 *nfp_vnic_get_sw_stats(struct net_device *netdev, u64 *data)
464464

465465
do {
466466
start = u64_stats_fetch_begin(&nn->r_vecs[i].rx_sync);
467-
*data++ = nn->r_vecs[i].rx_pkts;
467+
data[0] = nn->r_vecs[i].rx_pkts;
468468
tmp[0] = nn->r_vecs[i].hw_csum_rx_ok;
469469
tmp[1] = nn->r_vecs[i].hw_csum_rx_inner_ok;
470470
tmp[2] = nn->r_vecs[i].hw_csum_rx_error;
471471
} while (u64_stats_fetch_retry(&nn->r_vecs[i].rx_sync, start));
472472

473473
do {
474474
start = u64_stats_fetch_begin(&nn->r_vecs[i].tx_sync);
475-
*data++ = nn->r_vecs[i].tx_pkts;
476-
*data++ = nn->r_vecs[i].tx_busy;
475+
data[1] = nn->r_vecs[i].tx_pkts;
476+
data[2] = nn->r_vecs[i].tx_busy;
477477
tmp[3] = nn->r_vecs[i].hw_csum_tx;
478478
tmp[4] = nn->r_vecs[i].hw_csum_tx_inner;
479479
tmp[5] = nn->r_vecs[i].tx_gather;
480480
tmp[6] = nn->r_vecs[i].tx_lso;
481481
} while (u64_stats_fetch_retry(&nn->r_vecs[i].tx_sync, start));
482482

483+
data += 3;
484+
483485
for (j = 0; j < NN_ET_RVEC_GATHER_STATS; j++)
484486
gathered_stats[j] += tmp[j];
485487
}

0 commit comments

Comments
 (0)