Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7520141rwp; Tue, 18 Jul 2023 17:14:38 -0700 (PDT) X-Google-Smtp-Source: APBJJlErg1ecWpFudMgPB+UFjuJiyRYk284kiGIDGe4CxB59n+4vYhsRRcM+mVl5oK4KxR4h7vfo X-Received: by 2002:a17:90a:8586:b0:265:780e:5edc with SMTP id m6-20020a17090a858600b00265780e5edcmr866656pjn.10.1689725678505; Tue, 18 Jul 2023 17:14:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689725678; cv=none; d=google.com; s=arc-20160816; b=ACI4KKBuGQmbc1lCMsWtg3WYg5kNejFOr7foAJZTSronb0xOtRdFKsZ58mM1OC06Wb ZGVWVyD+mMCH3ylQ2zGQS59JW4ksQbTVGqhkTekrnNmdenF83DpKpfLijwjf81+zG/HW yJYRRXwNi4vzbXGQZ4dKdGiNBvFMTXxdDcDowhhuKOufp/XRBmz82SAKEmSbBTdorguY OL2XEpcbFyV/DDwPr2+hJgXMc3SgnT4QoMH99BBgW6SfzyyfKR6E2AKO05Y3bLoRAv7R jYZej9vPnFBO8ugDgn9EPzm9C9Q19hrD3dFIejMwGrx+2m6Zp2mPh8juYjSKs38tJRvX etdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=EzQPWMhde2JM67Z9YJrSaWfoJkaH/VUF8uE77z0Cvjs=; fh=5qA7X02o2skGitbAtY8yZLK4fmfA4uYoZfE1Tm/5VXw=; b=BwCLnUcxnLzAL8CRFjhPqYGGNZDE0zUrd+vTcXR4540n/m3jh/IY6qtEoyOs0nArs7 4mOC3DOGZbt3jDifFzAxp3JoYHjvGI6dIBgspQAYq605Y5z52HMYRAdX+Lf97exI14IC Z7TQS71yOh85FV/NgeRMZaOVSoU/RmgEryZ6AwFtVd7sMoTyNuMsZPEaAI7c8yxWPgKn kLHOiQ/2SGlPVdOZ1YG26jnRPPBzbLqdDE0x5jsb0PufpwsqXCNZqzpwhTiiCqvnIPjJ Ln77qBfh4Fl6a1p1Wijny6hyjjgxjUVVgwtnwqP0c6hWkzWol01MmjZcsbpzuXc8BNFg y/aA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=rG9L+BKf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m7-20020a17090a2c0700b00263d559dbf1si297866pjd.55.2023.07.18.17.14.25; Tue, 18 Jul 2023 17:14:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=rG9L+BKf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229934AbjGRXRm (ORCPT + 99 others); Tue, 18 Jul 2023 19:17:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbjGRXRl (ORCPT ); Tue, 18 Jul 2023 19:17:41 -0400 Received: from mail-lj1-x235.google.com (mail-lj1-x235.google.com [IPv6:2a00:1450:4864:20::235]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F008DE0; Tue, 18 Jul 2023 16:17:37 -0700 (PDT) Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-2b701dee4bfso99026221fa.0; Tue, 18 Jul 2023 16:17:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689722256; x=1692314256; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=EzQPWMhde2JM67Z9YJrSaWfoJkaH/VUF8uE77z0Cvjs=; b=rG9L+BKfL/ZAsrVSJFjjM0DSy6iUlGpCJj7xKQLmo38tapnIoC3I0vh908W1HRwDiz ZdboHB0TxJz6lM7sRMCZl1UDqZLhIF4QngAF+N+KCUycBygVpXvRswmcyJcO+IKdl9UN 1WzC+iZXqkkOgrpiVEyKxYPOLtB2bqY2Xy+c8TcBVNNzFTpsCP5b2+7b0FHzxdzrzdLA 3AusKdeNBQviiiQiD9bknJ+fEBnudpUkMdqY1FPx1y3HGmA1m6RN8Z/UJuOxCWTScjFx 47fCOABvJFLVvkFbJEtAsSdW11fiUW416yHS77jaF/M6VUuHnQ3aiFabutqqyq4gmMQn uGuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689722256; x=1692314256; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EzQPWMhde2JM67Z9YJrSaWfoJkaH/VUF8uE77z0Cvjs=; b=QPiqTgv+SGBwuA/Af24hGaTgoZ8pZzH7KZNkgZ88Cw6QOpnjo4mfoSACrZH0bJreL1 MVwhfGB/k0ZjXCk2vBLpZgKynFZMXfAFfeQEDuvHnF0hPibtehflPvTb9In/ckuqFk6m klI+zUUG50hERqG+TITAqgwWh+gzk19VEcVYi/829mINMF6ndKsbfzegwN8LD2CWDdEL uvorsmsifNmVf6q78DEY2v4w+R8pY/LSd+2PrPlWIpz23qVeRjRqGEhSy70dLS+7uCw0 C0LLv67lXHukcv1xF92f+s0D6jAJDiUV6Te8gLaRfVc75JrQ4DEzAsSpyVbMUc1wYKwa yuUQ== X-Gm-Message-State: ABy/qLa32NsYCyKxIpaAxPF2iUUtdFJSEOBqNRZKj8MSYDqXVH63N2AW ngcIrRWMVirvb5/JpWQ3/1j8iBRvK5gfFwStNOY= X-Received: by 2002:a2e:9d45:0:b0:2b9:40c7:f5ed with SMTP id y5-20020a2e9d45000000b002b940c7f5edmr4594165ljj.17.1689722256001; Tue, 18 Jul 2023 16:17:36 -0700 (PDT) MIME-Version: 1.0 References: <20230502005218.3627530-1-drosen@google.com> <20230718082615.08448806@kernel.org> <20230718090632.4590bae3@kernel.org> <20230718101841.146efae0@kernel.org> <20230718111101.57b1d411@kernel.org> <20230718160612.71f09752@kernel.org> In-Reply-To: <20230718160612.71f09752@kernel.org> From: Alexei Starovoitov Date: Tue, 18 Jul 2023 16:17:24 -0700 Message-ID: Subject: Re: [PATCH v2 1/3] bpf: Allow NULL buffers in bpf_dynptr_slice(_rw) To: Jakub Kicinski Cc: Daniel Rosenberg , bpf , Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Shuah Khan , Jonathan Corbet , Joanne Koong , Mykola Lysenko , LKML , "open list:KERNEL SELFTEST FRAMEWORK" , Android Kernel Team Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jul 18, 2023 at 4:06=E2=80=AFPM Jakub Kicinski wr= ote: > > On Tue, 18 Jul 2023 13:34:06 -0700 Alexei Starovoitov wrote: > > > Direct packet access via skb->data is there for those who want high > > > speed =F0=9F=A4=B7=EF=B8=8F > > > > skb->data/data_end approach unfortunately doesn't work that well. > > Too much verifier fighting. That's why dynptr was introduced. > > I wish Daniel told us more about the use case. > > > > My worry is that people will think that whether the buffer is needed = or > > > not depends on _their program_, rather than on the underlying platfor= m. > > > So if it works in testing without the buffer - the buffer must not be > > > required for their use case. > > > > Are you concerned about bpf progs breaking this way? > > Both, BPF progs breaking and netdev code doing things which don't make > sense. But I won't argue too hard about the former, i.e. the BPF API. > > > I thought you're worried about the driver misusing > > skb_header_pointer() with buffer=3D=3DNULL. > > > > We can remove !buffer check as in the attached patch, > > but I don't quite see how it would improve driver quality. > > The drivers may not be pretty but they aren't buggy AFAICT. > > > [0001-bpf-net-Introduce-skb_pointer_if_linear.patch application/octet-= stream (2873 bytes)] > > Or we can simply pretend we don't have the skb: > > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h > index 91ed66952580..217447f01d56 100644 > --- a/include/linux/skbuff.h > +++ b/include/linux/skbuff.h > @@ -4023,7 +4023,7 @@ __skb_header_pointer(const struct sk_buff *skb, int= offset, int len, > if (likely(hlen - offset >=3D len)) > return (void *)data + offset; > > - if (!skb || !buffer || unlikely(skb_copy_bits(skb, offset, buffer= , len) < 0)) > + if (!skb || unlikely(skb_copy_bits(skb, offset, buffer, len) < 0)= ) > return NULL; > > return buffer; > diff --git a/kernel/bpf/helpers.c b/kernel/bpf/helpers.c > index 9e80efa59a5d..8bc4622cc1df 100644 > --- a/kernel/bpf/helpers.c > +++ b/kernel/bpf/helpers.c > @@ -2239,7 +2239,13 @@ __bpf_kfunc void *bpf_dynptr_slice(const struct bp= f_dynptr_kern *ptr, u32 offset > case BPF_DYNPTR_TYPE_RINGBUF: > return ptr->data + ptr->offset + offset; > case BPF_DYNPTR_TYPE_SKB: > - return skb_header_pointer(ptr->data, ptr->offset + offset= , len, buffer__opt); > + { > + const struct sk_buff *skb =3D ptr->data; > + > + return __skb_header_pointer(NULL, ptr->offset + offset, l= en, > + skb->data, skb_headlen(skb), > + buffer__opt); > + } Which would encourage bnxt-like hacks. I don't like it tbh. At least skb_pointer_if_linear() has a clear meaning. It's more run-time overhead, since buffer__opt is checked early, but that's ok.