Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch '100GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue

Tony Nguyen says:

====================
Intel Wired LAN Driver Updates 2021-12-17

Maciej Fijalkowski says:

It seems that previous [0] Rx fix was not enough and there are still
issues with AF_XDP Rx ZC support in ice driver. Elza reported that for
multiple XSK sockets configured on a single netdev, some of them were
becoming dead after a while. We have spotted more things that needed to
be addressed this time. More of information can be found in particular
commit messages.

It also carries Alexandr's patch that was sent previously which was
overlapping with this set.

[0]: https://lore.kernel.org/bpf/20211129231746.2767739-1-anthony.l.nguyen@intel.com/
====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+62 -41
+17
drivers/net/ethernet/intel/ice/ice_base.c
··· 6 6 #include "ice_lib.h" 7 7 #include "ice_dcb_lib.h" 8 8 9 + static bool ice_alloc_rx_buf_zc(struct ice_rx_ring *rx_ring) 10 + { 11 + rx_ring->xdp_buf = kcalloc(rx_ring->count, sizeof(*rx_ring->xdp_buf), GFP_KERNEL); 12 + return !!rx_ring->xdp_buf; 13 + } 14 + 15 + static bool ice_alloc_rx_buf(struct ice_rx_ring *rx_ring) 16 + { 17 + rx_ring->rx_buf = kcalloc(rx_ring->count, sizeof(*rx_ring->rx_buf), GFP_KERNEL); 18 + return !!rx_ring->rx_buf; 19 + } 20 + 9 21 /** 10 22 * __ice_vsi_get_qs_contig - Assign a contiguous chunk of queues to VSI 11 23 * @qs_cfg: gathered variables needed for PF->VSI queues assignment ··· 504 492 xdp_rxq_info_reg(&ring->xdp_rxq, ring->netdev, 505 493 ring->q_index, ring->q_vector->napi.napi_id); 506 494 495 + kfree(ring->rx_buf); 507 496 ring->xsk_pool = ice_xsk_pool(ring); 508 497 if (ring->xsk_pool) { 498 + if (!ice_alloc_rx_buf_zc(ring)) 499 + return -ENOMEM; 509 500 xdp_rxq_info_unreg_mem_model(&ring->xdp_rxq); 510 501 511 502 ring->rx_buf_len = ··· 523 508 dev_info(dev, "Registered XDP mem model MEM_TYPE_XSK_BUFF_POOL on Rx ring %d\n", 524 509 ring->q_index); 525 510 } else { 511 + if (!ice_alloc_rx_buf(ring)) 512 + return -ENOMEM; 526 513 if (!xdp_rxq_info_is_reg(&ring->xdp_rxq)) 527 514 /* coverity[check_return] */ 528 515 xdp_rxq_info_reg(&ring->xdp_rxq,
+13 -6
drivers/net/ethernet/intel/ice/ice_txrx.c
··· 419 419 } 420 420 421 421 rx_skip_free: 422 - memset(rx_ring->rx_buf, 0, sizeof(*rx_ring->rx_buf) * rx_ring->count); 422 + if (rx_ring->xsk_pool) 423 + memset(rx_ring->xdp_buf, 0, array_size(rx_ring->count, sizeof(*rx_ring->xdp_buf))); 424 + else 425 + memset(rx_ring->rx_buf, 0, array_size(rx_ring->count, sizeof(*rx_ring->rx_buf))); 423 426 424 427 /* Zero out the descriptor ring */ 425 428 size = ALIGN(rx_ring->count * sizeof(union ice_32byte_rx_desc), ··· 449 446 if (xdp_rxq_info_is_reg(&rx_ring->xdp_rxq)) 450 447 xdp_rxq_info_unreg(&rx_ring->xdp_rxq); 451 448 rx_ring->xdp_prog = NULL; 452 - devm_kfree(rx_ring->dev, rx_ring->rx_buf); 453 - rx_ring->rx_buf = NULL; 449 + if (rx_ring->xsk_pool) { 450 + kfree(rx_ring->xdp_buf); 451 + rx_ring->xdp_buf = NULL; 452 + } else { 453 + kfree(rx_ring->rx_buf); 454 + rx_ring->rx_buf = NULL; 455 + } 454 456 455 457 if (rx_ring->desc) { 456 458 size = ALIGN(rx_ring->count * sizeof(union ice_32byte_rx_desc), ··· 483 475 /* warn if we are about to overwrite the pointer */ 484 476 WARN_ON(rx_ring->rx_buf); 485 477 rx_ring->rx_buf = 486 - devm_kcalloc(dev, sizeof(*rx_ring->rx_buf), rx_ring->count, 487 - GFP_KERNEL); 478 + kcalloc(rx_ring->count, sizeof(*rx_ring->rx_buf), GFP_KERNEL); 488 479 if (!rx_ring->rx_buf) 489 480 return -ENOMEM; 490 481 ··· 512 505 return 0; 513 506 514 507 err: 515 - devm_kfree(dev, rx_ring->rx_buf); 508 + kfree(rx_ring->rx_buf); 516 509 rx_ring->rx_buf = NULL; 517 510 return -ENOMEM; 518 511 }
-1
drivers/net/ethernet/intel/ice/ice_txrx.h
··· 24 24 #define ICE_MAX_DATA_PER_TXD_ALIGNED \ 25 25 (~(ICE_MAX_READ_REQ_SIZE - 1) & ICE_MAX_DATA_PER_TXD) 26 26 27 - #define ICE_RX_BUF_WRITE 16 /* Must be power of 2 */ 28 27 #define ICE_MAX_TXQ_PER_TXQG 128 29 28 30 29 /* Attempt to maximize the headroom available for incoming frames. We use a 2K
+32 -34
drivers/net/ethernet/intel/ice/ice_xsk.c
··· 12 12 #include "ice_txrx_lib.h" 13 13 #include "ice_lib.h" 14 14 15 + static struct xdp_buff **ice_xdp_buf(struct ice_rx_ring *rx_ring, u32 idx) 16 + { 17 + return &rx_ring->xdp_buf[idx]; 18 + } 19 + 15 20 /** 16 21 * ice_qp_reset_stats - Resets all stats for rings of given index 17 22 * @vsi: VSI that contains rings of interest ··· 377 372 dma_addr_t dma; 378 373 379 374 rx_desc = ICE_RX_DESC(rx_ring, ntu); 380 - xdp = &rx_ring->xdp_buf[ntu]; 375 + xdp = ice_xdp_buf(rx_ring, ntu); 381 376 382 377 nb_buffs = min_t(u16, count, rx_ring->count - ntu); 383 378 nb_buffs = xsk_buff_alloc_batch(rx_ring->xsk_pool, xdp, nb_buffs); ··· 395 390 } 396 391 397 392 ntu += nb_buffs; 398 - if (ntu == rx_ring->count) { 399 - rx_desc = ICE_RX_DESC(rx_ring, 0); 400 - xdp = rx_ring->xdp_buf; 393 + if (ntu == rx_ring->count) 401 394 ntu = 0; 402 - } 403 395 404 - /* clear the status bits for the next_to_use descriptor */ 405 - rx_desc->wb.status_error0 = 0; 406 396 ice_release_rx_desc(rx_ring, ntu); 407 397 408 398 return count == nb_buffs; ··· 419 419 /** 420 420 * ice_construct_skb_zc - Create an sk_buff from zero-copy buffer 421 421 * @rx_ring: Rx ring 422 - * @xdp_arr: Pointer to the SW ring of xdp_buff pointers 422 + * @xdp: Pointer to XDP buffer 423 423 * 424 424 * This function allocates a new skb from a zero-copy Rx buffer. 425 425 * 426 426 * Returns the skb on success, NULL on failure. 427 427 */ 428 428 static struct sk_buff * 429 - ice_construct_skb_zc(struct ice_rx_ring *rx_ring, struct xdp_buff **xdp_arr) 429 + ice_construct_skb_zc(struct ice_rx_ring *rx_ring, struct xdp_buff *xdp) 430 430 { 431 - struct xdp_buff *xdp = *xdp_arr; 431 + unsigned int datasize_hard = xdp->data_end - xdp->data_hard_start; 432 432 unsigned int metasize = xdp->data - xdp->data_meta; 433 433 unsigned int datasize = xdp->data_end - xdp->data; 434 - unsigned int datasize_hard = xdp->data_end - xdp->data_hard_start; 435 434 struct sk_buff *skb; 436 435 437 436 skb = __napi_alloc_skb(&rx_ring->q_vector->napi, datasize_hard, ··· 444 445 skb_metadata_set(skb, metasize); 445 446 446 447 xsk_buff_free(xdp); 447 - *xdp_arr = NULL; 448 448 return skb; 449 449 } 450 450 ··· 505 507 int ice_clean_rx_irq_zc(struct ice_rx_ring *rx_ring, int budget) 506 508 { 507 509 unsigned int total_rx_bytes = 0, total_rx_packets = 0; 508 - u16 cleaned_count = ICE_DESC_UNUSED(rx_ring); 509 510 struct ice_tx_ring *xdp_ring; 510 511 unsigned int xdp_xmit = 0; 511 512 struct bpf_prog *xdp_prog; ··· 519 522 while (likely(total_rx_packets < (unsigned int)budget)) { 520 523 union ice_32b_rx_flex_desc *rx_desc; 521 524 unsigned int size, xdp_res = 0; 522 - struct xdp_buff **xdp; 525 + struct xdp_buff *xdp; 523 526 struct sk_buff *skb; 524 527 u16 stat_err_bits; 525 528 u16 vlan_tag = 0; ··· 537 540 */ 538 541 dma_rmb(); 539 542 543 + xdp = *ice_xdp_buf(rx_ring, rx_ring->next_to_clean); 544 + 540 545 size = le16_to_cpu(rx_desc->wb.pkt_len) & 541 546 ICE_RX_FLX_DESC_PKT_LEN_M; 542 - if (!size) 543 - break; 547 + if (!size) { 548 + xdp->data = NULL; 549 + xdp->data_end = NULL; 550 + xdp->data_hard_start = NULL; 551 + xdp->data_meta = NULL; 552 + goto construct_skb; 553 + } 544 554 545 - xdp = &rx_ring->xdp_buf[rx_ring->next_to_clean]; 546 - xsk_buff_set_size(*xdp, size); 547 - xsk_buff_dma_sync_for_cpu(*xdp, rx_ring->xsk_pool); 555 + xsk_buff_set_size(xdp, size); 556 + xsk_buff_dma_sync_for_cpu(xdp, rx_ring->xsk_pool); 548 557 549 - xdp_res = ice_run_xdp_zc(rx_ring, *xdp, xdp_prog, xdp_ring); 558 + xdp_res = ice_run_xdp_zc(rx_ring, xdp, xdp_prog, xdp_ring); 550 559 if (xdp_res) { 551 560 if (xdp_res & (ICE_XDP_TX | ICE_XDP_REDIR)) 552 561 xdp_xmit |= xdp_res; 553 562 else 554 - xsk_buff_free(*xdp); 563 + xsk_buff_free(xdp); 555 564 556 - *xdp = NULL; 557 565 total_rx_bytes += size; 558 566 total_rx_packets++; 559 - cleaned_count++; 560 567 561 568 ice_bump_ntc(rx_ring); 562 569 continue; 563 570 } 564 - 571 + construct_skb: 565 572 /* XDP_PASS path */ 566 573 skb = ice_construct_skb_zc(rx_ring, xdp); 567 574 if (!skb) { ··· 573 572 break; 574 573 } 575 574 576 - cleaned_count++; 577 575 ice_bump_ntc(rx_ring); 578 576 579 577 if (eth_skb_pad(skb)) { ··· 594 594 ice_receive_skb(rx_ring, skb, vlan_tag); 595 595 } 596 596 597 - if (cleaned_count >= ICE_RX_BUF_WRITE) 598 - failure = !ice_alloc_rx_bufs_zc(rx_ring, cleaned_count); 597 + failure = !ice_alloc_rx_bufs_zc(rx_ring, ICE_DESC_UNUSED(rx_ring)); 599 598 600 599 ice_finalize_xdp_rx(xdp_ring, xdp_xmit); 601 600 ice_update_rx_ring_stats(rx_ring, total_rx_packets, total_rx_bytes); ··· 810 811 */ 811 812 void ice_xsk_clean_rx_ring(struct ice_rx_ring *rx_ring) 812 813 { 813 - u16 i; 814 + u16 count_mask = rx_ring->count - 1; 815 + u16 ntc = rx_ring->next_to_clean; 816 + u16 ntu = rx_ring->next_to_use; 814 817 815 - for (i = 0; i < rx_ring->count; i++) { 816 - struct xdp_buff **xdp = &rx_ring->xdp_buf[i]; 818 + for ( ; ntc != ntu; ntc = (ntc + 1) & count_mask) { 819 + struct xdp_buff *xdp = *ice_xdp_buf(rx_ring, ntc); 817 820 818 - if (!xdp) 819 - continue; 820 - 821 - *xdp = NULL; 821 + xsk_buff_free(xdp); 822 822 } 823 823 } 824 824