From patchwork Thu Nov 3 21:25:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 15220 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a40e:b0:83:7221:86ba with SMTP id ck14csp1127514dyb; Thu, 3 Nov 2022 14:37:32 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5ZOp8c3S6SDbXl93rrJ0P5GcOjVOpjj+I+ZHl8Hu4HVVbK3bbD8gWZU7vmsBHWg+tDgmFB X-Received: by 2002:a17:902:f60a:b0:186:a040:d4af with SMTP id n10-20020a170902f60a00b00186a040d4afmr195965plg.140.1667511452700; Thu, 03 Nov 2022 14:37:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667511452; cv=none; d=google.com; s=arc-20160816; b=vrHEkQ763LhCjqmfQkVRKU2udCfuvDB2SfqnFpeT3TkusemQsQ+ntHn6K+6arTAy82 gzD6/+TsrQo8pqzvCIJZ7Loj3DXE/oUX9BuXynH7TWaw/N6G9NGvP4ijO3YZsfr955Pr t0HFL35Qx3YZiU0a61ufgQfsWmA35IqjAt7KnWKr3bOn4VIbU/gZ8kE45OUJho0CaNIV h40uquoq3lFuyWszigKSB5Gf07OtqGdyt6J7weOCD6s3RFju7Gmweqp8K6kdVuCgZs6H CHXBAY5t0ExtTnvcFEEempT5oqWrGBobNTdg1lVr9UM7Uw43kLU00vpHteteLb/BqBq6 v7IA== 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=CbvR8VuafE8eZOle2gcxzJnLTEWWuPtnJ8HojgPG8FI=; b=bbpblrQBTCY6k25LRS5ixkFOqtrVm86F/QdCzH6v8kxaqI43Tj3uGO0tzoIhgxWDrV nkGXCoPiViZsLOIUW4LAWlVqN455nhaa0mLldOTVm1qM2JofWMu7wkH7UkYgNz20Whgi TEdaIf1Ho3ymquZpyy3u1WUcfCltxlCiBQHTdZatLlsWoGk6IBbnf+qKGnIsTNsgirVq vgJQ5KaIEqaxt5Ec+y4QJBtK738yZ7bX5+yvUCzUR1trmk6Cvn/LzGGddcs+N2ovCPSP 8pYBgHnq0qpjKQsu96fQtX6FzLdNrQmRbLe14PE1IarAh1vk1Qj3xzGT3e3KUAsL0Xx0 6t2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=i0Pj5NJz; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d3-20020a056a0024c300b0056ca7c10cf2si2358980pfv.251.2022.11.03.14.37.20; Thu, 03 Nov 2022 14:37:32 -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=i0Pj5NJz; 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 S231339AbiKCVZp (ORCPT + 99 others); Thu, 3 Nov 2022 17:25:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229591AbiKCVZg (ORCPT ); Thu, 3 Nov 2022 17:25:36 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BFF9319001 for ; Thu, 3 Nov 2022 14:25:35 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id l39-20020a05600c1d2700b003cf93c8156dso526464wms.4 for ; Thu, 03 Nov 2022 14:25:35 -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=CbvR8VuafE8eZOle2gcxzJnLTEWWuPtnJ8HojgPG8FI=; b=i0Pj5NJz6BQy2jzDSR6PRBtsI8yVo2CSGPtcH20TBjjb0Eigv4jxwlEhO8yQewQ8gH TiLzklJ8a4fuq4UgSoiR2bKq7VKewD+BleRukwzDpX1pYCq+a763u7xPO494HGRUESdb uCMqWOEDMDvnt59ZJl6Lu3qptYJFIetxLTzlixabS9d/g32OMDUMUy0QxG3j4EZqLJQ2 UkQj2eezhrK20k+ck1D+w6CBq+Uuql8KexWefgZ/0mlOFTpbmvlCU1baxTy+BfgbNqkX GcdLXy2/MiPCllet8CvSMCeoOB5MFDDQ+VzLD2WhRFeTp0lxZ9L+Zci9j6OemjU3GezS VlIA== 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=CbvR8VuafE8eZOle2gcxzJnLTEWWuPtnJ8HojgPG8FI=; b=rLFhNCBhfr8EWUSeg0NnocW+6EPuIPTIqDijxAMD7ERfAmpiQ5v8vUjRIU8Xm+sfZO srZvyeLZi1tz3nKUIim5f3RcSw3rodNaeSOYPAR3G4T3IUiMv+V19EP5+jdTKNKwAkPQ TGsiOMxXG+9XKoUuaOEVu8GqZtTLniz3TmcVWthNXL/P1FIzH7uBt3Vza38xyTnnMWLr LVobAbDyXWkywj1soZ7dkR33Bu2t0+jVkUXIeRszygFc32oTZi+CaRTRi9fdEFoECY4B d87ZUDa2K35Sk579E3gNHFK9oCeH1Ct1mP+T1Qpsy9889WJox8eqNk7VYx+qrfgMTjZS xnXQ== X-Gm-Message-State: ACrzQf21AzxyrrMJZETY1Qcv/6OIDI4Tw6yUFgiYNJcnvfjX60QfO5i2 vORwGrWeZo59ASxAbQTeq0rGUGDphee9kw== X-Received: by 2002:a05:600c:689b:b0:3c2:fd6e:1fe5 with SMTP id fn27-20020a05600c689b00b003c2fd6e1fe5mr21011103wmb.99.1667510734087; Thu, 03 Nov 2022 14:25:34 -0700 (PDT) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id t18-20020a05600c199200b003a601a1c2f7sm1038652wmq.19.2022.11.03.14.25.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 14:25:33 -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 v2 2/3] net/tcp: Separate tcp_md5sig_info allocation into tcp_md5sig_info_add() Date: Thu, 3 Nov 2022 21:25:23 +0000 Message-Id: <20221103212524.865762-3-dima@arista.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221103212524.865762-1-dima@arista.com> References: <20221103212524.865762-1-dima@arista.com> MIME-Version: 1.0 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748512489482784658?= X-GMAIL-MSGID: =?utf-8?q?1748512489482784658?= 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 Reviewed-by: Eric Dumazet --- 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)