Merge https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next
authorDavid S. Miller <davem@davemloft.net>
Thu, 25 Mar 2021 23:30:46 +0000 (16:30 -0700)
committerDavid S. Miller <davem@davemloft.net>
Thu, 25 Mar 2021 23:30:46 +0000 (16:30 -0700)
Alexei Starovoitov says:

====================
pull-request: bpf-next 2021-03-24

The following pull-request contains BPF updates for your *net-next* tree.

We've added 37 non-merge commits during the last 15 day(s) which contain
a total of 65 files changed, 3200 insertions(+), 738 deletions(-).

The main changes are:

1) Static linking of multiple BPF ELF files, from Andrii.

2) Move drop error path to devmap for XDP_REDIRECT, from Lorenzo.

3) Spelling fixes from various folks.
====================

Signed-off-by: David S. Miller <davem@davemloft.net>
12 files changed:
1  2 
drivers/net/ethernet/intel/i40e/i40e_txrx.c
drivers/net/ethernet/intel/ice/ice_txrx.c
drivers/net/ethernet/intel/igb/igb_main.c
drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
drivers/net/ethernet/socionext/netsec.c
drivers/net/veth.c
drivers/net/virtio_net.c
kernel/bpf/verifier.c
net/core/filter.c
tools/lib/bpf/Makefile
tools/lib/bpf/btf_dump.c
tools/lib/bpf/libbpf.c

@@@ -1569,6 -1569,17 +1569,6 @@@ void i40e_free_rx_resources(struct i40e
        }
  }
  
 -/**
 - * i40e_rx_offset - Return expected offset into page to access data
 - * @rx_ring: Ring we are requesting offset of
 - *
 - * Returns the offset value for ring into the data buffer.
 - */
 -static unsigned int i40e_rx_offset(struct i40e_ring *rx_ring)
 -{
 -      return ring_uses_build_skb(rx_ring) ? I40E_SKB_PAD : 0;
 -}
 -
  /**
   * i40e_setup_rx_descriptors - Allocate Rx descriptors
   * @rx_ring: Rx descriptor ring (for a specific queue) to setup
@@@ -1597,6 -1608,7 +1597,6 @@@ int i40e_setup_rx_descriptors(struct i4
        rx_ring->next_to_alloc = 0;
        rx_ring->next_to_clean = 0;
        rx_ring->next_to_use = 0;
 -      rx_ring->rx_offset = i40e_rx_offset(rx_ring);
  
        /* XDP RX-queue info only needed for RX rings exposed to XDP */
        if (rx_ring->vsi->type == I40E_VSI_MAIN) {
@@@ -3333,7 -3345,7 +3333,7 @@@ static int i40e_tx_enable_csum(struct s
  }
  
  /**
 - * i40e_create_tx_ctx Build the Tx context descriptor
 + * i40e_create_tx_ctx Build the Tx context descriptor
   * @tx_ring:  ring to create the descriptor on
   * @cd_type_cmd_tso_mss: Quad Word 1
   * @cd_tunneling: Quad Word 0 - bits 0-31
@@@ -3835,8 -3847,8 +3835,8 @@@ netdev_tx_t i40e_lan_xmit_frame(struct 
   * @frames: array of XDP buffer pointers
   * @flags: XDP extra info
   *
-  * Returns number of frames successfully sent. Frames that fail are
-  * free'ed via XDP return API.
+  * Returns number of frames successfully sent. Failed frames
+  * will be free'ed by XDP core.
   *
   * For error cases, a negative errno code is returned and no-frames
   * are transmitted (caller must handle freeing frames).
@@@ -3849,7 -3861,7 +3849,7 @@@ int i40e_xdp_xmit(struct net_device *de
        struct i40e_vsi *vsi = np->vsi;
        struct i40e_pf *pf = vsi->back;
        struct i40e_ring *xdp_ring;
-       int drops = 0;
+       int nxmit = 0;
        int i;
  
        if (test_bit(__I40E_VSI_DOWN, vsi->state))
                int err;
  
                err = i40e_xmit_xdp_ring(xdpf, xdp_ring);
-               if (err != I40E_XDP_TX) {
-                       xdp_return_frame_rx_napi(xdpf);
-                       drops++;
-               }
+               if (err != I40E_XDP_TX)
+                       break;
+               nxmit++;
        }
  
        if (unlikely(flags & XDP_XMIT_FLUSH))
                i40e_xdp_ring_update_tail(xdp_ring);
  
-       return n - drops;
+       return nxmit;
  }
@@@ -443,6 -443,22 +443,6 @@@ void ice_free_rx_ring(struct ice_ring *
        }
  }
  
 -/**
 - * ice_rx_offset - Return expected offset into page to access data
 - * @rx_ring: Ring we are requesting offset of
 - *
 - * Returns the offset value for ring into the data buffer.
 - */
 -static unsigned int ice_rx_offset(struct ice_ring *rx_ring)
 -{
 -      if (ice_ring_uses_build_skb(rx_ring))
 -              return ICE_SKB_PAD;
 -      else if (ice_is_xdp_ena_vsi(rx_ring->vsi))
 -              return XDP_PACKET_HEADROOM;
 -
 -      return 0;
 -}
 -
  /**
   * ice_setup_rx_ring - Allocate the Rx descriptors
   * @rx_ring: the Rx ring to set up
@@@ -477,6 -493,7 +477,6 @@@ int ice_setup_rx_ring(struct ice_ring *
  
        rx_ring->next_to_use = 0;
        rx_ring->next_to_clean = 0;
 -      rx_ring->rx_offset = ice_rx_offset(rx_ring);
  
        if (ice_is_xdp_ena_vsi(rx_ring->vsi))
                WRITE_ONCE(rx_ring->xdp_prog, rx_ring->vsi->xdp_prog);
@@@ -554,8 -571,8 +554,8 @@@ ice_run_xdp(struct ice_ring *rx_ring, s
   * @frames: XDP frames to be transmitted
   * @flags: transmit flags
   *
-  * Returns number of frames successfully sent. Frames that fail are
-  * free'ed via XDP return API.
+  * Returns number of frames successfully sent. Failed frames
+  * will be free'ed by XDP core.
   * For error cases, a negative errno code is returned and no-frames
   * are transmitted (caller must handle freeing frames).
   */
@@@ -567,7 -584,7 +567,7 @@@ ice_xdp_xmit(struct net_device *dev, in
        unsigned int queue_index = smp_processor_id();
        struct ice_vsi *vsi = np->vsi;
        struct ice_ring *xdp_ring;
-       int drops = 0, i;
+       int nxmit = 0, i;
  
        if (test_bit(__ICE_DOWN, vsi->state))
                return -ENETDOWN;
                int err;
  
                err = ice_xmit_xdp_ring(xdpf->data, xdpf->len, xdp_ring);
-               if (err != ICE_XDP_TX) {
-                       xdp_return_frame_rx_napi(xdpf);
-                       drops++;
-               }
+               if (err != ICE_XDP_TX)
+                       break;
+               nxmit++;
        }
  
        if (unlikely(flags & XDP_XMIT_FLUSH))
                ice_xdp_ring_update_tail(xdp_ring);
  
-       return n - drops;
+       return nxmit;
  }
  
  /**
@@@ -1098,11 -1114,6 +1097,11 @@@ int ice_clean_rx_irq(struct ice_ring *r
                dma_rmb();
  
                if (rx_desc->wb.rxdid == FDIR_DESC_RXDID || !rx_ring->netdev) {
 +                      struct ice_vsi *ctrl_vsi = rx_ring->vsi;
 +
 +                      if (rx_desc->wb.rxdid == FDIR_DESC_RXDID &&
 +                          ctrl_vsi->vf_id != ICE_INVAL_VFID)
 +                              ice_vc_fdir_irq_handler(ctrl_vsi, rx_desc);
                        ice_put_rx_buf(rx_ring, NULL, 0);
                        cleaned_count++;
                        continue;
@@@ -2037,7 -2037,7 +2037,7 @@@ static void igb_power_down_link(struct 
  }
  
  /**
 - * Detect and switch function for Media Auto Sense
 + * igb_check_swap_media -  Detect and switch function for Media Auto Sense
   * @adapter: address of the board private structure
   **/
  static void igb_check_swap_media(struct igb_adapter *adapter)
