From patchwork Wed Mar 20 14:49:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Willem de Bruijn X-Patchwork-Id: 1059269 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="a1eVZSgT"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44PXrf1hRyz9sNf for ; Thu, 21 Mar 2019 01:49:54 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728051AbfCTOtx (ORCPT ); Wed, 20 Mar 2019 10:49:53 -0400 Received: from mail-qk1-f193.google.com ([209.85.222.193]:43163 "EHLO mail-qk1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726067AbfCTOtv (ORCPT ); Wed, 20 Mar 2019 10:49:51 -0400 Received: by mail-qk1-f193.google.com with SMTP id c20so9506196qkc.10 for ; Wed, 20 Mar 2019 07:49:51 -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=MPg2+bByfx3IwFWrB/UbrDJlrmtNctIrkmc3yCxFTVs=; b=a1eVZSgTMLovGZz30EutuS6koWkuL1+kDT0grKA+Ah3JsgPFoy/Vnj0+QvcWC3MZP8 ZqANNXSvKyDM5CmkWuK8FH+/Il/Wp92V58jtAE1VcgCLHKTS7ivjxQNut3BDaKbhmi4i NhpHf84iZAs4qvuvvn/WEZpaL9sxq4hV+/yEdiyxUXIMegVLUsCe0nThTtETVK/+9Qw3 N9YezhZ9Ek96/5+HF9D1OkRnTxYzUyjak6fQzC8a5TTxNv7QOu/twbGJyEvxfuSY3mgx GPsMlYRIRtqsxSLLZdO6SR2klcntzUo+v5+0J24FRWR0x3r0A3+WnP08D+PnLoeaZKWR wKlg== 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=MPg2+bByfx3IwFWrB/UbrDJlrmtNctIrkmc3yCxFTVs=; b=mLS18SjuI2kygN2fSPSNkSoMk9yfzHsQFXWdNnA2o5qV/eHBjDyuKRHAdq0deAqMSW lvKyItuulYVDa+ioT/rSrhcMPm6QfkxxUpRQKnRURdiCJKJOq3sPu1pm7mg6evKe7S25 E4X4wx+12/YNgD4VHaxG1pIYcAsx5nc7c/YRPRjieuWXriHCGl/egW20hb/oV4WB/Kr/ tONT0GAWsdG501PYfiKuq0TlKxOTPR6zQZ/8r/0+RgoLZnFtbH8dl5mZHd9BzWgaG8bQ fo1ibJu1gneh9bK455bH3XGYKNkGWg55DWPgrrBCzg59/sE7Ey4tfWqQHCBwiALmTayY r6nQ== X-Gm-Message-State: APjAAAW1bN/b8SjihyFqjVNCMpyFIWd7FFoDtw28LHlh3QaHa7AesApi 8Pb/v+HVtzxcBRxWO8qJDXxEzUgG X-Google-Smtp-Source: APXvYqy4+4Is7gFBL1lk3KZlRF5VKtyf+4F9ybUJN5B1QcvzFte1+F1JOIrNfepbh6cRSGnlpKGvUQ== X-Received: by 2002:a37:e503:: with SMTP id e3mr6598413qkg.316.1553093390582; Wed, 20 Mar 2019 07:49:50 -0700 (PDT) Received: from willemb1.nyc.corp.google.com ([2620:0:1003:315:3fa1:a34c:1128:1d39]) by smtp.gmail.com with ESMTPSA id x201sm1142257qkb.92.2019.03.20.07.49.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Mar 2019 07:49:49 -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 01/13] bpf: in bpf_skb_adjust_room avoid copy in tx fast path Date: Wed, 20 Mar 2019 10:49:32 -0400 Message-Id: <20190320144944.147862-2-willemdebruijn.kernel@gmail.com> X-Mailer: git-send-email 2.21.0.225.g810b269d1ac-goog In-Reply-To: <20190320144944.147862-1-willemdebruijn.kernel@gmail.com> References: <20190320144944.147862-1-willemdebruijn.kernel@gmail.com> MIME-Version: 1.0 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 647c63a7b25b6..8e15fb919b574 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;