From patchwork Tue Nov 15 21:19:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 20572 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2947896wru; Tue, 15 Nov 2022 13:25:24 -0800 (PST) X-Google-Smtp-Source: AA0mqf6nRUPaHpiQ7cFGsLmjiNuKfiKzqfd+y90tvS8/NeqlJBynOxT3/jarX4BoaFb6J6SF4GEJ X-Received: by 2002:a05:6402:511:b0:461:e0b5:8402 with SMTP id m17-20020a056402051100b00461e0b58402mr16935976edv.189.1668547524276; Tue, 15 Nov 2022 13:25:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668547524; cv=none; d=google.com; s=arc-20160816; b=ZtTpCRaECZ2VAcDa+lHRPMQ+kTKBBrXo08YicIn4te2dfhIcgkNKGgPwqrCGdJnmQb XbG6BHd6bMtqNtVevY9KgpsG5zraaTmsa/HlrCCKnXzvVrXwB4aPhFa898wpCDXI6E+j FNFbZunoyeZUAnXoAGEYZUs8d/C4CtOnBc0MU44FVgfZZ8VzY+u2cDQS7p0aUNUd+nUX zRoenJ1GM6CqBSKSeynxS41czvQIBBl2dbTDwEbxpgqjxqTomVbSsLQ1P6RrJOfq7Lya nR+QsKm83sK5xetYFq4n/y/f7iwjBNmqEux3v+mHaM//W4xwUUZ8V/qidACJclXQKZOb UpHg== 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=sPhpWG/B/ETsWAJBokiac0uDxUYc7bB1l9hcDayXT5Y9rG3qoU2kRsC86m7XS/TtEe mPGpApVvWUml+YM8sAwT2vcoGloxRL9HYnA0qsjw81gyppiKg6PB7VIBxsiJKsYEGA9M 50Ma4lWHDmWtu7ApU22d0TxgTLUYqWsLb5xF9FRZjR6AGZsx9EXuO/EgPz76JXIc9uQt 7xkOioIqbbijb+vO72VboWs+eQvvbYbSHeVOSlehr8kJPW2/8THpZNWHlIAxrNOe/ZYr VEp6uBlVDh7Cfjxa0jAbpSRNjQvIyBYx4Hg6K1/PI08bvfl230IemOBhN9xukfDPqicv ezRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=So8k6c4Y; 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 mp27-20020a1709071b1b00b007aea9dfb4f5si15768373ejc.511.2022.11.15.13.24.57; Tue, 15 Nov 2022 13:25:24 -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=So8k6c4Y; 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 S232157AbiKOVT6 (ORCPT + 99 others); Tue, 15 Nov 2022 16:19:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45258 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231232AbiKOVTu (ORCPT ); Tue, 15 Nov 2022 16:19:50 -0500 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B13322BE2 for ; Tue, 15 Nov 2022 13:19:46 -0800 (PST) Received: by mail-wr1-x42e.google.com with SMTP id h9so26578941wrt.0 for ; Tue, 15 Nov 2022 13:19:46 -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=CbvR8VuafE8eZOle2gcxzJnLTEWWuPtnJ8HojgPG8FI=; b=So8k6c4YUMYle8Ql/rzA3xQ5ONAF2vFeIa6jwrybulTP13y/R3ALP9iTxURI6rMu6K ZIyS+KTc8uBbD4SJ/rVRGyi71ryjisJwpfc9gslhHK5FvC5NCBr0UJswTDAWAsMnc9fh tCuecNekzJkN3dZuHBa+Ce2pqo+Y8bRl4d26M/C4I/NrGZxRnqGdLdzEBK4Cp2sdfl23 MFyDAZaCvFLAhK1o953S6zagd00CG4fVMo/lLTsXr1FufWFd4J5fgw7uzphBOHvb2+OO NdLg7MRgSYitg/HwlWdd0Y76wIdRrO95Laa30A+hut7EAcrJQMTqL6hJ1rgHzMNyjsam 5YLw== 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=LVigGPpjXFk4JqV72zfxzvDZzR/nozckpXRNI67GTe3S0lvgoIL0qFXZsblHvdE0zN fav8SRtXaO2zuULAc98FyBHVMKKqgdMXxfQL25zXZdJ1DsDMS7Tq7SjW6rKAVO2NomjI m61k7zdgUHGJr8UepqD1HYp4sHAe7Q+I3ye9o8HFhl71cdtr9xbx7X+OjFuQSF/o30RK v8hX+2v2HsE9MOCAWqKf4dPBhH2HvBB2JusVI1m5/QWwQq0sic9D9GolSoAS5nIdlnmp pKxVf9L8Czgjz/59aIWnxm8CSEn6JJf+VM3Wcma7J9dnQ8lK8RWqovb6XHrOFyrgKIH7 C/Rg== X-Gm-Message-State: ANoB5pkhPAJCubmylM77J2VrD9iiFwayTGWBYdqmWZsN+/M88ewPTYB/ AU02HuIBJvmKXclobV2LIWuHJIONYwm63g== X-Received: by 2002:a5d:4d49:0:b0:235:470e:a9f3 with SMTP id a9-20020a5d4d49000000b00235470ea9f3mr11679576wru.263.1668547155798; Tue, 15 Nov 2022 13:19:15 -0800 (PST) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id n41-20020a05600c502900b003c65c9a36dfsm17201487wmr.48.2022.11.15.13.19.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Nov 2022 13:19:15 -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 v4 2/5] net/tcp: Separate tcp_md5sig_info allocation into tcp_md5sig_info_add() Date: Tue, 15 Nov 2022 21:19:02 +0000 Message-Id: <20221115211905.1685426-3-dima@arista.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221115211905.1685426-1-dima@arista.com> References: <20221115211905.1685426-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=ham 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?1749598888708788074?= X-GMAIL-MSGID: =?utf-8?q?1749598888708788074?= 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)