[RFC] xdp: Multi-Return Value Support For XDP

"Ye Zhengnan" <[email protected]> Wed, 7 May 2025 11:52:21 +0000
Newsgroups org.kernel.vger.xdp-newbies
Message-ID <183d3c7dd7e5c1de.576ea80cc02721fa.fe043bcc144c6691@mulp>
Hi all,

I'm proposing support for multiple return values in XDP programs to
enable combined actions like XDP_TX/XDP_REDIRECT with XDP_PASS. Please
review this design proposal and share your feedback.

=3D=3D Motivation =3D=3D

Current mutually exclusive return values prevent scenarios like:
- Fast forwarding (XDP_TX/XDP_REDIRECT) and ack by kernel network=20
stack (XDP_PASS)
- Traffic balancing while maintaining normal processing

=3D=3D Design Proposal =3D=3D

Option 1: True Tail Call Implementation

For Generic XDP:
  1. Parent XDP program:
    - Specify child XDP program using new helper functions
    - Return combined flags such as XDP_CALL | XDP_TX
  2. In net/core/dev.c:
    - After XDP_TX or XDP_REDIRECT, check XDP_CALL flag
      * Get child XDP program via bpf_tail_call
      * Goto netif_receive_generic_xdp()
    - Before bpf_net_ctx_set(), two approaches:
      a. Synchronous: ensure skb not recycled, run child XDP program
      b. Cloning: copy skb before driver uses it

For Native XDP:
  - Synchronization cost of TX operation is unclear
  - Cloning skb may be necessary
  - Offload XDP support is not considered for now

Challenges:=20
  - Conflicting packet modifications between parent/child programs
  - Potential need for packet cloning (performance impact)
  - Safe skb management when combining actions

Option 2: bpf_clone_redirect() for XDP

- Clone skb before return via bpf_clone_redirect()
- Send cloned skb to ingress path via backlog
- Prepare child XDP on target networker

Current Limitations:=20
- Redirect to ingress path not fully supported
- Memory copy overhead in XDP fast path

I'm new to Linux kernel development and would greatly appreciate
any feedback, suggestions, or corrections regarding this proposal or
the process.

Thank you for your time and consideration.

Best regards