Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1130880pxa; Wed, 5 Aug 2020 23:44:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYFZTgU19JmAMa5KwhW4oEa/gK3W2TneG9xA0krwo30MIjOGFjUQNP+1ZEyuGaO7/g+bYA X-Received: by 2002:a17:906:8316:: with SMTP id j22mr2835303ejx.20.1596696271329; Wed, 05 Aug 2020 23:44:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596696271; cv=none; d=google.com; s=arc-20160816; b=Urhak8NoH8QYnuOWA3YF7E+6jL1UdnIPQO/dttSUTUBJeWEKK+yALpJu8R205TZazl Yr9rVU8gglqBqeksk7ROeklBqlTWEngfOgCMZHON+FjjQtZqdlZ5vX+nHsZjBZT426fA zaopYIwh/hUpSnXZ1DigVxFv0dGqGO7oIkQyiru7mxQOHlhWz08aF8r1/FR+iAL+kI4+ 925YvEzHmdhreU5eGCGOBwrpYxCC29A0WbEZROAxJTm6VvQ/BEsdLjX9uBPkT95np7vV twGZ05v0U+2iF8Z2WqWiU0agvYRHHJB9sfW4qR9b+oHihaGpvFJRh5caVJvYuYYKreJv Aq1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:dkim-signature; bh=hA5JCTqaCCREAuEoCIHIc9jLTAOEK7qQNsr7rDO2FA0=; b=AV8FPbJjb57DJdwHEm1vGyOq/2abCUb24AaPUAgdSBjsOxF1sddDM4KbvmKZ80O+Re vf6vUYT3LdmPTJt6X54zcZov5buSoZYivTH/AmSdFwm9rA+K6VVhcQINUnvJ3RlLl/8o z4mMvHxES+/wyWt3H6YGcgGIJjvMGyDs5Lh2EHtnnrIcJt9Fvga2N280Kg2tMRTc5zPX XGLL1YK2rfjdb2NbFAgKy//TRE6+KpqmfaxFSr1J6ZW9/FbQ5TPQdq8TZ9QgH/itEBba G7nE0RSkZyTLDfe/9ZRhtFXoru6vCr5xcndnRk9xVEiSER0JeVK8LqQFvPXFDm3LEWZV kgLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@tessares-net.20150623.gappssmtp.com header.s=20150623 header.b=znsX4TBf; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z20si2692910ejb.359.2020.08.05.23.44.09; Wed, 05 Aug 2020 23:44:31 -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=@tessares-net.20150623.gappssmtp.com header.s=20150623 header.b=znsX4TBf; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728458AbgHFGln (ORCPT + 99 others); Thu, 6 Aug 2020 02:41:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726942AbgHFGlQ (ORCPT ); Thu, 6 Aug 2020 02:41:16 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 083CEC061574 for ; Wed, 5 Aug 2020 23:41:14 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id o18so49049778eje.7 for ; Wed, 05 Aug 2020 23:41:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tessares-net.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:mime-version; bh=hA5JCTqaCCREAuEoCIHIc9jLTAOEK7qQNsr7rDO2FA0=; b=znsX4TBfyR5p6MWtCGhXPPD+DRyjOvaJE1NVfd8TuaurE/zcGlPGJrBhwa4gq9QOCl yR8WY3AZGrKKdYiIaV0mxgadgXt0TvJjTrr0C0cxrvaM5vT9ODEsfpbZkeEfofFzkZM5 AZ560eyEC4kzBTm8RAon7PesCtCASvRuSvhE/1lJ4clbb1FUimJBWmzzwEBX6xXmXsn2 Bp/pRIeNTIH3K83zLWOrMn09spoRLlZ/DQZe+NaL50MiCQmtk5drjVKLlIPXd4TbuiGZ sczMaCU9T2GPtL4xpFka18bvECRuBM8Pkq/lOeH+SgXi6gP5jHjelfJ/K46eeN2swKRd wUNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version; bh=hA5JCTqaCCREAuEoCIHIc9jLTAOEK7qQNsr7rDO2FA0=; b=JWKvyQnU6qghZQZ0O4mzbeN/8sCkc58iphf/llw2oUJyvDxhuIEpBwH8KM6p+CTCIw 4EC6VHbeYmnoHqIb5jsPQ+VpBcs6wlSzj5jKrB9JREKwJvgtqgHMSACleBKk6k7dQjNt xfTOLS83u93wuSadN+koYVy6d/BNjZWWoaDDqudl3VqlqiA9+nVWkvyjGfXzlpsf8gHa fCxjWFF3YY5PVLPVG8XryHQzw0Mu3U8LhZdLCNWDC0c0JQDuSff3w+9YlFMGlf8J6Dkf J+CAhcC1nk7rnoeQsjScNlPduAwriKabQ/JiJNZQC+7aE8Uy711agbOJEvtX7MJAg0oK nA9A== X-Gm-Message-State: AOAM531SBNl1xFFjrigHt8jzYcUfUjeZ+adz2TncgjUYUOSle9IVf5jy UdZuKGd+ow/CwwrNjXK5xiW4LIf3/K+zJ2CcyCrRIcTbfp4Tm0kRylXXVQNoZ2hdHU/uaym9s9i 2kaMPJg6GjkIapxisbQ== X-Received: by 2002:a17:906:7253:: with SMTP id n19mr3006802ejk.387.1596696073363; Wed, 05 Aug 2020 23:41:13 -0700 (PDT) Received: from tim.froidcoeur.net (ptr-7tznw15pracyli75x11.18120a2.ip6.access.telenet.be. [2a02:1811:50e:f0f0:d05d:939:f42b:f575]) by smtp.gmail.com with ESMTPSA id h18sm2880984edw.56.2020.08.05.23.41.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2020 23:41:12 -0700 (PDT) From: Tim Froidcoeur To: "David S. Miller" , Jakub Kicinski , Alexey Kuznetsov , Hideaki YOSHIFUJI , KOVACS Krisztian , Patrick McHardy Cc: Tim Froidcoeur , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net 0/2] net: initialize fastreuse on inet_inherit_port Date: Thu, 6 Aug 2020 08:41:06 +0200 Message-Id: <20200806064109.183059-1-tim.froidcoeur@tessares.net> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In the case of TPROXY, bind_conflict optimizations for SO_REUSEADDR or SO_REUSEPORT are broken, possibly resulting in O(n) instead of O(1) bind behaviour or in the incorrect reuse of a bind. the kernel keeps track for each bind_bucket if all sockets in the bind_bucket support SO_REUSEADDR or SO_REUSEPORT in two fastreuse flags. These flags allow skipping the costly bind_conflict check when possible (meaning when all sockets have the proper SO_REUSE option). For every socket added to a bind_bucket, these flags need to be updated. As soon as a socket that does not support reuse is added, the flag is set to false and will never go back to true, unless the bind_bucket is deleted. Note that there is no mechanism to re-evaluate these flags when a socket is removed (this might make sense when removing a socket that would not allow reuse; this leaves room for a future patch). For this optimization to work, it is mandatory that these flags are properly initialized and updated. When a child socket is created from a listen socket in __inet_inherit_port, the TPROXY case could create a new bind bucket without properly initializing these flags, thus preventing the optimization to work. Alternatively, a socket not allowing reuse could be added to an existing bind bucket without updating the flags, causing bind_conflict to never be called as it should. Patch 1/2 refactors the fastreuse update code in inet_csk_get_port into a small helper function, making the actual fix tiny and easier to understand. Patch 2/2 calls this new helper when __inet_inherit_port decides to create a new bind_bucket or use a different bind_bucket than the one of the listen socket. Tim Froidcoeur (2): net: refactor bind_bucket fastreuse into helper net: initialize fastreuse on inet_inherit_port include/net/inet_connection_sock.h | 4 ++ net/ipv4/inet_connection_sock.c | 99 ++++++++++++++++-------------- net/ipv4/inet_hashtables.c | 1 + 3 files changed, 59 insertions(+), 45 deletions(-) -- 2.25.1 -- Disclaimer: https://www.tessares.net/mail-disclaimer/