From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA9D7C433E0 for ; Sun, 24 Jan 2021 11:55:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A639A22C9D for ; Sun, 24 Jan 2021 11:55:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726896AbhAXLzC (ORCPT ); Sun, 24 Jan 2021 06:55:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726987AbhAXLxW (ORCPT ); Sun, 24 Jan 2021 06:53:22 -0500 Received: from mail-oo1-xc29.google.com (mail-oo1-xc29.google.com [IPv6:2607:f8b0:4864:20::c29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05F4FC061756 for ; Sun, 24 Jan 2021 03:52:41 -0800 (PST) Received: by mail-oo1-xc29.google.com with SMTP id r199so2606354oor.2 for ; Sun, 24 Jan 2021 03:52:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daynix-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pu6Zr2Jo68blbhpXwzl9uRs7KbDV3skHPD8u3gz3sVI=; b=hLK0CiEKpK6Efjx+XUatItsaWE/mRmo/IWq/x6fk1BFPF2i7i2bt6e2DFk6OygAPzE skDu0spVWAOL2kvuzdgaIX2Qzsskv8asVzkubHi6iX0Ny6xxFzxJjd3ejJAIKNpcdQmB l2s+Xraztpfd/HTF6ODoGotgqxTnd9XN8vvHZVJfZ2UjfoOC1hS7U8dgydDpnwXWPG3Z KVKPhLqebfmRllhbj66PsU7MRJ0MA6C01kJ1uNo0VpBNMHDFWjksnk6joesUdAeLg94o 8DWm9RaNOF0kKvdzaOGdAbgJGAVRkvQey/hZo8Xq3kMC+AYT1hayxKGLfKPk03C3pgXo G36w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pu6Zr2Jo68blbhpXwzl9uRs7KbDV3skHPD8u3gz3sVI=; b=oFqYlfc38ExrbiHrNFfo8rt5mqSa/z9TCQZ81a9e/l52055TUIp8VVLXoiIxZ8a/LL dQWOOhE+8z2rzw45/dZzGay99d00kU4WfZbhihcAhxD9l1UDT6fEMi+0Ci0kHqY2yb3I jY1oiXjqS5l3G9HWG5cpZv2Bkgrvulo8rH3gX1czOhNPr9VIoxa21XcpeqlrlEkCzuLa pRJHoUvJ+hPxwwCFJ49p4U56BqUGfYQwuFL6r8RMcLeWAp1WK2wfoyQID/WU4YCBLCbs uE5idxRSCURqIFD6vvOh6Jh/Ws/+7dCd29+TNKlKjPTOgtCnYndxyTkEla3IlLN0kazF WqKw== X-Gm-Message-State: AOAM5326G9TGrAvkwY5OEQLdhuCgVs56d9szSLDTsQI7Y8DH9QLpN+x9 HoqHcKboEXXkvKsU2jxsiJ4Pi+MQGqeesrrYv6C5Cw== X-Google-Smtp-Source: ABdhPJwt8xWKLlXxiJG8fjcBaxoKGZnK9ey4WRGE+AXDo7swV/wzVlPEyFF7MT2HJelv6cWoDDRUCoFqXQlbsX91d4E= X-Received: by 2002:a4a:7353:: with SMTP id e19mr9268056oof.55.1611489161343; Sun, 24 Jan 2021 03:52:41 -0800 (PST) MIME-Version: 1.0 References: <20210112194143.1494-1-yuri.benditovich@daynix.com> <20210112194143.1494-4-yuri.benditovich@daynix.com> In-Reply-To: From: Yuri Benditovich Date: Sun, 24 Jan 2021 13:52:29 +0200 Message-ID: Subject: Re: [RFC PATCH 3/7] tun: allow use of BPF_PROG_TYPE_SCHED_CLS program type To: Alexei Starovoitov Cc: "David S. Miller" , Jakub Kicinski , "Michael S . Tsirkin" , Jason Wang , Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Randy Dunlap , Willem de Bruijn , "Gustavo A . R . Silva" , Herbert Xu , Steffen Klassert , Pablo Neira Ayuso , decui@microsoft.com, cai@lca.pw, Jakub Sitnicki , Marco Elver , Paolo Abeni , Network Development , LKML , kvm@vger.kernel.org, virtualization@lists.linux-foundation.org, bpf , Yan Vugenfirer Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Wed, Jan 20, 2021 at 8:45 PM Alexei Starovoitov wrote: > > On Tue, Jan 12, 2021 at 12:55 PM Yuri Benditovich > wrote: > > > > On Tue, Jan 12, 2021 at 10:40 PM Yuri Benditovich > > wrote: > > > > > > On Tue, Jan 12, 2021 at 9:42 PM Yuri Benditovich > > > wrote: > > > > > > > > This program type can set skb hash value. It will be useful > > > > when the tun will support hash reporting feature if virtio-net. > > > > > > > > Signed-off-by: Yuri Benditovich > > > > --- > > > > drivers/net/tun.c | 2 ++ > > > > 1 file changed, 2 insertions(+) > > > > > > > > diff --git a/drivers/net/tun.c b/drivers/net/tun.c > > > > index 7959b5c2d11f..455f7afc1f36 100644 > > > > --- a/drivers/net/tun.c > > > > +++ b/drivers/net/tun.c > > > > @@ -2981,6 +2981,8 @@ static int tun_set_ebpf(struct tun_struct *tun, struct tun_prog __rcu **prog_p, > > > > prog = NULL; > > > > } else { > > > > prog = bpf_prog_get_type(fd, BPF_PROG_TYPE_SOCKET_FILTER); > > > > + if (IS_ERR(prog)) > > > > + prog = bpf_prog_get_type(fd, BPF_PROG_TYPE_SCHED_CLS); > > > > if (IS_ERR(prog)) > > > > return PTR_ERR(prog); > > > > } > > > > > > Comment from Alexei Starovoitov: > > > Patches 1 and 2 are missing for me, so I couldn't review properly, > > > but this diff looks odd. > > > It allows sched_cls prog type to attach to tun. > > > That means everything that sched_cls progs can do will be done from tun hook? > > > > We do not have an intention to modify the packet in this steering eBPF. > > The intent is irrelevant. Using SCHED_CLS here will let users modify the packet > and some users will do so. Hence the tun code has to support it. > > > There is just one function that unavailable for BPF_PROG_TYPE_SOCKET_FILTER > > that the eBPF needs to make possible to deliver the hash to the guest > > VM - it is 'bpf_set_hash' > > > > Does it mean that we need to define a new eBPF type for socket filter > > operations + set_hash? > > > > Our problem is that the eBPF calculates 32-bit hash, 16-bit queue > > index and 8-bit of hash type. > > But it is able to return only 32-bit integer, so in this set of > > patches the eBPF returns > > queue index and hash type and saves the hash in skb->hash using bpf_set_hash(). > > bpf prog can only return a 32-bit integer. That's true. > But the prog can use helpers to set any number of bits and variables. > bpf_set_hash_v2() with hash, queue and index arguments could fit this purpose, > but if you allow it for SCHED_CLS type, Do I understand correctly that this means: 1. Creation of new helper like https://lists.linuxfoundation.org/pipermail/bridge/2020-July/013036.html 2. Validation on tun side that the BPF uses only limited subset of helpers available for SCHED_CLS > tc side of the code should be ready to deal with that too and this extended > helper should be meaningful for both tc and tun. > > In general if the purpose of the prog is to compute three values they better be > grouped together. Returned two of them via ORed 32-bit integer and > returning 32-bit via bpf_set_hash is an awkward api.