Skip to contentSkip to conversation

xdp: propagate queue_index through xdp_frame

PATCH New Anand Kumar Shaw 2 participants 3 messages Feb 17 1 message not in the archive

Subsystems (4)
lore
Share & tools
lore
#1 lore raw

PATCH 1/2 xdp: propagate queue_index through xdp_frame

In reply to a message not in the archive

When an XDP frame is redirected via cpumap or devmap, the original RX queue index from xdp_rxq_info is lost during the xdp_buff to xdp_frame conversion. This causes BPF programs running on the remote CPU to always see rx_queue_index as 0, and SKBs built from xdp_frame to lack proper RX queue metadata.

Add a queue_index field to struct xdp_frame and populate it from xdp->rxq->queue_index in both the normal conversion path (xdp_convert_buff_to_frame) and the zero-copy path (xdp_convert_zc_to_xdp_frame).

Additionally, call skb_record_rx_queue() in __xdp_build_skb_from_frame() to set the RX queue on SKBs built from xdp_frame, resolving a documented gap in the function.

---
 include/net/xdp.h | 2 ++
 net/core/xdp.c    | 3 ++-
 2 files changed, 4 insertions(+), 1 deletion(-)
include/net/xdp.h +2 -0
index aa742f413c35..4912e132ff84 100644
@@ -303,6 +303,7 @@ struct xdp_frame {
 	struct net_device *dev_rx; /* used by cpumap */
 	u32 frame_sz;
 	u32 flags; /* supported values defined in xdp_buff_flags */
+	u32 queue_index;
 };
 
 static __always_inline bool xdp_frame_has_frags(const struct xdp_frame *frame)
@@ -441,6 +442,7 @@ struct xdp_frame *xdp_convert_buff_to_frame(struct xdp_buff *xdp)
 
 	/* rxq only valid until napi_schedule ends, convert to xdp_mem_type */
 	xdp_frame->mem_type = xdp->rxq->mem.type;
+	xdp_frame->queue_index = xdp->rxq->queue_index;
 
 	return xdp_frame;
 }
net/core/xdp.c +2 -1
index fee6d080ee85..2d6a3f2c9584 100644
@@ -606,6 +606,7 @@ struct xdp_frame *xdp_convert_zc_to_xdp_frame(struct xdp_buff *xdp)
 	xdpf->metasize = metasize;
 	xdpf->frame_sz = PAGE_SIZE;
 	xdpf->mem_type = MEM_TYPE_PAGE_ORDER0;
+	xdpf->queue_index = xdp->rxq->queue_index;
 
 	xsk_buff_free(xdp);
 	return xdpf;
@@ -833,8 +834,8 @@ struct sk_buff *__xdp_build_skb_from_frame(struct xdp_frame *xdpf,
 	/* Optional SKB info, currently missing:
 	 * - HW checksum info		(skb->ip_summed)
 	 * - HW RX hash			(skb_set_hash)
-	 * - RX ring dev queue index	(skb_record_rx_queue)
 	 */
+	skb_record_rx_queue(skb, xdpf->queue_index);
 
 	if (xdpf->mem_type == MEM_TYPE_PAGE_POOL)
 		skb_mark_for_recycle(skb);
Signature · 1 line
2.39.5 (Apple Git-154)
#2 lore raw

PATCH 2/2 bpf: report queue_index to xdp_rxq_info in cpumap and devmap

In reply to a message not in the archive

When a second-stage XDP program runs on a cpumap or devmap redirected frame, ctx->rx_queue_index always returns 0 because the reconstructed xdp_rxq_info never had queue_index set.

Now that xdp_frame carries queue_index, set rxq.queue_index from xdpf->queue_index in both cpu_map_bpf_prog_run_xdp() and dev_map_bpf_prog_run(). This allows BPF programs to correctly identify the original hardware RX queue after a cpumap or devmap redirect.

Resolves a TODO left since the cpumap implementation.

---
 kernel/bpf/cpumap.c | 2 +-
 kernel/bpf/devmap.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
kernel/bpf/cpumap.c +1 -1
index 04171fbc39cb..f5b2ff17e328 100644
@@ -195,7 +195,7 @@ static int cpu_map_bpf_prog_run_xdp(struct bpf_cpu_map_entry *rcpu,
 
 		rxq.dev = xdpf->dev_rx;
 		rxq.mem.type = xdpf->mem_type;
-		/* TODO: report queue_index to xdp_rxq_info */
+		rxq.queue_index = xdpf->queue_index;
 
 		xdp_convert_frame_to_buff(xdpf, &xdp);
 
kernel/bpf/devmap.c +1 -0
index 2625601de76e..aa2e929792c8 100644
@@ -346,6 +346,7 @@ static int dev_map_bpf_prog_run(struct bpf_prog *xdp_prog,
 		u32 act;
 		int err;
 
+		rxq.queue_index = xdpf->queue_index;
 		xdp_convert_frame_to_buff(xdpf, &xdp);
 		xdp.txq = &txq;
 		xdp.rxq = &rxq;
Signature · 1 line
2.39.5 (Apple Git-154)
#3 lore raw

Re: [PATCH 2/2] bpf: report queue_index to xdp_rxq_info in cpumap and devmap

This approach of adding queue_index to struct xdp_frame was previously submitted by Lorenzo Bianconi and discussed in January 2026 when saiaunghlyanhtet posted the same change (v1 through v3).

kernel/bpf/cpumap.c struct xdp_rxq_info rxq = {}; · line 198

Quoted 9 lines
kernel/bpf/cpumap.c +1 -1
@@ -195,7 +195,7 @@ struct xdp_rxq_info rxq = {};
 
 		rxq.dev = xdpf->dev_rx;
 		rxq.mem.type = xdpf->mem_type;
-		/* TODO: report queue_index to xdp_rxq_info */
+		rxq.queue_index = xdpf->queue_index;

This approach of adding queue_index to struct xdp_frame was previously submitted by Lorenzo Bianconi and discussed in January 2026 when saiaunghlyanhtet posted the same change (v1 through v3).

Toke Hoiland-Jorgensen pointed out the earlier submission was rejected because adding fields to xdp_frame ad-hoc was not the preferred direction:

https://lore.kernel.org/bpf/[email protected]/

Jesper Dangaard Brouer (XDP maintainer) further noted that queue_index is not the most interesting metadata to propagate through cpumap, and pointed to his RX hints series as the proper mechanism for restoring metadata lost during XDP redirect:

https://lore.kernel.org/bpf/[email protected]/

Has the design concern about ad-hoc xdp_frame field additions been resolved since January, or should this wait for the RX hints infrastructure?

kernel/bpf/devmap.c

Quoted 1 line
kernel/bpf/devmap.c +0 -0

[ ... ]

---
AI reviewed your patch. Please fix the bug or email reply why it's not a bug.
See: https://github.com/kernel-patches/vmtest/blob/master/ci/claude/README.md

CI run summary: https://github.com/kernel-patches/bpf/actions/runs/22103049906

AI-authorship-score: medium
AI-authorship-explanation: Polished commit messages and cover letter with precise technical details for an apparent first-time contributor resubmitting a recently rejected approach suggest possible AI assistance, though the code itself is too simple to determine.
issues-found: 1
issue-severity-score: low
issue-severity-explanation: Unaddressed design concern from XDP maintainer about ad-hoc xdp_frame field additions; the code itself is correct but the approach was previously rejected.