Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp306677pxb; Wed, 14 Apr 2021 16:13:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1noLSm1m7h421CznNdkKqUGY5WD0fM3G2u9TO5waJRjJcKCDr8AiwZVWLlexCljx+1ryf X-Received: by 2002:a63:4c4:: with SMTP id 187mr645738pge.187.1618442023281; Wed, 14 Apr 2021 16:13:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618442023; cv=none; d=google.com; s=arc-20160816; b=ajt6RREbE28kWut6ny+tQ3lFzpiZy/pvLcWP075AO03JTy0SzqPo5F7+D05GmKmL6X afsg8+Yh6XajgCokTLRDyBjq+HLq4vC4/37leu7XP8Rx4PHhrQuaDkgoKOxR6lVNpFqZ 3tqWrhWPAYV9Sxn5dEKL+EEnTQfM5E0J1FJzpHkPVOxxkgJH/Ita1BS+EGt+OxVUcvpu 3IUy7rzYCvbRfVLPQRzPcc9Q7EZYEjjYtbzu7t6nwzfRJnYosCEK8EknWiDALGgEkBUD NdXbrRbwEhl1qbfXKo/EsasgEw+B0mf2mPTYTFYJ8kPVOElWkSDKUi7nIofHoRrdBZJi SjEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:references:in-reply-to:subject:cc:to:from :dkim-signature; bh=Rs2PlOx2xiUIBK9k56hAPqdrqHZQ9ahIYUEPYnsCJD4=; b=fcCnEpCpAjFYRSRrRL03QWVFP89ClyFbGnO+RU6QmXKfYlchUlx4gqztTaLF6Z2nR7 Q8HYI4fR7iNTeYfL92SXfck3RRpqij8XMZ5SQcLKBPY3cqDnb6L2OVNKvGRDEM3Lk082 r01PeC/X+JiDLryEIQRsQp3uwWUgpnLgk1fyEuJB3I3rUwEDjGHVujz3CHsQg5SqBi81 5YlwGqcgZPmr1K4cFUQfjuxMJKt68BZK376aygE3DWzzMYC797oFOFwGDuJcbkG9HEPR JrcBKP99Qy6r0Ct01hsPwWV2+1ZLrJ5XueW+xZFO1nO4HFrUoX2YMzA5wTga0byH2q78 FsuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gaBRz5ui; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a20si1020875pjh.160.2021.04.14.16.13.31; Wed, 14 Apr 2021 16:13:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=gaBRz5ui; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234297AbhDNK7b (ORCPT + 99 others); Wed, 14 Apr 2021 06:59:31 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:42308 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1343757AbhDNK7T (ORCPT ); Wed, 14 Apr 2021 06:59:19 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1618397937; 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=Rs2PlOx2xiUIBK9k56hAPqdrqHZQ9ahIYUEPYnsCJD4=; b=gaBRz5uiVPAGbXE2SRiJzDhsNiDYZX6vnCuelr/LDueWLVqhU4XMBANAHtw6WcfiFnsP6t U4wXfDXEOraUR6oj0GfdTnqqqDYjRvhXVE5K33/LyehHRcbpioArIL8jmjYRaUkOZYoWtJ o14cW2gL2maq1cL34+UraX+ILyMSPx8= Received: from mail-ed1-f69.google.com (mail-ed1-f69.google.com [209.85.208.69]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-476-afeA1wY5O5uXG_oos8WqWA-1; Wed, 14 Apr 2021 06:58:53 -0400 X-MC-Unique: afeA1wY5O5uXG_oos8WqWA-1 Received: by mail-ed1-f69.google.com with SMTP id w14-20020aa7da4e0000b02903834aeed684so1346600eds.13 for ; Wed, 14 Apr 2021 03:58:53 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:in-reply-to:references:date :message-id:mime-version:content-transfer-encoding; bh=Rs2PlOx2xiUIBK9k56hAPqdrqHZQ9ahIYUEPYnsCJD4=; b=mo5D7yHdqpLJ95+zmf1CS0F7x6wye5eOHfUE24tD8qTc2cUTyeHFpzg4wtWlkpybhf WD6rW9eaX+c7RU52HKDmXFF+xw5uHS5jNH9uGd8Zg+eVCt7Z/gKG3/uNip5euFrvvEng xOUF7/BBK7RXqm0TXoIgBlW+HJpZhhG66dhtj8Zh9ySMHQ1LdEEWDBS1UOcGHtmwqnLY v/ZeExiQ5EdgNmw4vkS0b4F7dvW0ANdXdyNLESImkIEjJO3wC5Y2yYANHhkpGQPGa1L7 9w1NKPUwm3HkWdQ7iGREqDqCNJb7XJfIZirW+ggMoUmV//iguzaTC/Pv7elc2dKVon17 jC1Q== X-Gm-Message-State: AOAM532IWRSv6AJySqGAqHYRZ7fqKIGllh+1OVKFsDlajgWvGKULNjzM h772ZMznNtChGRuJmeCVCfuvpGqXG4dLCj65yhBI7Oiolk3Zdag2olYOxiK9VPtcK5/Xmg5JO94 7vQI/iRa7C19bDT6OtsjfefiS X-Received: by 2002:a17:906:c7c3:: with SMTP id dc3mr25448727ejb.107.1618397932093; Wed, 14 Apr 2021 03:58:52 -0700 (PDT) X-Received: by 2002:a17:906:c7c3:: with SMTP id dc3mr25448688ejb.107.1618397931666; Wed, 14 Apr 2021 03:58:51 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id c16sm9866499ejx.81.2021.04.14.03.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Apr 2021 03:58:50 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 1B5021804E8; Wed, 14 Apr 2021 12:58:50 +0200 (CEST) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Andrii Nakryiko Cc: Alexei Starovoitov , Kumar Kartikeya Dwivedi , Daniel Borkmann , bpf , Jesper Dangaard Brouer , Alexei Starovoitov , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Shuah Khan , "David S. Miller" , Jakub Kicinski , Jesper Dangaard Brouer , Peter Zijlstra , open list , Networking , "open list:KERNEL SELFTEST FRAMEWORK" Subject: Re: [PATCH bpf-next 3/5] libbpf: add low level TC-BPF API In-Reply-To: References: <20210325120020.236504-4-memxor@gmail.com> <20210328080648.oorx2no2j6zslejk@apollo> <48b99ccc-8ef6-4ba9-00f9-d7e71ae4fb5d@iogearbox.net> <20210331094400.ldznoctli6fljz64@apollo> <5d59b5ee-a21e-1860-e2e5-d03f89306fd8@iogearbox.net> <20210402152743.dbadpgcmrgjt4eca@apollo> <20210402190806.nhcgappm3iocvd3d@apollo> <20210403174721.vg4wle327wvossgl@ast-mbp> <87blar4ti7.fsf@toke.dk> X-Clacks-Overhead: GNU Terry Pratchett Date: Wed, 14 Apr 2021 12:58:50 +0200 Message-ID: <874kg9m8t1.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Andrii Nakryiko writes: > On Tue, Apr 6, 2021 at 3:06 AM Toke H=C3=B8iland-J=C3=B8rgensen wrote: >> >> Andrii Nakryiko writes: >> >> > On Sat, Apr 3, 2021 at 10:47 AM Alexei Starovoitov >> > wrote: >> >> >> >> On Sat, Apr 03, 2021 at 12:38:06AM +0530, Kumar Kartikeya Dwivedi wro= te: >> >> > On Sat, Apr 03, 2021 at 12:02:14AM IST, Alexei Starovoitov wrote: >> >> > > On Fri, Apr 2, 2021 at 8:27 AM Kumar Kartikeya Dwivedi wrote: >> >> > > > [...] >> >> > > >> >> > > All of these things are messy because of tc legacy. bpf tried to = follow tc style >> >> > > with cls and act distinction and it didn't quite work. cls with >> >> > > direct-action is the only >> >> > > thing that became mainstream while tc style attach wasn't really = addressed. >> >> > > There were several incidents where tc had tens of thousands of pr= ogs attached >> >> > > because of this attach/query/index weirdness described above. >> >> > > I think the only way to address this properly is to introduce bpf= _link style of >> >> > > attaching to tc. Such bpf_link would support ingress/egress only. >> >> > > direction-action will be implied. There won't be any index and qu= ery >> >> > > will be obvious. >> >> > >> >> > Note that we already have bpf_link support working (without support= for pinning >> >> > ofcourse) in a limited way. The ifindex, protocol, parent_id, prior= ity, handle, >> >> > chain_index tuple uniquely identifies a filter, so we stash this in= the bpf_link >> >> > and are able to operate on the exact filter during release. >> >> >> >> Except they're not unique. The library can stash them, but something = else >> >> doing detach via iproute2 or their own netlink calls will detach the = prog. >> >> This other app can attach to the same spot a different prog and now >> >> bpf_link__destroy will be detaching somebody else prog. >> >> >> >> > > So I would like to propose to take this patch set a step further = from >> >> > > what Daniel said: >> >> > > int bpf_tc_attach(prog_fd, ifindex, {INGRESS,EGRESS}): >> >> > > and make this proposed api to return FD. >> >> > > To detach from tc ingress/egress just close(fd). >> >> > >> >> > You mean adding an fd-based TC API to the kernel? >> >> >> >> yes. >> > >> > I'm totally for bpf_link-based TC attachment. >> > >> > But I think *also* having "legacy" netlink-based APIs will allow >> > applications to handle older kernels in a much nicer way without extra >> > dependency on iproute2. We have a similar situation with kprobe, where >> > currently libbpf only supports "modern" fd-based attachment, but users >> > periodically ask questions and struggle to figure out issues on older >> > kernels that don't support new APIs. >> >> +1; I am OK with adding a new bpf_link-based way to attach TC programs, >> but we still need to support the netlink API in libbpf. >> >> > So I think we'd have to support legacy TC APIs, but I agree with >> > Alexei and Daniel that we should keep it to the simplest and most >> > straightforward API of supporting direction-action attachments and >> > setting up qdisc transparently (if I'm getting all the terminology >> > right, after reading Quentin's blog post). That coincidentally should >> > probably match how bpf_link-based TC API will look like, so all that >> > can be abstracted behind a single bpf_link__attach_tc() API as well, >> > right? That's the plan for dealing with kprobe right now, btw. Libbpf >> > will detect the best available API and transparently fall back (maybe >> > with some warning for awareness, due to inherent downsides of legacy >> > APIs: no auto-cleanup being the most prominent one). >> >> Yup, SGTM: Expose both in the low-level API (in bpf.c), and make the >> high-level API auto-detect. That way users can also still use the >> netlink attach function if they don't want the fd-based auto-close >> behaviour of bpf_link. > > So I thought a bit more about this, and it feels like the right move > would be to expose only higher-level TC BPF API behind bpf_link. It > will keep the API complexity and amount of APIs that libbpf will have > to support to the minimum, and will keep the API itself simple: > direct-attach with the minimum amount of input arguments. By not > exposing low-level APIs we also table the whole bpf_tc_cls_attach_id > design discussion, as we now can keep as much info as needed inside > bpf_link_tc (which will embed bpf_link internally as well) to support > detachment and possibly some additional querying, if needed. But then there would be no way for the caller to explicitly select a mechanism? I.e., if I write a BPF program using this mechanism targeting a 5.12 kernel, I'll get netlink attachment, which can stick around when I do bpf_link__disconnect(). But then if the kernel gets upgraded to support bpf_link for TC programs I'll suddenly transparently get bpf_link and the attachments will go away unless I pin them. This seems... less than ideal? If we expose the low-level API I can elect to just use this if I know I want netlink behaviour, but if bpf_program__attach_tc() is the only API available it would at least need a flag to enforce one mode or the other (I can see someone wanting to enforce kernel bpf_link semantics as well, so a flag for either mode seems reasonable?). -Toke