mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
linuxu: an ALLOC1 xarray never hands out index 0
xa_alloc ignored XA_FLAGS_ALLOC1, so the first DRM syncobj of every render-node file got handle 0, which userspace and upstream read as "no syncobj". Linux keeps index 0 busy in such an array; the shim now starts its search at 1. DEFINE_XARRAY_ALLOC also defined an ALLOC1 array, unlike upstream (where ALLOC counts from 0 and ALLOC1 from 1); DRM's minors use it and would have moved to card1. test_xarray_limit checks both kinds.
This commit is contained in:
1 parent
02920eb7ab
commit
b4d1555088
3 files changed
+24
-2
No files matched your search
@@ -203,7 +203,7 @@ static inline void xa_init_flags(struct xarray *xa, unsigned long flags)
|
||||
#define XARRAY_FLAGS(name, mask) struct xarray name = XARRAY_INIT(name, mask)
|
||||
|
||||
/*
|
||||
* DEFINE_XARRAY_FLAGS / DEFINE_XARRAY / DEFINE_XARRAY_ALLOC - vendor
|
||||
* DEFINE_XARRAY_FLAGS / DEFINE_XARRAY / DEFINE_XARRAY_ALLOC(1) - vendor
|
||||
* 2026 definitions (amdgpu_ids.c: DEFINE_XARRAY_FLAGS(amdgpu_pasid_xa,
|
||||
* XA_FLAGS_LOCK_IRQ | XA_FLAGS_ALLOC1)).
|
||||
*/
|
||||
@@ -211,7 +211,9 @@ static inline void xa_init_flags(struct xarray *xa, unsigned long flags)
|
||||
struct xarray name = { .xa_flags = (flags) }
|
||||
|
||||
#define DEFINE_XARRAY(name) DEFINE_XARRAY_FLAGS(name, 0)
|
||||
#define DEFINE_XARRAY_ALLOC(name) DEFINE_XARRAY_FLAGS(name, XA_FLAGS_ALLOC1)
|
||||
/* As upstream: ALLOC hands out indices from 0, ALLOC1 from 1. */
|
||||
#define DEFINE_XARRAY_ALLOC(name) DEFINE_XARRAY_FLAGS(name, XA_FLAGS_ALLOC)
|
||||
#define DEFINE_XARRAY_ALLOC1(name) DEFINE_XARRAY_FLAGS(name, XA_FLAGS_ALLOC1)
|
||||
|
||||
/*
|
||||
* struct xa_limit (vendor 2026, verbatim) + the limit-taking alloc
|
||||
|
||||
@@ -304,6 +304,10 @@ unsigned long xa_count(struct xarray *xa, unsigned long index, unsigned long max
|
||||
static int xa_alloc_locked(struct xarray *xa, unsigned long *indexp, void *entry,
|
||||
unsigned long start, unsigned long max, gfp_t gfp)
|
||||
{
|
||||
/* An XA_FLAGS_ALLOC1 array never hands out index 0 (Linux keeps it
|
||||
* busy from xa_init_flags): DRM syncobj handles, among others, are
|
||||
* nonzero, and 0 means "none" to their users. */
|
||||
if ((xa->xa_flags & XA_FLAGS_ALLOC1) && start == 0) start = 1;
|
||||
if (start > max) return -ENOSPC;
|
||||
unsigned long index = start;
|
||||
while (xa_load_locked(xa, index)) {
|
||||
|
||||
@@ -40,5 +40,21 @@ int main(void)
|
||||
assert(xa_alloc_limit(&xa, &result.id, NULL,
|
||||
XA_LIMIT(3, 2), 0) == -EINVAL);
|
||||
assert(xa_destroy(&xa) == 0);
|
||||
|
||||
/* XA_FLAGS_ALLOC1 (DRM syncobj handles): index 0 is never handed
|
||||
* out, by the limit or the cyclic form. */
|
||||
DEFINE_XARRAY_ALLOC1(one);
|
||||
u32 id = 99, next = 0;
|
||||
assert(xa_alloc_limit(&one, &id, (void *)0x1000, XA_LIMIT(0, 0xffffffffu), 0) == 0 && id == 1);
|
||||
assert(xa_alloc_limit(&one, &id, (void *)0x2000, XA_LIMIT(0, 0xffffffffu), 0) == 0 && id == 2);
|
||||
assert(xa_alloc_cyclic_limit(&one, &id, (void *)0x3000, XA_LIMIT(0, 7), &next, 0) == 0 &&
|
||||
id == 3);
|
||||
assert(xa_load(&one, 0) == NULL);
|
||||
assert(xa_alloc_limit(&one, &id, (void *)0x4000, XA_LIMIT(0, 0), 0) == -EBUSY);
|
||||
assert(xa_destroy(&one) == 0);
|
||||
/* DEFINE_XARRAY_ALLOC (DRM minors) starts at 0. */
|
||||
DEFINE_XARRAY_ALLOC(zero);
|
||||
assert(xa_alloc_limit(&zero, &id, (void *)0x1000, XA_LIMIT(0, 63), 0) == 0 && id == 0);
|
||||
assert(xa_destroy(&zero) == 0);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user