@@@ -2934,7 -2934,7 +2934,7 @@@ static int igb_xdp_xmit(struct net_devi
        int cpu = smp_processor_id();
        struct igb_ring *tx_ring;
        struct netdev_queue *nq;
-       int drops = 0;
+       int nxmit = 0;
        int i;
  
        if (unlikely(test_bit(__IGB_DOWN, &adapter->state)))
                int err;
  
                err = igb_xmit_xdp_ring(adapter, tx_ring, xdpf);
-               if (err != IGB_XDP_TX) {
-                       xdp_return_frame_rx_napi(xdpf);
-                       drops++;
-               }
+               if (err != IGB_XDP_TX)
+                       break;
+               nxmit++;
        }
  
        __netif_tx_unlock(nq);
        if (unlikely(flags & XDP_XMIT_FLUSH))
                igb_xdp_ring_update_tail(tx_ring);
  
-       return n - drops;
+       return nxmit;
  }
  
  static const struct net_device_ops igb_netdev_ops = {
@@@ -3115,7 -3114,7 +3114,7 @@@ static s32 igb_init_i2c(struct igb_adap
                return 0;
  
        /* Initialize the i2c bus which is controlled by the registers.
 -       * This bus will use the i2c_algo_bit structue that implements
 +       * This bus will use the i2c_algo_bit structure that implements
         * the protocol through toggling of the 4 bits in the register.
         */
        adapter->i2c_adap.owner = THIS_MODULE;
@@@ -4020,7 -4019,7 +4019,7 @@@ static int igb_sw_init(struct igb_adapt
  }
  
  /**
 - *  igb_open - Called when a network interface is made active
 + *  __igb_open - Called when a network interface is made active
   *  @netdev: network interface device structure
   *  @resuming: indicates whether we are in a resume call
   *
@@@ -4138,7 -4137,7 +4137,7 @@@ int igb_open(struct net_device *netdev
  }
  
  /**
 - *  igb_close - Disables a network interface
 + *  __igb_close - Disables a network interface
   *  @netdev: network interface device structure
   *  @suspending: indicates we are in a suspend call
   *
@@@ -5856,7 -5855,7 +5855,7 @@@ static void igb_tx_ctxtdesc(struct igb_
         */
        if (tx_ring->launchtime_enable) {
                ts = ktime_to_timespec64(first->skb->tstamp);
 -              first->skb->tstamp = ktime_set(0, 0);
 +              skb_txtime_consumed(first->skb);
                context_desc->seqnum_seed = cpu_to_le32(ts.tv_nsec / 32);
        } else {
                context_desc->seqnum_seed = 0;
@@@ -8214,8 -8213,7 +8213,8 @@@ static void igb_reuse_rx_page(struct ig
        new_buff->pagecnt_bias  = old_buff->pagecnt_bias;
  }
  
 -static bool igb_can_reuse_rx_page(struct igb_rx_buffer *rx_buffer)
 +static bool igb_can_reuse_rx_page(struct igb_rx_buffer *rx_buffer,
 +                                int rx_buf_pgcnt)
  {
        unsigned int pagecnt_bias = rx_buffer->pagecnt_bias;
        struct page *page = rx_buffer->page;
  
  #if (PAGE_SIZE < 8192)
        /* if we are only owner of page we can reuse it */
 -      if (unlikely((page_ref_count(page) - pagecnt_bias) > 1))
 +      if (unlikely((rx_buf_pgcnt - pagecnt_bias) > 1))
                return false;
  #else
  #define IGB_LAST_OFFSET \
@@@ -8302,10 -8300,9 +8301,10 @@@ static struct sk_buff *igb_construct_sk
                return NULL;
  
        if (unlikely(igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP))) {
 -              igb_ptp_rx_pktstamp(rx_ring->q_vector, xdp->data, skb);
 -              xdp->data += IGB_TS_HDR_LEN;
 -              size -= IGB_TS_HDR_LEN;
 +              if (!igb_ptp_rx_pktstamp(rx_ring->q_vector, xdp->data, skb)) {
 +                      xdp->data += IGB_TS_HDR_LEN;
 +                      size -= IGB_TS_HDR_LEN;
 +              }
        }
  
        /* Determine available headroom for copy */
@@@ -8366,8 -8363,8 +8365,8 @@@ static struct sk_buff *igb_build_skb(st
  
        /* pull timestamp out of packet data */
        if (igb_test_staterr(rx_desc, E1000_RXDADV_STAT_TSIP)) {
 -              igb_ptp_rx_pktstamp(rx_ring->q_vector, skb->data, skb);
 -              __skb_pull(skb, IGB_TS_HDR_LEN);
 +              if (!igb_ptp_rx_pktstamp(rx_ring->q_vector, skb->data, skb))
 +                      __skb_pull(skb, IGB_TS_HDR_LEN);
        }
  
        /* update buffer offset */
@@@ -8616,17 -8613,11 +8615,17 @@@ static unsigned int igb_rx_offset(struc
  }
  
  static struct igb_rx_buffer *igb_get_rx_buffer(struct igb_ring *rx_ring,
 -                                             const unsigned int size)
 +                                             const unsigned int size, int *rx_buf_pgcnt)
  {
        struct igb_rx_buffer *rx_buffer;
  
        rx_buffer = &rx_ring->rx_buffer_info[rx_ring->next_to_clean];
 +      *rx_buf_pgcnt =
 +#if (PAGE_SIZE < 8192)
 +              page_count(rx_buffer->page);
 +#else
 +              0;
 +#endif
        prefetchw(rx_buffer->page);
  
        /* we are reusing so sync this buffer for CPU use */
  }
  
  static void igb_put_rx_buffer(struct igb_ring *rx_ring,
 -                            struct igb_rx_buffer *rx_buffer)
 +                            struct igb_rx_buffer *rx_buffer, int rx_buf_pgcnt)
  {
 -      if (igb_can_reuse_rx_page(rx_buffer)) {
 +      if (igb_can_reuse_rx_page(rx_buffer, rx_buf_pgcnt)) {
                /* hand second half of page back to the ring */
                igb_reuse_rx_page(rx_ring, rx_buffer);
        } else {
@@@ -8672,7 -8663,6 +8671,7 @@@ static int igb_clean_rx_irq(struct igb_
        unsigned int xdp_xmit = 0;
        struct xdp_buff xdp;
        u32 frame_sz = 0;
 +      int rx_buf_pgcnt;
  
        /* Frame size depend on rx_ring setup when PAGE_SIZE=4K */
  #if (PAGE_SIZE < 8192)
                 */
                dma_rmb();
  
 -              rx_buffer = igb_get_rx_buffer(rx_ring, size);
 +              rx_buffer = igb_get_rx_buffer(rx_ring, size, &rx_buf_pgcnt);
  
                /* retrieve a buffer from the ring */
                if (!skb) {
                        break;
                }
  
 -              igb_put_rx_buffer(rx_ring, rx_buffer);
 +              igb_put_rx_buffer(rx_ring, rx_buffer, rx_buf_pgcnt);
                cleaned_count++;
  
                /* fetch next buffer in frame if non-eop */
@@@ -225,7 -225,7 +225,7 @@@ static s32 ixgbe_get_parent_bus_info(st
  }
  
  /**
 - * ixgbe_check_from_parent - Determine whether PCIe info should come from parent
 + * ixgbe_pcie_from_parent - Determine whether PCIe info should come from parent
   * @hw: hw specific details
   *
   * This function is used by probe to determine whether a device's PCI-Express
@@@ -4118,8 -4118,6 +4118,8 @@@ void ixgbe_configure_rx_ring(struct ixg
  #endif
        }
  
 +      ring->rx_offset = ixgbe_rx_offset(ring);
 +
        if (ring->xsk_pool && hw->mac.type != ixgbe_mac_82599EB) {
                u32 xsk_buf_len = xsk_pool_get_rx_frame_size(ring->xsk_pool);
  
@@@ -6158,7 -6156,7 +6158,7 @@@ void ixgbe_down(struct ixgbe_adapter *a
  }
  
  /**
 - * ixgbe_eee_capable - helper function to determine EEE support on X550
 + * ixgbe_set_eee_capable - helper function to determine EEE support on X550
   * @adapter: board private structure
   */
  static void ixgbe_set_eee_capable(struct ixgbe_adapter *adapter)
@@@ -6580,6 -6578,7 +6580,6 @@@ int ixgbe_setup_rx_resources(struct ixg
  
        rx_ring->next_to_clean = 0;
        rx_ring->next_to_use = 0;
 -      rx_ring->rx_offset = ixgbe_rx_offset(rx_ring);
  
        /* XDP RX-queue info */
        if (xdp_rxq_info_reg(&rx_ring->xdp_rxq, adapter->netdev,
@@@ -10189,7 -10188,7 +10189,7 @@@ static int ixgbe_xdp_xmit(struct net_de
  {
        struct ixgbe_adapter *adapter = netdev_priv(dev);
        struct ixgbe_ring *ring;
-       int drops = 0;
+       int nxmit = 0;
        int i;
  
        if (unlikely(test_bit(__IXGBE_DOWN, &adapter->state)))
                int err;
  
                err = ixgbe_xmit_xdp_ring(adapter, xdpf);
-               if (err != IXGBE_XDP_TX) {
-                       xdp_return_frame_rx_napi(xdpf);
-                       drops++;
-               }
+               if (err != IXGBE_XDP_TX)
+                       break;
+               nxmit++;
        }
  
        if (unlikely(flags & XDP_XMIT_FLUSH))
                ixgbe_xdp_ring_update_tail(ring);
  
-       return n - drops;
+       return nxmit;
  }
  
  static const struct net_device_ops ixgbe_netdev_ops = {
@@@ -1715,17 -1715,14 +1715,17 @@@ static int netsec_netdev_init(struct ne
                goto err1;
  
        /* set phy power down */
 -      data = netsec_phy_read(priv->mii_bus, priv->phy_addr, MII_BMCR) |
 -              BMCR_PDOWN;
 -      netsec_phy_write(priv->mii_bus, priv->phy_addr, MII_BMCR, data);
 +      data = netsec_phy_read(priv->mii_bus, priv->phy_addr, MII_BMCR);
 +      netsec_phy_write(priv->mii_bus, priv->phy_addr, MII_BMCR,
 +                       data | BMCR_PDOWN);
  
        ret = netsec_reset_hardware(priv, true);
        if (ret)
                goto err2;
  
 +      /* Restore phy power state */
 +      netsec_phy_write(priv->mii_bus, priv->phy_addr, MII_BMCR, data);
 +
        spin_lock_init(&priv->desc_ring[NETSEC_RING_TX].lock);
        spin_lock_init(&priv->desc_ring[NETSEC_RING_RX].lock);
  
@@@ -1760,8 -1757,7 +1760,7 @@@ static int netsec_xdp_xmit(struct net_d
  {
        struct netsec_priv *priv = netdev_priv(ndev);
        struct netsec_desc_ring *tx_ring = &priv->desc_ring[NETSEC_RING_TX];
-       int drops = 0;
-       int i;
+       int i, nxmit = 0;
  
        if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK))
                return -EINVAL;
                int err;
  
                err = netsec_xdp_queue_one(priv, xdpf, true);
-               if (err != NETSEC_XDP_TX) {
-                       xdp_return_frame_rx_napi(xdpf);
-                       drops++;
-               } else {
-                       tx_ring->xdp_xmit++;
-               }
+               if (err != NETSEC_XDP_TX)
+                       break;
+               tx_ring->xdp_xmit++;
+               nxmit++;
        }
        spin_unlock(&tx_ring->lock);
  
                tx_ring->xdp_xmit = 0;
        }
  
-       return n - drops;
+       return nxmit;
  }
  
  static int netsec_xdp_setup(struct netsec_priv *priv, struct bpf_prog *prog,
diff --combined drivers/net/veth.c
@@@ -302,7 -302,8 +302,7 @@@ static netdev_tx_t veth_xmit(struct sk_
        if (rxq < rcv->real_num_rx_queues) {
                rq = &rcv_priv->rq[rxq];
                rcv_xdp = rcu_access_pointer(rq->xdp_prog);
 -              if (rcv_xdp)
 -                      skb_record_rx_queue(skb, rxq);
 +              skb_record_rx_queue(skb, rxq);
        }
  
        skb_tx_timestamp(skb);
@@@ -433,7 -434,7 +433,7 @@@ static int veth_xdp_xmit(struct net_dev
                         u32 flags, bool ndo_xmit)
  {
        struct veth_priv *rcv_priv, *priv = netdev_priv(dev);
-       int i, ret = -ENXIO, drops = 0;
+       int i, ret = -ENXIO, nxmit = 0;
        struct net_device *rcv;
        unsigned int max_len;
        struct veth_rq *rq;
                void *ptr = veth_xdp_to_ptr(frame);
  
                if (unlikely(frame->len > max_len ||
-                            __ptr_ring_produce(&rq->xdp_ring, ptr))) {
-                       xdp_return_frame_rx_napi(frame);
-                       drops++;
-               }
+                            __ptr_ring_produce(&rq->xdp_ring, ptr)))
+                       break;
+               nxmit++;
        }
        spin_unlock(&rq->xdp_ring.producer_lock);
  
        if (flags & XDP_XMIT_FLUSH)
                __veth_xdp_flush(rq);
  
-       ret = n - drops;
+       ret = nxmit;
        if (ndo_xmit) {
                u64_stats_update_begin(&rq->stats.syncp);
-               rq->stats.vs.peer_tq_xdp_xmit += n - drops;
-               rq->stats.vs.peer_tq_xdp_xmit_err += drops;
+               rq->stats.vs.peer_tq_xdp_xmit += nxmit;
+               rq->stats.vs.peer_tq_xdp_xmit_err += n - nxmit;
                u64_stats_update_end(&rq->stats.syncp);
        }
  
@@@ -504,20 -504,23 +503,23 @@@ static int veth_ndo_xdp_xmit(struct net
  
  static void veth_xdp_flush_bq(struct veth_rq *rq, struct veth_xdp_tx_bq *bq)
  {
-       int sent, i, err = 0;
+       int sent, i, err = 0, drops;
  
        sent = veth_xdp_xmit(rq->dev, bq->count, bq->q, 0, false);
        if (sent < 0) {
                err = sent;
                sent = 0;
-               for (i = 0; i < bq->count; i++)
-                       xdp_return_frame(bq->q[i]);
        }
-       trace_xdp_bulk_tx(rq->dev, sent, bq->count - sent, err);
+       for (i = sent; unlikely(i < bq->count); i++)
+               xdp_return_frame(bq->q[i]);
+       drops = bq->count - sent;
+       trace_xdp_bulk_tx(rq->dev, sent, drops, err);
  
        u64_stats_update_begin(&rq->stats.syncp);
        rq->stats.vs.xdp_tx += sent;
-       rq->stats.vs.xdp_tx_err += bq->count - sent;
+       rq->stats.vs.xdp_tx_err += drops;
        u64_stats_update_end(&rq->stats.syncp);
  
        bq->count = 0;
diff --combined drivers/net/virtio_net.c
@@@ -195,9 -195,6 +195,9 @@@ struct virtnet_info 
        /* # of XDP queue pairs currently used by the driver */
        u16 xdp_queue_pairs;
  
 +      /* xdp_queue_pairs may be 0, when xdp is already loaded. So add this. */
 +      bool xdp_enabled;
 +
        /* I like... big packets and I cannot lie! */
        bool big_packets;
  
@@@ -484,41 -481,12 +484,41 @@@ static int __virtnet_xdp_xmit_one(struc
        return 0;
  }
  
 -static struct send_queue *virtnet_xdp_sq(struct virtnet_info *vi)
 -{
 -      unsigned int qp;
 -
 -      qp = vi->curr_queue_pairs - vi->xdp_queue_pairs + smp_processor_id();
 -      return &vi->sq[qp];
 +/* when vi->curr_queue_pairs > nr_cpu_ids, the txq/sq is only used for xdp tx on
 + * the current cpu, so it does not need to be locked.
 + *
 + * Here we use marco instead of inline functions because we have to deal with
 + * three issues at the same time: 1. the choice of sq. 2. judge and execute the
 + * lock/unlock of txq 3. make sparse happy. It is difficult for two inline
 + * functions to perfectly solve these three problems at the same time.
 + */
 +#define virtnet_xdp_get_sq(vi) ({                                       \
 +      struct netdev_queue *txq;                                       \
 +      typeof(vi) v = (vi);                                            \
 +      unsigned int qp;                                                \
 +                                                                      \
 +      if (v->curr_queue_pairs > nr_cpu_ids) {                         \
 +              qp = v->curr_queue_pairs - v->xdp_queue_pairs;          \
 +              qp += smp_processor_id();                               \
 +              txq = netdev_get_tx_queue(v->dev, qp);                  \
 +              __netif_tx_acquire(txq);                                \
 +      } else {                                                        \
 +              qp = smp_processor_id() % v->curr_queue_pairs;          \
 +              txq = netdev_get_tx_queue(v->dev, qp);                  \
 +              __netif_tx_lock(txq, raw_smp_processor_id());           \
 +      }                                                               \
 +      v->sq + qp;                                                     \
 +})
 +
 +#define virtnet_xdp_put_sq(vi, q) {                                     \
 +      struct netdev_queue *txq;                                       \
 +      typeof(vi) v = (vi);                                            \
 +                                                                      \
 +      txq = netdev_get_tx_queue(v->dev, (q) - v->sq);                 \
 +      if (v->curr_queue_pairs > nr_cpu_ids)                           \
 +              __netif_tx_release(txq);                                \
 +      else                                                            \
 +              __netif_tx_unlock(txq);                                 \
  }
  
  static int virtnet_xdp_xmit(struct net_device *dev,
        unsigned int len;
        int packets = 0;
        int bytes = 0;
-       int drops = 0;
+       int nxmit = 0;
        int kicks = 0;
-       int ret, err;
        void *ptr;
+       int ret;
        int i;
  
        /* Only allow ndo_xdp_xmit if XDP is loaded on dev, as this
        if (!xdp_prog)
                return -ENXIO;
  
 -      sq = virtnet_xdp_sq(vi);
 +      sq = virtnet_xdp_get_sq(vi);
  
        if (unlikely(flags & ~XDP_XMIT_FLAGS_MASK)) {
                ret = -EINVAL;
-               drops = n;
                goto out;
        }
  
        for (i = 0; i < n; i++) {
                struct xdp_frame *xdpf = frames[i];
  
-               err = __virtnet_xdp_xmit_one(vi, sq, xdpf);
-               if (err) {
-                       xdp_return_frame_rx_napi(xdpf);
-                       drops++;
-               }
+               if (__virtnet_xdp_xmit_one(vi, sq, xdpf))
+                       break;
+               nxmit++;
        }
-       ret = n - drops;
+       ret = nxmit;
  
        if (flags & XDP_XMIT_FLUSH) {
                if (virtqueue_kick_prepare(sq->vq) && virtqueue_notify(sq->vq))
@@@ -588,17 -553,16 +585,17 @@@ out
        sq->stats.bytes += bytes;
        sq->stats.packets += packets;
        sq->stats.xdp_tx += n;
-       sq->stats.xdp_tx_drops += drops;
+       sq->stats.xdp_tx_drops += n - nxmit;
        sq->stats.kicks += kicks;
        u64_stats_update_end(&sq->stats.syncp);
  
 +      virtnet_xdp_put_sq(vi, sq);
        return ret;
  }
  
  static unsigned int virtnet_get_headroom(struct virtnet_info *vi)
  {
 -      return vi->xdp_queue_pairs ? VIRTIO_XDP_HEADROOM : 0;
 +      return vi->xdp_enabled ? VIRTIO_XDP_HEADROOM : 0;
  }
  
  /* We copy the packet for XDP in the following cases:
@@@ -742,7 -706,9 +739,9 @@@ static struct sk_buff *receive_small(st
                        if (unlikely(!xdpf))
                                goto err_xdp;
                        err = virtnet_xdp_xmit(dev, 1, &xdpf, 0);
-                       if (unlikely(err < 0)) {
+                       if (unlikely(!err)) {
+                               xdp_return_frame_rx_napi(xdpf);
+                       } else if (unlikely(err < 0)) {
                                trace_xdp_exception(vi->dev, xdp_prog, act);
                                goto err_xdp;
                        }
@@@ -929,7 -895,9 +928,9 @@@ static struct sk_buff *receive_mergeabl
                        if (unlikely(!xdpf))
                                goto err_xdp;
                        err = virtnet_xdp_xmit(dev, 1, &xdpf, 0);
-                       if (unlikely(err < 0)) {
+                       if (unlikely(!err)) {
+                               xdp_return_frame_rx_napi(xdpf);
+                       } else if (unlikely(err < 0)) {
                                trace_xdp_exception(vi->dev, xdp_prog, act);
                                if (unlikely(xdp_page != page))
                                        put_page(xdp_page);
@@@ -1491,13 -1459,12 +1492,13 @@@ static int virtnet_poll(struct napi_str
                xdp_do_flush();
  
        if (xdp_xmit & VIRTIO_XDP_TX) {
 -              sq = virtnet_xdp_sq(vi);
 +              sq = virtnet_xdp_get_sq(vi);
                if (virtqueue_kick_prepare(sq->vq) && virtqueue_notify(sq->vq)) {
                        u64_stats_update_begin(&sq->stats.syncp);
                        sq->stats.kicks++;
                        u64_stats_update_end(&sq->stats.syncp);
                }
 +              virtnet_xdp_put_sq(vi, sq);
        }
  
        return received;
@@@ -2015,7 -1982,7 +2016,7 @@@ static void virtnet_set_affinity(struc
                }
                virtqueue_set_affinity(vi->rq[i].vq, mask);
                virtqueue_set_affinity(vi->sq[i].vq, mask);
 -              __netif_set_xps_queue(vi->dev, cpumask_bits(mask), i, false);
 +              __netif_set_xps_queue(vi->dev, cpumask_bits(mask), i, XPS_CPUS);
                cpumask_clear(mask);
        }
  
@@@ -2138,21 -2105,25 +2139,21 @@@ static int virtnet_set_channels(struct 
  static void virtnet_get_strings(struct net_device *dev, u32 stringset, u8 *data)
  {
        struct virtnet_info *vi = netdev_priv(dev);
 -      char *p = (char *)data;
        unsigned int i, j;
 +      u8 *p = data;
  
        switch (stringset) {
        case ETH_SS_STATS:
                for (i = 0; i < vi->curr_queue_pairs; i++) {
 -                      for (j = 0; j < VIRTNET_RQ_STATS_LEN; j++) {
 -                              snprintf(p, ETH_GSTRING_LEN, "rx_queue_%u_%s",
 -                                       i, virtnet_rq_stats_desc[j].desc);
 -                              p += ETH_GSTRING_LEN;
 -                      }
 +                      for (j = 0; j < VIRTNET_RQ_STATS_LEN; j++)
 +                              ethtool_sprintf(&p, "rx_queue_%u_%s", i,
 +                                              virtnet_rq_stats_desc[j].desc);
                }
  
                for (i = 0; i < vi->curr_queue_pairs; i++) {
 -                      for (j = 0; j < VIRTNET_SQ_STATS_LEN; j++) {
 -                              snprintf(p, ETH_GSTRING_LEN, "tx_queue_%u_%s",
 -                                       i, virtnet_sq_stats_desc[j].desc);
 -                              p += ETH_GSTRING_LEN;
 -                      }
 +                      for (j = 0; j < VIRTNET_SQ_STATS_LEN; j++)
 +                              ethtool_sprintf(&p, "tx_queue_%u_%s", i,
 +                                              virtnet_sq_stats_desc[j].desc);
                }
                break;
        }
@@@ -2448,9 -2419,10 +2449,9 @@@ static int virtnet_xdp_set(struct net_d
  
        /* XDP requires extra queues for XDP_TX */
        if (curr_qp + xdp_qp > vi->max_queue_pairs) {
 -              NL_SET_ERR_MSG_MOD(extack, "Too few free TX rings available");
 -              netdev_warn(dev, "request %i queues but max is %i\n",
 +              netdev_warn(dev, "XDP request %i queues but max is %i. XDP_TX and XDP_REDIRECT will operate in a slower locked tx mode.\n",
                            curr_qp + xdp_qp, vi->max_queue_pairs);
 -              return -ENOMEM;
 +              xdp_qp = 0;
        }
  
        old_prog = rtnl_dereference(vi->rq[0].xdp_prog);
        vi->xdp_queue_pairs = xdp_qp;
  
        if (prog) {
 +              vi->xdp_enabled = true;
                for (i = 0; i < vi->max_queue_pairs; i++) {
                        rcu_assign_pointer(vi->rq[i].xdp_prog, prog);
                        if (i == 0 && !old_prog)
                                virtnet_clear_guest_offloads(vi);
                }
 +      } else {
 +              vi->xdp_enabled = false;
        }
  
        for (i = 0; i < vi->max_queue_pairs; i++) {
@@@ -2559,7 -2528,7 +2560,7 @@@ static int virtnet_set_features(struct 
        int err;
  
        if ((dev->features ^ features) & NETIF_F_LRO) {
 -              if (vi->xdp_queue_pairs)
 +              if (vi->xdp_enabled)
                        return -EBUSY;
  
                if (features & NETIF_F_LRO)
diff --combined kernel/bpf/verifier.c
@@@ -6045,14 -6045,10 +6045,14 @@@ static int retrieve_ptr_limit(const str
  {
        bool mask_to_left = (opcode == BPF_ADD &&  off_is_neg) ||
                            (opcode == BPF_SUB && !off_is_neg);
 -      u32 off;
 +      u32 off, max;
  
        switch (ptr_reg->type) {
        case PTR_TO_STACK:
 +              /* Offset 0 is out-of-bounds, but acceptable start for the
 +               * left direction, see BPF_REG_FP.
 +               */
 +              max = MAX_BPF_STACK + mask_to_left;
                /* Indirect variable offset stack access is prohibited in
                 * unprivileged mode so it's not handled here.
                 */
                if (mask_to_left)
                        *ptr_limit = MAX_BPF_STACK + off;
                else
 -                      *ptr_limit = -off;
 -              return 0;
 +                      *ptr_limit = -off - 1;
 +              return *ptr_limit >= max ? -ERANGE : 0;
        case PTR_TO_MAP_KEY:
                /* Currently, this code is not exercised as the only use
                 * is bpf_for_each_map_elem() helper which requires
                }
                return 0;
        case PTR_TO_MAP_VALUE:
 +              max = ptr_reg->map_ptr->value_size;
                if (mask_to_left) {
                        *ptr_limit = ptr_reg->umax_value + ptr_reg->off;
                } else {
                        off = ptr_reg->smin_value + ptr_reg->off;
 -                      *ptr_limit = ptr_reg->map_ptr->value_size - off;
 +                      *ptr_limit = ptr_reg->map_ptr->value_size - off - 1;
                }
 -              return 0;
 +              return *ptr_limit >= max ? -ERANGE : 0;
        default:
                return -EINVAL;
        }
@@@ -6136,7 -6131,6 +6136,7 @@@ static int sanitize_ptr_alu(struct bpf_
        u32 alu_state, alu_limit;
        struct bpf_reg_state tmp;
        bool ret;
 +      int err;
  
        if (can_skip_alu_sanitation(env, insn))
                return 0;
        alu_state |= ptr_is_dst_reg ?
                     BPF_ALU_SANITIZE_SRC : BPF_ALU_SANITIZE_DST;
  
 -      if (retrieve_ptr_limit(ptr_reg, &alu_limit, opcode, off_is_neg))
 -              return 0;
 -      if (update_alu_sanitation_state(aux, alu_state, alu_limit))
 -              return -EACCES;
 +      err = retrieve_ptr_limit(ptr_reg, &alu_limit, opcode, off_is_neg);
 +      if (err < 0)
 +              return err;
 +
 +      err = update_alu_sanitation_state(aux, alu_state, alu_limit);
 +      if (err < 0)
 +              return err;
  do_sim:
        /* Simulate and find potential out-of-bounds access under
         * speculative execution from truncation as a result of
@@@ -6310,7 -6301,7 +6310,7 @@@ static int adjust_ptr_min_max_vals(stru
        case BPF_ADD:
                ret = sanitize_ptr_alu(env, insn, ptr_reg, dst_reg, smin_val < 0);
                if (ret < 0) {
 -                      verbose(env, "R%d tried to add from different maps or paths\n", dst);
 +                      verbose(env, "R%d tried to add from different maps, paths, or prohibited types\n", dst);
                        return ret;
                }
                /* We can take a fixed offset as long as it doesn't overflow
        case BPF_SUB:
                ret = sanitize_ptr_alu(env, insn, ptr_reg, dst_reg, smin_val < 0);
                if (ret < 0) {
 -                      verbose(env, "R%d tried to sub from different maps or paths\n", dst);
 +                      verbose(env, "R%d tried to sub from different maps, paths, or prohibited types\n", dst);
                        return ret;
                }
                if (dst_reg == off_reg) {
@@@ -9285,10 -9276,6 +9285,10 @@@ static int check_btf_info(struct bpf_ve
        btf = btf_get_by_fd(attr->prog_btf_fd);
        if (IS_ERR(btf))
                return PTR_ERR(btf);
 +      if (btf_is_kernel(btf)) {
 +              btf_put(btf);
 +              return -EACCES;
 +      }
        env->prog->aux->btf = btf;
  
        err = check_btf_func(env, attr, uattr);
@@@ -11912,7 -11899,6 +11912,6 @@@ static int do_misc_fixups(struct bpf_ve
                    insn->code == (BPF_ALU64 | BPF_SUB | BPF_X)) {
                        const u8 code_add = BPF_ALU64 | BPF_ADD | BPF_X;
                        const u8 code_sub = BPF_ALU64 | BPF_SUB | BPF_X;
-                       struct bpf_insn insn_buf[16];
                        struct bpf_insn *patch = &insn_buf[0];
                        bool issrc, isneg;
                        u32 off_reg;
                        off_reg = issrc ? insn->src_reg : insn->dst_reg;
                        if (isneg)
                                *patch++ = BPF_ALU64_IMM(BPF_MUL, off_reg, -1);
 -                      *patch++ = BPF_MOV32_IMM(BPF_REG_AX, aux->alu_limit - 1);
 +                      *patch++ = BPF_MOV32_IMM(BPF_REG_AX, aux->alu_limit);
                        *patch++ = BPF_ALU64_REG(BPF_SUB, BPF_REG_AX, off_reg);
                        *patch++ = BPF_ALU64_REG(BPF_OR, BPF_REG_AX, off_reg);
                        *patch++ = BPF_ALU64_IMM(BPF_NEG, BPF_REG_AX, 0);
diff --combined net/core/filter.c
@@@ -4729,6 -4729,9 +4729,9 @@@ static int _bpf_setsockopt(struct sock 
                                sk->sk_prot->keepalive(sk, valbool);
                        sock_valbool_flag(sk, SOCK_KEEPOPEN, valbool);
                        break;
+               case SO_REUSEPORT:
+                       sk->sk_reuseport = valbool;
+                       break;
                default:
                        ret = -EINVAL;
                }
@@@ -4898,6 -4901,9 +4901,9 @@@ static int _bpf_getsockopt(struct sock 
                case SO_BINDTOIFINDEX:
                        *((int *)optval) = sk->sk_bound_dev_if;
                        break;
+               case SO_REUSEPORT:
+                       *((int *)optval) = sk->sk_reuseport;
+                       break;
                default:
                        goto err_clear;
                }
@@@ -5600,7 -5606,7 +5606,7 @@@ BPF_CALL_5(bpf_skb_check_mtu, struct sk
        if (unlikely(flags & ~(BPF_MTU_CHK_SEGS)))
                return -EINVAL;
  
 -      if (unlikely(flags & BPF_MTU_CHK_SEGS && len_diff))
 +      if (unlikely(flags & BPF_MTU_CHK_SEGS && (len_diff || *mtu_len)))
                return -EINVAL;
  
        dev = __dev_via_ifindex(dev, ifindex);
        mtu = READ_ONCE(dev->mtu);
  
        dev_len = mtu + dev->hard_header_len;
 -      skb_len = skb->len + len_diff; /* minus result pass check */
 +
 +      /* If set use *mtu_len as input, L3 as iph->tot_len (like fib_lookup) */
 +      skb_len = *mtu_len ? *mtu_len + dev->hard_header_len : skb->len;
 +
 +      skb_len += len_diff; /* minus result pass check */
        if (skb_len <= dev_len) {
                ret = BPF_MTU_CHK_RET_SUCCESS;
                goto out;
@@@ -5659,10 -5661,6 +5665,10 @@@ BPF_CALL_5(bpf_xdp_check_mtu, struct xd
        /* Add L2-header as dev MTU is L3 size */
        dev_len = mtu + dev->hard_header_len;
  
 +      /* Use *mtu_len as input, L3 as iph->tot_len (like fib_lookup) */
 +      if (*mtu_len)
 +              xdp_len = *mtu_len + dev->hard_header_len;
 +
        xdp_len += len_diff; /* minus result pass check */
        if (xdp_len > dev_len)
                ret = BPF_MTU_CHK_RET_FRAG_NEEDED;
diff --combined tools/lib/bpf/Makefile
@@@ -215,7 -215,7 +215,7 @@@ define do_instal
        if [ ! -d '$(DESTDIR_SQ)$2' ]; then             \
                $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
        fi;                                             \
 -      $(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
 +      $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2'
  endef
  
  install_lib: all_cmd
@@@ -228,7 -228,6 +228,6 @@@ install_headers: $(BPF_HELPER_DEFS
                $(call do_install,bpf.h,$(prefix)/include/bpf,644); \
                $(call do_install,libbpf.h,$(prefix)/include/bpf,644); \
                $(call do_install,btf.h,$(prefix)/include/bpf,644); \
-               $(call do_install,libbpf_util.h,$(prefix)/include/bpf,644); \
                $(call do_install,libbpf_common.h,$(prefix)/include/bpf,644); \
                $(call do_install,xsk.h,$(prefix)/include/bpf,644); \
                $(call do_install,bpf_helpers.h,$(prefix)/include/bpf,644); \
diff --combined tools/lib/bpf/btf_dump.c
@@@ -166,11 -166,11 +166,11 @@@ static int btf_dump_resize(struct btf_d
        if (last_id <= d->last_id)
                return 0;
  
-       if (btf_ensure_mem((void **)&d->type_states, &d->type_states_cap,
-                          sizeof(*d->type_states), last_id + 1))
+       if (libbpf_ensure_mem((void **)&d->type_states, &d->type_states_cap,
+                             sizeof(*d->type_states), last_id + 1))
                return -ENOMEM;
-       if (btf_ensure_mem((void **)&d->cached_names, &d->cached_names_cap,
-                          sizeof(*d->cached_names), last_id + 1))
+       if (libbpf_ensure_mem((void **)&d->cached_names, &d->cached_names_cap,
+                             sizeof(*d->cached_names), last_id + 1))
                return -ENOMEM;
  
        if (d->last_id == 0) {
@@@ -464,7 -464,7 +464,7 @@@ static int btf_dump_order_type(struct b
                return err;
  
        case BTF_KIND_ARRAY:
 -              return btf_dump_order_type(d, btf_array(t)->type, through_ptr);
 +              return btf_dump_order_type(d, btf_array(t)->type, false);
  
        case BTF_KIND_STRUCT:
        case BTF_KIND_UNION: {
diff --combined tools/lib/bpf/libbpf.c
  #include "libbpf_internal.h"
  #include "hashmap.h"
  
- #ifndef EM_BPF
- #define EM_BPF 247
- #endif
  #ifndef BPF_FS_MAGIC
  #define BPF_FS_MAGIC          0xcafe4a11
  #endif
@@@ -1134,11 -1130,6 +1130,6 @@@ static void bpf_object__elf_finish(stru
        obj->efile.obj_buf_sz = 0;
  }
  
- /* if libelf is old and doesn't support mmap(), fall back to read() */
- #ifndef ELF_C_READ_MMAP
- #define ELF_C_READ_MMAP ELF_C_READ
- #endif
  static int bpf_object__elf_init(struct bpf_object *obj)
  {
        int err = 0;
        if (!elf_rawdata(elf_getscn(obj->efile.elf, obj->efile.shstrndx), NULL)) {
                pr_warn("elf: failed to get section names strings from %s: %s\n",
                        obj->path, elf_errmsg(-1));
 -              return -LIBBPF_ERRNO__FORMAT;
 +              err = -LIBBPF_ERRNO__FORMAT;
 +              goto errout;
        }
  
        /* Old LLVM set e_machine to EM_NONE */
@@@ -2808,7 -2798,7 +2799,7 @@@ static bool ignore_elf_section(GElf_Shd
                return true;
  
        /* ignore .llvm_addrsig section as well */
-       if (hdr->sh_type == 0x6FFF4C03 /* SHT_LLVM_ADDRSIG */)
+       if (hdr->sh_type == SHT_LLVM_ADDRSIG)
                return true;
  
        /* no subprograms will lead to an empty .text section, ignore it */
@@@ -4868,8 -4858,8 +4859,8 @@@ static int load_module_btfs(struct bpf_
                        goto err_out;
                }
  
-               err = btf_ensure_mem((void **)&obj->btf_modules, &obj->btf_module_cap,
-                                    sizeof(*obj->btf_modules), obj->btf_module_cnt + 1);
+               err = libbpf_ensure_mem((void **)&obj->btf_modules, &obj->btf_module_cap,
+                                       sizeof(*obj->btf_modules), obj->btf_module_cnt + 1);
                if (err)
                        goto err_out;