From nobody Tue Feb 07 17:22:43 2023 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4PB91b4zf3z3nTRx; Tue, 7 Feb 2023 17:22:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4PB91b4N9Wz4CMY; Tue, 7 Feb 2023 17:22:43 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675790563; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PuwEu9bz6hkEDoQRFc0D2eXwZZH3dSWMZ2WYaJDzmnI=; b=BV4Rub4sGAk0yqKHD+PE0QX3aPNJhNx7WNxAEHa2fkZvjDAeQGGCIT1kEWmk/wX5IqalGL byKeIKLow4W/uCCx0H8njrJGlyYmcglFZ/Yrpdj/icpYcr3WxggaC8knsJJxyEIOrnXp9u hHyvBnhq5PSKI4W8FJMr99mIMJWeQospv68PRj3fJu9yej5zaJcSEpMGxKqmVMF1sV5PFn DHE7IgtQIc9hslnQKdgfr/URPpgD59pHnn78q2Pt+9Dlo0kb7GD6N0DnxoM1qQXbUhPmUE Za8ABkQjdgtfdlY9s+z4FPePjFBM1ZcHwFLRWjQKsta7fJT1kuBJo8yuU8on0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675790563; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=PuwEu9bz6hkEDoQRFc0D2eXwZZH3dSWMZ2WYaJDzmnI=; b=aLylog0UFuwGRLRvQmjlac72WpIAt72U50T/F7LaKBA9uEZ5cgWBAjKHvVqTRVtKFtJsPY ONn8IMDtmcW96gcJi3MPaEdFYALAXQnvpTwOXJBkFnOhV1ANpDYd6QLMXdKGt9iOkgNNnQ k8Ne28QeKGetnWdfWtmcXrCQ61ko0Z14CUP1R3uCj/mk4R1uw348CbJworWIVCdJOsMaLp GOz7/awKAFo/Oj9aSFPMUIDM9vkf+MZQBg3tLdQR+u7BVaA3YbatYkbTZ5tMnfe4oVarG/ +BMiZvh0xDh+GXPb/wwUHBPhDv5Npodt6r0xNszA0JDTsEYo4If61tq7oyJgAQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675790563; a=rsa-sha256; cv=none; b=qVfwOMt4mMNyXfrNxMFPLRC3h0Dr2DEkONUGQ396dmBXauMzTATU9PMC4xIwCSfTtaDdcE 0EZ9CJjZDpjscSUx2rFT0qfpUxj/OQJVcE4slDuQPb8vgR4WsuPDEQ0ZoNBiHgEqS0DdCx f6tHh4ijBlhpd0v5cpOpaRRaw1srIIyq3g8AGJP3Y+2HdtC7FCyivshvn6gA5NASsXPhcP YY7bLE+r6mJUqUsNaCd/jzYqtaOeTb2it4bym04numMeTwgIPxOzEFzMomJpe8h8J+rnRC 9BAhMoygf1o0U+th8WIZa7LIZ9FioqSeZJlvrumKEYOx3vbzQZZFUK1yR4hG5Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4PB91b3Tl1zPqk; Tue, 7 Feb 2023 17:22:43 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 317HMhP1089907; Tue, 7 Feb 2023 17:22:43 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 317HMhS0089906; Tue, 7 Feb 2023 17:22:43 GMT (envelope-from git) Date: Tue, 7 Feb 2023 17:22:43 GMT Message-Id: <202302071722.317HMhS0089906@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: 220d89212943 - main - inpcb: immediately return matching pcb on lookup List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 220d892129439e4596b8ef054f56b6e0ede03538 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=220d892129439e4596b8ef054f56b6e0ede03538 commit 220d892129439e4596b8ef054f56b6e0ede03538 Author: Gleb Smirnoff AuthorDate: 2023-02-07 17:21:52 +0000 Commit: Gleb Smirnoff CommitDate: 2023-02-07 17:21:52 +0000 inpcb: immediately return matching pcb on lookup This saves a lot of CPU cycles if you got large connection table. The code removed originates from 413628a7e3d, a very large changeset. Discussed that with Bjoern, Jamie we can't recover why would we ever have identical 4-tuples in the hash, even in the presence of jails. Bjoern did a test that confirms that it is impossible to allocate an identical connection from a jail to a host. Code review also confirms that system shouldn't allow for such connections to exist. With a lack of proper test suite we decided to take a risk and go forward with removing that code. Reviewed by: gallatin, bz, markj Differential Revision: https://reviews.freebsd.org/D38015 --- sys/netinet/in_pcb.c | 18 +++--------------- sys/netinet6/in6_pcb.c | 18 +++--------------- 2 files changed, 6 insertions(+), 30 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 2a775ff5fc31..728178f1011c 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -2225,7 +2225,7 @@ in_pcblookup_hash_locked(struct inpcbinfo *pcbinfo, struct in_addr faddr, struct ifnet *ifp, uint8_t numa_domain) { struct inpcbhead *head; - struct inpcb *inp, *tmpinp; + struct inpcb *inp; u_short fport = fport_arg, lport = lport_arg; KASSERT((lookupflags & ~(INPLOOKUP_WILDCARD)) == 0, @@ -2239,7 +2239,6 @@ in_pcblookup_hash_locked(struct inpcbinfo *pcbinfo, struct in_addr faddr, /* * First look for an exact match. */ - tmpinp = NULL; head = &pcbinfo->ipi_hashbase[INP_PCBHASH(&faddr, lport, fport, pcbinfo->ipi_hashmask)]; CK_LIST_FOREACH(inp, head, inp_hash) { @@ -2251,20 +2250,9 @@ in_pcblookup_hash_locked(struct inpcbinfo *pcbinfo, struct in_addr faddr, if (inp->inp_faddr.s_addr == faddr.s_addr && inp->inp_laddr.s_addr == laddr.s_addr && inp->inp_fport == fport && - inp->inp_lport == lport) { - /* - * XXX We should be able to directly return - * the inp here, without any checks. - * Well unless both bound with SO_REUSEPORT? - */ - if (prison_flag(inp->inp_cred, PR_IP4)) - return (inp); - if (tmpinp == NULL) - tmpinp = inp; - } + inp->inp_lport == lport) + return (inp); } - if (tmpinp != NULL) - return (tmpinp); /* * Then look for a wildcard match, if requested. diff --git a/sys/netinet6/in6_pcb.c b/sys/netinet6/in6_pcb.c index 1b57fce7ec47..80540f2695e7 100644 --- a/sys/netinet6/in6_pcb.c +++ b/sys/netinet6/in6_pcb.c @@ -966,7 +966,7 @@ in6_pcblookup_hash_locked(struct inpcbinfo *pcbinfo, struct in6_addr *faddr, int lookupflags, struct ifnet *ifp, uint8_t numa_domain) { struct inpcbhead *head; - struct inpcb *inp, *tmpinp; + struct inpcb *inp; u_short fport = fport_arg, lport = lport_arg; KASSERT((lookupflags & ~(INPLOOKUP_WILDCARD)) == 0, @@ -981,7 +981,6 @@ in6_pcblookup_hash_locked(struct inpcbinfo *pcbinfo, struct in6_addr *faddr, /* * First look for an exact match. */ - tmpinp = NULL; head = &pcbinfo->ipi_hashbase[INP6_PCBHASH(faddr, lport, fport, pcbinfo->ipi_hashmask)]; CK_LIST_FOREACH(inp, head, inp_hash) { @@ -991,20 +990,9 @@ in6_pcblookup_hash_locked(struct inpcbinfo *pcbinfo, struct in6_addr *faddr, if (IN6_ARE_ADDR_EQUAL(&inp->in6p_faddr, faddr) && IN6_ARE_ADDR_EQUAL(&inp->in6p_laddr, laddr) && inp->inp_fport == fport && - inp->inp_lport == lport) { - /* - * XXX We should be able to directly return - * the inp here, without any checks. - * Well unless both bound with SO_REUSEPORT? - */ - if (prison_flag(inp->inp_cred, PR_IP6)) - return (inp); - if (tmpinp == NULL) - tmpinp = inp; - } + inp->inp_lport == lport) + return (inp); } - if (tmpinp != NULL) - return (tmpinp); /* * Then look for a wildcard match, if requested.