Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp3021927ybj; Mon, 23 Sep 2019 13:22:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqyW/ePqeh3aop7BQn9qGNDAfiuo8Cpc6lAhpV6iHMAd7Mce4oJXlOR60EhuBsthjh1sQYlp X-Received: by 2002:a50:e718:: with SMTP id a24mr2026423edn.289.1569270144278; Mon, 23 Sep 2019 13:22:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569270144; cv=none; d=google.com; s=arc-20160816; b=AKGqAVc5DNRxvlPmCQCYDbOyu2WUlGsA3BJDfcqpsRZRH19xsaFcOvblqy2ACtLJBP jQW5hkNcWciWrGraFoRMnUpjIVi5BwJPm+OPh8Qi8ZCV5cjRuHgIGdwGEu3xtrxTc+Gd UUrE7gUBHFEBd+t2HHa838nq1XJW7briRKENNE2wz2bro922D7E4HoTxnNK/WTcmAqwO tsVqHVDjyheR5jhOJg5igDsJpeNFPO8KPVDnvFZlcFYJTCeKAV3O+Z/Nzbslfa4xUyRr YlXGvzFqjuKkSYRThJrf51sywFKNp5kmqNXt1KCcGbhNp+2DJmI7YxHdzIYpH63qXVIs eRdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=ZIZ6PVJwNqKV66/6V0eWwKczW/IuITxJoofGCnfWMcw=; b=GNuy3x1o1zuMf3jy443ec/5eof5egsqoptj7TQ4d3ez/q1/zb7evAHfyog+CoALSxW YIgLZilS7vcPM5k7uA/oYyDHV1BF1aP+PvR32DCFbfZybHGcdIjo9HO16Y0q8A/hwaTz K/QRTHtYdUM/HYXqjBkBdvhVPiwl/hKaKDYtoftmDHd5C07lt06+gpaj9XzjH/GiUoVF Pc7SCCmNi4ZISWRoLcI60okXtNBxjiEkbURDLlMpRerVIwkNIHRhcmdCZFTfz3hz7RgQ kMgjPlTLl8/ksJF8pHV0QXilCg4nxy160lhX6Tw7wLhbegJ591QDBWyNduMtDpUY5NKw 07wQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 64si8525496edf.34.2019.09.23.13.22.00; Mon, 23 Sep 2019 13:22:24 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728945AbfIVMhk (ORCPT + 99 others); Sun, 22 Sep 2019 08:37:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35002 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728920AbfIVMhk (ORCPT ); Sun, 22 Sep 2019 08:37:40 -0400 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4987481F10 for ; Sun, 22 Sep 2019 12:37:39 +0000 (UTC) Received: by mail-qt1-f200.google.com with SMTP id f15so14110380qth.6 for ; Sun, 22 Sep 2019 05:37:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=ZIZ6PVJwNqKV66/6V0eWwKczW/IuITxJoofGCnfWMcw=; b=c77fwRyiUNrtR8+yFhC7EXaqOrYZz5Gw9FhjmAf465ElCz3M4juYhLZgexeV7osHUp BVAOuInf7Qg6mFQG2WwPYXiYJofPHfZI0Dc9NzYAfnf57k3Ka86jyCMfwibCnrxPnrz6 OrECtmVo58DEGgd8blx7WUGR40MZDV8KF88kCxTY7sldrvmcB2bxc2TpqWFRDjHFYHgF iBuMEpJKnBjCj5JFA5chKNFetIlWSx1TXmKU3msLY6i+qiG7fzVh5fVdjKt65Bq9HBnX ztBUHvj5zT+O8zDS90C4QB2IazrIZC6xxzi7ZRsSeASA803GWkB8aQaynDDuEk+Zx7td 3e+Q== X-Gm-Message-State: APjAAAVHRSptOR6FsvXxYCt0LjLErAsf+LEMwhjyfinS7sszCzwdO9aU v5gZT6PHZ4nD9KL9UzsHjOrE9ersPbJYc5JPtvIO09zwp6MgaKwG3n35f26pU3SSqZCryd3boOq 4Z5EFJ7Cg5V7bPShV/5Q+Qf/3 X-Received: by 2002:a0c:b0cb:: with SMTP id p11mr20902506qvc.216.1569155858544; Sun, 22 Sep 2019 05:37:38 -0700 (PDT) X-Received: by 2002:a0c:b0cb:: with SMTP id p11mr20902486qvc.216.1569155858290; Sun, 22 Sep 2019 05:37:38 -0700 (PDT) Received: from redhat.com (bzq-79-176-40-226.red.bezeqint.net. [79.176.40.226]) by smtp.gmail.com with ESMTPSA id w18sm3976903qts.44.2019.09.22.05.37.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 22 Sep 2019 05:37:37 -0700 (PDT) Date: Sun, 22 Sep 2019 08:37:30 -0400 From: "Michael S. Tsirkin" To: Matthew Cover Cc: davem@davemloft.net, ast@kernel.org, daniel@iogearbox.net, kafai@fb.com, songliubraving@fb.com, yhs@fb.com, jasowang@redhat.com, edumazet@google.com, sdf@google.com, matthew.cover@stackpath.com, mail@timurcelik.de, pabeni@redhat.com, nicolas.dichtel@6wind.com, wangli39@baidu.com, lifei.shirley@bytedance.com, tglx@linutronix.de, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Subject: Re: [PATCH net-next] tuntap: Fallback to automq on TUNSETSTEERINGEBPF prog negative return Message-ID: <20190922080326-mutt-send-email-mst@kernel.org> References: <20190920185843.4096-1-matthew.cover@stackpath.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190920185843.4096-1-matthew.cover@stackpath.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 20, 2019 at 11:58:43AM -0700, Matthew Cover wrote: > Treat a negative return from a TUNSETSTEERINGEBPF bpf prog as a signal > to fallback to tun_automq_select_queue() for tx queue selection. > > Compilation of this exact patch was tested. > > For functional testing 3 additional printk()s were added. > > Functional testing results (on 2 txq tap device): > > [Fri Sep 20 18:33:27 2019] ========== tun no prog ========== > [Fri Sep 20 18:33:27 2019] tuntap: tun_ebpf_select_queue() returned '-1' > [Fri Sep 20 18:33:27 2019] tuntap: tun_automq_select_queue() ran > [Fri Sep 20 18:33:27 2019] ========== tun prog -1 ========== > [Fri Sep 20 18:33:27 2019] tuntap: bpf_prog_run_clear_cb() returned '-1' > [Fri Sep 20 18:33:27 2019] tuntap: tun_ebpf_select_queue() returned '-1' > [Fri Sep 20 18:33:27 2019] tuntap: tun_automq_select_queue() ran > [Fri Sep 20 18:33:27 2019] ========== tun prog 0 ========== > [Fri Sep 20 18:33:27 2019] tuntap: bpf_prog_run_clear_cb() returned '0' > [Fri Sep 20 18:33:27 2019] tuntap: tun_ebpf_select_queue() returned '0' > [Fri Sep 20 18:33:27 2019] ========== tun prog 1 ========== > [Fri Sep 20 18:33:27 2019] tuntap: bpf_prog_run_clear_cb() returned '1' > [Fri Sep 20 18:33:27 2019] tuntap: tun_ebpf_select_queue() returned '1' > [Fri Sep 20 18:33:27 2019] ========== tun prog 2 ========== > [Fri Sep 20 18:33:27 2019] tuntap: bpf_prog_run_clear_cb() returned '2' > [Fri Sep 20 18:33:27 2019] tuntap: tun_ebpf_select_queue() returned '0' > > Signed-off-by: Matthew Cover Could you add a bit more motivation data here? 1. why is this a good idea 2. how do we know existing userspace does not rely on existing behaviour 3. why doesn't userspace need a way to figure out whether it runs on a kernel with and without this patch thanks, MST > --- > drivers/net/tun.c | 20 +++++++++++--------- > 1 file changed, 11 insertions(+), 9 deletions(-) > > diff --git a/drivers/net/tun.c b/drivers/net/tun.c > index aab0be4..173d159 100644 > --- a/drivers/net/tun.c > +++ b/drivers/net/tun.c > @@ -583,35 +583,37 @@ static u16 tun_automq_select_queue(struct tun_struct *tun, struct sk_buff *skb) > return txq; > } > > -static u16 tun_ebpf_select_queue(struct tun_struct *tun, struct sk_buff *skb) > +static int tun_ebpf_select_queue(struct tun_struct *tun, struct sk_buff *skb) > { > struct tun_prog *prog; > u32 numqueues; > - u16 ret = 0; > + int ret = -1; > > numqueues = READ_ONCE(tun->numqueues); > if (!numqueues) > return 0; > > + rcu_read_lock(); > prog = rcu_dereference(tun->steering_prog); > if (prog) > ret = bpf_prog_run_clear_cb(prog->prog, skb); > + rcu_read_unlock(); > > - return ret % numqueues; > + if (ret >= 0) > + ret %= numqueues; > + > + return ret; > } > > static u16 tun_select_queue(struct net_device *dev, struct sk_buff *skb, > struct net_device *sb_dev) > { > struct tun_struct *tun = netdev_priv(dev); > - u16 ret; > + int ret; > > - rcu_read_lock(); > - if (rcu_dereference(tun->steering_prog)) > - ret = tun_ebpf_select_queue(tun, skb); > - else > + ret = tun_ebpf_select_queue(tun, skb); > + if (ret < 0) > ret = tun_automq_select_queue(tun, skb); > - rcu_read_unlock(); > > return ret; > } > -- > 1.8.3.1