From nobody Sun Feb 16 19:08:00 2025 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 4YwwKY4ZKnz5npZQ; Sun, 16 Feb 2025 19:08:01 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YwwKY0DPDz3DWn; Sun, 16 Feb 2025 19:08:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1739732881; 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=HP0RTIp7ry1YF2xNU9/4syWuaWNBHWzompIFCY3oxrE=; b=VMOiJJvVTycOTjVl5NJsK2WMKawiDTBLMO8gruE1Y+byC1y2WodIFUQWXUcpOSLRTmPC3K gKF46qsosdkqeNo6j4ohcYDMgkUCOk/+GsD04VvRJerv1FN/WbX4bX3qXVeXX1Kd5h3Xgp Xb53mQxIUhVfYS4dHXiR9EiD/+42aWkC9OfWoZfANB3XOY38wIeCO09smv5AbSobq0xoMc 58SroM6xdn4B7MamQkjl+WlTJbnbhvW9WRWEDLn+ubtqfoA34QI7107R71rKZ9uERFZCzR NMKtDt++diksQKBbRKrGfvcpD3mNPSsmwdEIMVtV3EQU2jVI+p5j9J9qzwp5/w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1739732881; a=rsa-sha256; cv=none; b=rgR0i2+CakyV1ekXXMgZpDWheq1ydNK3BIo3TQJRVotUcvmQy51OXGYmSFKt+3e2Sz9oi9 /UQjem2UWOsJBuURj9cybz+MRtiFHuzWCwKkiOuK5U+dgIN4VKEXFh3jFwyZ9oRE1tBn5n 0Xac77u7y7z/oTQh+d5atPP2VZd5BMtzdmlxlVR2igN/BONizs3W4+U2j+aO1UJiaNhxKi V0qjbI4/Di2iZvNMALf5g6vEbMCm4vdVZiND/L+18Jx1VWeAP/thVu03vqvwcD7nlrqWGA 8pBtrZG7LzE7jKDZz3V6iyIDt+1Lp0xQkZdYTUKsUbvHhQr07icumUwnI2KaNw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1739732881; 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=HP0RTIp7ry1YF2xNU9/4syWuaWNBHWzompIFCY3oxrE=; b=F23h4WJ1OWLAo7n04bPSIFrc61pJVed0dPJv9R/11LUXd2Lu9I0StWHmwF1sF9TmjxZr64 aeB1zH74iu5Tc5Y0PTieQlxsRov/5HxqAf9FFsKUbcMBktTjDmwSPrBd9mMqC6nCoCXaiO kuMTCWTKXs+tQVk4VL/uQcpkCU5zHy76nUG1ubZzyQa7JJto+ZggwAbi9zSwzVqwDPYCJt 3c1eesyGoeF0TBWNmI4MWlpJvEJN6iM6aD3Yy63u0Z+qwBH8YfTbZ8Q4QiBd8VfME00lcz YU+NZS1E72q9Wjef2hBlAhGH6432N/6e89fkaU3Has/3v6pepPtgoKRURiHTJg== 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 4YwwKX6wk6z108P; Sun, 16 Feb 2025 19:08:00 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 51GJ80HB033114; Sun, 16 Feb 2025 19:08:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 51GJ806X033111; Sun, 16 Feb 2025 19:08:00 GMT (envelope-from git) Date: Sun, 16 Feb 2025 19:08:00 GMT Message-Id: <202502161908.51GJ806X033111@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Doug Moore Subject: git: bba883df5e88 - main - pctrie: iter_remove check from panic to KASSERT 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: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dougm X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: bba883df5e88d0fb1133b23c05db5501dd321ad8 Auto-Submitted: auto-generated The branch main has been updated by dougm: URL: https://cgit.FreeBSD.org/src/commit/?id=bba883df5e88d0fb1133b23c05db5501dd321ad8 commit bba883df5e88d0fb1133b23c05db5501dd321ad8 Author: Doug Moore AuthorDate: 2025-02-16 19:05:18 +0000 Commit: Doug Moore CommitDate: 2025-02-16 19:05:18 +0000 pctrie: iter_remove check from panic to KASSERT pctrie_iter_remove checks to see if the thing the iterator points to is actually there, and panics if it is not. This panic would likely indicate the same iterator had been used for removal twice, without advancing the iterator in-between. This test takes a bit of time, and as it indicates a programmer error rather than some external condition, it is better handled as a KASSERT. This means with KASSERTs disabled, a wee bit of time is saved. Reviewed by: alc, markj Differential Revision: https://reviews.freebsd.org/D49015 --- sys/kern/subr_pctrie.c | 41 +++++++++++++++++++---------------------- sys/sys/pctrie.h | 7 ++----- 2 files changed, 21 insertions(+), 27 deletions(-) diff --git a/sys/kern/subr_pctrie.c b/sys/kern/subr_pctrie.c index 16690c3521bf..51be005cccd7 100644 --- a/sys/kern/subr_pctrie.c +++ b/sys/kern/subr_pctrie.c @@ -826,26 +826,22 @@ pctrie_iter_jump_le(struct pctrie_iter *it, int64_t jump) } /* - * If 'child', a leaf and a child of 'parent', is not NULL and has key 'index', - * then remove it from the pctrie and return its value. If doing so produces an - * internal node with only one child, purge it from the pctrie and save it in - * *freenode for later disposal. + * Remove the non-NULL child identified by 'index' from the set of children of + * 'node'. If doing so causes 'node' to have only one child, purge it from the + * pctrie and save it in *freenode for later disposal. */ -static uint64_t * +static void pctrie_remove(struct pctrie *ptree, struct pctrie_node *node, uint64_t index, - struct pctrie_node *child, struct pctrie_node **freenode) + struct pctrie_node **freenode) { - uint64_t *m; + struct pctrie_node *child; int slot; *freenode = NULL; - m = pctrie_match_value(child, index); - if (m == NULL) - return (m); if (node == NULL) { pctrie_node_store(pctrie_root(ptree), PCTRIE_NULL, PCTRIE_LOCKED); - return (m); + return; } slot = pctrie_slot(node, index); KASSERT((node->pn_popmap & (1 << slot)) != 0, @@ -854,7 +850,7 @@ pctrie_remove(struct pctrie *ptree, struct pctrie_node *node, uint64_t index, node->pn_popmap ^= 1 << slot; pctrie_node_store(&node->pn_child[slot], PCTRIE_NULL, PCTRIE_LOCKED); if (!powerof2(node->pn_popmap)) - return (m); + return; KASSERT(node->pn_popmap != 0, ("%s: bad popmap all zeroes", __func__)); slot = ffs(node->pn_popmap) - 1; child = pctrie_node_load(&node->pn_child[slot], NULL, PCTRIE_LOCKED); @@ -866,7 +862,6 @@ pctrie_remove(struct pctrie *ptree, struct pctrie_node *node, uint64_t index, pctrie_setparent(child, node); pctrie_node_store(pctrie_child(ptree, node, index), child, PCTRIE_LOCKED); - return (m); } /* @@ -878,6 +873,7 @@ pctrie_remove_lookup(struct pctrie *ptree, uint64_t index, struct pctrie_node **freenode) { struct pctrie_node *child, *node; + uint64_t *m; int slot; node = NULL; @@ -888,25 +884,26 @@ pctrie_remove_lookup(struct pctrie *ptree, uint64_t index, child = pctrie_node_load(&node->pn_child[slot], NULL, PCTRIE_LOCKED); } - return (pctrie_remove(ptree, node, index, child, freenode)); + if ((m = pctrie_match_value(child, index)) != NULL) + pctrie_remove(ptree, node, index, freenode); + else + *freenode = NULL; + return (m); } /* * Remove from the trie the leaf last chosen by the iterator, and * adjust the path if it's last member is to be freed. */ -uint64_t * +void pctrie_iter_remove(struct pctrie_iter *it, struct pctrie_node **freenode) { - struct pctrie_node *child; - uint64_t *m; - - child = pctrie_node_load(pctrie_child(it->ptree, it->node, it->index), - NULL, PCTRIE_LOCKED); - m = pctrie_remove(it->ptree, it->node, it->index, child, freenode); + KASSERT(NULL != pctrie_match_value(pctrie_node_load(pctrie_child( + it->ptree, it->node, it->index), NULL, PCTRIE_LOCKED), it->index), + ("%s: removing value %lx not at iter", __func__, it->index)); + pctrie_remove(it->ptree, it->node, it->index, freenode); if (*freenode != NULL) it->node = pctrie_parent(it->node); - return (m); } /* diff --git a/sys/sys/pctrie.h b/sys/sys/pctrie.h index 196449e663d3..42473dc8e632 100644 --- a/sys/sys/pctrie.h +++ b/sys/sys/pctrie.h @@ -312,12 +312,9 @@ name##_PCTRIE_REMOVE_BASE(struct pctrie *ptree, \ static __inline __unused void \ name##_PCTRIE_ITER_REMOVE(struct pctrie_iter *it) \ { \ - uint64_t *val; \ struct pctrie_node *freenode; \ \ - val = pctrie_iter_remove(it, &freenode); \ - if (val == NULL) \ - panic("%s: key not found", __func__); \ + pctrie_iter_remove(it, &freenode); \ name##_PCTRIE_REMOVE_BASE(it->ptree, freenode); \ } \ \ @@ -386,7 +383,7 @@ struct pctrie_node *pctrie_reclaim_resume_cb(struct pctrie_node **pnode, pctrie_cb_t callback, int keyoff, void *arg); uint64_t *pctrie_remove_lookup(struct pctrie *ptree, uint64_t index, struct pctrie_node **killnode); -uint64_t *pctrie_iter_remove(struct pctrie_iter *it, +void pctrie_iter_remove(struct pctrie_iter *it, struct pctrie_node **freenode); uint64_t *pctrie_iter_value(struct pctrie_iter *it); uint64_t *pctrie_replace(struct pctrie *ptree, uint64_t *newval);