Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1152700pxb; Wed, 1 Sep 2021 19:09:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDl/QZe72jBwpmj6SD6loWuwkzLg5B0bAjAejMDyYBy3O4DuQfId4WG6qwuREZ2aqhqzEQ X-Received: by 2002:a5d:824e:: with SMTP id n14mr768377ioo.134.1630548574487; Wed, 01 Sep 2021 19:09:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630548574; cv=none; d=google.com; s=arc-20160816; b=UVIh5eI46+CqILMKICeV7YSottiMCzHyqvdkrTkJcS8CzHLeQXS+MzTx8x1bn2hzCO Z74+606igzjKV80nEBLp5jda6vAv/SCp8C3FEEQ8e93QiAjB9aoWpDp/7URFyk9pTZ6L OH3fTjhwdbf13ntVEU+gb2y+zg4Msc4VhTm1uq8kDfhwV5fgGKi9QmxCYOSg7SQz0jR3 OIEynwVayvkX0QTgvB+oBewTcIfJ2hJxvGQcuIBXxvLaeOe3LpHBvdqXFgFRxz7uDHDo YE0c1w8TFZ7DB+R4LOEqkGsX1SCBNGORCamkmxqwlzd/Y/+QWVhY2oqwvh0c22jIeCJB y5LQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=7rDswtBwpxZMhyhwjzyBRGO+x8VhuIFk2eELWDrFYhg=; b=SmxZZmePJ/rC3dP86fafL56deRGRjwqJvKZqlajrM5Y4k6GdPosQUnkS971KHc0+LZ xRe/JRMxe82Co39w7e4JR7h7EQzNZfg0ppwpUJO02fPKdRbgOPl2kBhH8Fk2kbnly3Rg NSbJVFK629MYNgVZn6Uv85vhcgrXDWbTFmyaA3rlpjsdZzTYd3n9WoKN/eZJRR7F8hOq roYEzLuWvtXGcpk10qMNcSUNT3sQVr+hTtFGAJBDZKZzciU0Ppe9s28AFHKgClkjUp4E +g5fPR9aza4MwgGLNn7ebtJ/u9Dbea0QzfPqSk3M4tl+/bYbpjcrvSdWpyMqLZQ0COGw dSuA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v14si362813ioh.72.2021.09.01.19.09.21; Wed, 01 Sep 2021 19:09:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232530AbhIBCG6 (ORCPT + 99 others); Wed, 1 Sep 2021 22:06:58 -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. > . >