Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2655386pxa; Mon, 17 Aug 2020 15:39:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw+0xoPPkYErQ3oMWQ08Mwjl3A/CPx15eLyxsNQawqT5WK/C8YGoTf4pr1qBnWva/BnJ1AI X-Received: by 2002:a05:6402:6da:: with SMTP id n26mr6314553edy.262.1597703972741; Mon, 17 Aug 2020 15:39:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597703972; cv=none; d=google.com; s=arc-20160816; b=yagKdbZqTm3tDxm29eShSrlcJvO3M6NVV17JxDUHPf/je7Zkj6UizOIY7epaVw1Ox7 mDzV/GUgPN/h7sbKNYnJodte3HhUtSbdF4LnvZmwJBc9R+bia3YZo7UmaXilUvFzHOgt kcTKMMg3iil9J7wXzZzM0O+FH12v/1eyG5PaywfhjjqxlZZ9pcpnxypiUKKGq9Fsan/b F15F2kDDpP6VFmQ5s17kkRcxM711WhvUCRBubrs8GfCLCTUOLe3Joa+nRfKSHv/U+Uge u8qyB6/eRe/I1DKAJkiWVxLE/OQiZLWwC8YO3hp/k/pT65wis39/228uvfTw7Zsxufb7 IxAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=u7GSpNUWBbbysT4pZSjN7emEzCGZteTWrjvKpEKHOUk=; b=K/CAv01Juj4YLiANivxbIHEju1kphTH1TvPFq43FCqTLKpjMhy73CKMcSdUeng5PtL IuV/OrTg4HrmdaQeEyVjZXnuW59nMtixypFBgcc22DyWcHjiYVYQNQuhs4zIVIYqEtE5 yGFzglrD2MbhU4cw5ZjTl6lMlt/2GnCn2VBlbQaWvg90+ZnNuhcs2Y9vTvnxlLxVN+tr iNlxqMWtIbQWcaoROU6mgX92ZC2t5uVI4bi1UjxFH3qlXLBDGoO5L7naCyTmHabYfjZZ keOf3dNr2gpXb4SsL2eOkb4Lbz4wuHFTPHoSg2VihlKjel6zsCMKXjBrgYeYyuNeq/GL ejoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pVLsQSwW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a16si11861258ejx.411.2020.08.17.15.39.09; Mon, 17 Aug 2020 15:39:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=pVLsQSwW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390063AbgHQSEz (ORCPT + 99 others); Mon, 17 Aug 2020 14:04:55 -0400 Received: from mail.kernel.org ([198.145.29.99]:33542 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388516AbgHQQJl (ORCPT ); Mon, 17 Aug 2020 12:09:41 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 9238720729; Mon, 17 Aug 2020 16:09:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597680580; bh=sOLvYu9ayPOYRlmi4Mna/3oKgrT4g2RpifvvT/N1fGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pVLsQSwWOsQvgRLEU6DH2lWyebi6HvCqGU8I4n/tD/KLp6K2CmQEufBEXmegI4qUY WHxw2RfXRiKD3E5u6V38aMCgci8rmzOs4t93pZz4ZxB1c8fqIzIDAH9sjzif/CPL7w d6dhysTqRSF//WOG467Ve2cQAQ7f1DnPJbipLI3o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Matthieu Baerts , Tim Froidcoeur , "David S. Miller" Subject: [PATCH 5.4 226/270] net: refactor bind_bucket fastreuse into helper Date: Mon, 17 Aug 2020 17:17:07 +0200 Message-Id: <20200817143807.031294396@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143755.807583758@linuxfoundation.org> References: <20200817143755.807583758@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Tim Froidcoeur [ Upstream commit 62ffc589abb176821662efc4525ee4ac0b9c3894 ] Refactor the fastreuse update code in inet_csk_get_port into a small helper function that can be called from other places. Acked-by: Matthieu Baerts Signed-off-by: Tim Froidcoeur Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- include/net/inet_connection_sock.h | 4 + net/ipv4/inet_connection_sock.c | 97 ++++++++++++++++++++----------------- 2 files changed, 57 insertions(+), 44 deletions(-) --- a/include/net/inet_connection_sock.h +++ b/include/net/inet_connection_sock.h @@ -309,6 +309,10 @@ int inet_csk_compat_getsockopt(struct so int inet_csk_compat_setsockopt(struct sock *sk, int level, int optname, char __user *optval, unsigned int optlen); +/* update the fast reuse flag when adding a socket */ +void inet_csk_update_fastreuse(struct inet_bind_bucket *tb, + struct sock *sk); + struct dst_entry *inet_csk_update_pmtu(struct sock *sk, u32 mtu); #define TCP_PINGPONG_THRESH 3 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c @@ -284,6 +284,57 @@ static inline int sk_reuseport_match(str ipv6_only_sock(sk), true, false); } +void inet_csk_update_fastreuse(struct inet_bind_bucket *tb, + struct sock *sk) +{ + kuid_t uid = sock_i_uid(sk); + bool reuse = sk->sk_reuse && sk->sk_state != TCP_LISTEN; + + if (hlist_empty(&tb->owners)) { + tb->fastreuse = reuse; + if (sk->sk_reuseport) { + tb->fastreuseport = FASTREUSEPORT_ANY; + tb->fastuid = uid; + tb->fast_rcv_saddr = sk->sk_rcv_saddr; + tb->fast_ipv6_only = ipv6_only_sock(sk); + tb->fast_sk_family = sk->sk_family; +#if IS_ENABLED(CONFIG_IPV6) + tb->fast_v6_rcv_saddr = sk->sk_v6_rcv_saddr; +#endif + } else { + tb->fastreuseport = 0; + } + } else { + if (!reuse) + tb->fastreuse = 0; + if (sk->sk_reuseport) { + /* We didn't match or we don't have fastreuseport set on + * the tb, but we have sk_reuseport set on this socket + * and we know that there are no bind conflicts with + * this socket in this tb, so reset our tb's reuseport + * settings so that any subsequent sockets that match + * our current socket will be put on the fast path. + * + * If we reset we need to set FASTREUSEPORT_STRICT so we + * do extra checking for all subsequent sk_reuseport + * socks. + */ + if (!sk_reuseport_match(tb, sk)) { + tb->fastreuseport = FASTREUSEPORT_STRICT; + tb->fastuid = uid; + tb->fast_rcv_saddr = sk->sk_rcv_saddr; + tb->fast_ipv6_only = ipv6_only_sock(sk); + tb->fast_sk_family = sk->sk_family; +#if IS_ENABLED(CONFIG_IPV6) + tb->fast_v6_rcv_saddr = sk->sk_v6_rcv_saddr; +#endif + } + } else { + tb->fastreuseport = 0; + } + } +} + /* Obtain a reference to a local port for the given sock, * if snum is zero it means select any available local port. * We try to allocate an odd port (and leave even ports for connect()) @@ -296,7 +347,6 @@ int inet_csk_get_port(struct sock *sk, u struct inet_bind_hashbucket *head; struct net *net = sock_net(sk); struct inet_bind_bucket *tb = NULL; - kuid_t uid = sock_i_uid(sk); int l3mdev; l3mdev = inet_sk_bound_l3mdev(sk); @@ -333,49 +383,8 @@ tb_found: goto fail_unlock; } success: - if (hlist_empty(&tb->owners)) { - tb->fastreuse = reuse; - if (sk->sk_reuseport) { - tb->fastreuseport = FASTREUSEPORT_ANY; - tb->fastuid = uid; - tb->fast_rcv_saddr = sk->sk_rcv_saddr; - tb->fast_ipv6_only = ipv6_only_sock(sk); - tb->fast_sk_family = sk->sk_family; -#if IS_ENABLED(CONFIG_IPV6) - tb->fast_v6_rcv_saddr = sk->sk_v6_rcv_saddr; -#endif - } else { - tb->fastreuseport = 0; - } - } else { - if (!reuse) - tb->fastreuse = 0; - if (sk->sk_reuseport) { - /* We didn't match or we don't have fastreuseport set on - * the tb, but we have sk_reuseport set on this socket - * and we know that there are no bind conflicts with - * this socket in this tb, so reset our tb's reuseport - * settings so that any subsequent sockets that match - * our current socket will be put on the fast path. - * - * If we reset we need to set FASTREUSEPORT_STRICT so we - * do extra checking for all subsequent sk_reuseport - * socks. - */ - if (!sk_reuseport_match(tb, sk)) { - tb->fastreuseport = FASTREUSEPORT_STRICT; - tb->fastuid = uid; - tb->fast_rcv_saddr = sk->sk_rcv_saddr; - tb->fast_ipv6_only = ipv6_only_sock(sk); - tb->fast_sk_family = sk->sk_family; -#if IS_ENABLED(CONFIG_IPV6) - tb->fast_v6_rcv_saddr = sk->sk_v6_rcv_saddr; -#endif - } - } else { - tb->fastreuseport = 0; - } - } + inet_csk_update_fastreuse(tb, sk); + if (!inet_csk(sk)->icsk_bind_hash) inet_bind_hash(sk, tb, port); WARN_ON(inet_csk(sk)->icsk_bind_hash != tb);