| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/12/01 04:23 | flow | patch-triage |
2mArgs:null Results: {
"EnableConfigs": [
"NET",
"BPF_SYSCALL",
"XDP_SOCKETS",
"VETH",
"DEBUG_INFO_BTF"
],
"FocusSymbols": [
"xdp_buff_shrink_tail",
"xdp_buff_shrink_data",
"bpf_xdp_adjust_tail",
"bpf_xdp_pull_data"
],
"KMSANReasoning": "The patch series makes two main sets of changes:\n1. Refactors `bpf_xdp_frags_shrink_tail` and `bpf_xdp_shrink_data` from `net/core/filter.c` into `xdp_buff_shrink_tail` and `xdp_buff_shrink_data` in `net/core/xdp.c` (preserving the exact shrink bounds checks and logic, without adding any tail-growth paths or uninitialized reads).\n2. Updates the `stmmac` Ethernet driver (`drivers/net/ethernet/stmicro/stmmac/`) to build RX packets via `struct xdp_buff` (`ctx.xdp`, `xdp_init_buff`, `xdp_prepare_buff`, `xdp_buff_add_frag`, `xdp_buff_shrink_tail`, `xdp_build_skb_from_buff`, `__xdp_return_buff`), adjusts VLAN RX offload feature detection (`stmmac_rx_8021q_offload`, `stmmac_rx_8021ad_offload`, `stmmac_has_ip_ethertype`), and adds `phylink_rx_clk_stop_block/unblock` in `stmmac_selftest_run`.\n\nAnalysis of KMSAN vs KASAN applicability:\n- No kernel structures are newly allocated or copied to user space (`copy_to_user`, `put_user`, netlink attributes, ioctl outputs, or BPF buffers) with potential uninitialized fields or struct padding leaks.\n- All stack and state variables introduced or modified (such as `ctx.priv`, `n_descs`, `res` in `stmmac_xdp_run_prog`, `depth` in `stmmac_has_ip_ethertype`, and `xdp_buff` fields initialized via `xdp_init_buff`/`xdp_prepare_buff` when `n_descs == 0`) are properly initialized before being read or branched on. (Even if `rx_q-\u003estate.xdp = ctx.xdp` executes when `in_progress` is true with `n_descs == 0` and `error == 1`, `rx_q-\u003estate.xdp` is never read when `n_descs == 0`.)\n- `xdp_buff_shrink_tail` only shrinks `data_end` or fragment sizes after bounds checks (`ETH_HLEN`), and `rx_q-\u003enapi_skb_frag_size` is updated to `PAGE_SIZE \u003c\u003c pp_params.order` to match the allocated page pool order rather than exposing uninitialized buffer bytes.\n- Potential bugs in RX descriptor/fragment handling, bounds checks, or reference counting (such as out-of-bounds accesses, use-after-free, or page pool refcount issues) are memory corruption / lifetime errors caught by KASAN and standard debug checks rather than uninitialized memory bugs requiring KMSAN.",
"NeedsKMSAN": false,
"Reasoning": "While the stmmac driver changes target hardware not emulated in standard QEMU, the patch series also modifies core networking and BPF/XDP code in net/core/xdp.c and net/core/filter.c. Specifically, bpf_xdp_adjust_tail now routes all negative-offset calls (for both linear and non-linear xdp_buff) to the new xdp_buff_shrink_tail helper, and bpf_xdp_pull_data and xdp_frags_shrink_tail use the refactored xdp_buff_shrink_data / xdp_buff_shrink_data_zc helpers. These paths are directly reachable in virtualized environments via BPF_PROG_TEST_RUN (BPF_PROG_TYPE_XDP), veth with XDP attached, and AF_XDP sockets.",
"WorthFuzzing": true
} |
| 1/1 | 2026/12/01 04:23 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit b454ef3570e631c9e43d22ec78887bcf930b8b07\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Tue Dec 1 04:23:16 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h\nindex fcc395321816fd..d77e442249abbf 100644\n--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h\n+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h\n@@ -133,7 +133,8 @@ struct stmmac_rx_queue {\n \tdma_addr_t dma_rx_phy;\n \tunsigned int state_saved;\n \tstruct {\n-\t\tstruct sk_buff *skb;\n+\t\tstruct xdp_buff xdp;\n+\t\tunsigned int n_descs;\n \t\tunsigned int len;\n \t\tunsigned int error;\n \t} state;\n@@ -478,4 +479,16 @@ static inline int stmmac_selftest_get_count(struct stmmac_priv *priv)\n }\n #endif /* CONFIG_STMMAC_SELFTESTS */\n \n+static inline bool stmmac_rx_8021q_offload(struct stmmac_priv *priv)\n+{\n+\treturn priv-\u003ehw-\u003evlan \u0026\u0026 priv-\u003ehw-\u003evlan-\u003eset_hw_vlan_mode \u0026\u0026\n+\t priv-\u003ehw-\u003evlan-\u003erx_hw_vlan;\n+}\n+\n+static inline bool stmmac_rx_8021ad_offload(struct stmmac_priv *priv)\n+{\n+\treturn stmmac_rx_8021q_offload(priv) \u0026\u0026\n+\t priv-\u003ehw-\u003edesc-\u003eget_rx_vlan_proto;\n+}\n+\n #endif /* __STMMAC_H__ */\ndiff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c\nindex ca4c7fb11b73fe..56355d80ba161c 100644\n--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c\n+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c\n@@ -2195,8 +2195,10 @@ static void __free_dma_rx_desc_resources(struct stmmac_priv *priv,\n \telse\n \t\tdma_free_rx_skbufs(priv, dma_conf, queue);\n \n-\tdev_kfree_skb_any(rx_q-\u003estate.skb);\n-\trx_q-\u003estate.skb = NULL;\n+\tif (rx_q-\u003estate.n_descs \u0026\u0026 !rx_q-\u003exsk_pool) {\n+\t\t__xdp_return_buff(\u0026rx_q-\u003estate.xdp, false);\n+\t\trx_q-\u003estate.n_descs = 0;\n+\t}\n \trx_q-\u003estate_saved = false;\n \trx_q-\u003ebuf_alloc_num = 0;\n \trx_q-\u003exsk_pool = NULL;\n@@ -2316,10 +2318,6 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,\n \t\t\t SKB_DATA_ALIGN(sizeof(struct skb_shared_info));\n \tnum_pages = DIV_ROUND_UP(dma_buf_sz_pad, PAGE_SIZE);\n \n-\trx_q-\u003equeue_index = queue;\n-\trx_q-\u003epriv_data = priv;\n-\trx_q-\u003enapi_skb_frag_size = num_pages * PAGE_SIZE;\n-\n \tpp_params.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV;\n \tpp_params.pool_size = dma_conf-\u003edma_rx_size;\n \tpp_params.order = order_base_2(num_pages);\n@@ -2351,6 +2349,10 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,\n \t\tgoto err_free_buf_pool;\n \t}\n \n+\trx_q-\u003equeue_index = queue;\n+\trx_q-\u003epriv_data = priv;\n+\trx_q-\u003enapi_skb_frag_size = PAGE_SIZE \u003c\u003c pp_params.order;\n+\n \tif (priv-\u003eextend_desc)\n \t\trx_q-\u003edma_erx = addr;\n \telse\n@@ -2362,7 +2364,8 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,\n \telse\n \t\tnapi_id = ch-\u003erx_napi.napi_id;\n \n-\tret = xdp_rxq_info_reg(\u0026rx_q-\u003exdp_rxq, priv-\u003edev, queue, napi_id);\n+\tret = __xdp_rxq_info_reg(\u0026rx_q-\u003exdp_rxq, priv-\u003edev, queue, napi_id,\n+\t\t\t\t rx_q-\u003enapi_skb_frag_size);\n \tif (ret) {\n \t\tnetdev_err(priv-\u003edev, \"Failed to register xdp rxq info\\n\");\n \t\tgoto err_free_dma;\n@@ -4879,7 +4882,9 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)\n \n /**\n * stmmac_has_ip_ethertype() - Check if packet has IP ethertype\n+ * @priv: driver private structure\n * @skb: socket buffer to check\n+ * @xmit: transmit path\n *\n * Check if a packet has an ethertype that will trigger the IP header checks\n * and IP/TCP checksum engine of the stmmac core.\n@@ -4887,16 +4892,25 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)\n * Return: true if the ethertype can trigger the checksum engine, false\n * otherwise\n */\n-static bool stmmac_has_ip_ethertype(struct sk_buff *skb)\n+static bool stmmac_has_ip_ethertype(struct stmmac_priv *priv,\n+\t\t\t\t struct sk_buff *skb, bool xmit)\n {\n-\tint depth = 0;\n-\t__be16 proto;\n+\t__be16 proto, h_proto = eth_header_parse_protocol(skb);\n+\tint max_l2_hlen, depth = 0;\n+\n+\t/* An S-tag still in the payload may not have been parsed by the\n+\t * checksum engine; only trust it when the hardware stripped it, in\n+\t * which case h_proto is no longer ETH_P_8021AD.\n+\t */\n+\tif (h_proto == htons(ETH_P_8021AD))\n+\t\treturn false;\n \n-\tproto = __vlan_get_protocol(skb, eth_header_parse_protocol(skb),\n-\t\t\t\t \u0026depth);\n+\tproto = vlan_get_protocol_offset_inline(skb, h_proto,\n+\t\t\t\t\t\tskb_mac_offset(skb), \u0026depth);\n \n-\treturn (depth \u003c= ETH_HLEN) \u0026\u0026\n-\t\t(proto == htons(ETH_P_IP) || proto == htons(ETH_P_IPV6));\n+\tmax_l2_hlen = xmit || priv-\u003ehw-\u003ehw_vlan_en ? ETH_HLEN : VLAN_ETH_HLEN;\n+\treturn depth \u003c= max_l2_hlen \u0026\u0026\n+\t (proto == htons(ETH_P_IP) || proto == htons(ETH_P_IPV6));\n }\n \n /**\n@@ -5153,7 +5167,7 @@ static netdev_features_t stmmac_features_check(struct sk_buff *skb,\n \t * harmonize_features() in net/core/dev.c\n \t */\n \tif (priv-\u003eplat-\u003etx_queues_cfg[queue].coe_unsupported ||\n-\t !stmmac_has_ip_ethertype(skb))\n+\t !stmmac_has_ip_ethertype(priv, skb, true))\n \t\tfeatures \u0026= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);\n \n \tif (skb_is_gso(skb)) {\n@@ -5175,37 +5189,6 @@ static netdev_features_t stmmac_features_check(struct sk_buff *skb,\n \treturn vlan_features_check(skb, features);\n }\n \n-static int stmmac_rx_vlan(struct net_device *dev, struct sk_buff *skb)\n-{\n-\tstruct vlan_ethhdr *veth;\n-\n-\tif (!pskb_may_pull(skb, ETH_HLEN))\n-\t\treturn -EINVAL;\n-\n-\tveth = skb_vlan_eth_hdr(skb);\n-\tif ((veth-\u003eh_vlan_proto == htons(ETH_P_8021Q) \u0026\u0026\n-\t dev-\u003efeatures \u0026 NETIF_F_HW_VLAN_CTAG_RX) ||\n-\t (veth-\u003eh_vlan_proto == htons(ETH_P_8021AD) \u0026\u0026\n-\t dev-\u003efeatures \u0026 NETIF_F_HW_VLAN_STAG_RX)) {\n-\t\t__be16 vlan_proto = veth-\u003eh_vlan_proto;\n-\t\tu8 meta_len = skb_metadata_len(skb);\n-\t\tu16 vlanid;\n-\n-\t\t/* pop the vlan tag */\n-\t\tif (!pskb_may_pull(skb, VLAN_ETH_HLEN))\n-\t\t\treturn -EINVAL;\n-\n-\t\tveth = skb_vlan_eth_hdr(skb);\n-\t\tvlanid = ntohs(veth-\u003eh_vlan_TCI);\n-\t\tmemmove(skb-\u003edata - meta_len + VLAN_HLEN,\n-\t\t\tskb-\u003edata - meta_len, meta_len + ETH_ALEN * 2);\n-\t\tskb_pull(skb, VLAN_HLEN);\n-\t\t__vlan_hwaccel_put_tag(skb, vlan_proto, vlanid);\n-\t}\n-\n-\treturn 0;\n-}\n-\n static bool stmmac_rx_need_ic(struct stmmac_priv *priv,\n \t\t\t struct stmmac_rx_queue *rx_q, u32 queue)\n {\n@@ -5554,8 +5537,8 @@ static int __stmmac_xdp_run_prog(struct stmmac_priv *priv,\n static struct sk_buff *stmmac_xdp_run_prog(struct stmmac_priv *priv,\n \t\t\t\t\t struct xdp_buff *xdp)\n {\n+\tint res = STMMAC_XDP_CONSUMED;\n \tstruct bpf_prog *prog;\n-\tint res;\n \n \tprog = READ_ONCE(priv-\u003exdp_prog);\n \tif (!prog) {\n@@ -5563,7 +5546,8 @@ static struct sk_buff *stmmac_xdp_run_prog(struct stmmac_priv *priv,\n \t\tgoto out;\n \t}\n \n-\tres = __stmmac_xdp_run_prog(priv, prog, xdp);\n+\tif (likely(!xdp_buff_has_frags(xdp) || prog-\u003eaux-\u003exdp_has_frags))\n+\t\tres = __stmmac_xdp_run_prog(priv, prog, xdp);\n out:\n \treturn ERR_PTR(-res);\n }\n@@ -5626,15 +5610,11 @@ static void stmmac_dispatch_skb_zc(struct stmmac_priv *priv, u32 queue,\n \tif (priv-\u003ehw-\u003ehw_vlan_en) {\n \t\t/* MAC level stripping. */\n \t\tstmmac_rx_hw_vlan(priv, priv-\u003ehw, p, skb);\n-\t} else if (stmmac_rx_vlan(priv-\u003edev, skb)) {\n-\t\tdev_kfree_skb_any(skb);\n-\t\tpriv-\u003exstats.rx_dropped++;\n-\t\treturn;\n \t}\n \n \tskb-\u003eprotocol = eth_type_trans(skb, priv-\u003edev);\n \n-\tif (unlikely(!coe) || !stmmac_has_ip_ethertype(skb) ||\n+\tif (unlikely(!coe) || !stmmac_has_ip_ethertype(priv, skb, false) ||\n \t (status \u0026 csum_none))\n \t\tskb_checksum_none_assert(skb);\n \telse\n@@ -5897,6 +5877,25 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)\n \treturn failure ? limit : (int)count;\n }\n \n+static bool stmmac_build_xdp_frags(struct stmmac_priv *priv,\n+\t\t\t\t struct stmmac_rx_queue *rx_q,\n+\t\t\t\t unsigned int len, struct page *page,\n+\t\t\t\t unsigned int offset,\n+\t\t\t\t enum dma_data_direction dma_dir,\n+\t\t\t\t struct xdp_buff *xdp)\n+{\n+\tdma_addr_t dma_addr = page_pool_get_dma_addr(page) + offset;\n+\n+\tdma_sync_single_for_cpu(priv-\u003edevice, dma_addr, len, dma_dir);\n+\tif (!xdp_buff_add_frag(xdp, page_to_netmem(page), offset, len,\n+\t\t\t xdp-\u003eframe_sz)) {\n+\t\tpage_pool_put_full_page(rx_q-\u003epage_pool, page, true);\n+\t\treturn false;\n+\t}\n+\n+\treturn true;\n+}\n+\n /**\n * stmmac_rx - manage the receive process\n * @priv: driver private structure\n@@ -5910,21 +5909,20 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)\n \tu32 rx_errors = 0, rx_dropped = 0, rx_bytes = 0, rx_packets = 0;\n \tstruct stmmac_rxq_stats *rxq_stats = \u0026priv-\u003exstats.rxq_stats[queue];\n \tstruct stmmac_rx_queue *rx_q = \u0026priv-\u003edma_conf.rx_queue[queue];\n+\tunsigned int n_descs = 0, next_entry = rx_q-\u003ecur_rx;\n \tstruct stmmac_channel *ch = \u0026priv-\u003echannel[queue];\n \tunsigned int count = 0, error = 0, len = 0;\n-\tunsigned int next_entry = rx_q-\u003ecur_rx;\n \tbool in_progress = rx_q-\u003estate_saved;\n \tenum dma_data_direction dma_dir;\n \tint coe = priv-\u003ehw-\u003erx_csum;\n-\tunsigned int desc_size;\n-\tstruct sk_buff *skb = NULL;\n \tstruct stmmac_xdp_buff ctx;\n-\tbool fcs_stripped = false;\n+\tunsigned int desc_size;\n \tint xdp_status = 0;\n \tint bufsz;\n \n \tdma_dir = page_pool_get_dma_dir(rx_q-\u003epage_pool);\n-\tbufsz = DIV_ROUND_UP(priv-\u003edma_conf.dma_buf_sz, PAGE_SIZE) * PAGE_SIZE;\n+\tbufsz = rx_q-\u003enapi_skb_frag_size;\n+\tctx.priv = priv;\n \n \tif (netif_msg_rx_status(priv)) {\n \t\tvoid *rx_head = stmmac_get_rx_desc(priv, rx_q, 0);\n@@ -5937,11 +5935,12 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)\n \t}\n \n \tif (rx_q-\u003estate_saved) {\n-\t\tskb = rx_q-\u003estate.skb;\n+\t\tctx.xdp = rx_q-\u003estate.xdp;\n \t\terror = rx_q-\u003estate.error;\n+\t\tn_descs = rx_q-\u003estate.n_descs;\n \t\tlen = rx_q-\u003estate.len;\n-\t\trx_q-\u003estate.skb = NULL;\n \t\trx_q-\u003estate_saved = false;\n+\t\trx_q-\u003estate.n_descs = 0;\n \t}\n \n \twhile (count \u003c limit) {\n@@ -5949,11 +5948,11 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)\n \t\tenum pkt_hash_types hash_type;\n \t\tstruct stmmac_rx_buffer *buf;\n \t\tstruct dma_desc *np, *p;\n+\t\tstruct sk_buff *skb;\n \t\tint entry, status;\n \t\tu32 hash;\n \n \t\tif (!in_progress) {\n-\t\t\tskb = NULL;\n \t\t\terror = 0;\n \t\t\tlen = 0;\n \t\t}\n@@ -6001,19 +6000,11 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)\n \t\t\t\trx_errors++;\n \t\t}\n \n-\t\t/* We do not support SG in XDP mode */\n-\t\tif (unlikely(!error \u0026\u0026 (status \u0026 rx_not_ls) \u0026\u0026\n-\t\t\t stmmac_xdp_is_enabled(priv))) {\n-\t\t\trx_dropped++;\n-\t\t\terror = 1;\n-\t\t}\n-\n \t\tif (unlikely(error)) {\n \t\t\tif (status \u0026 rx_not_ls)\n \t\t\t\tgoto read_again;\n \n-\t\t\tdev_kfree_skb(skb);\n-\t\t\tgoto next;\n+\t\t\tgoto error_free_frag;\n \t\t}\n \n \t\t/* Buffer is good. Go on. */\n@@ -6023,134 +6014,88 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)\n \t\tbuf2_len = stmmac_rx_buf2_len(priv, p, status, len);\n \t\tlen += buf2_len;\n \n-\t\t/* Drop the packet if it is split over buf1 and buf2 on a\n-\t\t * single descriptor if the interface is running in XDP mode.\n-\t\t */\n-\t\tif (unlikely(stmmac_xdp_is_enabled(priv) \u0026\u0026 buf2_len)) {\n-\t\t\trx_dropped++;\n-\t\t\tgoto next;\n-\t\t}\n-\n-\t\t/* ACS is disabled; strip manually. */\n-\t\tif (likely(!(status \u0026 rx_not_ls)))\n-\t\t\tlen -= ETH_FCS_LEN;\n-\n-\t\tif (!skb) {\n-\t\t\t/* Each frame starts here: reset the FCS handling */\n-\t\t\tfcs_stripped = false;\n-\n+\t\tif (!n_descs) {\n \t\t\tdma_sync_single_for_cpu(priv-\u003edevice, buf-\u003eaddr,\n \t\t\t\t\t\tbuf1_len, dma_dir);\n \t\t\tnet_prefetch(page_address(buf-\u003epage) +\n \t\t\t\t buf-\u003epage_offset);\n \n-\t\t\tif (stmmac_xdp_is_enabled(priv) \u0026\u0026 !buf2_len) {\n-\t\t\t\tbuf1_len -= ETH_FCS_LEN;\n-\t\t\t\tfcs_stripped = true;\n-\t\t\t}\n-\n \t\t\txdp_init_buff(\u0026ctx.xdp, bufsz, \u0026rx_q-\u003exdp_rxq);\n \t\t\txdp_prepare_buff(\u0026ctx.xdp, page_address(buf-\u003epage),\n \t\t\t\t\t buf-\u003epage_offset, buf1_len, true);\n-\n-\t\t\tctx.priv = priv;\n-\t\t\tctx.desc = p;\n-\t\t\tctx.ndesc = np;\n-\n-\t\t\tskb = stmmac_xdp_run_prog(priv, \u0026ctx.xdp);\n-\t\t\t/* For Not XDP_PASS verdict */\n-\t\t\tif (IS_ERR(skb)) {\n-\t\t\t\tunsigned int xdp_res = -PTR_ERR(skb);\n-\n-\t\t\t\tif (xdp_res \u0026 STMMAC_XDP_CONSUMED) {\n-\t\t\t\t\tpage_pool_recycle_direct(rx_q-\u003epage_pool,\n-\t\t\t\t\t\t\t\t virt_to_head_page(ctx.xdp.data));\n-\t\t\t\t\tbuf-\u003epage = NULL;\n+\t\t\tbuf-\u003epage = NULL;\n+\t\t} else if (buf1_len) {\n+\t\t\tif (!stmmac_build_xdp_frags(priv, rx_q, buf1_len,\n+\t\t\t\t\t\t buf-\u003epage,\n+\t\t\t\t\t\t buf-\u003epage_offset,\n+\t\t\t\t\t\t dma_dir, \u0026ctx.xdp)) {\n+\t\t\t\tif (!error)\n \t\t\t\t\trx_dropped++;\n-\t\t\t\t\tgoto next;\n-\t\t\t\t} else if (xdp_res \u0026 (STMMAC_XDP_TX |\n-\t\t\t\t\t\t STMMAC_XDP_REDIRECT)) {\n-\t\t\t\t\txdp_status |= xdp_res;\n-\t\t\t\t\tbuf-\u003epage = NULL;\n-\t\t\t\t\tgoto next;\n-\t\t\t\t}\n-\t\t\t}\n-\t\t}\n-\n-\t\tif (!skb) {\n-\t\t\tunsigned int metasize;\n-\n-\t\t\t/* XDP program may expand or reduce tail */\n-\t\t\tbuf1_len = ctx.xdp.data_end - ctx.xdp.data;\n-\n-\t\t\tskb = napi_build_skb(page_address(buf-\u003epage),\n-\t\t\t\t\t rx_q-\u003enapi_skb_frag_size);\n-\t\t\tif (!skb) {\n-\t\t\t\tpage_pool_recycle_direct(rx_q-\u003epage_pool,\n-\t\t\t\t\t\t\t buf-\u003epage);\n-\t\t\t\tbuf-\u003epage = NULL;\n-\t\t\t\trx_dropped++;\n \t\t\t\terror = 1;\n-\t\t\t\tgoto drain_data;\n \t\t\t}\n-\n-\t\t\t/* XDP program may adjust header */\n-\t\t\tskb_reserve(skb,\n-\t\t\t\t ctx.xdp.data - ctx.xdp.data_hard_start);\n-\t\t\tskb_put(skb, buf1_len);\n-\t\t\tskb_mark_for_recycle(skb);\n-\n-\t\t\tmetasize = ctx.xdp.data - ctx.xdp.data_meta;\n-\t\t\tif (metasize)\n-\t\t\t\tskb_metadata_set(skb, metasize);\n-\t\t\tbuf-\u003epage = NULL;\n-\t\t} else if (buf1_len) {\n-\t\t\tdma_sync_single_for_cpu(priv-\u003edevice, buf-\u003eaddr,\n-\t\t\t\t\t\tbuf1_len, dma_dir);\n-\t\t\tskb_add_rx_frag(skb, skb_shinfo(skb)-\u003enr_frags,\n-\t\t\t\t\tbuf-\u003epage, buf-\u003epage_offset, buf1_len,\n-\t\t\t\t\tpriv-\u003edma_conf.dma_buf_sz);\n \t\t\tbuf-\u003epage = NULL;\n \t\t}\n \n \t\tif (buf2_len) {\n-\t\t\tdma_sync_single_for_cpu(priv-\u003edevice, buf-\u003esec_addr,\n-\t\t\t\t\t\tbuf2_len, dma_dir);\n-\t\t\tskb_add_rx_frag(skb, skb_shinfo(skb)-\u003enr_frags,\n-\t\t\t\t\tbuf-\u003esec_page, 0, buf2_len,\n-\t\t\t\t\tpriv-\u003edma_conf.dma_buf_sz);\n+\t\t\tif (!stmmac_build_xdp_frags(priv, rx_q, buf2_len,\n+\t\t\t\t\t\t buf-\u003esec_page, 0,\n+\t\t\t\t\t\t dma_dir, \u0026ctx.xdp)) {\n+\t\t\t\tif (!error)\n+\t\t\t\t\trx_dropped++;\n+\t\t\t\terror = 1;\n+\t\t\t}\n \t\t\tbuf-\u003esec_page = NULL;\n \t\t}\n+\t\tn_descs++;\n \n-drain_data:\n \t\tif (likely(status \u0026 rx_not_ls))\n \t\t\tgoto read_again;\n-\t\tif (!skb)\n-\t\t\tgoto next;\n \n-\t\t/* Got entire packet into SKB. Finish it. */\n+\t\t/* ACS is disabled; strip manually. */\n+\t\tlen -= ETH_FCS_LEN;\n+\t\tif (xdp_buff_shrink_tail(\u0026ctx.xdp, ETH_FCS_LEN)) {\n+\t\t\tif (!error)\n+\t\t\t\trx_dropped++;\n+\t\t\terror = 1;\n+\t\t}\n \n-\t\t/* Remove FCS if needed */\n-\t\tif (!fcs_stripped \u0026\u0026 pskb_trim(skb, len)) {\n-\t\t\tdev_kfree_skb_any(skb);\n-\t\t\trx_dropped++;\n+\t\tif (unlikely(error))\n+\t\t\tgoto error_free_frag;\n+\n+\t\tctx.desc = p;\n+\t\tctx.ndesc = np;\n+\n+\t\tskb = stmmac_xdp_run_prog(priv, \u0026ctx.xdp);\n+\t\t/* For Not XDP_PASS verdict */\n+\t\tif (IS_ERR(skb)) {\n+\t\t\tunsigned int xdp_res = -PTR_ERR(skb);\n+\n+\t\t\tif (xdp_res \u0026 STMMAC_XDP_CONSUMED) {\n+\t\t\t\t__xdp_return_buff(\u0026ctx.xdp, true);\n+\t\t\t\trx_dropped++;\n+\t\t\t} else if (xdp_res \u0026 (STMMAC_XDP_TX |\n+\t\t\t\t\t STMMAC_XDP_REDIRECT)) {\n+\t\t\t\txdp_status |= xdp_res;\n+\t\t\t}\n \t\t\tgoto next;\n \t\t}\n \n+\t\tskb = xdp_build_skb_from_buff(\u0026ctx.xdp);\n+\t\tif (!skb) {\n+\t\t\trx_dropped++;\n+\t\t\tgoto error_free_frag;\n+\t\t}\n+\n+\t\t/* Got entire packet into SKB. Finish it. */\n \t\tstmmac_get_rx_hwtstamp(priv, p, np, skb);\n \n \t\tif (priv-\u003ehw-\u003ehw_vlan_en) {\n \t\t\t/* MAC level stripping. */\n \t\t\tstmmac_rx_hw_vlan(priv, priv-\u003ehw, p, skb);\n-\t\t} else if (stmmac_rx_vlan(priv-\u003edev, skb)) {\n-\t\t\tdev_kfree_skb_any(skb);\n-\t\t\trx_dropped++;\n-\t\t\tgoto next;\n \t\t}\n \n-\t\tskb-\u003eprotocol = eth_type_trans(skb, priv-\u003edev);\n-\n-\t\tif (unlikely(!coe) || !stmmac_has_ip_ethertype(skb) ||\n+\t\tif (unlikely(!coe) ||\n+\t\t !stmmac_has_ip_ethertype(priv, skb, false) ||\n \t\t (status \u0026 csum_none))\n \t\t\tskb_checksum_none_assert(skb);\n \t\telse\n@@ -6159,21 +6104,28 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)\n \t\tif (!stmmac_get_rx_hash(priv, p, \u0026hash, \u0026hash_type))\n \t\t\tskb_set_hash(skb, hash, hash_type);\n \n-\t\tskb_record_rx_queue(skb, queue);\n \t\tnapi_gro_receive(\u0026ch-\u003erx_napi, skb);\n \t\trx_packets++;\n \t\trx_bytes += len;\n next:\n \t\tin_progress = false;\n-\t\tskb = NULL;\n+\t\tn_descs = 0;\n+\t\tcount++;\n+\t\tcontinue;\n+error_free_frag:\n+\t\tif (n_descs)\n+\t\t\t__xdp_return_buff(\u0026ctx.xdp, true);\n+\t\tin_progress = false;\n+\t\tn_descs = 0;\n \t\tcount++;\n \t}\n \n-\tif (in_progress || skb) {\n-\t\trx_q-\u003estate_saved = true;\n-\t\trx_q-\u003estate.skb = skb;\n+\tif (in_progress || n_descs) {\n+\t\trx_q-\u003estate.xdp = ctx.xdp;\n+\t\trx_q-\u003estate.n_descs = n_descs;\n \t\trx_q-\u003estate.error = error;\n \t\trx_q-\u003estate.len = len;\n+\t\trx_q-\u003estate_saved = true;\n \t}\n \n \tstmmac_finalize_xdp_rx(priv, xdp_status);\n@@ -6429,7 +6381,7 @@ static netdev_features_t stmmac_fix_features(struct net_device *dev,\n \tif (priv-\u003eplat-\u003ebugged_jumbo \u0026\u0026 (dev-\u003emtu \u003e ETH_DATA_LEN))\n \t\tfeatures \u0026= ~NETIF_F_CSUM_MASK;\n \n-\tif (priv-\u003eplat-\u003ecore_type == DWMAC_CORE_XGMAC) {\n+\tif (stmmac_rx_8021ad_offload(priv)) {\n \t\tif (features \u0026 NETIF_F_HW_VLAN_CTAG_RX)\n \t\t\tfeatures |= NETIF_F_HW_VLAN_STAG_RX;\n \t\telse\n@@ -6462,7 +6414,7 @@ static int stmmac_set_features(struct net_device *netdev,\n \t\t\tstmmac_enable_sph(priv, priv-\u003eioaddr, sph_en, chan);\n \t}\n \n-\tif (features \u0026 NETIF_F_HW_VLAN_CTAG_RX)\n+\tif (features \u0026 (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX))\n \t\tpriv-\u003ehw-\u003ehw_vlan_en = true;\n \telse\n \t\tpriv-\u003ehw-\u003ehw_vlan_en = false;\n@@ -8275,15 +8227,17 @@ static int __stmmac_dvr_probe(struct device *device,\n \tndev-\u003efeatures |= ndev-\u003ehw_features | NETIF_F_HIGHDMA;\n \tndev-\u003ewatchdog_timeo = msecs_to_jiffies(watchdog);\n #ifdef STMMAC_VLAN_TAG_USED\n-\t/* Both mac100 and gmac support receive VLAN tag detection */\n-\tndev-\u003efeatures |= NETIF_F_HW_VLAN_CTAG_RX;\n-\tif (priv-\u003eplat-\u003ecore_type == DWMAC_CORE_XGMAC)\n-\t\tndev-\u003efeatures |= NETIF_F_HW_VLAN_STAG_RX;\n-\n-\tif (dwmac_is_xmac(priv-\u003eplat-\u003ecore_type)) {\n+\tif (stmmac_rx_8021q_offload(priv)) {\n+\t\tndev-\u003efeatures |= NETIF_F_HW_VLAN_CTAG_RX;\n \t\tndev-\u003ehw_features |= NETIF_F_HW_VLAN_CTAG_RX;\n \t\tpriv-\u003ehw-\u003ehw_vlan_en = true;\n \t}\n+\n+\tif (stmmac_rx_8021ad_offload(priv)) {\n+\t\tndev-\u003efeatures |= NETIF_F_HW_VLAN_STAG_RX;\n+\t\tndev-\u003ehw_features |= NETIF_F_HW_VLAN_STAG_RX;\n+\t}\n+\n \tif (priv-\u003edma_cap.vlhash) {\n \t\tndev-\u003efeatures |= NETIF_F_HW_VLAN_CTAG_FILTER;\n \t\tif (priv-\u003eplat-\u003ecore_type == DWMAC_CORE_XGMAC)\n@@ -8544,9 +8498,12 @@ static void stmmac_reset_rx_queue(struct stmmac_priv *priv, u32 queue)\n {\n \tstruct stmmac_rx_queue *rx_q = \u0026priv-\u003edma_conf.rx_queue[queue];\n \n-\tdev_kfree_skb_any(rx_q-\u003estate.skb);\n-\trx_q-\u003estate.skb = NULL;\n+\tif (rx_q-\u003estate.n_descs \u0026\u0026 !rx_q-\u003exsk_pool) {\n+\t\t__xdp_return_buff(\u0026rx_q-\u003estate.xdp, false);\n+\t\trx_q-\u003estate.n_descs = 0;\n+\t}\n \trx_q-\u003estate_saved = false;\n+\n \trx_q-\u003ecur_rx = 0;\n \trx_q-\u003edirty_rx = 0;\n }\ndiff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c\nindex df696e2c15284d..41a8493cf9dd3a 100644\n--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c\n+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c\n@@ -1940,12 +1940,14 @@ void stmmac_selftest_run(struct net_device *dev,\n \t\treturn;\n \t}\n \n+\tphylink_rx_clk_stop_block(priv-\u003ephylink);\n \tfor (i = 0; i \u003c count; i++) {\n \t\tret = stmmac_selftests[i].fn(priv);\n \t\tif (ret \u0026\u0026 (ret != -EOPNOTSUPP))\n \t\t\tetest-\u003eflags |= ETH_TEST_FL_FAILED;\n \t\tbuf[i] = ret;\n \t}\n+\tphylink_rx_clk_stop_unblock(priv-\u003ephylink);\n \n \tstmmac_set_mac_loopback(priv, priv-\u003eioaddr, false);\n }\ndiff --git a/include/net/xdp.h b/include/net/xdp.h\nindex 07231adfb5f829..f0946500c48747 100644\n--- a/include/net/xdp.h\n+++ b/include/net/xdp.h\n@@ -388,6 +388,9 @@ struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf,\n struct sk_buff *xdp_build_skb_from_frame(struct xdp_frame *xdpf,\n \t\t\t\t\t struct net_device *dev);\n struct xdp_frame *xdpf_clone(struct xdp_frame *xdpf);\n+int xdp_buff_shrink_tail(struct xdp_buff *xdp, int offset);\n+bool xdp_buff_shrink_data(struct xdp_buff *xdp, skb_frag_t *frag,\n+\t\t\t int shrink, bool tail);\n \n static inline\n void xdp_convert_frame_to_buff(const struct xdp_frame *frame,\n@@ -454,7 +457,12 @@ void __xdp_return(netmem_ref netmem, enum xdp_mem_type mem_type,\n \t\t bool napi_direct, struct xdp_buff *xdp);\n void xdp_return_frame(struct xdp_frame *xdpf);\n void xdp_return_frame_rx_napi(struct xdp_frame *xdpf);\n-void xdp_return_buff(struct xdp_buff *xdp);\n+void __xdp_return_buff(struct xdp_buff *xdp, bool napi_direct);\n+static inline void xdp_return_buff(struct xdp_buff *xdp)\n+{\n+\t__xdp_return_buff(xdp, true);\n+}\n+\n void xdp_return_frame_bulk(struct xdp_frame *xdpf,\n \t\t\t struct xdp_frame_bulk *bq);\n \ndiff --git a/net/core/filter.c b/net/core/filter.c\nindex f42ecfb5841f9c..cdbb54a10b0b88 100644\n--- a/net/core/filter.c\n+++ b/net/core/filter.c\n@@ -4438,88 +4438,16 @@ static int bpf_xdp_frags_increase_tail(struct xdp_buff *xdp, int offset)\n \treturn 0;\n }\n \n-static struct xdp_buff *bpf_xdp_shrink_data_zc(struct xdp_buff *xdp, int shrink,\n-\t\t\t\t\t bool tail, bool release)\n-{\n-\tstruct xdp_buff *zc_frag = tail ? xsk_buff_get_tail(xdp) :\n-\t\t\t\t\t xsk_buff_get_head(xdp);\n-\n-\tif (release) {\n-\t\txsk_buff_del_frag(zc_frag);\n-\t} else {\n-\t\tif (tail)\n-\t\t\tzc_frag-\u003edata_end -= shrink;\n-\t\telse\n-\t\t\tzc_frag-\u003edata += shrink;\n-\t}\n-\n-\treturn zc_frag;\n-}\n-\n-static bool bpf_xdp_shrink_data(struct xdp_buff *xdp, skb_frag_t *frag,\n-\t\t\t\tint shrink, bool tail)\n-{\n-\tenum xdp_mem_type mem_type = xdp-\u003erxq-\u003emem.type;\n-\tbool release = skb_frag_size(frag) == shrink;\n-\tnetmem_ref netmem = skb_frag_netmem(frag);\n-\tstruct xdp_buff *zc_frag = NULL;\n-\n-\tif (mem_type == MEM_TYPE_XSK_BUFF_POOL) {\n-\t\tnetmem = 0;\n-\t\tzc_frag = bpf_xdp_shrink_data_zc(xdp, shrink, tail, release);\n-\t}\n-\n-\tif (release) {\n-\t\t__xdp_return(netmem, mem_type, false, zc_frag);\n-\t} else {\n-\t\tif (!tail)\n-\t\t\tskb_frag_off_add(frag, shrink);\n-\t\tskb_frag_size_sub(frag, shrink);\n-\t}\n-\n-\treturn release;\n-}\n-\n-static int bpf_xdp_frags_shrink_tail(struct xdp_buff *xdp, int offset)\n-{\n-\tstruct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);\n-\tint i, n_frags_free = 0, len_free = 0;\n-\n-\tif (unlikely(offset \u003e (int)xdp_get_buff_len(xdp) - ETH_HLEN))\n-\t\treturn -EINVAL;\n-\n-\tfor (i = sinfo-\u003enr_frags - 1; i \u003e= 0 \u0026\u0026 offset \u003e 0; i--) {\n-\t\tskb_frag_t *frag = \u0026sinfo-\u003efrags[i];\n-\t\tint shrink = min_t(int, offset, skb_frag_size(frag));\n-\n-\t\tlen_free += shrink;\n-\t\toffset -= shrink;\n-\t\tif (bpf_xdp_shrink_data(xdp, frag, shrink, true))\n-\t\t\tn_frags_free++;\n-\t}\n-\tsinfo-\u003enr_frags -= n_frags_free;\n-\tsinfo-\u003exdp_frags_size -= len_free;\n-\n-\tif (unlikely(!sinfo-\u003enr_frags)) {\n-\t\txdp_buff_clear_frags_flag(xdp);\n-\t\txdp_buff_clear_frag_pfmemalloc(xdp);\n-\t\txdp-\u003edata_end -= offset;\n-\t}\n-\n-\treturn 0;\n-}\n-\n BPF_CALL_2(bpf_xdp_adjust_tail, struct xdp_buff *, xdp, int, offset)\n {\n \tvoid *data_hard_end = xdp_data_hard_end(xdp); /* use xdp-\u003eframe_sz */\n \tvoid *data_end = xdp-\u003edata_end + offset;\n \n-\tif (unlikely(xdp_buff_has_frags(xdp))) { /* non-linear xdp buff */\n-\t\tif (offset \u003c 0)\n-\t\t\treturn bpf_xdp_frags_shrink_tail(xdp, -offset);\n+\tif (offset \u003c 0)\n+\t\treturn xdp_buff_shrink_tail(xdp, -offset);\n \n+\tif (unlikely(xdp_buff_has_frags(xdp))) /* non-linear xdp buff */\n \t\treturn bpf_xdp_frags_increase_tail(xdp, offset);\n-\t}\n \n \t/* Notice that xdp_data_hard_end have reserved some tailroom */\n \tif (unlikely(data_end \u003e data_hard_end))\n@@ -12840,7 +12768,7 @@ __bpf_kfunc int bpf_xdp_pull_data(struct xdp_md *x, u32 len)\n \t\txdp-\u003edata_end += shrink;\n \t\tsinfo-\u003exdp_frags_size -= shrink;\n \t\tdelta -= shrink;\n-\t\tif (bpf_xdp_shrink_data(xdp, frag, shrink, false))\n+\t\tif (xdp_buff_shrink_data(xdp, frag, shrink, false))\n \t\t\tn_frags_free++;\n \t}\n \ndiff --git a/net/core/xdp.c b/net/core/xdp.c\nindex 1d679e8fd64937..f35ae7e118f567 100644\n--- a/net/core/xdp.c\n+++ b/net/core/xdp.c\n@@ -546,7 +546,7 @@ void xdp_return_frag(netmem_ref netmem, const struct xdp_buff *xdp)\n }\n EXPORT_SYMBOL_GPL(xdp_return_frag);\n \n-void xdp_return_buff(struct xdp_buff *xdp)\n+void __xdp_return_buff(struct xdp_buff *xdp, bool napi_direct)\n {\n \tstruct skb_shared_info *sinfo;\n \n@@ -556,12 +556,13 @@ void xdp_return_buff(struct xdp_buff *xdp)\n \tsinfo = xdp_get_shared_info_from_buff(xdp);\n \tfor (u32 i = 0; i \u003c sinfo-\u003enr_frags; i++)\n \t\t__xdp_return(skb_frag_netmem(\u0026sinfo-\u003efrags[i]),\n-\t\t\t xdp-\u003erxq-\u003emem.type, true, xdp);\n+\t\t\t xdp-\u003erxq-\u003emem.type, napi_direct, xdp);\n \n out:\n-\t__xdp_return(virt_to_netmem(xdp-\u003edata), xdp-\u003erxq-\u003emem.type, true, xdp);\n+\t__xdp_return(virt_to_netmem(xdp-\u003edata), xdp-\u003erxq-\u003emem.type,\n+\t\t napi_direct, xdp);\n }\n-EXPORT_SYMBOL_GPL(xdp_return_buff);\n+EXPORT_SYMBOL_GPL(__xdp_return_buff);\n \n void xdp_attachment_setup(struct xdp_attachment_info *info,\n \t\t\t struct netdev_bpf *bpf)\n@@ -673,6 +674,95 @@ struct sk_buff *xdp_build_skb_from_buff(const struct xdp_buff *xdp)\n }\n EXPORT_SYMBOL_GPL(xdp_build_skb_from_buff);\n \n+static struct xdp_buff *xdp_buff_shrink_data_zc(struct xdp_buff *xdp,\n+\t\t\t\t\t\tint shrink, bool tail,\n+\t\t\t\t\t\tbool release)\n+{\n+\tstruct xdp_buff *zc_frag = tail ? xsk_buff_get_tail(xdp) :\n+\t\t\t\t\t xsk_buff_get_head(xdp);\n+\n+\tif (release) {\n+\t\txsk_buff_del_frag(zc_frag);\n+\t} else {\n+\t\tif (tail)\n+\t\t\tzc_frag-\u003edata_end -= shrink;\n+\t\telse\n+\t\t\tzc_frag-\u003edata += shrink;\n+\t}\n+\n+\treturn zc_frag;\n+}\n+\n+bool xdp_buff_shrink_data(struct xdp_buff *xdp, skb_frag_t *frag,\n+\t\t\t int shrink, bool tail)\n+{\n+\tenum xdp_mem_type mem_type = xdp-\u003erxq-\u003emem.type;\n+\tbool release = skb_frag_size(frag) == shrink;\n+\tnetmem_ref netmem = skb_frag_netmem(frag);\n+\tstruct xdp_buff *zc_frag = NULL;\n+\n+\tif (mem_type == MEM_TYPE_XSK_BUFF_POOL) {\n+\t\tnetmem = 0;\n+\t\tzc_frag = xdp_buff_shrink_data_zc(xdp, shrink, tail, release);\n+\t}\n+\n+\tif (release) {\n+\t\t__xdp_return(netmem, mem_type, false, zc_frag);\n+\t} else {\n+\t\tif (!tail)\n+\t\t\tskb_frag_off_add(frag, shrink);\n+\t\tskb_frag_size_sub(frag, shrink);\n+\t}\n+\n+\treturn release;\n+}\n+\n+static int xdp_frags_shrink_tail(struct xdp_buff *xdp, int offset)\n+{\n+\tstruct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);\n+\tint i, n_frags_free = 0, len_free = 0;\n+\n+\tif (unlikely(offset \u003e (int)xdp_get_buff_len(xdp) - ETH_HLEN))\n+\t\treturn -EINVAL;\n+\n+\tfor (i = sinfo-\u003enr_frags - 1; i \u003e= 0 \u0026\u0026 offset \u003e 0; i--) {\n+\t\tskb_frag_t *frag = \u0026sinfo-\u003efrags[i];\n+\t\tint shrink = min_t(int, offset, skb_frag_size(frag));\n+\n+\t\tlen_free += shrink;\n+\t\toffset -= shrink;\n+\t\tif (xdp_buff_shrink_data(xdp, frag, shrink, true))\n+\t\t\tn_frags_free++;\n+\t}\n+\tsinfo-\u003enr_frags -= n_frags_free;\n+\tsinfo-\u003exdp_frags_size -= len_free;\n+\n+\tif (unlikely(!sinfo-\u003enr_frags)) {\n+\t\txdp_buff_clear_frags_flag(xdp);\n+\t\txdp_buff_clear_frag_pfmemalloc(xdp);\n+\t\txdp-\u003edata_end -= offset;\n+\t}\n+\n+\treturn 0;\n+}\n+\n+int xdp_buff_shrink_tail(struct xdp_buff *xdp, int offset)\n+{\n+\tif (unlikely(offset \u003c 0))\n+\t\treturn -EINVAL;\n+\n+\tif (unlikely(xdp_buff_has_frags(xdp))) /* non-linear xdp buff */\n+\t\treturn xdp_frags_shrink_tail(xdp, offset);\n+\n+\tif (unlikely(offset \u003e xdp-\u003edata_end - xdp-\u003edata - ETH_HLEN))\n+\t\treturn -EINVAL;\n+\n+\txdp-\u003edata_end = xdp-\u003edata_end - offset;\n+\n+\treturn 0;\n+}\n+EXPORT_SYMBOL_GPL(xdp_buff_shrink_tail);\n+\n /**\n * xdp_copy_frags_from_zc - copy frags from XSk buff to skb\n * @skb: skb to copy frags to\n"
} |
| 2/1 | 2026/12/01 04:23 | agent | patch-evaluator |
1mModel:core Args: null Results: {
"EnableConfigs": [
"NET",
"BPF_SYSCALL",
"XDP_SOCKETS",
"VETH",
"DEBUG_INFO_BTF"
],
"FocusSymbols": [
"xdp_buff_shrink_tail",
"xdp_buff_shrink_data",
"bpf_xdp_adjust_tail",
"bpf_xdp_pull_data"
],
"Reasoning": "While the stmmac driver changes target hardware not emulated in standard QEMU, the patch series also modifies core networking and BPF/XDP code in net/core/xdp.c and net/core/filter.c. Specifically, bpf_xdp_adjust_tail now routes all negative-offset calls (for both linear and non-linear xdp_buff) to the new xdp_buff_shrink_tail helper, and bpf_xdp_pull_data and xdp_frags_shrink_tail use the refactored xdp_buff_shrink_data / xdp_buff_shrink_data_zc helpers. These paths are directly reachable in virtualized environments via BPF_PROG_TEST_RUN (BPF_PROG_TYPE_XDP), veth with XDP attached, and AF_XDP sockets.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit b454ef3570e631c9e43d22ec78887bcf930b8b07
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Dec 1 04:23:16 2026 +0000
syz-cluster: applied patch under review
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index fcc395321816fd..d77e442249abbf 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -133,7 +133,8 @@ struct stmmac_rx_queue {
dma_addr_t dma_rx_phy;
unsigned int state_saved;
struct {
- struct sk_buff *skb;
+ struct xdp_buff xdp;
+ unsigned int n_descs;
unsigned int len;
unsigned int error;
} state;
@@ -478,4 +479,16 @@ static inline int stmmac_selftest_get_count(struct stmmac_priv *priv)
}
#endif /* CONFIG_STMMAC_SELFTESTS */
+static inline bool stmmac_rx_8021q_offload(struct stmmac_priv *priv)
+{
+ return priv->hw->vlan && priv->hw->vlan->set_hw_vlan_mode &&
+ priv->hw->vlan->rx_hw_vlan;
+}
+
+static inline bool stmmac_rx_8021ad_offload(struct stmmac_priv *priv)
+{
+ return stmmac_rx_8021q_offload(priv) &&
+ priv->hw->desc->get_rx_vlan_proto;
+}
+
#endif /* __STMMAC_H__ */
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index ca4c7fb11b73fe..56355d80ba161c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -2195,8 +2195,10 @@ static void __free_dma_rx_desc_resources(struct stmmac_priv *priv,
else
dma_free_rx_skbufs(priv, dma_conf, queue);
- dev_kfree_skb_any(rx_q->state.skb);
- rx_q->state.skb = NULL;
+ if (rx_q->state.n_descs && !rx_q->xsk_pool) {
+ __xdp_return_buff(&rx_q->state.xdp, false);
+ rx_q->state.n_descs = 0;
+ }
rx_q->state_saved = false;
rx_q->buf_alloc_num = 0;
rx_q->xsk_pool = NULL;
@@ -2316,10 +2318,6 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
num_pages = DIV_ROUND_UP(dma_buf_sz_pad, PAGE_SIZE);
- rx_q->queue_index = queue;
- rx_q->priv_data = priv;
- rx_q->napi_skb_frag_size = num_pages * PAGE_SIZE;
-
pp_params.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV;
pp_params.pool_size = dma_conf->dma_rx_size;
pp_params.order = order_base_2(num_pages);
@@ -2351,6 +2349,10 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
goto err_free_buf_pool;
}
+ rx_q->queue_index = queue;
+ rx_q->priv_data = priv;
+ rx_q->napi_skb_frag_size = PAGE_SIZE << pp_params.order;
+
if (priv->extend_desc)
rx_q->dma_erx = addr;
else
@@ -2362,7 +2364,8 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
else
napi_id = ch->rx_napi.napi_id;
- ret = xdp_rxq_info_reg(&rx_q->xdp_rxq, priv->dev, queue, napi_id);
+ ret = __xdp_rxq_info_reg(&rx_q->xdp_rxq, priv->dev, queue, napi_id,
+ rx_q->napi_skb_frag_size);
if (ret) {
netdev_err(priv->dev, "Failed to register xdp rxq info\n");
goto err_free_dma;
@@ -4879,7 +4882,9 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
/**
* stmmac_has_ip_ethertype() - Check if packet has IP ethertype
+ * @priv: driver private structure
* @skb: socket buffer to check
+ * @xmit: transmit path
*
* Check if a packet has an ethertype that will trigger the IP header checks
* and IP/TCP checksum engine of the stmmac core.
@@ -4887,16 +4892,25 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
* Return: true if the ethertype can trigger the checksum engine, false
* otherwise
*/
-static bool stmmac_has_ip_ethertype(struct sk_buff *skb)
+static bool stmmac_has_ip_ethertype(struct stmmac_priv *priv,
+ struct sk_buff *skb, bool xmit)
{
- int depth = 0;
- __be16 proto;
+ __be16 proto, h_proto = eth_header_parse_protocol(skb);
+ int max_l2_hlen, depth = 0;
+
+ /* An S-tag still in the payload may not have been parsed by the
+ * checksum engine; only trust it when the hardware stripped it, in
+ * which case h_proto is no longer ETH_P_8021AD.
+ */
+ if (h_proto == htons(ETH_P_8021AD))
+ return false;
- proto = __vlan_get_protocol(skb, eth_header_parse_protocol(skb),
- &depth);
+ proto = vlan_get_protocol_offset_inline(skb, h_proto,
+ skb_mac_offset(skb), &depth);
- return (depth <= ETH_HLEN) &&
- (proto == htons(ETH_P_IP) || proto == htons(ETH_P_IPV6));
+ max_l2_hlen = xmit || priv->hw->hw_vlan_en ? ETH_HLEN : VLAN_ETH_HLEN;
+ return depth <= max_l2_hlen &&
+ (proto == htons(ETH_P_IP) || proto == htons(ETH_P_IPV6));
}
/**
@@ -5153,7 +5167,7 @@ static netdev_features_t stmmac_features_check(struct sk_buff *skb,
* harmonize_features() in net/core/dev.c
*/
if (priv->plat->tx_queues_cfg[queue].coe_unsupported ||
- !stmmac_has_ip_ethertype(skb))
+ !stmmac_has_ip_ethertype(priv, skb, true))
features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
if (skb_is_gso(skb)) {
@@ -5175,37 +5189,6 @@ static netdev_features_t stmmac_features_check(struct sk_buff *skb,
return vlan_features_check(skb, features);
}
-static int stmmac_rx_vlan(struct net_device *dev, struct sk_buff *skb)
-{
- struct vlan_ethhdr *veth;
-
- if (!pskb_may_pull(skb, ETH_HLEN))
- return -EINVAL;
-
- veth = skb_vlan_eth_hdr(skb);
- if ((veth->h_vlan_proto == htons(ETH_P_8021Q) &&
- dev->features & NETIF_F_HW_VLAN_CTAG_RX) ||
- (veth->h_vlan_proto == htons(ETH_P_8021AD) &&
- dev->features & NETIF_F_HW_VLAN_STAG_RX)) {
- __be16 vlan_proto = veth->h_vlan_proto;
- u8 meta_len = skb_metadata_len(skb);
- u16 vlanid;
-
- /* pop the vlan tag */
- if (!pskb_may_pull(skb, VLAN_ETH_HLEN))
- return -EINVAL;
-
- veth = skb_vlan_eth_hdr(skb);
- vlanid = ntohs(veth->h_vlan_TCI);
- memmove(skb->data - meta_len + VLAN_HLEN,
- skb->data - meta_len, meta_len + ETH_ALEN * 2);
- skb_pull(skb, VLAN_HLEN);
- __vlan_hwaccel_put_tag(skb, vlan_proto, vlanid);
- }
-
- return 0;
-}
-
static bool stmmac_rx_need_ic(struct stmmac_priv *priv,
struct stmmac_rx_queue *rx_q, u32 queue)
{
@@ -5554,8 +5537,8 @@ static int __stmmac_xdp_run_prog(struct stmmac_priv *priv,
static struct sk_buff *stmmac_xdp_run_prog(struct stmmac_priv *priv,
struct xdp_buff *xdp)
{
+ int res = STMMAC_XDP_CONSUMED;
struct bpf_prog *prog;
- int res;
prog = READ_ONCE(priv->xdp_prog);
if (!prog) {
@@ -5563,7 +5546,8 @@ static struct sk_buff *stmmac_xdp_run_prog(struct stmmac_priv *priv,
goto out;
}
- res = __stmmac_xdp_run_prog(priv, prog, xdp);
+ if (likely(!xdp_buff_has_frags(xdp) || prog->aux->xdp_has_frags))
+ res = __stmmac_xdp_run_prog(priv, prog, xdp);
out:
return ERR_PTR(-res);
}
@@ -5626,15 +5610,11 @@ static void stmmac_dispatch_skb_zc(struct stmmac_priv *priv, u32 queue,
if (priv->hw->hw_vlan_en) {
/* MAC level stripping. */
stmmac_rx_hw_vlan(priv, priv->hw, p, skb);
- } else if (stmmac_rx_vlan(priv->dev, skb)) {
- dev_kfree_skb_any(skb);
- priv->xstats.rx_dropped++;
- return;
}
skb->protocol = eth_type_trans(skb, priv->dev);
- if (unlikely(!coe) || !stmmac_has_ip_ethertype(skb) ||
+ if (unlikely(!coe) || !stmmac_has_ip_ethertype(priv, skb, false) ||
(status & csum_none))
skb_checksum_none_assert(skb);
else
@@ -5897,6 +5877,25 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
return failure ? limit : (int)count;
}
+static bool stmmac_build_xdp_frags(struct stmmac_priv *priv,
+ struct stmmac_rx_queue *rx_q,
+ unsigned int len, struct page *page,
+ unsigned int offset,
+ enum dma_data_direction dma_dir,
+ struct xdp_buff *xdp)
+{
+ dma_addr_t dma_addr = page_pool_get_dma_addr(page) + offset;
+
+ dma_sync_single_for_cpu(priv->device, dma_addr, len, dma_dir);
+ if (!xdp_buff_add_frag(xdp, page_to_netmem(page), offset, len,
+ xdp->frame_sz)) {
+ page_pool_put_full_page(rx_q->page_pool, page, true);
+ return false;
+ }
+
+ return true;
+}
+
/**
* stmmac_rx - manage the receive process
* @priv: driver private structure
@@ -5910,21 +5909,20 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
u32 rx_errors = 0, rx_dropped = 0, rx_bytes = 0, rx_packets = 0;
struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[queue];
struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
+ unsigned int n_descs = 0, next_entry = rx_q->cur_rx;
struct stmmac_channel *ch = &priv->channel[queue];
unsigned int count = 0, error = 0, len = 0;
- unsigned int next_entry = rx_q->cur_rx;
bool in_progress = rx_q->state_saved;
enum dma_data_direction dma_dir;
int coe = priv->hw->rx_csum;
- unsigned int desc_size;
- struct sk_buff *skb = NULL;
struct stmmac_xdp_buff ctx;
- bool fcs_stripped = false;
+ unsigned int desc_size;
int xdp_status = 0;
int bufsz;
dma_dir = page_pool_get_dma_dir(rx_q->page_pool);
- bufsz = DIV_ROUND_UP(priv->dma_conf.dma_buf_sz, PAGE_SIZE) * PAGE_SIZE;
+ bufsz = rx_q->napi_skb_frag_size;
+ ctx.priv = priv;
if (netif_msg_rx_status(priv)) {
void *rx_head = stmmac_get_rx_desc(priv, rx_q, 0);
@@ -5937,11 +5935,12 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
}
if (rx_q->state_saved) {
- skb = rx_q->state.skb;
+ ctx.xdp = rx_q->state.xdp;
error = rx_q->state.error;
+ n_descs = rx_q->state.n_descs;
len = rx_q->state.len;
- rx_q->state.skb = NULL;
rx_q->state_saved = false;
+ rx_q->state.n_descs = 0;
}
while (count < limit) {
@@ -5949,11 +5948,11 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
enum pkt_hash_types hash_type;
struct stmmac_rx_buffer *buf;
struct dma_desc *np, *p;
+ struct sk_buff *skb;
int entry, status;
u32 hash;
if (!in_progress) {
- skb = NULL;
error = 0;
len = 0;
}
@@ -6001,19 +6000,11 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
rx_errors++;
}
- /* We do not support SG in XDP mode */
- if (unlikely(!error && (status & rx_not_ls) &&
- stmmac_xdp_is_enabled(priv))) {
- rx_dropped++;
- error = 1;
- }
-
if (unlikely(error)) {
if (status & rx_not_ls)
goto read_again;
- dev_kfree_skb(skb);
- goto next;
+ goto error_free_frag;
}
/* Buffer is good. Go on. */
@@ -6023,134 +6014,88 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
buf2_len = stmmac_rx_buf2_len(priv, p, status, len);
len += buf2_len;
- /* Drop the packet if it is split over buf1 and buf2 on a
- * single descriptor if the interface is running in XDP mode.
- */
- if (unlikely(stmmac_xdp_is_enabled(priv) && buf2_len)) {
- rx_dropped++;
- goto next;
- }
-
- /* ACS is disabled; strip manually. */
- if (likely(!(status & rx_not_ls)))
- len -= ETH_FCS_LEN;
-
- if (!skb) {
- /* Each frame starts here: reset the FCS handling */
- fcs_stripped = false;
-
+ if (!n_descs) {
dma_sync_single_for_cpu(priv->device, buf->addr,
buf1_len, dma_dir);
net_prefetch(page_address(buf->page) +
buf->page_offset);
- if (stmmac_xdp_is_enabled(priv) && !buf2_len) {
- buf1_len -= ETH_FCS_LEN;
- fcs_stripped = true;
- }
-
xdp_init_buff(&ctx.xdp, bufsz, &rx_q->xdp_rxq);
xdp_prepare_buff(&ctx.xdp, page_address(buf->page),
buf->page_offset, buf1_len, true);
-
- ctx.priv = priv;
- ctx.desc = p;
- ctx.ndesc = np;
-
- skb = stmmac_xdp_run_prog(priv, &ctx.xdp);
- /* For Not XDP_PASS verdict */
- if (IS_ERR(skb)) {
- unsigned int xdp_res = -PTR_ERR(skb);
-
- if (xdp_res & STMMAC_XDP_CONSUMED) {
- page_pool_recycle_direct(rx_q->page_pool,
- virt_to_head_page(ctx.xdp.data));
- buf->page = NULL;
+ buf->page = NULL;
+ } else if (buf1_len) {
+ if (!stmmac_build_xdp_frags(priv, rx_q, buf1_len,
+ buf->page,
+ buf->page_offset,
+ dma_dir, &ctx.xdp)) {
+ if (!error)
rx_dropped++;
- goto next;
- } else if (xdp_res & (STMMAC_XDP_TX |
- STMMAC_XDP_REDIRECT)) {
- xdp_status |= xdp_res;
- buf->page = NULL;
- goto next;
- }
- }
- }
-
- if (!skb) {
- unsigned int metasize;
-
- /* XDP program may expand or reduce tail */
- buf1_len = ctx.xdp.data_end - ctx.xdp.data;
-
- skb = napi_build_skb(page_address(buf->page),
- rx_q->napi_skb_frag_size);
- if (!skb) {
- page_pool_recycle_direct(rx_q->page_pool,
- buf->page);
- buf->page = NULL;
- rx_dropped++;
error = 1;
- goto drain_data;
}
-
- /* XDP program may adjust header */
- skb_reserve(skb,
- ctx.xdp.data - ctx.xdp.data_hard_start);
- skb_put(skb, buf1_len);
- skb_mark_for_recycle(skb);
-
- metasize = ctx.xdp.data - ctx.xdp.data_meta;
- if (metasize)
- skb_metadata_set(skb, metasize);
- buf->page = NULL;
- } else if (buf1_len) {
- dma_sync_single_for_cpu(priv->device, buf->addr,
- buf1_len, dma_dir);
- skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
- buf->page, buf->page_offset, buf1_len,
- priv->dma_conf.dma_buf_sz);
buf->page = NULL;
}
if (buf2_len) {
- dma_sync_single_for_cpu(priv->device, buf->sec_addr,
- buf2_len, dma_dir);
- skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
- buf->sec_page, 0, buf2_len,
- priv->dma_conf.dma_buf_sz);
+ if (!stmmac_build_xdp_frags(priv, rx_q, buf2_len,
+ buf->sec_page, 0,
+ dma_dir, &ctx.xdp)) {
+ if (!error)
+ rx_dropped++;
+ error = 1;
+ }
buf->sec_page = NULL;
}
+ n_descs++;
-drain_data:
if (likely(status & rx_not_ls))
goto read_again;
- if (!skb)
- goto next;
- /* Got entire packet into SKB. Finish it. */
+ /* ACS is disabled; strip manually. */
+ len -= ETH_FCS_LEN;
+ if (xdp_buff_shrink_tail(&ctx.xdp, ETH_FCS_LEN)) {
+ if (!error)
+ rx_dropped++;
+ error = 1;
+ }
- /* Remove FCS if needed */
- if (!fcs_stripped && pskb_trim(skb, len)) {
- dev_kfree_skb_any(skb);
- rx_dropped++;
+ if (unlikely(error))
+ goto error_free_frag;
+
+ ctx.desc = p;
+ ctx.ndesc = np;
+
+ skb = stmmac_xdp_run_prog(priv, &ctx.xdp);
+ /* For Not XDP_PASS verdict */
+ if (IS_ERR(skb)) {
+ unsigned int xdp_res = -PTR_ERR(skb);
+
+ if (xdp_res & STMMAC_XDP_CONSUMED) {
+ __xdp_return_buff(&ctx.xdp, true);
+ rx_dropped++;
+ } else if (xdp_res & (STMMAC_XDP_TX |
+ STMMAC_XDP_REDIRECT)) {
+ xdp_status |= xdp_res;
+ }
goto next;
}
+ skb = xdp_build_skb_from_buff(&ctx.xdp);
+ if (!skb) {
+ rx_dropped++;
+ goto error_free_frag;
+ }
+
+ /* Got entire packet into SKB. Finish it. */
stmmac_get_rx_hwtstamp(priv, p, np, skb);
if (priv->hw->hw_vlan_en) {
/* MAC level stripping. */
stmmac_rx_hw_vlan(priv, priv->hw, p, skb);
- } else if (stmmac_rx_vlan(priv->dev, skb)) {
- dev_kfree_skb_any(skb);
- rx_dropped++;
- goto next;
}
- skb->protocol = eth_type_trans(skb, priv->dev);
-
- if (unlikely(!coe) || !stmmac_has_ip_ethertype(skb) ||
+ if (unlikely(!coe) ||
+ !stmmac_has_ip_ethertype(priv, skb, false) ||
(status & csum_none))
skb_checksum_none_assert(skb);
else
@@ -6159,21 +6104,28 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
if (!stmmac_get_rx_hash(priv, p, &hash, &hash_type))
skb_set_hash(skb, hash, hash_type);
- skb_record_rx_queue(skb, queue);
napi_gro_receive(&ch->rx_napi, skb);
rx_packets++;
rx_bytes += len;
next:
in_progress = false;
- skb = NULL;
+ n_descs = 0;
+ count++;
+ continue;
+error_free_frag:
+ if (n_descs)
+ __xdp_return_buff(&ctx.xdp, true);
+ in_progress = false;
+ n_descs = 0;
count++;
}
- if (in_progress || skb) {
- rx_q->state_saved = true;
- rx_q->state.skb = skb;
+ if (in_progress || n_descs) {
+ rx_q->state.xdp = ctx.xdp;
+ rx_q->state.n_descs = n_descs;
rx_q->state.error = error;
rx_q->state.len = len;
+ rx_q->state_saved = true;
}
stmmac_finalize_xdp_rx(priv, xdp_status);
@@ -6429,7 +6381,7 @@ static netdev_features_t stmmac_fix_features(struct net_device *dev,
if (priv->plat->bugged_jumbo && (dev->mtu > ETH_DATA_LEN))
features &= ~NETIF_F_CSUM_MASK;
- if (priv->plat->core_type == DWMAC_CORE_XGMAC) {
+ if (stmmac_rx_8021ad_offload(priv)) {
if (features & NETIF_F_HW_VLAN_CTAG_RX)
features |= NETIF_F_HW_VLAN_STAG_RX;
else
@@ -6462,7 +6414,7 @@ static int stmmac_set_features(struct net_device *netdev,
stmmac_enable_sph(priv, priv->ioaddr, sph_en, chan);
}
- if (features & NETIF_F_HW_VLAN_CTAG_RX)
+ if (features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX))
priv->hw->hw_vlan_en = true;
else
priv->hw->hw_vlan_en = false;
@@ -8275,15 +8227,17 @@ static int __stmmac_dvr_probe(struct device *device,
ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA;
ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
#ifdef STMMAC_VLAN_TAG_USED
- /* Both mac100 and gmac support receive VLAN tag detection */
- ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
- if (priv->plat->core_type == DWMAC_CORE_XGMAC)
- ndev->features |= NETIF_F_HW_VLAN_STAG_RX;
-
- if (dwmac_is_xmac(priv->plat->core_type)) {
+ if (stmmac_rx_8021q_offload(priv)) {
+ ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
ndev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
priv->hw->hw_vlan_en = true;
}
+
+ if (stmmac_rx_8021ad_offload(priv)) {
+ ndev->features |= NETIF_F_HW_VLAN_STAG_RX;
+ ndev->hw_features |= NETIF_F_HW_VLAN_STAG_RX;
+ }
+
if (priv->dma_cap.vlhash) {
ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
if (priv->plat->core_type == DWMAC_CORE_XGMAC)
@@ -8544,9 +8498,12 @@ static void stmmac_reset_rx_queue(struct stmmac_priv *priv, u32 queue)
{
struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
- dev_kfree_skb_any(rx_q->state.skb);
- rx_q->state.skb = NULL;
+ if (rx_q->state.n_descs && !rx_q->xsk_pool) {
+ __xdp_return_buff(&rx_q->state.xdp, false);
+ rx_q->state.n_descs = 0;
+ }
rx_q->state_saved = false;
+
rx_q->cur_rx = 0;
rx_q->dirty_rx = 0;
}
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index df696e2c15284d..41a8493cf9dd3a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -1940,12 +1940,14 @@ void stmmac_selftest_run(struct net_device *dev,
return;
}
+ phylink_rx_clk_stop_block(priv->phylink);
for (i = 0; i < count; i++) {
ret = stmmac_selftests[i].fn(priv);
if (ret && (ret != -EOPNOTSUPP))
etest->flags |= ETH_TEST_FL_FAILED;
buf[i] = ret;
}
+ phylink_rx_clk_stop_unblock(priv->phylink);
stmmac_set_mac_loopback(priv, priv->ioaddr, false);
}
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 07231adfb5f829..f0946500c48747 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -388,6 +388,9 @@ struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf,
struct sk_buff *xdp_build_skb_from_frame(struct xdp_frame *xdpf,
struct net_device *dev);
struct xdp_frame *xdpf_clone(struct xdp_frame *xdpf);
+int xdp_buff_shrink_tail(struct xdp_buff *xdp, int offset);
+bool xdp_buff_shrink_data(struct xdp_buff *xdp, skb_frag_t *frag,
+ int shrink, bool tail);
static inline
void xdp_convert_frame_to_buff(const struct xdp_frame *frame,
@@ -454,7 +457,12 @@ void __xdp_return(netmem_ref netmem, enum xdp_mem_type mem_type,
bool napi_direct, struct xdp_buff *xdp);
void xdp_return_frame(struct xdp_frame *xdpf);
void xdp_return_frame_rx_napi(struct xdp_frame *xdpf);
-void xdp_return_buff(struct xdp_buff *xdp);
+void __xdp_return_buff(struct xdp_buff *xdp, bool napi_direct);
+static inline void xdp_return_buff(struct xdp_buff *xdp)
+{
+ __xdp_return_buff(xdp, true);
+}
+
void xdp_return_frame_bulk(struct xdp_frame *xdpf,
struct xdp_frame_bulk *bq);
diff --git a/net/core/filter.c b/net/core/filter.c
index f42ecfb5841f9c..cdbb54a10b0b88 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4438,88 +4438,16 @@ static int bpf_xdp_frags_increase_tail(struct xdp_buff *xdp, int offset)
return 0;
}
-static struct xdp_buff *bpf_xdp_shrink_data_zc(struct xdp_buff *xdp, int shrink,
- bool tail, bool release)
-{
- struct xdp_buff *zc_frag = tail ? xsk_buff_get_tail(xdp) :
- xsk_buff_get_head(xdp);
-
- if (release) {
- xsk_buff_del_frag(zc_frag);
- } else {
- if (tail)
- zc_frag->data_end -= shrink;
- else
- zc_frag->data += shrink;
- }
-
- return zc_frag;
-}
-
-static bool bpf_xdp_shrink_data(struct xdp_buff *xdp, skb_frag_t *frag,
- int shrink, bool tail)
-{
- enum xdp_mem_type mem_type = xdp->rxq->mem.type;
- bool release = skb_frag_size(frag) == shrink;
- netmem_ref netmem = skb_frag_netmem(frag);
- struct xdp_buff *zc_frag = NULL;
-
- if (mem_type == MEM_TYPE_XSK_BUFF_POOL) {
- netmem = 0;
- zc_frag = bpf_xdp_shrink_data_zc(xdp, shrink, tail, release);
- }
-
- if (release) {
- __xdp_return(netmem, mem_type, false, zc_frag);
- } else {
- if (!tail)
- skb_frag_off_add(frag, shrink);
- skb_frag_size_sub(frag, shrink);
- }
-
- return release;
-}
-
-static int bpf_xdp_frags_shrink_tail(struct xdp_buff *xdp, int offset)
-{
- struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
- int i, n_frags_free = 0, len_free = 0;
-
- if (unlikely(offset > (int)xdp_get_buff_len(xdp) - ETH_HLEN))
- return -EINVAL;
-
- for (i = sinfo->nr_frags - 1; i >= 0 && offset > 0; i--) {
- skb_frag_t *frag = &sinfo->frags[i];
- int shrink = min_t(int, offset, skb_frag_size(frag));
-
- len_free += shrink;
- offset -= shrink;
- if (bpf_xdp_shrink_data(xdp, frag, shrink, true))
- n_frags_free++;
- }
- sinfo->nr_frags -= n_frags_free;
- sinfo->xdp_frags_size -= len_free;
-
- if (unlikely(!sinfo->nr_frags)) {
- xdp_buff_clear_frags_flag(xdp);
- xdp_buff_clear_frag_pfmemalloc(xdp);
- xdp->data_end -= offset;
- }
-
- return 0;
-}
-
BPF_CALL_2(bpf_xdp_adjust_tail, struct xdp_buff *, xdp, int, offset)
{
void *data_hard_end = xdp_data_hard_end(xdp); /* use xdp->frame_sz */
void *data_end = xdp->data_end + offset;
- if (unlikely(xdp_buff_has_frags(xdp))) { /* non-linear xdp buff */
- if (offset < 0)
- return bpf_xdp_frags_shrink_tail(xdp, -offset);
+ if (offset < 0)
+ return xdp_buff_shrink_tail(xdp, -offset);
+ if (unlikely(xdp_buff_has_frags(xdp))) /* non-linear xdp buff */
return bpf_xdp_frags_increase_tail(xdp, offset);
- }
/* Notice that xdp_data_hard_end have reserved some tailroom */
if (unlikely(data_end > data_hard_end))
@@ -12840,7 +12768,7 @@ __bpf_kfunc int bpf_xdp_pull_data(struct xdp_md *x, u32 len)
xdp->data_end += shrink;
sinfo->xdp_frags_size -= shrink;
delta -= shrink;
- if (bpf_xdp_shrink_data(xdp, frag, shrink, false))
+ if (xdp_buff_shrink_data(xdp, frag, shrink, false))
n_frags_free++;
}
diff --git a/net/core/xdp.c b/net/core/xdp.c
index 1d679e8fd64937..f35ae7e118f567 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -546,7 +546,7 @@ void xdp_return_frag(netmem_ref netmem, const struct xdp_buff *xdp)
}
EXPORT_SYMBOL_GPL(xdp_return_frag);
-void xdp_return_buff(struct xdp_buff *xdp)
+void __xdp_return_buff(struct xdp_buff *xdp, bool napi_direct)
{
struct skb_shared_info *sinfo;
@@ -556,12 +556,13 @@ void xdp_return_buff(struct xdp_buff *xdp)
sinfo = xdp_get_shared_info_from_buff(xdp);
for (u32 i = 0; i < sinfo->nr_frags; i++)
__xdp_return(skb_frag_netmem(&sinfo->frags[i]),
- xdp->rxq->mem.type, true, xdp);
+ xdp->rxq->mem.type, napi_direct, xdp);
out:
- __xdp_return(virt_to_netmem(xdp->data), xdp->rxq->mem.type, true, xdp);
+ __xdp_return(virt_to_netmem(xdp->data), xdp->rxq->mem.type,
+ napi_direct, xdp);
}
-EXPORT_SYMBOL_GPL(xdp_return_buff);
+EXPORT_SYMBOL_GPL(__xdp_return_buff);
void xdp_attachment_setup(struct xdp_attachment_info *info,
struct netdev_bpf *bpf)
@@ -673,6 +674,95 @@ struct sk_buff *xdp_build_skb_from_buff(const struct xdp_buff *xdp)
}
EXPORT_SYMBOL_GPL(xdp_build_skb_from_buff);
+static struct xdp_buff *xdp_buff_shrink_data_zc(struct xdp_buff *xdp,
+ int shrink, bool tail,
+ bool release)
+{
+ struct xdp_buff *zc_frag = tail ? xsk_buff_get_tail(xdp) :
+ xsk_buff_get_head(xdp);
+
+ if (release) {
+ xsk_buff_del_frag(zc_frag);
+ } else {
+ if (tail)
+ zc_frag->data_end -= shrink;
+ else
+ zc_frag->data += shrink;
+ }
+
+ return zc_frag;
+}
+
+bool xdp_buff_shrink_data(struct xdp_buff *xdp, skb_frag_t *frag,
+ int shrink, bool tail)
+{
+ enum xdp_mem_type mem_type = xdp->rxq->mem.type;
+ bool release = skb_frag_size(frag) == shrink;
+ netmem_ref netmem = skb_frag_netmem(frag);
+ struct xdp_buff *zc_frag = NULL;
+
+ if (mem_type == MEM_TYPE_XSK_BUFF_POOL) {
+ netmem = 0;
+ zc_frag = xdp_buff_shrink_data_zc(xdp, shrink, tail, release);
+ }
+
+ if (release) {
+ __xdp_return(netmem, mem_type, false, zc_frag);
+ } else {
+ if (!tail)
+ skb_frag_off_add(frag, shrink);
+ skb_frag_size_sub(frag, shrink);
+ }
+
+ return release;
+}
+
+static int xdp_frags_shrink_tail(struct xdp_buff *xdp, int offset)
+{
+ struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
+ int i, n_frags_free = 0, len_free = 0;
+
+ if (unlikely(offset > (int)xdp_get_buff_len(xdp) - ETH_HLEN))
+ return -EINVAL;
+
+ for (i = sinfo->nr_frags - 1; i >= 0 && offset > 0; i--) {
+ skb_frag_t *frag = &sinfo->frags[i];
+ int shrink = min_t(int, offset, skb_frag_size(frag));
+
+ len_free += shrink;
+ offset -= shrink;
+ if (xdp_buff_shrink_data(xdp, frag, shrink, true))
+ n_frags_free++;
+ }
+ sinfo->nr_frags -= n_frags_free;
+ sinfo->xdp_frags_size -= len_free;
+
+ if (unlikely(!sinfo->nr_frags)) {
+ xdp_buff_clear_frags_flag(xdp);
+ xdp_buff_clear_frag_pfmemalloc(xdp);
+ xdp->data_end -= offset;
+ }
+
+ return 0;
+}
+
+int xdp_buff_shrink_tail(struct xdp_buff *xdp, int offset)
+{
+ if (unlikely(offset < 0))
+ return -EINVAL;
+
+ if (unlikely(xdp_buff_has_frags(xdp))) /* non-linear xdp buff */
+ return xdp_frags_shrink_tail(xdp, offset);
+
+ if (unlikely(offset > xdp->data_end - xdp->data - ETH_HLEN))
+ return -EINVAL;
+
+ xdp->data_end = xdp->data_end - offset;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(xdp_buff_shrink_tail);
+
/**
* xdp_copy_frags_from_zc - copy frags from XSk buff to skb
* @skb: skb to copy frags to
|
| 3/2 | 2026/12/01 04:23 | llm | patch-evaluator |
0mModel:gemini-4-hydrogen Args: null Results: null Tokens: input: 14608 output: 198 thoughts: 715 Thoughts: **Analyzing the XDP and stmmac Patch** Okay, let's dive into this diff. First, I need to understand the scope of these changes. It looks like we're touching `drivers/net/ethernet/stmicro/stmmac/` – specifically `stmmac.h`, `stmmac_main.c`, and `stmmac_selftests.c`, all NIC driver code. I'm wondering if `stmmac` is emulated in QEMU, or if this change is on reachable hardware. Probably not in a standard x86_64 QEMU setup without a PCI or platform device, but let's double-check. I'll make a mental note to check both `stmmac` *and* the `net/core` files: `filter.c`, `xdp.c`, and `include/net/xdp.h`. Now, focusing on the core changes, the modifications to `net/core/filter.c` and `net/core/xdp.c` are immediately intriguing. Specifically, `bpf_xdp_adjust_tail` now has an unconditional call to `xdp_buff_shrink_tail(xdp, -offset)` when `offset < 0`. This is a significant shift in behavior. Previously, the code handled non-linear XDP buffers differently with `bpf_xdp_frags_shrink_tail` if `offset < 0`. It looks like it is changed to unconditionally call `xdp_buff_shrink_tail` when `offset < 0`. The previous logic of `bpf_xdp_adjust_tail` checked for non-linear buffers and handled `offset < 0` via `bpf_xdp_frags_shrink_tail` and `offset > 0` through `bpf_xdp_frags_increase_tail`. There were checks for `data_end` exceeding `data_hard_end` and `data_end` being less than `xdp->data + ETH_HLEN`. This unconditional call raises a flag. If `offset` is `INT_MIN` in `bpf_xdp_adjust_tail`, then `-INT_MIN` would be UB or negative, but `xdp_buff_shrink_tail` has the check `if (unlikely(offset < 0))`. For a linear buffer, `xdp_buff_shrink_tail` checks `if (unlikely(offset > xdp->data_end - xdp->data - ETH_HLEN)) return -EINVAL;`. I need to fully understand all possible edge cases and error handling around those shrink operations, specifically looking at potential integer overflows and unexpected behavior, especially when dealing with negative offsets. I need to re-examine all the involved functions: `xdp_buff_shrink_data`, `xdp_frags_shrink_tail`, `xdp_buff_shrink_data_zc`, `__xdp_return_buff`, and `bpf_xdp_pull_data`. To get a clearer picture, I'm going to look at `net/core/filter.c` around lines 4440 and 12770, `net/core/xdp.c` around lines 545 and 675, and I'll do a quick `Kconfig` search for `stmmac` just in case there's something relevant there. I'll get some tools running in parallel to check these things. |
| 4/2 | 2026/12/01 04:23 | tool | read-file |
0mArgs:{
"File": "net/core/filter.c",
"FirstLine": 4430,
"LineCount": 60
}Results: {
"Contents": "4430:\t\t\treturn -EINVAL;\n4431:\t\n4432:\t\tmemset(skb_frag_address(frag) + skb_frag_size(frag), 0, offset);\n4433:\t\tskb_frag_size_add(frag, offset);\n4434:\t\tsinfo-\u003exdp_frags_size += offset;\n4435:\t\tif (rxq-\u003emem.type == MEM_TYPE_XSK_BUFF_POOL)\n4436:\t\t\txsk_buff_get_tail(xdp)-\u003edata_end += offset;\n4437:\t\n4438:\t\treturn 0;\n4439:\t}\n4440:\t\n4441:\tBPF_CALL_2(bpf_xdp_adjust_tail, struct xdp_buff *, xdp, int, offset)\n4442:\t{\n4443:\t\tvoid *data_hard_end = xdp_data_hard_end(xdp); /* use xdp-\u003eframe_sz */\n4444:\t\tvoid *data_end = xdp-\u003edata_end + offset;\n4445:\t\n4446:\t\tif (offset \u003c 0)\n4447:\t\t\treturn xdp_buff_shrink_tail(xdp, -offset);\n4448:\t\n4449:\t\tif (unlikely(xdp_buff_has_frags(xdp))) /* non-linear xdp buff */\n4450:\t\t\treturn bpf_xdp_frags_increase_tail(xdp, offset);\n4451:\t\n4452:\t\t/* Notice that xdp_data_hard_end have reserved some tailroom */\n4453:\t\tif (unlikely(data_end \u003e data_hard_end))\n4454:\t\t\treturn -EINVAL;\n4455:\t\n4456:\t\tif (unlikely(data_end \u003c xdp-\u003edata + ETH_HLEN))\n4457:\t\t\treturn -EINVAL;\n4458:\t\n4459:\t\t/* Clear memory area on grow, can contain uninit kernel memory */\n4460:\t\tif (offset \u003e 0)\n4461:\t\t\tmemset(xdp-\u003edata_end, 0, offset);\n4462:\t\n4463:\t\txdp-\u003edata_end = data_end;\n4464:\t\n4465:\t\treturn 0;\n4466:\t}\n4467:\t\n4468:\tstatic const struct bpf_func_proto bpf_xdp_adjust_tail_proto = {\n4469:\t\t.func\t\t= bpf_xdp_adjust_tail,\n4470:\t\t.gpl_only\t= false,\n4471:\t\t.ret_type\t= RET_INTEGER,\n4472:\t\t.arg1_type\t= ARG_PTR_TO_CTX,\n4473:\t\t.arg2_type\t= ARG_ANYTHING,\n4474:\t};\n4475:\t\n4476:\tBPF_CALL_2(bpf_xdp_adjust_meta, struct xdp_buff *, xdp, int, offset)\n4477:\t{\n4478:\t\tvoid *xdp_frame_end = xdp-\u003edata_hard_start + sizeof(struct xdp_frame);\n4479:\t\tvoid *meta = xdp-\u003edata_meta + offset;\n4480:\t\tunsigned long metalen = xdp-\u003edata - meta;\n4481:\t\n4482:\t\tif (xdp_data_meta_unsupported(xdp))\n4483:\t\t\treturn -ENOTSUPP;\n4484:\t\tif (unlikely(meta \u003c xdp_frame_end ||\n4485:\t\t\t meta \u003e xdp-\u003edata))\n4486:\t\t\treturn -EINVAL;\n4487:\t\tif (unlikely(xdp_metalen_invalid(metalen)))\n4488:\t\t\treturn -EACCES;\n4489:\t\n"
} |
| 5/2 | 2026/12/01 04:23 | tool | read-file |
0mArgs:{
"File": "net/core/filter.c",
"FirstLine": 12740,
"LineCount": 60
}Results: {
"Contents": "12740:\t\n12741:\t\tif (unlikely(len \u003e xdp_get_buff_len(xdp)))\n12742:\t\t\treturn -EINVAL;\n12743:\t\n12744:\t\tstart = xdp_data_meta_unsupported(xdp) ? xdp-\u003edata : xdp-\u003edata_meta;\n12745:\t\n12746:\t\theadroom = start - xdp-\u003edata_hard_start - sizeof(struct xdp_frame);\n12747:\t\ttailroom = data_hard_end - xdp-\u003edata_end;\n12748:\t\n12749:\t\tdelta = len - data_len;\n12750:\t\tif (unlikely(delta \u003e tailroom + headroom))\n12751:\t\t\treturn -EINVAL;\n12752:\t\n12753:\t\tshift = delta - tailroom;\n12754:\t\tif (shift \u003e 0) {\n12755:\t\t\tmemmove(start - shift, start, xdp-\u003edata_end - start);\n12756:\t\n12757:\t\t\txdp-\u003edata_meta -= shift;\n12758:\t\t\txdp-\u003edata -= shift;\n12759:\t\t\txdp-\u003edata_end -= shift;\n12760:\t\t}\n12761:\t\n12762:\t\tfor (i = 0; i \u003c sinfo-\u003enr_frags \u0026\u0026 delta; i++) {\n12763:\t\t\tskb_frag_t *frag = \u0026sinfo-\u003efrags[i];\n12764:\t\t\tu32 shrink = min_t(u32, delta, skb_frag_size(frag));\n12765:\t\n12766:\t\t\tmemcpy(xdp-\u003edata_end, skb_frag_address(frag), shrink);\n12767:\t\n12768:\t\t\txdp-\u003edata_end += shrink;\n12769:\t\t\tsinfo-\u003exdp_frags_size -= shrink;\n12770:\t\t\tdelta -= shrink;\n12771:\t\t\tif (xdp_buff_shrink_data(xdp, frag, shrink, false))\n12772:\t\t\t\tn_frags_free++;\n12773:\t\t}\n12774:\t\n12775:\t\tif (unlikely(n_frags_free)) {\n12776:\t\t\tmemmove(sinfo-\u003efrags, sinfo-\u003efrags + n_frags_free,\n12777:\t\t\t\t(sinfo-\u003enr_frags - n_frags_free) * sizeof(skb_frag_t));\n12778:\t\n12779:\t\t\tsinfo-\u003enr_frags -= n_frags_free;\n12780:\t\n12781:\t\t\tif (!sinfo-\u003enr_frags) {\n12782:\t\t\t\txdp_buff_clear_frags_flag(xdp);\n12783:\t\t\t\txdp_buff_clear_frag_pfmemalloc(xdp);\n12784:\t\t\t}\n12785:\t\t}\n12786:\t\n12787:\t\treturn 0;\n12788:\t}\n12789:\t\n12790:\t/**\n12791:\t * bpf_icmp_send - Send an ICMP control message\n12792:\t * @skb_ctx: Packet that triggered the control message\n12793:\t * @type: ICMP type (only ICMP_DEST_UNREACH/ICMPV6_DEST_UNREACH supported)\n12794:\t * @code: ICMP code (0-15 except ICMP_FRAG_NEEDED for IPv4, 0-6 for IPv6)\n12795:\t *\n12796:\t * Sends an ICMP control message in response to the packet. The original packet\n12797:\t * is cloned before sending the ICMP message, so the BPF program can still let\n12798:\t * the packet pass if desired.\n12799:\t *\n"
} |
| 6/2 | 2026/12/01 04:23 | tool | read-file |
0mArgs:{
"File": "net/core/xdp.c",
"FirstLine": 540,
"LineCount": 45
}Results: {
"Contents": " 540:\t * @netmem: network memory reference to release\n 541:\t * @xdp: \u0026xdp_buff to release the frag for\n 542:\t */\n 543:\tvoid xdp_return_frag(netmem_ref netmem, const struct xdp_buff *xdp)\n 544:\t{\n 545:\t\t__xdp_return(netmem, xdp-\u003erxq-\u003emem.type, true, NULL);\n 546:\t}\n 547:\tEXPORT_SYMBOL_GPL(xdp_return_frag);\n 548:\t\n 549:\tvoid __xdp_return_buff(struct xdp_buff *xdp, bool napi_direct)\n 550:\t{\n 551:\t\tstruct skb_shared_info *sinfo;\n 552:\t\n 553:\t\tif (likely(!xdp_buff_has_frags(xdp)))\n 554:\t\t\tgoto out;\n 555:\t\n 556:\t\tsinfo = xdp_get_shared_info_from_buff(xdp);\n 557:\t\tfor (u32 i = 0; i \u003c sinfo-\u003enr_frags; i++)\n 558:\t\t\t__xdp_return(skb_frag_netmem(\u0026sinfo-\u003efrags[i]),\n 559:\t\t\t\t xdp-\u003erxq-\u003emem.type, napi_direct, xdp);\n 560:\t\n 561:\tout:\n 562:\t\t__xdp_return(virt_to_netmem(xdp-\u003edata), xdp-\u003erxq-\u003emem.type,\n 563:\t\t\t napi_direct, xdp);\n 564:\t}\n 565:\tEXPORT_SYMBOL_GPL(__xdp_return_buff);\n 566:\t\n 567:\tvoid xdp_attachment_setup(struct xdp_attachment_info *info,\n 568:\t\t\t\t struct netdev_bpf *bpf)\n 569:\t{\n 570:\t\tif (info-\u003eprog)\n 571:\t\t\tbpf_prog_put(info-\u003eprog);\n 572:\t\tinfo-\u003eprog = bpf-\u003eprog;\n 573:\t\tinfo-\u003eflags = bpf-\u003eflags;\n 574:\t}\n 575:\tEXPORT_SYMBOL_GPL(xdp_attachment_setup);\n 576:\t\n 577:\tstruct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp)\n 578:\t{\n 579:\t\tunsigned int metasize, totsize;\n 580:\t\tvoid *addr, *data_to_copy;\n 581:\t\tstruct xdp_frame *xdpf;\n 582:\t\tstruct page *page;\n 583:\t\n 584:\t\t/* Clone into a MEM_TYPE_PAGE_ORDER0 xdp_frame. */\n"
} |
| 7/2 | 2026/12/01 04:23 | tool | read-file |
0mArgs:{
"File": "net/core/xdp.c",
"FirstLine": 670,
"LineCount": 100
}Results: {
"Contents": " 670:\t\n 671:\t\tskb-\u003eprotocol = eth_type_trans(skb, rxq-\u003edev);\n 672:\t\n 673:\t\treturn skb;\n 674:\t}\n 675:\tEXPORT_SYMBOL_GPL(xdp_build_skb_from_buff);\n 676:\t\n 677:\tstatic struct xdp_buff *xdp_buff_shrink_data_zc(struct xdp_buff *xdp,\n 678:\t\t\t\t\t\t\tint shrink, bool tail,\n 679:\t\t\t\t\t\t\tbool release)\n 680:\t{\n 681:\t\tstruct xdp_buff *zc_frag = tail ? xsk_buff_get_tail(xdp) :\n 682:\t\t\t\t\t\t xsk_buff_get_head(xdp);\n 683:\t\n 684:\t\tif (release) {\n 685:\t\t\txsk_buff_del_frag(zc_frag);\n 686:\t\t} else {\n 687:\t\t\tif (tail)\n 688:\t\t\t\tzc_frag-\u003edata_end -= shrink;\n 689:\t\t\telse\n 690:\t\t\t\tzc_frag-\u003edata += shrink;\n 691:\t\t}\n 692:\t\n 693:\t\treturn zc_frag;\n 694:\t}\n 695:\t\n 696:\tbool xdp_buff_shrink_data(struct xdp_buff *xdp, skb_frag_t *frag,\n 697:\t\t\t\t int shrink, bool tail)\n 698:\t{\n 699:\t\tenum xdp_mem_type mem_type = xdp-\u003erxq-\u003emem.type;\n 700:\t\tbool release = skb_frag_size(frag) == shrink;\n 701:\t\tnetmem_ref netmem = skb_frag_netmem(frag);\n 702:\t\tstruct xdp_buff *zc_frag = NULL;\n 703:\t\n 704:\t\tif (mem_type == MEM_TYPE_XSK_BUFF_POOL) {\n 705:\t\t\tnetmem = 0;\n 706:\t\t\tzc_frag = xdp_buff_shrink_data_zc(xdp, shrink, tail, release);\n 707:\t\t}\n 708:\t\n 709:\t\tif (release) {\n 710:\t\t\t__xdp_return(netmem, mem_type, false, zc_frag);\n 711:\t\t} else {\n 712:\t\t\tif (!tail)\n 713:\t\t\t\tskb_frag_off_add(frag, shrink);\n 714:\t\t\tskb_frag_size_sub(frag, shrink);\n 715:\t\t}\n 716:\t\n 717:\t\treturn release;\n 718:\t}\n 719:\t\n 720:\tstatic int xdp_frags_shrink_tail(struct xdp_buff *xdp, int offset)\n 721:\t{\n 722:\t\tstruct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);\n 723:\t\tint i, n_frags_free = 0, len_free = 0;\n 724:\t\n 725:\t\tif (unlikely(offset \u003e (int)xdp_get_buff_len(xdp) - ETH_HLEN))\n 726:\t\t\treturn -EINVAL;\n 727:\t\n 728:\t\tfor (i = sinfo-\u003enr_frags - 1; i \u003e= 0 \u0026\u0026 offset \u003e 0; i--) {\n 729:\t\t\tskb_frag_t *frag = \u0026sinfo-\u003efrags[i];\n 730:\t\t\tint shrink = min_t(int, offset, skb_frag_size(frag));\n 731:\t\n 732:\t\t\tlen_free += shrink;\n 733:\t\t\toffset -= shrink;\n 734:\t\t\tif (xdp_buff_shrink_data(xdp, frag, shrink, true))\n 735:\t\t\t\tn_frags_free++;\n 736:\t\t}\n 737:\t\tsinfo-\u003enr_frags -= n_frags_free;\n 738:\t\tsinfo-\u003exdp_frags_size -= len_free;\n 739:\t\n 740:\t\tif (unlikely(!sinfo-\u003enr_frags)) {\n 741:\t\t\txdp_buff_clear_frags_flag(xdp);\n 742:\t\t\txdp_buff_clear_frag_pfmemalloc(xdp);\n 743:\t\t\txdp-\u003edata_end -= offset;\n 744:\t\t}\n 745:\t\n 746:\t\treturn 0;\n 747:\t}\n 748:\t\n 749:\tint xdp_buff_shrink_tail(struct xdp_buff *xdp, int offset)\n 750:\t{\n 751:\t\tif (unlikely(offset \u003c 0))\n 752:\t\t\treturn -EINVAL;\n 753:\t\n 754:\t\tif (unlikely(xdp_buff_has_frags(xdp))) /* non-linear xdp buff */\n 755:\t\t\treturn xdp_frags_shrink_tail(xdp, offset);\n 756:\t\n 757:\t\tif (unlikely(offset \u003e xdp-\u003edata_end - xdp-\u003edata - ETH_HLEN))\n 758:\t\t\treturn -EINVAL;\n 759:\t\n 760:\t\txdp-\u003edata_end = xdp-\u003edata_end - offset;\n 761:\t\n 762:\t\treturn 0;\n 763:\t}\n 764:\tEXPORT_SYMBOL_GPL(xdp_buff_shrink_tail);\n 765:\t\n 766:\t/**\n 767:\t * xdp_copy_frags_from_zc - copy frags from XSk buff to skb\n 768:\t * @skb: skb to copy frags to\n 769:\t * @xdp: XSk \u0026xdp_buff from which the frags will be copied\n"
} |
| 8/2 | 2026/12/01 04:23 | tool | read-file |
0mArgs:{
"File": "drivers/net/ethernet/stmicro/stmmac/Kconfig",
"FirstLine": 1,
"LineCount": 50
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\tconfig STMMAC_ETH\n 3:\t\ttristate \"STMicroelectronics Multi-Gigabit Ethernet driver\"\n 4:\t\tdepends on HAS_IOMEM \u0026\u0026 HAS_DMA\n 5:\t\tdepends on PTP_1588_CLOCK_OPTIONAL\n 6:\t\tdepends on ETHTOOL_NETLINK\n 7:\t\tselect MII\n 8:\t\tselect PCS_XPCS\n 9:\t\tselect PAGE_POOL\n 10:\t\tselect PHYLINK\n 11:\t\tselect CRC32\n 12:\t\tselect RESET_CONTROLLER\n 13:\t\tselect NET_DEVLINK\n 14:\t\thelp\n 15:\t\t This is the driver for the Ethernet IPs built around a\n 16:\t\t Synopsys IP Core.\n 17:\t\n 18:\tif STMMAC_ETH\n 19:\t\n 20:\tconfig STMMAC_SELFTESTS\n 21:\t\tbool \"Support for STMMAC Selftests\"\n 22:\t\tdepends on INET\n 23:\t\tdefault n\n 24:\t\thelp\n 25:\t\t This adds support for STMMAC Selftests using ethtool. Enable this\n 26:\t\t feature if you are facing problems with your HW and submit the test\n 27:\t\t results to the netdev Mailing List.\n 28:\t\n 29:\tconfig STMMAC_PLATFORM\n 30:\t\ttristate \"STMMAC Platform bus support\"\n 31:\t\tselect MFD_SYSCON\n 32:\t\tdefault y\n 33:\t\thelp\n 34:\t\t This selects the platform specific bus support for the stmmac driver.\n 35:\t\t This is the driver used on several SoCs:\n 36:\t\t STi, Allwinner, Amlogic Meson, Altera SOCFPGA.\n 37:\t\n 38:\t\t If you have a controller with this interface, say Y or M here.\n 39:\t\n 40:\t\t If unsure, say N.\n 41:\t\n 42:\tif STMMAC_PLATFORM\n 43:\t\n 44:\tconfig DWMAC_DWC_QOS_ETH\n 45:\t\ttristate \"Support for snps,dwc-qos-ethernet.txt DT binding.\"\n 46:\t\tselect CRC32\n 47:\t\tselect MII\n 48:\t\tdepends on OF \u0026\u0026 HAS_DMA\n 49:\t\thelp\n 50:\t\t Support for chips using the snps,dwc-qos-ethernet.txt DT binding.\n"
} |
| 9/2 | 2026/12/01 04:23 | llm | patch-evaluator |
0mModel:gemini-4-hydrogen Args: null Results: null Tokens: input: 20584 output: 86 thoughts: 181 Thoughts: **XDP/BPF Function Call Analysis for Potential Fuzzing Targets** Okay, let's dive in. My initial thought is to identify potential fuzzing targets related to XDP/BPF. I need to be thorough. I'll start by checking for any additional calls to key functions like `xdp_return_buff`, `xdp_buff_shrink_tail`, `xdp_buff_shrink_data`, `bpf_xdp_adjust_tail`, and `bpf_xdp_pull_data`. It's possible I'm missing something if there are indirect calls. I'm also going to quickly rule out `stmmac` having a QEMU virtual device. I'm pretty sure that's a non-issue given its nature as Synopsys DesignWare MAC for embedded SoCs and PCI devices, but better safe than sorry. I'll take a quick peek at `stmmac_pci.c` just to be certain. Regardless, the core XDP/BPF changes we've seen already make this WorthFuzzing=true! Now, to solidify my findings I'll execute a grep for `xdp_return_buff` and then go through a more focused investigation of the callers of `bpf_xdp_adjust_tail`, `bpf_xdp_pull_data`, `__xdp_return_buff`, and `xdp_buff_shrink_tail`. This should paint a clear picture of the attack surface, and make sure that this is the best possible use of my time. |
| 10/2 | 2026/12/01 04:23 | tool | grepper |
0mArgs:{
"Expression": "xdp_return_buff|xdp_buff_shrink_tail|xdp_buff_shrink_data"
}Results: {
"Output": "\nFull output is too long, showing 200 out of 250 lines.\nUse more precise expression or PathPrefixes if possible.\n\nNumber of matching lines per file (14 files in total):\ndrivers/net/ethernet/intel/ice/ice_txrx.c:2\ndrivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c:1\ndrivers/net/ethernet/intel/libeth/tx.c:1\ndrivers/net/ethernet/intel/libeth/xdp.c:12\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:5\ndrivers/net/veth.c:1\ndrivers/net/xen-netfront.c:1\ninclude/net/libeth/tx.h:1\ninclude/net/libeth/xdp.h:11\ninclude/net/xdp.h:5\nnet/bpf/test_run.c:3\nnet/core/filter.c:2\nnet/core/xdp.c:8\nnet/xdp/xsk.c:1\n\ndrivers/net/ethernet/intel/ice/ice_txrx.c=651=ice_run_xdp(struct ice_rx_ring *rx_ring, struct libeth_xdp_buff *xdp,\n--\ndrivers/net/ethernet/intel/ice/ice_txrx.c-688-\tcase XDP_DROP:\ndrivers/net/ethernet/intel/ice/ice_txrx.c:689:\t\tlibeth_xdp_return_buff(xdp);\ndrivers/net/ethernet/intel/ice/ice_txrx.c-690-\t\tret = ICE_XDP_CONSUMED;\n--\ndrivers/net/ethernet/intel/ice/ice_txrx.c=945=static int ice_clean_rx_irq(struct ice_rx_ring *rx_ring, int budget)\n--\ndrivers/net/ethernet/intel/ice/ice_txrx.c-1047-\t\tif (!skb) {\ndrivers/net/ethernet/intel/ice/ice_txrx.c:1048:\t\t\tlibeth_xdp_return_buff_slow(xdp);\ndrivers/net/ethernet/intel/ice/ice_txrx.c-1049-\t\t\tice_stats_inc(rx_ring-\u003ering_stats, rx_buf_failed);\n--\ndrivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c=1034=static int idpf_rx_singleq_clean(struct idpf_rx_queue *rx_q, int budget)\n--\ndrivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c-1085-\t\t\t\t\t\t\t IDPF_RXD_ERR_S))) {\ndrivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c:1086:\t\t\tlibeth_xdp_return_buff_slow(xdp);\ndrivers/net/ethernet/intel/idpf/idpf_singleq_txrx.c-1087-\t\t\tcontinue;\n--\ndrivers/net/ethernet/intel/libeth/tx.c-11-\ndrivers/net/ethernet/intel/libeth/tx.c:12:DEFINE_STATIC_CALL_NULL(bulk, libeth_xdp_return_buff_bulk);\ndrivers/net/ethernet/intel/libeth/tx.c-13-DEFINE_STATIC_CALL_NULL(xsk, libeth_xsk_buff_free_slow);\n--\ndrivers/net/ethernet/intel/libeth/xdp.c=226=void __libeth_xdp_return_stash(struct libeth_xdp_buff_stash *stash)\n--\ndrivers/net/ethernet/intel/libeth/xdp.c-230-\tlibeth_xdp_load_stash(xdp, stash);\ndrivers/net/ethernet/intel/libeth/xdp.c:231:\tlibeth_xdp_return_buff_slow(xdp);\ndrivers/net/ethernet/intel/libeth/xdp.c-232-\n--\ndrivers/net/ethernet/intel/libeth/xdp.c=235=EXPORT_SYMBOL_GPL(__libeth_xdp_return_stash);\n--\ndrivers/net/ethernet/intel/libeth/xdp.c-237-/**\ndrivers/net/ethernet/intel/libeth/xdp.c:238: * libeth_xdp_return_buff_slow - free \u0026libeth_xdp_buff\ndrivers/net/ethernet/intel/libeth/xdp.c-239- * @xdp: buffer to free/return\ndrivers/net/ethernet/intel/libeth/xdp.c-240- *\ndrivers/net/ethernet/intel/libeth/xdp.c:241: * Slowpath version of libeth_xdp_return_buff() to be called on exceptions,\ndrivers/net/ethernet/intel/libeth/xdp.c-242- * queue clean-ups etc., without unwanted inlining.\ndrivers/net/ethernet/intel/libeth/xdp.c-243- */\ndrivers/net/ethernet/intel/libeth/xdp.c:244:void __cold libeth_xdp_return_buff_slow(struct libeth_xdp_buff *xdp)\ndrivers/net/ethernet/intel/libeth/xdp.c-245-{\ndrivers/net/ethernet/intel/libeth/xdp.c:246:\t__libeth_xdp_return_buff(xdp, false);\ndrivers/net/ethernet/intel/libeth/xdp.c-247-}\ndrivers/net/ethernet/intel/libeth/xdp.c:248:EXPORT_SYMBOL_GPL(libeth_xdp_return_buff_slow);\ndrivers/net/ethernet/intel/libeth/xdp.c-249-\n--\ndrivers/net/ethernet/intel/libeth/xdp.c=261=bool libeth_xdp_buff_add_frag(struct libeth_xdp_buff *xdp,\n--\ndrivers/net/ethernet/intel/libeth/xdp.c-275-\tlibeth_rx_recycle_slow(netmem);\ndrivers/net/ethernet/intel/libeth/xdp.c:276:\tlibeth_xdp_return_buff_slow(xdp);\ndrivers/net/ethernet/intel/libeth/xdp.c-277-\n--\ndrivers/net/ethernet/intel/libeth/xdp.c=295=u32 __cold libeth_xdp_prog_exception(const struct libeth_xdp_tx_bulk *bq,\n--\ndrivers/net/ethernet/intel/libeth/xdp.c-306-\ndrivers/net/ethernet/intel/libeth/xdp.c:307:\tlibeth_xdp_return_buff_slow(xdp);\ndrivers/net/ethernet/intel/libeth/xdp.c-308-\n--\ndrivers/net/ethernet/intel/libeth/xdp.c=315=static void libeth_xdp_put_netmem_bulk(netmem_ref netmem,\n--\ndrivers/net/ethernet/intel/libeth/xdp.c-324-/**\ndrivers/net/ethernet/intel/libeth/xdp.c:325: * libeth_xdp_return_buff_bulk - free \u0026xdp_buff as part of a bulk\ndrivers/net/ethernet/intel/libeth/xdp.c-326- * @sinfo: shared info corresponding to the buffer\n--\ndrivers/net/ethernet/intel/libeth/xdp.c-333- */\ndrivers/net/ethernet/intel/libeth/xdp.c:334:void libeth_xdp_return_buff_bulk(const struct skb_shared_info *sinfo,\ndrivers/net/ethernet/intel/libeth/xdp.c-335-\t\t\t\t struct xdp_frame_bulk *bq, bool frags)\n--\ndrivers/net/ethernet/intel/libeth/xdp.c-346-}\ndrivers/net/ethernet/intel/libeth/xdp.c:347:EXPORT_SYMBOL_GPL(libeth_xdp_return_buff_bulk);\ndrivers/net/ethernet/intel/libeth/xdp.c-348-\n--\ndrivers/net/ethernet/intel/libeth/xdp.c=430=static const struct libeth_xdp_ops xdp_ops __initconst = {\ndrivers/net/ethernet/intel/libeth/xdp.c:431:\t.bulk\t= libeth_xdp_return_buff_bulk,\ndrivers/net/ethernet/intel/libeth/xdp.c-432-\t.xsk\t= libeth_xsk_buff_free_slow,\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c=2184=static void __free_dma_rx_desc_resources(struct stmmac_priv *priv,\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-2198-\tif (rx_q-\u003estate.n_descs \u0026\u0026 !rx_q-\u003exsk_pool) {\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:2199:\t\t__xdp_return_buff(\u0026rx_q-\u003estate.xdp, false);\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-2200-\t\trx_q-\u003estate.n_descs = 0;\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c=5907=static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-6055-\t\tlen -= ETH_FCS_LEN;\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:6056:\t\tif (xdp_buff_shrink_tail(\u0026ctx.xdp, ETH_FCS_LEN)) {\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-6057-\t\t\tif (!error)\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-6073-\t\t\tif (xdp_res \u0026 STMMAC_XDP_CONSUMED) {\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:6074:\t\t\t\t__xdp_return_buff(\u0026ctx.xdp, true);\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-6075-\t\t\t\trx_dropped++;\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-6116-\t\tif (n_descs)\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:6117:\t\t\t__xdp_return_buff(\u0026ctx.xdp, true);\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-6118-\t\tin_progress = false;\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c=8497=static void stmmac_reset_rx_queue(struct stmmac_priv *priv, u32 queue)\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-8501-\tif (rx_q-\u003estate.n_descs \u0026\u0026 !rx_q-\u003exsk_pool) {\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:8502:\t\t__xdp_return_buff(\u0026rx_q-\u003estate.xdp, false);\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-8503-\t\trx_q-\u003estate.n_descs = 0;\n--\ndrivers/net/veth.c=796=static struct sk_buff *veth_xdp_rcv_skb(struct veth_rq *rq,\n--\ndrivers/net/veth.c-907-\trcu_read_unlock();\ndrivers/net/veth.c:908:\txdp_return_buff(xdp);\ndrivers/net/veth.c-909-xdp_xmit:\n--\ndrivers/net/xen-netfront.c=972=static u32 xennet_run_xdp(struct netfront_queue *queue, struct page *pdata,\n--\ndrivers/net/xen-netfront.c-1007-\t\t\ttrace_xdp_exception(queue-\u003einfo-\u003enetdev, prog, act);\ndrivers/net/xen-netfront.c:1008:\t\t\txdp_return_buff(xdp);\ndrivers/net/xen-netfront.c-1009-\t\t}\n--\ninclude/net/libeth/tx.h-20- * @__LIBETH_SQE_XDP_START: separator between skb and XDP types\ninclude/net/libeth/tx.h:21: * @LIBETH_SQE_XDP_TX: \u0026skb_shared_info, libeth_xdp_return_buff_bulk(), stats\ninclude/net/libeth/tx.h-22- * @LIBETH_SQE_XDP_XMIT: \u0026xdp_frame, unmap and xdp_return_frame_bulk(), stats\n--\ninclude/net/libeth/xdp.h=517=libeth_xdp_tx_xmit_bulk(const struct libeth_xdp_tx_frame *bulk, void *xdpsq,\n--\ninclude/net/libeth/xdp.h-588-\ninclude/net/libeth/xdp.h:589:void libeth_xdp_return_buff_slow(struct libeth_xdp_buff *xdp);\ninclude/net/libeth/xdp.h-590-\n--\ninclude/net/libeth/xdp.h=637=libeth_xdp_tx_queue_bulk(struct libeth_xdp_tx_bulk *bq,\n--\ninclude/net/libeth/xdp.h-647-\t unlikely(!flush_bulk(bq, 0))) {\ninclude/net/libeth/xdp.h:648:\t\tlibeth_xdp_return_buff_slow(xdp);\ninclude/net/libeth/xdp.h-649-\t\treturn false;\n--\ninclude/net/libeth/xdp.h=1230=static inline void libeth_xdp_return_frags(const struct skb_shared_info *sinfo,\n--\ninclude/net/libeth/xdp.h-1240-/**\ninclude/net/libeth/xdp.h:1241: * libeth_xdp_return_buff - free/recycle \u0026libeth_xdp_buff\ninclude/net/libeth/xdp.h-1242- * @xdp: buffer to free\ninclude/net/libeth/xdp.h-1243- *\ninclude/net/libeth/xdp.h:1244: * Hotpath helper to free \u0026libeth_xdp_buff. Comparing to xdp_return_buff(),\ninclude/net/libeth/xdp.h-1245- * it's faster as it gets inlined and always assumes order-0 pages and safe\n--\ninclude/net/libeth/xdp.h-1247- */\ninclude/net/libeth/xdp.h:1248:#define libeth_xdp_return_buff(xdp)\t__libeth_xdp_return_buff(xdp, true)\ninclude/net/libeth/xdp.h-1249-\ninclude/net/libeth/xdp.h:1250:static inline void __libeth_xdp_return_buff(struct libeth_xdp_buff *xdp,\ninclude/net/libeth/xdp.h-1251-\t\t\t\t\t bool napi)\n--\ninclude/net/libeth/xdp.h=1355=__libeth_xdp_run_prog(struct libeth_xdp_buff *xdp,\n--\ninclude/net/libeth/xdp.h-1367-\tcase XDP_DROP:\ninclude/net/libeth/xdp.h:1368:\t\tlibeth_xdp_return_buff(xdp);\ninclude/net/libeth/xdp.h-1369-\n--\ninclude/net/libeth/xdp.h=1469=__libeth_xdp_run_pass(struct libeth_xdp_buff *xdp,\n--\ninclude/net/libeth/xdp.h-1499-\tif (unlikely(!skb)) {\ninclude/net/libeth/xdp.h:1500:\t\tlibeth_xdp_return_buff_slow(xdp);\ninclude/net/libeth/xdp.h-1501-\t\treturn;\n--\ninclude/net/libeth/xdp.h=1729=static inline int libeth_xdpmo_rx_hash(u32 *hash,\n--\ninclude/net/libeth/xdp.h-1743-\ninclude/net/libeth/xdp.h:1744:void libeth_xdp_return_buff_bulk(const struct skb_shared_info *sinfo,\ninclude/net/libeth/xdp.h-1745-\t\t\t\t struct xdp_frame_bulk *bq, bool frags);\n--\ninclude/net/libeth/xdp.h=1761=__libeth_xdp_complete_tx(struct libeth_sqe *sqe, struct libeth_cq_pp *cp,\ninclude/net/libeth/xdp.h:1762:\t\t\t typeof(libeth_xdp_return_buff_bulk) bulk,\ninclude/net/libeth/xdp.h-1763-\t\t\t typeof(libeth_xsk_buff_free_slow) xsk)\n--\ninclude/net/libeth/xdp.h=1810=static inline void libeth_xdp_complete_tx(struct libeth_sqe *sqe,\n--\ninclude/net/libeth/xdp.h-1812-{\ninclude/net/libeth/xdp.h:1813:\t__libeth_xdp_complete_tx(sqe, cp, libeth_xdp_return_buff_bulk,\ninclude/net/libeth/xdp.h-1814-\t\t\t\t libeth_xsk_buff_free_slow);\n--\ninclude/net/xdp.h=390=struct xdp_frame *xdpf_clone(struct xdp_frame *xdpf);\ninclude/net/xdp.h:391:int xdp_buff_shrink_tail(struct xdp_buff *xdp, int offset);\ninclude/net/xdp.h:392:bool xdp_buff_shrink_data(struct xdp_buff *xdp, skb_frag_t *frag,\ninclude/net/xdp.h-393-\t\t\t int shrink, bool tail);\n--\ninclude/net/xdp.h=459=void xdp_return_frame_rx_napi(struct xdp_frame *xdpf);\ninclude/net/xdp.h:460:void __xdp_return_buff(struct xdp_buff *xdp, bool napi_direct);\ninclude/net/xdp.h:461:static inline void xdp_return_buff(struct xdp_buff *xdp)\ninclude/net/xdp.h-462-{\ninclude/net/xdp.h:463:\t__xdp_return_buff(xdp, true);\ninclude/net/xdp.h-464-}\n--\nnet/bpf/test_run.c=273=static int xdp_test_run_batch(struct xdp_test_data *xdp, struct bpf_prog *prog,\n--\nnet/bpf/test_run.c-311-\t\t\tif (ret) {\nnet/bpf/test_run.c:312:\t\t\t\txdp_return_buff(ctx);\nnet/bpf/test_run.c-313-\t\t\t\tcontinue;\n--\nnet/bpf/test_run.c-330-\t\t\tif (ret)\nnet/bpf/test_run.c:331:\t\t\t\txdp_return_buff(ctx);\nnet/bpf/test_run.c-332-\t\t\tbreak;\n--\nnet/bpf/test_run.c-339-\t\tcase XDP_DROP:\nnet/bpf/test_run.c:340:\t\t\txdp_return_buff(ctx);\nnet/bpf/test_run.c-341-\t\t\tbreak;\n--\nnet/core/filter.c=4441=BPF_CALL_2(bpf_xdp_adjust_tail, struct xdp_buff *, xdp, int, offset)\n--\nnet/core/filter.c-4446-\tif (offset \u003c 0)\n\n"
} |
| 11/2 | 2026/12/01 04:23 | tool | read-file |
0mArgs:{
"File": "drivers/net/ethernet/stmicro/stmmac/Kconfig",
"FirstLine": 200,
"LineCount": 70
}Results: {
"Contents": " 200:\t\t device driver. This driver is used for the S32CC series\n 201:\t\t SOCs GMAC ethernet controller, ie. S32G2xx, S32G3xx and\n 202:\t\t S32R45.\n 203:\t\n 204:\tconfig DWMAC_SOCFPGA\n 205:\t\ttristate \"SOCFPGA dwmac support\"\n 206:\t\tdefault ARCH_INTEL_SOCFPGA\n 207:\t\tdepends on OF \u0026\u0026 (ARCH_INTEL_SOCFPGA || COMPILE_TEST)\n 208:\t\tselect MFD_SYSCON\n 209:\t\tselect MDIO_REGMAP\n 210:\t\tselect REGMAP_MMIO\n 211:\t\tselect PCS_LYNX\n 212:\t\thelp\n 213:\t\t Support for ethernet controller on Altera SOCFPGA\n 214:\t\n 215:\t\t This selects the Altera SOCFPGA SoC glue layer support\n 216:\t\t for the stmmac device driver. This driver is used for\n 217:\t\t arria5 and cyclone5 FPGA SoCs.\n 218:\t\n 219:\tconfig DWMAC_SOPHGO\n 220:\t\ttristate \"Sophgo dwmac support\"\n 221:\t\tdepends on OF \u0026\u0026 (ARCH_SOPHGO || COMPILE_TEST)\n 222:\t\tdefault m if ARCH_SOPHGO\n 223:\t\thelp\n 224:\t\t Support for ethernet controllers on Sophgo RISC-V SoCs\n 225:\t\n 226:\t\t This selects the Sophgo SoC specific glue layer support\n 227:\t\t for the stmmac device driver. This driver is used for the\n 228:\t\t ethernet controllers on various Sophgo SoCs.\n 229:\t\n 230:\tconfig DWMAC_SPACEMIT\n 231:\t\ttristate \"Spacemit dwmac support\"\n 232:\t\tdepends on OF \u0026\u0026 (ARCH_SPACEMIT || COMPILE_TEST)\n 233:\t\tselect MFD_SYSCON\n 234:\t\tdefault m if ARCH_SPACEMIT\n 235:\t\thelp\n 236:\t\t Support for ethernet controllers on Spacemit RISC-V SoCs\n 237:\t\n 238:\t\t This selects the Spacemit platform specific glue layer support\n 239:\t\t for the stmmac device driver. This driver is used for the\n 240:\t\t Spacemit K3 ethernet controllers.\n 241:\t\n 242:\tconfig DWMAC_STARFIVE\n 243:\t\ttristate \"StarFive dwmac support\"\n 244:\t\tdepends on OF \u0026\u0026 (ARCH_STARFIVE || COMPILE_TEST)\n 245:\t\tselect MFD_SYSCON\n 246:\t\tdefault m if ARCH_STARFIVE\n 247:\t\thelp\n 248:\t\t Support for ethernet controllers on StarFive RISC-V SoCs\n 249:\t\n 250:\t\t This selects the StarFive platform specific glue layer support\n 251:\t\t for the stmmac device driver. This driver is used for the\n 252:\t\t StarFive JH7100 and JH7110 ethernet controllers.\n 253:\t\n 254:\tconfig DWMAC_STI\n 255:\t\ttristate \"STi GMAC support\"\n 256:\t\tdefault ARCH_STI\n 257:\t\tdepends on OF \u0026\u0026 (ARCH_STI || COMPILE_TEST)\n 258:\t\tselect MFD_SYSCON\n 259:\t\thelp\n 260:\t\t Support for ethernet controller on STi SOCs.\n 261:\t\n 262:\t\t This selects STi SoC glue layer support for the stmmac\n 263:\t\t device driver. This driver is used on for the STi series\n 264:\t\t SOCs GMAC ethernet controller.\n 265:\t\n 266:\tconfig DWMAC_STM32\n 267:\t\ttristate \"STM32 DWMAC support\"\n 268:\t\tdefault ARCH_STM32\n 269:\t\tdepends on OF \u0026\u0026 HAS_IOMEM \u0026\u0026 (ARCH_STM32 || COMPILE_TEST)\n"
} |
| 12/2 | 2026/12/01 04:23 | llm | patch-evaluator |
0mModel:gemini-4-hydrogen Args: null Results: null Tokens: input: 27200 output: 129 thoughts: 905 Thoughts: **XDP Reachability and Potential Vulnerabilities** Okay, so I'm looking at how easily we can reach `net/core/filter.c` and `net/core/xdp.c`. It's pretty direct. We have this chain: `bpf_xdp_adjust_tail` -> `xdp_buff_shrink_tail` -> `xdp_frags_shrink_tail` -> `xdp_buff_shrink_data` -> `xdp_buff_shrink_data_zc`, and also `bpf_xdp_pull_data` which leads to `xdp_buff_shrink_data` and then `xdp_buff_shrink_data_zc`. Then we have `__xdp_return_buff`, which is called inline by `xdp_return_buff`, and this is used in places like `veth.c`, `net/bpf/test_run.c`, and `net/xdp/xsk.c`. The really interesting bit is that all of this is reachable via standard environments like QEMU and GCE, using things like BPF_PROG_TEST_RUN (XDP), veth + XDP, and XSK (AF_XDP) sockets. This means these code paths are likely to be hit by someone. Let's dive into `bpf_xdp_adjust_tail` and `xdp_buff_shrink_tail`. Previously, in `bpf_xdp_adjust_tail`, with linear `xdp_buff`, it was checking `data_end < xdp->data + ETH_HLEN` and returning `-EINVAL`. Now, when `offset < 0`, it calls `xdp_buff_shrink_tail(xdp, -offset)`. In `xdp_buff_shrink_tail` we have some bounds checking like `offset < 0`, `offset > xdp->data_end - xdp->data - ETH_HLEN`. So that's interesting. Also, these functions, `xdp_buff_shrink_tail`, `xdp_frags_shrink_tail`, `xdp_buff_shrink_data`, and `xdp_buff_shrink_data_zc` are newly introduced or refactored functions in `net/core/xdp.c`, and they're called by `bpf_xdp_adjust_tail` and `bpf_xdp_pull_data`. Also, `__xdp_return_buff` in `net/core/xdp.c` has been modified (it was renamed from `xdp_return_buff`). I'm wondering about inlining or if any of those new functions are static. `xdp_buff_shrink_tail`, `xdp_buff_shrink_data`, and `__xdp_return_buff` are *not* static, and `xdp_buff_shrink_tail` and `__xdp_return_buff` are `EXPORT_SYMBOL_GPL`. On the other hand, `bpf_xdp_adjust_tail` and `bpf_xdp_pull_data` are BPF helpers/kfuncs in `net/core/filter.c`. Wait a minute, `BPF_CALL_2(bpf_xdp_adjust_tail, ...)` expands to `static u64 ____bpf_xdp_adjust_tail(...)` and `u64 bpf_xdp_adjust_tail(...)`. That macro is hiding a little something there, might need to double check how the symbols are generated to make sure I understand the name situation. I'll need to check the `BPF_CALL_2` macro definition to be sure. Same goes for `bpf_xdp_pull_data`. Also, I'll check `net/core/Kconfig` or `net/bpf/` Kconfigs to see the enabling configurations like XDP, BPF_SYSCALL, XDP_SOCKETS, and VETH. |
| 13/2 | 2026/12/01 04:23 | tool | grepper |
0mArgs:{
"Expression": "#define BPF_CALL_2",
"PathPrefixes": [
"include/"
]
}Results: {
"Output": "include/linux/filter.h=452=static inline int bpf_atomic_load_reg(const struct bpf_insn *insn)\n--\ninclude/linux/filter.h-708-#define BPF_CALL_1(name, ...)\tBPF_CALL_x(1, __NOATTR, name, __VA_ARGS__)\ninclude/linux/filter.h:709:#define BPF_CALL_2(name, ...)\tBPF_CALL_x(2, __NOATTR, name, __VA_ARGS__)\ninclude/linux/filter.h-710-#define BPF_CALL_3(name, ...)\tBPF_CALL_x(3, __NOATTR, name, __VA_ARGS__)\n"
} |
| 14/2 | 2026/12/01 04:23 | tool | grepper |
0mArgs:{
"Expression": "xdp_frags_shrink_tail|xdp_buff_shrink_data_zc|xdp_buff_shrink_data|xdp_buff_shrink_tail",
"PathPrefixes": [
"net/"
]
}Results: {
"Output": "net/core/filter.c=4441=BPF_CALL_2(bpf_xdp_adjust_tail, struct xdp_buff *, xdp, int, offset)\n--\nnet/core/filter.c-4446-\tif (offset \u003c 0)\nnet/core/filter.c:4447:\t\treturn xdp_buff_shrink_tail(xdp, -offset);\nnet/core/filter.c-4448-\n--\nnet/core/filter.c=12729=__bpf_kfunc int bpf_xdp_pull_data(struct xdp_md *x, u32 len)\n--\nnet/core/filter.c-12770-\t\tdelta -= shrink;\nnet/core/filter.c:12771:\t\tif (xdp_buff_shrink_data(xdp, frag, shrink, false))\nnet/core/filter.c-12772-\t\t\tn_frags_free++;\n--\nnet/core/xdp.c=675=EXPORT_SYMBOL_GPL(xdp_build_skb_from_buff);\nnet/core/xdp.c-676-\nnet/core/xdp.c:677:static struct xdp_buff *xdp_buff_shrink_data_zc(struct xdp_buff *xdp,\nnet/core/xdp.c-678-\t\t\t\t\t\tint shrink, bool tail,\n--\nnet/core/xdp.c-695-\nnet/core/xdp.c:696:bool xdp_buff_shrink_data(struct xdp_buff *xdp, skb_frag_t *frag,\nnet/core/xdp.c-697-\t\t\t int shrink, bool tail)\n--\nnet/core/xdp.c-705-\t\tnetmem = 0;\nnet/core/xdp.c:706:\t\tzc_frag = xdp_buff_shrink_data_zc(xdp, shrink, tail, release);\nnet/core/xdp.c-707-\t}\n--\nnet/core/xdp.c-719-\nnet/core/xdp.c:720:static int xdp_frags_shrink_tail(struct xdp_buff *xdp, int offset)\nnet/core/xdp.c-721-{\n--\nnet/core/xdp.c-733-\t\toffset -= shrink;\nnet/core/xdp.c:734:\t\tif (xdp_buff_shrink_data(xdp, frag, shrink, true))\nnet/core/xdp.c-735-\t\t\tn_frags_free++;\n--\nnet/core/xdp.c-748-\nnet/core/xdp.c:749:int xdp_buff_shrink_tail(struct xdp_buff *xdp, int offset)\nnet/core/xdp.c-750-{\n--\nnet/core/xdp.c-754-\tif (unlikely(xdp_buff_has_frags(xdp))) /* non-linear xdp buff */\nnet/core/xdp.c:755:\t\treturn xdp_frags_shrink_tail(xdp, offset);\nnet/core/xdp.c-756-\n--\nnet/core/xdp.c-763-}\nnet/core/xdp.c:764:EXPORT_SYMBOL_GPL(xdp_buff_shrink_tail);\nnet/core/xdp.c-765-\n"
} |
| 15/2 | 2026/12/01 04:23 | tool | read-file |
0mArgs:{
"File": "net/xdp/Kconfig",
"FirstLine": 1,
"LineCount": 30
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0-only\n 2:\tconfig XDP_SOCKETS\n 3:\t\tbool \"XDP sockets\"\n 4:\t\tdepends on BPF_SYSCALL\n 5:\t\tdefault n\n 6:\t\thelp\n 7:\t\t XDP sockets allows a channel between XDP programs and\n 8:\t\t userspace applications.\n 9:\t\n 10:\tconfig XDP_SOCKETS_DIAG\n 11:\t\ttristate \"XDP sockets: monitoring interface\"\n 12:\t\tdepends on XDP_SOCKETS\n 13:\t\tdefault n\n 14:\t\thelp\n 15:\t\t Support for PF_XDP sockets monitoring interface used by the ss tool.\n 16:\t\t If unsure, say Y.\n"
} |
| 16/2 | 2026/12/01 04:23 | llm | patch-evaluator |
0mModel:gemini-4-hydrogen Args: null Results: null Tokens: input: 29501 output: 119 thoughts: 87 Thoughts: Okay, here's my summary, taking the perspective of someone deeply familiar with kernel networking and XDP: **Diving Deep into the Kernel's XDP & Driver Landscape** Right, so to get a truly complete picture, I need to check a few specific areas. First, I want to drill down into `include/linux/filter.h`, specifically around line 708. I know that file defines crucial structures and macros for BPF and XDP filtering, so pinpointing that location will give me context for understanding the potential configuration and capabilities related to XDP. Then, I'm shifting my focus to the build process. I'll need to examine `net/core/Makefile` to confirm how `xdp.o` and `filter.o` are being built. Understanding the build dependencies and options helps me identify if the XDP component is included and how it is linked to the broader networking stack. Are there conditional builds or specific flags involved? That's what I need to see. Finally, I'll turn my attention to the device driver. I'll look at `drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c`, which is the driver for the STM32 MAC. I want to check for any PCI IDs specifically related to that driver. The driver implementation provides clues on the underlying hardware support for XDP. Is XDP offloaded? Is it a hybrid? Or is it purely a software implementation? Does it require specific hardware features? I'm trying to identify if the driver is hardware-dependent or if there's any PCI dependency. |
| 17/2 | 2026/12/01 04:23 | tool | read-file |
0mArgs:{
"File": "include/linux/filter.h",
"FirstLine": 680,
"LineCount": 35
}Results: {
"Contents": " 680:\t\t(__force t)\t\t\t\t\t\t\t \\\n 681:\t\t(__force\t\t\t\t\t\t\t \\\n 682:\t\t typeof(__builtin_choose_expr(sizeof(t) == sizeof(unsigned long), \\\n 683:\t\t\t\t\t (unsigned long)0, (t)0))) a\n 684:\t#define __BPF_V void\n 685:\t#define __BPF_N\n 686:\t\n 687:\t#define __BPF_DECL_ARGS(t, a) t a\n 688:\t#define __BPF_DECL_REGS(t, a) u64 a\n 689:\t\n 690:\t#define __BPF_PAD(n)\t\t\t\t\t\t\t \\\n 691:\t\t__BPF_MAP(n, __BPF_DECL_ARGS, __BPF_N, u64, __ur_1, u64, __ur_2, \\\n 692:\t\t\t u64, __ur_3, u64, __ur_4, u64, __ur_5)\n 693:\t\n 694:\t#define BPF_CALL_x(x, attr, name, ...)\t\t\t\t\t \\\n 695:\t\tstatic __always_inline\t\t\t\t\t\t \\\n 696:\t\tu64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__)); \\\n 697:\t\ttypedef u64 (*btf_##name)(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__)); \\\n 698:\t\tattr u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)); \\\n 699:\t\tattr u64 name(__BPF_REG(x, __BPF_DECL_REGS, __BPF_N, __VA_ARGS__)) \\\n 700:\t\t{\t\t\t\t\t\t\t\t \\\n 701:\t\t\treturn ((btf_##name)____##name)(__BPF_MAP(x,__BPF_CAST,__BPF_N,__VA_ARGS__));\\\n 702:\t\t}\t\t\t\t\t\t\t\t \\\n 703:\t\tstatic __always_inline\t\t\t\t\t\t \\\n 704:\t\tu64 ____##name(__BPF_MAP(x, __BPF_DECL_ARGS, __BPF_V, __VA_ARGS__))\n 705:\t\n 706:\t#define __NOATTR\n 707:\t#define BPF_CALL_0(name, ...)\tBPF_CALL_x(0, __NOATTR, name, __VA_ARGS__)\n 708:\t#define BPF_CALL_1(name, ...)\tBPF_CALL_x(1, __NOATTR, name, __VA_ARGS__)\n 709:\t#define BPF_CALL_2(name, ...)\tBPF_CALL_x(2, __NOATTR, name, __VA_ARGS__)\n 710:\t#define BPF_CALL_3(name, ...)\tBPF_CALL_x(3, __NOATTR, name, __VA_ARGS__)\n 711:\t#define BPF_CALL_4(name, ...)\tBPF_CALL_x(4, __NOATTR, name, __VA_ARGS__)\n 712:\t#define BPF_CALL_5(name, ...)\tBPF_CALL_x(5, __NOATTR, name, __VA_ARGS__)\n 713:\t\n 714:\t#define NOTRACE_BPF_CALL_1(name, ...)\tBPF_CALL_x(1, notrace, name, __VA_ARGS__)\n"
} |
| 18/2 | 2026/12/01 04:23 | tool | read-file |
0mArgs:{
"File": "net/core/Makefile",
"FirstLine": 1,
"LineCount": 45
}Results: {
"Contents": " 1:\t# SPDX-License-Identifier: GPL-2.0\n 2:\t#\n 3:\t# Makefile for the Linux networking core.\n 4:\t#\n 5:\t\n 6:\tobj-y := sock.o skbuff.o datagram.o stream.o scm.o \\\n 7:\t\t gen_stats.o gen_estimator.o net_namespace.o secure_seq.o \\\n 8:\t\t flow_dissector.o\n 9:\t\n 10:\tobj-$(CONFIG_SYSCTL) += sysctl_net_core.o\n 11:\t\n 12:\tobj-y\t\t += dev.o dev_api.o dev_addr_lists.o dst.o netevent.o \\\n 13:\t\t\t\tneighbour.o rtnetlink.o utils.o link_watch.o filter.o \\\n 14:\t\t\t\tsock_diag.o dev_ioctl.o tso.o sock_reuseport.o \\\n 15:\t\t\t\tfib_notifier.o xdp.o flow_offload.o gro.o \\\n 16:\t\t\t\tnetdev-genl.o netdev-genl-gen.o netdev_work.o gso.o\n 17:\t\n 18:\tobj-$(CONFIG_NETDEV_ADDR_LIST_TEST) += dev_addr_lists_test.o\n 19:\t\n 20:\tobj-y += net-sysfs.o\n 21:\tobj-y += hotdata.o\n 22:\tobj-y += netdev_config.o\n 23:\tobj-y += netdev_rx_queue.o\n 24:\tobj-y += netdev_queues.o\n 25:\tobj-$(CONFIG_PAGE_POOL) += page_pool.o page_pool_user.o\n 26:\tobj-$(CONFIG_PROC_FS) += net-procfs.o\n 27:\tobj-$(CONFIG_NET_PKTGEN) += pktgen.o\n 28:\tobj-$(CONFIG_NETPOLL) += netpoll.o\n 29:\tobj-$(CONFIG_FIB_RULES) += fib_rules.o\n 30:\tobj-$(CONFIG_TRACEPOINTS) += net-traces.o\n 31:\tobj-$(CONFIG_NET_DROP_MONITOR) += drop_monitor.o\n 32:\tobj-$(CONFIG_NET_IEEE8021Q_HELPERS) += ieee8021q_helpers.o\n 33:\tobj-$(CONFIG_NET_SELFTESTS) += selftests.o\n 34:\tobj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += timestamping.o\n 35:\tobj-$(CONFIG_NET_PTP_CLASSIFY) += ptp_classifier.o\n 36:\tobj-$(CONFIG_CGROUP_NET_PRIO) += netprio_cgroup.o\n 37:\tobj-$(CONFIG_CGROUP_NET_CLASSID) += netclassid_cgroup.o\n 38:\tobj-$(CONFIG_LWTUNNEL) += lwtunnel.o\n 39:\tobj-$(CONFIG_LWTUNNEL_BPF) += lwt_bpf.o\n 40:\tobj-$(CONFIG_DST_CACHE) += dst_cache.o\n 41:\tobj-$(CONFIG_HWBM) += hwbm.o\n 42:\tobj-$(CONFIG_GRO_CELLS) += gro_cells.o\n 43:\tobj-$(CONFIG_FAILOVER) += failover.o\n 44:\tobj-$(CONFIG_NET_SOCK_MSG) += skmsg.o\n 45:\tobj-$(CONFIG_BPF_SYSCALL) += sock_map.o\n"
} |
| 19/2 | 2026/12/01 04:23 | tool | read-file |
0mArgs:{
"File": "drivers/net/ethernet/stmicro/stmmac/stmmac_pci.c",
"FirstLine": 1,
"LineCount": 50
}Results: {
"Contents": " 1:\t// SPDX-License-Identifier: GPL-2.0-only\n 2:\t/*******************************************************************************\n 3:\t This contains the functions to handle the pci driver.\n 4:\t\n 5:\t Copyright (C) 2011-2012 Vayavya Labs Pvt Ltd\n 6:\t\n 7:\t\n 8:\t Author: Rayagond Kokatanur \u003crayagond@vayavyalabs.com\u003e\n 9:\t Author: Giuseppe Cavallaro \u003cpeppe.cavallaro@st.com\u003e\n 10:\t*******************************************************************************/\n 11:\t\n 12:\t#include \u003clinux/clk-provider.h\u003e\n 13:\t#include \u003clinux/pci.h\u003e\n 14:\t#include \u003clinux/dmi.h\u003e\n 15:\t\n 16:\t#include \"stmmac.h\"\n 17:\t#include \"stmmac_libpci.h\"\n 18:\t\n 19:\tstruct stmmac_pci_info {\n 20:\t\tint (*setup)(struct pci_dev *pdev, struct plat_stmmacenet_data *plat);\n 21:\t};\n 22:\t\n 23:\tstatic void common_default_data(struct plat_stmmacenet_data *plat)\n 24:\t{\n 25:\t\t/* clk_csr_i = 20-35MHz \u0026 MDC = clk_csr_i/16 */\n 26:\t\tplat-\u003eclk_csr = STMMAC_CSR_20_35M;\n 27:\t\tplat-\u003ecore_type = DWMAC_CORE_GMAC;\n 28:\t\tplat-\u003eforce_sf_dma_mode = true;\n 29:\t\n 30:\t\tplat-\u003emdio_bus_data-\u003eneeds_reset = true;\n 31:\t}\n 32:\t\n 33:\tstatic int stmmac_default_data(struct pci_dev *pdev,\n 34:\t\t\t\t struct plat_stmmacenet_data *plat)\n 35:\t{\n 36:\t\t/* Set common default data first */\n 37:\t\tcommon_default_data(plat);\n 38:\t\n 39:\t\tplat-\u003ebus_id = 1;\n 40:\t\tplat-\u003ephy_addr = 0;\n 41:\t\tplat-\u003ephy_interface = PHY_INTERFACE_MODE_GMII;\n 42:\t\n 43:\t\tplat-\u003edma_cfg-\u003epbl = 32;\n 44:\t\tplat-\u003edma_cfg-\u003epblx8 = true;\n 45:\t\t/* TODO: AXI */\n 46:\t\n 47:\t\treturn 0;\n 48:\t}\n 49:\t\n 50:\tstatic const struct stmmac_pci_info stmmac_pci_info = {\n"
} |
| 20/2 | 2026/12/01 04:23 | llm | patch-evaluator |
0mModel:gemini-4-hydrogen Args: null Results: null Tokens: input: 32232 output: 53 thoughts: 179 Thoughts: Here's my analysis of the situation: **Investigating XDP and BPF Helper Dependencies** Okay, so I'm looking at the `net/core/Makefile` and it's clear that `filter.o` and `xdp.o` are *always* included in the build (`obj-y`) when `CONFIG_NET` is enabled. That's a fundamental starting point. Now, I need to confirm something: the BPF XDP helpers, specifically `bpf_xdp_adjust_tail` and `bpf_xdp_pull_data`, seem to be highly dependent. I know they require `BPF_SYSCALL` (that's a given), and obviously, the base `NET` config, along with `XDP_SOCKETS` if we're dealing with the zero-copy (ZC) path, and `VETH` is necessary if we are dealing with a veth XDP path. `BPF_JIT` is generally good to have, but it seems more like an optimization, a nice-to-have, and not strictly a dependency. But wait a minute... I really need to double-check this. Before I proceed, I need to make *absolutely* sure that there aren't any subtle `#ifdef` guards around the implementations of those helper functions, `bpf_xdp_adjust_tail` and `bpf_xdp_pull_data`, in `net/core/filter.c` and `net/core/xdp.c`. Just because the Makefile *includes* the object files doesn't mean those specific helper functions are *always* available. There could be other config flags that are crucial here, and I can't afford to miss something crucial. I need to be thorough with my checks. |
| 21/2 | 2026/12/01 04:23 | tool | grepper |
0mArgs:{
"Expression": "CONFIG_XDP|CONFIG_BPF|CONFIG_NET",
"PathPrefixes": [
"net/core/xdp.c",
"net/core/filter.c"
]
}Results: {
"Output": "net/core/filter.c=4551=EXPORT_SYMBOL_GPL(xdp_do_flush);\nnet/core/filter.c-4552-\nnet/core/filter.c:4553:#if defined(CONFIG_DEBUG_NET) \u0026\u0026 defined(CONFIG_BPF_SYSCALL)\nnet/core/filter.c-4554-void xdp_do_check_flushed(struct napi_struct *napi)\n--\nnet/core/filter.c=10052=static struct bpf_insn *bpf_convert_tstamp_read(const struct bpf_prog *prog,\n--\nnet/core/filter.c-10058-\nnet/core/filter.c:10059:#ifdef CONFIG_NET_XGRESS\nnet/core/filter.c-10060-\t/* If the tstamp_type is read,\n--\nnet/core/filter.c=10087=static struct bpf_insn *bpf_convert_tstamp_write(const struct bpf_prog *prog,\n--\nnet/core/filter.c-10093-\nnet/core/filter.c:10094:#ifdef CONFIG_NET_XGRESS\nnet/core/filter.c-10095-\t/* If the tstamp_type is read,\n--\nnet/core/filter.c=10125=static u32 bpf_convert_ctx_access(enum bpf_access_type type,\n--\nnet/core/filter.c-10298-\tcase offsetof(struct __sk_buff, tc_index):\nnet/core/filter.c:10299:#ifdef CONFIG_NET_SCHED\nnet/core/filter.c-10300-\t\tif (type == BPF_WRITE)\n--\nnet/core/filter.c-10317-\tcase offsetof(struct __sk_buff, napi_id):\nnet/core/filter.c:10318:#if defined(CONFIG_NET_RX_BUSY_POLL)\nnet/core/filter.c-10319-\t\t*insn++ = BPF_LDX_MEM(BPF_W, si-\u003edst_reg, si-\u003esrc_reg,\n"
} |
| 22/2 | 2026/12/01 04:23 | llm | patch-evaluator |
0mModel:gemini-4-hydrogen Args: null Results: null Tokens: input: 33015 output: 25 thoughts: 887 Thoughts: **Focus Symbol Refinement for XDP Operations** Okay, let's zero in on the key functions for analysis. I need to determine if these functions are good "FocusSymbols" – that is, if they are central to the code changes, and where the changes actually matter. Specifically, I'm looking at `xdp_buff_shrink_tail`, `bpf_xdp_adjust_tail`, `bpf_xdp_pull_data`, and `__xdp_return_buff`. First, `xdp_buff_shrink_tail` is a newly exported function in `net/core/xdp.c`, and importantly, is called by `bpf_xdp_adjust_tail`. Then there is `xdp_buff_shrink_data`, another new function in `net/core/xdp.c`, this one non-static, called by `xdp_frags_shrink_tail` and `bpf_xdp_pull_data`. There's also `xdp_frags_shrink_tail`, which is static, only called by `xdp_buff_shrink_tail`, so that means `xdp_buff_shrink_tail` is the relevant function to investigate. Then there is the modified `__xdp_return_buff`, also in `net/core/xdp.c`. I need to confirm whether `__xdp_return_buff` is frequently called. It looks like it is, in `net/bpf/test_run.c` and `drivers/net/veth.c`, where `xdp_return_buff` (an inline wrapper calling `__xdp_return_buff`) is called for XDP DROP/error returns. It's not as frequent as `kfree` or `alloc_skb`, but it's used in testing. However, the functions related to the refactoring and modifications seem to be: `xdp_buff_shrink_tail`, `xdp_buff_shrink_data`, `bpf_xdp_adjust_tail`, and `bpf_xdp_pull_data`. They look much more targeted. Let's check `__xdp_return_buff` itself. It looks like it didn't change behavior for any existing callers. It simply passes `napi_direct` to `__xdp_return`, where `xdp_return_buff` passes `true`. So the changes are minimal, which is great. Okay, now for the changes I can see. - `bpf_xdp_adjust_tail` in `net/core/filter.c` now changes control flow with a negative `offset`. It unconditionally calls `xdp_buff_shrink_tail(xdp, -offset)` for both linear and non-linear `xdp_buff`! This is an important change. - `xdp_buff_shrink_tail` in `net/core/xdp.c` is the key implementation of the new, unified tail shrinking for both buffer types. The `offset` passed to it can be negative which is handled by either `xdp_frags_shrink_tail` which handles multi-frag XDP buffers or XSK ZC buffers. - `xdp_buff_shrink_data` in `net/core/xdp.c` is called by `xdp_frags_shrink_tail` and `bpf_xdp_pull_data`. - `bpf_xdp_pull_data` in `net/core/filter.c` now calls `xdp_buff_shrink_data`. I should check the `bpf_xdp_pull_data` registration. I need to see if there are any config options beyond `BPF_SYSCALL` and `NET` that enable it. I'll grep for `bpf_xdp_pull_data`. |
| 23/2 | 2026/12/01 04:24 | tool | grepper |
0mArgs:{
"Expression": "bpf_xdp_pull_data"
}Results: {
"Output": "kernel/bpf/verifier.c=13683=enum special_kfunc_type {\n--\nkernel/bpf/verifier.c-13716-\tKF_bpf_dynptr_from_skb_meta,\nkernel/bpf/verifier.c:13717:\tKF_bpf_xdp_pull_data,\nkernel/bpf/verifier.c-13718-\tKF_bpf_dynptr_slice,\n--\nkernel/bpf/verifier.c=13789=BTF_ID(func, bpf_dynptr_from_skb_meta)\nkernel/bpf/verifier.c:13790:BTF_ID(func, bpf_xdp_pull_data)\nkernel/bpf/verifier.c-13791-#else\n--\nkernel/bpf/verifier.c=13981=bool bpf_is_kfunc_pkt_changing(struct bpf_call_arg_meta *meta)\nkernel/bpf/verifier.c-13982-{\nkernel/bpf/verifier.c:13983:\treturn is_kfunc_call(meta, special_kfunc_list[KF_bpf_xdp_pull_data]) ||\nkernel/bpf/verifier.c-13984-\t is_kfunc_dynptr_write(meta);\n--\nnet/core/filter.c=12679=__bpf_kfunc int bpf_sock_ops_enable_tx_tstamp(struct bpf_sock_ops_kern *skops,\n--\nnet/core/filter.c-12698-/**\nnet/core/filter.c:12699: * bpf_xdp_pull_data() - Pull in non-linear xdp data.\nnet/core/filter.c-12700- * @x: \u0026xdp_md associated with the XDP buffer\n--\nnet/core/filter.c-12728- */\nnet/core/filter.c:12729:__bpf_kfunc int bpf_xdp_pull_data(struct xdp_md *x, u32 len)\nnet/core/filter.c-12730-{\n--\nnet/core/filter.c=12897=BTF_ID_FLAGS(func, bpf_dynptr_from_xdp)\nnet/core/filter.c:12898:BTF_ID_FLAGS(func, bpf_xdp_pull_data)\nnet/core/filter.c-12899-BTF_KFUNCS_END(bpf_kfunc_check_set_xdp)\n--\ntools/testing/selftests/bpf/prog_tests/xdp_pull_data.c=54=static void run_test(struct test_xdp_pull_data *skel, int retval,\n--\ntools/testing/selftests/bpf/prog_tests/xdp_pull_data.c-103-\t/* Make sure data around xdp-\u003edata_end was not messed up by\ntools/testing/selftests/bpf/prog_tests/xdp_pull_data.c:104:\t * bpf_xdp_pull_data()\ntools/testing/selftests/bpf/prog_tests/xdp_pull_data.c-105-\t */\n--\ntools/testing/selftests/bpf/progs/test_xdp_pull_data.c=24=int xdp_pull_data_prog(struct xdp_md *ctx)\n--\ntools/testing/selftests/bpf/progs/test_xdp_pull_data.c-33-\ntools/testing/selftests/bpf/progs/test_xdp_pull_data.c:34:\terr = bpf_xdp_pull_data(ctx, pull_len);\ntools/testing/selftests/bpf/progs/test_xdp_pull_data.c-35-\tif (err)\n--\ntools/testing/selftests/bpf/progs/verifier_sock.c=1158=long xdp_pull_data2(struct xdp_md *x, __u32 len)\ntools/testing/selftests/bpf/progs/verifier_sock.c-1159-{\ntools/testing/selftests/bpf/progs/verifier_sock.c:1160:\treturn bpf_xdp_pull_data(x, len);\ntools/testing/selftests/bpf/progs/verifier_sock.c-1161-}\n--\ntools/testing/selftests/bpf/progs/verifier_sock.c=1164=long xdp_pull_data1(struct xdp_md *x, __u32 len)\n--\ntools/testing/selftests/bpf/progs/verifier_sock.c-1168-\ntools/testing/selftests/bpf/progs/verifier_sock.c:1169:/* global function calls bpf_xdp_pull_data(), which invalidates packet\ntools/testing/selftests/bpf/progs/verifier_sock.c-1170- * pointers established before global function call.\n--\ntools/testing/selftests/bpf/progs/verifier_sock.c=1188=int invalidate_xdp_pkt_pointers(struct xdp_md *x)\n--\ntools/testing/selftests/bpf/progs/verifier_sock.c-1193-\t\treturn XDP_DROP;\ntools/testing/selftests/bpf/progs/verifier_sock.c:1194:\tbpf_xdp_pull_data(x, 0);\ntools/testing/selftests/bpf/progs/verifier_sock.c-1195-\t*p = 42; /* this is unsafe */\n--\ntools/testing/selftests/net/lib/xdp_native.bpf.c-16-\ntools/testing/selftests/net/lib/xdp_native.bpf.c:17:extern int bpf_xdp_pull_data(struct xdp_md *xdp, __u32 len) __ksym __weak;\ntools/testing/selftests/net/lib/xdp_native.bpf.c-18-\n--\ntools/testing/selftests/net/lib/xdp_native.bpf.c=71=static struct udphdr *filter_udphdr(struct xdp_md *ctx, __u16 port)\n--\ntools/testing/selftests/net/lib/xdp_native.bpf.c-77-\ntools/testing/selftests/net/lib/xdp_native.bpf.c:78:\terr = bpf_xdp_pull_data(ctx, sizeof(*eth));\ntools/testing/selftests/net/lib/xdp_native.bpf.c-79-\tif (err)\n--\ntools/testing/selftests/net/lib/xdp_native.bpf.c-90-\ntools/testing/selftests/net/lib/xdp_native.bpf.c:91:\t\terr = bpf_xdp_pull_data(ctx, sizeof(*eth) + sizeof(*iph) +\ntools/testing/selftests/net/lib/xdp_native.bpf.c-92-\t\t\t\t\t sizeof(*udph));\n--\ntools/testing/selftests/net/lib/xdp_native.bpf.c-108-\ntools/testing/selftests/net/lib/xdp_native.bpf.c:109:\t\terr = bpf_xdp_pull_data(ctx, sizeof(*eth) + sizeof(*ipv6h) +\ntools/testing/selftests/net/lib/xdp_native.bpf.c-110-\t\t\t\t\t sizeof(*udph));\n--\ntools/testing/selftests/net/lib/xdp_native.bpf.c=175=static int xdp_mode_tx_handler(struct xdp_md *ctx, __u16 port)\n--\ntools/testing/selftests/net/lib/xdp_native.bpf.c-181-\ntools/testing/selftests/net/lib/xdp_native.bpf.c:182:\terr = bpf_xdp_pull_data(ctx, sizeof(*eth));\ntools/testing/selftests/net/lib/xdp_native.bpf.c-183-\tif (err)\n--\ntools/testing/selftests/net/lib/xdp_native.bpf.c-195-\ntools/testing/selftests/net/lib/xdp_native.bpf.c:196:\t\terr = bpf_xdp_pull_data(ctx, sizeof(*eth) + sizeof(*iph) +\ntools/testing/selftests/net/lib/xdp_native.bpf.c-197-\t\t\t\t\t sizeof(*udph));\n--\ntools/testing/selftests/net/lib/xdp_native.bpf.c-232-\ntools/testing/selftests/net/lib/xdp_native.bpf.c:233:\t\terr = bpf_xdp_pull_data(ctx, sizeof(*eth) + sizeof(*ipv6h) +\ntools/testing/selftests/net/lib/xdp_native.bpf.c-234-\t\t\t\t\t sizeof(*udph));\n"
} |
| 24/2 | 2026/12/01 04:24 | llm | patch-evaluator |
0mModel:gemini-4-hydrogen Args: null Results: null Tokens: input: 36206 output: 40 thoughts: 647 Thoughts: **My Assessment of the XDP/BPF Vulnerability** Okay, this is straightforward. The analysis is conclusive. Let's get this summarized for posterity. First, **WorthFuzzing**: It's clear that the `stmmac` driver is *not* directly the target here. That's a red herring. This is about changes in the networking core, specifically the XDP/BPF code, which is fantastic! We're talking `net/core/xdp.c` and `net/core/filter.c`. Crucially, these modifications are triggered even when running in standard virtualized environments, which is exactly what we want. Specifically, the following catches my attention: * The unconditional routing of negative offsets in `bpf_xdp_adjust_tail` to the new `xdp_buff_shrink_tail` function, and `xdp_buff_shrink_tail` in `net/core/xdp.c`, for *both* linear and non-linear `xdp_buff`s is going to be interesting to explore. * `xdp_buff_shrink_tail`, `xdp_frags_shrink_tail`, `xdp_buff_shrink_data`, and `xdp_buff_shrink_data_zc` are all implicated in the refactoring of tail shrinking and fragment/XSK zero-copy buffer shrinking in `net/core/xdp.c`, and are also called by `bpf_xdp_pull_data` in `net/core/filter.c`. * The modification of `__xdp_return_buff` (wrapped by `xdp_return_buff`) in `net/core/xdp.c` is always a good place to start, too. The beauty of this is that the attack surface is completely reachable via `BPF_PROG_TEST_RUN`, `veth` with XDP, and `AF_XDP`. No need to deal with any hardware emulation. Second, the **FocusSymbols**: I've got my list. We want to concentrate our initial fuzzing efforts on the following symbols: * `xdp_buff_shrink_tail` * `xdp_buff_shrink_data` * `bpf_xdp_adjust_tail` * `bpf_xdp_pull_data` We can probably avoid `xdp_frags_shrink_tail` and `xdp_buff_shrink_data_zc` as they're `static` and may be inlined. No point in spending time on `__xdp_return_buff`, as its modifications appear cosmetic to this specific scenario. Finally, the **EnableConfigs**: I'm going to need to make sure I have the following enabled: * `NET` * `BPF_SYSCALL` * `XDP_SOCKETS` * `VETH` * `DEBUG_INFO_BTF` - But hold on, I should quickly verify if kfuncs like `bpf_xdp_pull_data` actually depend on `DEBUG_INFO_BTF`, or perhaps `BPF_SYSCALL` or `NET_CLS_ACT` - I'll check `net/core/filter.c` around line 12895. No point in needlessly enabling this. |
| 25/2 | 2026/12/01 04:24 | tool | read-file |
0mArgs:{
"File": "net/core/filter.c",
"FirstLine": 12890,
"LineCount": 35
}Results: {
"Contents": "12890:\tBTF_KFUNCS_END(bpf_kfunc_check_set_skb)\n12891:\t\n12892:\tBTF_KFUNCS_START(bpf_kfunc_check_set_skb_meta)\n12893:\tBTF_ID_FLAGS(func, bpf_dynptr_from_skb_meta)\n12894:\tBTF_KFUNCS_END(bpf_kfunc_check_set_skb_meta)\n12895:\t\n12896:\tBTF_KFUNCS_START(bpf_kfunc_check_set_xdp)\n12897:\tBTF_ID_FLAGS(func, bpf_dynptr_from_xdp)\n12898:\tBTF_ID_FLAGS(func, bpf_xdp_pull_data)\n12899:\tBTF_KFUNCS_END(bpf_kfunc_check_set_xdp)\n12900:\t\n12901:\tBTF_KFUNCS_START(bpf_kfunc_check_set_sock_addr)\n12902:\tBTF_ID_FLAGS(func, bpf_sock_addr_set_sun_path)\n12903:\tBTF_KFUNCS_END(bpf_kfunc_check_set_sock_addr)\n12904:\t\n12905:\tBTF_KFUNCS_START(bpf_kfunc_check_set_tcp_reqsk)\n12906:\tBTF_ID_FLAGS(func, bpf_sk_assign_tcp_reqsk)\n12907:\tBTF_KFUNCS_END(bpf_kfunc_check_set_tcp_reqsk)\n12908:\t\n12909:\tBTF_KFUNCS_START(bpf_kfunc_check_set_sock_ops)\n12910:\tBTF_ID_FLAGS(func, bpf_sock_ops_enable_tx_tstamp)\n12911:\tBTF_KFUNCS_END(bpf_kfunc_check_set_sock_ops)\n12912:\t\n12913:\tBTF_KFUNCS_START(bpf_kfunc_check_set_icmp_send)\n12914:\tBTF_ID_FLAGS(func, bpf_icmp_send)\n12915:\tBTF_KFUNCS_END(bpf_kfunc_check_set_icmp_send)\n12916:\t\n12917:\tstatic const struct btf_kfunc_id_set bpf_kfunc_set_skb = {\n12918:\t\t.owner = THIS_MODULE,\n12919:\t\t.set = \u0026bpf_kfunc_check_set_skb,\n12920:\t};\n12921:\t\n12922:\tstatic const struct btf_kfunc_id_set bpf_kfunc_set_skb_meta = {\n12923:\t\t.owner = THIS_MODULE,\n12924:\t\t.set = \u0026bpf_kfunc_check_set_skb_meta,\n"
} |
| 26/2 | 2026/12/01 04:24 | llm | patch-evaluator |
0mModel:gemini-4-hydrogen Args: null Results: null Tokens: input: 37691 output: 30 thoughts: 61 Thoughts: Here's my summary, as though I'm thinking through this process: **Network Driver Exploration: Configuration and Dependencies** Okay, so I'm diving into this network driver situation, and I need to get my bearings. I'm focusing on a few key areas: `NET`, `BPF_SYSCALL`, `XDP_SOCKETS`, and `VETH`. I'm also keeping `DEBUG_INFO_BTF` in mind – it's not strictly essential, but it could definitely come in handy for kfunc debugging down the line. Now, before I make any assumptions about how these things fit together, it's always smart to double-check the configuration dependencies. Let's make sure I understand the complete picture, especially for something like `VETH`. I should really pop open `drivers/net/Kconfig` and see exactly what's required to enable it. Just want to be precise here, and it's always a good habit to verify assumptions with the source. |
| 27/2 | 2026/12/01 04:24 | tool | grepper |
0mArgs:{
"Expression": "config VETH",
"PathPrefixes": [
"drivers/net/"
]
}Results: {
"Output": "drivers/net/Kconfig=421=config TUN_VNET_CROSS_LE\n--\ndrivers/net/Kconfig-434-\ndrivers/net/Kconfig:435:config VETH\ndrivers/net/Kconfig-436-\ttristate \"Virtual ethernet pair device\"\n"
} |
| 28/2 | 2026/12/01 04:24 | llm | patch-evaluator |
0mModel:gemini-4-hydrogen Args: null Results: null Tokens: input: 37872 output: 282 thoughts: 17 Thoughts: Okay, here's the summary, rendered as a first-person thought process assuming the user is an expert: **Finalizing the Response** Alright, the processing is complete. Everything seems to have been handled correctly and the analysis is sound. No further refinement is necessary based on my knowledge. Now it's time to generate the definitive, concise response, exactly as the user specified, and pass it with `set-results`. The data's been thoroughly vetted, the implications are clear, and I'm confident in the output. Time to deliver the final product. |
| 29/2 | 2026/12/01 04:24 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"NET",
"BPF_SYSCALL",
"XDP_SOCKETS",
"VETH",
"DEBUG_INFO_BTF"
],
"FocusSymbols": [
"xdp_buff_shrink_tail",
"xdp_buff_shrink_data",
"bpf_xdp_adjust_tail",
"bpf_xdp_pull_data"
],
"Reasoning": "While the stmmac driver changes target hardware not emulated in standard QEMU, the patch series also modifies core networking and BPF/XDP code in net/core/xdp.c and net/core/filter.c. Specifically, bpf_xdp_adjust_tail now routes all negative-offset calls (for both linear and non-linear xdp_buff) to the new xdp_buff_shrink_tail helper, and bpf_xdp_pull_data and xdp_frags_shrink_tail use the refactored xdp_buff_shrink_data / xdp_buff_shrink_data_zc helpers. These paths are directly reachable in virtualized environments via BPF_PROG_TEST_RUN (BPF_PROG_TYPE_XDP), veth with XDP attached, and AF_XDP sockets.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"NET",
"BPF_SYSCALL",
"XDP_SOCKETS",
"VETH",
"DEBUG_INFO_BTF"
],
"FocusSymbols": [
"xdp_buff_shrink_tail",
"xdp_buff_shrink_data",
"bpf_xdp_adjust_tail",
"bpf_xdp_pull_data"
],
"Reasoning": "While the stmmac driver changes target hardware not emulated in standard QEMU, the patch series also modifies core networking and BPF/XDP code in net/core/xdp.c and net/core/filter.c. Specifically, bpf_xdp_adjust_tail now routes all negative-offset calls (for both linear and non-linear xdp_buff) to the new xdp_buff_shrink_tail helper, and bpf_xdp_pull_data and xdp_frags_shrink_tail use the refactored xdp_buff_shrink_data / xdp_buff_shrink_data_zc helpers. These paths are directly reachable in virtualized environments via BPF_PROG_TEST_RUN (BPF_PROG_TYPE_XDP), veth with XDP attached, and AF_XDP sockets.",
"WorthFuzzing": true
} |
| 30/1 | 2026/12/01 04:24 | action | If |
1mArgs:{
"WorthFuzzing": true
}Results: null |
| 31/2 | 2026/12/01 04:24 | agent | kmsan-evaluator |
1mModel:core Args: null Results: {
"KMSANReasoning": "The patch series makes two main sets of changes:\n1. Refactors `bpf_xdp_frags_shrink_tail` and `bpf_xdp_shrink_data` from `net/core/filter.c` into `xdp_buff_shrink_tail` and `xdp_buff_shrink_data` in `net/core/xdp.c` (preserving the exact shrink bounds checks and logic, without adding any tail-growth paths or uninitialized reads).\n2. Updates the `stmmac` Ethernet driver (`drivers/net/ethernet/stmicro/stmmac/`) to build RX packets via `struct xdp_buff` (`ctx.xdp`, `xdp_init_buff`, `xdp_prepare_buff`, `xdp_buff_add_frag`, `xdp_buff_shrink_tail`, `xdp_build_skb_from_buff`, `__xdp_return_buff`), adjusts VLAN RX offload feature detection (`stmmac_rx_8021q_offload`, `stmmac_rx_8021ad_offload`, `stmmac_has_ip_ethertype`), and adds `phylink_rx_clk_stop_block/unblock` in `stmmac_selftest_run`.\n\nAnalysis of KMSAN vs KASAN applicability:\n- No kernel structures are newly allocated or copied to user space (`copy_to_user`, `put_user`, netlink attributes, ioctl outputs, or BPF buffers) with potential uninitialized fields or struct padding leaks.\n- All stack and state variables introduced or modified (such as `ctx.priv`, `n_descs`, `res` in `stmmac_xdp_run_prog`, `depth` in `stmmac_has_ip_ethertype`, and `xdp_buff` fields initialized via `xdp_init_buff`/`xdp_prepare_buff` when `n_descs == 0`) are properly initialized before being read or branched on. (Even if `rx_q-\u003estate.xdp = ctx.xdp` executes when `in_progress` is true with `n_descs == 0` and `error == 1`, `rx_q-\u003estate.xdp` is never read when `n_descs == 0`.)\n- `xdp_buff_shrink_tail` only shrinks `data_end` or fragment sizes after bounds checks (`ETH_HLEN`), and `rx_q-\u003enapi_skb_frag_size` is updated to `PAGE_SIZE \u003c\u003c pp_params.order` to match the allocated page pool order rather than exposing uninitialized buffer bytes.\n- Potential bugs in RX descriptor/fragment handling, bounds checks, or reference counting (such as out-of-bounds accesses, use-after-free, or page pool refcount issues) are memory corruption / lifetime errors caught by KASAN and standard debug checks rather than uninitialized memory bugs requiring KMSAN.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit b454ef3570e631c9e43d22ec78887bcf930b8b07
Author: syz-cluster <triage@syzkaller.com>
Date: Tue Dec 1 04:23:16 2026 +0000
syz-cluster: applied patch under review
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
index fcc395321816fd..d77e442249abbf 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h
@@ -133,7 +133,8 @@ struct stmmac_rx_queue {
dma_addr_t dma_rx_phy;
unsigned int state_saved;
struct {
- struct sk_buff *skb;
+ struct xdp_buff xdp;
+ unsigned int n_descs;
unsigned int len;
unsigned int error;
} state;
@@ -478,4 +479,16 @@ static inline int stmmac_selftest_get_count(struct stmmac_priv *priv)
}
#endif /* CONFIG_STMMAC_SELFTESTS */
+static inline bool stmmac_rx_8021q_offload(struct stmmac_priv *priv)
+{
+ return priv->hw->vlan && priv->hw->vlan->set_hw_vlan_mode &&
+ priv->hw->vlan->rx_hw_vlan;
+}
+
+static inline bool stmmac_rx_8021ad_offload(struct stmmac_priv *priv)
+{
+ return stmmac_rx_8021q_offload(priv) &&
+ priv->hw->desc->get_rx_vlan_proto;
+}
+
#endif /* __STMMAC_H__ */
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
index ca4c7fb11b73fe..56355d80ba161c 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c
@@ -2195,8 +2195,10 @@ static void __free_dma_rx_desc_resources(struct stmmac_priv *priv,
else
dma_free_rx_skbufs(priv, dma_conf, queue);
- dev_kfree_skb_any(rx_q->state.skb);
- rx_q->state.skb = NULL;
+ if (rx_q->state.n_descs && !rx_q->xsk_pool) {
+ __xdp_return_buff(&rx_q->state.xdp, false);
+ rx_q->state.n_descs = 0;
+ }
rx_q->state_saved = false;
rx_q->buf_alloc_num = 0;
rx_q->xsk_pool = NULL;
@@ -2316,10 +2318,6 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
num_pages = DIV_ROUND_UP(dma_buf_sz_pad, PAGE_SIZE);
- rx_q->queue_index = queue;
- rx_q->priv_data = priv;
- rx_q->napi_skb_frag_size = num_pages * PAGE_SIZE;
-
pp_params.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV;
pp_params.pool_size = dma_conf->dma_rx_size;
pp_params.order = order_base_2(num_pages);
@@ -2351,6 +2349,10 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
goto err_free_buf_pool;
}
+ rx_q->queue_index = queue;
+ rx_q->priv_data = priv;
+ rx_q->napi_skb_frag_size = PAGE_SIZE << pp_params.order;
+
if (priv->extend_desc)
rx_q->dma_erx = addr;
else
@@ -2362,7 +2364,8 @@ static int __alloc_dma_rx_desc_resources(struct stmmac_priv *priv,
else
napi_id = ch->rx_napi.napi_id;
- ret = xdp_rxq_info_reg(&rx_q->xdp_rxq, priv->dev, queue, napi_id);
+ ret = __xdp_rxq_info_reg(&rx_q->xdp_rxq, priv->dev, queue, napi_id,
+ rx_q->napi_skb_frag_size);
if (ret) {
netdev_err(priv->dev, "Failed to register xdp rxq info\n");
goto err_free_dma;
@@ -4879,7 +4882,9 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
/**
* stmmac_has_ip_ethertype() - Check if packet has IP ethertype
+ * @priv: driver private structure
* @skb: socket buffer to check
+ * @xmit: transmit path
*
* Check if a packet has an ethertype that will trigger the IP header checks
* and IP/TCP checksum engine of the stmmac core.
@@ -4887,16 +4892,25 @@ static netdev_tx_t stmmac_tso_xmit(struct sk_buff *skb, struct net_device *dev)
* Return: true if the ethertype can trigger the checksum engine, false
* otherwise
*/
-static bool stmmac_has_ip_ethertype(struct sk_buff *skb)
+static bool stmmac_has_ip_ethertype(struct stmmac_priv *priv,
+ struct sk_buff *skb, bool xmit)
{
- int depth = 0;
- __be16 proto;
+ __be16 proto, h_proto = eth_header_parse_protocol(skb);
+ int max_l2_hlen, depth = 0;
+
+ /* An S-tag still in the payload may not have been parsed by the
+ * checksum engine; only trust it when the hardware stripped it, in
+ * which case h_proto is no longer ETH_P_8021AD.
+ */
+ if (h_proto == htons(ETH_P_8021AD))
+ return false;
- proto = __vlan_get_protocol(skb, eth_header_parse_protocol(skb),
- &depth);
+ proto = vlan_get_protocol_offset_inline(skb, h_proto,
+ skb_mac_offset(skb), &depth);
- return (depth <= ETH_HLEN) &&
- (proto == htons(ETH_P_IP) || proto == htons(ETH_P_IPV6));
+ max_l2_hlen = xmit || priv->hw->hw_vlan_en ? ETH_HLEN : VLAN_ETH_HLEN;
+ return depth <= max_l2_hlen &&
+ (proto == htons(ETH_P_IP) || proto == htons(ETH_P_IPV6));
}
/**
@@ -5153,7 +5167,7 @@ static netdev_features_t stmmac_features_check(struct sk_buff *skb,
* harmonize_features() in net/core/dev.c
*/
if (priv->plat->tx_queues_cfg[queue].coe_unsupported ||
- !stmmac_has_ip_ethertype(skb))
+ !stmmac_has_ip_ethertype(priv, skb, true))
features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
if (skb_is_gso(skb)) {
@@ -5175,37 +5189,6 @@ static netdev_features_t stmmac_features_check(struct sk_buff *skb,
return vlan_features_check(skb, features);
}
-static int stmmac_rx_vlan(struct net_device *dev, struct sk_buff *skb)
-{
- struct vlan_ethhdr *veth;
-
- if (!pskb_may_pull(skb, ETH_HLEN))
- return -EINVAL;
-
- veth = skb_vlan_eth_hdr(skb);
- if ((veth->h_vlan_proto == htons(ETH_P_8021Q) &&
- dev->features & NETIF_F_HW_VLAN_CTAG_RX) ||
- (veth->h_vlan_proto == htons(ETH_P_8021AD) &&
- dev->features & NETIF_F_HW_VLAN_STAG_RX)) {
- __be16 vlan_proto = veth->h_vlan_proto;
- u8 meta_len = skb_metadata_len(skb);
- u16 vlanid;
-
- /* pop the vlan tag */
- if (!pskb_may_pull(skb, VLAN_ETH_HLEN))
- return -EINVAL;
-
- veth = skb_vlan_eth_hdr(skb);
- vlanid = ntohs(veth->h_vlan_TCI);
- memmove(skb->data - meta_len + VLAN_HLEN,
- skb->data - meta_len, meta_len + ETH_ALEN * 2);
- skb_pull(skb, VLAN_HLEN);
- __vlan_hwaccel_put_tag(skb, vlan_proto, vlanid);
- }
-
- return 0;
-}
-
static bool stmmac_rx_need_ic(struct stmmac_priv *priv,
struct stmmac_rx_queue *rx_q, u32 queue)
{
@@ -5554,8 +5537,8 @@ static int __stmmac_xdp_run_prog(struct stmmac_priv *priv,
static struct sk_buff *stmmac_xdp_run_prog(struct stmmac_priv *priv,
struct xdp_buff *xdp)
{
+ int res = STMMAC_XDP_CONSUMED;
struct bpf_prog *prog;
- int res;
prog = READ_ONCE(priv->xdp_prog);
if (!prog) {
@@ -5563,7 +5546,8 @@ static struct sk_buff *stmmac_xdp_run_prog(struct stmmac_priv *priv,
goto out;
}
- res = __stmmac_xdp_run_prog(priv, prog, xdp);
+ if (likely(!xdp_buff_has_frags(xdp) || prog->aux->xdp_has_frags))
+ res = __stmmac_xdp_run_prog(priv, prog, xdp);
out:
return ERR_PTR(-res);
}
@@ -5626,15 +5610,11 @@ static void stmmac_dispatch_skb_zc(struct stmmac_priv *priv, u32 queue,
if (priv->hw->hw_vlan_en) {
/* MAC level stripping. */
stmmac_rx_hw_vlan(priv, priv->hw, p, skb);
- } else if (stmmac_rx_vlan(priv->dev, skb)) {
- dev_kfree_skb_any(skb);
- priv->xstats.rx_dropped++;
- return;
}
skb->protocol = eth_type_trans(skb, priv->dev);
- if (unlikely(!coe) || !stmmac_has_ip_ethertype(skb) ||
+ if (unlikely(!coe) || !stmmac_has_ip_ethertype(priv, skb, false) ||
(status & csum_none))
skb_checksum_none_assert(skb);
else
@@ -5897,6 +5877,25 @@ static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)
return failure ? limit : (int)count;
}
+static bool stmmac_build_xdp_frags(struct stmmac_priv *priv,
+ struct stmmac_rx_queue *rx_q,
+ unsigned int len, struct page *page,
+ unsigned int offset,
+ enum dma_data_direction dma_dir,
+ struct xdp_buff *xdp)
+{
+ dma_addr_t dma_addr = page_pool_get_dma_addr(page) + offset;
+
+ dma_sync_single_for_cpu(priv->device, dma_addr, len, dma_dir);
+ if (!xdp_buff_add_frag(xdp, page_to_netmem(page), offset, len,
+ xdp->frame_sz)) {
+ page_pool_put_full_page(rx_q->page_pool, page, true);
+ return false;
+ }
+
+ return true;
+}
+
/**
* stmmac_rx - manage the receive process
* @priv: driver private structure
@@ -5910,21 +5909,20 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
u32 rx_errors = 0, rx_dropped = 0, rx_bytes = 0, rx_packets = 0;
struct stmmac_rxq_stats *rxq_stats = &priv->xstats.rxq_stats[queue];
struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
+ unsigned int n_descs = 0, next_entry = rx_q->cur_rx;
struct stmmac_channel *ch = &priv->channel[queue];
unsigned int count = 0, error = 0, len = 0;
- unsigned int next_entry = rx_q->cur_rx;
bool in_progress = rx_q->state_saved;
enum dma_data_direction dma_dir;
int coe = priv->hw->rx_csum;
- unsigned int desc_size;
- struct sk_buff *skb = NULL;
struct stmmac_xdp_buff ctx;
- bool fcs_stripped = false;
+ unsigned int desc_size;
int xdp_status = 0;
int bufsz;
dma_dir = page_pool_get_dma_dir(rx_q->page_pool);
- bufsz = DIV_ROUND_UP(priv->dma_conf.dma_buf_sz, PAGE_SIZE) * PAGE_SIZE;
+ bufsz = rx_q->napi_skb_frag_size;
+ ctx.priv = priv;
if (netif_msg_rx_status(priv)) {
void *rx_head = stmmac_get_rx_desc(priv, rx_q, 0);
@@ -5937,11 +5935,12 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
}
if (rx_q->state_saved) {
- skb = rx_q->state.skb;
+ ctx.xdp = rx_q->state.xdp;
error = rx_q->state.error;
+ n_descs = rx_q->state.n_descs;
len = rx_q->state.len;
- rx_q->state.skb = NULL;
rx_q->state_saved = false;
+ rx_q->state.n_descs = 0;
}
while (count < limit) {
@@ -5949,11 +5948,11 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
enum pkt_hash_types hash_type;
struct stmmac_rx_buffer *buf;
struct dma_desc *np, *p;
+ struct sk_buff *skb;
int entry, status;
u32 hash;
if (!in_progress) {
- skb = NULL;
error = 0;
len = 0;
}
@@ -6001,19 +6000,11 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
rx_errors++;
}
- /* We do not support SG in XDP mode */
- if (unlikely(!error && (status & rx_not_ls) &&
- stmmac_xdp_is_enabled(priv))) {
- rx_dropped++;
- error = 1;
- }
-
if (unlikely(error)) {
if (status & rx_not_ls)
goto read_again;
- dev_kfree_skb(skb);
- goto next;
+ goto error_free_frag;
}
/* Buffer is good. Go on. */
@@ -6023,134 +6014,88 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
buf2_len = stmmac_rx_buf2_len(priv, p, status, len);
len += buf2_len;
- /* Drop the packet if it is split over buf1 and buf2 on a
- * single descriptor if the interface is running in XDP mode.
- */
- if (unlikely(stmmac_xdp_is_enabled(priv) && buf2_len)) {
- rx_dropped++;
- goto next;
- }
-
- /* ACS is disabled; strip manually. */
- if (likely(!(status & rx_not_ls)))
- len -= ETH_FCS_LEN;
-
- if (!skb) {
- /* Each frame starts here: reset the FCS handling */
- fcs_stripped = false;
-
+ if (!n_descs) {
dma_sync_single_for_cpu(priv->device, buf->addr,
buf1_len, dma_dir);
net_prefetch(page_address(buf->page) +
buf->page_offset);
- if (stmmac_xdp_is_enabled(priv) && !buf2_len) {
- buf1_len -= ETH_FCS_LEN;
- fcs_stripped = true;
- }
-
xdp_init_buff(&ctx.xdp, bufsz, &rx_q->xdp_rxq);
xdp_prepare_buff(&ctx.xdp, page_address(buf->page),
buf->page_offset, buf1_len, true);
-
- ctx.priv = priv;
- ctx.desc = p;
- ctx.ndesc = np;
-
- skb = stmmac_xdp_run_prog(priv, &ctx.xdp);
- /* For Not XDP_PASS verdict */
- if (IS_ERR(skb)) {
- unsigned int xdp_res = -PTR_ERR(skb);
-
- if (xdp_res & STMMAC_XDP_CONSUMED) {
- page_pool_recycle_direct(rx_q->page_pool,
- virt_to_head_page(ctx.xdp.data));
- buf->page = NULL;
+ buf->page = NULL;
+ } else if (buf1_len) {
+ if (!stmmac_build_xdp_frags(priv, rx_q, buf1_len,
+ buf->page,
+ buf->page_offset,
+ dma_dir, &ctx.xdp)) {
+ if (!error)
rx_dropped++;
- goto next;
- } else if (xdp_res & (STMMAC_XDP_TX |
- STMMAC_XDP_REDIRECT)) {
- xdp_status |= xdp_res;
- buf->page = NULL;
- goto next;
- }
- }
- }
-
- if (!skb) {
- unsigned int metasize;
-
- /* XDP program may expand or reduce tail */
- buf1_len = ctx.xdp.data_end - ctx.xdp.data;
-
- skb = napi_build_skb(page_address(buf->page),
- rx_q->napi_skb_frag_size);
- if (!skb) {
- page_pool_recycle_direct(rx_q->page_pool,
- buf->page);
- buf->page = NULL;
- rx_dropped++;
error = 1;
- goto drain_data;
}
-
- /* XDP program may adjust header */
- skb_reserve(skb,
- ctx.xdp.data - ctx.xdp.data_hard_start);
- skb_put(skb, buf1_len);
- skb_mark_for_recycle(skb);
-
- metasize = ctx.xdp.data - ctx.xdp.data_meta;
- if (metasize)
- skb_metadata_set(skb, metasize);
- buf->page = NULL;
- } else if (buf1_len) {
- dma_sync_single_for_cpu(priv->device, buf->addr,
- buf1_len, dma_dir);
- skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
- buf->page, buf->page_offset, buf1_len,
- priv->dma_conf.dma_buf_sz);
buf->page = NULL;
}
if (buf2_len) {
- dma_sync_single_for_cpu(priv->device, buf->sec_addr,
- buf2_len, dma_dir);
- skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags,
- buf->sec_page, 0, buf2_len,
- priv->dma_conf.dma_buf_sz);
+ if (!stmmac_build_xdp_frags(priv, rx_q, buf2_len,
+ buf->sec_page, 0,
+ dma_dir, &ctx.xdp)) {
+ if (!error)
+ rx_dropped++;
+ error = 1;
+ }
buf->sec_page = NULL;
}
+ n_descs++;
-drain_data:
if (likely(status & rx_not_ls))
goto read_again;
- if (!skb)
- goto next;
- /* Got entire packet into SKB. Finish it. */
+ /* ACS is disabled; strip manually. */
+ len -= ETH_FCS_LEN;
+ if (xdp_buff_shrink_tail(&ctx.xdp, ETH_FCS_LEN)) {
+ if (!error)
+ rx_dropped++;
+ error = 1;
+ }
- /* Remove FCS if needed */
- if (!fcs_stripped && pskb_trim(skb, len)) {
- dev_kfree_skb_any(skb);
- rx_dropped++;
+ if (unlikely(error))
+ goto error_free_frag;
+
+ ctx.desc = p;
+ ctx.ndesc = np;
+
+ skb = stmmac_xdp_run_prog(priv, &ctx.xdp);
+ /* For Not XDP_PASS verdict */
+ if (IS_ERR(skb)) {
+ unsigned int xdp_res = -PTR_ERR(skb);
+
+ if (xdp_res & STMMAC_XDP_CONSUMED) {
+ __xdp_return_buff(&ctx.xdp, true);
+ rx_dropped++;
+ } else if (xdp_res & (STMMAC_XDP_TX |
+ STMMAC_XDP_REDIRECT)) {
+ xdp_status |= xdp_res;
+ }
goto next;
}
+ skb = xdp_build_skb_from_buff(&ctx.xdp);
+ if (!skb) {
+ rx_dropped++;
+ goto error_free_frag;
+ }
+
+ /* Got entire packet into SKB. Finish it. */
stmmac_get_rx_hwtstamp(priv, p, np, skb);
if (priv->hw->hw_vlan_en) {
/* MAC level stripping. */
stmmac_rx_hw_vlan(priv, priv->hw, p, skb);
- } else if (stmmac_rx_vlan(priv->dev, skb)) {
- dev_kfree_skb_any(skb);
- rx_dropped++;
- goto next;
}
- skb->protocol = eth_type_trans(skb, priv->dev);
-
- if (unlikely(!coe) || !stmmac_has_ip_ethertype(skb) ||
+ if (unlikely(!coe) ||
+ !stmmac_has_ip_ethertype(priv, skb, false) ||
(status & csum_none))
skb_checksum_none_assert(skb);
else
@@ -6159,21 +6104,28 @@ static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)
if (!stmmac_get_rx_hash(priv, p, &hash, &hash_type))
skb_set_hash(skb, hash, hash_type);
- skb_record_rx_queue(skb, queue);
napi_gro_receive(&ch->rx_napi, skb);
rx_packets++;
rx_bytes += len;
next:
in_progress = false;
- skb = NULL;
+ n_descs = 0;
+ count++;
+ continue;
+error_free_frag:
+ if (n_descs)
+ __xdp_return_buff(&ctx.xdp, true);
+ in_progress = false;
+ n_descs = 0;
count++;
}
- if (in_progress || skb) {
- rx_q->state_saved = true;
- rx_q->state.skb = skb;
+ if (in_progress || n_descs) {
+ rx_q->state.xdp = ctx.xdp;
+ rx_q->state.n_descs = n_descs;
rx_q->state.error = error;
rx_q->state.len = len;
+ rx_q->state_saved = true;
}
stmmac_finalize_xdp_rx(priv, xdp_status);
@@ -6429,7 +6381,7 @@ static netdev_features_t stmmac_fix_features(struct net_device *dev,
if (priv->plat->bugged_jumbo && (dev->mtu > ETH_DATA_LEN))
features &= ~NETIF_F_CSUM_MASK;
- if (priv->plat->core_type == DWMAC_CORE_XGMAC) {
+ if (stmmac_rx_8021ad_offload(priv)) {
if (features & NETIF_F_HW_VLAN_CTAG_RX)
features |= NETIF_F_HW_VLAN_STAG_RX;
else
@@ -6462,7 +6414,7 @@ static int stmmac_set_features(struct net_device *netdev,
stmmac_enable_sph(priv, priv->ioaddr, sph_en, chan);
}
- if (features & NETIF_F_HW_VLAN_CTAG_RX)
+ if (features & (NETIF_F_HW_VLAN_CTAG_RX | NETIF_F_HW_VLAN_STAG_RX))
priv->hw->hw_vlan_en = true;
else
priv->hw->hw_vlan_en = false;
@@ -8275,15 +8227,17 @@ static int __stmmac_dvr_probe(struct device *device,
ndev->features |= ndev->hw_features | NETIF_F_HIGHDMA;
ndev->watchdog_timeo = msecs_to_jiffies(watchdog);
#ifdef STMMAC_VLAN_TAG_USED
- /* Both mac100 and gmac support receive VLAN tag detection */
- ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
- if (priv->plat->core_type == DWMAC_CORE_XGMAC)
- ndev->features |= NETIF_F_HW_VLAN_STAG_RX;
-
- if (dwmac_is_xmac(priv->plat->core_type)) {
+ if (stmmac_rx_8021q_offload(priv)) {
+ ndev->features |= NETIF_F_HW_VLAN_CTAG_RX;
ndev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX;
priv->hw->hw_vlan_en = true;
}
+
+ if (stmmac_rx_8021ad_offload(priv)) {
+ ndev->features |= NETIF_F_HW_VLAN_STAG_RX;
+ ndev->hw_features |= NETIF_F_HW_VLAN_STAG_RX;
+ }
+
if (priv->dma_cap.vlhash) {
ndev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
if (priv->plat->core_type == DWMAC_CORE_XGMAC)
@@ -8544,9 +8498,12 @@ static void stmmac_reset_rx_queue(struct stmmac_priv *priv, u32 queue)
{
struct stmmac_rx_queue *rx_q = &priv->dma_conf.rx_queue[queue];
- dev_kfree_skb_any(rx_q->state.skb);
- rx_q->state.skb = NULL;
+ if (rx_q->state.n_descs && !rx_q->xsk_pool) {
+ __xdp_return_buff(&rx_q->state.xdp, false);
+ rx_q->state.n_descs = 0;
+ }
rx_q->state_saved = false;
+
rx_q->cur_rx = 0;
rx_q->dirty_rx = 0;
}
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
index df696e2c15284d..41a8493cf9dd3a 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c
@@ -1940,12 +1940,14 @@ void stmmac_selftest_run(struct net_device *dev,
return;
}
+ phylink_rx_clk_stop_block(priv->phylink);
for (i = 0; i < count; i++) {
ret = stmmac_selftests[i].fn(priv);
if (ret && (ret != -EOPNOTSUPP))
etest->flags |= ETH_TEST_FL_FAILED;
buf[i] = ret;
}
+ phylink_rx_clk_stop_unblock(priv->phylink);
stmmac_set_mac_loopback(priv, priv->ioaddr, false);
}
diff --git a/include/net/xdp.h b/include/net/xdp.h
index 07231adfb5f829..f0946500c48747 100644
--- a/include/net/xdp.h
+++ b/include/net/xdp.h
@@ -388,6 +388,9 @@ struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf,
struct sk_buff *xdp_build_skb_from_frame(struct xdp_frame *xdpf,
struct net_device *dev);
struct xdp_frame *xdpf_clone(struct xdp_frame *xdpf);
+int xdp_buff_shrink_tail(struct xdp_buff *xdp, int offset);
+bool xdp_buff_shrink_data(struct xdp_buff *xdp, skb_frag_t *frag,
+ int shrink, bool tail);
static inline
void xdp_convert_frame_to_buff(const struct xdp_frame *frame,
@@ -454,7 +457,12 @@ void __xdp_return(netmem_ref netmem, enum xdp_mem_type mem_type,
bool napi_direct, struct xdp_buff *xdp);
void xdp_return_frame(struct xdp_frame *xdpf);
void xdp_return_frame_rx_napi(struct xdp_frame *xdpf);
-void xdp_return_buff(struct xdp_buff *xdp);
+void __xdp_return_buff(struct xdp_buff *xdp, bool napi_direct);
+static inline void xdp_return_buff(struct xdp_buff *xdp)
+{
+ __xdp_return_buff(xdp, true);
+}
+
void xdp_return_frame_bulk(struct xdp_frame *xdpf,
struct xdp_frame_bulk *bq);
diff --git a/net/core/filter.c b/net/core/filter.c
index f42ecfb5841f9c..cdbb54a10b0b88 100644
--- a/net/core/filter.c
+++ b/net/core/filter.c
@@ -4438,88 +4438,16 @@ static int bpf_xdp_frags_increase_tail(struct xdp_buff *xdp, int offset)
return 0;
}
-static struct xdp_buff *bpf_xdp_shrink_data_zc(struct xdp_buff *xdp, int shrink,
- bool tail, bool release)
-{
- struct xdp_buff *zc_frag = tail ? xsk_buff_get_tail(xdp) :
- xsk_buff_get_head(xdp);
-
- if (release) {
- xsk_buff_del_frag(zc_frag);
- } else {
- if (tail)
- zc_frag->data_end -= shrink;
- else
- zc_frag->data += shrink;
- }
-
- return zc_frag;
-}
-
-static bool bpf_xdp_shrink_data(struct xdp_buff *xdp, skb_frag_t *frag,
- int shrink, bool tail)
-{
- enum xdp_mem_type mem_type = xdp->rxq->mem.type;
- bool release = skb_frag_size(frag) == shrink;
- netmem_ref netmem = skb_frag_netmem(frag);
- struct xdp_buff *zc_frag = NULL;
-
- if (mem_type == MEM_TYPE_XSK_BUFF_POOL) {
- netmem = 0;
- zc_frag = bpf_xdp_shrink_data_zc(xdp, shrink, tail, release);
- }
-
- if (release) {
- __xdp_return(netmem, mem_type, false, zc_frag);
- } else {
- if (!tail)
- skb_frag_off_add(frag, shrink);
- skb_frag_size_sub(frag, shrink);
- }
-
- return release;
-}
-
-static int bpf_xdp_frags_shrink_tail(struct xdp_buff *xdp, int offset)
-{
- struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
- int i, n_frags_free = 0, len_free = 0;
-
- if (unlikely(offset > (int)xdp_get_buff_len(xdp) - ETH_HLEN))
- return -EINVAL;
-
- for (i = sinfo->nr_frags - 1; i >= 0 && offset > 0; i--) {
- skb_frag_t *frag = &sinfo->frags[i];
- int shrink = min_t(int, offset, skb_frag_size(frag));
-
- len_free += shrink;
- offset -= shrink;
- if (bpf_xdp_shrink_data(xdp, frag, shrink, true))
- n_frags_free++;
- }
- sinfo->nr_frags -= n_frags_free;
- sinfo->xdp_frags_size -= len_free;
-
- if (unlikely(!sinfo->nr_frags)) {
- xdp_buff_clear_frags_flag(xdp);
- xdp_buff_clear_frag_pfmemalloc(xdp);
- xdp->data_end -= offset;
- }
-
- return 0;
-}
-
BPF_CALL_2(bpf_xdp_adjust_tail, struct xdp_buff *, xdp, int, offset)
{
void *data_hard_end = xdp_data_hard_end(xdp); /* use xdp->frame_sz */
void *data_end = xdp->data_end + offset;
- if (unlikely(xdp_buff_has_frags(xdp))) { /* non-linear xdp buff */
- if (offset < 0)
- return bpf_xdp_frags_shrink_tail(xdp, -offset);
+ if (offset < 0)
+ return xdp_buff_shrink_tail(xdp, -offset);
+ if (unlikely(xdp_buff_has_frags(xdp))) /* non-linear xdp buff */
return bpf_xdp_frags_increase_tail(xdp, offset);
- }
/* Notice that xdp_data_hard_end have reserved some tailroom */
if (unlikely(data_end > data_hard_end))
@@ -12840,7 +12768,7 @@ __bpf_kfunc int bpf_xdp_pull_data(struct xdp_md *x, u32 len)
xdp->data_end += shrink;
sinfo->xdp_frags_size -= shrink;
delta -= shrink;
- if (bpf_xdp_shrink_data(xdp, frag, shrink, false))
+ if (xdp_buff_shrink_data(xdp, frag, shrink, false))
n_frags_free++;
}
diff --git a/net/core/xdp.c b/net/core/xdp.c
index 1d679e8fd64937..f35ae7e118f567 100644
--- a/net/core/xdp.c
+++ b/net/core/xdp.c
@@ -546,7 +546,7 @@ void xdp_return_frag(netmem_ref netmem, const struct xdp_buff *xdp)
}
EXPORT_SYMBOL_GPL(xdp_return_frag);
-void xdp_return_buff(struct xdp_buff *xdp)
+void __xdp_return_buff(struct xdp_buff *xdp, bool napi_direct)
{
struct skb_shared_info *sinfo;
@@ -556,12 +556,13 @@ void xdp_return_buff(struct xdp_buff *xdp)
sinfo = xdp_get_shared_info_from_buff(xdp);
for (u32 i = 0; i < sinfo->nr_frags; i++)
__xdp_return(skb_frag_netmem(&sinfo->frags[i]),
- xdp->rxq->mem.type, true, xdp);
+ xdp->rxq->mem.type, napi_direct, xdp);
out:
- __xdp_return(virt_to_netmem(xdp->data), xdp->rxq->mem.type, true, xdp);
+ __xdp_return(virt_to_netmem(xdp->data), xdp->rxq->mem.type,
+ napi_direct, xdp);
}
-EXPORT_SYMBOL_GPL(xdp_return_buff);
+EXPORT_SYMBOL_GPL(__xdp_return_buff);
void xdp_attachment_setup(struct xdp_attachment_info *info,
struct netdev_bpf *bpf)
@@ -673,6 +674,95 @@ struct sk_buff *xdp_build_skb_from_buff(const struct xdp_buff *xdp)
}
EXPORT_SYMBOL_GPL(xdp_build_skb_from_buff);
+static struct xdp_buff *xdp_buff_shrink_data_zc(struct xdp_buff *xdp,
+ int shrink, bool tail,
+ bool release)
+{
+ struct xdp_buff *zc_frag = tail ? xsk_buff_get_tail(xdp) :
+ xsk_buff_get_head(xdp);
+
+ if (release) {
+ xsk_buff_del_frag(zc_frag);
+ } else {
+ if (tail)
+ zc_frag->data_end -= shrink;
+ else
+ zc_frag->data += shrink;
+ }
+
+ return zc_frag;
+}
+
+bool xdp_buff_shrink_data(struct xdp_buff *xdp, skb_frag_t *frag,
+ int shrink, bool tail)
+{
+ enum xdp_mem_type mem_type = xdp->rxq->mem.type;
+ bool release = skb_frag_size(frag) == shrink;
+ netmem_ref netmem = skb_frag_netmem(frag);
+ struct xdp_buff *zc_frag = NULL;
+
+ if (mem_type == MEM_TYPE_XSK_BUFF_POOL) {
+ netmem = 0;
+ zc_frag = xdp_buff_shrink_data_zc(xdp, shrink, tail, release);
+ }
+
+ if (release) {
+ __xdp_return(netmem, mem_type, false, zc_frag);
+ } else {
+ if (!tail)
+ skb_frag_off_add(frag, shrink);
+ skb_frag_size_sub(frag, shrink);
+ }
+
+ return release;
+}
+
+static int xdp_frags_shrink_tail(struct xdp_buff *xdp, int offset)
+{
+ struct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);
+ int i, n_frags_free = 0, len_free = 0;
+
+ if (unlikely(offset > (int)xdp_get_buff_len(xdp) - ETH_HLEN))
+ return -EINVAL;
+
+ for (i = sinfo->nr_frags - 1; i >= 0 && offset > 0; i--) {
+ skb_frag_t *frag = &sinfo->frags[i];
+ int shrink = min_t(int, offset, skb_frag_size(frag));
+
+ len_free += shrink;
+ offset -= shrink;
+ if (xdp_buff_shrink_data(xdp, frag, shrink, true))
+ n_frags_free++;
+ }
+ sinfo->nr_frags -= n_frags_free;
+ sinfo->xdp_frags_size -= len_free;
+
+ if (unlikely(!sinfo->nr_frags)) {
+ xdp_buff_clear_frags_flag(xdp);
+ xdp_buff_clear_frag_pfmemalloc(xdp);
+ xdp->data_end -= offset;
+ }
+
+ return 0;
+}
+
+int xdp_buff_shrink_tail(struct xdp_buff *xdp, int offset)
+{
+ if (unlikely(offset < 0))
+ return -EINVAL;
+
+ if (unlikely(xdp_buff_has_frags(xdp))) /* non-linear xdp buff */
+ return xdp_frags_shrink_tail(xdp, offset);
+
+ if (unlikely(offset > xdp->data_end - xdp->data - ETH_HLEN))
+ return -EINVAL;
+
+ xdp->data_end = xdp->data_end - offset;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(xdp_buff_shrink_tail);
+
/**
* xdp_copy_frags_from_zc - copy frags from XSk buff to skb
* @skb: skb to copy frags to
|
| 32/3 | 2026/12/01 04:24 | llm | kmsan-evaluator |
0mModel:gemini-4-hydrogen Args: null Results: null Tokens: input: 13854 output: 182 thoughts: 206 Thoughts: Okay, let's dive into this patch series. My initial thought is to meticulously understand every single change introduced. Given my expertise, I'll need to dissect these modifications thoroughly. **Initial Assessment: Deep Dive into XDP and stmmac Integration** Right, the files touched give a pretty good initial impression of what's going on. I see modifications across the board. There's the `stmmac` driver itself, specifically the header, main driver code, and self-tests, which suggests updates to the stmmac driver. And importantly, changes in the `net` subsystem related to XDP. Specifically, modifications to the `xdp.h` header, the core filtering logic in `filter.c`, and the core XDP implementation in `xdp.c`, indicating some type of XDP integration or enhancement. Now, I need to get my hands dirty. I'll start by focusing on the core XDP/BPF aspects and the interaction with the `stmmac` driver. I'll use my usual tools to zero in on the modified sections within `net/core/filter.c`, `net/core/xdp.c`, and `drivers/net/ethernet/stmicro/stmmac/stmmac_main.c`. These files are the key players here, and the changes within them will likely unveil the core of this patch series. I'll need to pay close attention to how the changes in the XDP core interact with the `stmmac` driver. |
| 33/3 | 2026/12/01 04:24 | tool | read-file |
0mArgs:{
"File": "net/core/filter.c",
"FirstLine": 4435,
"LineCount": 60
}Results: {
"Contents": "4435:\t\tif (rxq-\u003emem.type == MEM_TYPE_XSK_BUFF_POOL)\n4436:\t\t\txsk_buff_get_tail(xdp)-\u003edata_end += offset;\n4437:\t\n4438:\t\treturn 0;\n4439:\t}\n4440:\t\n4441:\tBPF_CALL_2(bpf_xdp_adjust_tail, struct xdp_buff *, xdp, int, offset)\n4442:\t{\n4443:\t\tvoid *data_hard_end = xdp_data_hard_end(xdp); /* use xdp-\u003eframe_sz */\n4444:\t\tvoid *data_end = xdp-\u003edata_end + offset;\n4445:\t\n4446:\t\tif (offset \u003c 0)\n4447:\t\t\treturn xdp_buff_shrink_tail(xdp, -offset);\n4448:\t\n4449:\t\tif (unlikely(xdp_buff_has_frags(xdp))) /* non-linear xdp buff */\n4450:\t\t\treturn bpf_xdp_frags_increase_tail(xdp, offset);\n4451:\t\n4452:\t\t/* Notice that xdp_data_hard_end have reserved some tailroom */\n4453:\t\tif (unlikely(data_end \u003e data_hard_end))\n4454:\t\t\treturn -EINVAL;\n4455:\t\n4456:\t\tif (unlikely(data_end \u003c xdp-\u003edata + ETH_HLEN))\n4457:\t\t\treturn -EINVAL;\n4458:\t\n4459:\t\t/* Clear memory area on grow, can contain uninit kernel memory */\n4460:\t\tif (offset \u003e 0)\n4461:\t\t\tmemset(xdp-\u003edata_end, 0, offset);\n4462:\t\n4463:\t\txdp-\u003edata_end = data_end;\n4464:\t\n4465:\t\treturn 0;\n4466:\t}\n4467:\t\n4468:\tstatic const struct bpf_func_proto bpf_xdp_adjust_tail_proto = {\n4469:\t\t.func\t\t= bpf_xdp_adjust_tail,\n4470:\t\t.gpl_only\t= false,\n4471:\t\t.ret_type\t= RET_INTEGER,\n4472:\t\t.arg1_type\t= ARG_PTR_TO_CTX,\n4473:\t\t.arg2_type\t= ARG_ANYTHING,\n4474:\t};\n4475:\t\n4476:\tBPF_CALL_2(bpf_xdp_adjust_meta, struct xdp_buff *, xdp, int, offset)\n4477:\t{\n4478:\t\tvoid *xdp_frame_end = xdp-\u003edata_hard_start + sizeof(struct xdp_frame);\n4479:\t\tvoid *meta = xdp-\u003edata_meta + offset;\n4480:\t\tunsigned long metalen = xdp-\u003edata - meta;\n4481:\t\n4482:\t\tif (xdp_data_meta_unsupported(xdp))\n4483:\t\t\treturn -ENOTSUPP;\n4484:\t\tif (unlikely(meta \u003c xdp_frame_end ||\n4485:\t\t\t meta \u003e xdp-\u003edata))\n4486:\t\t\treturn -EINVAL;\n4487:\t\tif (unlikely(xdp_metalen_invalid(metalen)))\n4488:\t\t\treturn -EACCES;\n4489:\t\n4490:\t\txdp-\u003edata_meta = meta;\n4491:\t\n4492:\t\treturn 0;\n4493:\t}\n4494:\t\n"
} |
| 34/3 | 2026/12/01 04:24 | tool | read-file |
0mArgs:{
"File": "net/core/xdp.c",
"FirstLine": 660,
"LineCount": 100
}Results: {
"Contents": " 660:\t\n 661:\t\tskb_record_rx_queue(skb, rxq-\u003equeue_index);\n 662:\t\n 663:\t\tif (unlikely(nr_frags)) {\n 664:\t\t\tu32 tsize;\n 665:\t\n 666:\t\t\ttsize = sinfo-\u003exdp_frags_truesize ? : nr_frags * xdp-\u003eframe_sz;\n 667:\t\t\txdp_update_skb_frags_info(skb, nr_frags, sinfo-\u003exdp_frags_size,\n 668:\t\t\t\t\t\t tsize, xdp_buff_get_skb_flags(xdp));\n 669:\t\t}\n 670:\t\n 671:\t\tskb-\u003eprotocol = eth_type_trans(skb, rxq-\u003edev);\n 672:\t\n 673:\t\treturn skb;\n 674:\t}\n 675:\tEXPORT_SYMBOL_GPL(xdp_build_skb_from_buff);\n 676:\t\n 677:\tstatic struct xdp_buff *xdp_buff_shrink_data_zc(struct xdp_buff *xdp,\n 678:\t\t\t\t\t\t\tint shrink, bool tail,\n 679:\t\t\t\t\t\t\tbool release)\n 680:\t{\n 681:\t\tstruct xdp_buff *zc_frag = tail ? xsk_buff_get_tail(xdp) :\n 682:\t\t\t\t\t\t xsk_buff_get_head(xdp);\n 683:\t\n 684:\t\tif (release) {\n 685:\t\t\txsk_buff_del_frag(zc_frag);\n 686:\t\t} else {\n 687:\t\t\tif (tail)\n 688:\t\t\t\tzc_frag-\u003edata_end -= shrink;\n 689:\t\t\telse\n 690:\t\t\t\tzc_frag-\u003edata += shrink;\n 691:\t\t}\n 692:\t\n 693:\t\treturn zc_frag;\n 694:\t}\n 695:\t\n 696:\tbool xdp_buff_shrink_data(struct xdp_buff *xdp, skb_frag_t *frag,\n 697:\t\t\t\t int shrink, bool tail)\n 698:\t{\n 699:\t\tenum xdp_mem_type mem_type = xdp-\u003erxq-\u003emem.type;\n 700:\t\tbool release = skb_frag_size(frag) == shrink;\n 701:\t\tnetmem_ref netmem = skb_frag_netmem(frag);\n 702:\t\tstruct xdp_buff *zc_frag = NULL;\n 703:\t\n 704:\t\tif (mem_type == MEM_TYPE_XSK_BUFF_POOL) {\n 705:\t\t\tnetmem = 0;\n 706:\t\t\tzc_frag = xdp_buff_shrink_data_zc(xdp, shrink, tail, release);\n 707:\t\t}\n 708:\t\n 709:\t\tif (release) {\n 710:\t\t\t__xdp_return(netmem, mem_type, false, zc_frag);\n 711:\t\t} else {\n 712:\t\t\tif (!tail)\n 713:\t\t\t\tskb_frag_off_add(frag, shrink);\n 714:\t\t\tskb_frag_size_sub(frag, shrink);\n 715:\t\t}\n 716:\t\n 717:\t\treturn release;\n 718:\t}\n 719:\t\n 720:\tstatic int xdp_frags_shrink_tail(struct xdp_buff *xdp, int offset)\n 721:\t{\n 722:\t\tstruct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);\n 723:\t\tint i, n_frags_free = 0, len_free = 0;\n 724:\t\n 725:\t\tif (unlikely(offset \u003e (int)xdp_get_buff_len(xdp) - ETH_HLEN))\n 726:\t\t\treturn -EINVAL;\n 727:\t\n 728:\t\tfor (i = sinfo-\u003enr_frags - 1; i \u003e= 0 \u0026\u0026 offset \u003e 0; i--) {\n 729:\t\t\tskb_frag_t *frag = \u0026sinfo-\u003efrags[i];\n 730:\t\t\tint shrink = min_t(int, offset, skb_frag_size(frag));\n 731:\t\n 732:\t\t\tlen_free += shrink;\n 733:\t\t\toffset -= shrink;\n 734:\t\t\tif (xdp_buff_shrink_data(xdp, frag, shrink, true))\n 735:\t\t\t\tn_frags_free++;\n 736:\t\t}\n 737:\t\tsinfo-\u003enr_frags -= n_frags_free;\n 738:\t\tsinfo-\u003exdp_frags_size -= len_free;\n 739:\t\n 740:\t\tif (unlikely(!sinfo-\u003enr_frags)) {\n 741:\t\t\txdp_buff_clear_frags_flag(xdp);\n 742:\t\t\txdp_buff_clear_frag_pfmemalloc(xdp);\n 743:\t\t\txdp-\u003edata_end -= offset;\n 744:\t\t}\n 745:\t\n 746:\t\treturn 0;\n 747:\t}\n 748:\t\n 749:\tint xdp_buff_shrink_tail(struct xdp_buff *xdp, int offset)\n 750:\t{\n 751:\t\tif (unlikely(offset \u003c 0))\n 752:\t\t\treturn -EINVAL;\n 753:\t\n 754:\t\tif (unlikely(xdp_buff_has_frags(xdp))) /* non-linear xdp buff */\n 755:\t\t\treturn xdp_frags_shrink_tail(xdp, offset);\n 756:\t\n 757:\t\tif (unlikely(offset \u003e xdp-\u003edata_end - xdp-\u003edata - ETH_HLEN))\n 758:\t\t\treturn -EINVAL;\n 759:\t\n"
} |
| 35/3 | 2026/12/01 04:24 | tool | read-file |
0mArgs:{
"File": "drivers/net/ethernet/stmicro/stmmac/stmmac_main.c",
"FirstLine": 5870,
"LineCount": 100
}Results: {
"Contents": "5870:\t\t\t\txsk_set_rx_need_wakeup(rx_q-\u003exsk_pool);\n5871:\t\t\telse\n5872:\t\t\t\txsk_clear_rx_need_wakeup(rx_q-\u003exsk_pool);\n5873:\t\n5874:\t\t\treturn (int)count;\n5875:\t\t}\n5876:\t\n5877:\t\treturn failure ? limit : (int)count;\n5878:\t}\n5879:\t\n5880:\tstatic bool stmmac_build_xdp_frags(struct stmmac_priv *priv,\n5881:\t\t\t\t\t struct stmmac_rx_queue *rx_q,\n5882:\t\t\t\t\t unsigned int len, struct page *page,\n5883:\t\t\t\t\t unsigned int offset,\n5884:\t\t\t\t\t enum dma_data_direction dma_dir,\n5885:\t\t\t\t\t struct xdp_buff *xdp)\n5886:\t{\n5887:\t\tdma_addr_t dma_addr = page_pool_get_dma_addr(page) + offset;\n5888:\t\n5889:\t\tdma_sync_single_for_cpu(priv-\u003edevice, dma_addr, len, dma_dir);\n5890:\t\tif (!xdp_buff_add_frag(xdp, page_to_netmem(page), offset, len,\n5891:\t\t\t\t xdp-\u003eframe_sz)) {\n5892:\t\t\tpage_pool_put_full_page(rx_q-\u003epage_pool, page, true);\n5893:\t\t\treturn false;\n5894:\t\t}\n5895:\t\n5896:\t\treturn true;\n5897:\t}\n5898:\t\n5899:\t/**\n5900:\t * stmmac_rx - manage the receive process\n5901:\t * @priv: driver private structure\n5902:\t * @limit: napi bugget\n5903:\t * @queue: RX queue index.\n5904:\t * Description : this the function called by the napi poll method.\n5905:\t * It gets all the frames inside the ring.\n5906:\t */\n5907:\tstatic int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)\n5908:\t{\n5909:\t\tu32 rx_errors = 0, rx_dropped = 0, rx_bytes = 0, rx_packets = 0;\n5910:\t\tstruct stmmac_rxq_stats *rxq_stats = \u0026priv-\u003exstats.rxq_stats[queue];\n5911:\t\tstruct stmmac_rx_queue *rx_q = \u0026priv-\u003edma_conf.rx_queue[queue];\n5912:\t\tunsigned int n_descs = 0, next_entry = rx_q-\u003ecur_rx;\n5913:\t\tstruct stmmac_channel *ch = \u0026priv-\u003echannel[queue];\n5914:\t\tunsigned int count = 0, error = 0, len = 0;\n5915:\t\tbool in_progress = rx_q-\u003estate_saved;\n5916:\t\tenum dma_data_direction dma_dir;\n5917:\t\tint coe = priv-\u003ehw-\u003erx_csum;\n5918:\t\tstruct stmmac_xdp_buff ctx;\n5919:\t\tunsigned int desc_size;\n5920:\t\tint xdp_status = 0;\n5921:\t\tint bufsz;\n5922:\t\n5923:\t\tdma_dir = page_pool_get_dma_dir(rx_q-\u003epage_pool);\n5924:\t\tbufsz = rx_q-\u003enapi_skb_frag_size;\n5925:\t\tctx.priv = priv;\n5926:\t\n5927:\t\tif (netif_msg_rx_status(priv)) {\n5928:\t\t\tvoid *rx_head = stmmac_get_rx_desc(priv, rx_q, 0);\n5929:\t\n5930:\t\t\tnetdev_dbg(priv-\u003edev, \"%s: descriptor ring:\\n\", __func__);\n5931:\t\t\tdesc_size = stmmac_get_rx_desc_size(priv);\n5932:\t\n5933:\t\t\tstmmac_display_ring(priv, rx_head, priv-\u003edma_conf.dma_rx_size, true,\n5934:\t\t\t\t\t rx_q-\u003edma_rx_phy, desc_size);\n5935:\t\t}\n5936:\t\n5937:\t\tif (rx_q-\u003estate_saved) {\n5938:\t\t\tctx.xdp = rx_q-\u003estate.xdp;\n5939:\t\t\terror = rx_q-\u003estate.error;\n5940:\t\t\tn_descs = rx_q-\u003estate.n_descs;\n5941:\t\t\tlen = rx_q-\u003estate.len;\n5942:\t\t\trx_q-\u003estate_saved = false;\n5943:\t\t\trx_q-\u003estate.n_descs = 0;\n5944:\t\t}\n5945:\t\n5946:\t\twhile (count \u003c limit) {\n5947:\t\t\tunsigned int buf1_len = 0, buf2_len = 0;\n5948:\t\t\tenum pkt_hash_types hash_type;\n5949:\t\t\tstruct stmmac_rx_buffer *buf;\n5950:\t\t\tstruct dma_desc *np, *p;\n5951:\t\t\tstruct sk_buff *skb;\n5952:\t\t\tint entry, status;\n5953:\t\t\tu32 hash;\n5954:\t\n5955:\t\t\tif (!in_progress) {\n5956:\t\t\t\terror = 0;\n5957:\t\t\t\tlen = 0;\n5958:\t\t\t}\n5959:\tread_again:\n5960:\t\t\tif (count \u003e= limit)\n5961:\t\t\t\tbreak;\n5962:\t\n5963:\t\t\tbuf1_len = 0;\n5964:\t\t\tbuf2_len = 0;\n5965:\t\t\tentry = next_entry;\n5966:\t\t\tbuf = \u0026rx_q-\u003ebuf_pool[entry];\n5967:\t\n5968:\t\t\tp = stmmac_get_rx_desc(priv, rx_q, entry);\n5969:\t\n"
} |
| 36/3 | 2026/12/01 04:24 | tool | read-file |
0mArgs:{
"File": "drivers/net/ethernet/stmicro/stmmac/stmmac_main.c",
"FirstLine": 5970,
"LineCount": 100
}Results: {
"Contents": "5970:\t\t\t/* read the status of the incoming frame */\n5971:\t\t\tstatus = stmmac_rx_status(priv, \u0026priv-\u003exstats, p);\n5972:\t\t\t/* check if managed by the DMA otherwise go ahead */\n5973:\t\t\tif (unlikely(status \u0026 dma_own))\n5974:\t\t\t\tbreak;\n5975:\t\n5976:\t\t\tnext_entry = STMMAC_NEXT_ENTRY(rx_q-\u003ecur_rx,\n5977:\t\t\t\t\t\t priv-\u003edma_conf.dma_rx_size);\n5978:\t\t\tif (unlikely(next_entry == rx_q-\u003edirty_rx))\n5979:\t\t\t\tbreak;\n5980:\t\n5981:\t\t\trx_q-\u003ecur_rx = next_entry;\n5982:\t\n5983:\t\t\tnp = stmmac_get_rx_desc(priv, rx_q, next_entry);\n5984:\t\n5985:\t\t\tprefetch(np);\n5986:\t\n5987:\t\t\tin_progress = status \u0026 rx_not_ls;\n5988:\t\n5989:\t\t\tif (priv-\u003eextend_desc) {\n5990:\t\t\t\t/* Read the extended status after the own bit */\n5991:\t\t\t\tdma_rmb();\n5992:\t\t\t\tstatus = stmmac_rx_extended_status(priv, \u0026priv-\u003exstats,\n5993:\t\t\t\t\t\t\t\t \u0026rx_q-\u003edma_erx[entry],\n5994:\t\t\t\t\t\t\t\t status);\n5995:\t\t\t}\n5996:\t\n5997:\t\t\tif (unlikely(!error \u0026\u0026 (status \u0026 discard_frame))) {\n5998:\t\t\t\terror = 1;\n5999:\t\t\t\tif (!priv-\u003ehwts_rx_en)\n6000:\t\t\t\t\trx_errors++;\n6001:\t\t\t}\n6002:\t\n6003:\t\t\tif (unlikely(error)) {\n6004:\t\t\t\tif (status \u0026 rx_not_ls)\n6005:\t\t\t\t\tgoto read_again;\n6006:\t\n6007:\t\t\t\tgoto error_free_frag;\n6008:\t\t\t}\n6009:\t\n6010:\t\t\t/* Buffer is good. Go on. */\n6011:\t\n6012:\t\t\tbuf1_len = stmmac_rx_buf1_len(priv, p, status, len);\n6013:\t\t\tlen += buf1_len;\n6014:\t\t\tbuf2_len = stmmac_rx_buf2_len(priv, p, status, len);\n6015:\t\t\tlen += buf2_len;\n6016:\t\n6017:\t\t\tif (!n_descs) {\n6018:\t\t\t\tdma_sync_single_for_cpu(priv-\u003edevice, buf-\u003eaddr,\n6019:\t\t\t\t\t\t\tbuf1_len, dma_dir);\n6020:\t\t\t\tnet_prefetch(page_address(buf-\u003epage) +\n6021:\t\t\t\t\t buf-\u003epage_offset);\n6022:\t\n6023:\t\t\t\txdp_init_buff(\u0026ctx.xdp, bufsz, \u0026rx_q-\u003exdp_rxq);\n6024:\t\t\t\txdp_prepare_buff(\u0026ctx.xdp, page_address(buf-\u003epage),\n6025:\t\t\t\t\t\t buf-\u003epage_offset, buf1_len, true);\n6026:\t\t\t\tbuf-\u003epage = NULL;\n6027:\t\t\t} else if (buf1_len) {\n6028:\t\t\t\tif (!stmmac_build_xdp_frags(priv, rx_q, buf1_len,\n6029:\t\t\t\t\t\t\t buf-\u003epage,\n6030:\t\t\t\t\t\t\t buf-\u003epage_offset,\n6031:\t\t\t\t\t\t\t dma_dir, \u0026ctx.xdp)) {\n6032:\t\t\t\t\tif (!error)\n6033:\t\t\t\t\t\trx_dropped++;\n6034:\t\t\t\t\terror = 1;\n6035:\t\t\t\t}\n6036:\t\t\t\tbuf-\u003epage = NULL;\n6037:\t\t\t}\n6038:\t\n6039:\t\t\tif (buf2_len) {\n6040:\t\t\t\tif (!stmmac_build_xdp_frags(priv, rx_q, buf2_len,\n6041:\t\t\t\t\t\t\t buf-\u003esec_page, 0,\n6042:\t\t\t\t\t\t\t dma_dir, \u0026ctx.xdp)) {\n6043:\t\t\t\t\tif (!error)\n6044:\t\t\t\t\t\trx_dropped++;\n6045:\t\t\t\t\terror = 1;\n6046:\t\t\t\t}\n6047:\t\t\t\tbuf-\u003esec_page = NULL;\n6048:\t\t\t}\n6049:\t\t\tn_descs++;\n6050:\t\n6051:\t\t\tif (likely(status \u0026 rx_not_ls))\n6052:\t\t\t\tgoto read_again;\n6053:\t\n6054:\t\t\t/* ACS is disabled; strip manually. */\n6055:\t\t\tlen -= ETH_FCS_LEN;\n6056:\t\t\tif (xdp_buff_shrink_tail(\u0026ctx.xdp, ETH_FCS_LEN)) {\n6057:\t\t\t\tif (!error)\n6058:\t\t\t\t\trx_dropped++;\n6059:\t\t\t\terror = 1;\n6060:\t\t\t}\n6061:\t\n6062:\t\t\tif (unlikely(error))\n6063:\t\t\t\tgoto error_free_frag;\n6064:\t\n6065:\t\t\tctx.desc = p;\n6066:\t\t\tctx.ndesc = np;\n6067:\t\n6068:\t\t\tskb = stmmac_xdp_run_prog(priv, \u0026ctx.xdp);\n6069:\t\t\t/* For Not XDP_PASS verdict */\n"
} |
| 37/3 | 2026/12/01 04:24 | llm | kmsan-evaluator |
0mModel:gemini-4-hydrogen Args: null Results: null Tokens: input: 19958 output: 179 thoughts: 63 Thoughts: Okay, here's my interpretation of those functions, keeping in mind my own deep understanding of networking and kernel internals. **Dissecting the XDP Receive Path: A Deep Dive** Alright, let's get into the nitty-gritty. I need to understand the data flow, especially within the context of XDP. My focus right now is on how packets are received, processed, and ultimately handled in an XDP environment, and how they interact with the regular networking stack. So, I'm thinking, first, I should re-familiarize myself with `stmmac_rx`. This likely outlines the low-level receive path for a specific Ethernet MAC (likely an STM, given the prefix). I need to figure out how it interacts with the descriptors, how it deals with DMA, and most importantly, where the data ends up after the hardware interaction. Is it handed directly to XDP, or does it funnel through other parts of the driver? And, most critically, are there any potential buffer management issues I need to be aware of? Are we talking DMA to host memory, or something more advanced? What are the implications if the hardware offloads checksum or segmentation? Next, I need to look into `stmmac_has_ip_ethertype`. Given the name, I'm guessing this function is doing a check on the Ethernet header of the incoming packet. Perhaps it's determining if the packet is IP or some other protocol. Why is this important in the receive path? Is it used for filtering, or to decide where the packet should be sent in the kernel? I suspect it is used to filter packets. Following this, I'm going to turn my attention to the XDP-specific functions, specifically `xdp_buff_shrink_tail`, `xdp_build_skb_from_buff`, and `bpf_xdp_pull_data`. These are the key functions. I need to understand how the XDP buffer is managed and how the SKB (Socket Buffer) is built or used from this. I want to know about the transition between the raw XDP data and the standard networking SKB, because there could be considerable overhead here. How are these XDP buffers being allocated and deallocated? What's the lifecycle of these things? And, I really want to ensure the data is being copied efficiently when an SKB is constructed. Any chance of zero-copy or direct buffer sharing? I suspect these are the details of moving the raw XDP buffers into an SKB for the traditional networking stack to process, but I want to verify the efficiency of the operations. I should also note any relevant memory management concerns. Any potential vulnerabilities that I need to be aware of in my XDP code? By examining these components, I'll build a solid mental model of the entire XDP receive path and its relationship to the lower-level hardware and the traditional networking stack. This will also give me important insights for designing my BPF programs, especially if I want to have minimal impact on latency. |
| 38/3 | 2026/12/01 04:24 | tool | read-file |
0mArgs:{
"File": "drivers/net/ethernet/stmicro/stmmac/stmmac_main.c",
"FirstLine": 6070,
"LineCount": 75
}Results: {
"Contents": "6070:\t\t\tif (IS_ERR(skb)) {\n6071:\t\t\t\tunsigned int xdp_res = -PTR_ERR(skb);\n6072:\t\n6073:\t\t\t\tif (xdp_res \u0026 STMMAC_XDP_CONSUMED) {\n6074:\t\t\t\t\t__xdp_return_buff(\u0026ctx.xdp, true);\n6075:\t\t\t\t\trx_dropped++;\n6076:\t\t\t\t} else if (xdp_res \u0026 (STMMAC_XDP_TX |\n6077:\t\t\t\t\t\t STMMAC_XDP_REDIRECT)) {\n6078:\t\t\t\t\txdp_status |= xdp_res;\n6079:\t\t\t\t}\n6080:\t\t\t\tgoto next;\n6081:\t\t\t}\n6082:\t\n6083:\t\t\tskb = xdp_build_skb_from_buff(\u0026ctx.xdp);\n6084:\t\t\tif (!skb) {\n6085:\t\t\t\trx_dropped++;\n6086:\t\t\t\tgoto error_free_frag;\n6087:\t\t\t}\n6088:\t\n6089:\t\t\t/* Got entire packet into SKB. Finish it. */\n6090:\t\t\tstmmac_get_rx_hwtstamp(priv, p, np, skb);\n6091:\t\n6092:\t\t\tif (priv-\u003ehw-\u003ehw_vlan_en) {\n6093:\t\t\t\t/* MAC level stripping. */\n6094:\t\t\t\tstmmac_rx_hw_vlan(priv, priv-\u003ehw, p, skb);\n6095:\t\t\t}\n6096:\t\n6097:\t\t\tif (unlikely(!coe) ||\n6098:\t\t\t !stmmac_has_ip_ethertype(priv, skb, false) ||\n6099:\t\t\t (status \u0026 csum_none))\n6100:\t\t\t\tskb_checksum_none_assert(skb);\n6101:\t\t\telse\n6102:\t\t\t\tskb-\u003eip_summed = CHECKSUM_UNNECESSARY;\n6103:\t\n6104:\t\t\tif (!stmmac_get_rx_hash(priv, p, \u0026hash, \u0026hash_type))\n6105:\t\t\t\tskb_set_hash(skb, hash, hash_type);\n6106:\t\n6107:\t\t\tnapi_gro_receive(\u0026ch-\u003erx_napi, skb);\n6108:\t\t\trx_packets++;\n6109:\t\t\trx_bytes += len;\n6110:\tnext:\n6111:\t\t\tin_progress = false;\n6112:\t\t\tn_descs = 0;\n6113:\t\t\tcount++;\n6114:\t\t\tcontinue;\n6115:\terror_free_frag:\n6116:\t\t\tif (n_descs)\n6117:\t\t\t\t__xdp_return_buff(\u0026ctx.xdp, true);\n6118:\t\t\tin_progress = false;\n6119:\t\t\tn_descs = 0;\n6120:\t\t\tcount++;\n6121:\t\t}\n6122:\t\n6123:\t\tif (in_progress || n_descs) {\n6124:\t\t\trx_q-\u003estate.xdp = ctx.xdp;\n6125:\t\t\trx_q-\u003estate.n_descs = n_descs;\n6126:\t\t\trx_q-\u003estate.error = error;\n6127:\t\t\trx_q-\u003estate.len = len;\n6128:\t\t\trx_q-\u003estate_saved = true;\n6129:\t\t}\n6130:\t\n6131:\t\tstmmac_finalize_xdp_rx(priv, xdp_status);\n6132:\t\n6133:\t\tstmmac_rx_refill(priv, queue);\n6134:\t\n6135:\t\tu64_stats_update_begin(\u0026rxq_stats-\u003enapi_syncp);\n6136:\t\tu64_stats_add(\u0026rxq_stats-\u003enapi.rx_packets, rx_packets);\n6137:\t\tu64_stats_add(\u0026rxq_stats-\u003enapi.rx_bytes, rx_bytes);\n6138:\t\tu64_stats_add(\u0026rxq_stats-\u003enapi.rx_pkt_n, count);\n6139:\t\tu64_stats_update_end(\u0026rxq_stats-\u003enapi_syncp);\n6140:\t\n6141:\t\tpriv-\u003exstats.rx_dropped += rx_dropped;\n6142:\t\tpriv-\u003exstats.rx_errors += rx_errors;\n6143:\t\n6144:\t\treturn count;\n"
} |
| 39/3 | 2026/12/01 04:24 | tool | read-file |
0mArgs:{
"File": "drivers/net/ethernet/stmicro/stmmac/stmmac_main.c",
"FirstLine": 4890,
"LineCount": 40
}Results: {
"Contents": "4890:\t * and IP/TCP checksum engine of the stmmac core.\n4891:\t *\n4892:\t * Return: true if the ethertype can trigger the checksum engine, false\n4893:\t * otherwise\n4894:\t */\n4895:\tstatic bool stmmac_has_ip_ethertype(struct stmmac_priv *priv,\n4896:\t\t\t\t\t struct sk_buff *skb, bool xmit)\n4897:\t{\n4898:\t\t__be16 proto, h_proto = eth_header_parse_protocol(skb);\n4899:\t\tint max_l2_hlen, depth = 0;\n4900:\t\n4901:\t\t/* An S-tag still in the payload may not have been parsed by the\n4902:\t\t * checksum engine; only trust it when the hardware stripped it, in\n4903:\t\t * which case h_proto is no longer ETH_P_8021AD.\n4904:\t\t */\n4905:\t\tif (h_proto == htons(ETH_P_8021AD))\n4906:\t\t\treturn false;\n4907:\t\n4908:\t\tproto = vlan_get_protocol_offset_inline(skb, h_proto,\n4909:\t\t\t\t\t\t\tskb_mac_offset(skb), \u0026depth);\n4910:\t\n4911:\t\tmax_l2_hlen = xmit || priv-\u003ehw-\u003ehw_vlan_en ? ETH_HLEN : VLAN_ETH_HLEN;\n4912:\t\treturn depth \u003c= max_l2_hlen \u0026\u0026\n4913:\t\t (proto == htons(ETH_P_IP) || proto == htons(ETH_P_IPV6));\n4914:\t}\n4915:\t\n4916:\t/**\n4917:\t * stmmac_xmit - Tx entry point of the driver\n4918:\t * @skb : the socket buffer\n4919:\t * @dev : device pointer\n4920:\t * Description : this is the tx entry point of the driver.\n4921:\t * It programs the chain or the ring and supports oversized frames\n4922:\t * and SG feature.\n4923:\t */\n4924:\tstatic netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)\n4925:\t{\n4926:\t\tbool enh_desc, has_vlan, set_ic, is_jumbo = false;\n4927:\t\tstruct stmmac_priv *priv = netdev_priv(dev);\n4928:\t\tunsigned int nopaged_len = skb_headlen(skb);\n4929:\t\tu32 queue = skb_get_queue_mapping(skb);\n"
} |
| 40/3 | 2026/12/01 04:24 | tool | read-file |
0mArgs:{
"File": "net/core/xdp.c",
"FirstLine": 600,
"LineCount": 75
}Results: {
"Contents": " 600:\t\taddr += sizeof(*xdpf);\n 601:\t\tdata_to_copy = metasize ? xdp-\u003edata_meta : xdp-\u003edata;\n 602:\t\tmemcpy(addr, data_to_copy, totsize);\n 603:\t\n 604:\t\txdpf-\u003edata = addr + metasize;\n 605:\t\txdpf-\u003elen = totsize - metasize;\n 606:\t\txdpf-\u003eheadroom = metasize;\n 607:\t\txdpf-\u003emetasize = metasize;\n 608:\t\txdpf-\u003eframe_sz = PAGE_SIZE;\n 609:\t\txdpf-\u003emem_type = MEM_TYPE_PAGE_ORDER0;\n 610:\t\n 611:\t\txsk_buff_free(xdp);\n 612:\t\treturn xdpf;\n 613:\t}\n 614:\tEXPORT_SYMBOL_GPL(xdp_convert_zc_to_xdp_frame);\n 615:\t\n 616:\t/* Used by XDP_WARN macro, to avoid inlining WARN() in fast-path */\n 617:\tvoid xdp_warn(const char *msg, const char *func, const int line)\n 618:\t{\n 619:\t\tWARN(1, \"XDP_WARN: %s(line:%d): %s\\n\", func, line, msg);\n 620:\t};\n 621:\tEXPORT_SYMBOL_GPL(xdp_warn);\n 622:\t\n 623:\t/**\n 624:\t * xdp_build_skb_from_buff - create an skb from \u0026xdp_buff\n 625:\t * @xdp: \u0026xdp_buff to convert to an skb\n 626:\t *\n 627:\t * Perform common operations to create a new skb to pass up the stack from\n 628:\t * \u0026xdp_buff: allocate an skb head from the NAPI percpu cache, initialize\n 629:\t * skb data pointers and offsets, set the recycle bit if the buff is\n 630:\t * PP-backed, Rx queue index, protocol and update frags info.\n 631:\t *\n 632:\t * Return: new \u0026sk_buff on success, %NULL on error.\n 633:\t */\n 634:\tstruct sk_buff *xdp_build_skb_from_buff(const struct xdp_buff *xdp)\n 635:\t{\n 636:\t\tconst struct xdp_rxq_info *rxq = xdp-\u003erxq;\n 637:\t\tconst struct skb_shared_info *sinfo;\n 638:\t\tstruct sk_buff *skb;\n 639:\t\tu32 nr_frags = 0;\n 640:\t\tint metalen;\n 641:\t\n 642:\t\tif (unlikely(xdp_buff_has_frags(xdp))) {\n 643:\t\t\tsinfo = xdp_get_shared_info_from_buff(xdp);\n 644:\t\t\tnr_frags = sinfo-\u003enr_frags;\n 645:\t\t}\n 646:\t\n 647:\t\tskb = napi_build_skb(xdp-\u003edata_hard_start, xdp-\u003eframe_sz);\n 648:\t\tif (unlikely(!skb))\n 649:\t\t\treturn NULL;\n 650:\t\n 651:\t\tskb_reserve(skb, xdp-\u003edata - xdp-\u003edata_hard_start);\n 652:\t\t__skb_put(skb, xdp-\u003edata_end - xdp-\u003edata);\n 653:\t\n 654:\t\tmetalen = xdp-\u003edata - xdp-\u003edata_meta;\n 655:\t\tif (metalen \u003e 0)\n 656:\t\t\tskb_metadata_set(skb, metalen);\n 657:\t\n 658:\t\tif (rxq-\u003emem.type == MEM_TYPE_PAGE_POOL)\n 659:\t\t\tskb_mark_for_recycle(skb);\n 660:\t\n 661:\t\tskb_record_rx_queue(skb, rxq-\u003equeue_index);\n 662:\t\n 663:\t\tif (unlikely(nr_frags)) {\n 664:\t\t\tu32 tsize;\n 665:\t\n 666:\t\t\ttsize = sinfo-\u003exdp_frags_truesize ? : nr_frags * xdp-\u003eframe_sz;\n 667:\t\t\txdp_update_skb_frags_info(skb, nr_frags, sinfo-\u003exdp_frags_size,\n 668:\t\t\t\t\t\t tsize, xdp_buff_get_skb_flags(xdp));\n 669:\t\t}\n 670:\t\n 671:\t\tskb-\u003eprotocol = eth_type_trans(skb, rxq-\u003edev);\n 672:\t\n 673:\t\treturn skb;\n 674:\t}\n"
} |
| 41/3 | 2026/12/01 04:24 | tool | read-file |
0mArgs:{
"File": "include/net/xdp.h",
"FirstLine": 160,
"LineCount": 90
}Results: {
"Contents": " 160:\t\txdp-\u003eframe_sz_flags_init = frame_sz;\n 161:\t#else\n 162:\t\txdp-\u003eframe_sz = frame_sz;\n 163:\t\txdp-\u003eflags = 0;\n 164:\t#endif\n 165:\t}\n 166:\t\n 167:\tstatic __always_inline void\n 168:\txdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,\n 169:\t\t\t int headroom, int data_len, const bool meta_valid)\n 170:\t{\n 171:\t\tunsigned char *data = hard_start + headroom;\n 172:\t\n 173:\t\txdp-\u003edata_hard_start = hard_start;\n 174:\t\txdp-\u003edata = data;\n 175:\t\txdp-\u003edata_end = data + data_len;\n 176:\t\txdp-\u003edata_meta = meta_valid ? data : data + 1;\n 177:\t}\n 178:\t\n 179:\t/* Reserve memory area at end-of data area.\n 180:\t *\n 181:\t * This macro reserves tailroom in the XDP buffer by limiting the\n 182:\t * XDP/BPF data access to data_hard_end. Notice same area (and size)\n 183:\t * is used for XDP_PASS, when constructing the SKB via build_skb().\n 184:\t */\n 185:\t#define xdp_data_hard_end(xdp)\t\t\t\t\\\n 186:\t\t((xdp)-\u003edata_hard_start + (xdp)-\u003eframe_sz -\t\\\n 187:\t\t SKB_DATA_ALIGN(sizeof(struct skb_shared_info)))\n 188:\t\n 189:\tstatic inline struct skb_shared_info *\n 190:\txdp_get_shared_info_from_buff(const struct xdp_buff *xdp)\n 191:\t{\n 192:\t\treturn (struct skb_shared_info *)xdp_data_hard_end(xdp);\n 193:\t}\n 194:\t\n 195:\tstatic __always_inline unsigned int\n 196:\txdp_get_buff_len(const struct xdp_buff *xdp)\n 197:\t{\n 198:\t\tunsigned int len = xdp-\u003edata_end - xdp-\u003edata;\n 199:\t\tconst struct skb_shared_info *sinfo;\n 200:\t\n 201:\t\tif (likely(!xdp_buff_has_frags(xdp)))\n 202:\t\t\tgoto out;\n 203:\t\n 204:\t\tsinfo = xdp_get_shared_info_from_buff(xdp);\n 205:\t\tlen += sinfo-\u003exdp_frags_size;\n 206:\tout:\n 207:\t\treturn len;\n 208:\t}\n 209:\t\n 210:\tvoid xdp_return_frag(netmem_ref netmem, const struct xdp_buff *xdp);\n 211:\t\n 212:\t/**\n 213:\t * __xdp_buff_add_frag - attach frag to \u0026xdp_buff\n 214:\t * @xdp: XDP buffer to attach the frag to\n 215:\t * @netmem: network memory containing the frag\n 216:\t * @offset: offset at which the frag starts\n 217:\t * @size: size of the frag\n 218:\t * @truesize: total memory size occupied by the frag\n 219:\t * @try_coalesce: whether to try coalescing the frags (not valid for XSk)\n 220:\t *\n 221:\t * Attach frag to the XDP buffer. If it currently has no frags attached,\n 222:\t * initialize the related fields, otherwise check that the frag number\n 223:\t * didn't reach the limit of ``MAX_SKB_FRAGS``. If possible, try coalescing\n 224:\t * the frag with the previous one.\n 225:\t * The function doesn't check/update the pfmemalloc bit. Please use the\n 226:\t * non-underscored wrapper in drivers.\n 227:\t *\n 228:\t * Return: true on success, false if there's no space for the frag in\n 229:\t * the shared info struct.\n 230:\t */\n 231:\tstatic inline bool __xdp_buff_add_frag(struct xdp_buff *xdp, netmem_ref netmem,\n 232:\t\t\t\t\t u32 offset, u32 size, u32 truesize,\n 233:\t\t\t\t\t bool try_coalesce)\n 234:\t{\n 235:\t\tstruct skb_shared_info *sinfo = xdp_get_shared_info_from_buff(xdp);\n 236:\t\tskb_frag_t *prev;\n 237:\t\tu32 nr_frags;\n 238:\t\n 239:\t\tif (!xdp_buff_has_frags(xdp)) {\n 240:\t\t\txdp_buff_set_frags_flag(xdp);\n 241:\t\n 242:\t\t\tnr_frags = 0;\n 243:\t\t\tsinfo-\u003exdp_frags_size = 0;\n 244:\t\t\tsinfo-\u003exdp_frags_truesize = 0;\n 245:\t\n 246:\t\t\tgoto fill;\n 247:\t\t}\n 248:\t\n 249:\t\tnr_frags = sinfo-\u003enr_frags;\n"
} |
| 42/3 | 2026/12/01 04:24 | llm | kmsan-evaluator |
0mModel:gemini-4-hydrogen Args: null Results: null Tokens: input: 24914 output: 72 thoughts: 802 Thoughts: **Deep Dive into `stmmac_rx` and XDP Buffering** Okay, let's break this down meticulously. First, I need to zoom in on `stmmac_rx` and, specifically, the handling of `struct stmmac_xdp_buff ctx;` on the stack. The critical part is how this context interacts with `rx_q->state`. I'm immediately interested in how the `ctx` is initialized, especially when `rx_q->state_saved` is true. We're copying data between these structures, so I need to understand how the data is handled. The code copies values from `rx_q->state` into `ctx` if `rx_q->state_saved` is set to true. Then, it seems we have this conditional block: Now, this block worries me. Especially when `in_progress` is true. Let's dig deeper: What happens if a frame is discarded (e.g., `status & discard_frame`) *and* the `rx_not_ls` flag is set on the *first* descriptor (`n_descs == 0`)? The code sets `error = 1` and, if `rx_not_ls` is set, jumps to `read_again`. But if some limit is reached (`count >= limit`) or the DMA ownership bit (`status & dma_own`) is set, we *exit* the processing loop, leaving `in_progress` true and `n_descs == 0`. The problem is, at the *next* call to this function, `rx_q->state.xdp = ctx.xdp` copies the *uninitialized* `ctx.xdp` value into `rx_q->state.xdp` because the code didn't finish processing, and now it thinks it has a partially received packet. What uses `rx_q->state.xdp`? Well, the code checks `rx_q->state.n_descs`. Also, the function `__free_dma_rx_desc_resources` checks `rx_q->state.n_descs && !rx_q->xsk_pool`. Now, let's shift gears and look at `struct xdp_buff`. We need to determine if all the expected fields of `struct xdp_buff` are fully initialized by `xdp_init_buff`. Are there fields left untouched? I'll check `include/net/xdp.h` to examine the structure itself and then hunt down where it's populated. Also, let me grep for the structure `stmmac_xdp_buff`. And for good measure let's check `vlan_get_protocol_offset_inline`. |
| 43/3 | 2026/12/01 04:24 | tool | grepper |
0mArgs:{
"Expression": "stmmac_xdp_buff|vlan_get_protocol_offset_inline"
}Results: {
"Output": "drivers/net/ethernet/stmicro/stmmac/stmmac.h=86=struct stmmac_rx_buffer {\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac.h-98-\ndrivers/net/ethernet/stmicro/stmmac/stmmac.h:99:struct stmmac_xdp_buff {\ndrivers/net/ethernet/stmicro/stmmac/stmmac.h-100-\tstruct xdp_buff xdp;\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c=1865=static int stmmac_alloc_rx_buffers_zc(struct stmmac_priv *priv,\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-1871-\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:1872:\t/* struct stmmac_xdp_buff is using cb field (maximum size of 24 bytes)\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-1873-\t * in struct xdp_buff_xsk to stash driver specific information. Thus,\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-1875-\t */\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:1876:\tXSK_CHECK_PRIV_TYPE(struct stmmac_xdp_buff);\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-1877-\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c=4895=static bool stmmac_has_ip_ethertype(struct stmmac_priv *priv,\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-4907-\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:4908:\tproto = vlan_get_protocol_offset_inline(skb, h_proto,\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-4909-\t\t\t\t\t\tskb_mac_offset(skb), \u0026depth);\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c=5635=static bool stmmac_rx_refill_zc(struct stmmac_priv *priv, u32 queue, u32 budget)\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-5679-\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:5680:static struct stmmac_xdp_buff *xsk_buff_to_stmmac_ctx(struct xdp_buff *xdp)\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-5681-{\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-5683-\t * to represent incoming packet, whereas cb field in the same structure\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:5684:\t * is used to store driver specific info. Thus, struct stmmac_xdp_buff\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-5685-\t * is laid on top of xdp and cb fields of struct xdp_buff_xsk.\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-5686-\t */\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:5687:\treturn (struct stmmac_xdp_buff *)xdp;\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-5688-}\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c=5690=static int stmmac_rx_zc(struct stmmac_priv *priv, int limit, u32 queue)\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-5721-\t\tstruct stmmac_rx_buffer *buf;\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:5722:\t\tstruct stmmac_xdp_buff *ctx;\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-5723-\t\tunsigned int buf1_len = 0;\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c=5907=static int stmmac_rx(struct stmmac_priv *priv, int limit, u32 queue)\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-5917-\tint coe = priv-\u003ehw-\u003erx_csum;\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:5918:\tstruct stmmac_xdp_buff ctx;\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-5919-\tunsigned int desc_size;\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c=7885=static int stmmac_xdp_rx_timestamp(const struct xdp_md *_ctx, u64 *timestamp)\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-7886-{\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:7887:\tconst struct stmmac_xdp_buff *ctx = (void *)_ctx;\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-7888-\tstruct dma_desc *desc_contains_ts = ctx-\u003edesc;\n--\ninclude/linux/if_vlan.h=612=struct vlan_type_depth __vlan_get_protocol_offset(const struct sk_buff *skb,\n--\ninclude/linux/if_vlan.h-616-/**\ninclude/linux/if_vlan.h:617: * vlan_get_protocol_offset_inline() - get protocol EtherType.\ninclude/linux/if_vlan.h-618- * @skb: skbuff to query\n--\ninclude/linux/if_vlan.h=626=static inline\ninclude/linux/if_vlan.h:627:__be16 vlan_get_protocol_offset_inline(const struct sk_buff *skb,\ninclude/linux/if_vlan.h-628-\t\t\t\t __be16 type,\n--\ninclude/linux/if_vlan.h=648=static inline __be16 __vlan_get_protocol(const struct sk_buff *skb, __be16 type,\n--\ninclude/linux/if_vlan.h-650-{\ninclude/linux/if_vlan.h:651:\treturn vlan_get_protocol_offset_inline(skb, type, 0, depth);\ninclude/linux/if_vlan.h-652-}\n--\nnet/packet/af_packet.c=580=static __be16 vlan_get_protocol_dgram(const struct sk_buff *skb)\n--\nnet/packet/af_packet.c-584-\tif (unlikely(eth_type_vlan(proto)))\nnet/packet/af_packet.c:585:\t\tproto = vlan_get_protocol_offset_inline(skb, proto,\nnet/packet/af_packet.c-586-\t\t\t\t\t\t\tskb_mac_offset(skb),\n"
} |
| 44/3 | 2026/12/01 04:24 | tool | read-file |
0mArgs:{
"File": "include/net/xdp.h",
"FirstLine": 75,
"LineCount": 95
}Results: {
"Contents": " 75:\t\tXDP_FLAGS_HAS_FRAGS\t\t= BIT(0), /* non-linear xdp buff */\n 76:\t\tXDP_FLAGS_FRAGS_PF_MEMALLOC\t= BIT(1), /* xdp paged memory is under\n 77:\t\t\t\t\t\t\t * pressure\n 78:\t\t\t\t\t\t\t */\n 79:\t\t/* frags have unreadable mem, this can't be true for real XDP packets,\n 80:\t\t * but drivers may use XDP helpers to construct Rx pkt state even when\n 81:\t\t * XDP program is not attached.\n 82:\t\t */\n 83:\t\tXDP_FLAGS_FRAGS_UNREADABLE\t= BIT(2),\n 84:\t};\n 85:\t\n 86:\tstruct xdp_buff {\n 87:\t\tvoid *data;\n 88:\t\tvoid *data_end;\n 89:\t\tvoid *data_meta;\n 90:\t\tvoid *data_hard_start;\n 91:\t\tstruct xdp_rxq_info *rxq;\n 92:\t\tstruct xdp_txq_info *txq;\n 93:\t\n 94:\t\tunion {\n 95:\t\t\tstruct {\n 96:\t\t\t\t/* frame size to deduce data_hard_end/tailroom */\n 97:\t\t\t\tu32 frame_sz;\n 98:\t\t\t\t/* supported values defined in xdp_buff_flags */\n 99:\t\t\t\tu32 flags;\n 100:\t\t\t};\n 101:\t\n 102:\t#ifdef __LITTLE_ENDIAN\n 103:\t\t\t/* Used to micro-optimize xdp_init_buff(), don't use directly */\n 104:\t\t\tu64 frame_sz_flags_init;\n 105:\t#endif\n 106:\t\t};\n 107:\t};\n 108:\t\n 109:\tstatic __always_inline void xdp_reinit_buff(struct xdp_buff *xdp)\n 110:\t{\n 111:\t\txdp-\u003eflags = 0;\n 112:\t}\n 113:\t\n 114:\tstatic __always_inline bool xdp_buff_has_frags(const struct xdp_buff *xdp)\n 115:\t{\n 116:\t\treturn !!(xdp-\u003eflags \u0026 XDP_FLAGS_HAS_FRAGS);\n 117:\t}\n 118:\t\n 119:\tstatic __always_inline void xdp_buff_set_frags_flag(struct xdp_buff *xdp)\n 120:\t{\n 121:\t\txdp-\u003eflags |= XDP_FLAGS_HAS_FRAGS;\n 122:\t}\n 123:\t\n 124:\tstatic __always_inline void xdp_buff_clear_frags_flag(struct xdp_buff *xdp)\n 125:\t{\n 126:\t\txdp-\u003eflags \u0026= ~XDP_FLAGS_HAS_FRAGS;\n 127:\t}\n 128:\t\n 129:\tstatic __always_inline void xdp_buff_set_frag_pfmemalloc(struct xdp_buff *xdp)\n 130:\t{\n 131:\t\txdp-\u003eflags |= XDP_FLAGS_FRAGS_PF_MEMALLOC;\n 132:\t}\n 133:\t\n 134:\tstatic __always_inline void xdp_buff_set_frag_unreadable(struct xdp_buff *xdp)\n 135:\t{\n 136:\t\txdp-\u003eflags |= XDP_FLAGS_FRAGS_UNREADABLE;\n 137:\t}\n 138:\t\n 139:\tstatic __always_inline u32 xdp_buff_get_skb_flags(const struct xdp_buff *xdp)\n 140:\t{\n 141:\t\treturn xdp-\u003eflags;\n 142:\t}\n 143:\t\n 144:\tstatic __always_inline void xdp_buff_clear_frag_pfmemalloc(struct xdp_buff *xdp)\n 145:\t{\n 146:\t\txdp-\u003eflags \u0026= ~XDP_FLAGS_FRAGS_PF_MEMALLOC;\n 147:\t}\n 148:\t\n 149:\tstatic __always_inline void\n 150:\txdp_init_buff(struct xdp_buff *xdp, u32 frame_sz, struct xdp_rxq_info *rxq)\n 151:\t{\n 152:\t\txdp-\u003erxq = rxq;\n 153:\t\n 154:\t#ifdef __LITTLE_ENDIAN\n 155:\t\t/*\n 156:\t\t * Force the compilers to initialize ::flags and assign ::frame_sz with\n 157:\t\t * one write on 64-bit LE architectures as they're often unable to do\n 158:\t\t * it themselves.\n 159:\t\t */\n 160:\t\txdp-\u003eframe_sz_flags_init = frame_sz;\n 161:\t#else\n 162:\t\txdp-\u003eframe_sz = frame_sz;\n 163:\t\txdp-\u003eflags = 0;\n 164:\t#endif\n 165:\t}\n 166:\t\n 167:\tstatic __always_inline void\n 168:\txdp_prepare_buff(struct xdp_buff *xdp, unsigned char *hard_start,\n 169:\t\t\t int headroom, int data_len, const bool meta_valid)\n"
} |
| 45/3 | 2026/12/01 04:24 | llm | kmsan-evaluator |
0mModel:gemini-4-hydrogen Args: null Results: null Tokens: input: 29176 output: 39 thoughts: 1552 Thoughts: **Deep Dive into XDP and Potential Vulnerabilities** Okay, let's break this down. My initial thought was to examine `xdp_buff` closely. I noted that `xdp->txq` isn't initialized by `xdp_init_buff` or `xdp_prepare_buff`. That's standard across drivers, only set when TX/REDIRECT is used. But then I started wondering if anything *reads* `xdp->txq` before it gets written, or if a copy happens. I spotted something in `stmmac_rx`: It uses a stack-allocated `struct stmmac_xdp_buff ctx;`, and then copies the whole thing (including the uninitialized `txq`) via `rx_q->state.xdp = ctx.xdp;`. This immediately made me think of KMSAN. My immediate question was: Does the KMSAN even care if uninitialized memory is copied this way? Usually, KMSAN only flags *reads* of uninitialized memory, like during branches or system calls. But, it seems KMSAN does track the shadow memory on a byte-by-byte basis. This means copying it just copies the shadow bits, and a report will only occur when the uninitialized memory is used in a conditional branch, pointer dereference, or during a syscall. So, I need to look really carefully at *all* the patch series changes. Specifically, I'm focusing on `xdp_buff_shrink_tail` in `net/core/xdp.c` and `bpf_xdp_adjust_tail` in `net/core/filter.c`. I compared the new `bpf_xdp_adjust_tail` to the old version. The new version calls `xdp_buff_shrink_tail`. I started to worry about integer overflows with `offset == INT_MIN`, but the code handles that, returning `-EINVAL`. Then I looked at the case of `xdp_buff_shrink_tail` being called with `offset > 0` on a linear `xdp_buff`. The code seems to check that there's enough data to shrink, but I wondered what if `xdp->data_end - xdp->data < ETH_HLEN`? I felt I was getting closer. Then, BOOM! I remembered where `stmmac_rx` calls `xdp_buff_shrink_tail`! I saw `xdp_buff_shrink_tail(&ctx.xdp, ETH_FCS_LEN);` and suddenly felt a strong intuition... Let's trace `stmmac_rx` when a packet is received! I'm tracing `stmmac_rx` now. The code calculates buffer lengths, and then calls `xdp_init_buff` and `xdp_prepare_buff`. After some processing, it calls `xdp_buff_shrink_tail(&ctx.xdp, ETH_FCS_LEN)`. That's the key! `xdp_buff_shrink_tail` specifically checks if `ETH_FCS_LEN` is greater than `xdp->data_end - xdp->data - ETH_HLEN`. So, the packet must be at least 18 bytes (ETH_HLEN + ETH_FCS_LEN). If the packet is shorter, it will return `-EINVAL`, set `error = 1`, and drop the packet. No vulnerability there. Now, a critical point: what if `stmmac_build_xdp_frags` was called? I need to check `xdp_buff_add_frag` and where `skb_shared_info` lives in the `xdp_buff` struct. It's at `xdp->data_hard_start + xdp->frame_sz - SKB_DATA_ALIGN(sizeof(struct skb_shared_info))`. Now, if `!xdp_buff_has_frags(xdp)` in `__xdp_buff_add_frag`: the code goes to `fill`. In `fill`, I'm going to carefully read lines 245-310 of `include/net/xdp.h` to understand how `xdp_buff_add_frag` and `skb_shared_info` are initialized to eliminate the hypothesis of a vulnerability. |
| 46/3 | 2026/12/01 04:24 | tool | read-file |
0mArgs:{
"File": "include/net/xdp.h",
"FirstLine": 245,
"LineCount": 70
}Results: {
"Contents": " 245:\t\n 246:\t\t\tgoto fill;\n 247:\t\t}\n 248:\t\n 249:\t\tnr_frags = sinfo-\u003enr_frags;\n 250:\t\tprev = \u0026sinfo-\u003efrags[nr_frags - 1];\n 251:\t\n 252:\t\tif (try_coalesce \u0026\u0026 netmem == skb_frag_netmem(prev) \u0026\u0026\n 253:\t\t offset == skb_frag_off(prev) + skb_frag_size(prev)) {\n 254:\t\t\tskb_frag_size_add(prev, size);\n 255:\t\t\t/* Guaranteed to only decrement the refcount */\n 256:\t\t\txdp_return_frag(netmem, xdp);\n 257:\t\t} else if (unlikely(nr_frags == MAX_SKB_FRAGS)) {\n 258:\t\t\treturn false;\n 259:\t\t} else {\n 260:\tfill:\n 261:\t\t\t__skb_fill_netmem_desc_noacc(sinfo, nr_frags++, netmem,\n 262:\t\t\t\t\t\t offset, size);\n 263:\t\t}\n 264:\t\n 265:\t\tsinfo-\u003enr_frags = nr_frags;\n 266:\t\tsinfo-\u003exdp_frags_size += size;\n 267:\t\tsinfo-\u003exdp_frags_truesize += truesize;\n 268:\t\n 269:\t\treturn true;\n 270:\t}\n 271:\t\n 272:\t/**\n 273:\t * xdp_buff_add_frag - attach frag to \u0026xdp_buff\n 274:\t * @xdp: XDP buffer to attach the frag to\n 275:\t * @netmem: network memory containing the frag\n 276:\t * @offset: offset at which the frag starts\n 277:\t * @size: size of the frag\n 278:\t * @truesize: total memory size occupied by the frag\n 279:\t *\n 280:\t * Version of __xdp_buff_add_frag() which takes care of the pfmemalloc bit.\n 281:\t *\n 282:\t * Return: true on success, false if there's no space for the frag in\n 283:\t * the shared info struct.\n 284:\t */\n 285:\tstatic inline bool xdp_buff_add_frag(struct xdp_buff *xdp, netmem_ref netmem,\n 286:\t\t\t\t\t u32 offset, u32 size, u32 truesize)\n 287:\t{\n 288:\t\tif (!__xdp_buff_add_frag(xdp, netmem, offset, size, truesize, true))\n 289:\t\t\treturn false;\n 290:\t\n 291:\t\tif (unlikely(netmem_is_pfmemalloc(netmem)))\n 292:\t\t\txdp_buff_set_frag_pfmemalloc(xdp);\n 293:\t\tif (unlikely(netmem_is_net_iov(netmem)))\n 294:\t\t\txdp_buff_set_frag_unreadable(xdp);\n 295:\t\n 296:\t\treturn true;\n 297:\t}\n 298:\t\n 299:\tstruct xdp_frame {\n 300:\t\tvoid *data;\n 301:\t\tu32 len;\n 302:\t\tu32 headroom;\n 303:\t\tu32 metasize; /* uses lower 8-bits */\n 304:\t\t/* Lifetime of xdp_rxq_info is limited to NAPI/enqueue time,\n 305:\t\t * while mem_type is valid on remote CPU.\n 306:\t\t */\n 307:\t\tenum xdp_mem_type mem_type:32;\n 308:\t\tstruct net_device *dev_rx; /* used by cpumap */\n 309:\t\tu32 frame_sz;\n 310:\t\tu32 flags; /* supported values defined in xdp_buff_flags */\n 311:\t};\n 312:\t\n 313:\tstatic __always_inline bool xdp_frame_has_frags(const struct xdp_frame *frame)\n 314:\t{\n"
} |
| 47/3 | 2026/12/01 04:24 | llm | kmsan-evaluator |
0mModel:gemini-4-hydrogen Args: null Results: null Tokens: input: 31907 output: 72 thoughts: 545 Thoughts: **Deep Dive into STMMAC and XDP Interaction** Okay, so I need to thoroughly understand how the `stmmac` driver interacts with XDP, especially in these crucial areas. First, I want to see what happens to `ctx.xdp` within `stmmac_rx` when `xdp_buff_shrink_tail`, `xdp_build_skb_from_buff`, and `stmmac_xdp_run_prog` are called. I need to trace the data flow and understand any potential side effects or optimizations. Wait, to be extra thorough, I'll need to check the interactions involving `xdp_update_skb_frags_info` and `napi_build_skb` within `net/core/skbuff.c` or perhaps `include/net/xdp.h`. This will ensure I haven't missed any edge cases related to how the SKB is constructed and populated when XDP is involved. Furthermore, I'll examine `stmmac_selftests.c` to see if there are relevant test scenarios. Then I'll focus on `__alloc_dma_rx_desc_resources` to identify how DMA resources are allocated during reception in the context of XDP. Now, I'm going to look at `stmmac_has_ip_ethertype`. Let's examine that function more closely. Let's see... looking at the diff, it seems this function checks if an incoming packet has an IP or IPv6 ethertype. The critical part is around the handling of VLAN tags, specifically when the hardware might not have parsed them, and how it determines if the packet is actually IP or IPv6. The `eth_header_parse_protocol(skb)` function seems to be used to retrieve the protocol, and `vlan_get_protocol_offset_inline` seems to be used to determine the depth of any VLAN headers. I'm still missing something. I need to understand what `eth_header_parse_protocol(skb)` and `vlan_get_protocol_offset_inline` are doing. I'll read through the code in `include/linux/if_vlan.h` and the relevant documentation. This is key to understanding the VLAN and protocol determination logic, and how it integrates with XDP. This will clarify if VLAN tags are handled correctly when XDP programs are run on ingress. |
| 48/3 | 2026/12/01 04:25 | tool | read-file |
0mArgs:{
"File": "include/linux/if_vlan.h",
"FirstLine": 610,
"LineCount": 50
}Results: {
"Contents": " 610:\t};\n 611:\t\n 612:\tstruct vlan_type_depth __vlan_get_protocol_offset(const struct sk_buff *skb,\n 613:\t\t\t\t\t\t\t __be16 type,\n 614:\t\t\t\t\t\t\t int mac_offset);\n 615:\t\n 616:\t/**\n 617:\t * vlan_get_protocol_offset_inline() - get protocol EtherType.\n 618:\t * @skb: skbuff to query\n 619:\t * @type: first vlan protocol\n 620:\t * @mac_offset: MAC offset\n 621:\t * @depth: buffer to store length of eth and vlan tags in bytes\n 622:\t *\n 623:\t * Returns: the EtherType of the packet, regardless of whether it is\n 624:\t * vlan encapsulated (normal or hardware accelerated) or not.\n 625:\t */\n 626:\tstatic inline\n 627:\t__be16 vlan_get_protocol_offset_inline(const struct sk_buff *skb,\n 628:\t\t\t\t\t __be16 type,\n 629:\t\t\t\t\t int mac_offset,\n 630:\t\t\t\t\t int *depth)\n 631:\t{\n 632:\t\tif (eth_type_vlan(type)) {\n 633:\t\t\tstruct vlan_type_depth res;\n 634:\t\n 635:\t\t\tres = __vlan_get_protocol_offset(skb, type, mac_offset);\n 636:\t\n 637:\t\t\tif (depth \u0026\u0026 res.type)\n 638:\t\t\t\t*depth = res.depth;\n 639:\t\t\treturn res.type;\n 640:\t\t}\n 641:\t\n 642:\t\tif (depth)\n 643:\t\t\t*depth = skb-\u003emac_len;\n 644:\t\n 645:\t\treturn type;\n 646:\t}\n 647:\t\n 648:\tstatic inline __be16 __vlan_get_protocol(const struct sk_buff *skb, __be16 type,\n 649:\t\t\t\t\t\t int *depth)\n 650:\t{\n 651:\t\treturn vlan_get_protocol_offset_inline(skb, type, 0, depth);\n 652:\t}\n 653:\t\n 654:\t/**\n 655:\t * vlan_get_protocol - get protocol EtherType.\n 656:\t * @skb: skbuff to query\n 657:\t *\n 658:\t * Returns: the EtherType of the packet, regardless of whether it is\n 659:\t * vlan encapsulated (normal or hardware accelerated) or not.\n"
} |
| 49/3 | 2026/12/01 04:25 | tool | grepper |
0mArgs:{
"Expression": "eth_header_parse_protocol|__vlan_get_protocol_offset"
}Results: {
"Output": "drivers/net/ethernet/stmicro/stmmac/stmmac_main.c=4895=static bool stmmac_has_ip_ethertype(struct stmmac_priv *priv,\n--\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-4897-{\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c:4898:\t__be16 proto, h_proto = eth_header_parse_protocol(skb);\ndrivers/net/ethernet/stmicro/stmmac/stmmac_main.c-4899-\tint max_l2_hlen, depth = 0;\n--\ndrivers/net/ipvlan/ipvlan_main.c=443=static const struct header_ops ipvlan_header_ops = {\n--\ndrivers/net/ipvlan/ipvlan_main.c-447-\t.cache_update\t= eth_header_cache_update,\ndrivers/net/ipvlan/ipvlan_main.c:448:\t.parse_protocol\t= eth_header_parse_protocol,\ndrivers/net/ipvlan/ipvlan_main.c-449-};\n--\ndrivers/net/macvlan.c=627=static const struct header_ops macvlan_hard_header_ops = {\n--\ndrivers/net/macvlan.c-631-\t.cache_update\t= eth_header_cache_update,\ndrivers/net/macvlan.c:632:\t.parse_protocol\t= eth_header_parse_protocol,\ndrivers/net/macvlan.c-633-};\n--\ninclude/linux/etherdevice.h=77=void eth_header_cache_update(struct hh_cache *hh, const struct net_device *dev,\ninclude/linux/etherdevice.h-78-\t\t\t const unsigned char *haddr);\ninclude/linux/etherdevice.h:79:__be16 eth_header_parse_protocol(const struct sk_buff *skb);\ninclude/linux/etherdevice.h-80-int eth_prepare_mac_addr_change(struct net_device *dev, void *p);\n--\ninclude/linux/if_vlan.h=607=struct vlan_type_depth {\n--\ninclude/linux/if_vlan.h-611-\ninclude/linux/if_vlan.h:612:struct vlan_type_depth __vlan_get_protocol_offset(const struct sk_buff *skb,\ninclude/linux/if_vlan.h-613-\t\t\t\t\t\t __be16 type,\n--\ninclude/linux/if_vlan.h=627=__be16 vlan_get_protocol_offset_inline(const struct sk_buff *skb,\n--\ninclude/linux/if_vlan.h-634-\ninclude/linux/if_vlan.h:635:\t\tres = __vlan_get_protocol_offset(skb, type, mac_offset);\ninclude/linux/if_vlan.h-636-\n--\nnet/core/skbuff.c=8053=EXPORT_SYMBOL(net_iov_dec_ref);\nnet/core/skbuff.c-8054-\nnet/core/skbuff.c:8055:struct vlan_type_depth __vlan_get_protocol_offset(const struct sk_buff *skb,\nnet/core/skbuff.c-8056-\t\t\t\t\t\t __be16 type,\n--\nnet/core/skbuff.c-8088-}\nnet/core/skbuff.c:8089:EXPORT_SYMBOL(__vlan_get_protocol_offset);\n--\nnet/ethernet/eth.c=239=EXPORT_SYMBOL(eth_header_cache_update);\n--\nnet/ethernet/eth.c-241-/**\nnet/ethernet/eth.c:242: * eth_header_parse_protocol - extract protocol from L2 header\nnet/ethernet/eth.c-243- * @skb: packet to extract protocol from\nnet/ethernet/eth.c-244- */\nnet/ethernet/eth.c:245:__be16 eth_header_parse_protocol(const struct sk_buff *skb)\nnet/ethernet/eth.c-246-{\n--\nnet/ethernet/eth.c-250-}\nnet/ethernet/eth.c:251:EXPORT_SYMBOL(eth_header_parse_protocol);\nnet/ethernet/eth.c-252-\n--\nnet/ethernet/eth.c=314=const struct header_ops eth_header_ops ____cacheline_aligned = {\n--\nnet/ethernet/eth.c-318-\t.cache_update\t= eth_header_cache_update,\nnet/ethernet/eth.c:319:\t.parse_protocol\t= eth_header_parse_protocol,\nnet/ethernet/eth.c-320-};\n"
} |
| 50/3 | 2026/12/01 04:25 | llm | kmsan-evaluator |
0mModel:gemini-4-hydrogen Args: null Results: null Tokens: input: 34447 output: 52 thoughts: 1611 Thoughts: **XDP Buffer Shrinkage and Stmmac XSK Integration** Okay, let's dive into these changes. My initial thought is to examine the evolution of buffer shrinking functions, specifically `bpf_xdp_pull_data`, `xdp_buff_shrink_data`, `xdp_frags_shrink_tail`, and the newly introduced `xdp_buff_shrink_tail`. First, I need to confirm the history of these functions. I recall that `bpf_xdp_frags_shrink_tail` and `bpf_xdp_shrink_data` were originally located within `net/core/filter.c`. Now, they've been relocated to `net/core/xdp.c` and renamed to `xdp_frags_shrink_tail` and `xdp_buff_shrink_data` respectively. Also, `xdp_buff_shrink_tail` has been added. My main concern now is to see if any logic has changed in the code. Upon inspection, `xdp_frags_shrink_tail` appears to be functionally identical to the previous `bpf_xdp_frags_shrink_tail`. It calls `xdp_buff_shrink_data` but the code remains the same. Now, I should look at `xdp_buff_shrink_tail` and see its logic. It handles the non-linear XDP buffer case by calling `xdp_frags_shrink_tail`. In the simple linear case, it updates `xdp->data_end`. Next, I need to check the changes in `stmmac_main.c` related to XDP integration. It looks like the main area of interest are `__free_dma_rx_desc_resources` and `stmmac_reset_rx_queue`, where the function `__xdp_return_buff` is called. The code checks if `rx_q->state.n_descs` is non-zero and `rx_q->xsk_pool` is empty. If so, it calls `__xdp_return_buff` to return the associated XDP buffer. If `rx_q->state.n_descs` is non-zero, this means `rx_q->state.xdp` was initialized by `xdp_init_buff` + `xdp_prepare_buff`. I'll need to double check the internals of `__xdp_return_buff` which can be found in `net/core/xdp.c`. It iterates through fragments and calls `__xdp_return` on each fragment. After the loop, it returns the buffer's data. All of the variables being read here (`xdp->flags`, `sinfo->nr_frags`, `sinfo->frags[i]`, `xdp->rxq->mem.type`, `xdp->data`) must be initialized properly! Also, in `__alloc_dma_rx_desc_resources` there's a change to how `rx_q->napi_skb_frag_size` is calculated. It used to be `num_pages * PAGE_SIZE`, but now it's `PAGE_SIZE << pp_params.order`. Since `pp_params.order = order_base_2(num_pages);`, this represents a power of 2 page allocation size, to match the `page_pool` allocation size. And, since `__xdp_rxq_info_reg` sets `frag_size` on `xdp_rxq`, I need to check the exact location of `rx_q->queue_index`, `rx_q->priv_data`, and `rx_q->napi_skb_frag_size`! I need to ensure there are no unintended side effects by double-checking lines 2315-2360 of `stmmac_main.c`! |
| 51/3 | 2026/12/01 04:25 | tool | read-file |
0mArgs:{
"File": "drivers/net/ethernet/stmicro/stmmac/stmmac_main.c",
"FirstLine": 2315,
"LineCount": 55
}Results: {
"Contents": "2315:\t\tint ret;\n2316:\t\n2317:\t\tdma_buf_sz_pad = stmmac_rx_offset(priv) + dma_conf-\u003edma_buf_sz +\n2318:\t\t\t\t SKB_DATA_ALIGN(sizeof(struct skb_shared_info));\n2319:\t\tnum_pages = DIV_ROUND_UP(dma_buf_sz_pad, PAGE_SIZE);\n2320:\t\n2321:\t\tpp_params.flags = PP_FLAG_DMA_MAP | PP_FLAG_DMA_SYNC_DEV;\n2322:\t\tpp_params.pool_size = dma_conf-\u003edma_rx_size;\n2323:\t\tpp_params.order = order_base_2(num_pages);\n2324:\t\tpp_params.nid = dev_to_node(priv-\u003edevice);\n2325:\t\tpp_params.dev = priv-\u003edevice;\n2326:\t\tpp_params.dma_dir = xdp_prog ? DMA_BIDIRECTIONAL : DMA_FROM_DEVICE;\n2327:\t\tpp_params.offset = 0;\n2328:\t\tpp_params.max_len = dma_conf-\u003edma_buf_sz + stmmac_rx_offset(priv);\n2329:\t\n2330:\t\trx_q-\u003epage_pool = page_pool_create(\u0026pp_params);\n2331:\t\tif (IS_ERR(rx_q-\u003epage_pool)) {\n2332:\t\t\tret = PTR_ERR(rx_q-\u003epage_pool);\n2333:\t\t\trx_q-\u003epage_pool = NULL;\n2334:\t\t\treturn ret;\n2335:\t\t}\n2336:\t\n2337:\t\trx_q-\u003ebuf_pool = kzalloc_objs(*rx_q-\u003ebuf_pool, dma_conf-\u003edma_rx_size);\n2338:\t\tif (!rx_q-\u003ebuf_pool) {\n2339:\t\t\tret = -ENOMEM;\n2340:\t\t\tgoto err_destroy_pool;\n2341:\t\t}\n2342:\t\n2343:\t\tsize = stmmac_get_rx_desc_size(priv) * dma_conf-\u003edma_rx_size;\n2344:\t\n2345:\t\taddr = dma_alloc_coherent(priv-\u003edevice, size, \u0026rx_q-\u003edma_rx_phy,\n2346:\t\t\t\t\t GFP_KERNEL);\n2347:\t\tif (!addr) {\n2348:\t\t\tret = -ENOMEM;\n2349:\t\t\tgoto err_free_buf_pool;\n2350:\t\t}\n2351:\t\n2352:\t\trx_q-\u003equeue_index = queue;\n2353:\t\trx_q-\u003epriv_data = priv;\n2354:\t\trx_q-\u003enapi_skb_frag_size = PAGE_SIZE \u003c\u003c pp_params.order;\n2355:\t\n2356:\t\tif (priv-\u003eextend_desc)\n2357:\t\t\trx_q-\u003edma_erx = addr;\n2358:\t\telse\n2359:\t\t\trx_q-\u003edma_rx = addr;\n2360:\t\n2361:\t\tif (stmmac_xdp_is_enabled(priv) \u0026\u0026\n2362:\t\t test_bit(queue, priv-\u003eaf_xdp_zc_qps))\n2363:\t\t\tnapi_id = ch-\u003erxtx_napi.napi_id;\n2364:\t\telse\n2365:\t\t\tnapi_id = ch-\u003erx_napi.napi_id;\n2366:\t\n2367:\t\tret = __xdp_rxq_info_reg(\u0026rx_q-\u003exdp_rxq, priv-\u003edev, queue, napi_id,\n2368:\t\t\t\t\t rx_q-\u003enapi_skb_frag_size);\n2369:\t\tif (ret) {\n"
} |
| 52/3 | 2026/12/01 04:25 | llm | kmsan-evaluator |
0mModel:gemini-4-hydrogen Args: null Results: null Tokens: input: 37115 output: 676 thoughts: 2647 Thoughts: **Analysis of Potential Uninitialized Memory Risks in the STMMAC Driver and XDP Core Changes** Okay, let's break this down. First, I focused on the changes to `stmmac_rx`, `stmmac_xdp_run_prog`, and associated functions, particularly concerning XDP integration. The initialization of the `res` variable in `stmmac_xdp_run_prog` to `STMMAC_XDP_CONSUMED` is a minor, but good, defensive programming improvement. I then dug deep into `stmmac_rx`, especially the handling of `ctx.xdp`. I traced its usage meticulously, looking for places where uninitialized data could be copied or dereferenced. The key concern was the potential for the `ctx.xdp` struct to contain uninitialized data when `rx_q->state_saved` is true, and the descriptor loop restarts. However, I concluded that even if `ctx.xdp` is copied to `rx_q->state.xdp`, that copy doesn't actually trigger any use of the data itself - even though it is uninitialized, the code paths either avoid using the uninitialized data, or the initialization of `ctx.xdp` happens before any dereferencing. I also considered the case where `n_descs == 0` and looked at how `xdp_init_buff` and `xdp_prepare_buff` are always called in this case, ensuring initialization. I confirmed that even if `ctx.xdp.txq` is set (which is rare), it is never read/dereferenced by `xdp_build_skb_from_buff` or `__xdp_return_buff`, or `xdp_buff_shrink_tail`. Next, I examined the `xdp_buff_shrink_tail` and `xdp_buff_shrink_data` functions in the core XDP code and looked for any new potential risks. My analysis of `xdp_frags_shrink_tail` found that it essentially mirrors the original behavior of `bpf_xdp_frags_shrink_tail`, so it's not introducing anything new. I then reviewed other functions, like `stmmac_has_ip_ethertype`, `stmmac_selftest_run`, `stmmac_fix_features`, `stmmac_set_features`, and `__stmmac_dvr_probe`. These functions don't look like they introduce any memory safety issues. Finally, I emphasized that the changes are primarily a refactoring to move the FCS stripping/tail shrinking functionality into a shared core `xdp_buff_shrink_tail` function, and that this shift does not appear to introduce any uninitialized memory read issues. It only makes the stripping easier to read by factoring out the logic. I looked for potential risks across the board and concluded the changes don't expose any uninitialized data to userspace, or conditional logic on uninitialized values. The patch does not do any potentially dangerous things. |
| 53/3 | 2026/12/01 04:25 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch series makes two main sets of changes:\n1. Refactors `bpf_xdp_frags_shrink_tail` and `bpf_xdp_shrink_data` from `net/core/filter.c` into `xdp_buff_shrink_tail` and `xdp_buff_shrink_data` in `net/core/xdp.c` (preserving the exact shrink bounds checks and logic, without adding any tail-growth paths or uninitialized reads).\n2. Updates the `stmmac` Ethernet driver (`drivers/net/ethernet/stmicro/stmmac/`) to build RX packets via `struct xdp_buff` (`ctx.xdp`, `xdp_init_buff`, `xdp_prepare_buff`, `xdp_buff_add_frag`, `xdp_buff_shrink_tail`, `xdp_build_skb_from_buff`, `__xdp_return_buff`), adjusts VLAN RX offload feature detection (`stmmac_rx_8021q_offload`, `stmmac_rx_8021ad_offload`, `stmmac_has_ip_ethertype`), and adds `phylink_rx_clk_stop_block/unblock` in `stmmac_selftest_run`.\n\nAnalysis of KMSAN vs KASAN applicability:\n- No kernel structures are newly allocated or copied to user space (`copy_to_user`, `put_user`, netlink attributes, ioctl outputs, or BPF buffers) with potential uninitialized fields or struct padding leaks.\n- All stack and state variables introduced or modified (such as `ctx.priv`, `n_descs`, `res` in `stmmac_xdp_run_prog`, `depth` in `stmmac_has_ip_ethertype`, and `xdp_buff` fields initialized via `xdp_init_buff`/`xdp_prepare_buff` when `n_descs == 0`) are properly initialized before being read or branched on. (Even if `rx_q-\u003estate.xdp = ctx.xdp` executes when `in_progress` is true with `n_descs == 0` and `error == 1`, `rx_q-\u003estate.xdp` is never read when `n_descs == 0`.)\n- `xdp_buff_shrink_tail` only shrinks `data_end` or fragment sizes after bounds checks (`ETH_HLEN`), and `rx_q-\u003enapi_skb_frag_size` is updated to `PAGE_SIZE \u003c\u003c pp_params.order` to match the allocated page pool order rather than exposing uninitialized buffer bytes.\n- Potential bugs in RX descriptor/fragment handling, bounds checks, or reference counting (such as out-of-bounds accesses, use-after-free, or page pool refcount issues) are memory corruption / lifetime errors caught by KASAN and standard debug checks rather than uninitialized memory bugs requiring KMSAN.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch series makes two main sets of changes:\n1. Refactors `bpf_xdp_frags_shrink_tail` and `bpf_xdp_shrink_data` from `net/core/filter.c` into `xdp_buff_shrink_tail` and `xdp_buff_shrink_data` in `net/core/xdp.c` (preserving the exact shrink bounds checks and logic, without adding any tail-growth paths or uninitialized reads).\n2. Updates the `stmmac` Ethernet driver (`drivers/net/ethernet/stmicro/stmmac/`) to build RX packets via `struct xdp_buff` (`ctx.xdp`, `xdp_init_buff`, `xdp_prepare_buff`, `xdp_buff_add_frag`, `xdp_buff_shrink_tail`, `xdp_build_skb_from_buff`, `__xdp_return_buff`), adjusts VLAN RX offload feature detection (`stmmac_rx_8021q_offload`, `stmmac_rx_8021ad_offload`, `stmmac_has_ip_ethertype`), and adds `phylink_rx_clk_stop_block/unblock` in `stmmac_selftest_run`.\n\nAnalysis of KMSAN vs KASAN applicability:\n- No kernel structures are newly allocated or copied to user space (`copy_to_user`, `put_user`, netlink attributes, ioctl outputs, or BPF buffers) with potential uninitialized fields or struct padding leaks.\n- All stack and state variables introduced or modified (such as `ctx.priv`, `n_descs`, `res` in `stmmac_xdp_run_prog`, `depth` in `stmmac_has_ip_ethertype`, and `xdp_buff` fields initialized via `xdp_init_buff`/`xdp_prepare_buff` when `n_descs == 0`) are properly initialized before being read or branched on. (Even if `rx_q-\u003estate.xdp = ctx.xdp` executes when `in_progress` is true with `n_descs == 0` and `error == 1`, `rx_q-\u003estate.xdp` is never read when `n_descs == 0`.)\n- `xdp_buff_shrink_tail` only shrinks `data_end` or fragment sizes after bounds checks (`ETH_HLEN`), and `rx_q-\u003enapi_skb_frag_size` is updated to `PAGE_SIZE \u003c\u003c pp_params.order` to match the allocated page pool order rather than exposing uninitialized buffer bytes.\n- Potential bugs in RX descriptor/fragment handling, bounds checks, or reference counting (such as out-of-bounds accesses, use-after-free, or page pool refcount issues) are memory corruption / lifetime errors caught by KASAN and standard debug checks rather than uninitialized memory bugs requiring KMSAN.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|