Received: by 2002:a05:6358:111d:b0:dc:6189:e246 with SMTP id f29csp481828rwi; Wed, 2 Nov 2022 14:20:52 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7/afNO/I06oudsUGN4gCN35mFhXRVXB7w9kSZEoFXPklE/YOW5suyw15H/ALE5tzURnpxS X-Received: by 2002:aa7:942d:0:b0:56c:6e8c:6ff6 with SMTP id y13-20020aa7942d000000b0056c6e8c6ff6mr26951095pfo.67.1667424051902; Wed, 02 Nov 2022 14:20:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667424051; cv=none; d=google.com; s=arc-20160816; b=vD22mdqwtn+IffHG50yFdR1N6/R1Yshj2zwVwQXSz9qUayfAl/63uIPryuQ3irhnTP hZUPu5H8+kRzkT5xhoI4MqAmYBTuUqWtyN6CW/LRzkhLlDAWeFDegfoNA/bYdYQhX2aB /VHPQKTiDjffAOD/lVMcgioajDG+1xH8kkj2ZnAT5rMEaCm53/CPAR1IcP6uAQJmGbAj rRHM+WwKv13Z7T93PUM4r2QLhO8VOvLQNqOGt97wagF+HIKKXVfbtAPqis0//k/+ZPOh 82qcfX5Q2wrepKaw2SHiQBOTudhaNhvWQtodcWmxGHxq0OOj1Cp2jSp9N9TrF7BjxxSu aZSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mqJckVrQg7Ntll0dZ6IL+1cA9p9Fyu8BflY8RBnW50o=; b=0rBE4xL07yFpVd7xr2Hnhu/Xh2EeSMRp/W4IR47QRCMdU9Y8xcEPWMS8/+YUcgKf0o 70xAEXqKWqiEC1YsPA8OWMifYTT0gUfu29BXvzdVFAfKLG8B1hwWnZVpbOXeBbAuZf+7 4AhtO+mDDl2cCH2w0DkHT5RsqtIBtYqCh46dlkDOjsporqBP6rQ2GF4mpTAcU0shO3xQ mKuP1APjmWwyNW5bJiIgY+6lpybmT7xBYUBcbt76ndsvZtfIXI1qWu4KMeHCYCIb7RNM amdr0b9Ol7ifUx1WHVS8d7RWuHQYu4Zt4ADt6EthluKgBk3QDqwzNireozPefhYYcogl PDWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=Ev2+grcy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p33-20020a635b21000000b0045a8b142a48si19833668pgb.657.2022.11.02.14.20.39; Wed, 02 Nov 2022 14:20:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=Ev2+grcy; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231315AbiKBVOH (ORCPT + 97 others); Wed, 2 Nov 2022 17:14:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230427AbiKBVOD (ORCPT ); Wed, 2 Nov 2022 17:14:03 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3397D2180 for ; Wed, 2 Nov 2022 14:14:00 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id l14so94959wrw.2 for ; Wed, 02 Nov 2022 14:14:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=mqJckVrQg7Ntll0dZ6IL+1cA9p9Fyu8BflY8RBnW50o=; b=Ev2+grcy4sVBMYH5Elr6o9GmomnMLZkIfCvEtFjRHVabXHNCB/jkDZvul+CUXWw4HU gK4/A7o5m4dTUOK7vrjKMfsJ68hlP/OHdgXyyPyYPTKoxyvtMTLcwdt25ibf9m++U0eb MMuqn1/CH8QcevlEX3HKsYmpHGBxaRCEVwwF95DuYhuB+Ypo6EybUldqxtdpAHGNxCTq sy8dT/zBrICqWFGYq1min4dLWGXpYno/3dawfXwNOPTsOItMiZGk6OiPBc4iukaFIbe8 DdrRwYX193RPlLGB6l3MFFtL9RJY0pTuaeyhyspS2Tcx6blx8ZFeeMMgNC6Tb6ruEKHh qaWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mqJckVrQg7Ntll0dZ6IL+1cA9p9Fyu8BflY8RBnW50o=; b=1q6jeK75dyxexDqV0KoYwIvkyTzSQ+xTxPOauhFbihkYlfgj2AkHP2l/PoY2VczwjH baY1VIxrlSI/gHPCGPqyaW4JKuCUD8L7kgfHUeZNB74l2jnUQGTJ1D7jaTQBsjUXMioC hJmWZMKKqxRFAAskxnTnlq0MwmUDilrMEumq9kGkNLwWKEaObnXNgybgC1pFwSIcI0RZ zlr9sktbofsnKl+RbkBfPTFR7FzSMskoWI6l/fcYPUnP7lWdw2rs4aSXC96u4xk/TPhW MwJyEc6C3a2z7X+oKlFdDvFAL1VTLuXCu/HtCCGbsWWSNCZg21F8TpouIgZvqxPRJnt8 Dkgg== X-Gm-Message-State: ACrzQf0Nb+zC9hX6us9MeZFqOGKwzBfIHMFMMUCgbYdzl8XG72xButSU jCmfuWOJREIlGV8G+OaYfRa0jzHb73GHxA== X-Received: by 2002:a5d:5410:0:b0:236:fe1:bb74 with SMTP id g16-20020a5d5410000000b002360fe1bb74mr16433511wrv.512.1667423638531; Wed, 02 Nov 2022 14:13:58 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id cc6-20020a5d5c06000000b002364835caacsm14179851wrb.112.2022.11.02.14.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Nov 2022 14:13:58 -0700 (PDT) From: Dmitry Safonov To: linux-kernel@vger.kernel.org, David Ahern , Eric Dumazet Cc: Dmitry Safonov , Bob Gilligan , "David S. Miller" , Dmitry Safonov <0x7f454c46@gmail.com>, Francesco Ruggeri , Hideaki YOSHIFUJI , Jakub Kicinski , Paolo Abeni , Salam Noureddine , netdev@vger.kernel.org Subject: [PATCH 1/2] net/tcp: Separate tcp_md5sig_info allocation into tcp_md5sig_info_add() Date: Wed, 2 Nov 2022 21:13:49 +0000 Message-Id: <20221102211350.625011-2-dima@arista.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221102211350.625011-1-dima@arista.com> References: <20221102211350.625011-1-dima@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a helper to allocate tcp_md5sig_info, that will help later to do/allocate things when info allocated, once per socket. Signed-off-by: Dmitry Safonov --- net/ipv4/tcp_ipv4.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 87d440f47a70..fae80b1a1796 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1172,6 +1172,24 @@ struct tcp_md5sig_key *tcp_v4_md5_lookup(const struct sock *sk, } EXPORT_SYMBOL(tcp_v4_md5_lookup); +static int tcp_md5sig_info_add(struct sock *sk, gfp_t gfp) +{ + struct tcp_sock *tp = tcp_sk(sk); + struct tcp_md5sig_info *md5sig; + + if (rcu_dereference_protected(tp->md5sig_info, lockdep_sock_is_held(sk))) + return 0; + + md5sig = kmalloc(sizeof(*md5sig), gfp); + if (!md5sig) + return -ENOMEM; + + sk_gso_disable(sk); + INIT_HLIST_HEAD(&md5sig->head); + rcu_assign_pointer(tp->md5sig_info, md5sig); + return 0; +} + /* This can be called on a newly created socket, from other files */ int tcp_md5_do_add(struct sock *sk, const union tcp_md5_addr *addr, int family, u8 prefixlen, int l3index, u8 flags, @@ -1202,17 +1220,11 @@ int tcp_md5_do_add(struct sock *sk, const union tcp_md5_addr *addr, return 0; } + if (tcp_md5sig_info_add(sk, gfp)) + return -ENOMEM; + md5sig = rcu_dereference_protected(tp->md5sig_info, lockdep_sock_is_held(sk)); - if (!md5sig) { - md5sig = kmalloc(sizeof(*md5sig), gfp); - if (!md5sig) - return -ENOMEM; - - sk_gso_disable(sk); - INIT_HLIST_HEAD(&md5sig->head); - rcu_assign_pointer(tp->md5sig_info, md5sig); - } key = sock_kmalloc(sk, sizeof(*key), gfp | __GFP_ZERO); if (!key) -- 2.38.1