From nobody Sun Dec 5 18:47:02 2021 X-Original-To: dev-commits-src-all@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 76BC118BE556; Sun, 5 Dec 2021 18:47:03 +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 4J6bBv03Lmz4k96; Sun, 5 Dec 2021 18:47:03 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 D68C31CFFB; Sun, 5 Dec 2021 18:47:02 +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 1B5Il2UK030288; Sun, 5 Dec 2021 18:47:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1B5Il2GP030287; Sun, 5 Dec 2021 18:47:02 GMT (envelope-from git) Date: Sun, 5 Dec 2021 18:47:02 GMT Message-Id: <202112051847.1B5Il2GP030287@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: eb93b99d6986 - main - in_pcb: delay crfree() down into UMA dtor List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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: eb93b99d698674e3b1cc7139fda98e2b175b8c5b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1638730023; 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=z08mVD+1OaLYJf5t0AFK4HZGI89r9IYmKgqgERjseME=; b=MqNd05xr9MDN+QW4ap3oUrOuydMb9sbnlCK+w9gzljb01Vv11X+V4zh7Mz/noKgqVdzUDy kHuvwOHI5gIgMcK/AFu/nSaje0a1Ti0cKZUlB1f8S6wrD91NHXiRbyViOEj9Um0HE+zH7p w1p++oLAoB/VVGvaSMXjv7gaKR+YBo5qIF24+rxVcYKNdH2QTuR0JQWVUASs1Bf/8ANZEM E3TzUi6BtUdpJNZ+1fxcnfQssxzVOKhj25GFeB6p2A3mkP/VqxEcSuZFNeLcyFYDohij5X 30SS4OAPfD1A1vLvcOYMo9BL5zx5shHjLBXjkVvcXOwSVlSny4d89VXd8hd//w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1638730023; a=rsa-sha256; cv=none; b=Sk8YUHXusc3DJnuDBLfphFCtuj/XnkjFvCUQSY7JzF61YDNhsDKkvLBkhSwuEMOZyBuOoA s7TOiOg4F8x2sp7tGI0oPkA31Dhi6BpaNoVVnKQiQCl9Wjgjzo3AGuz2XOxIp2lIx4gt23 x62rgBNrWVmqdcFx9RHSTsF8tvQ0yau2+Orp0frPmdhqpF1oH4Ewr52mMhJxBv3U7Vs7TU b5h/OjCvYX21GWT9ikdreorCCo+yNC06CrlhUELwood97d9sSAY2cQizZYQDWgpuKy1K+7 wDOtZApXunj2L5Pp6FfHztSu0HHPIeAlKpsbiS2egRgJX6uqq8PFVRNyIQ0Wyw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=eb93b99d698674e3b1cc7139fda98e2b175b8c5b commit eb93b99d698674e3b1cc7139fda98e2b175b8c5b Author: Gleb Smirnoff AuthorDate: 2021-12-05 16:47:24 +0000 Commit: Gleb Smirnoff CommitDate: 2021-12-05 18:46:37 +0000 in_pcb: delay crfree() down into UMA dtor inpcb lookups, which check inp_cred, work with pcbs that potentially went through in_pcbfree(). So inp_cred should stay valid until SMR guarantees its invisibility to lookups. While here, put the whole inpcb destruction sequence of in_pcbfree(), inpcb_dtor() and inpcb_fini() sequentially. Submitted by: markj Differential revision: https://reviews.freebsd.org/D33273 --- sys/netinet/in_pcb.c | 42 +++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/sys/netinet/in_pcb.c b/sys/netinet/in_pcb.c index 0a44eae0d908..ffcc93553c22 100644 --- a/sys/netinet/in_pcb.c +++ b/sys/netinet/in_pcb.c @@ -502,18 +502,6 @@ abort_with_hash_wlock: return (err); } -/* - * Different protocols initialize their inpcbs differently - giving - * different name to the lock. But they all are disposed the same. - */ -static void -inpcb_fini(void *mem, int size) -{ - struct inpcb *inp = mem; - - INP_LOCK_DESTROY(inp); -} - /* Make sure it is safe to use hashinit(9) on CK_LIST. */ CTASSERT(sizeof(struct inpcbhead) == sizeof(LIST_HEAD(, inpcb))); @@ -521,6 +509,8 @@ CTASSERT(sizeof(struct inpcbhead) == sizeof(LIST_HEAD(, inpcb))); * Initialize an inpcbinfo -- we should be able to reduce the number of * arguments in time. */ +static void inpcb_dtor(void *, int, void *); +static void inpcb_fini(void *, int); void in_pcbinfo_init(struct inpcbinfo *pcbinfo, const char *name, u_int hash_nelements, int porthash_nelements, char *inpcbzone_name, @@ -542,7 +532,7 @@ in_pcbinfo_init(struct inpcbinfo *pcbinfo, const char *name, pcbinfo->ipi_lbgrouphashbase = hashinit(porthash_nelements, M_PCB, &pcbinfo->ipi_lbgrouphashmask); pcbinfo->ipi_zone = uma_zcreate(inpcbzone_name, sizeof(struct inpcb), - NULL, NULL, inpcbzone_init, inpcb_fini, UMA_ALIGN_PTR, + NULL, inpcb_dtor, inpcbzone_init, inpcb_fini, UMA_ALIGN_PTR, UMA_ZONE_SMR); uma_zone_set_max(pcbinfo->ipi_zone, maxsockets); uma_zone_set_warning(pcbinfo->ipi_zone, @@ -644,7 +634,6 @@ in_pcballoc(struct socket *so, struct inpcbinfo *pcbinfo) #if defined(IPSEC) || defined(IPSEC_SUPPORT) || defined(MAC) out: - crfree(inp->inp_cred); uma_zfree_smr(pcbinfo->ipi_zone, inp); return (error); #endif @@ -1833,7 +1822,6 @@ in_pcbfree(struct inpcb *inp) inp->inp_flags &= ~INP_INHASHLIST; } - crfree(inp->inp_cred); RO_INVALIDATE_CACHE(&inp->inp_route); #ifdef MAC mac_inpcb_destroy(inp); @@ -1864,6 +1852,30 @@ in_pcbfree(struct inpcb *inp) #ifdef INET inp_freemoptions(imo); #endif + /* Destruction is finalized in inpcb_dtor(). */ +} + +static void +inpcb_dtor(void *mem, int size, void *arg) +{ + struct inpcb *inp = mem; + + crfree(inp->inp_cred); +#ifdef INVARIANTS + inp->inp_cred = NULL; +#endif +} + +/* + * Different protocols initialize their inpcbs differently - giving + * different name to the lock. But they all are disposed the same. + */ +static void +inpcb_fini(void *mem, int size) +{ + struct inpcb *inp = mem; + + INP_LOCK_DESTROY(inp); } /*