Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp806817rwb; Fri, 13 Jan 2023 04:32:17 -0800 (PST) X-Google-Smtp-Source: AMrXdXsL/BW/zCtdAduPcjyk/NkoMYu5l0E22kOjUAVTPxcbdlD9VSJt1Jv3Iz4aRkwtIH4H5qcI X-Received: by 2002:a17:907:7707:b0:844:c651:ce4b with SMTP id kw7-20020a170907770700b00844c651ce4bmr66009652ejc.33.1673613137625; Fri, 13 Jan 2023 04:32:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673613137; cv=none; d=google.com; s=arc-20160816; b=E+sipzy9xJktPhI55tdJZtNaeK6QyWTx4P5nYPpe5gw2p2POzZAMzB79Frqxd73NFs RCeO+mMfTv8cpScl+MTfiHP7hKS3k6iUVwaZMdpXRHuGcWeslS3EIj7UxmgZnrUrt5MX 9xyd5HSbmrFU+PQsehsk+/rAEwOX2wsoE6nxEebQySY1qt0kmtoIxcAHXDHnoz2gJaUK fhj/VWN7T9SgPta3v8lr9dF8ackjyVRjVbwEdZzac4O+BXrakSrAMW1YwL1skWiCGZ0d iIJ7T+mbnX+meR9oohE6rUjTmrjwz7STNM2TBZSnDhUNM6Nn6efbrbVs4AthH5q/M01B fQeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=+PtZnNS70XnntmnTOZy027lj3AuB4jtCCxH9ncjY8es=; b=dEYHs4TVpMupV7PFKTk2eY99Toy2HXfoQ3MXA5NjkeyfF68JkB6tDcrSdRAgRqX9nr lOUUc+8mGkLUqHgiY8Ziu8PAIiv4uusEsr+LLx5RDtB5ARqZlAXJgdG8o7HXkyVWYLOp FnMuL8XT8uDcYdndcD9CSkRUqIPTJYABbI+ufeOiZ98AjQi+SEzsuazgcle09UQfJB2+ NwytGbsmE7edOlzNjHjonbf6MYWc73u0E9qUd60QSCV0knhODFHoKHgsYbhddiZWAJTY 1AMGMlXxgvOQ58qKzGBTNjXfZCcmQ3OVSiRajx4HfaY90kbIepUIgRN7xTbWK0xBl3BL n1yA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=taE3+ILi; 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=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dr6-20020a170907720600b0084d197a89e2si20847308ejc.957.2023.01.13.04.32.05; Fri, 13 Jan 2023 04:32:17 -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=@google.com header.s=20210112 header.b=taE3+ILi; 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=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232671AbjAMMWf (ORCPT + 51 others); Fri, 13 Jan 2023 07:22:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240584AbjAMMWB (ORCPT ); Fri, 13 Jan 2023 07:22:01 -0500 Received: from mail-yb1-xb29.google.com (mail-yb1-xb29.google.com [IPv6:2607:f8b0:4864:20::b29]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C622B34771 for ; Fri, 13 Jan 2023 04:16:33 -0800 (PST) Received: by mail-yb1-xb29.google.com with SMTP id d62so5969854ybh.8 for ; Fri, 13 Jan 2023 04:16:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=+PtZnNS70XnntmnTOZy027lj3AuB4jtCCxH9ncjY8es=; b=taE3+ILiaxDnaLaoP7hhjNDlyCmeAS1Ea6O0cbhB3nYeaiL+auDT7eShoUNDqu7idQ TkB2svZoeXd4C7V8qrxxHG1/bsV+JvjJzDUomhRJa+sYEVmrufFML8PZ9Sf+PJdVtEnP P8wgiX+huEmNwcMvZ3WQ5ECWawz+4zaIAUPm4CZWx6VfOdVqIcbrmO427wfn/ic4IE5/ dGfx8i8yzi9rCYzq5JhsnTojbQWhzkBTlQJvWD2cNqPk0JNJq1J71VJJ0fWsysmhVtDA NAQSHl8ornL4fLxaAIK1xwLstPy+Fp/C/oX6zJo23qUsnj93H4ermFn3H2HzFyHJRWAV HmQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=+PtZnNS70XnntmnTOZy027lj3AuB4jtCCxH9ncjY8es=; b=MUO6DryKpMYmzK+DDCilL8yCJqkNu5z1g7Sro37OZI0/HVKSnKow3XQv8/LFP9r38b fY3gNhYceDxwgOow8U/hLMSWw9MMloreBiAE5QBqqpy0gRnN5YR2e5U7CE4jNYTTSkxS TSkcOKyfqZwPQmm+3fwdVMp/J7NPDfSn6+BlsPEwubGUTnAIllA26O6gdV3ippLEoZ/I /Y/VgvWsOWPKUKyKZ23IJrAvVKtT6O6IL2c2JKbiKHDs/C11YfI8YlKXAC5bz1qGJr9d bCKMOuqATEkwqJqC9GHRvj7kqvFcP69xtJGsoWQz5++c4IDNUvztupN9OhUUNioL7tto o47w== X-Gm-Message-State: AFqh2kpeeHJ6U2IecoBmgaRJTKDKGSjnHxJ6ycWgByKcvJnZBCWLCrCc QliyBO+r/XruWEIK20q0KNd4VzwlquKQPXUTm8KNeg== X-Received: by 2002:a25:46c6:0:b0:7b8:a0b8:f7ec with SMTP id t189-20020a2546c6000000b007b8a0b8f7ecmr3315906yba.36.1673612192479; Fri, 13 Jan 2023 04:16:32 -0800 (PST) MIME-Version: 1.0 References: <20230112-inet_hash_connect_bind_head-v2-1-5ec926ddd985@diag.uniroma1.it> In-Reply-To: <20230112-inet_hash_connect_bind_head-v2-1-5ec926ddd985@diag.uniroma1.it> From: Eric Dumazet Date: Fri, 13 Jan 2023 13:16:20 +0100 Message-ID: Subject: Re: [PATCH v2] inet: fix fast path in __inet_hash_connect() To: Pietro Borrello Cc: "David S. Miller" , Jakub Kicinski , Paolo Abeni , Hideaki YOSHIFUJI , David Ahern , Cristiano Giuffrida , "Bos, H.J." , Jakob Koschel , netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Kuniyuki Iwashima Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Fri, Jan 13, 2023 at 12:40 PM Pietro Borrello wrote: > > __inet_hash_connect() has a fast path taken if sk_head(&tb->owners) is > equal to the sk parameter. > sk_head() returns the hlist_entry() with respect to the sk_node field. > However entries in the tb->owners list are inserted with respect to the > sk_bind_node field with sk_add_bind_node(). > Thus the check would never pass and the fast path never execute. > > Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") > Reviewed-by: Kuniyuki Iwashima > Signed-off-by: Pietro Borrello > --- > Changes in v2: > - nit: s/list_entry/hlist_entry/ > - Link to v1: https://lore.kernel.org/r/20230112-inet_hash_connect_bind_head-v1-1-7e3c770157c8@diag.uniroma1.it > --- > include/net/sock.h | 10 ++++++++++ > net/ipv4/inet_hashtables.c | 2 +- > 2 files changed, 11 insertions(+), 1 deletion(-) > > diff --git a/include/net/sock.h b/include/net/sock.h > index dcd72e6285b2..23fc403284db 100644 > --- a/include/net/sock.h > +++ b/include/net/sock.h > @@ -860,6 +860,16 @@ static inline void sk_nulls_add_node_rcu(struct sock *sk, struct hlist_nulls_hea > __sk_nulls_add_node_rcu(sk, list); > } > > +static inline struct sock *__sk_bind_head(const struct hlist_head *head) > +{ > + return hlist_entry(head->first, struct sock, sk_bind_node); > +} > + > +static inline struct sock *sk_bind_head(const struct hlist_head *head) > +{ > + return hlist_empty(head) ? NULL : __sk_bind_head(head); > +} > + > static inline void __sk_del_bind_node(struct sock *sk) > { > __hlist_del(&sk->sk_bind_node); > diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c > index d039b4e732a3..a805e086fb48 100644 > --- a/net/ipv4/inet_hashtables.c > +++ b/net/ipv4/inet_hashtables.c > @@ -998,7 +998,7 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row, > hinfo->bhash_size)]; > tb = inet_csk(sk)->icsk_bind_hash; > spin_lock_bh(&head->lock); > - if (sk_head(&tb->owners) == sk && !sk->sk_bind_node.next) { > + if (sk_bind_head(&tb->owners) == sk && !sk->sk_bind_node.next) { > inet_ehash_nolisten(sk, NULL, NULL); 1) Given this path was never really used, we have no coverage. 2) Given that we do not check inet_ehash_nolisten() return code here. I would recommend _not_ adding the Fixes: tag, and target net-next tree In fact, I would remove this dead code, and reduce complexity. I doubt the difference is going to be noticed. (We have to access the ehash bucket anyway) > spin_unlock_bh(&head->lock); > return 0; > > --- > base-commit: 1b929c02afd37871d5afb9d498426f83432e71c2 > change-id: 20230112-inet_hash_connect_bind_head-8f2dc98f08b1 > > Best regards, > -- > Pietro Borrello