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=-10.5 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, MENTIONS_GIT_HOSTING,SIGNED_OFF_BY,SPF_PASS,URIBL_BLOCKED,USER_AGENT_MUTT autolearn=ham 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 47CA6C43381 for ; Wed, 20 Mar 2019 19:48:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0CC4E20857 for ; Wed, 20 Mar 2019 19:48:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=fomichev-me.20150623.gappssmtp.com header.i=@fomichev-me.20150623.gappssmtp.com header.b="CfDa+rPU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726303AbfCTTs5 (ORCPT ); Wed, 20 Mar 2019 15:48:57 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:45312 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726006AbfCTTs5 (ORCPT ); Wed, 20 Mar 2019 15:48:57 -0400 Received: by mail-pg1-f193.google.com with SMTP id y3so2524747pgk.12 for ; Wed, 20 Mar 2019 12:48:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fomichev-me.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=jX7WicPCQPfLKLxHpuRfga9wjw5515mO+BSeyHMoBd0=; b=CfDa+rPU7vnLx/0jNNgTJOf3nAqfKPq9FG1gqeY0491yGr8ZLVDrIDo/KqKPDu2nn3 otON9djwZCeQ7oi4VAekjqYBLlFvM1806hsvRXDBH6HiK4A+fiG2wruIf8hjbD0eAOjJ 9Cwzp1rdS5pZV89+T1Y4X7h+KsO29U7BdQyE8HaCmHSUHtNva4jZ5VFL+uNhZCy0tDqj jeUbikfX8vCft3DVRXgvAhrnwO+cv8fXP23Q6vp3GLiluTgBFyfhJwecDD5Cs/E5WQ0C ufppXeXWBRPWq4CMFKE3qLbAWcnGVbgtrQrkH2VVn4IGu+Qvtgglxe5lWCRVyO9EFXTY viqw== 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:user-agent; bh=jX7WicPCQPfLKLxHpuRfga9wjw5515mO+BSeyHMoBd0=; b=htYG97btlPs5yVxvy6IKiYZ0nChQL2iX7BK1L/r80oUHhZsSpmYPv6en3+F9jooHDG IW/RWNsNAqeuEqe2RE8gTKR5iJdhCSgsPyYEhTHShpwuLmItMeSpCFSZs7s2sDtsBRii gaRw0lzDUN080mhBe4g7sh9nR0/OchnJM0bacu+WwMxy94NXsr4hbl3RyFIIfRAq0/C+ kiS8LEilBDKlU8B2qawYAHEKsEJ6QAF/G/Cp99ClVE/yvYDFns5geqybHsflax2OrF2b 4atcdKjnudvSyiPjIMT2f7eU5BwPxTitgwMsQrd9kAMJehwb7Yntfkdj81FTpt64NteG WH2A== X-Gm-Message-State: APjAAAW3S8PEF/CkcZmATpw5lpgFbM3wyWVjeI8j3LHChACxphAF20RS zl8lRty2Wilv+8GadmXlJ8QZog== X-Google-Smtp-Source: APXvYqxNs7EEufp+TiyUtDE+htYLUef32HtASu97RCjDKVG58W7SfBXFc/af60X2RrGxEVtseFuEwg== X-Received: by 2002:a17:902:e612:: with SMTP id cm18mr9496700plb.147.1553111336430; Wed, 20 Mar 2019 12:48:56 -0700 (PDT) Received: from localhost ([2601:646:8f00:18d9:d0fa:7a4b:764f:de48]) by smtp.gmail.com with ESMTPSA id j20sm3753091pfa.158.2019.03.20.12.48.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 20 Mar 2019 12:48:55 -0700 (PDT) Date: Wed, 20 Mar 2019 12:48:54 -0700 From: Stanislav Fomichev To: Willem de Bruijn Cc: Stanislav Fomichev , Network Development , bpf@vger.kernel.org, David Miller , Alexei Starovoitov , Daniel Borkmann , simon.horman@netronome.com, Willem de Bruijn , Petar Penkov Subject: Re: [RFC bpf-next v2 7/9] bpf: when doing BPF_PROG_TEST_RUN for flow dissector use no-skb mode Message-ID: <20190320194854.GN7431@mini-arch.hsd1.ca.comcast.net> References: <20190319221948.170441-1-sdf@google.com> <20190319221948.170441-8-sdf@google.com> <20190320165744.GI7431@mini-arch.hsd1.ca.comcast.net> <20190320190225.GL7431@mini-arch.hsd1.ca.comcast.net> <20190320191912.GM7431@mini-arch.hsd1.ca.comcast.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.3 (2019-02-01) Sender: bpf-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On 03/20, Willem de Bruijn wrote: > On Wed, Mar 20, 2019 at 3:19 PM Stanislav Fomichev wrote: > > > > On 03/20, Willem de Bruijn wrote: > > > On Wed, Mar 20, 2019 at 3:02 PM Stanislav Fomichev wrote: > > > > > > > > On 03/20, Willem de Bruijn wrote: > > > > > On Wed, Mar 20, 2019 at 12:57 PM Stanislav Fomichev wrote: > > > > > > > > > > > > On 03/19, Willem de Bruijn wrote: > > > > > > > On Tue, Mar 19, 2019 at 6:21 PM Stanislav Fomichev wrote: > > > > > > > > > > > > > > > > Now that we have __flow_bpf_dissect which works on raw data (by > > > > > > > > constructing temporary on-stack skb), use it when doing > > > > > > > > BPF_PROG_TEST_RUN for flow dissector. > > > > > > > > > > > > > > > > This should help us catch any possible bugs due to missing shinfo on > > > > > > > > the per-cpu skb. > > > > > > > > > > > > > > > > Note that existing __skb_flow_bpf_dissect swallows L2 headers and returns > > > > > > > > nhoff=0, we need to preserve the existing behavior. > > > > > > > > > > > > > > > > Signed-off-by: Stanislav Fomichev > > > > > > > > --- > > > > > > > > net/bpf/test_run.c | 48 ++++++++++++++-------------------------------- > > > > > > > > 1 file changed, 14 insertions(+), 34 deletions(-) > > > > > > > > > > > > > > > > > > > > > > > @@ -300,9 +277,13 @@ int bpf_prog_test_run_flow_dissector(struct bpf_prog *prog, > > > > > > > > preempt_disable(); > > > > > > > > time_start = ktime_get_ns(); > > > > > > > > for (i = 0; i < repeat; i++) { > > > > > > > > - retval = bpf_flow_dissect_skb(prog, skb, > > > > > > > > - &flow_keys_dissector, > > > > > > > > - &flow_keys); > > > > > > > > + retval = bpf_flow_dissect(prog, data, eth->h_proto, ETH_HLEN, > > > > > > > > + size, &flow_keys_dissector, > > > > > > > > + &flow_keys); > > > > > > > > + if (flow_keys.nhoff >= ETH_HLEN) > > > > > > > > + flow_keys.nhoff -= ETH_HLEN; > > > > > > > > + if (flow_keys.thoff >= ETH_HLEN) > > > > > > > > + flow_keys.thoff -= ETH_HLEN; > > > > > > > > > > > > > > why are these conditional? > > > > > > Hm, I didn't want these to be negative, because bpf flow program can set > > > > > > them to zero and clamp_flow_keys makes sure they are in a "sensible" > > > > > > range. For this particular case, I think we need to amend > > > > > > clamp_flow_keys to make sure that flow_keys.nhoff is in the range of > > > > > > initial_nhoff..hlen, not 0..hlen (and then we can drop these checks). > > > > > > > > > > So, previously eth_type_trans would call with data at the network > > > > > header. Now it is called with data at the link layer. How would > > > > > __skb_flow_bpf_dissect "swallows L2 headers and returns nhoff=0"? That > > > > s/__skb_flow_bpf_dissect/eth_type_trans/, I'll clarify that in the patch > > > > description. > > > > > > > > > sounds incorrect. > > > > Previously, for skb case, eth_type_trans would pull ETH_HLEN (L2) and > > > > after that we did skb_reset_network_header. So when later we initialized > > > > flow keys (flow_keys->nhoff = skb_network_offset(skb)), that would > > > > yield nhoff == 0. > > > > > > > > For example, see: > > > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/tools/testing/selftests/bpf/prog_tests/flow_dissector.c > > > > > > > > Now, we explicitly call bpf_flow_dissect with nhoff=ETH_HLEN and have to > > > > undo it, otherwise, it breaks those tests. > > > > > > > > We could do something like the following instead: > > > > retval = bpf_flow_dissect(prog, data + ETH_HLEN, eth->h_proto, 0, > > > > size, &flow_keys_dissector, > > > > &flow_keys); > > > > > > > > But I wanted to make sure nhoff != 0 works. > > > > > > Makes sense. Ensuring that nhoff lies within initial_nhoff..hlen > > > sounds correct to me. But this is a limitation of the test, so should > > > be in the test logic, not in the generic clamp code. Perhaps just fail > > > the test if returned nhoff < ETH_HLEN? > > I don't think it's only about the tests. BPF program can return > > nhoff/thoff out of range as well (if there was some bug in its logic, > > for example). We should not blindly trust whatever it returns, right? > > Definitely. That's why we clamp. I'm not sure that we have to restrict > the minimum offset to initial nhoff, however. Makes sense. TBH, only the tests currently care about nhoff that flow dissector returns. In the kernel we use only thoff from bpf flow dissector and ignore any modifications to the nhoff. Do you think there is a usecase for nhoff possibly going backwards? In other words, why not prohibit that from the beginning and set the expectations strait (i.e. nhoff only grows).