Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0+
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  * test_xarray.c: Test the XArray API
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Copyright (c) 2017-2018 Microsoft Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  * Copyright (c) 2019-2020 Oracle
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  * Author: Matthew Wilcox <willy@infradead.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) #include <linux/xarray.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) static unsigned int tests_run;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) static unsigned int tests_passed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) static const unsigned int order_limit =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) 		IS_ENABLED(CONFIG_XARRAY_MULTI) ? BITS_PER_LONG : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #ifndef XA_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) # ifdef __KERNEL__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) void xa_dump(const struct xarray *xa) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) # endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #undef XA_BUG_ON
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #define XA_BUG_ON(xa, x) do {					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 	tests_run++;						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) 	if (x) {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 		printk("BUG at %s:%d\n", __func__, __LINE__);	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 		xa_dump(xa);					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 		dump_stack();					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 	} else {						\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 		tests_passed++;					\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 	}							\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) static void *xa_mk_index(unsigned long index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 	return xa_mk_value(index & LONG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) static void *xa_store_index(struct xarray *xa, unsigned long index, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) 	return xa_store(xa, index, xa_mk_index(index), gfp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) static void xa_insert_index(struct xarray *xa, unsigned long index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 	XA_BUG_ON(xa, xa_insert(xa, index, xa_mk_index(index),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 				GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) static void xa_alloc_index(struct xarray *xa, unsigned long index, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 	u32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 	XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(index), xa_limit_32b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) 				gfp) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) 	XA_BUG_ON(xa, id != index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) static void xa_erase_index(struct xarray *xa, unsigned long index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) 	XA_BUG_ON(xa, xa_erase(xa, index) != xa_mk_index(index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	XA_BUG_ON(xa, xa_load(xa, index) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67)  * If anyone needs this, please move it to xarray.c.  We have no current
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68)  * users outside the test suite because all current multislot users want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69)  * to use the advanced API.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) static void *xa_store_order(struct xarray *xa, unsigned long index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 		unsigned order, void *entry, gfp_t gfp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) 	XA_STATE_ORDER(xas, xa, index, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	void *curr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) 		xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 		curr = xas_store(&xas, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 		xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	} while (xas_nomem(&xas, gfp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	return curr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) static noinline void check_xa_err(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	XA_BUG_ON(xa, xa_err(xa_store_index(xa, 0, GFP_NOWAIT)) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	XA_BUG_ON(xa, xa_err(xa_erase(xa, 0)) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) #ifndef __KERNEL__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 	/* The kernel does not fail GFP_NOWAIT allocations */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	XA_BUG_ON(xa, xa_err(xa_store_index(xa, 1, GFP_NOWAIT)) != -ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) 	XA_BUG_ON(xa, xa_err(xa_store_index(xa, 1, GFP_NOWAIT)) != -ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) 	XA_BUG_ON(xa, xa_err(xa_store_index(xa, 1, GFP_KERNEL)) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) 	XA_BUG_ON(xa, xa_err(xa_store(xa, 1, xa_mk_value(0), GFP_KERNEL)) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	XA_BUG_ON(xa, xa_err(xa_erase(xa, 1)) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) // kills the test-suite :-(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) //	XA_BUG_ON(xa, xa_err(xa_store(xa, 0, xa_mk_internal(0), 0)) != -EINVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) static noinline void check_xas_retry(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	XA_STATE(xas, xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	xa_store_index(xa, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 	xa_store_index(xa, 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 	XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != xa_mk_value(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 	xa_erase_index(xa, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 	XA_BUG_ON(xa, !xa_is_retry(xas_reload(&xas)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 	XA_BUG_ON(xa, xas_retry(&xas, NULL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	XA_BUG_ON(xa, xas_retry(&xas, xa_mk_value(0)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	xas_reset(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 	XA_BUG_ON(xa, xas.xa_node != XAS_RESTART);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 	XA_BUG_ON(xa, xas_next_entry(&xas, ULONG_MAX) != xa_mk_value(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 	XA_BUG_ON(xa, xas.xa_node != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 	XA_BUG_ON(xa, xa_store_index(xa, 1, GFP_KERNEL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 	XA_BUG_ON(xa, !xa_is_internal(xas_reload(&xas)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 	xas.xa_node = XAS_RESTART;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	XA_BUG_ON(xa, xas_next_entry(&xas, ULONG_MAX) != xa_mk_value(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	/* Make sure we can iterate through retry entries */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 	xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 	xas_set(&xas, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 	xas_store(&xas, XA_RETRY_ENTRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 	xas_set(&xas, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 	xas_store(&xas, XA_RETRY_ENTRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 	xas_set(&xas, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 	xas_for_each(&xas, entry, ULONG_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 		xas_store(&xas, xa_mk_index(xas.xa_index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 	xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 	xa_erase_index(xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	xa_erase_index(xa, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) static noinline void check_xa_load(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	unsigned long i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 	for (i = 0; i < 1024; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 		for (j = 0; j < 1024; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 			void *entry = xa_load(xa, j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 			if (j < i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 				XA_BUG_ON(xa, xa_to_value(entry) != j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 				XA_BUG_ON(xa, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 		XA_BUG_ON(xa, xa_store_index(xa, i, GFP_KERNEL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	for (i = 0; i < 1024; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 		for (j = 0; j < 1024; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 			void *entry = xa_load(xa, j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 			if (j >= i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 				XA_BUG_ON(xa, xa_to_value(entry) != j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) 				XA_BUG_ON(xa, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) 		xa_erase_index(xa, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) static noinline void check_xa_mark_1(struct xarray *xa, unsigned long index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	unsigned int order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 8 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	/* NULL elements have no marks set */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	xa_set_mark(xa, index, XA_MARK_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	/* Storing a pointer will not make a mark appear */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	XA_BUG_ON(xa, xa_store_index(xa, index, GFP_KERNEL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	xa_set_mark(xa, index, XA_MARK_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	XA_BUG_ON(xa, !xa_get_mark(xa, index, XA_MARK_0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	/* Setting one mark will not set another mark */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	XA_BUG_ON(xa, xa_get_mark(xa, index + 1, XA_MARK_0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 	XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 	/* Storing NULL clears marks, and they can't be set again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	xa_erase_index(xa, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	xa_set_mark(xa, index, XA_MARK_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	 * Storing a multi-index entry over entries with marks gives the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	 * entire entry the union of the marks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	BUG_ON((index % 4) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	for (order = 2; order < max_order; order++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 		unsigned long base = round_down(index, 1UL << order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 		unsigned long next = base + (1UL << order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 		unsigned long i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 		XA_BUG_ON(xa, xa_store_index(xa, index + 1, GFP_KERNEL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) 		xa_set_mark(xa, index + 1, XA_MARK_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 		XA_BUG_ON(xa, xa_store_index(xa, index + 2, GFP_KERNEL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 		xa_set_mark(xa, index + 2, XA_MARK_2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 		XA_BUG_ON(xa, xa_store_index(xa, next, GFP_KERNEL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 		xa_store_order(xa, index, order, xa_mk_index(index),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 				GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 		for (i = base; i < next; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 			XA_STATE(xas, xa, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 			unsigned int seen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 			void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 			XA_BUG_ON(xa, !xa_get_mark(xa, i, XA_MARK_0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 			XA_BUG_ON(xa, xa_get_mark(xa, i, XA_MARK_1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 			XA_BUG_ON(xa, !xa_get_mark(xa, i, XA_MARK_2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 			/* We should see two elements in the array */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 			rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 			xas_for_each(&xas, entry, ULONG_MAX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 				seen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 			XA_BUG_ON(xa, seen != 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 			/* One of which is marked */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 			xas_set(&xas, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 			seen = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 			rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 			xas_for_each_marked(&xas, entry, ULONG_MAX, XA_MARK_0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 				seen++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 			XA_BUG_ON(xa, seen != 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 		XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 		XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 		XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 		xa_erase_index(xa, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 		xa_erase_index(xa, next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) 		XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254) static noinline void check_xa_mark_2(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256) 	XA_STATE(xas, xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257) 	unsigned long index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258) 	unsigned int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	xa_store_index(xa, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 	xa_set_mark(xa, 0, XA_MARK_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	xas_load(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	xas_init_marks(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	XA_BUG_ON(xa, !xa_get_mark(xa, 0, XA_MARK_0) == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 	for (index = 3500; index < 4500; index++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 		xa_store_index(xa, index, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 		xa_set_mark(xa, index, XA_MARK_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 	xas_reset(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	xas_for_each_marked(&xas, entry, ULONG_MAX, XA_MARK_0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 		count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	XA_BUG_ON(xa, count != 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	xas_for_each(&xas, entry, ULONG_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 		xas_init_marks(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 		XA_BUG_ON(xa, !xa_get_mark(xa, xas.xa_index, XA_MARK_0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 		XA_BUG_ON(xa, !xas_get_mark(&xas, XA_MARK_0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) static noinline void check_xa_mark_3(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) #ifdef CONFIG_XARRAY_MULTI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 	XA_STATE(xas, xa, 0x41);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 	int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 	xa_store_order(xa, 0x40, 2, xa_mk_index(0x40), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	xa_set_mark(xa, 0x41, XA_MARK_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	xas_for_each_marked(&xas, entry, ULONG_MAX, XA_MARK_0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 		count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		XA_BUG_ON(xa, entry != xa_mk_index(0x40));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 	XA_BUG_ON(xa, count != 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) static noinline void check_xa_mark(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	unsigned long index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	for (index = 0; index < 16384; index += 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		check_xa_mark_1(xa, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 	check_xa_mark_2(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 	check_xa_mark_3(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) static noinline void check_xa_shrink(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 	XA_STATE(xas, xa, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 	struct xa_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 	unsigned int order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 15 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	XA_BUG_ON(xa, xa_store_index(xa, 0, GFP_KERNEL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 	XA_BUG_ON(xa, xa_store_index(xa, 1, GFP_KERNEL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	 * Check that erasing the entry at 1 shrinks the tree and properly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 	 * marks the node as being deleted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 	xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	XA_BUG_ON(xa, xas_load(&xas) != xa_mk_value(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	node = xas.xa_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	XA_BUG_ON(xa, xa_entry_locked(xa, node, 0) != xa_mk_value(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	XA_BUG_ON(xa, xas_store(&xas, NULL) != xa_mk_value(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	XA_BUG_ON(xa, xa_load(xa, 1) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	XA_BUG_ON(xa, xas.xa_node != XAS_BOUNDS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	XA_BUG_ON(xa, xa_entry_locked(xa, node, 0) != XA_RETRY_ENTRY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	XA_BUG_ON(xa, xas_load(&xas) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	XA_BUG_ON(xa, xa_load(xa, 0) != xa_mk_value(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	xa_erase_index(xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 	for (order = 0; order < max_order; order++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 		unsigned long max = (1UL << order) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 		xa_store_order(xa, 0, order, xa_mk_value(0), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 		XA_BUG_ON(xa, xa_load(xa, max) != xa_mk_value(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 		XA_BUG_ON(xa, xa_load(xa, max + 1) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 		node = xa_head(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		XA_BUG_ON(xa, xa_store_index(xa, ULONG_MAX, GFP_KERNEL) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 				NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 		XA_BUG_ON(xa, xa_head(xa) == node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 		XA_BUG_ON(xa, xa_load(xa, max + 1) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 		xa_erase_index(xa, ULONG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 		XA_BUG_ON(xa, xa->xa_head != node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 		xa_erase_index(xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) static noinline void check_insert(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	unsigned long i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	for (i = 0; i < 1024; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 		xa_insert_index(xa, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 		XA_BUG_ON(xa, xa_load(xa, i - 1) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 		XA_BUG_ON(xa, xa_load(xa, i + 1) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 		xa_erase_index(xa, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	for (i = 10; i < BITS_PER_LONG; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 		xa_insert_index(xa, 1UL << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 		XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 1) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 		XA_BUG_ON(xa, xa_load(xa, (1UL << i) + 1) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 		xa_erase_index(xa, 1UL << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 		xa_insert_index(xa, (1UL << i) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 		XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 2) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 		XA_BUG_ON(xa, xa_load(xa, 1UL << i) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 		xa_erase_index(xa, (1UL << i) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	xa_insert_index(xa, ~0UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	XA_BUG_ON(xa, xa_load(xa, 0UL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	XA_BUG_ON(xa, xa_load(xa, ~1UL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	xa_erase_index(xa, ~0UL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) static noinline void check_cmpxchg(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	void *FIVE = xa_mk_value(5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 	void *SIX = xa_mk_value(6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	void *LOTS = xa_mk_value(12345678);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_KERNEL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 	XA_BUG_ON(xa, xa_insert(xa, 12345678, xa, GFP_KERNEL) != -EBUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, SIX, FIVE, GFP_KERNEL) != LOTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, LOTS, FIVE, GFP_KERNEL) != LOTS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 	XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, FIVE, LOTS, GFP_KERNEL) != FIVE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 	XA_BUG_ON(xa, xa_cmpxchg(xa, 5, FIVE, NULL, GFP_KERNEL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 	XA_BUG_ON(xa, xa_cmpxchg(xa, 5, NULL, FIVE, GFP_KERNEL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	XA_BUG_ON(xa, xa_insert(xa, 5, FIVE, GFP_KERNEL) != -EBUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 	XA_BUG_ON(xa, xa_cmpxchg(xa, 5, FIVE, NULL, GFP_KERNEL) != FIVE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 	XA_BUG_ON(xa, xa_insert(xa, 5, FIVE, GFP_KERNEL) == -EBUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	xa_erase_index(xa, 12345678);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 	xa_erase_index(xa, 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) static noinline void check_reserve(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) 	unsigned long index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) 	int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	/* An array with a reserved entry is not empty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 	XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	XA_BUG_ON(xa, xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 	XA_BUG_ON(xa, xa_load(xa, 12345678));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	xa_release(xa, 12345678);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	/* Releasing a used entry does nothing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_NOWAIT) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 	xa_release(xa, 12345678);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 	xa_erase_index(xa, 12345678);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 	/* cmpxchg sees a reserved entry as ZERO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 	XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, XA_ZERO_ENTRY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 				xa_mk_value(12345678), GFP_NOWAIT) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 	xa_release(xa, 12345678);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	xa_erase_index(xa, 12345678);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	/* xa_insert treats it as busy */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) 	XA_BUG_ON(xa, xa_insert(xa, 12345678, xa_mk_value(12345678), 0) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 			-EBUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) 	XA_BUG_ON(xa, xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) 	XA_BUG_ON(xa, xa_erase(xa, 12345678) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	/* Can iterate through a reserved entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	xa_store_index(xa, 5, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 	XA_BUG_ON(xa, xa_reserve(xa, 6, GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	xa_store_index(xa, 7, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	xa_for_each(xa, index, entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		XA_BUG_ON(xa, index != 5 && index != 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 		count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	XA_BUG_ON(xa, count != 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 	/* If we free a reserved entry, we should be able to allocate it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 	if (xa->xa_flags & XA_FLAGS_ALLOC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		u32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 		XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_value(8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 					XA_LIMIT(5, 10), GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		XA_BUG_ON(xa, id != 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 		xa_release(xa, 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 		XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_value(6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 					XA_LIMIT(5, 10), GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) 		XA_BUG_ON(xa, id != 6);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) static noinline void check_xas_erase(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	XA_STATE(xas, xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	unsigned long i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	for (i = 0; i < 200; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		for (j = i; j < 2 * i + 17; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 			xas_set(&xas, j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 			do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 				xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 				xas_store(&xas, xa_mk_index(j));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 				xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 			} while (xas_nomem(&xas, GFP_KERNEL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 		xas_set(&xas, ULONG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 			xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 			xas_store(&xas, xa_mk_value(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 			xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		} while (xas_nomem(&xas, GFP_KERNEL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 		xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 		xas_store(&xas, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 		xas_set(&xas, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 		j = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 		xas_for_each(&xas, entry, ULONG_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 			XA_BUG_ON(xa, entry != xa_mk_index(j));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 			xas_store(&xas, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 			j++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 		xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 		XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) #ifdef CONFIG_XARRAY_MULTI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) static noinline void check_multi_store_1(struct xarray *xa, unsigned long index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 		unsigned int order)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 	XA_STATE(xas, xa, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 	unsigned long min = index & ~((1UL << order) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	unsigned long max = min + (1UL << order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	xa_store_order(xa, index, order, xa_mk_index(index), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	XA_BUG_ON(xa, xa_load(xa, min) != xa_mk_index(index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 	XA_BUG_ON(xa, xa_load(xa, max - 1) != xa_mk_index(index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	XA_BUG_ON(xa, xa_load(xa, max) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	XA_BUG_ON(xa, xas_store(&xas, xa_mk_index(min)) != xa_mk_index(index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 	xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	XA_BUG_ON(xa, xa_load(xa, min) != xa_mk_index(min));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 	XA_BUG_ON(xa, xa_load(xa, max - 1) != xa_mk_index(min));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	XA_BUG_ON(xa, xa_load(xa, max) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 	XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 	xa_erase_index(xa, min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) static noinline void check_multi_store_2(struct xarray *xa, unsigned long index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 		unsigned int order)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	XA_STATE(xas, xa, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	xa_store_order(xa, index, order, xa_mk_value(0), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	XA_BUG_ON(xa, xas_store(&xas, xa_mk_value(1)) != xa_mk_value(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	XA_BUG_ON(xa, xas.xa_index != index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	XA_BUG_ON(xa, xas_store(&xas, NULL) != xa_mk_value(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) static noinline void check_multi_store_3(struct xarray *xa, unsigned long index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 		unsigned int order)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) 	XA_STATE(xas, xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	int n = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	xa_store_order(xa, index, order, xa_mk_index(index), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	xas_for_each(&xas, entry, ULONG_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 		XA_BUG_ON(xa, entry != xa_mk_index(index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 		n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	XA_BUG_ON(xa, n != 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	xas_set(&xas, index + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 	xas_for_each(&xas, entry, ULONG_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 		XA_BUG_ON(xa, entry != xa_mk_index(index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 		n++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 	XA_BUG_ON(xa, n != 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) static noinline void check_multi_store(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) #ifdef CONFIG_XARRAY_MULTI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	unsigned long i, j, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	unsigned int max_order = (sizeof(long) == 4) ? 30 : 60;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	/* Loading from any position returns the same value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	xa_store_order(xa, 0, 1, xa_mk_value(0), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	XA_BUG_ON(xa, xa_load(xa, 0) != xa_mk_value(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	XA_BUG_ON(xa, xa_load(xa, 1) != xa_mk_value(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	XA_BUG_ON(xa, xa_load(xa, 2) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	XA_BUG_ON(xa, xa_to_node(xa_head(xa))->count != 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	XA_BUG_ON(xa, xa_to_node(xa_head(xa))->nr_values != 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	/* Storing adjacent to the value does not alter the value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 	xa_store(xa, 3, xa, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	XA_BUG_ON(xa, xa_load(xa, 0) != xa_mk_value(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	XA_BUG_ON(xa, xa_load(xa, 1) != xa_mk_value(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) 	XA_BUG_ON(xa, xa_load(xa, 2) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) 	XA_BUG_ON(xa, xa_to_node(xa_head(xa))->count != 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) 	XA_BUG_ON(xa, xa_to_node(xa_head(xa))->nr_values != 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 	/* Overwriting multiple indexes works */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	xa_store_order(xa, 0, 2, xa_mk_value(1), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 	XA_BUG_ON(xa, xa_load(xa, 0) != xa_mk_value(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	XA_BUG_ON(xa, xa_load(xa, 1) != xa_mk_value(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	XA_BUG_ON(xa, xa_load(xa, 2) != xa_mk_value(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	XA_BUG_ON(xa, xa_load(xa, 3) != xa_mk_value(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	XA_BUG_ON(xa, xa_load(xa, 4) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	XA_BUG_ON(xa, xa_to_node(xa_head(xa))->count != 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	XA_BUG_ON(xa, xa_to_node(xa_head(xa))->nr_values != 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	/* We can erase multiple values with a single store */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 	xa_store_order(xa, 0, BITS_PER_LONG - 1, NULL, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	/* Even when the first slot is empty but the others aren't */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	xa_store_index(xa, 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	xa_store_index(xa, 2, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	xa_store_order(xa, 0, 2, NULL, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 	for (i = 0; i < max_order; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 		for (j = 0; j < max_order; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 			xa_store_order(xa, 0, i, xa_mk_index(i), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 			xa_store_order(xa, 0, j, xa_mk_index(j), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 			for (k = 0; k < max_order; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 				void *entry = xa_load(xa, (1UL << k) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 				if ((i < k) && (j < k))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 					XA_BUG_ON(xa, entry != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 					XA_BUG_ON(xa, entry != xa_mk_index(j));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 			xa_erase(xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 			XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	for (i = 0; i < 20; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		check_multi_store_1(xa, 200, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 		check_multi_store_1(xa, 0, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 		check_multi_store_1(xa, (1UL << i) + 1, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 	check_multi_store_2(xa, 4095, 9);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	for (i = 1; i < 20; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 		check_multi_store_3(xa, 0, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 		check_multi_store_3(xa, 1UL << i, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) static noinline void check_xa_alloc_1(struct xarray *xa, unsigned int base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 	u32 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	/* An empty array should assign %base to the first alloc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 	xa_alloc_index(xa, base, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 	/* Erasing it should make the array empty again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	xa_erase_index(xa, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 	/* And it should assign %base again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	xa_alloc_index(xa, base, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 	/* Allocating and then erasing a lot should not lose base */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	for (i = base + 1; i < 2 * XA_CHUNK_SIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		xa_alloc_index(xa, i, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	for (i = base; i < 2 * XA_CHUNK_SIZE; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		xa_erase_index(xa, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 	xa_alloc_index(xa, base, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	/* Destroying the array should do the same as erasing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 	/* And it should assign %base again */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 	xa_alloc_index(xa, base, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	/* The next assigned ID should be base+1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 	xa_alloc_index(xa, base + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	xa_erase_index(xa, base + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	/* Storing a value should mark it used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	xa_store_index(xa, base + 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	xa_alloc_index(xa, base + 2, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	/* If we then erase base, it should be free */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	xa_erase_index(xa, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	xa_alloc_index(xa, base, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 	xa_erase_index(xa, base + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 	xa_erase_index(xa, base + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 	for (i = 1; i < 5000; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		xa_alloc_index(xa, base + i, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	/* Check that we fail properly at the limit of allocation */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(UINT_MAX - 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 				XA_LIMIT(UINT_MAX - 1, UINT_MAX),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 				GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	XA_BUG_ON(xa, id != 0xfffffffeU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(UINT_MAX),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 				XA_LIMIT(UINT_MAX - 1, UINT_MAX),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 				GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 	XA_BUG_ON(xa, id != 0xffffffffU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 	id = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 	XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 				XA_LIMIT(UINT_MAX - 1, UINT_MAX),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 				GFP_KERNEL) != -EBUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	XA_BUG_ON(xa, id != 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(10), XA_LIMIT(10, 5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 				GFP_KERNEL) != -EBUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 	XA_BUG_ON(xa, xa_store_index(xa, 3, GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(10), XA_LIMIT(10, 5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 				GFP_KERNEL) != -EBUSY);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 	xa_erase_index(xa, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) static noinline void check_xa_alloc_2(struct xarray *xa, unsigned int base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 	unsigned int i, id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	unsigned long index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	/* Allocate and free a NULL and check xa_empty() behaves */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 	XA_BUG_ON(xa, xa_alloc(xa, &id, NULL, xa_limit_32b, GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 	XA_BUG_ON(xa, id != base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 	XA_BUG_ON(xa, xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 	XA_BUG_ON(xa, xa_erase(xa, id) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 	/* Ditto, but check destroy instead of erase */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 	XA_BUG_ON(xa, xa_alloc(xa, &id, NULL, xa_limit_32b, GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 	XA_BUG_ON(xa, id != base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	XA_BUG_ON(xa, xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	for (i = base; i < base + 10; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		XA_BUG_ON(xa, xa_alloc(xa, &id, NULL, xa_limit_32b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 					GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		XA_BUG_ON(xa, id != i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 	XA_BUG_ON(xa, xa_store(xa, 3, xa_mk_index(3), GFP_KERNEL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	XA_BUG_ON(xa, xa_store(xa, 4, xa_mk_index(4), GFP_KERNEL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	XA_BUG_ON(xa, xa_store(xa, 4, NULL, GFP_KERNEL) != xa_mk_index(4));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	XA_BUG_ON(xa, xa_erase(xa, 5) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) 	XA_BUG_ON(xa, xa_alloc(xa, &id, NULL, xa_limit_32b, GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 	XA_BUG_ON(xa, id != 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 	xa_for_each(xa, index, entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) 		xa_erase_index(xa, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	for (i = base; i < base + 9; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 		XA_BUG_ON(xa, xa_erase(xa, i) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 		XA_BUG_ON(xa, xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	XA_BUG_ON(xa, xa_erase(xa, 8) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	XA_BUG_ON(xa, xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	XA_BUG_ON(xa, xa_erase(xa, base + 9) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) static noinline void check_xa_alloc_3(struct xarray *xa, unsigned int base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 	struct xa_limit limit = XA_LIMIT(1, 0x3fff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 	u32 next = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 	unsigned int i, id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 	unsigned long index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(1), limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 				&next, GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	XA_BUG_ON(xa, id != 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 	next = 0x3ffd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(0x3ffd), limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 				&next, GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 	XA_BUG_ON(xa, id != 0x3ffd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 	xa_erase_index(xa, 0x3ffd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	xa_erase_index(xa, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	for (i = 0x3ffe; i < 0x4003; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		if (i < 0x4000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 			entry = xa_mk_index(i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 			entry = xa_mk_index(i - 0x3fff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 		XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, entry, limit,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 					&next, GFP_KERNEL) != (id == 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		XA_BUG_ON(xa, xa_mk_index(id) != entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 	/* Check wrap-around is handled correctly */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	if (base != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 		xa_erase_index(xa, base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	xa_erase_index(xa, base + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	next = UINT_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(UINT_MAX),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 				xa_limit_32b, &next, GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	XA_BUG_ON(xa, id != UINT_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(base),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 				xa_limit_32b, &next, GFP_KERNEL) != 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	XA_BUG_ON(xa, id != base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 	XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(base + 1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 				xa_limit_32b, &next, GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 	XA_BUG_ON(xa, id != base + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	xa_for_each(xa, index, entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 		xa_erase_index(xa, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) static DEFINE_XARRAY_ALLOC(xa0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) static DEFINE_XARRAY_ALLOC1(xa1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) static noinline void check_xa_alloc(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	check_xa_alloc_1(&xa0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	check_xa_alloc_1(&xa1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 	check_xa_alloc_2(&xa0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	check_xa_alloc_2(&xa1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 	check_xa_alloc_3(&xa0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	check_xa_alloc_3(&xa1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) static noinline void __check_store_iter(struct xarray *xa, unsigned long start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 			unsigned int order, unsigned int present)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	XA_STATE_ORDER(xas, xa, start, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	unsigned int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) retry:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 	xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	xas_for_each_conflict(&xas, entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		XA_BUG_ON(xa, !xa_is_value(entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 		XA_BUG_ON(xa, entry < xa_mk_index(start));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 		XA_BUG_ON(xa, entry > xa_mk_index(start + (1UL << order) - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	xas_store(&xas, xa_mk_index(start));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	if (xas_nomem(&xas, GFP_KERNEL)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 		count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 		goto retry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 	XA_BUG_ON(xa, xas_error(&xas));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	XA_BUG_ON(xa, count != present);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 	XA_BUG_ON(xa, xa_load(xa, start) != xa_mk_index(start));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	XA_BUG_ON(xa, xa_load(xa, start + (1UL << order) - 1) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 			xa_mk_index(start));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	xa_erase_index(xa, start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) static noinline void check_store_iter(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	unsigned int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 	for (i = 0; i < max_order; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 		unsigned int min = 1 << i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 		unsigned int max = (2 << i) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		__check_store_iter(xa, 0, i, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 		__check_store_iter(xa, min, i, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 		XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		xa_store_index(xa, min, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 		__check_store_iter(xa, min, i, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 		xa_store_index(xa, max, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 		__check_store_iter(xa, min, i, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		for (j = 0; j < min; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 			xa_store_index(xa, j, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		__check_store_iter(xa, 0, i, min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 		for (j = 0; j < min; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 			xa_store_index(xa, min + j, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		__check_store_iter(xa, min, i, min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) #ifdef CONFIG_XARRAY_MULTI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 	xa_store_index(xa, 63, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	xa_store_index(xa, 65, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 	__check_store_iter(xa, 64, 2, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	xa_erase_index(xa, 63);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) static noinline void check_multi_find_1(struct xarray *xa, unsigned order)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) #ifdef CONFIG_XARRAY_MULTI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 	unsigned long multi = 3 << order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) 	unsigned long next = 4 << order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) 	unsigned long index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	xa_store_order(xa, multi, order, xa_mk_value(multi), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	XA_BUG_ON(xa, xa_store_index(xa, next, GFP_KERNEL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	XA_BUG_ON(xa, xa_store_index(xa, next + 1, GFP_KERNEL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 	XA_BUG_ON(xa, xa_find(xa, &index, ULONG_MAX, XA_PRESENT) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 			xa_mk_value(multi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	XA_BUG_ON(xa, index != multi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	index = multi + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	XA_BUG_ON(xa, xa_find(xa, &index, ULONG_MAX, XA_PRESENT) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 			xa_mk_value(multi));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	XA_BUG_ON(xa, (index < multi) || (index >= next));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	XA_BUG_ON(xa, xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 			xa_mk_value(next));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	XA_BUG_ON(xa, index != next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 	XA_BUG_ON(xa, xa_find_after(xa, &index, next, XA_PRESENT) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 	XA_BUG_ON(xa, index != next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 	xa_erase_index(xa, multi);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 	xa_erase_index(xa, next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	xa_erase_index(xa, next + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) static noinline void check_multi_find_2(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 10 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	unsigned int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	for (i = 0; i < max_order; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 		unsigned long index = 1UL << i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 		for (j = 0; j < index; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 			XA_STATE(xas, xa, j + index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 			xa_store_index(xa, index - 1, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 			xa_store_order(xa, index, i, xa_mk_index(index),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 					GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 			rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 			xas_for_each(&xas, entry, ULONG_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 				xa_erase_index(xa, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 			xa_erase_index(xa, index - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 			XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) static noinline void check_multi_find_3(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	unsigned int order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	for (order = 5; order < order_limit; order++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 		unsigned long index = 1UL << (order - 5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 		XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 		xa_store_order(xa, 0, order - 4, xa_mk_index(0), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 		XA_BUG_ON(xa, xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 		xa_erase_index(xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) static noinline void check_find_1(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	unsigned long i, j, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	 * Check xa_find with all pairs between 0 and 99 inclusive,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	 * starting at every index between 0 and 99
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	for (i = 0; i < 100; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 		XA_BUG_ON(xa, xa_store_index(xa, i, GFP_KERNEL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 		xa_set_mark(xa, i, XA_MARK_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 		for (j = 0; j < i; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 			XA_BUG_ON(xa, xa_store_index(xa, j, GFP_KERNEL) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 					NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 			xa_set_mark(xa, j, XA_MARK_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 			for (k = 0; k < 100; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 				unsigned long index = k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 				void *entry = xa_find(xa, &index, ULONG_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 								XA_PRESENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 				if (k <= j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 					XA_BUG_ON(xa, index != j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 				else if (k <= i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 					XA_BUG_ON(xa, index != i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 					XA_BUG_ON(xa, entry != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 				index = k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 				entry = xa_find(xa, &index, ULONG_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 								XA_MARK_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 				if (k <= j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 					XA_BUG_ON(xa, index != j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 				else if (k <= i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 					XA_BUG_ON(xa, index != i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 				else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 					XA_BUG_ON(xa, entry != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 			xa_erase_index(xa, j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 			XA_BUG_ON(xa, xa_get_mark(xa, j, XA_MARK_0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 			XA_BUG_ON(xa, !xa_get_mark(xa, i, XA_MARK_0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 		xa_erase_index(xa, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 		XA_BUG_ON(xa, xa_get_mark(xa, i, XA_MARK_0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) static noinline void check_find_2(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	unsigned long i, j, index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 	xa_for_each(xa, index, entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) 		XA_BUG_ON(xa, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) 	for (i = 0; i < 1024; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 		xa_store_index(xa, index, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) 		j = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		xa_for_each(xa, index, entry) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 			XA_BUG_ON(xa, xa_mk_index(index) != entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 			XA_BUG_ON(xa, index != j++);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) static noinline void check_find_3(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 	XA_STATE(xas, xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	unsigned long i, j, k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	for (i = 0; i < 100; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		for (j = 0; j < 100; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 			rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 			for (k = 0; k < 100; k++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 				xas_set(&xas, j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 				xas_for_each_marked(&xas, entry, k, XA_MARK_0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 					;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 				if (j > k)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 					XA_BUG_ON(xa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 						xas.xa_node != XAS_RESTART);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 			rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 		xa_store_index(xa, i, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 		xa_set_mark(xa, i, XA_MARK_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) static noinline void check_find_4(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 	unsigned long index = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 	xa_store_index(xa, ULONG_MAX, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 	entry = xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	XA_BUG_ON(xa, entry != xa_mk_index(ULONG_MAX));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	entry = xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	XA_BUG_ON(xa, entry);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 	xa_erase_index(xa, ULONG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) static noinline void check_find(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	unsigned i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	check_find_1(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	check_find_2(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	check_find_3(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	check_find_4(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	for (i = 2; i < 10; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 		check_multi_find_1(xa, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	check_multi_find_2(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	check_multi_find_3(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) /* See find_swap_entry() in mm/shmem.c */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) static noinline unsigned long xa_find_entry(struct xarray *xa, void *item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 	XA_STATE(xas, xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	unsigned int checked = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	xas_for_each(&xas, entry, ULONG_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		if (xas_retry(&xas, entry))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 		if (entry == item)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 		checked++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 		if ((checked % 4) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 		xas_pause(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	return entry ? xas.xa_index : -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) static noinline void check_find_entry(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) #ifdef CONFIG_XARRAY_MULTI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 	unsigned int order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) 	unsigned long offset, index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	for (order = 0; order < 20; order++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 		for (offset = 0; offset < (1UL << (order + 3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 		     offset += (1UL << order)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 			for (index = 0; index < (1UL << (order + 5));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 			     index += (1UL << order)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 				xa_store_order(xa, index, order,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 						xa_mk_index(index), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 				XA_BUG_ON(xa, xa_load(xa, index) !=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 						xa_mk_index(index));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 				XA_BUG_ON(xa, xa_find_entry(xa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 						xa_mk_index(index)) != index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 			XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 			xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	xa_store_index(xa, ULONG_MAX, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	XA_BUG_ON(xa, xa_find_entry(xa, xa_mk_index(ULONG_MAX)) != -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	xa_erase_index(xa, ULONG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) static noinline void check_pause(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	XA_STATE(xas, xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	unsigned int order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	unsigned long index = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	unsigned int count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	for (order = 0; order < order_limit; order++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 		XA_BUG_ON(xa, xa_store_order(xa, index, order,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 					xa_mk_index(index), GFP_KERNEL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 		index += 1UL << order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	xas_for_each(&xas, entry, ULONG_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 		XA_BUG_ON(xa, entry != xa_mk_index(1UL << count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 		count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	XA_BUG_ON(xa, count != order_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	count = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	xas_set(&xas, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	xas_for_each(&xas, entry, ULONG_MAX) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 		XA_BUG_ON(xa, entry != xa_mk_index(1UL << count));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 		count++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 		xas_pause(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	XA_BUG_ON(xa, count != order_limit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) static noinline void check_move_tiny(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	XA_STATE(xas, xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	XA_BUG_ON(xa, xas_next(&xas) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	XA_BUG_ON(xa, xas_next(&xas) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) 	xa_store_index(xa, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) 	xas_set(&xas, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	XA_BUG_ON(xa, xas_next(&xas) != xa_mk_index(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	XA_BUG_ON(xa, xas_next(&xas) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	xas_set(&xas, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	XA_BUG_ON(xa, xas_prev(&xas) != xa_mk_index(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	XA_BUG_ON(xa, xas_prev(&xas) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	xa_erase_index(xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) static noinline void check_move_max(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	XA_STATE(xas, xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	xa_store_index(xa, ULONG_MAX, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != xa_mk_index(ULONG_MAX));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	xas_set(&xas, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != xa_mk_index(ULONG_MAX));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	xas_pause(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	xa_erase_index(xa, ULONG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) static noinline void check_move_small(struct xarray *xa, unsigned long idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	XA_STATE(xas, xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 	unsigned long i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 	xa_store_index(xa, 0, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 	xa_store_index(xa, idx, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 	for (i = 0; i < idx * 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 		void *entry = xas_next(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 		if (i <= idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 			XA_BUG_ON(xa, xas.xa_node == XAS_RESTART);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		XA_BUG_ON(xa, xas.xa_index != i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 		if (i == 0 || i == idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 			XA_BUG_ON(xa, entry != xa_mk_index(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 			XA_BUG_ON(xa, entry != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	xas_next(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 	XA_BUG_ON(xa, xas.xa_index != i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 		void *entry = xas_prev(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 		i--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 		if (i <= idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 			XA_BUG_ON(xa, xas.xa_node == XAS_RESTART);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 		XA_BUG_ON(xa, xas.xa_index != i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 		if (i == 0 || i == idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 			XA_BUG_ON(xa, entry != xa_mk_index(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 			XA_BUG_ON(xa, entry != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 	} while (i > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 	xas_set(&xas, ULONG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 	XA_BUG_ON(xa, xas_next(&xas) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 	XA_BUG_ON(xa, xas.xa_index != ULONG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 	XA_BUG_ON(xa, xas_next(&xas) != xa_mk_value(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	XA_BUG_ON(xa, xas.xa_index != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	XA_BUG_ON(xa, xas_prev(&xas) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 	XA_BUG_ON(xa, xas.xa_index != ULONG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	xa_erase_index(xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	xa_erase_index(xa, idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) static noinline void check_move(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 	XA_STATE(xas, xa, (1 << 16) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 	unsigned long i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 	for (i = 0; i < (1 << 16); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		XA_BUG_ON(xa, xa_store_index(xa, i, GFP_KERNEL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 		void *entry = xas_prev(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 		i--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 		XA_BUG_ON(xa, entry != xa_mk_index(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 		XA_BUG_ON(xa, i != xas.xa_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 	} while (i != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 	XA_BUG_ON(xa, xas_prev(&xas) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 	XA_BUG_ON(xa, xas.xa_index != ULONG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 		void *entry = xas_next(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 		XA_BUG_ON(xa, entry != xa_mk_index(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 		XA_BUG_ON(xa, i != xas.xa_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	} while (i < (1 << 16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	for (i = (1 << 8); i < (1 << 15); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 		xa_erase_index(xa, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	i = xas.xa_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 		void *entry = xas_prev(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 		i--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 		if ((i < (1 << 8)) || (i >= (1 << 15)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 			XA_BUG_ON(xa, entry != xa_mk_index(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 			XA_BUG_ON(xa, entry != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 		XA_BUG_ON(xa, i != xas.xa_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	} while (i != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	XA_BUG_ON(xa, xas_prev(&xas) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	XA_BUG_ON(xa, xas.xa_index != ULONG_MAX);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 		void *entry = xas_next(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 		if ((i < (1 << 8)) || (i >= (1 << 15)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 			XA_BUG_ON(xa, entry != xa_mk_index(i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 			XA_BUG_ON(xa, entry != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 		XA_BUG_ON(xa, i != xas.xa_index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 		i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 	} while (i < (1 << 16));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	check_move_tiny(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	check_move_max(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 	for (i = 0; i < 16; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 		check_move_small(xa, 1UL << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 	for (i = 2; i < 16; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 		check_move_small(xa, (1UL << i) - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) static noinline void xa_store_many_order(struct xarray *xa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 		unsigned long index, unsigned order)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	XA_STATE_ORDER(xas, xa, index, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 	unsigned int i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 		xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 		XA_BUG_ON(xa, xas_find_conflict(&xas));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 		xas_create_range(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 		if (xas_error(&xas))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 			goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 		for (i = 0; i < (1U << order); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 			XA_BUG_ON(xa, xas_store(&xas, xa_mk_index(index + i)));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 			xas_next(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 		xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 	} while (xas_nomem(&xas, GFP_KERNEL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	XA_BUG_ON(xa, xas_error(&xas));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) static noinline void check_create_range_1(struct xarray *xa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 		unsigned long index, unsigned order)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 	unsigned long i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	xa_store_many_order(xa, index, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 	for (i = index; i < index + (1UL << order); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 		xa_erase_index(xa, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) static noinline void check_create_range_2(struct xarray *xa, unsigned order)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 	unsigned long i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	unsigned long nr = 1UL << order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	for (i = 0; i < nr * nr; i += nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 		xa_store_many_order(xa, i, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 	for (i = 0; i < nr * nr; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 		xa_erase_index(xa, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) static noinline void check_create_range_3(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	XA_STATE(xas, NULL, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 	xas_set_err(&xas, -EEXIST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 	xas_create_range(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	XA_BUG_ON(NULL, xas_error(&xas) != -EEXIST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) static noinline void check_create_range_4(struct xarray *xa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 		unsigned long index, unsigned order)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	XA_STATE_ORDER(xas, xa, index, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	unsigned long base = xas.xa_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	unsigned long i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 	xa_store_index(xa, index, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 		xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 		xas_create_range(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 		if (xas_error(&xas))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 			goto unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 		for (i = 0; i < (1UL << order); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 			void *old = xas_store(&xas, xa_mk_index(base + i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 			if (xas.xa_index == index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 				XA_BUG_ON(xa, old != xa_mk_index(base + i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 			else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 				XA_BUG_ON(xa, old != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 			xas_next(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 		xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	} while (xas_nomem(&xas, GFP_KERNEL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 	XA_BUG_ON(xa, xas_error(&xas));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 	for (i = base; i < base + (1UL << order); i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 		xa_erase_index(xa, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) static noinline void check_create_range_5(struct xarray *xa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) 		unsigned long index, unsigned int order)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	XA_STATE_ORDER(xas, xa, index, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	xa_store_order(xa, index, order, xa_mk_index(index), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	for (i = 0; i < order + 10; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 		do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 			xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 			xas_create_range(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 			xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 		} while (xas_nomem(&xas, GFP_KERNEL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) static noinline void check_create_range(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 	unsigned int order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 	unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 12 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 	for (order = 0; order < max_order; order++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) 		check_create_range_1(xa, 0, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 		check_create_range_1(xa, 1U << order, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 		check_create_range_1(xa, 2U << order, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 		check_create_range_1(xa, 3U << order, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 		check_create_range_1(xa, 1U << 24, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 		if (order < 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 			check_create_range_2(xa, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 		check_create_range_4(xa, 0, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 		check_create_range_4(xa, 1U << order, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 		check_create_range_4(xa, 2U << order, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 		check_create_range_4(xa, 3U << order, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 		check_create_range_4(xa, 1U << 24, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 		check_create_range_4(xa, 1, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 		check_create_range_4(xa, (1U << order) + 1, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 		check_create_range_4(xa, (2U << order) + 1, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 		check_create_range_4(xa, (2U << order) - 1, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 		check_create_range_4(xa, (3U << order) + 1, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 		check_create_range_4(xa, (3U << order) - 1, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 		check_create_range_4(xa, (1U << 24) + 1, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 		check_create_range_5(xa, 0, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 		check_create_range_5(xa, (1U << order), order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	check_create_range_3();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) static noinline void __check_store_range(struct xarray *xa, unsigned long first,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) 		unsigned long last)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) #ifdef CONFIG_XARRAY_MULTI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	xa_store_range(xa, first, last, xa_mk_index(first), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 	XA_BUG_ON(xa, xa_load(xa, first) != xa_mk_index(first));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) 	XA_BUG_ON(xa, xa_load(xa, last) != xa_mk_index(first));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 	XA_BUG_ON(xa, xa_load(xa, first - 1) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) 	XA_BUG_ON(xa, xa_load(xa, last + 1) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 	xa_store_range(xa, first, last, NULL, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) static noinline void check_store_range(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 	unsigned long i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) 	for (i = 0; i < 128; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 		for (j = i; j < 128; j++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) 			__check_store_range(xa, i, j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) 			__check_store_range(xa, 128 + i, 128 + j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 			__check_store_range(xa, 4095 + i, 4095 + j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 			__check_store_range(xa, 4096 + i, 4096 + j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) 			__check_store_range(xa, 123456 + i, 123456 + j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 			__check_store_range(xa, (1 << 24) + i, (1 << 24) + j);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) #ifdef CONFIG_XARRAY_MULTI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) static void check_split_1(struct xarray *xa, unsigned long index,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 				unsigned int order, unsigned int new_order)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 	XA_STATE_ORDER(xas, xa, index, new_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	xa_store_order(xa, index, order, xa, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 	xas_split_alloc(&xas, xa, order, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 	xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 	xas_split(&xas, xa, order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 	for (i = 0; i < (1 << order); i += (1 << new_order))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 		__xa_store(xa, index + i, xa_mk_index(index + i), 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 	xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 	for (i = 0; i < (1 << order); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 		unsigned int val = index + (i & ~((1 << new_order) - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 		XA_BUG_ON(xa, xa_load(xa, index + i) != xa_mk_index(val));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) 	xa_set_mark(xa, index, XA_MARK_0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 	XA_BUG_ON(xa, !xa_get_mark(xa, index, XA_MARK_0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) static noinline void check_split(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 	unsigned int order, new_order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 	for (order = 1; order < 2 * XA_CHUNK_SHIFT; order++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 		for (new_order = 0; new_order < order; new_order++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 			check_split_1(xa, 0, order, new_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 			check_split_1(xa, 1UL << order, order, new_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 			check_split_1(xa, 3UL << order, order, new_order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) static void check_split(struct xarray *xa) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) static void check_align_1(struct xarray *xa, char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) 	unsigned int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 	unsigned long index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) 	void *entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 	for (i = 0; i < 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 		XA_BUG_ON(xa, xa_alloc(xa, &id, name + i, xa_limit_32b,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 					GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 		XA_BUG_ON(xa, id != i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) 	xa_for_each(xa, index, entry)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 		XA_BUG_ON(xa, xa_is_err(entry));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616)  * We should always be able to store without allocating memory after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617)  * reserving a slot.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) static void check_align_2(struct xarray *xa, char *name)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 	for (i = 0; i < 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 		XA_BUG_ON(xa, xa_store(xa, 0, name + i, GFP_KERNEL) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 		xa_erase(xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 	for (i = 0; i < 8; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 		XA_BUG_ON(xa, xa_reserve(xa, 0, GFP_KERNEL) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 		XA_BUG_ON(xa, xa_store(xa, 0, name + i, 0) != NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 		xa_erase(xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) static noinline void check_align(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 	char name[] = "Motorola 68000";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 	check_align_1(xa, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	check_align_1(xa, name + 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 	check_align_1(xa, name + 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 	check_align_1(xa, name + 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	check_align_2(xa, name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) static LIST_HEAD(shadow_nodes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) static void test_update_node(struct xa_node *node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 	if (node->count && node->count == node->nr_values) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 		if (list_empty(&node->private_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 			list_add(&shadow_nodes, &node->private_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 		if (!list_empty(&node->private_list))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 			list_del_init(&node->private_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) static noinline void shadow_remove(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 	struct xa_node *node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 	xa_lock(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 	while ((node = list_first_entry_or_null(&shadow_nodes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 					struct xa_node, private_list))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 		XA_BUG_ON(xa, node->array != xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 		list_del_init(&node->private_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 		xa_delete_node(node, test_update_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	xa_unlock(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) static noinline void check_workingset(struct xarray *xa, unsigned long index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 	XA_STATE(xas, xa, index);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 	xas_set_update(&xas, test_update_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 		xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 		xas_store(&xas, xa_mk_value(0));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 		xas_next(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 		xas_store(&xas, xa_mk_value(1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 		xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 	} while (xas_nomem(&xas, GFP_KERNEL));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 	XA_BUG_ON(xa, list_empty(&shadow_nodes));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 	xas_lock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 	xas_next(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694) 	xas_store(&xas, &xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 	XA_BUG_ON(xa, !list_empty(&shadow_nodes));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) 	xas_store(&xas, xa_mk_value(2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 	xas_unlock(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) 	XA_BUG_ON(xa, list_empty(&shadow_nodes));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	shadow_remove(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	XA_BUG_ON(xa, !list_empty(&shadow_nodes));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707)  * Check that the pointer / value / sibling entries are accounted the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708)  * way we expect them to be.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) static noinline void check_account(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) #ifdef CONFIG_XARRAY_MULTI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	unsigned int order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 	for (order = 1; order < 12; order++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 		XA_STATE(xas, xa, 1 << order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 		xa_store_order(xa, 0, order, xa, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 		rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 		xas_load(&xas);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 		XA_BUG_ON(xa, xas.xa_node->count == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 		XA_BUG_ON(xa, xas.xa_node->count > (1 << order));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 		XA_BUG_ON(xa, xas.xa_node->nr_values != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 		rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 		xa_store_order(xa, 1 << order, order, xa_mk_index(1UL << order),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 				GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 		XA_BUG_ON(xa, xas.xa_node->count != xas.xa_node->nr_values * 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 		xa_erase(xa, 1 << order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) 		XA_BUG_ON(xa, xas.xa_node->nr_values != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 		xa_erase(xa, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 		XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) static noinline void check_get_order(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 	unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 	unsigned int order;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 	unsigned long i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 	for (i = 0; i < 3; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 		XA_BUG_ON(xa, xa_get_order(xa, i) != 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) 	for (order = 0; order < max_order; order++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 		for (i = 0; i < 10; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) 			xa_store_order(xa, i << order, order,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) 					xa_mk_index(i << order), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 			for (j = i << order; j < (i + 1) << order; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 				XA_BUG_ON(xa, xa_get_order(xa, j) != order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 			xa_erase(xa, i << order);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) static noinline void check_destroy(struct xarray *xa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) 	unsigned long index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 	/* Destroying an empty array is a no-op */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) 	/* Destroying an array with a single entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 	for (index = 0; index < 1000; index++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) 		xa_store_index(xa, index, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) 		XA_BUG_ON(xa, xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 		xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 		XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	/* Destroying an array with a single entry at ULONG_MAX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 	xa_store(xa, ULONG_MAX, xa, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 	XA_BUG_ON(xa, xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) #ifdef CONFIG_XARRAY_MULTI
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 	/* Destroying an array with a multi-index entry */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 	xa_store_order(xa, 1 << 11, 11, xa, GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	XA_BUG_ON(xa, xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 	xa_destroy(xa);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 	XA_BUG_ON(xa, !xa_empty(xa));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) static DEFINE_XARRAY(array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) static int xarray_checks(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 	check_xa_err(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 	check_xas_retry(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 	check_xa_load(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 	check_xa_mark(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 	check_xa_shrink(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 	check_xas_erase(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 	check_insert(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 	check_cmpxchg(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 	check_reserve(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 	check_reserve(&xa0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 	check_multi_store(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	check_get_order(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	check_xa_alloc();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 	check_find(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 	check_find_entry(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 	check_pause(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 	check_account(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 	check_destroy(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	check_move(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	check_create_range(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 	check_store_range(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	check_store_iter(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 	check_align(&xa0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 	check_split(&array);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 	check_workingset(&array, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 	check_workingset(&array, 64);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 	check_workingset(&array, 4096);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 	printk("XArray: %u of %u tests passed\n", tests_passed, tests_run);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) 	return (tests_run == tests_passed) ? 0 : -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1827) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1829) static void xarray_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1830) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1831) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1832) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1833) module_init(xarray_checks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1834) module_exit(xarray_exit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1835) MODULE_AUTHOR("Matthew Wilcox <willy@infradead.org>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1836) MODULE_LICENSE("GPL");