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=-11.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=unavailable 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 D9A53C4320A for ; Thu, 2 Sep 2021 02:07:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B037961058 for ; Thu, 2 Sep 2021 02:07:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232789AbhIBCHA (ORCPT ); Wed, 1 Sep 2021 22:07:00 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:15380 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229871AbhIBCG6 (ORCPT ); Wed, 1 Sep 2021 22:06:58 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4H0PLf2QtmzbgYH; Thu, 2 Sep 2021 10:02:02 +0800 (CST) Received: from dggpemm500005.china.huawei.com (7.185.36.74) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 2 Sep 2021 10:05:58 +0800 Received: from [10.69.30.204] (10.69.30.204) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.8; Thu, 2 Sep 2021 10:05:58 +0800 Subject: Re: [PATCH net-next] tcp: add tcp_tx_skb_cache_key checking in sk_stream_alloc_skb() To: Eric Dumazet CC: David Miller , Jakub Kicinski , netdev , LKML , , Hideaki YOSHIFUJI , "David Ahern" References: <1630492744-60396-1-git-send-email-linyunsheng@huawei.com> From: Yunsheng Lin Message-ID: Date: Thu, 2 Sep 2021 10:05:57 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.69.30.204] X-ClientProxiedBy: dggeme714-chm.china.huawei.com (10.1.199.110) To dggpemm500005.china.huawei.com (7.185.36.74) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021/9/2 9:13, Eric Dumazet wrote: > On Wed, Sep 1, 2021 at 5:47 PM Yunsheng Lin wrote: >> >> On 2021/9/1 18:39, Yunsheng Lin wrote: >>> Since tcp_tx_skb_cache is disabled by default in: >>> commit 0b7d7f6b2208 ("tcp: add tcp_tx_skb_cache sysctl") >>> >>> Add tcp_tx_skb_cache_key checking in sk_stream_alloc_skb() to >>> avoid possible branch-misses. >>> >>> Signed-off-by: Yunsheng Lin >>> --- >>> Also, the sk->sk_tx_skb_cache may be both changed by allocation >>> and freeing side, I assume there may be some implicit protection >>> here too, such as the NAPI protection for rx? >> >> Hi, Eric >> Is there any implicit protection for sk->sk_tx_skb_cache? >> As my understanding, sk_stream_alloc_skb() seems to be protected >> by lock_sock(), and the sk_wmem_free_skb() seems to be mostly >> happening in NAPI polling for TCP(when ack packet is received) >> without lock_sock(), so it seems there is no protection here? >> > > Please look again. > This is protected by socket lock of course. > Otherwise sk_mem_uncharge() would be very broken, sk->sk_forward_alloc > is not an atomic field. Thanks for clarifying. I have been looking for a point to implement the socket'pp_alloc_cache for page pool, and sk_wmem_free_skb() seems like the place to avoid the scalablity problem of ptr_ring in page pool. The protection for sk_wmem_free_skb() is in tcp_v4_rcv(), right? https://elixir.bootlin.com/linux/latest/source/net/ipv4/tcp_ipv4.c#L2081 > > TCP stack has no direct relation with NAPI. > It can run over loopback interface, no NAPI there. > . >