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=-0.9 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS 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 C5C8FC43381 for ; Sun, 24 Feb 2019 18:00:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8A51D20652 for ; Sun, 24 Feb 2019 18:00:23 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="o4eu1Uu3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727833AbfBXSAW (ORCPT ); Sun, 24 Feb 2019 13:00:22 -0500 Received: from mail-yw1-f68.google.com ([209.85.161.68]:32817 "EHLO mail-yw1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726206AbfBXSAV (ORCPT ); Sun, 24 Feb 2019 13:00:21 -0500 Received: by mail-yw1-f68.google.com with SMTP id i204so309323ywb.0 for ; Sun, 24 Feb 2019 10:00:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=iu0BwbmPBSk6HACWYYU6ipF8uzIqoA+huOA6EksA3BY=; b=o4eu1Uu3soJf9p3LiWN8kdlRB/VnocZVW6npEKZCjPonqNPsfh7aP5OuDyEWPenl8f sl+rv+GFOQ/GM5Ii7qnujXhfm3p0ZpZUvN2oOe8xYVLkkxsBNdXPYm5bUDTcwUV8jo2o 07Qxmp0i03hGRyIyn5fWQZ4MhIDaEFhz13acAgTwUfEu83LlQrk6dZgfBJ5xXEibv+KA QD1IHoqDP2s+Tf2Me32CmDocvdpdLpry0Quy8B+1te4xepN6hjIh4bWbrAZxY9HBU9QK hMsxxXw6SteQ1jlYQD8R71AJUTFUyQcW9nCwgG3PuPGcjM4r9jZHOvFdYFDxKIpdSHco IY9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=iu0BwbmPBSk6HACWYYU6ipF8uzIqoA+huOA6EksA3BY=; b=bWVy4KZV79GsXkm7VT/Ib/20aHy3/fa+BeNhAqYUT2QuRuau5cKl4JBDMKuAweT5Zh HgvXloUK55F/00tXtp0ww+VAL4Dw733foKxREw1o6ZzFJA3tuiYYNzFba8nJOX474Ttr Qjf2fJfcY14HxPvzh3mPMGVFBGFoc4Vo6bUvbCO2bx5WASjWZUmSr357El+WjiWWlzTI qgI0b8MoLsOQZdTlnT3eqX4WBg2nshIEgrbbiKQo91vBZ2Z2G1t5Vo2OxobA1Zbhj97n rMJyEr7s/QMloAo2XVSfKKVx3QYGlD2HXHTLYEGV/X9NkBtoS0JqhatNTMU/nT8lrdqZ nCTA== X-Gm-Message-State: AHQUAuYcM3d4Ovb5g1W0YrZJBTUIC59iNa7Y/pzp+Qon3ap8bz9806BM OQYnwnM9l3D4kzpH8jgp5xE= X-Google-Smtp-Source: AHgI3Iar2z0IzPqA+o7CX65tYQKyOpanyjXHJdbFsQtMjbKVK+HH/nqZ/RrjsmeY5ojgk4inTFkiqA== X-Received: by 2002:a0d:c544:: with SMTP id h65mr11090687ywd.35.1551031220503; Sun, 24 Feb 2019 10:00:20 -0800 (PST) Received: from [192.168.86.235] (c-73-241-150-70.hsd1.ca.comcast.net. [73.241.150.70]) by smtp.gmail.com with ESMTPSA id n128sm2198846ywf.74.2019.02.24.10.00.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Feb 2019 10:00:18 -0800 (PST) Subject: Re: [PATCH v2 bpf-next 2/9] bpf: Add bpf helper bpf_tcp_enter_cwr To: Martin Lau , Eric Dumazet Cc: Lawrence Brakmo , netdev , Alexei Starovoitov , Daniel Borkmann , Kernel Team References: <20190223010703.678070-1-brakmo@fb.com> <20190223010703.678070-3-brakmo@fb.com> <2a218060-8a62-150c-c05e-5433df18aaab@gmail.com> <20190224030845.imwjbkoaxipuzb75@kafai-mbp.dhcp.thefacebook.com> From: Eric Dumazet Message-ID: <254ae6a8-13d8-101f-45a3-18a1cbe6dea6@gmail.com> Date: Sun, 24 Feb 2019 10:00:16 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20190224030845.imwjbkoaxipuzb75@kafai-mbp.dhcp.thefacebook.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On 02/23/2019 07:08 PM, Martin Lau wrote: > On Sat, Feb 23, 2019 at 05:32:14PM -0800, Eric Dumazet wrote: >> >> >> On 02/22/2019 05:06 PM, brakmo wrote: >>> From: Martin KaFai Lau >>> >>> This patch adds a new bpf helper BPF_FUNC_tcp_enter_cwr >>> "int bpf_tcp_enter_cwr(struct bpf_tcp_sock *tp)". >>> It is added to BPF_PROG_TYPE_CGROUP_SKB which can be attached >>> to the egress path where the bpf prog is called by >>> ip_finish_output() or ip6_finish_output(). The verifier >>> ensures that the parameter must be a tcp_sock. >>> >>> This helper makes a tcp_sock enter CWR state. It can be used >>> by a bpf_prog to manage egress network bandwidth limit per >>> cgroupv2. A later patch will have a sample program to >>> show how it can be used to limit bandwidth usage per cgroupv2. >>> >>> To ensure it is only called from BPF_CGROUP_INET_EGRESS, the >>> attr->expected_attach_type must be specified as BPF_CGROUP_INET_EGRESS >>> during load time if the prog uses this new helper. >>> The newly added prog->enforce_expected_attach_type bit will also be set >>> if this new helper is used. This bit is for backward compatibility reason >>> because currently prog->expected_attach_type has been ignored in >>> BPF_PROG_TYPE_CGROUP_SKB. During attach time, >>> prog->expected_attach_type is only enforced if the >>> prog->enforce_expected_attach_type bit is set. >>> i.e. prog->expected_attach_type is only enforced if this new helper >>> is used by the prog. >>> >> >> BTW, it seems to me that BPF_CGROUP_INET_EGRESS can be used while the socket lock is not held. > Thanks for pointing it out. > > ic. I just noticed the comments at ip6_xmit(): > /* > * xmit an sk_buff (used by TCP, SCTP and DCCP) > * Note : socket lock is not held for SYNACK packets, but might be modified > * by calls to skb_set_owner_w() and ipv6_local_error(), > * which are using proper atomic operations or spinlocks. > */ > Is there other cases other than SYNACK? Well, I was referring to various virtual devices, re-entering ip stack. Since we can have a qdisc on any netdev, there is no way we can guarantee the socket is locked by the current thread. Random example : ipvlan_process_v4_outbound() ... err = ip_local_out(net, skb->sk, skb); ...