On Wed, Jun 10, 2026 at 1:13 PM Jiayuan Chen <[email protected]> wrote: > > > On 6/10/26 9:58 AM, sun jian wrote: > > On Wed, Jun 10, 2026 at 9:21 AM Menglong Dong <[email protected]> > > wrote: > >> On 2026/6/10 08:06 Emil Tsalapatis <[email protected]> write: > >>> On Tue Jun 9, 2026 at 7:06 AM EDT, Menglong Dong wrote: > >>>> On 2026/6/9 18:02 Sun Jian <[email protected]> write: > [...] > >>>> Hi, Jian. > >>>> > >>>> This sounds like a good idea in this case. When I have a look at > >>>> bpf_clone_redirect(), > >>>> I found that it use skb_clone() too, which means it has the same > >>>> problem. The > >>>> data can be modified by other xdp prog in the destination NIC if we use > >>>> bpf_clone_redirect(). > >>>> > >>>> So maybe this is the default logic, and I'm not sure if this patch can > >>>> break the > >>>> existing users :/ > >>> I think for use cases where we are using bpf_clone_redirect() to use > >>> one clone for inspection this would add an unnecessary copy. Maybe > >>> adding *_copy() variants instead of changing the *_clone() would be > >>> better? That way we wouldn't be changing the behavior for existing > >>> consumers and the naming would be consistent with the skb_* methods. > >> Agree. It's not a good idea to change the logic of the existing API. Or > >> maybe we can add a BPF_F_CLONE flag for the existing API. > >> > >>> But more importantly, is there an actual use case for the kind of API > >>> that the modified selftest requires? Nobody until now has considered > >>> the existing behavior to be a problem. > >> Agree too. Obviously, this is not a bug. For the use case in the commit > >> log, it's something that can be fixed by the user themself. If we need > >> modify the MAC, we'd better attach a BPF program for all the egress > >> device in the devmap. > >> > [...] > >>>> > > Thanks for all the comments. > > > > I agree this should not be treated as a generic skb_clone() issue, and I > > understand the concern about changing existing clone/shared-data semantics. > > > > The case I was trying to address is narrower: generic XDP devmap > > broadcast/multi redirect with per-devmap-entry egress programs. The use > > case is > > not newly introduced by this patch. The existing xdp_veth_egress test > > already > > attaches xdp_devmap_prog to all egress devmap entries, and that program > > rewrites > > eth->h_source based on ctx->egress_ifindex. My change only strengthens the > > test > > from checking that the observed MAC is not equal to a single magic MAC to > > checking that each destination observes the MAC selected for its own egress > > ifindex. > > > > So attaching an egress program to all devmap entries is already what this > > test > > does. The SKB_MODE failure happens because the cloned skbs can still share > > the > > packet data, and a later per-egress rewrite can be observed by another > > destination. > > > > That said, I see the concern that this may need a clearer semantic boundary > > between clone and copy behavior. I will also check the last_dst path > > pointed out > > by Sashiko before deciding whether this should be handled as a bug fix, or > > whether it needs a separate explicit copy/isolated redirect semantic > > instead. > > > I agree there's a real concern here. For context, native XDP already > makes a full copy > of the frame for every broadcast destination: > > dev_map_enqueue_multi -> dev_map_enqueue_clone -> xdpf_clone > > so on the native path each destination gets its own independent buffer. > > The generic path is the odd one out, because skb_clone() shares the > underlying data. > I think this rationale should be spelled out in the commit message. > > Regarding performance: generic XDP is already a slow path — the ingress > side already > linearizes / expands the skb (pskb_expand_head() in > netif_receive_generic_xdp()) > so the extra copy here is not a concern. > > > However, there is one problem with the patch as it stands. > > The last destination is transmitted using the original skb directly, > without unsharing it. > So with two destinations where the first one has no egress XDP program > and the second (i.e. the last one) does, > the egress modification on the second destination will corrupt the > packet sent to the first. > > This could be addressed by doing the skb_unshare() inside > dev_map_generic_redirect() instead ? > > For the non-broadcast (existing) path the skb is not cloned, so > skb_unshare() simply returns it unchanged. > > > Hi Jiayuan,
Thanks for the detailed explanation. I checked the last_dst case and was able to reproduce it locally. In that case, earlier destinations without devmap egress programs can still observe the packet data rewritten by the final destination's egress program. I also tried your suggestion of handling this in dev_map_generic_redirect(), right before running the devmap egress program. That fixes both the original case and the last_dst case. One detail I changed in the implementation is to use skb_copy() + consume_skb() instead of skb_unshare(), so that allocation failure does not consume the skb and the existing caller error paths keep their ownership semantics. With that version, the following tests pass: ./test_progs -t xdp_veth_egress ./test_progs -t xdp_veth ./test_progs -t xdp I'll send v2 shortly. Thanks, sun jian

