Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp2342527pxb; Sun, 24 Jan 2021 03:57:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJztJS+HmAqESwcClJWoDdTWtGIxDxZgbpgCzyWmJQJAsv4XQS++kmhSp1TDi+7RbB1jT+yO X-Received: by 2002:a05:6402:ca9:: with SMTP id cn9mr296064edb.208.1611489425148; Sun, 24 Jan 2021 03:57:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611489425; cv=none; d=google.com; s=arc-20160816; b=avPYHLH3GH9udPFnQeQLbdTfciXT76j2St/SeuzieYG+79/cb7nrAKeg/Q08O+qL06 pswxlMFys/Op7c17mhUtihwFdNd7Rcjw/2yJrUcqkVb/zPnYkV7AbzlCXdYNqFV2PcuU WLlr7NGGPEqw05uu6ACpCN8CyvS7i9x5+/JyFkS1vqtI09w3mXqgmCfc/C0GqQb+HVUL GUuHisZp29gnND/4EdpA2Foc2L4hfialLKH2GwoubGYzdCgdejhxucjDyWAYccwJ1pp1 BtnF3ImwmiCFdAHDhT9HYD87uQwTHTD6kgcCKZfnSSkoTApoBxZrlrA6VChG+bHHYlT9 VoaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=pu6Zr2Jo68blbhpXwzl9uRs7KbDV3skHPD8u3gz3sVI=; b=06UfMyH0sMYeXS1rY0RVa+QwUSe+JNKpS1J7u6g4N/Bffr6OSIsjwseofBxJFu8uQl bgo/GA6Ybt487UWTyGKKZlGK62jekvxGY4ZpT0K7xl93UbrRMWPFhDIYTAxJ9JiksRZA jlmbJWtOZYEb9RuvA8dTFfG1gPmH9hRPb/XoqubHb8jFopr5yjuE0pTvX586Dn5qgigt z+Nf0IO0ceQqi+I3KKz16k6raz/OZUIFP+odJDteRXJ8LHI3YzFZaZ3k4PArXvNpp6Td Pcb0XuB3+8C1Q6ACPNyU0Tj3LdSLaMsrLwuBiArT2CzU+Yzj1n5E/nnktyotKvzgQlM5 MIrQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@daynix-com.20150623.gappssmtp.com header.s=20150623 header.b=hLK0CiEK; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g5si6311664edv.276.2021.01.24.03.56.42; Sun, 24 Jan 2021 03:57:05 -0800 (PST) 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=@daynix-com.20150623.gappssmtp.com header.s=20150623 header.b=hLK0CiEK; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726944AbhAXLyG (ORCPT + 99 others); Sun, 24 Jan 2021 06:54:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726986AbhAXLxW (ORCPT ); Sun, 24 Jan 2021 06:53:22 -0500 Received: from mail-oo1-xc32.google.com (mail-oo1-xc32.google.com [IPv6:2607:f8b0:4864:20::c32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CC39C0613D6 for ; Sun, 24 Jan 2021 03:52:41 -0800 (PST) Received: by mail-oo1-xc32.google.com with SMTP id q6so2600460ooo.8 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=GlmXpIGRFMW45t2VObziVP4h2WQjcBcUJW+BlWyY4TPXDEzEBuUklXBDN1GDzqgyfh g88VsKKzUse7D8TTbVAmFI6/i2LLZ8ce1Q2jHooS/aqvS/cAcCv7A9mCy90xlzeBkuYV cvxVQxoYe5MqTp/qyy4sO6X7S2BLHqTdWqUD0NUclAPzGqDTeVYwBDlmzVmfqAccRvfn XaNF2MnKkZfbLPrXMr+K+Cc2cNguF/v6SqtUkSMPXA/l0PKzqa/AhHvfLjuqXRbuc18C K10BKffairwSbWeBKaZvttc/VtYBzjpi0ahSKrCntvi8keu19uIFQD884TOHkzeaJF9A 5oZw== X-Gm-Message-State: AOAM53014NPELQ13hHI9tIHLstY1wCAW636ymQAQ2ny+TE6dJ8/Wf5l/ zBR82ymU1poiNkHgHeRgSe9JI2AKi7nOg8XO6lvETg== 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: linux-kernel@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.