From nobody Mon Jun 29 06:34:11 2026 X-Original-To: dev-commits-src-branches@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 4gpc1w0TJJz6k54J for ; Mon, 29 Jun 2026 06:34:12 +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 "YR1" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4gpc1v2vMfz4Ggg for ; Mon, 29 Jun 2026 06:34:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1782714851; 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=Q9NF20jllPwTDli+avHMjFrhtPfay3S3LyXwEa13BsY=; b=DgrhwCWxce4nPqvLE40oPqwWNOP0Aargkx9mlaFwyzVw/zMfg0YPt88kP+ZqXvM+yDy9n1 5Ya3D5X2Mrm4YJoXGFOGcV8HW2YvjV9C4PdHZ52l0LhXsbaRoGEGM2dJudbus4FHua/OVr 2vzM+comcVWuipDS7fSRJMOebnRZZmS8jDxVStBuZ77BV+Dw2wCFGxmfukXTJmtvRxaEy5 Pn2iCzs4MN62luf7a2hgsYO2bHQolk5JDFtn2DRbCGwAZvV8zddplvY/aWMlo9WQDPRfvp MHFaJTFV4iWdd1PMQGdLu4TTqorOnP8a47Iq1VURv18983Wr6pVBqXrpqFQIYg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1782714851; a=rsa-sha256; cv=none; b=KU5brp/H5MwJ52p5NLLKWKcnq2iTrHbeEVKmuMdcod+ADqQczdI/QdcGlCD3tK39KaYWAY d9o/jytrLPzrD2b+uLz6CA/R2+mNdHVBfPXh8UnDBoOateKppGfctrMgOUBhRD2riNFvCJ IqAXQ9rmnmgKUa8fvgIK+5jlj57ZSNLE9IEr/0+kxg4+YwEtTCZt5cGxO11pb2lU0zFr8P dvchDRAgEJKRf1gOOKXHu4im7zmEVL2zi1ByX6AItjqdFZEgoHLjObRD7FvNQ9YwViK2LJ dpR0tQdGfn6jInkQCzSbsEag6BjXZhyzrd/Y5VmKO3tTR/yKaQ5uoIs9/ygN8Q== 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=1782714851; 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=Q9NF20jllPwTDli+avHMjFrhtPfay3S3LyXwEa13BsY=; b=neikUyJ5rH75mwrpXAZFUeh6rYfsNnIHfj0ryPWZeOwS6jyO6rNPMJQsH9d5uKBfcVna+E HBBTheJ0lOUSv1zF49aJxtVDmuR0bMYWGGOVPY+lpibgRiy85YlZq3Fhh+qq4t1c2DLHNc UQNepJrnvD+D1lRIjhoKvngz1DWNs+eNBm+mDjlcWlC59uQqhs6Fplws4hu8BcnOLBv/NJ wDdPlGHJB3mkm/MZAUVfopxxjQov7m4r+t7ggGigsp8xvlpOGq9Yam3wxcAvAmm65ZMlDn O56HhXCfTgHw42RZbIimmoLZRPhp/yaTlM2W1wgxVGUWOw0M1iozJ8/LPSr4Yw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4gpc1v1CHtzmVB for ; Mon, 29 Jun 2026 06:34:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 4727c by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Mon, 29 Jun 2026 06:34:11 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Bjoern A. Zeeb Subject: git: ea1dfeca866c - stable/15 - LinuxKPi: idr: use macros for idr lock operations List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bz X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: ea1dfeca866c27da131d3752a62d61e179fd2860 Auto-Submitted: auto-generated Date: Mon, 29 Jun 2026 06:34:11 +0000 Message-Id: <6a4211e3.4727c.3ec0a2da@gitrepo.freebsd.org> The branch stable/15 has been updated by bz: URL: https://cgit.FreeBSD.org/src/commit/?id=ea1dfeca866c27da131d3752a62d61e179fd2860 commit ea1dfeca866c27da131d3752a62d61e179fd2860 Author: Bjoern A. Zeeb AuthorDate: 2026-02-17 03:06:19 +0000 Commit: Bjoern A. Zeeb CommitDate: 2026-06-29 03:51:01 +0000 LinuxKPi: idr: use macros for idr lock operations Our idr implementation is using a mtx lock which in the past has already caused problems (613723bac219c). In order to make it easier to tackle the problem start by factoring out all the operations related to the idr->lock into macros as we have often done in other parts of code as well. Sponsored by: The FreeBSD Foundation Reviewed by: wulf, emaste Differential Revision: https://reviews.freebsd.org/D55392 (cherry picked from commit b53eab322946e88fb95ea4e143d1147d3de18d04) --- sys/compat/linuxkpi/common/src/linux_idr.c | 67 +++++++++++++++++------------- 1 file changed, 37 insertions(+), 30 deletions(-) diff --git a/sys/compat/linuxkpi/common/src/linux_idr.c b/sys/compat/linuxkpi/common/src/linux_idr.c index 664177835c85..7e5f0d28867e 100644 --- a/sys/compat/linuxkpi/common/src/linux_idr.c +++ b/sys/compat/linuxkpi/common/src/linux_idr.c @@ -62,6 +62,13 @@ DPCPU_DEFINE_STATIC(struct linux_idr_cache, linux_idr_cache); */ static MALLOC_DEFINE(M_IDR, "idr", "Linux IDR compat"); +#define IDR_LOCK_INIT(_idr) mtx_init(&(_idr)->lock, "idr", NULL, MTX_DEF); +#define IDR_LOCK_DESTROY(_idr) mtx_destroy(&(_idr)->lock); +#define IDR_LOCK(_idr) mtx_lock(&(_idr)->lock); +#define IDR_UNLOCK(_idr) mtx_unlock(&(_idr)->lock); +#define IDR_LOCK_ASSERT(_idr) mtx_assert(&(_idr)->lock, MA_OWNED); +#define IDR_LOCK_INITALIZED(_idr) mtx_initialized(&(_idr)->lock) + static struct idr_layer * idr_preload_dequeue_locked(struct linux_idr_cache *lic) { @@ -168,7 +175,7 @@ void idr_init(struct idr *idr) { bzero(idr, sizeof(*idr)); - mtx_init(&idr->lock, "idr", NULL, MTX_DEF); + IDR_LOCK_INIT(idr); } /* Only frees cached pages. */ @@ -182,17 +189,17 @@ idr_destroy(struct idr *idr) * without a idr_init(). Check if this is the case. If we do not do this * then the mutex will panic while asserting that it is valid. */ - if (mtx_initialized(&idr->lock) == 0) + if (IDR_LOCK_INITALIZED(idr) == 0) return; idr_remove_all(idr); - mtx_lock(&idr->lock); + IDR_LOCK(idr); for (il = idr->free; il != NULL; il = iln) { iln = il->ary[0]; free(il, M_IDR); } - mtx_unlock(&idr->lock); - mtx_destroy(&idr->lock); + IDR_UNLOCK(idr); + IDR_LOCK_DESTROY(idr); } static void @@ -215,11 +222,11 @@ void idr_remove_all(struct idr *idr) { - mtx_lock(&idr->lock); + IDR_LOCK(idr); idr_remove_layer(idr->top, idr->layers - 1); idr->top = NULL; idr->layers = 0; - mtx_unlock(&idr->lock); + IDR_UNLOCK(idr); } static void * @@ -266,9 +273,9 @@ idr_remove(struct idr *idr, int id) { void *res; - mtx_lock(&idr->lock); + IDR_LOCK(idr); res = idr_remove_locked(idr, id); - mtx_unlock(&idr->lock); + IDR_UNLOCK(idr); return (res); } @@ -298,7 +305,7 @@ idr_replace(struct idr *idr, void *ptr, int id) void *res; int idx; - mtx_lock(&idr->lock); + IDR_LOCK(idr); il = idr_find_layer_locked(idr, id); idx = id & IDR_MASK; @@ -309,7 +316,7 @@ idr_replace(struct idr *idr, void *ptr, int id) res = il->ary[idx]; il->ary[idx] = ptr; } - mtx_unlock(&idr->lock); + IDR_UNLOCK(idr); return (res); } @@ -319,7 +326,7 @@ idr_find_locked(struct idr *idr, int id) struct idr_layer *il; void *res; - mtx_assert(&idr->lock, MA_OWNED); + IDR_LOCK_ASSERT(idr); il = idr_find_layer_locked(idr, id); if (il != NULL) res = il->ary[id & IDR_MASK]; @@ -333,9 +340,9 @@ idr_find(struct idr *idr, int id) { void *res; - mtx_lock(&idr->lock); + IDR_LOCK(idr); res = idr_find_locked(idr, id); - mtx_unlock(&idr->lock); + IDR_UNLOCK(idr); return (res); } @@ -345,7 +352,7 @@ idr_get_next(struct idr *idr, int *nextidp) void *res = NULL; int id = *nextidp; - mtx_lock(&idr->lock); + IDR_LOCK(idr); for (; id <= idr_max(idr); id++) { res = idr_find_locked(idr, id); if (res == NULL) @@ -353,7 +360,7 @@ idr_get_next(struct idr *idr, int *nextidp) *nextidp = id; break; } - mtx_unlock(&idr->lock); + IDR_UNLOCK(idr); return (res); } @@ -364,12 +371,12 @@ idr_pre_get(struct idr *idr, gfp_t gfp_mask) struct idr_layer *head; int need; - mtx_lock(&idr->lock); + IDR_LOCK(idr); for (;;) { need = idr->layers + 1; for (il = idr->free; il != NULL; il = il->ary[0]) need--; - mtx_unlock(&idr->lock); + IDR_UNLOCK(idr); if (need <= 0) break; for (head = NULL; need; need--) { @@ -385,7 +392,7 @@ idr_pre_get(struct idr *idr, gfp_t gfp_mask) } if (head == NULL) return (0); - mtx_lock(&idr->lock); + IDR_LOCK(idr); il->ary[0] = idr->free; idr->free = head; } @@ -435,7 +442,7 @@ idr_get_new_locked(struct idr *idr, void *ptr, int *idp) int idx; int id; - mtx_assert(&idr->lock, MA_OWNED); + IDR_LOCK_ASSERT(idr); error = -EAGAIN; /* @@ -506,9 +513,9 @@ idr_get_new(struct idr *idr, void *ptr, int *idp) { int retval; - mtx_lock(&idr->lock); + IDR_LOCK(idr); retval = idr_get_new_locked(idr, ptr, idp); - mtx_unlock(&idr->lock); + IDR_UNLOCK(idr); return (retval); } @@ -522,7 +529,7 @@ idr_get_new_above_locked(struct idr *idr, void *ptr, int starting_id, int *idp) int idx, sidx; int id; - mtx_assert(&idr->lock, MA_OWNED); + IDR_LOCK_ASSERT(idr); error = -EAGAIN; /* @@ -624,9 +631,9 @@ idr_get_new_above(struct idr *idr, void *ptr, int starting_id, int *idp) { int retval; - mtx_lock(&idr->lock); + IDR_LOCK(idr); retval = idr_get_new_above_locked(idr, ptr, starting_id, idp); - mtx_unlock(&idr->lock); + IDR_UNLOCK(idr); return (retval); } @@ -643,7 +650,7 @@ idr_alloc_locked(struct idr *idr, void *ptr, int start, int end) int error; int id; - mtx_assert(&idr->lock, MA_OWNED); + IDR_LOCK_ASSERT(idr); if (unlikely(start < 0)) return (-EINVAL); @@ -669,9 +676,9 @@ idr_alloc(struct idr *idr, void *ptr, int start, int end, gfp_t gfp_mask) { int retval; - mtx_lock(&idr->lock); + IDR_LOCK(idr); retval = idr_alloc_locked(idr, ptr, start, end); - mtx_unlock(&idr->lock); + IDR_UNLOCK(idr); return (retval); } @@ -680,13 +687,13 @@ idr_alloc_cyclic(struct idr *idr, void *ptr, int start, int end, gfp_t gfp_mask) { int retval; - mtx_lock(&idr->lock); + IDR_LOCK(idr); retval = idr_alloc_locked(idr, ptr, max(start, idr->next_cyclic_id), end); if (unlikely(retval == -ENOSPC)) retval = idr_alloc_locked(idr, ptr, start, end); if (likely(retval >= 0)) idr->next_cyclic_id = retval + 1; - mtx_unlock(&idr->lock); + IDR_UNLOCK(idr); return (retval); }