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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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 A33ADC433E6 for ; Wed, 20 Jan 2021 19:25:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 55C6923403 for ; Wed, 20 Jan 2021 19:25:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2392145AbhATTYe (ORCPT ); Wed, 20 Jan 2021 14:24:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389903AbhATSpz (ORCPT ); Wed, 20 Jan 2021 13:45:55 -0500 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09A44C061575; Wed, 20 Jan 2021 10:45:11 -0800 (PST) Received: by mail-lf1-x12b.google.com with SMTP id o17so35520168lfg.4; Wed, 20 Jan 2021 10:45:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=zrMNRZvlEESWdG6jggtCoB+4numwazy+fXWH/nTPU9U=; b=GbiCYI2AOS9Mde7ZZGAB8iKTEaPVyUk3NJn7BsJ4aNMPDW3bfjjQOlDjJVeyI01LfK yGrcSPsCfKcKMod8xBD3FRFhA2PKjb0+UA9u+c+PLBc6ucvOs4H76CCyWbj5qRgGzSxL YYeBDYP7YKSgdZ2tcOGzhxRWs+uk1fru9f/FsIBpFq4b3uFMzw/dOgkhsRnbJz85JTGD OFp28kiITVDeZNpIvktOImEsP9FYI+HUZ15TQ4xgjNS0A45AjvFeCkc/hiGkbKW6oV51 UkYN9KTEvNSswvk+NvyWRYiqpqIG5SqjCPISQdicL2egTc1jJYF1v01KBc8Pl6R7uTGn P/AA== 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=zrMNRZvlEESWdG6jggtCoB+4numwazy+fXWH/nTPU9U=; b=BQqb9xHzS3Q3cW/HfiF08HssFRa7X4tkKto4CQaRFNYQQzYdTk832/+3VIv6E8x+EK EaMwg/9gLe9eEeJwrdYBqFN8Xblu8mO7MPFMSuSv5lNCL+jizh/6khQd/7X5Ki3y4Rbc YsAN91msjEOo9Nytsqb2qp32kRvO1w2WLdMG/y0/eeAwijR+K2H1cPJKBtGzUcxOJdC+ Zp0d22MRKB4wqwGV3XbaNhxQQNwGJX9QyGu3rM/BDJ1zCXLauh6PBsmxyQlTTeGoS6yR nIqJlkvgxC3hrlecfsCho6C5SDv4b8u8fnj5rwOChyrc03c1hYFCI5TwH/N+DJnKRHEF 8NQQ== X-Gm-Message-State: AOAM532QOqGUBY9ruwM2TTcc8NDIkXf+Lq/IztatkLw4Meff+hL4RCDV IUCK24Vi5NiTJRjtUHFWiZOIeBAwz0CJB2CFVuE= X-Google-Smtp-Source: ABdhPJysfNizrzDQUVINGOhhgWus7azEpICiAnwV+p4EXlvDkyaX1pVlGFfbUwglU72IpLHWW5TDXiNALg3A++evFDI= X-Received: by 2002:a05:6512:34c5:: with SMTP id w5mr4908698lfr.214.1611168309505; Wed, 20 Jan 2021 10:45:09 -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: Alexei Starovoitov Date: Wed, 20 Jan 2021 10:44:58 -0800 Message-ID: Subject: Re: [RFC PATCH 3/7] tun: allow use of BPF_PROG_TYPE_SCHED_CLS program type To: Yuri Benditovich 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 , gustavoars@kernel.org, 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 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, 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.