Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp265161pxf; Wed, 31 Mar 2021 02:53:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLg8UIMs4oMIe5hPCw6BFPpzvQAZzZB1nMeBD3Nw+uhrQh8uxM6cxl9QbH07zEX6ubpw6T X-Received: by 2002:a05:6402:438f:: with SMTP id o15mr2632875edc.123.1617184411126; Wed, 31 Mar 2021 02:53:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617184411; cv=none; d=google.com; s=arc-20160816; b=sPE9v1ljDBMrTP94twVFAGvDcYGKUSJSQH4MpsmxgmP2/z6CFPElQXAYA4BmuAEUH4 Iqj2UjjDzZxT0IYsOtWP7P0p/rQucIq7f4XD118lqukA4RIY83W/uSbY6LWLp9Iconu1 leDgn5gZPRZsK4kzeDMdNPshM6Sc6mnKw1AUl6TXYKhxcAKo+W1sgTwz/jvc1hhlZyZX p4o2WNQrZxAYIhlpiaxRgi4PUX/BVaJ/LTLTo+nlvFhy6NFaUdjayzP0K87ZpWsEjG9/ HkEf3CWU5pAPWeZ5beLCAmlunrl/KAjUZHjCzlVugcWys8aPVHoTVMEGil31kQgDqOZm atTQ== 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=gSVEMu/gb4JEhF05TMYdAdHmEbbEjzD0QedOu+4cT4M=; b=G1e+DvRYfk8FOVkST/f7WANt87tPEGq9X0X2ickT+7at3WMIeR7U2JeCDn0oezLP+m q3+6j0b2AVK13qfrvDz0k5whapRkz+yCufYvfIs9JC8zg10f34ZY6VQ+54IeR94UyADi vitL2ig8ka8mwfwKhyl7Xgzoxb2E7rMY3c5jobg26d038cftJEn+az2wGyF29W1YjeNf BSOuy1EPdoXrf7O6W9XOXgyLo31Ncw0nNpsDm9OinPvUSguFWvfbbJ5vHWCM6noX8uLq gbX6ubaJtDB48Jl2VfjuL/qpVGuKClNsJRH1lhycMuROfGhwTOX9hnTkjUcIuWNEOR5g WvHQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=iq4imOGb; 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 a18si1348981ejr.606.2021.03.31.02.53.08; Wed, 31 Mar 2021 02:53:31 -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=iq4imOGb; 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 S234790AbhCaJwM (ORCPT + 99 others); Wed, 31 Mar 2021 05:52:12 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:34695 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234792AbhCaJvv (ORCPT ); Wed, 31 Mar 2021 05:51:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1617184310; 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=gSVEMu/gb4JEhF05TMYdAdHmEbbEjzD0QedOu+4cT4M=; b=iq4imOGbJkT/ZJ4ecr7xH9/z4je/W83CfNMXwBfR87oUT5Z3zE7MTPWnEFGmUaToi0ti52 qoiZZ8xIaLkTnVbYmSHB+nN9EoIjayRwc+j1buB3G2iOkfSz9qtOg+yZgpLQG4cYTnTfZj gqHhtW7Rff43Q2oOefGYu9/bl9Ea2wU= Received: from mail-ed1-f71.google.com (mail-ed1-f71.google.com [209.85.208.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-206-gItKbiTJMjuxxjrspMSKVQ-1; Wed, 31 Mar 2021 05:51:48 -0400 X-MC-Unique: gItKbiTJMjuxxjrspMSKVQ-1 Received: by mail-ed1-f71.google.com with SMTP id a2so830641edx.0 for ; Wed, 31 Mar 2021 02:51:48 -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=gSVEMu/gb4JEhF05TMYdAdHmEbbEjzD0QedOu+4cT4M=; b=cM0aFIqKjWDJ7y/7emnXEbzsZ/j4EUOjb7Ym7XjHMnUulB0rfUpufJTO30Qy4syL1/ NR0D5dIXZgADTgzqysqeVymDL9PxU74IxL1VtQ9QTGrLyomQAVdZy6qfqQ67HCs6Wn+Q sw9K6TWm0llXlvpjSsdSgSuY5jm9MTlb5MPzP/03mk8Ev0MwCZ1UdAxt5z+aPXomFTYi hvWE//HscALfAQLnGia2KkBkWY9EJAPpx4tyO32j5pdSY3Bd4Y44fONUPo61o/nMRW09 6ngxDBkOv7oO3UNijXma33+hGHT7a933Uc1UFgTGBubXAxrYZocXbnyitxzqpRZKJz+e 7aXg== X-Gm-Message-State: AOAM532Zb06WRQDTVQI88tbWMvNelMyi61YUXeLwOASi12QlNIrbBujA vFCXSnv5ZCcdOemRcvKcwDy8k24s9R3PdeI7X1Vfw6sfMDx/2er+VyYuGIOLQOCHTyGwDD/LkpM QCk8zvlBLTZYvCpytOYuscxit X-Received: by 2002:aa7:d954:: with SMTP id l20mr2610490eds.1.1617184306910; Wed, 31 Mar 2021 02:51:46 -0700 (PDT) X-Received: by 2002:aa7:d954:: with SMTP id l20mr2610446eds.1.1617184306509; Wed, 31 Mar 2021 02:51:46 -0700 (PDT) Received: from alrua-x1.borgediget.toke.dk ([2a0c:4d80:42:443::2]) by smtp.gmail.com with ESMTPSA id h17sm1123457eds.26.2021.03.31.02.51.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Mar 2021 02:51:46 -0700 (PDT) Received: by alrua-x1.borgediget.toke.dk (Postfix, from userid 1000) id 5FCE6181B24; Wed, 31 Mar 2021 11:51:45 +0200 (CEST) From: Toke =?utf-8?Q?H=C3=B8iland-J=C3=B8rgensen?= To: Daniel Borkmann , Andrii Nakryiko , Kumar Kartikeya Dwivedi Cc: 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: <48b99ccc-8ef6-4ba9-00f9-d7e71ae4fb5d@iogearbox.net> References: <20210325120020.236504-1-memxor@gmail.com> <20210325120020.236504-4-memxor@gmail.com> <20210328080648.oorx2no2j6zslejk@apollo> <48b99ccc-8ef6-4ba9-00f9-d7e71ae4fb5d@iogearbox.net> X-Clacks-Overhead: GNU Terry Pratchett Date: Wed, 31 Mar 2021 11:51:45 +0200 Message-ID: <878s63r6q6.fsf@toke.dk> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Daniel Borkmann writes: > On 3/30/21 10:39 PM, Andrii Nakryiko wrote: >> On Sun, Mar 28, 2021 at 1:11 AM Kumar Kartikeya Dwivedi >> wrote: >>> On Sun, Mar 28, 2021 at 10:12:40AM IST, Andrii Nakryiko wrote: >>>> Is there some succinct but complete enough documentation/tutorial/etc >>>> that I can reasonably read to understand kernel APIs provided by TC >>>> (w.r.t. BPF, of course). I'm trying to wrap my head around this and >>>> whether API makes sense or not. Please share links, if you have some. >>> >>> Hi Andrii, >>> >>> Unfortunately for the kernel API part, I couldn't find any when I was working >>> on this. So I had to read the iproute2 tc code (tc_filter.c, f_bpf.c, >>> m_action.c, m_bpf.c) and the kernel side bits (cls_api.c, cls_bpf.c, act_api.c, >>> act_bpf.c) to grok anything I didn't understand. There's also similar code in >>> libnl (lib/route/{act,cls}.c). >>> >>> Other than that, these resources were useful (perhaps you already went through >>> some/all of them): >>> >>> https://docs.cilium.io/en/latest/bpf/#tc-traffic-control >>> https://qmonnet.github.io/whirl-offload/2020/04/11/tc-bpf-direct-action/ >>> tc(8), and tc-bpf(8) man pages >>> >>> I hope this is helpful! >> >> Thanks! I'll take a look. Sorry, I'm a bit behind with all the stuff, >> trying to catch up. >> >> I was just wondering if it would be more natural instead of having >> _dev _block variants and having to specify __u32 ifindex, __u32 >> parent_id, __u32 protocol, to have some struct specifying TC >> "destination"? Maybe not, but I thought I'd bring this up early. So >> you'd have just bpf_tc_cls_attach(), and you'd so something like >> >> bpf_tc_cls_attach(prog_fd, TC_DEV(ifindex, parent_id, protocol)) >> >> or >> >> bpf_tc_cls_attach(prog_fd, TC_BLOCK(block_idx, protocol)) >> >> ? Or it's taking it too far? >> >> But even if not, I think detaching can be unified between _dev and >> _block, can't it? > > Do we even need the _block variant? I would rather prefer to take the chance > and make it as simple as possible, and only iff really needed extend with > other APIs, for example: > > bpf_tc_attach(prog_fd, ifindex, {INGRESS,EGRESS}); > > Internally, this will create the sch_clsact qdisc & cls_bpf filter instance > iff not present yet, and attach to a default prio 1 handle 1, and _always_ in > direct-action mode. This is /as simple as it gets/ and we don't need to bother > users with more complex tc/cls_bpf internals unless desired. For example, > extended APIs could add prio/parent so that multi-prog can be attached to a > single cls_bpf instance, but even that could be a second step, imho. While I'm all for simplifying where possible, the question becomes at what level? I.e., we initially figured we'd expose (most of) the netlink API in the low-level API (patch 3 in the series) and then have the bpf_program__* level API be the simple "just attach" one... We could simplify the low-level one further, of course, for instance by getting rid of the block stuff entirely, but I don't see much value in leaving out the support for prio/parent in the bpf_tc_cls_* - we'd have to make the API extensible so it could be added later anyway, so why not just include it from the get-go (especially as Kumar has already written the code?) -Toke