From patchwork Wed Nov 23 17:38:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 25098 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2930859wrr; Wed, 23 Nov 2022 09:45:04 -0800 (PST) X-Google-Smtp-Source: AA0mqf5HOP9s9kpizRKOtPqTqXz2A/MNUgve7JQR+nP4wxMTjvaRK8Eaj21kwcpgFzpKdv77qJxs X-Received: by 2002:a17:907:3907:b0:7ae:37a8:9b5c with SMTP id so7-20020a170907390700b007ae37a89b5cmr9328849ejc.241.1669225504071; Wed, 23 Nov 2022 09:45:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669225504; cv=none; d=google.com; s=arc-20160816; b=LwfNiYPKFgQsyKoIDHS62dNCMQvFWBmDeQMP34MhRpB1qBxmvhuf1jrj4SjI2TCRBQ pM4refFm7svIoEamFIEciCUfAg8Cf4uBmJsI0wK+dVilkegB2oRUGYiD1LG6qcD2JwHP c13qOcdFxwIrv2rt5i3YwTw2dzBh0Bzs1dNt4W8N8hEkC3TbJna7T8V2nNPLfsz5AgUQ YNoyz1beCTRcbbZO/VmVnWI7LRfakJN5HjEGGn4nZfYJgRQg1B4bZYaOXdKZ2uIMD+Fl GBuucqgy5bDUGYvE0x+BJdODuY6vViEaJdE24bLOUfparV0sYqn9li0wd3f8wfxpOrHd RKCw== 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=B6YByZGXcPaxVAwfhLuLTeQPsdnWRNfeeMbhOwZgWvo=; b=tiQc3k7eRD7k6EU7unN+EbNOal7UjvvUd91tFFsf6i569Q+ZYFurIV5FsR1aD+3qS3 9Yet/LVtNxms0NyZStilJdVHAoVk9ZGLZHwiddyKgADQudBjnITMqnnRf/jDjpF67TL1 5sf957RXc1QjZX9ZnHupfndzsW+gwnzBPeT/KXcKgoAL/UVo8SBWu2qNbQHuTj6Svq6g f6qiJbK4xnWSiVEAlZ1ZxWM+jXTkyYEPwtiI1TJuNEIH8T59oDJn5XkjArV4dzzBsfl8 rptye/6+5QWzZTGyFPSDv7J/862lo1K5kXjhV3nXuKY0Om/2ubEVu4UuPr7QFzXmweCp Hbiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=JPBm03qP; 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 qb5-20020a1709077e8500b0079800b81747si495067ejc.735.2022.11.23.09.44.37; Wed, 23 Nov 2022 09:45:04 -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=JPBm03qP; 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 S238130AbiKWRkH (ORCPT + 99 others); Wed, 23 Nov 2022 12:40:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239177AbiKWRjX (ORCPT ); Wed, 23 Nov 2022 12:39:23 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06C2CB97C1 for ; Wed, 23 Nov 2022 09:39:16 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id c65-20020a1c3544000000b003cfffd00fc0so2043145wma.1 for ; Wed, 23 Nov 2022 09:39:15 -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=B6YByZGXcPaxVAwfhLuLTeQPsdnWRNfeeMbhOwZgWvo=; b=JPBm03qP/4/EIPZVSZlhAkYt210/IaMdI4rETETcBPQ1Ry1KY1ZIObqQaEOP5XKoYb RgX98xIjbhsZm7VIgN1F4l6nP7POFydPt/LNkg0DaPPceR4UXQIEw3cvxqU6qeClZyh8 DR2RPbUIwhrmKi6S1H6Taf938/zIIGQ03P57vklgYI0K4RNjT5OGR+bK63++sVupcIfp zaqWqpohktUIk5JCmdRqzCBRNd6E7Bc/d3n2FtU1Fj40dTLGaUsmQaEB4LT3vqyg2I3p 1WyyrbhxFuaKNJXtJ7iiDY0Qe4fcv/AVtneQx8TRHgjPNKv2LX5FFdPFRugZ6bkQIS+M fqkA== 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=B6YByZGXcPaxVAwfhLuLTeQPsdnWRNfeeMbhOwZgWvo=; b=gNcyjxBKkWQMkhSqy4JO4DhcvKnNWOIeDzf8iuBH77sWxkyVH/sp+QJ7ndChLPJ8pw yupJVzdE+E9u7PziWXFnN2IiUydMv0rMrKy2qFmNujdwmh+nbxaa3cugZ8mAuUzpYERo 44kc2FviMjbzRQeUN+B5SbeuT9q3E4ZOUFjFFb2JCKTzH792oa3Jn1TdpaP1Qt8gYdwg tVfb+PVqYwvIdLRaXno3m1lpqPzQRw8aXvzT5Pd4Z0AHF77g1jybfkexsDCcnIr3xNkq jy9s1hMfpO9ecQkiT8alACTRvVwy3MjsnJV4SPf8vszikJec4yLkayBHMfH5sBauqOOO Yz+A== X-Gm-Message-State: ANoB5pnT1xxyzxfO1iptGZAljGIFX5WxOC8Y+HAfwTB/WHdrPGnqTzhq xm2FXFizvPIKIKNpjjgt9L4a4VrBk6wFsw== X-Received: by 2002:a1c:4b12:0:b0:3cf:5237:c0be with SMTP id y18-20020a1c4b12000000b003cf5237c0bemr20405557wma.163.1669225154298; Wed, 23 Nov 2022 09:39:14 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Nov 2022 09:39:13 -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 5/5] net/tcp: Separate initialization of twsk Date: Wed, 23 Nov 2022 17:38:59 +0000 Message-Id: <20221123173859.473629-6-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?1750309802318050448?= X-GMAIL-MSGID: =?utf-8?q?1750309802318050448?= Convert BUG_ON() to WARN_ON_ONCE() and warn as well for unlikely static key int overflow error-path. Signed-off-by: Dmitry Safonov Acked-by: Jakub Kicinski Reviewed-by: Eric Dumazet --- net/ipv4/tcp_minisocks.c | 61 +++++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 26 deletions(-) diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c index 6908812d50d3..e002f2e1d4f2 100644 --- a/net/ipv4/tcp_minisocks.c +++ b/net/ipv4/tcp_minisocks.c @@ -240,6 +240,40 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb, } EXPORT_SYMBOL(tcp_timewait_state_process); +static void tcp_time_wait_init(struct sock *sk, struct tcp_timewait_sock *tcptw) +{ +#ifdef CONFIG_TCP_MD5SIG + const struct tcp_sock *tp = tcp_sk(sk); + struct tcp_md5sig_key *key; + + /* + * The timewait bucket does not have the key DB from the + * sock structure. We just make a quick copy of the + * md5 key being used (if indeed we are using one) + * so the timewait ack generating code has the key. + */ + tcptw->tw_md5_key = NULL; + if (!static_branch_unlikely(&tcp_md5_needed.key)) + return; + + key = tp->af_specific->md5_lookup(sk, sk); + if (key) { + tcptw->tw_md5_key = kmemdup(key, sizeof(*key), GFP_ATOMIC); + if (!tcptw->tw_md5_key) + return; + if (!tcp_alloc_md5sig_pool()) + goto out_free; + if (!static_key_fast_inc_not_disabled(&tcp_md5_needed.key.key)) + goto out_free; + } + return; +out_free: + WARN_ON_ONCE(1); + kfree(tcptw->tw_md5_key); + tcptw->tw_md5_key = NULL; +#endif +} + /* * Move a socket to time-wait or dead fin-wait-2 state. */ @@ -282,32 +316,7 @@ void tcp_time_wait(struct sock *sk, int state, int timeo) } #endif -#ifdef CONFIG_TCP_MD5SIG - /* - * The timewait bucket does not have the key DB from the - * sock structure. We just make a quick copy of the - * md5 key being used (if indeed we are using one) - * so the timewait ack generating code has the key. - */ - do { - tcptw->tw_md5_key = NULL; - if (static_branch_unlikely(&tcp_md5_needed.key)) { - struct tcp_md5sig_key *key; - - key = tp->af_specific->md5_lookup(sk, sk); - if (key) { - tcptw->tw_md5_key = kmemdup(key, sizeof(*key), GFP_ATOMIC); - if (!tcptw->tw_md5_key) - break; - BUG_ON(!tcp_alloc_md5sig_pool()); - if (!static_key_fast_inc_not_disabled(&tcp_md5_needed.key.key)) { - kfree(tcptw->tw_md5_key); - tcptw->tw_md5_key = NULL; - } - } - } - } while (0); -#endif + tcp_time_wait_init(sk, tcptw); /* Get the TIME_WAIT timeout firing. */ if (timeo < rto)