From patchwork Wed Nov 23 17:38:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 25095 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2930596wrr; Wed, 23 Nov 2022 09:44:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf4JWgUUOPbX5sI0tAJN7fidZKjsIyjQYjOjX7buuIMCK6OpdwulPqzXpUnJy9PJWCcv6hDH X-Received: by 2002:a17:906:edbd:b0:783:5326:90e5 with SMTP id sa29-20020a170906edbd00b00783532690e5mr4670313ejb.374.1669225466523; Wed, 23 Nov 2022 09:44:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669225466; cv=none; d=google.com; s=arc-20160816; b=z3FpVYiCfF+DrvVSBoQboDcp1XsajT2oqaL43DkRpHsYyURUX9DBffon52XkVPvN5O pzzqPtlqw6EeTMsxsyHpFOgGYnZMHmE/bwXzPdWvTZirJ/v6XsYHdKO5Xx5Ut2CPuzYt fo7cK/UUKTkJrCM5t7z1GoY68RTm4dLSIkar8uZ67jrJv1ezVIctCFBcRJJqgMSZ6rkh kcBudtcykC/tTsFCDNtMILC/UP3pZ4K5u5+xXLcJRwrp454fPbyHv2KVMGkNKAzz5wNe AkiNGOIdOUlaiBng5Nu4HDWCLXjGYuYY6nj2XPO3Sae5tWhiXTmAa4AJhaGJg4mc3sPV fZmg== 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=olRr0NxHpe7WEA5OvPe/+zbTbmND6iy3IpcPyCocNn4=; b=v8RigzEumGMARNvwzEQNaVUJ0jAScGdYxDhoH4EELlH+GN99L7WNAasRovaNyjOsZv 0yVcJPwhR7sM9xlPneP3MTLseG58SeX0aKrEI0FKNSLQrpVJEwak5othQt3IzvvoYl2k EhM9PsanBzBED3jaj3djdWwLRHZp0Ll9E4RUYVyTn4y2xkI9O2VgF4ktigAuMkkrrRTH 8Jtgmqwzq/nture1wA08vFK+kJn/Ruqbe7QEIrh0/DA708B3jebhgt89sjrYw9nvmv6A mBA19sFXYPIAbeiGVTyWOm4FaTMm3pXrQogjLnnguFu6Nuoj0GPbkuBMbMRfZSzicNFn 38Gw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=MGZ7Qykb; 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 f10-20020a170906824a00b007add0c2ee2csi11358735ejx.924.2022.11.23.09.43.58; Wed, 23 Nov 2022 09:44:26 -0800 (PST) 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=MGZ7Qykb; 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 S239099AbiKWRjb (ORCPT + 99 others); Wed, 23 Nov 2022 12:39:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58826 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238749AbiKWRjS (ORCPT ); Wed, 23 Nov 2022 12:39:18 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98FAC711BA for ; Wed, 23 Nov 2022 09:39:11 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id p16so13617714wmc.3 for ; Wed, 23 Nov 2022 09:39:11 -0800 (PST) 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=olRr0NxHpe7WEA5OvPe/+zbTbmND6iy3IpcPyCocNn4=; b=MGZ7QykbkGij1YHktOvviVyuOHcrM4D71hg6bgmigrwh1aI2PXhTjkh/bhjj80SOLu HIfRLgpltd7ZARZGjE8AfzX4m8IsaSfJOMB4KF38mYZKM5amck060zKzxudmYDdpZ+cF 7sFTyBnqskBT8GbYEpR+TPRglwVIl7YThS7+wOU2BaMr79APWYKsHN3P9KG4x8i1/QqX qudcetSody7PYuQhyKZehAViaumz+mkzZgueaiUNLLb5nAMCUDQG3mACdNuZIfOzhYpP 2f9dk7nWj9UIChiAGAeP7So0MTiWDgUhuep5AMUJYEfeuK6QOimTBM0b32ceKoMp1If+ kXWQ== 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=olRr0NxHpe7WEA5OvPe/+zbTbmND6iy3IpcPyCocNn4=; b=jEY9y4Ymrtp9l1cJQqeMts+cBG8IbWsMjJ2hLT872cldHUvfy+hpavd0hEWQixXT+t rWbKhBGOStZn7ceqbbtNZvOkYAJWobdlPMy2sLsabg4ASTlKe2/PeyYwYC3JurTLcjIz 2BqWXy2xpF79JyICVfosn5JuDENyEY7Mxbs4civpntQfo+ojfw/wUc8OWbiBCGSBp3fI QWywCJ1MViZkfuKvBTdug5X5Mli4JjHvRk9wDjn+I1b9gSbFjTjZt7BDvmE6VQcTZ9yz UQwo6c8F2ooh3Qw5XOU2YUhQ3Lpqe4+PpXP80YjJ8Mob3LLuGnDVejlckUC0vXsc0f2M X09w== X-Gm-Message-State: ANoB5pnccB4HoHrLHO/PxIoBogCdxG5CSw3NixVUvYa1vbBWpmADEY19 W2Pv16G8eQPhjuOvJ0aP/umzjTIRe3xfxw== X-Received: by 2002:a05:600c:ac1:b0:3c6:d18b:304b with SMTP id c1-20020a05600c0ac100b003c6d18b304bmr9474739wmr.142.1669225149831; Wed, 23 Nov 2022 09:39:09 -0800 (PST) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id v10-20020adfe28a000000b0023647841c5bsm17464636wri.60.2022.11.23.09.39.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 09:39:09 -0800 (PST) From: Dmitry Safonov To: linux-kernel@vger.kernel.org, David Ahern , Eric Dumazet , Peter Zijlstra Cc: Dmitry Safonov , Ard Biesheuvel , Bob Gilligan , "David S. Miller" , Dmitry Safonov <0x7f454c46@gmail.com>, Francesco Ruggeri , Hideaki YOSHIFUJI , Jakub Kicinski , Jason Baron , Josh Poimboeuf , Paolo Abeni , Salam Noureddine , Steven Rostedt , netdev@vger.kernel.org Subject: [PATCH v6 2/5] net/tcp: Separate tcp_md5sig_info allocation into tcp_md5sig_info_add() Date: Wed, 23 Nov 2022 17:38:56 +0000 Message-Id: <20221123173859.473629-3-dima@arista.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221123173859.473629-1-dima@arista.com> References: <20221123173859.473629-1-dima@arista.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.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?1750309763016159698?= X-GMAIL-MSGID: =?utf-8?q?1750309763016159698?= 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 Acked-by: Jakub Kicinski --- 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 f0343538d1f8..2d76d50b8ae8 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)