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=-8.5 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_PASS,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 E9D3AC282CC for ; Tue, 5 Feb 2019 20:45:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B86FE2083B for ; Tue, 5 Feb 2019 20:45:41 +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="Gm8xgKZi" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728334AbfBEUpk (ORCPT ); Tue, 5 Feb 2019 15:45:40 -0500 Received: from mail-pl1-f195.google.com ([209.85.214.195]:43302 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726624AbfBEUpe (ORCPT ); Tue, 5 Feb 2019 15:45:34 -0500 Received: by mail-pl1-f195.google.com with SMTP id gn14so2026700plb.10 for ; Tue, 05 Feb 2019 12:45:33 -0800 (PST) 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=BU0v4UWPsr2e5QPnPeVSPjPzjGsIdnj3KuPvGmGk3+o=; b=Gm8xgKZijmfbvl8vCoBptIzyAUqLv5nhUAMKltF3psCp1x1dZMLiG9bjD3zB1mQ3Hp aar7+OYV8QzsoEoJrgO6ifty5Svhe3C8LLOKnLNrK+54ar/UIJRpkgWRZE0J82Ogzdiq 2igfVY6Rcb8gl3b5qMXhNphqGOVUlICEyglE/zlzd3uUmAp3iv51i9Jr4hrHWPazMajN LlY/9YFCTkEoYQzeFVDoVuEDlyflo2ZjB95KoGPpUjkC07n5W5OJJMsxmR5F1qdChjjE M8ndlvI+nuJveCuVJf2n9yUnx3mAbUBtKFrumbEztmudUoqkGXZe41H+T9mWWYqltC8v E/BA== 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=BU0v4UWPsr2e5QPnPeVSPjPzjGsIdnj3KuPvGmGk3+o=; b=qSP+iRNOm79J1ms5hbds5UVIwR7T9CCLyZ+e0GDPzwRQXhjb34iTqKY7gcsuWlsWAq xvScAYjWgjoAQPQGmqg50ggRI13teaV9SWq8XrOI6BAZE7qVJu9tPmM1pKJg6UbsyVNT Gw+5NaQ4JAylyTX9Ee/cK4THo9DIJtO5Bkd+0HSAIY97uxWjfRTSYjC4CiRA0NogpsFX onfmTw28wllHXZQMeRbwzCfdtoprMm0ZznkKczoVemy3jR8PLSC3LKKUj0rORcpll6jM 6ElmTZKjALVPL43vIm0Sqa/68gy8XKLGVowiJ0Epul2zwnT3T6lWdY/EDHQt21GD8xyh UorA== X-Gm-Message-State: AHQUAuZU/g8KA9rFlTRkqNFJMwLLxb4cbwILWOshGC4uk414AQLEyLL2 bvR72lGLfK5M4bPGufFUJATfvw== X-Google-Smtp-Source: AHgI3IYC0PWfRs6EkM6u6DBiIrZlqLgMfm8NpiEfrpOFnv0xb5qwbwoMCbp8GOyKpVhTkF2G2Y+/mQ== X-Received: by 2002:a17:902:968d:: with SMTP id n13mr7094416plp.109.1549399533190; Tue, 05 Feb 2019 12:45:33 -0800 (PST) Received: from localhost ([2601:646:8f00:18d9:d0fa:7a4b:764f:de48]) by smtp.gmail.com with ESMTPSA id s6sm5638704pgo.4.2019.02.05.12.45.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 05 Feb 2019 12:45:32 -0800 (PST) Date: Tue, 5 Feb 2019 12:45:31 -0800 From: Stanislav Fomichev To: Willem de Bruijn Cc: Stanislav Fomichev , Network Development , David Miller , Alexei Starovoitov , Daniel Borkmann , simon.horman@netronome.com, Willem de Bruijn Subject: Re: [RFC bpf-next 4/7] net: flow_dissector: handle no-skb use case Message-ID: <20190205204531.GE10769@mini-arch> References: <20190205173629.160717-1-sdf@google.com> <20190205173629.160717-5-sdf@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.11.2 (2019-01-07) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 02/05, Willem de Bruijn wrote: > On Tue, Feb 5, 2019 at 12:57 PM Stanislav Fomichev wrote: > > > > When flow_dissector is called without skb (with only data and hlen), > > construct on-stack skb (which has a linear chunk of data passed > > to the flow dissector). This should let us handle eth_get_headlen > > case where only data is provided and we don't want to (yet) allocate > > an skb. > > > > Since this on-stack skb doesn't allocate its own data, we can't > > add shinfo and need to be careful to avoid any code paths that use > > it. Flow dissector BPF programs can only call bpf_skb_load_bytes helper, > > which doesn't touch shinfo in our case (skb->len is the length of the > > linear header so it exits early). > > > > Signed-off-by: Stanislav Fomichev > > --- > > include/linux/skbuff.h | 5 +++ > > net/core/flow_dissector.c | 95 +++++++++++++++++++++++++++++---------- > > 2 files changed, 76 insertions(+), 24 deletions(-) > > > > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h > > index aa9a9983de80..5f1c085cb34c 100644 > > --- a/include/linux/skbuff.h > > +++ b/include/linux/skbuff.h > > @@ -1227,6 +1227,11 @@ bool __skb_flow_bpf_dissect(struct bpf_prog *prog, > > const struct sk_buff *skb, > > struct flow_dissector *flow_dissector, > > struct bpf_flow_keys *flow_keys); > > +bool __flow_bpf_dissect(struct bpf_prog *prog, > > + void *data, __be16 proto, > > + int nhoff, int hlen, > > + struct flow_dissector *flow_dissector, > > + struct bpf_flow_keys *flow_keys); > > nit: please use more descriptive name. Perhaps bpf_flow_dissect_raw > and rename __skb_flow_bpf_dissect to bpf_flow_dissect_skb. Agreed. > > +bool __flow_bpf_dissect(struct bpf_prog *prog, > > + void *data, __be16 proto, > > + int nhoff, int hlen, > > + struct flow_dissector *flow_dissector, > > + struct bpf_flow_keys *flow_keys) > > +{ > > + struct bpf_skb_data_end *cb; > > + struct sk_buff skb; > > + u32 result; > > + > > + __init_skb(&skb, data, hlen); > > + skb_put(&skb, hlen); > > + skb.protocol = proto; > > + > > + init_flow_keys(flow_keys, &skb, nhoff); > > + > > + cb = (struct bpf_skb_data_end *)skb.cb; > > + cb->data_meta = skb.data; > > + cb->data_end = skb.data + skb_headlen(&skb); > > + > > + result = BPF_PROG_RUN(prog, &skb); > > + > > + clamp_flow_keys(flow_keys, hlen); > > > > return result == BPF_OK; > > } > > Can__flow_bpf_dissect just construct an skb and then call > __skb_flow_bpf_dissect? __skb_flow_bpf_dissect calls bpf_compute_data_pointers which calls skb_metadata_len which touches shinfo. And I don't think I have a clever way to handle that. > > It will unnecessarily save and restore the control block, but that is > a relatively small cost (compared to, say, zeroing the entire skb).