From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4DBD230BDB for ; Thu, 11 Jun 2026 08:30:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781166642; cv=none; b=pAGV0jSlTAHeQWqcWWtBGhxNUXIQrxlMLaO3vUR3Fb62YWNiUmxIrfnAMpsFd0ZOuYm+lNH7LnvBLWQsxCFCLpnzGCMK9lq5cMfQRBvudPivE1/QsdXWJDkELiSW7Hc1B97+56iY/Pu3xKMgN3fzmtyEYNovxS9xdhvKonuqjMs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781166642; c=relaxed/simple; bh=XR0V+4h+8MJh9uy6euPn7a63rvq06PZMS77yDeSWSwQ=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=Bt7Iewy0mZCSTPfTHX+0Na1fQ+Xn9DuLWW7pYfEedgXIGdopvJEQ+xwnODX71vJF+g3pGNh4O7jFOOcOtvSrvXE7PG+hVs96qgTikoHRcgrdFSwxnMOGlEyCjlhqDnMNyPjOcAsG0YoSoM9CYDsPn0dKOCkCH9/ftxmE8l/zOFY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ctDdKLeH; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=XFevLNkb; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ctDdKLeH"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="XFevLNkb" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781166639; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=K0b7sev+YXar1BdsAXXs6+O/y7RGvS4oVWMa4UAvNR4=; b=ctDdKLeHJRLv5m4ouOEffdB3b8dMB1SYIaqvPfmg7+M+zZsNIwwCSEJbHGFhN5mdB1EbKp ckjha26x5ELzzLHrCMciBPGgESKot7uOIhfVmVYBR6qDKztklov2TKgRA+9hTYYBgv8SeF aOyX6yOsFDjV9gF/L7PtRMPzSLzqDMU= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-264-ce35iAJXPvu0L5ItbDcL4A-1; Thu, 11 Jun 2026 04:30:38 -0400 X-MC-Unique: ce35iAJXPvu0L5ItbDcL4A-1 X-Mimecast-MFC-AGG-ID: ce35iAJXPvu0L5ItbDcL4A_1781166637 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-490e17fff23so6830045e9.3 for ; Thu, 11 Jun 2026 01:30:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1781166637; x=1781771437; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:from:to:cc:subject:date:message-id :reply-to; bh=K0b7sev+YXar1BdsAXXs6+O/y7RGvS4oVWMa4UAvNR4=; b=XFevLNkbb2tPXCzcxti/MwmkwoZL1FVCyYfFqjRoidx3forL6ayFkISRluyeI3VOL4 nZ4MC3HZ4+5nwOTxeBihImXnsk4JOeR6dYziKuL0nyz7guzIWcathuGv4rqNf+jCbkrY WDgSOc9CUsSLWEqPD8EbYMQw7u6xdsThNWiFfLeXMDhCui5po1XTqRFt8XSDTBvpUBuE DAGcyesZ3jcAeqpjVfTBm90uBo/QreH+10Ct2WlOzdk1l9dxQw8DDKZWGBCJtDTBi78a BtzOclt9zyK/DM+MW9S03kH8Nd8o92gPlLSZs+i9yk+YMniYe8UK9RS24Zifbmn7lBC5 5N4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781166637; x=1781771437; h=content-transfer-encoding:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:x-gm-gg:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=K0b7sev+YXar1BdsAXXs6+O/y7RGvS4oVWMa4UAvNR4=; b=UZbJfvh68nyMXY2nNRYpXNOM0M7e0ICYvPtX5HkszOzcjirAF8gm8KrZM6xYjdiEK2 Dpt3pDqLYT8ESKpVIut5hP8JU22TL40fQAnEuzw2/YZHHEe2xfi9Fwn5a87V+/ErPbJj ML4lDXQ+XvweiUGNFF6mbtne+on1PJsgDiB94p0YPGKgoYK8yznHNpV9rvL8SCcMuPwt ztmVHFxCAmz5w0KMOQdQP47E2Oem54mgIhOQZ2oUVnMNrTfSf7RSG7MAIUtet2tPvDHy 5pUaA48AhXBVJEEb3c3GPnaqi1p2G5qWrA7Sm4VATC8lvhVGyV2VhCHbMQNHfD2RXw6Z D7Gw== X-Forwarded-Encrypted: i=1; AFNElJ/B3GriygZezhNfDjFVz5Yaa77sHpiNSsogYBjr25izgleZSnsoWYvGYYX6v7XhjIhG84FOTwGn09E9jKY=@vger.kernel.org X-Gm-Message-State: AOJu0YyaeX1N0Xn28w3WcCB9IDxI0gpqUGXhEv0Cab6eZ804mBwwTUgZ bKqGXvmVxnsXDrcbgLCxu4fnGpyjc4wgK5GRI+NXxJgJZn8sAgQIbZz+BIKDfVceyPNwXVqBohC EfQIkNsQ0xDGCouSeYIjW3ii/4vYnNON6RgmK7X1N3Qdlwna0nkDQt7+Fv+q13edfmw== X-Gm-Gg: Acq92OFEP48Mc/neLpsyoNOqhIY+6wsGsWgTzgLNahvL8toRJIDyECZUvN4H7lYfVAX Qgv6e0enSnlxpkul04wMrBUtVPynrwK+VpGUY6C4HtFdygY6778PlKzezgDLQTkyth/QuuF5sLk /t86Cr27ot7j0acv1+JTjEYiAJHE5+yRmdsJokaHTEL9A8gMIfPqJjrhS+PX/km57rE+jz82A8m IB3Tb9lLEq0LtfgANBooj2JzAOhp5cr3Apvge1P7rH2R8IGuLJ2fzrXdN31qzEEZMgVh9T5Kjo6 4vYhw8Vec4Szast6nRUKxY7YD7M8dXZQ/Ub7iHM/YwBJ4ZJOVcc6H0kXOmhhRIvl7fCTH6l8rzp 5m6spLFHiLcHEV4SaV8c2cLFZLU+g2yIGfRNZ5kDeZy+vU1hk7Cq8GofP X-Received: by 2002:a05:600c:4444:b0:490:bcf6:469f with SMTP id 5b1f17b1804b1-490e534d301mr20585795e9.0.1781166636985; Thu, 11 Jun 2026 01:30:36 -0700 (PDT) X-Received: by 2002:a05:600c:4444:b0:490:bcf6:469f with SMTP id 5b1f17b1804b1-490e534d301mr20585325e9.0.1781166636452; Thu, 11 Jun 2026 01:30:36 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-490e2c9057bsm55175325e9.5.2026.06.11.01.30.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2026 01:30:35 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 0F0E17BCC96; Thu, 11 Jun 2026 10:30:35 +0200 (CEST) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Sun Jian , bpf@vger.kernel.org Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@linux.dev, davem@davemloft.net, kuba@kernel.org, hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me, shuah@kernel.org, jiayuan.chen@linux.dev, menglong.dong@linux.dev, emil@etsalapatis.com, Sun Jian Subject: Re: [PATCH bpf v4 1/2] bpf: Run generic devmap egress prog on private skb In-Reply-To: <20260611080850.536996-2-sun.jian.kdev@gmail.com> References: <20260611080850.536996-1-sun.jian.kdev@gmail.com> <20260611080850.536996-2-sun.jian.kdev@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett Date: Thu, 11 Jun 2026 10:30:35 +0200 Message-ID: <87se6t8ono.fsf@toke.dk> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Sun Jian writes: > Generic XDP devmap multi redirect uses skb_clone() for intermediate > destinations and sends the last destination with the original skb. This > can leave multiple destinations sharing the same packet data. > > This becomes visible after generic devmap egress-program support was > added: a devmap egress program may mutate packet data, and another > destination sharing the same data can observe that mutation. > > Native XDP broadcast redirect does not have this issue because > xdpf_clone() copies the frame data for each destination. Generic XDP > should provide the same per-destination isolation before running a > devmap egress program. > > Fix this by making cloned skbs private before running the generic devmap > egress program. Use skb_copy() instead of skb_unshare() so allocation > failure does not consume the skb and the existing caller error paths keep > their ownership semantics. > > Fixes: 2ea5eabaf04a ("bpf: devmap: Implement devmap prog execution for ge= neric XDP") > Suggested-by: Jiayuan Chen > Suggested-by: Jakub Kicinski > Reviewed-by: Toke H=C3=B8iland-J=C3=B8rgensen > Signed-off-by: Sun Jian > --- > kernel/bpf/devmap.c | 41 +++++++++++++++++++++++++++++++---------- > 1 file changed, 31 insertions(+), 10 deletions(-) > > diff --git a/kernel/bpf/devmap.c b/kernel/bpf/devmap.c > index cc0a43ebab6b..a3d6c60dbddb 100644 > --- a/kernel/bpf/devmap.c > +++ b/kernel/bpf/devmap.c > @@ -512,35 +512,52 @@ static inline int __xdp_enqueue(struct net_device *= dev, struct xdp_frame *xdpf, > return 0; > } >=20=20 > -static u32 dev_map_bpf_prog_run_skb(struct sk_buff *skb, struct bpf_dtab= _netdev *dst) > +static int dev_map_bpf_prog_run_skb(struct sk_buff **pskb, > + struct bpf_dtab_netdev *dst, > + u32 *act) > { > + struct sk_buff *skb =3D *pskb; > struct xdp_txq_info txq =3D { .dev =3D dst->dev }; > struct xdp_buff xdp; > - u32 act; >=20=20 > - if (!dst->xdp_prog) > - return XDP_PASS; > + if (!dst->xdp_prog) { > + *act =3D XDP_PASS; > + return 0; > + } > + > + if (skb_cloned(skb)) { > + struct sk_buff *nskb; > + > + nskb =3D skb_copy(skb, GFP_ATOMIC); > + if (!nskb) > + return -ENOMEM; > + > + nskb->mac_len =3D skb->mac_len; > + consume_skb(skb); > + skb =3D nskb; > + *pskb =3D nskb; > + } So with all this pointer soup and back and forth, the version you had in v2 (with the check and skb_copy() in dev_map_generic_redirect()) was much cleaner :/ -Toke