Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4266965pxf; Tue, 6 Apr 2021 11:56:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxoSbJ/ZLIsSo9M8QWsGLJRkwO3rnfsxHHSTc0o1sWFE6DpClBq5eq0Uuxz8nC+p5RdTGk/ X-Received: by 2002:a6b:d60e:: with SMTP id w14mr24941643ioa.187.1617735416746; Tue, 06 Apr 2021 11:56:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617735416; cv=none; d=google.com; s=arc-20160816; b=U7mRb90T/Fgah/dZzHHklrCz5/Claay029FVBgqlcduCX3pV6M7RGPpypiyhMB0lne El3nyquaDGCZ0q4JK1lx5zSIOf0DATWTGuB5r1nmnvl8N8/ZJVQ1tpev92y7REnpo5hm xsAT37CeNUpEiNSk12Ten8CGcKCgPcnSUlXFZfxlTPZiSUeHFtnEwwWUJLXKtXxKRFOS 1ZDY6IyyhikWchmrIFMI0sSbITZAXj7QEH3R1UjGw8GtUKC2WtfQl+rusEo1Fv00bIXj GTct827ChSlM0AkUoDAbWa907Ow1Xvyo4UC3+WpeFSforOjUhQGKJh6qfBjk0j3nlqFA bn9A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=HMmoJ8lzD0jdeUc9n0Wk+eKCrv0ig+3eGAmzp2n3I2E=; b=TcWjV8qYXikNgHJNgZw9gnMekZYlMBEzcxgsvfKiBbLPl2oCu+7MAxcBwC9hrKninv 9eU9art+udKr8FUjKaT7XWZb1cWMYZj+4oBEa3Zm2T8/v8KRs0TL/CQkIJtjR/nr+xG5 iUGW0UrSdjKRjXBzuVt/8FDFHC/T/XR/DTifYMumJVJx1P3yegim49qRrFVsXOjx+Yap WiQ/mDmO2BMOSFSL13ZPtrjNDWEppGg6x7niz3LHQHGdcbDt4iWpwwtt75+WI5ZMlLnA RTT7g3can78SFTL95xn87WiKxhmE81AkWRaxbu6Zu1V2LZXmwLSDEgrlJzMSiWeMiqyF coCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=INDUQlMM; 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 l2si19195255ios.47.2021.04.06.11.56.44; Tue, 06 Apr 2021 11:56:56 -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=INDUQlMM; 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 S241747AbhDFKGk (ORCPT + 99 others); Tue, 6 Apr 2021 06:06:40 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:24400 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240979AbhDFKGg (ORCPT ); Tue, 6 Apr 2021 06:06:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617703588; 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: in-reply-to:in-reply-to:references:references; bh=HMmoJ8lzD0jdeUc9n0Wk+eKCrv0ig+3eGAmzp2n3I2E=; b=INDUQlMMCnNy7zUZKn1tS4/9uI+hySXS/W1TKZPDnDRdOmzXcXrAV531tyXZyVtRRgZDXf xaKMsuda9LgWWeXxUAk5CMFkpWLiRMILR+eI9M0dBpPV3jMKuT0wnu6zEkXzkdgvvoLNDQ 5yN+o7ZQLICmWqCpO5sqfVdX3Xx1RzM= Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-387-2SvUCcR3Oru5f0oUNT4wAA-1; Tue, 06 Apr 2021 06:06:26 -0400 X-MC-Unique: 2SvUCcR3Oru5f0oUNT4wAA-1 Received: by mail-ed1-f72.google.com with SMTP id g7so1226174edp.11 for ; Tue, 06 Apr 2021 03:06:26 -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; bh=HMmoJ8lzD0jdeUc9n0Wk+eKCrv0ig+3eGAmzp2n3I2E=; b=Jn3rCmGZKzxR1xBLBMl0ooZ4hjZJC+2+DD4yD9jGXYoaXqMkYMnxwlDbGFjE9NxjgQ olk0/D3la1SzR4HiYFZh4S+9PEqnxb/xYfQ6QBnvdPoY5SHR8O2uMinPynhHWCYygzL3 tdVzOULxgr8F81uI6kZKFb85MjFiQr6XJGTlX24eSFO2HGvtANXMp9Mkhy7ZPTtTSS0Z yzoVDMk3DijEIQgYnlMj77AvLnHAD0xJRbapvwiuoUl09dCEmUgEVrgmJsy/7rmNFUYw 06ZRLN1zsoik9XOGkAJgM3uSkuiWH40EKD1noyCv26kUKuHpi4d7vYf5NQ4OHQFrZE5K a0zQ== X-Gm-Message-State: AOAM531E2R932xj6bGH/CAbXuFTKX5c+Ll+7s3lLF0RryJ5AYZ52yXl9 trJe6BzdRh5faC8VRgq5Vn9WJ949HelZvVc/dkaAMVaGX7sdzN78Q/fg9NO8yrupAzf8sVcOCWD htTeVV6j61lYpZhGP66eoo/5T X-Received: by 2002:a05:6402:1b1c:: with SMTP id by28mr12908383edb.62.1617703585740; Tue, 06 Apr 2021 03:06:25 -0700 (PDT) X-Received: by 2002:a05:6402:1b1c:: with SMTP id by28mr12908347edb.62.1617703585534; Tue, 06 Apr 2021 03:06:25 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([45.145.92.2]) by smtp.gmail.com with ESMTPSA id y24sm13732387eds.23.2021.04.06.03.06.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Apr 2021 03:06:24 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 5D5CF180300; Tue, 6 Apr 2021 12:06:24 +0200 (CEST) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Andrii Nakryiko , Alexei Starovoitov Cc: 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> X-Clacks-Overhead: GNU Terry Pratchett Date: Tue, 06 Apr 2021 12:06:24 +0200 Message-ID: <87blar4ti7.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 wrote: >> > 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 progs 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 query >> > > 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, priority, 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. -Toke