From nobody Thu Feb 16 11:56:33 2023 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 4PHYM62r7Hz3q5hD; Thu, 16 Feb 2023 11:56:34 +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 4PHYM61cvnz4BHx; Thu, 16 Feb 2023 11:56:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676548594; 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=rYQR+E8BrZx5ecV82eo6u1PymT1tmh01tZ6bekcyxH0=; b=TC9bY2ZFbFqBvmazUOsoGftv/qQIRLqDev4KCuDuNHfkGPyynYHJv7nYNxxQdEt4BedHEC Be8NMJ4XHCNn+fuWb0+dKcI+jOuPJ+0cSC2cjxwTwtbyzq6cqWUEvO69BuUPUg/kVX10Wy ziwkYdbHBaX8HSfBgu4wP7D+TgdGhtBP0b6kg2zHaIm1BeZWnBV4WjL9km/FVe8WFbywrI eRq5S4qiitub7xKNwSgwM7AiaSo4CWg31mNnFEXBeEi8lCO0XxQMHiUu6lEDPnnho6Zrwd yaG6uVdJ3OADKZ/2rq3QtdiRHaEIK7zTdv563FrRhbKrBbNdDhpkwJE56OMX2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1676548594; 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=rYQR+E8BrZx5ecV82eo6u1PymT1tmh01tZ6bekcyxH0=; b=q4fmmitIffsipadmy+9j16pDvJYj+zlKxH5kmeAYGx7oI6E/r3KwibqlAk+eKNGrdaq28g US9HrY2ArAzzTJXon/zY3qMAC4UIEK8zeY0BSNNW8EdVS/80Tcuf1ydwPUYaoJHoWEAbJ1 dHEwEPPi/RXl/p4ftKCRIft17JvswKxfG2ZMDVsxuRhW0tmyTNUiUG0wWnmGu2+QwUhNbv Pz90KAirBm4F2y89q3ZBZPzg0s4oqlprOKmZ1/FqH5+bEma+GJrV6B6FomJG5FfAELxv+r GfIdZC5ygQuiTLrqnQEBZJpSIfw9lDCDE2JqcxdHa1eQR9iJAKC2hWKerNQdOA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1676548594; a=rsa-sha256; cv=none; b=JFSz4a1d39omYoBJQGEWbly5ozQoN+PH81esuVrQ6P9gni7UezCdOk7u7oAE47tx2WMqQ5 OMnVcEljQSaEWdjeuz66gCE0s/qh3PYSC1ihwnqqIVd3KlramvgOFRY5mbr6GBGRW0Ikv8 kcJOHPjxxNyCgT/ehi2dVX0Vucl6KOV+/jyQvKcKFFigbkHbDphbC6wVQE6r24OdkaxZao MYuPhNt/VNuH0y07jS7gnUfNiXGFWt8IIFPQZpSbtAeUjOa9dX2xvNmUgQhRxapX77VzFn f1/9UD6M/nCDo7yd1GRNG3W6A2kmrGfQ0xqtt+o9j9iLdtjlU1TA3vUMMijXgA== 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 4PHYM60k1Bz12fZ; Thu, 16 Feb 2023 11:56:34 +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 31GBuYW0056367; Thu, 16 Feb 2023 11:56:34 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 31GBuXXo056366; Thu, 16 Feb 2023 11:56:33 GMT (envelope-from git) Date: Thu, 16 Feb 2023 11:56:33 GMT Message-Id: <202302161156.31GBuXXo056366@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: =?utf-8?Q?Jean-S=C3=A9bastien=20P=C3=A9dron?= Subject: git: 895d286a36cf - stable/13 - linuxkpi: Accept NULL as a value in `linux_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: 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: dumbbell X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 895d286a36cf70fa527538ca3c9a1a545f81a9cd Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by dumbbell (ports committer): URL: https://cgit.FreeBSD.org/src/commit/?id=895d286a36cf70fa527538ca3c9a1a545f81a9cd commit 895d286a36cf70fa527538ca3c9a1a545f81a9cd Author: Jean-Sébastien Pédron AuthorDate: 2023-02-11 10:12:08 +0000 Commit: Jean-Sébastien Pédron CommitDate: 2023-02-16 11:55:20 +0000 linuxkpi: Accept NULL as a value in `linux_xarray` Linux' XArray allows to store a NULL pointer as a value. `xa_load()` would return NULL for both an unused index and an index set to NULL. But it impacts `xa_alloc()` which needs to find the next available index. However, our implementation relies on a radix tree (see `linux_radix.c`) which does not accept NULL pointers as values. I'm not sure if this is a limitation or a feature, so to work around this, a NULL value is replaced by `NULL_VALUE`, an unlikely address, when we pass it to linux_radix. Reviewed by: emaste, manu Approved by: emaste, manu Differential Revision: https://reviews.freebsd.org/D38543 (cherry picked from commit 3102ea3b15b6c3ed1ea50716d65980b680375ebc) --- sys/compat/linuxkpi/common/src/linux_xarray.c | 38 ++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/sys/compat/linuxkpi/common/src/linux_xarray.c b/sys/compat/linuxkpi/common/src/linux_xarray.c index a41784103852..e8a107fa6f27 100644 --- a/sys/compat/linuxkpi/common/src/linux_xarray.c +++ b/sys/compat/linuxkpi/common/src/linux_xarray.c @@ -31,6 +31,18 @@ __FBSDID("$FreeBSD$"); #include +/* + * Linux' XArray allows to store a NULL pointer as a value. xa_load() would + * return NULL for both an unused index and an index set to NULL. But it + * impacts xa_alloc() which needs to find the next available index. + * + * However, our implementation relies on a radix tree (see `linux_radix.c`) + * which does not accept NULL pointers as values. I'm not sure this is a + * limitation or a feature, so to work around this, a NULL value is replaced by + * `NULL_VALUE`, an unlikely address, when we pass it to linux_radix. + */ +#define NULL_VALUE (void *)0x1 + /* * This function removes the element at the given index and returns * the pointer to the removed element, if any. @@ -38,9 +50,15 @@ __FBSDID("$FreeBSD$"); void * __xa_erase(struct xarray *xa, uint32_t index) { + void *retval; + XA_ASSERT_LOCKED(xa); - return (radix_tree_delete(&xa->root, index)); + retval = radix_tree_delete(&xa->root, index); + if (retval == NULL_VALUE) + retval = NULL; + + return (retval); } void * @@ -68,6 +86,9 @@ xa_load(struct xarray *xa, uint32_t index) retval = radix_tree_lookup(&xa->root, index); xa_unlock(xa); + if (retval == NULL_VALUE) + retval = NULL; + return (retval); } @@ -109,6 +130,8 @@ __xa_alloc(struct xarray *xa, uint32_t *pindex, void *ptr, uint32_t mask, gfp_t MPASS((mask & (mask + 1)) == 0); *pindex = (xa->flags & XA_FLAGS_ALLOC1) != 0 ? 1 : 0; + if (ptr == NULL) + ptr = NULL_VALUE; retry: retval = radix_tree_insert(&xa->root, *pindex, ptr); @@ -137,6 +160,9 @@ xa_alloc(struct xarray *xa, uint32_t *pindex, void *ptr, uint32_t mask, gfp_t gf { int retval; + if (ptr == NULL) + ptr = NULL_VALUE; + xa_lock(xa); retval = __xa_alloc(xa, pindex, ptr, mask, gfp); xa_unlock(xa); @@ -166,6 +192,8 @@ __xa_alloc_cyclic(struct xarray *xa, uint32_t *pindex, void *ptr, uint32_t mask, MPASS((mask & (mask + 1)) == 0); *pnext_index = (xa->flags & XA_FLAGS_ALLOC1) != 0 ? 1 : 0; + if (ptr == NULL) + ptr = NULL_VALUE; retry: retval = radix_tree_insert(&xa->root, *pnext_index, ptr); @@ -220,6 +248,8 @@ __xa_insert(struct xarray *xa, uint32_t index, void *ptr, gfp_t gfp) int retval; XA_ASSERT_LOCKED(xa); + if (ptr == NULL) + ptr = NULL_VALUE; retry: retval = radix_tree_insert(&xa->root, index, ptr); @@ -262,11 +292,15 @@ __xa_store(struct xarray *xa, uint32_t index, void *ptr, gfp_t gfp) int retval; XA_ASSERT_LOCKED(xa); + if (ptr == NULL) + ptr = NULL_VALUE; retry: retval = radix_tree_store(&xa->root, index, &ptr); switch (retval) { case 0: + if (ptr == NULL_VALUE) + ptr = NULL; break; case -ENOMEM: if (likely(gfp & M_WAITOK)) { @@ -374,6 +408,8 @@ __xa_next(struct xarray *xa, unsigned long *pindex, bool not_first) found = radix_tree_iter_find(&xa->root, &iter, &ppslot); if (likely(found)) { retval = *ppslot; + if (retval == NULL_VALUE) + retval = NULL; *pindex = iter.index; } else { retval = NULL;