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.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,USER_AGENT_GIT 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 353BEC43381 for ; Fri, 22 Mar 2019 18:33:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0A30F21900 for ; Fri, 22 Mar 2019 18:33:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="bRx6BON8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729130AbfCVSdI (ORCPT ); Fri, 22 Mar 2019 14:33:08 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:39962 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727050AbfCVSdG (ORCPT ); Fri, 22 Mar 2019 14:33:06 -0400 Received: by mail-qt1-f193.google.com with SMTP id x12so3624890qts.7 for ; Fri, 22 Mar 2019 11:33:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QrTIattnnzoIoCXnBhPZLw71a4gsLg0y5JBNqRqRd9A=; b=bRx6BON8EG3TEYcivtyYGOp0vIyK74gMymWUxmd9+UXx/hNFosmIUTurGtZ9vhJtyA GMO53xo0qi+4ItLqB6VLs5tF0PUKGSmwf37DsKKTvd7NhZUyt4xnGT7xXlfbJjhdDMBz diRarImZ35//STHLn5zRaegChv++lD/6YsFKGCWo3OF6hgD5sOnJmtGexoT3uV21tXf6 2A9F3uXZ/mVYhwmPVC5tv6oJ9pT7t5wVMXcHOAEcCYfdO5esC6+Fk1eIpvGI7+FmA610 0b2MDiQXUSau4kn0h7drRuext9I/7vj5eysYS6JX/gT4rTwCO6hKMmbvfbbjxrV0cxdx eGmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QrTIattnnzoIoCXnBhPZLw71a4gsLg0y5JBNqRqRd9A=; b=j0MfpXdkDISu9LR03Wn9UoW/0K6NABTN83Vpubi/vUsqP+361Nh8Jmvfzuqa44SahF 80rIMHuRmKrRJuCeHlb1P/Zoh0qlWQraCWCEtTkr9gyECzPUE1Hn2O6Jnxql2U8ogf+P 5qvUJmDgIZcPbTFqqDAS/5ET2fT6ZzMPeZVgu963anpRQVd21Njj51tkz0ToKDWtjQqL AQfra+I+2BSw85JJctL15CDFuqtrzGb5FZJzSz2C1+RxOgrA5Bh2UP062OUFGcNwcDsW IkBObpDZDpCNsDb9JF9vLNrwNekp0o82NcqT7BDFMeqFHNolGETODjyyxZ4gv4e3aYWi I1yQ== X-Gm-Message-State: APjAAAWo7ca0Cez9v6Sc5hLODRCu/fI1r3w5iDStwywFOVovkhxAX3FV PqBM2+cxfD1q+/ahlv0duavzJc43 X-Google-Smtp-Source: APXvYqwk3IAkPtmXX5bhbhBAIhkcHyznyUU5jPCsi5wLiRvE/jh0Ti5U5QGhLpMNt5CddI6I+HBpsw== X-Received: by 2002:aed:3829:: with SMTP id j38mr9131928qte.385.1553279585387; Fri, 22 Mar 2019 11:33:05 -0700 (PDT) Received: from willemb1.nyc.corp.google.com ([2620:0:1003:315:3fa1:a34c:1128:1d39]) by smtp.gmail.com with ESMTPSA id t49sm5828331qte.86.2019.03.22.11.33.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Mar 2019 11:33:04 -0700 (PDT) From: Willem de Bruijn To: netdev@vger.kernel.org Cc: ast@kernel.org, daniel@iogearbox.net, sdf@google.com, posk@google.com, Willem de Bruijn Subject: [PATCH bpf-next v3 01/13] bpf: in bpf_skb_adjust_room avoid copy in tx fast path Date: Fri, 22 Mar 2019 14:32:48 -0400 Message-Id: <20190322183300.196277-2-willemdebruijn.kernel@gmail.com> X-Mailer: git-send-email 2.21.0.392.gf8f6787159e-goog In-Reply-To: <20190322183300.196277-1-willemdebruijn.kernel@gmail.com> References: <20190322183300.196277-1-willemdebruijn.kernel@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Willem de Bruijn bpf_skb_adjust_room calls skb_cow on grow. This expensive operation can be avoided in the fast path when the only other clone has released the header. This is the common case for TCP, where one headerless clone is kept on the retransmit queue. It is safe to do so even when touching the gso fields in skb_shinfo. Regular tunnel encap with iptunnel_handle_offloads takes the same optimization. The tcp stack unclones in the unlikely case that it accesses these fields through headerless clones packets on the retransmit queue (see __tcp_retransmit_skb). If any other clones are present, e.g., from packet sockets, skb_cow_head returns the same value as skb_cow(). Signed-off-by: Willem de Bruijn --- net/core/filter.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/filter.c b/net/core/filter.c index d2511fe46db3..d21e1acdde29 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -2971,7 +2971,7 @@ static int bpf_skb_net_grow(struct sk_buff *skb, u32 len_diff) if (skb_is_gso(skb) && !skb_is_gso_tcp(skb)) return -ENOTSUPP; - ret = skb_cow(skb, len_diff); + ret = skb_cow_head(skb, len_diff); if (unlikely(ret < 0)) return ret; -- 2.21.0.392.gf8f6787159e-goog