Page MenuHomeFreeBSD

D56445.diff
No OneTemporary

D56445.diff

Index: sys/compat/linuxkpi/common/include/linux/xarray.h
===================================================================
--- sys/compat/linuxkpi/common/include/linux/xarray.h
+++ sys/compat/linuxkpi/common/include/linux/xarray.h
@@ -34,9 +34,6 @@
#include <sys/lock.h>
#include <sys/mutex.h>
-#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 @@
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 @@
* 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 *);
Index: sys/compat/linuxkpi/common/src/linux_xarray.c
===================================================================
--- sys/compat/linuxkpi/common/src/linux_xarray.c
+++ sys/compat/linuxkpi/common/src/linux_xarray.c
@@ -115,19 +115,16 @@
* 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 @@
switch (retval) {
case -EEXIST:
- if (likely(*pindex != mask)) {
+ if (likely(*pindex < limit.max)) {
(*pindex)++;
goto retry;
}
@@ -154,7 +151,7 @@
}
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 @@
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 @@
* 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_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 @@
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 @@
}
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 @@
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);

File Metadata

Mime Type
text/plain
Expires
Mon, Apr 20, 3:13 PM (10 h, 43 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
31847512
Default Alt Text
D56445.diff (6 KB)

Event Timeline