From nobody Thu Apr 30 07:18:29 2026 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 4g5lrq06w5z6bCcR for ; Thu, 30 Apr 2026 07:18:35 +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 "R13" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 4g5lrp27dPz3pBq for ; Thu, 30 Apr 2026 07:18:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1777533514; 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=ZNWjbttZ2E3G4Z9GfzMGO4rim4/5VUgciR3+BXc1cIA=; b=qYXPA2rLsV7pjH3eAuYYqoBTwcNyV//UXVREnJrv5n7N1P62hmOS3hJ7TEHqwehXqMBq0t nmNBAUFbE7T3vgNvkjVpH8I1zSBTbezqiOrJUyjdecnBpP4lovyMl689rOT0EeIPhoy7AX MfQm8EGRprC1C8iydUspOe6zvh07W6Ntq16fZMZFDT7JqtupL5JUCMT35Z1GTXuBhpIeKn JB5EOMAN/QiaQRPunhqwBcjg82LGmVRVNwI1VFjuFHX0OQGZPXZby6WnvaFsGA+LdikOsz ANSeSCDvxIZf7Uaw42w1Tuw4fRWsq6rAKserHqJ7N4dUzwClkH+njYQiD4LY9A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1777533514; a=rsa-sha256; cv=none; b=KCKvQAo3GNkxGO1kSK97TuDvpO7Ky3lW03GH2V5N7YAL7Wwdi45h8+Ya98Pi82R9h+MLY7 3vHhtU5dlmr1h8FaGa8DZYFHTDCP945npiBDOK0/yTZxbteZykwWzLXst6+nR1R2+SFmlv 16lopzmRi8VBcnfjJdV2RpHSnefudctJvu61lP/CZXzuTKCM3Ip3qSLPVX0tM0CgpHMdF5 l/72TbpZdEJ48A1KaQ86xy9AxByoTkYYxvlVGdLa+NtbE/BCKdHvLlMLfBB999GhhPpYEp ZiseRmHD1CjDUwflVoHIrE2n4p9ZLDZ0DZHORb3EyFrOdtAfBZD+RlLttjdA8w== 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=1777533514; 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=ZNWjbttZ2E3G4Z9GfzMGO4rim4/5VUgciR3+BXc1cIA=; b=ZJ0MGSM5CZ2lBVt7V+c6HtR1aZwLLLHM5N+4d2n9pDyPSAou5PtDemhmeUZN7dxRufRsxT T42jJzSjvmki2VdjGNf9g+UiHV6e5Q4yiMpuoas+gf6lJcQR8akyNNvcdtBZLj9hgpXh8r nB8tF7/glLduIyeddBw8q24J+bEjqV0UMCVUqTV5xxjQGX3gdg0e72pDYzh7scoSrdS0iO jvyJT2DgCR1RLPo3pZMQfoIWh7x9JEbgxPc0DedqREkSrnU5OPndnO67sQCrhr252a1DIC v7dAtiJzwxjWSsfMLdm0f+7GnZLxkGsvSW5rhW45QD6CSYKuZEwx8xuP1qDn1Q== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4g5lrp0QlDz1Fn5 for ; Thu, 30 Apr 2026 07:18:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 3699a by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 30 Apr 2026 07:18:29 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Jean-=?utf-8?Q?S=C3=A9bast?==?utf-8?Q?ien P=C3=A9?=dron Subject: git: 783d018cf954 - main - linuxkpi: Add `struct xa_limit` support to xarray 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: dumbbell X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 783d018cf954f99032a0a4f655af8916024598a8 Auto-Submitted: auto-generated Date: Thu, 30 Apr 2026 07:18:29 +0000 Message-Id: <69f30245.3699a.5ff2d68e@gitrepo.freebsd.org> The branch main has been updated by dumbbell: URL: https://cgit.FreeBSD.org/src/commit/?id=783d018cf954f99032a0a4f655af8916024598a8 commit 783d018cf954f99032a0a4f655af8916024598a8 Author: Jean-Sébastien Pédron AuthorDate: 2026-04-13 21:39:22 +0000 Commit: Jean-Sébastien Pédron CommitDate: 2026-04-30 07:05:01 +0000 linuxkpi: Add `struct xa_limit` support to xarray The `xa_alloc*()` functions family takes a `struct xa_limit` to describe the range of IDs the caller wants to allocate. We were using a single mask to qualify a maximum ID only. This commit changes that to use the same `struct xa_limit`. The logic did not change, except it now supports a minimum ID as well. The definition of `XA_LIMIT()` macro is adapted, as well as the definitions of `xa_limit_*` (only `xa_limit_32b` existed, the other two are added with this commit). The DRM generic code started to use this `struct xa_limit` in Linux 6.12. Reviewed by: bz Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D56445 --- sys/compat/linuxkpi/common/include/linux/xarray.h | 26 ++++++++------ sys/compat/linuxkpi/common/src/linux_xarray.c | 41 ++++++++++------------- 2 files changed, 34 insertions(+), 33 deletions(-) diff --git a/sys/compat/linuxkpi/common/include/linux/xarray.h b/sys/compat/linuxkpi/common/include/linux/xarray.h index fba36eea0ab5..e6511130d50c 100644 --- a/sys/compat/linuxkpi/common/include/linux/xarray.h +++ b/sys/compat/linuxkpi/common/include/linux/xarray.h @@ -34,9 +34,6 @@ #include #include -#define XA_LIMIT(min, max) \ - ({ CTASSERT((min) == 0); (uint32_t)(max); }) - #define XA_FLAGS_ALLOC (1U << 0) #define XA_FLAGS_LOCK_IRQ (1U << 1) #define XA_FLAGS_ALLOC1 (1U << 2) @@ -47,8 +44,6 @@ #define xa_is_err(x) \ IS_ERR(x) -#define xa_limit_32b XA_LIMIT(0, 0xFFFFFFFF) - #define XA_ASSERT_LOCKED(xa) mtx_assert(&(xa)->xa_lock, MA_OWNED) #define xa_lock(xa) mtx_lock(&(xa)->xa_lock) #define xa_unlock(xa) mtx_unlock(&(xa)->xa_lock) @@ -59,15 +54,26 @@ struct xarray { uint32_t xa_flags; /* see XA_FLAGS_XXX */ }; +struct xa_limit { + uint32_t max; + uint32_t min; +}; + +#define XA_LIMIT(min_, max_) (struct xa_limit){ .min = (min_), .max = (max_) } + +#define xa_limit_16b XA_LIMIT(0, USHRT_MAX) +#define xa_limit_31b XA_LIMIT(0, INT_MAX) +#define xa_limit_32b XA_LIMIT(0, UINT_MAX) + /* * Extensible arrays API implemented as a wrapper * around the radix tree implementation. */ void *xa_erase(struct xarray *, uint32_t); void *xa_load(struct xarray *, uint32_t); -int xa_alloc(struct xarray *, uint32_t *, void *, uint32_t, gfp_t); -int xa_alloc_cyclic(struct xarray *, uint32_t *, void *, uint32_t, uint32_t *, gfp_t); -int xa_alloc_cyclic_irq(struct xarray *, uint32_t *, void *, uint32_t, uint32_t *, gfp_t); +int xa_alloc(struct xarray *, uint32_t *, void *, struct xa_limit, gfp_t); +int xa_alloc_cyclic(struct xarray *, uint32_t *, void *, struct xa_limit, uint32_t *, gfp_t); +int xa_alloc_cyclic_irq(struct xarray *, uint32_t *, void *, struct xa_limit, uint32_t *, gfp_t); int xa_insert(struct xarray *, uint32_t, void *, gfp_t); void *xa_store(struct xarray *, uint32_t, void *, gfp_t); void xa_init_flags(struct xarray *, uint32_t); @@ -83,8 +89,8 @@ void *xa_next(struct xarray *, unsigned long *, bool); * Unlocked version of functions above. */ void *__xa_erase(struct xarray *, uint32_t); -int __xa_alloc(struct xarray *, uint32_t *, void *, uint32_t, gfp_t); -int __xa_alloc_cyclic(struct xarray *, uint32_t *, void *, uint32_t, uint32_t *, gfp_t); +int __xa_alloc(struct xarray *, uint32_t *, void *, struct xa_limit, gfp_t); +int __xa_alloc_cyclic(struct xarray *, uint32_t *, void *, struct xa_limit, uint32_t *, gfp_t); int __xa_insert(struct xarray *, uint32_t, void *, gfp_t); void *__xa_store(struct xarray *, uint32_t, void *, gfp_t); bool __xa_empty(struct xarray *); diff --git a/sys/compat/linuxkpi/common/src/linux_xarray.c b/sys/compat/linuxkpi/common/src/linux_xarray.c index 8caefbaf7e50..4a305f8d58b6 100644 --- a/sys/compat/linuxkpi/common/src/linux_xarray.c +++ b/sys/compat/linuxkpi/common/src/linux_xarray.c @@ -115,19 +115,16 @@ xa_vm_wait_locked(struct xarray *xa) * available to complete the radix tree insertion. */ int -__xa_alloc(struct xarray *xa, uint32_t *pindex, void *ptr, uint32_t mask, gfp_t gfp) +__xa_alloc(struct xarray *xa, uint32_t *pindex, void *ptr, struct xa_limit limit, gfp_t gfp) { int retval; XA_ASSERT_LOCKED(xa); - /* mask should allow to allocate at least one item */ - MPASS(mask > ((xa->xa_flags & XA_FLAGS_ALLOC1) != 0 ? 1 : 0)); - - /* mask can be any power of two value minus one */ - MPASS((mask & (mask + 1)) == 0); + MPASS(limit.max > limit.min); *pindex = (xa->xa_flags & XA_FLAGS_ALLOC1) != 0 ? 1 : 0; + *pindex = MAX(*pindex, limit.min); if (ptr == NULL) ptr = NULL_VALUE; retry: @@ -135,7 +132,7 @@ retry: switch (retval) { case -EEXIST: - if (likely(*pindex != mask)) { + if (likely(*pindex < limit.max)) { (*pindex)++; goto retry; } @@ -154,7 +151,7 @@ retry: } int -xa_alloc(struct xarray *xa, uint32_t *pindex, void *ptr, uint32_t mask, gfp_t gfp) +xa_alloc(struct xarray *xa, uint32_t *pindex, void *ptr, struct xa_limit limit, gfp_t gfp) { int retval; @@ -162,7 +159,7 @@ xa_alloc(struct xarray *xa, uint32_t *pindex, void *ptr, uint32_t mask, gfp_t gf ptr = NULL_VALUE; xa_lock(xa); - retval = __xa_alloc(xa, pindex, ptr, mask, gfp); + retval = __xa_alloc(xa, pindex, ptr, limit, gfp); xa_unlock(xa); return (retval); @@ -175,7 +172,7 @@ xa_alloc(struct xarray *xa, uint32_t *pindex, void *ptr, uint32_t mask, gfp_t gf * beginning of the array. If the xarray is full -ENOMEM is returned. */ int -__xa_alloc_cyclic(struct xarray *xa, uint32_t *pindex, void *ptr, uint32_t mask, +__xa_alloc_cyclic(struct xarray *xa, uint32_t *pindex, void *ptr, struct xa_limit limit, uint32_t *pnext_index, gfp_t gfp) { int retval; @@ -183,13 +180,10 @@ __xa_alloc_cyclic(struct xarray *xa, uint32_t *pindex, void *ptr, uint32_t mask, XA_ASSERT_LOCKED(xa); - /* mask should allow to allocate at least one item */ - MPASS(mask > ((xa->xa_flags & XA_FLAGS_ALLOC1) != 0 ? 1 : 0)); - - /* mask can be any power of two value minus one */ - MPASS((mask & (mask + 1)) == 0); + MPASS(limit.max > limit.min); *pnext_index = (xa->xa_flags & XA_FLAGS_ALLOC1) != 0 ? 1 : 0; + *pnext_index = MAX(*pnext_index, limit.min); if (ptr == NULL) ptr = NULL_VALUE; retry: @@ -197,14 +191,15 @@ retry: switch (retval) { case -EEXIST: - if (unlikely(*pnext_index == mask) && !timeout--) { + if (unlikely(*pnext_index == limit.max) && !timeout--) { retval = -ENOMEM; break; } (*pnext_index)++; - (*pnext_index) &= mask; - if (*pnext_index == 0 && (xa->xa_flags & XA_FLAGS_ALLOC1) != 0) - (*pnext_index)++; + if (*pnext_index > limit.max) { + *pnext_index = (xa->xa_flags & XA_FLAGS_ALLOC1) != 0 ? 1 : 0; + *pnext_index = MAX(*pnext_index, limit.min); + } goto retry; case -ENOMEM: if (likely(gfp & M_WAITOK)) { @@ -221,13 +216,13 @@ retry: } int -xa_alloc_cyclic(struct xarray *xa, uint32_t *pindex, void *ptr, uint32_t mask, +xa_alloc_cyclic(struct xarray *xa, uint32_t *pindex, void *ptr, struct xa_limit limit, uint32_t *pnext_index, gfp_t gfp) { int retval; xa_lock(xa); - retval = __xa_alloc_cyclic(xa, pindex, ptr, mask, pnext_index, gfp); + retval = __xa_alloc_cyclic(xa, pindex, ptr, limit, pnext_index, gfp); xa_unlock(xa); return (retval); @@ -235,12 +230,12 @@ xa_alloc_cyclic(struct xarray *xa, uint32_t *pindex, void *ptr, uint32_t mask, int xa_alloc_cyclic_irq(struct xarray *xa, uint32_t *pindex, void *ptr, - uint32_t mask, uint32_t *pnext_index, gfp_t gfp) + struct xa_limit limit, uint32_t *pnext_index, gfp_t gfp) { int retval; xa_lock_irq(xa); - retval = __xa_alloc_cyclic(xa, pindex, ptr, mask, pnext_index, gfp); + retval = __xa_alloc_cyclic(xa, pindex, ptr, limit, pnext_index, gfp); xa_unlock_irq(xa); return (retval);