| @@ -6,10 +6,11 @@ · 5 unmodified lines |
| 6 | * Author: Matthew Wilcox <willy@infradead.org> | 6 | * Author: Matthew Wilcox <willy@infradead.org> |
| 7 | */ | 7 | */ |
| 8 | | 8 | |
| 9 | #include <kunit/test.h> | | |
| 10 | | | |
| 11 | #include <linux/module.h> | | |
| 12 | #include <linux/xarray.h> | 9 | #include <linux/xarray.h> |
| | 10 | #include <linux/module.h> |
| | 11 | |
| | 12 | static unsigned int tests_run; |
| | 13 | static unsigned int tests_passed; |
| 13 | | 14 | |
| 14 | static const unsigned int order_limit = | 15 | static const unsigned int order_limit = |
| 15 | IS_ENABLED(CONFIG_XARRAY_MULTI) ? BITS_PER_LONG : 1; | 16 | IS_ENABLED(CONFIG_XARRAY_MULTI) ? BITS_PER_LONG : 1; |
| @@ -19,12 +20,15 @@ static const unsigned int order_limit = · 3 unmodified lines |
| 19 | void xa_dump(const struct xarray *xa) { } | 20 | void xa_dump(const struct xarray *xa) { } |
| 20 | # endif | 21 | # endif |
| 21 | #undef XA_BUG_ON | 22 | #undef XA_BUG_ON |
| 22 | #define XA_BUG_ON(xa, x) do { \ | 23 | #define XA_BUG_ON(xa, x) do { \ |
| 23 | if (x) { \ | 24 | tests_run++; \ |
| 24 | KUNIT_FAIL(test, #x); \ | 25 | if (x) { \ |
| 25 | xa_dump(xa); \ | 26 | printk("BUG at %s:%d\n", __func__, __LINE__); \ |
| 26 | dump_stack(); \ | 27 | xa_dump(xa); \ |
| 27 | } \ | 28 | dump_stack(); \ |
| | 29 | } else { \ |
| | 30 | tests_passed++; \ |
| | 31 | } \ |
| 28 | } while (0) | 32 | } while (0) |
| 29 | #endif | 33 | #endif |
| 30 | | 34 | |
| @@ -38,13 +42,13 @@ static void *xa_store_index(struct xarray *xa, unsigned long index, gfp_t gfp) · 7 unmodified lines |
| 38 | return xa_store(xa, index, xa_mk_index(index), gfp); | 42 | return xa_store(xa, index, xa_mk_index(index), gfp); |
| 39 | } | 43 | } |
| 40 | | 44 | |
| 41 | static void xa_insert_index(struct kunit *test, struct xarray *xa, unsigned long index) | 45 | static void xa_insert_index(struct xarray *xa, unsigned long index) |
| 42 | { | 46 | { |
| 43 | XA_BUG_ON(xa, xa_insert(xa, index, xa_mk_index(index), | 47 | XA_BUG_ON(xa, xa_insert(xa, index, xa_mk_index(index), |
| 44 | GFP_KERNEL) != 0); | 48 | GFP_KERNEL) != 0); |
| 45 | } | 49 | } |
| 46 | | 50 | |
| 47 | static void xa_alloc_index(struct kunit *test, struct xarray *xa, unsigned long index, gfp_t gfp) | 51 | static void xa_alloc_index(struct xarray *xa, unsigned long index, gfp_t gfp) |
| 48 | { | 52 | { |
| 49 | u32 id; | 53 | u32 id; |
| 50 | | 54 | |
| @@ -53,7 +57,7 @@ static void xa_alloc_index(struct kunit *test, struct xarray *xa, unsigned long · 2 unmodified lines |
| 53 | XA_BUG_ON(xa, id != index); | 57 | XA_BUG_ON(xa, id != index); |
| 54 | } | 58 | } |
| 55 | | 59 | |
| 56 | static void xa_erase_index(struct kunit *test, struct xarray *xa, unsigned long index) | 60 | static void xa_erase_index(struct xarray *xa, unsigned long index) |
| 57 | { | 61 | { |
| 58 | XA_BUG_ON(xa, xa_erase(xa, index) != xa_mk_index(index)); | 62 | XA_BUG_ON(xa, xa_erase(xa, index) != xa_mk_index(index)); |
| 59 | XA_BUG_ON(xa, xa_load(xa, index) != NULL); | 63 | XA_BUG_ON(xa, xa_load(xa, index) != NULL); |
| @@ -79,15 +83,8 @@ static void *xa_store_order(struct xarray *xa, unsigned long index, · 19 unmodified lines |
| 79 | return curr; | 83 | return curr; |
| 80 | } | 84 | } |
| 81 | | 85 | |
| 82 | static inline struct xarray *xa_param(struct kunit *test) | 86 | static noinline void check_xa_err(struct xarray *xa) |
| 83 | { | 87 | { |
| 84 | return *(struct xarray **)test->param_value; | | |
| 85 | } | | |
| 86 | | | |
| 87 | static noinline void check_xa_err(struct kunit *test) | | |
| 88 | { | | |
| 89 | struct xarray *xa = xa_param(test); | | |
| 90 | | | |
| 91 | XA_BUG_ON(xa, xa_err(xa_store_index(xa, 0, GFP_NOWAIT)) != 0); | 88 | XA_BUG_ON(xa, xa_err(xa_store_index(xa, 0, GFP_NOWAIT)) != 0); |
| 92 | XA_BUG_ON(xa, xa_err(xa_erase(xa, 0)) != 0); | 89 | XA_BUG_ON(xa, xa_err(xa_erase(xa, 0)) != 0); |
| 93 | #ifndef __KERNEL__ | 90 | #ifndef __KERNEL__ |
| @@ -102,10 +99,8 @@ static noinline void check_xa_err(struct kunit *test) · 8 unmodified lines |
| 102 | // XA_BUG_ON(xa, xa_err(xa_store(xa, 0, xa_mk_internal(0), 0)) != -EINVAL); | 99 | // XA_BUG_ON(xa, xa_err(xa_store(xa, 0, xa_mk_internal(0), 0)) != -EINVAL); |
| 103 | } | 100 | } |
| 104 | | 101 | |
| 105 | static noinline void check_xas_retry(struct kunit *test) | 102 | static noinline void check_xas_retry(struct xarray *xa) |
| 106 | { | 103 | { |
| 107 | struct xarray *xa = xa_param(test); | | |
| 108 | | | |
| 109 | XA_STATE(xas, xa, 0); | 104 | XA_STATE(xas, xa, 0); |
| 110 | void *entry; | 105 | void *entry; |
| 111 | | 106 | |
| @@ -114,7 +109,7 @@ static noinline void check_xas_retry(struct kunit *test) · 2 unmodified lines |
| 114 | | 109 | |
| 115 | rcu_read_lock(); | 110 | rcu_read_lock(); |
| 116 | XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != xa_mk_value(0)); | 111 | XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != xa_mk_value(0)); |
| 117 | xa_erase_index(test, xa, 1); | 112 | xa_erase_index(xa, 1); |
| 118 | XA_BUG_ON(xa, !xa_is_retry(xas_reload(&xas))); | 113 | XA_BUG_ON(xa, !xa_is_retry(xas_reload(&xas))); |
| 119 | XA_BUG_ON(xa, xas_retry(&xas, NULL)); | 114 | XA_BUG_ON(xa, xas_retry(&xas, NULL)); |
| 120 | XA_BUG_ON(xa, xas_retry(&xas, xa_mk_value(0))); | 115 | XA_BUG_ON(xa, xas_retry(&xas, xa_mk_value(0))); |
| @@ -145,14 +140,12 @@ static noinline void check_xas_retry(struct kunit *test) · 24 unmodified lines |
| 145 | } | 140 | } |
| 146 | xas_unlock(&xas); | 141 | xas_unlock(&xas); |
| 147 | | 142 | |
| 148 | xa_erase_index(test, xa, 0); | 143 | xa_erase_index(xa, 0); |
| 149 | xa_erase_index(test, xa, 1); | 144 | xa_erase_index(xa, 1); |
| 150 | } | 145 | } |
| 151 | | 146 | |
| 152 | static noinline void check_xa_load(struct kunit *test) | 147 | static noinline void check_xa_load(struct xarray *xa) |
| 153 | { | 148 | { |
| 154 | struct xarray *xa = xa_param(test); | | |
| 155 | | | |
| 156 | unsigned long i, j; | 149 | unsigned long i, j; |
| 157 | | 150 | |
| 158 | for (i = 0; i < 1024; i++) { | 151 | for (i = 0; i < 1024; i++) { |
| @@ -174,15 +167,13 @@ static noinline void check_xa_load(struct kunit *test) · 15 unmodified lines |
| 174 | else | 167 | else |
| 175 | XA_BUG_ON(xa, entry); | 168 | XA_BUG_ON(xa, entry); |
| 176 | } | 169 | } |
| 177 | xa_erase_index(test, xa, i); | 170 | xa_erase_index(xa, i); |
| 178 | } | 171 | } |
| 179 | XA_BUG_ON(xa, !xa_empty(xa)); | 172 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 180 | } | 173 | } |
| 181 | | 174 | |
| 182 | static noinline void check_xa_mark_1(struct kunit *test, unsigned long index) | 175 | static noinline void check_xa_mark_1(struct xarray *xa, unsigned long index) |
| 183 | { | 176 | { |
| 184 | struct xarray *xa = xa_param(test); | | |
| 185 | | | |
| 186 | unsigned int order; | 177 | unsigned int order; |
| 187 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 8 : 1; | 178 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 8 : 1; |
| 188 | | 179 | |
| @@ -202,7 +193,7 @@ static noinline void check_xa_mark_1(struct kunit *test, unsigned long index) · 13 unmodified lines |
| 202 | XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_1)); | 193 | XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_1)); |
| 203 | | 194 | |
| 204 | /* Storing NULL clears marks, and they can't be set again */ | 195 | /* Storing NULL clears marks, and they can't be set again */ |
| 205 | xa_erase_index(test, xa, index); | 196 | xa_erase_index(xa, index); |
| 206 | XA_BUG_ON(xa, !xa_empty(xa)); | 197 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 207 | XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_0)); | 198 | XA_BUG_ON(xa, xa_get_mark(xa, index, XA_MARK_0)); |
| 208 | xa_set_mark(xa, index, XA_MARK_0); | 199 | xa_set_mark(xa, index, XA_MARK_0); |
| @@ -253,17 +244,15 @@ static noinline void check_xa_mark_1(struct kunit *test, unsigned long index) · 44 unmodified lines |
| 253 | XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_0)); | 244 | XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_0)); |
| 254 | XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_1)); | 245 | XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_1)); |
| 255 | XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_2)); | 246 | XA_BUG_ON(xa, xa_get_mark(xa, next, XA_MARK_2)); |
| 256 | xa_erase_index(test, xa, index); | 247 | xa_erase_index(xa, index); |
| 257 | xa_erase_index(test, xa, next); | 248 | xa_erase_index(xa, next); |
| 258 | XA_BUG_ON(xa, !xa_empty(xa)); | 249 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 259 | } | 250 | } |
| 260 | XA_BUG_ON(xa, !xa_empty(xa)); | 251 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 261 | } | 252 | } |
| 262 | | 253 | |
| 263 | static noinline void check_xa_mark_2(struct kunit *test) | 254 | static noinline void check_xa_mark_2(struct xarray *xa) |
| 264 | { | 255 | { |
| 265 | struct xarray *xa = xa_param(test); | | |
| 266 | | | |
| 267 | XA_STATE(xas, xa, 0); | 256 | XA_STATE(xas, xa, 0); |
| 268 | unsigned long index; | 257 | unsigned long index; |
| 269 | unsigned int count = 0; | 258 | unsigned int count = 0; |
| @@ -300,11 +289,9 @@ static noinline void check_xa_mark_2(struct kunit *test) · 30 unmodified lines |
| 300 | xa_destroy(xa); | 289 | xa_destroy(xa); |
| 301 | } | 290 | } |
| 302 | | 291 | |
| 303 | static noinline void check_xa_mark_3(struct kunit *test) | 292 | static noinline void check_xa_mark_3(struct xarray *xa) |
| 304 | { | 293 | { |
| 305 | #ifdef CONFIG_XARRAY_MULTI | 294 | #ifdef CONFIG_XARRAY_MULTI |
| 306 | struct xarray *xa = xa_param(test); | | |
| 307 | | | |
| 308 | XA_STATE(xas, xa, 0x41); | 295 | XA_STATE(xas, xa, 0x41); |
| 309 | void *entry; | 296 | void *entry; |
| 310 | int count = 0; | 297 | int count = 0; |
| @@ -323,21 +310,19 @@ static noinline void check_xa_mark_3(struct kunit *test) · 12 unmodified lines |
| 323 | #endif | 310 | #endif |
| 324 | } | 311 | } |
| 325 | | 312 | |
| 326 | static noinline void check_xa_mark(struct kunit *test) | 313 | static noinline void check_xa_mark(struct xarray *xa) |
| 327 | { | 314 | { |
| 328 | unsigned long index; | 315 | unsigned long index; |
| 329 | | 316 | |
| 330 | for (index = 0; index < 16384; index += 4) | 317 | for (index = 0; index < 16384; index += 4) |
| 331 | check_xa_mark_1(test, index); | 318 | check_xa_mark_1(xa, index); |
| 332 | | 319 | |
| 333 | check_xa_mark_2(test); | 320 | check_xa_mark_2(xa); |
| 334 | check_xa_mark_3(test); | 321 | check_xa_mark_3(xa); |
| 335 | } | 322 | } |
| 336 | | 323 | |
| 337 | static noinline void check_xa_shrink(struct kunit *test) | 324 | static noinline void check_xa_shrink(struct xarray *xa) |
| 338 | { | 325 | { |
| 339 | struct xarray *xa = xa_param(test); | | |
| 340 | | | |
| 341 | XA_STATE(xas, xa, 1); | 326 | XA_STATE(xas, xa, 1); |
| 342 | struct xa_node *node; | 327 | struct xa_node *node; |
| 343 | unsigned int order; | 328 | unsigned int order; |
| @@ -362,7 +347,7 @@ static noinline void check_xa_shrink(struct kunit *test) · 18 unmodified lines |
| 362 | XA_BUG_ON(xa, xas_load(&xas) != NULL); | 347 | XA_BUG_ON(xa, xas_load(&xas) != NULL); |
| 363 | xas_unlock(&xas); | 348 | xas_unlock(&xas); |
| 364 | XA_BUG_ON(xa, xa_load(xa, 0) != xa_mk_value(0)); | 349 | XA_BUG_ON(xa, xa_load(xa, 0) != xa_mk_value(0)); |
| 365 | xa_erase_index(test, xa, 0); | 350 | xa_erase_index(xa, 0); |
| 366 | XA_BUG_ON(xa, !xa_empty(xa)); | 351 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 367 | | 352 | |
| 368 | for (order = 0; order < max_order; order++) { | 353 | for (order = 0; order < max_order; order++) { |
| @@ -379,49 +364,45 @@ static noinline void check_xa_shrink(struct kunit *test) · 10 unmodified lines |
| 379 | XA_BUG_ON(xa, xa_head(xa) == node); | 364 | XA_BUG_ON(xa, xa_head(xa) == node); |
| 380 | rcu_read_unlock(); | 365 | rcu_read_unlock(); |
| 381 | XA_BUG_ON(xa, xa_load(xa, max + 1) != NULL); | 366 | XA_BUG_ON(xa, xa_load(xa, max + 1) != NULL); |
| 382 | xa_erase_index(test, xa, ULONG_MAX); | 367 | xa_erase_index(xa, ULONG_MAX); |
| 383 | XA_BUG_ON(xa, xa->xa_head != node); | 368 | XA_BUG_ON(xa, xa->xa_head != node); |
| 384 | xa_erase_index(test, xa, 0); | 369 | xa_erase_index(xa, 0); |
| 385 | } | 370 | } |
| 386 | } | 371 | } |
| 387 | | 372 | |
| 388 | static noinline void check_insert(struct kunit *test) | 373 | static noinline void check_insert(struct xarray *xa) |
| 389 | { | 374 | { |
| 390 | struct xarray *xa = xa_param(test); | | |
| 391 | | | |
| 392 | unsigned long i; | 375 | unsigned long i; |
| 393 | | 376 | |
| 394 | for (i = 0; i < 1024; i++) { | 377 | for (i = 0; i < 1024; i++) { |
| 395 | xa_insert_index(test, xa, i); | 378 | xa_insert_index(xa, i); |
| 396 | XA_BUG_ON(xa, xa_load(xa, i - 1) != NULL); | 379 | XA_BUG_ON(xa, xa_load(xa, i - 1) != NULL); |
| 397 | XA_BUG_ON(xa, xa_load(xa, i + 1) != NULL); | 380 | XA_BUG_ON(xa, xa_load(xa, i + 1) != NULL); |
| 398 | xa_erase_index(test, xa, i); | 381 | xa_erase_index(xa, i); |
| 399 | } | 382 | } |
| 400 | | 383 | |
| 401 | for (i = 10; i < BITS_PER_LONG; i++) { | 384 | for (i = 10; i < BITS_PER_LONG; i++) { |
| 402 | xa_insert_index(test, xa, 1UL << i); | 385 | xa_insert_index(xa, 1UL << i); |
| 403 | XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 1) != NULL); | 386 | XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 1) != NULL); |
| 404 | XA_BUG_ON(xa, xa_load(xa, (1UL << i) + 1) != NULL); | 387 | XA_BUG_ON(xa, xa_load(xa, (1UL << i) + 1) != NULL); |
| 405 | xa_erase_index(test, xa, 1UL << i); | 388 | xa_erase_index(xa, 1UL << i); |
| 406 | | 389 | |
| 407 | xa_insert_index(test, xa, (1UL << i) - 1); | 390 | xa_insert_index(xa, (1UL << i) - 1); |
| 408 | XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 2) != NULL); | 391 | XA_BUG_ON(xa, xa_load(xa, (1UL << i) - 2) != NULL); |
| 409 | XA_BUG_ON(xa, xa_load(xa, 1UL << i) != NULL); | 392 | XA_BUG_ON(xa, xa_load(xa, 1UL << i) != NULL); |
| 410 | xa_erase_index(test, xa, (1UL << i) - 1); | 393 | xa_erase_index(xa, (1UL << i) - 1); |
| 411 | } | 394 | } |
| 412 | | 395 | |
| 413 | xa_insert_index(test, xa, ~0UL); | 396 | xa_insert_index(xa, ~0UL); |
| 414 | XA_BUG_ON(xa, xa_load(xa, 0UL) != NULL); | 397 | XA_BUG_ON(xa, xa_load(xa, 0UL) != NULL); |
| 415 | XA_BUG_ON(xa, xa_load(xa, ~1UL) != NULL); | 398 | XA_BUG_ON(xa, xa_load(xa, ~1UL) != NULL); |
| 416 | xa_erase_index(test, xa, ~0UL); | 399 | xa_erase_index(xa, ~0UL); |
| 417 | | 400 | |
| 418 | XA_BUG_ON(xa, !xa_empty(xa)); | 401 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 419 | } | 402 | } |
| 420 | | 403 | |
| 421 | static noinline void check_cmpxchg(struct kunit *test) | 404 | static noinline void check_cmpxchg(struct xarray *xa) |
| 422 | { | 405 | { |
| 423 | struct xarray *xa = xa_param(test); | | |
| 424 | | | |
| 425 | void *FIVE = xa_mk_value(5); | 406 | void *FIVE = xa_mk_value(5); |
| 426 | void *SIX = xa_mk_value(6); | 407 | void *SIX = xa_mk_value(6); |
| 427 | void *LOTS = xa_mk_value(12345678); | 408 | void *LOTS = xa_mk_value(12345678); |
| @@ -437,16 +418,14 @@ static noinline void check_cmpxchg(struct kunit *test) · 9 unmodified lines |
| 437 | XA_BUG_ON(xa, xa_insert(xa, 5, FIVE, GFP_KERNEL) != -EBUSY); | 418 | XA_BUG_ON(xa, xa_insert(xa, 5, FIVE, GFP_KERNEL) != -EBUSY); |
| 438 | XA_BUG_ON(xa, xa_cmpxchg(xa, 5, FIVE, NULL, GFP_KERNEL) != FIVE); | 419 | XA_BUG_ON(xa, xa_cmpxchg(xa, 5, FIVE, NULL, GFP_KERNEL) != FIVE); |
| 439 | XA_BUG_ON(xa, xa_insert(xa, 5, FIVE, GFP_KERNEL) == -EBUSY); | 420 | XA_BUG_ON(xa, xa_insert(xa, 5, FIVE, GFP_KERNEL) == -EBUSY); |
| 440 | xa_erase_index(test, xa, 12345678); | 421 | xa_erase_index(xa, 12345678); |
| 441 | xa_erase_index(test, xa, 5); | 422 | xa_erase_index(xa, 5); |
| 442 | XA_BUG_ON(xa, !xa_empty(xa)); | 423 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 443 | } | 424 | } |
| 444 | | 425 | |
| 445 | static noinline void check_cmpxchg_order(struct kunit *test) | 426 | static noinline void check_cmpxchg_order(struct xarray *xa) |
| 446 | { | 427 | { |
| 447 | #ifdef CONFIG_XARRAY_MULTI | 428 | #ifdef CONFIG_XARRAY_MULTI |
| 448 | struct xarray *xa = xa_param(test); | | |
| 449 | | | |
| 450 | void *FIVE = xa_mk_value(5); | 429 | void *FIVE = xa_mk_value(5); |
| 451 | unsigned int i, order = 3; | 430 | unsigned int i, order = 3; |
| 452 | | 431 | |
| @@ -497,10 +476,8 @@ static noinline void check_cmpxchg_order(struct kunit *test) · 44 unmodified lines |
| 497 | #endif | 476 | #endif |
| 498 | } | 477 | } |
| 499 | | 478 | |
| 500 | static noinline void check_reserve(struct kunit *test) | 479 | static noinline void check_reserve(struct xarray *xa) |
| 501 | { | 480 | { |
| 502 | struct xarray *xa = xa_param(test); | | |
| 503 | | | |
| 504 | void *entry; | 481 | void *entry; |
| 505 | unsigned long index; | 482 | unsigned long index; |
| 506 | int count; | 483 | int count; |
| @@ -517,7 +494,7 @@ static noinline void check_reserve(struct kunit *test) · 10 unmodified lines |
| 517 | XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0); | 494 | XA_BUG_ON(xa, xa_reserve(xa, 12345678, GFP_KERNEL) != 0); |
| 518 | XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_NOWAIT) != NULL); | 495 | XA_BUG_ON(xa, xa_store_index(xa, 12345678, GFP_NOWAIT) != NULL); |
| 519 | xa_release(xa, 12345678); | 496 | xa_release(xa, 12345678); |
| 520 | xa_erase_index(test, xa, 12345678); | 497 | xa_erase_index(xa, 12345678); |
| 521 | XA_BUG_ON(xa, !xa_empty(xa)); | 498 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 522 | | 499 | |
| 523 | /* cmpxchg sees a reserved entry as ZERO */ | 500 | /* cmpxchg sees a reserved entry as ZERO */ |
| @@ -525,7 +502,7 @@ static noinline void check_reserve(struct kunit *test) · 1 unmodified line |
| 525 | XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, XA_ZERO_ENTRY, | 502 | XA_BUG_ON(xa, xa_cmpxchg(xa, 12345678, XA_ZERO_ENTRY, |
| 526 | xa_mk_value(12345678), GFP_NOWAIT) != NULL); | 503 | xa_mk_value(12345678), GFP_NOWAIT) != NULL); |
| 527 | xa_release(xa, 12345678); | 504 | xa_release(xa, 12345678); |
| 528 | xa_erase_index(test, xa, 12345678); | 505 | xa_erase_index(xa, 12345678); |
| 529 | XA_BUG_ON(xa, !xa_empty(xa)); | 506 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 530 | | 507 | |
| 531 | /* xa_insert treats it as busy */ | 508 | /* xa_insert treats it as busy */ |
| @@ -565,10 +542,8 @@ static noinline void check_reserve(struct kunit *test) · 33 unmodified lines |
| 565 | xa_destroy(xa); | 542 | xa_destroy(xa); |
| 566 | } | 543 | } |
| 567 | | 544 | |
| 568 | static noinline void check_xas_erase(struct kunit *test) | 545 | static noinline void check_xas_erase(struct xarray *xa) |
| 569 | { | 546 | { |
| 570 | struct xarray *xa = xa_param(test); | | |
| 571 | | | |
| 572 | XA_STATE(xas, xa, 0); | 547 | XA_STATE(xas, xa, 0); |
| 573 | void *entry; | 548 | void *entry; |
| 574 | unsigned long i, j; | 549 | unsigned long i, j; |
| @@ -606,11 +581,9 @@ static noinline void check_xas_erase(struct kunit *test) · 31 unmodified lines |
| 606 | } | 581 | } |
| 607 | | 582 | |
| 608 | #ifdef CONFIG_XARRAY_MULTI | 583 | #ifdef CONFIG_XARRAY_MULTI |
| 609 | static noinline void check_multi_store_1(struct kunit *test, unsigned long index, | 584 | static noinline void check_multi_store_1(struct xarray *xa, unsigned long index, |
| 610 | unsigned int order) | 585 | unsigned int order) |
| 611 | { | 586 | { |
| 612 | struct xarray *xa = xa_param(test); | | |
| 613 | | | |
| 614 | XA_STATE(xas, xa, index); | 587 | XA_STATE(xas, xa, index); |
| 615 | unsigned long min = index & ~((1UL << order) - 1); | 588 | unsigned long min = index & ~((1UL << order) - 1); |
| 616 | unsigned long max = min + (1UL << order); | 589 | unsigned long max = min + (1UL << order); |
| @@ -629,15 +602,13 @@ static noinline void check_multi_store_1(struct kunit *test, unsigned long index · 12 unmodified lines |
| 629 | XA_BUG_ON(xa, xa_load(xa, max) != NULL); | 602 | XA_BUG_ON(xa, xa_load(xa, max) != NULL); |
| 630 | XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL); | 603 | XA_BUG_ON(xa, xa_load(xa, min - 1) != NULL); |
| 631 | | 604 | |
| 632 | xa_erase_index(test, xa, min); | 605 | xa_erase_index(xa, min); |
| 633 | XA_BUG_ON(xa, !xa_empty(xa)); | 606 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 634 | } | 607 | } |
| 635 | | 608 | |
| 636 | static noinline void check_multi_store_2(struct kunit *test, unsigned long index, | 609 | static noinline void check_multi_store_2(struct xarray *xa, unsigned long index, |
| 637 | unsigned int order) | 610 | unsigned int order) |
| 638 | { | 611 | { |
| 639 | struct xarray *xa = xa_param(test); | | |
| 640 | | | |
| 641 | XA_STATE(xas, xa, index); | 612 | XA_STATE(xas, xa, index); |
| 642 | xa_store_order(xa, index, order, xa_mk_value(0), GFP_KERNEL); | 613 | xa_store_order(xa, index, order, xa_mk_value(0), GFP_KERNEL); |
| 643 | | 614 | |
| @@ -649,11 +620,9 @@ static noinline void check_multi_store_2(struct kunit *test, unsigned long index · 5 unmodified lines |
| 649 | XA_BUG_ON(xa, !xa_empty(xa)); | 620 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 650 | } | 621 | } |
| 651 | | 622 | |
| 652 | static noinline void check_multi_store_3(struct kunit *test, unsigned long index, | 623 | static noinline void check_multi_store_3(struct xarray *xa, unsigned long index, |
| 653 | unsigned int order) | 624 | unsigned int order) |
| 654 | { | 625 | { |
| 655 | struct xarray *xa = xa_param(test); | | |
| 656 | | | |
| 657 | XA_STATE(xas, xa, 0); | 626 | XA_STATE(xas, xa, 0); |
| 658 | void *entry; | 627 | void *entry; |
| 659 | int n = 0; | 628 | int n = 0; |
| @@ -678,11 +647,9 @@ static noinline void check_multi_store_3(struct kunit *test, unsigned long index · 18 unmodified lines |
| 678 | } | 647 | } |
| 679 | #endif | 648 | #endif |
| 680 | | 649 | |
| 681 | static noinline void check_multi_store(struct kunit *test) | 650 | static noinline void check_multi_store(struct xarray *xa) |
| 682 | { | 651 | { |
| 683 | #ifdef CONFIG_XARRAY_MULTI | 652 | #ifdef CONFIG_XARRAY_MULTI |
| 684 | struct xarray *xa = xa_param(test); | | |
| 685 | | | |
| 686 | unsigned long i, j, k; | 653 | unsigned long i, j, k; |
| 687 | unsigned int max_order = (sizeof(long) == 4) ? 30 : 60; | 654 | unsigned int max_order = (sizeof(long) == 4) ? 30 : 60; |
| 688 | | 655 | |
| @@ -747,28 +714,26 @@ static noinline void check_multi_store(struct kunit *test) · 58 unmodified lines |
| 747 | } | 714 | } |
| 748 | | 715 | |
| 749 | for (i = 0; i < 20; i++) { | 716 | for (i = 0; i < 20; i++) { |
| 750 | check_multi_store_1(test, 200, i); | 717 | check_multi_store_1(xa, 200, i); |
| 751 | check_multi_store_1(test, 0, i); | 718 | check_multi_store_1(xa, 0, i); |
| 752 | check_multi_store_1(test, (1UL << i) + 1, i); | 719 | check_multi_store_1(xa, (1UL << i) + 1, i); |
| 753 | } | 720 | } |
| 754 | check_multi_store_2(test, 4095, 9); | 721 | check_multi_store_2(xa, 4095, 9); |
| 755 | | 722 | |
| 756 | for (i = 1; i < 20; i++) { | 723 | for (i = 1; i < 20; i++) { |
| 757 | check_multi_store_3(test, 0, i); | 724 | check_multi_store_3(xa, 0, i); |
| 758 | check_multi_store_3(test, 1UL << i, i); | 725 | check_multi_store_3(xa, 1UL << i, i); |
| 759 | } | 726 | } |
| 760 | #endif | 727 | #endif |
| 761 | } | 728 | } |
| 762 | | 729 | |
| 763 | #ifdef CONFIG_XARRAY_MULTI | 730 | #ifdef CONFIG_XARRAY_MULTI |
| 764 | /* mimics page cache __filemap_add_folio() */ | 731 | /* mimics page cache __filemap_add_folio() */ |
| 765 | static noinline void check_xa_multi_store_adv_add(struct kunit *test, | 732 | static noinline void check_xa_multi_store_adv_add(struct xarray *xa, |
| 766 | unsigned long index, | 733 | unsigned long index, |
| 767 | unsigned int order, | 734 | unsigned int order, |
| 768 | void *p) | 735 | void *p) |
| 769 | { | 736 | { |
| 770 | struct xarray *xa = xa_param(test); | | |
| 771 | | | |
| 772 | XA_STATE(xas, xa, index); | 737 | XA_STATE(xas, xa, index); |
| 773 | unsigned int nrpages = 1UL << order; | 738 | unsigned int nrpages = 1UL << order; |
| 774 | | 739 | |
| @@ -796,12 +761,10 @@ static noinline void check_xa_multi_store_adv_add(struct kunit *test, · 21 unmodified lines |
| 796 | } | 761 | } |
| 797 | | 762 | |
| 798 | /* mimics page_cache_delete() */ | 763 | /* mimics page_cache_delete() */ |
| 799 | static noinline void check_xa_multi_store_adv_del_entry(struct kunit *test, | 764 | static noinline void check_xa_multi_store_adv_del_entry(struct xarray *xa, |
| 800 | unsigned long index, | 765 | unsigned long index, |
| 801 | unsigned int order) | 766 | unsigned int order) |
| 802 | { | 767 | { |
| 803 | struct xarray *xa = xa_param(test); | | |
| 804 | | | |
| 805 | XA_STATE(xas, xa, index); | 768 | XA_STATE(xas, xa, index); |
| 806 | | 769 | |
| 807 | xas_set_order(&xas, index, order); | 770 | xas_set_order(&xas, index, order); |
| @@ -809,14 +772,12 @@ static noinline void check_xa_multi_store_adv_del_entry(struct kunit *test, · 1 unmodified line |
| 809 | xas_init_marks(&xas); | 772 | xas_init_marks(&xas); |
| 810 | } | 773 | } |
| 811 | | 774 | |
| 812 | static noinline void check_xa_multi_store_adv_delete(struct kunit *test, | 775 | static noinline void check_xa_multi_store_adv_delete(struct xarray *xa, |
| 813 | unsigned long index, | 776 | unsigned long index, |
| 814 | unsigned int order) | 777 | unsigned int order) |
| 815 | { | 778 | { |
| 816 | struct xarray *xa = xa_param(test); | | |
| 817 | | | |
| 818 | xa_lock_irq(xa); | 779 | xa_lock_irq(xa); |
| 819 | check_xa_multi_store_adv_del_entry(test, index, order); | 780 | check_xa_multi_store_adv_del_entry(xa, index, order); |
| 820 | xa_unlock_irq(xa); | 781 | xa_unlock_irq(xa); |
| 821 | } | 782 | } |
| 822 | | 783 | |
| @@ -853,12 +814,10 @@ static unsigned long some_val = 0xdeadbeef; · 30 unmodified lines |
| 853 | static unsigned long some_val_2 = 0xdeaddead; | 814 | static unsigned long some_val_2 = 0xdeaddead; |
| 854 | | 815 | |
| 855 | /* mimics the page cache usage */ | 816 | /* mimics the page cache usage */ |
| 856 | static noinline void check_xa_multi_store_adv(struct kunit *test, | 817 | static noinline void check_xa_multi_store_adv(struct xarray *xa, |
| 857 | unsigned long pos, | 818 | unsigned long pos, |
| 858 | unsigned int order) | 819 | unsigned int order) |
| 859 | { | 820 | { |
| 860 | struct xarray *xa = xa_param(test); | | |
| 861 | | | |
| 862 | unsigned int nrpages = 1UL << order; | 821 | unsigned int nrpages = 1UL << order; |
| 863 | unsigned long index, base, next_index, next_next_index; | 822 | unsigned long index, base, next_index, next_next_index; |
| 864 | unsigned int i; | 823 | unsigned int i; |
| @@ -868,7 +827,7 @@ static noinline void check_xa_multi_store_adv(struct kunit *test, · 3 unmodified lines |
| 868 | next_index = round_down(base + nrpages, nrpages); | 827 | next_index = round_down(base + nrpages, nrpages); |
| 869 | next_next_index = round_down(next_index + nrpages, nrpages); | 828 | next_next_index = round_down(next_index + nrpages, nrpages); |
| 870 | | 829 | |
| 871 | check_xa_multi_store_adv_add(test, base, order, &some_val); | 830 | check_xa_multi_store_adv_add(xa, base, order, &some_val); |
| 872 | | 831 | |
| 873 | for (i = 0; i < nrpages; i++) | 832 | for (i = 0; i < nrpages; i++) |
| 874 | XA_BUG_ON(xa, test_get_entry(xa, base + i) != &some_val); | 833 | XA_BUG_ON(xa, test_get_entry(xa, base + i) != &some_val); |
| @@ -876,20 +835,20 @@ static noinline void check_xa_multi_store_adv(struct kunit *test, · 1 unmodified line |
| 876 | XA_BUG_ON(xa, test_get_entry(xa, next_index) != NULL); | 835 | XA_BUG_ON(xa, test_get_entry(xa, next_index) != NULL); |
| 877 | | 836 | |
| 878 | /* Use order 0 for the next item */ | 837 | /* Use order 0 for the next item */ |
| 879 | check_xa_multi_store_adv_add(test, next_index, 0, &some_val_2); | 838 | check_xa_multi_store_adv_add(xa, next_index, 0, &some_val_2); |
| 880 | XA_BUG_ON(xa, test_get_entry(xa, next_index) != &some_val_2); | 839 | XA_BUG_ON(xa, test_get_entry(xa, next_index) != &some_val_2); |
| 881 | | 840 | |
| 882 | /* Remove the next item */ | 841 | /* Remove the next item */ |
| 883 | check_xa_multi_store_adv_delete(test, next_index, 0); | 842 | check_xa_multi_store_adv_delete(xa, next_index, 0); |
| 884 | | 843 | |
| 885 | /* Now use order for a new pointer */ | 844 | /* Now use order for a new pointer */ |
| 886 | check_xa_multi_store_adv_add(test, next_index, order, &some_val_2); | 845 | check_xa_multi_store_adv_add(xa, next_index, order, &some_val_2); |
| 887 | | 846 | |
| 888 | for (i = 0; i < nrpages; i++) | 847 | for (i = 0; i < nrpages; i++) |
| 889 | XA_BUG_ON(xa, test_get_entry(xa, next_index + i) != &some_val_2); | 848 | XA_BUG_ON(xa, test_get_entry(xa, next_index + i) != &some_val_2); |
| 890 | | 849 | |
| 891 | check_xa_multi_store_adv_delete(test, next_index, order); | 850 | check_xa_multi_store_adv_delete(xa, next_index, order); |
| 892 | check_xa_multi_store_adv_delete(test, base, order); | 851 | check_xa_multi_store_adv_delete(xa, base, order); |
| 893 | XA_BUG_ON(xa, !xa_empty(xa)); | 852 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 894 | | 853 | |
| 895 | /* starting fresh again */ | 854 | /* starting fresh again */ |
| @@ -897,7 +856,7 @@ static noinline void check_xa_multi_store_adv(struct kunit *test, · 1 unmodified line |
| 897 | /* let's test some holes now */ | 856 | /* let's test some holes now */ |
| 898 | | 857 | |
| 899 | /* hole at base and next_next */ | 858 | /* hole at base and next_next */ |
| 900 | check_xa_multi_store_adv_add(test, next_index, order, &some_val_2); | 859 | check_xa_multi_store_adv_add(xa, next_index, order, &some_val_2); |
| 901 | | 860 | |
| 902 | for (i = 0; i < nrpages; i++) | 861 | for (i = 0; i < nrpages; i++) |
| 903 | XA_BUG_ON(xa, test_get_entry(xa, base + i) != NULL); | 862 | XA_BUG_ON(xa, test_get_entry(xa, base + i) != NULL); |
| @@ -908,12 +867,12 @@ static noinline void check_xa_multi_store_adv(struct kunit *test, · 4 unmodified lines |
| 908 | for (i = 0; i < nrpages; i++) | 867 | for (i = 0; i < nrpages; i++) |
| 909 | XA_BUG_ON(xa, test_get_entry(xa, next_next_index + i) != NULL); | 868 | XA_BUG_ON(xa, test_get_entry(xa, next_next_index + i) != NULL); |
| 910 | | 869 | |
| 911 | check_xa_multi_store_adv_delete(test, next_index, order); | 870 | check_xa_multi_store_adv_delete(xa, next_index, order); |
| 912 | XA_BUG_ON(xa, !xa_empty(xa)); | 871 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 913 | | 872 | |
| 914 | /* hole at base and next */ | 873 | /* hole at base and next */ |
| 915 | | 874 | |
| 916 | check_xa_multi_store_adv_add(test, next_next_index, order, &some_val_2); | 875 | check_xa_multi_store_adv_add(xa, next_next_index, order, &some_val_2); |
| 917 | | 876 | |
| 918 | for (i = 0; i < nrpages; i++) | 877 | for (i = 0; i < nrpages; i++) |
| 919 | XA_BUG_ON(xa, test_get_entry(xa, base + i) != NULL); | 878 | XA_BUG_ON(xa, test_get_entry(xa, base + i) != NULL); |
| @@ -924,12 +883,12 @@ static noinline void check_xa_multi_store_adv(struct kunit *test, · 4 unmodified lines |
| 924 | for (i = 0; i < nrpages; i++) | 883 | for (i = 0; i < nrpages; i++) |
| 925 | XA_BUG_ON(xa, test_get_entry(xa, next_next_index + i) != &some_val_2); | 884 | XA_BUG_ON(xa, test_get_entry(xa, next_next_index + i) != &some_val_2); |
| 926 | | 885 | |
| 927 | check_xa_multi_store_adv_delete(test, next_next_index, order); | 886 | check_xa_multi_store_adv_delete(xa, next_next_index, order); |
| 928 | XA_BUG_ON(xa, !xa_empty(xa)); | 887 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 929 | } | 888 | } |
| 930 | #endif | 889 | #endif |
| 931 | | 890 | |
| 932 | static noinline void check_multi_store_advanced(struct kunit *test) | 891 | static noinline void check_multi_store_advanced(struct xarray *xa) |
| 933 | { | 892 | { |
| 934 | #ifdef CONFIG_XARRAY_MULTI | 893 | #ifdef CONFIG_XARRAY_MULTI |
| 935 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1; | 894 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1; |
| @@ -941,59 +900,59 @@ static noinline void check_multi_store_advanced(struct kunit *test) · 5 unmodified lines |
| 941 | */ | 900 | */ |
| 942 | for (pos = 7; pos < end; pos = (pos * pos) + 564) { | 901 | for (pos = 7; pos < end; pos = (pos * pos) + 564) { |
| 943 | for (i = 0; i < max_order; i++) { | 902 | for (i = 0; i < max_order; i++) { |
| 944 | check_xa_multi_store_adv(test, pos, i); | 903 | check_xa_multi_store_adv(xa, pos, i); |
| 945 | check_xa_multi_store_adv(test, pos + 157, i); | 904 | check_xa_multi_store_adv(xa, pos + 157, i); |
| 946 | } | 905 | } |
| 947 | } | 906 | } |
| 948 | #endif | 907 | #endif |
| 949 | } | 908 | } |
| 950 | | 909 | |
| 951 | static noinline void check_xa_alloc_1(struct kunit *test, struct xarray *xa, unsigned int base) | 910 | static noinline void check_xa_alloc_1(struct xarray *xa, unsigned int base) |
| 952 | { | 911 | { |
| 953 | int i; | 912 | int i; |
| 954 | u32 id; | 913 | u32 id; |
| 955 | | 914 | |
| 956 | XA_BUG_ON(xa, !xa_empty(xa)); | 915 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 957 | /* An empty array should assign %base to the first alloc */ | 916 | /* An empty array should assign %base to the first alloc */ |
| 958 | xa_alloc_index(test, xa, base, GFP_KERNEL); | 917 | xa_alloc_index(xa, base, GFP_KERNEL); |
| 959 | | 918 | |
| 960 | /* Erasing it should make the array empty again */ | 919 | /* Erasing it should make the array empty again */ |
| 961 | xa_erase_index(test, xa, base); | 920 | xa_erase_index(xa, base); |
| 962 | XA_BUG_ON(xa, !xa_empty(xa)); | 921 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 963 | | 922 | |
| 964 | /* And it should assign %base again */ | 923 | /* And it should assign %base again */ |
| 965 | xa_alloc_index(test, xa, base, GFP_KERNEL); | 924 | xa_alloc_index(xa, base, GFP_KERNEL); |
| 966 | | 925 | |
| 967 | /* Allocating and then erasing a lot should not lose base */ | 926 | /* Allocating and then erasing a lot should not lose base */ |
| 968 | for (i = base + 1; i < 2 * XA_CHUNK_SIZE; i++) | 927 | for (i = base + 1; i < 2 * XA_CHUNK_SIZE; i++) |
| 969 | xa_alloc_index(test, xa, i, GFP_KERNEL); | 928 | xa_alloc_index(xa, i, GFP_KERNEL); |
| 970 | for (i = base; i < 2 * XA_CHUNK_SIZE; i++) | 929 | for (i = base; i < 2 * XA_CHUNK_SIZE; i++) |
| 971 | xa_erase_index(test, xa, i); | 930 | xa_erase_index(xa, i); |
| 972 | xa_alloc_index(test, xa, base, GFP_KERNEL); | 931 | xa_alloc_index(xa, base, GFP_KERNEL); |
| 973 | | 932 | |
| 974 | /* Destroying the array should do the same as erasing */ | 933 | /* Destroying the array should do the same as erasing */ |
| 975 | xa_destroy(xa); | 934 | xa_destroy(xa); |
| 976 | | 935 | |
| 977 | /* And it should assign %base again */ | 936 | /* And it should assign %base again */ |
| 978 | xa_alloc_index(test, xa, base, GFP_KERNEL); | 937 | xa_alloc_index(xa, base, GFP_KERNEL); |
| 979 | | 938 | |
| 980 | /* The next assigned ID should be base+1 */ | 939 | /* The next assigned ID should be base+1 */ |
| 981 | xa_alloc_index(test, xa, base + 1, GFP_KERNEL); | 940 | xa_alloc_index(xa, base + 1, GFP_KERNEL); |
| 982 | xa_erase_index(test, xa, base + 1); | 941 | xa_erase_index(xa, base + 1); |
| 983 | | 942 | |
| 984 | /* Storing a value should mark it used */ | 943 | /* Storing a value should mark it used */ |
| 985 | xa_store_index(xa, base + 1, GFP_KERNEL); | 944 | xa_store_index(xa, base + 1, GFP_KERNEL); |
| 986 | xa_alloc_index(test, xa, base + 2, GFP_KERNEL); | 945 | xa_alloc_index(xa, base + 2, GFP_KERNEL); |
| 987 | | 946 | |
| 988 | /* If we then erase base, it should be free */ | 947 | /* If we then erase base, it should be free */ |
| 989 | xa_erase_index(test, xa, base); | 948 | xa_erase_index(xa, base); |
| 990 | xa_alloc_index(test, xa, base, GFP_KERNEL); | 949 | xa_alloc_index(xa, base, GFP_KERNEL); |
| 991 | | 950 | |
| 992 | xa_erase_index(test, xa, base + 1); | 951 | xa_erase_index(xa, base + 1); |
| 993 | xa_erase_index(test, xa, base + 2); | 952 | xa_erase_index(xa, base + 2); |
| 994 | | 953 | |
| 995 | for (i = 1; i < 5000; i++) { | 954 | for (i = 1; i < 5000; i++) { |
| 996 | xa_alloc_index(test, xa, base + i, GFP_KERNEL); | 955 | xa_alloc_index(xa, base + i, GFP_KERNEL); |
| 997 | } | 956 | } |
| 998 | | 957 | |
| 999 | xa_destroy(xa); | 958 | xa_destroy(xa); |
| @@ -1016,14 +975,14 @@ static noinline void check_xa_alloc_1(struct kunit *test, struct xarray *xa, uns · 16 unmodified lines |
| 1016 | | 975 | |
| 1017 | XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(10), XA_LIMIT(10, 5), | 976 | XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(10), XA_LIMIT(10, 5), |
| 1018 | GFP_KERNEL) != -EBUSY); | 977 | GFP_KERNEL) != -EBUSY); |
| 1019 | XA_BUG_ON(xa, xa_store_index(xa, 3, GFP_KERNEL) != NULL); | 978 | XA_BUG_ON(xa, xa_store_index(xa, 3, GFP_KERNEL) != 0); |
| 1020 | XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(10), XA_LIMIT(10, 5), | 979 | XA_BUG_ON(xa, xa_alloc(xa, &id, xa_mk_index(10), XA_LIMIT(10, 5), |
| 1021 | GFP_KERNEL) != -EBUSY); | 980 | GFP_KERNEL) != -EBUSY); |
| 1022 | xa_erase_index(test, xa, 3); | 981 | xa_erase_index(xa, 3); |
| 1023 | XA_BUG_ON(xa, !xa_empty(xa)); | 982 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1024 | } | 983 | } |
| 1025 | | 984 | |
| 1026 | static noinline void check_xa_alloc_2(struct kunit *test, struct xarray *xa, unsigned int base) | 985 | static noinline void check_xa_alloc_2(struct xarray *xa, unsigned int base) |
| 1027 | { | 986 | { |
| 1028 | unsigned int i, id; | 987 | unsigned int i, id; |
| 1029 | unsigned long index; | 988 | unsigned long index; |
| @@ -1059,7 +1018,7 @@ static noinline void check_xa_alloc_2(struct kunit *test, struct xarray *xa, uns · 29 unmodified lines |
| 1059 | XA_BUG_ON(xa, id != 5); | 1018 | XA_BUG_ON(xa, id != 5); |
| 1060 | | 1019 | |
| 1061 | xa_for_each(xa, index, entry) { | 1020 | xa_for_each(xa, index, entry) { |
| 1062 | xa_erase_index(test, xa, index); | 1021 | xa_erase_index(xa, index); |
| 1063 | } | 1022 | } |
| 1064 | | 1023 | |
| 1065 | for (i = base; i < base + 9; i++) { | 1024 | for (i = base; i < base + 9; i++) { |
| @@ -1074,7 +1033,7 @@ static noinline void check_xa_alloc_2(struct kunit *test, struct xarray *xa, uns · 8 unmodified lines |
| 1074 | xa_destroy(xa); | 1033 | xa_destroy(xa); |
| 1075 | } | 1034 | } |
| 1076 | | 1035 | |
| 1077 | static noinline void check_xa_alloc_3(struct kunit *test, struct xarray *xa, unsigned int base) | 1036 | static noinline void check_xa_alloc_3(struct xarray *xa, unsigned int base) |
| 1078 | { | 1037 | { |
| 1079 | struct xa_limit limit = XA_LIMIT(1, 0x3fff); | 1038 | struct xa_limit limit = XA_LIMIT(1, 0x3fff); |
| 1080 | u32 next = 0; | 1039 | u32 next = 0; |
| @@ -1090,8 +1049,8 @@ static noinline void check_xa_alloc_3(struct kunit *test, struct xarray *xa, uns · 9 unmodified lines |
| 1090 | XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(0x3ffd), limit, | 1049 | XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(0x3ffd), limit, |
| 1091 | &next, GFP_KERNEL) != 0); | 1050 | &next, GFP_KERNEL) != 0); |
| 1092 | XA_BUG_ON(xa, id != 0x3ffd); | 1051 | XA_BUG_ON(xa, id != 0x3ffd); |
| 1093 | xa_erase_index(test, xa, 0x3ffd); | 1052 | xa_erase_index(xa, 0x3ffd); |
| 1094 | xa_erase_index(test, xa, 1); | 1053 | xa_erase_index(xa, 1); |
| 1095 | XA_BUG_ON(xa, !xa_empty(xa)); | 1054 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1096 | | 1055 | |
| 1097 | for (i = 0x3ffe; i < 0x4003; i++) { | 1056 | for (i = 0x3ffe; i < 0x4003; i++) { |
| @@ -1106,8 +1065,8 @@ static noinline void check_xa_alloc_3(struct kunit *test, struct xarray *xa, uns · 8 unmodified lines |
| 1106 | | 1065 | |
| 1107 | /* Check wrap-around is handled correctly */ | 1066 | /* Check wrap-around is handled correctly */ |
| 1108 | if (base != 0) | 1067 | if (base != 0) |
| 1109 | xa_erase_index(test, xa, base); | 1068 | xa_erase_index(xa, base); |
| 1110 | xa_erase_index(test, xa, base + 1); | 1069 | xa_erase_index(xa, base + 1); |
| 1111 | next = UINT_MAX; | 1070 | next = UINT_MAX; |
| 1112 | XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(UINT_MAX), | 1071 | XA_BUG_ON(xa, xa_alloc_cyclic(xa, &id, xa_mk_index(UINT_MAX), |
| 1113 | xa_limit_32b, &next, GFP_KERNEL) != 0); | 1072 | xa_limit_32b, &next, GFP_KERNEL) != 0); |
| @@ -1120,7 +1079,7 @@ static noinline void check_xa_alloc_3(struct kunit *test, struct xarray *xa, uns · 6 unmodified lines |
| 1120 | XA_BUG_ON(xa, id != base + 1); | 1079 | XA_BUG_ON(xa, id != base + 1); |
| 1121 | | 1080 | |
| 1122 | xa_for_each(xa, index, entry) | 1081 | xa_for_each(xa, index, entry) |
| 1123 | xa_erase_index(test, xa, index); | 1082 | xa_erase_index(xa, index); |
| 1124 | | 1083 | |
| 1125 | XA_BUG_ON(xa, !xa_empty(xa)); | 1084 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1126 | } | 1085 | } |
| @@ -1128,21 +1087,19 @@ static noinline void check_xa_alloc_3(struct kunit *test, struct xarray *xa, uns · 1 unmodified line |
| 1128 | static DEFINE_XARRAY_ALLOC(xa0); | 1087 | static DEFINE_XARRAY_ALLOC(xa0); |
| 1129 | static DEFINE_XARRAY_ALLOC1(xa1); | 1088 | static DEFINE_XARRAY_ALLOC1(xa1); |
| 1130 | | 1089 | |
| 1131 | static noinline void check_xa_alloc(struct kunit *test) | 1090 | static noinline void check_xa_alloc(void) |
| 1132 | { | 1091 | { |
| 1133 | check_xa_alloc_1(test, &xa0, 0); | 1092 | check_xa_alloc_1(&xa0, 0); |
| 1134 | check_xa_alloc_1(test, &xa1, 1); | 1093 | check_xa_alloc_1(&xa1, 1); |
| 1135 | check_xa_alloc_2(test, &xa0, 0); | 1094 | check_xa_alloc_2(&xa0, 0); |
| 1136 | check_xa_alloc_2(test, &xa1, 1); | 1095 | check_xa_alloc_2(&xa1, 1); |
| 1137 | check_xa_alloc_3(test, &xa0, 0); | 1096 | check_xa_alloc_3(&xa0, 0); |
| 1138 | check_xa_alloc_3(test, &xa1, 1); | 1097 | check_xa_alloc_3(&xa1, 1); |
| 1139 | } | 1098 | } |
| 1140 | | 1099 | |
| 1141 | static noinline void __check_store_iter(struct kunit *test, unsigned long start, | 1100 | static noinline void __check_store_iter(struct xarray *xa, unsigned long start, |
| 1142 | unsigned int order, unsigned int present) | 1101 | unsigned int order, unsigned int present) |
| 1143 | { | 1102 | { |
| 1144 | struct xarray *xa = xa_param(test); | | |
| 1145 | | | |
| 1146 | XA_STATE_ORDER(xas, xa, start, order); | 1103 | XA_STATE_ORDER(xas, xa, start, order); |
| 1147 | void *entry; | 1104 | void *entry; |
| 1148 | unsigned int count = 0; | 1105 | unsigned int count = 0; |
| @@ -1166,54 +1123,50 @@ retry: · 17 unmodified lines |
| 1166 | XA_BUG_ON(xa, xa_load(xa, start) != xa_mk_index(start)); | 1123 | XA_BUG_ON(xa, xa_load(xa, start) != xa_mk_index(start)); |
| 1167 | XA_BUG_ON(xa, xa_load(xa, start + (1UL << order) - 1) != | 1124 | XA_BUG_ON(xa, xa_load(xa, start + (1UL << order) - 1) != |
| 1168 | xa_mk_index(start)); | 1125 | xa_mk_index(start)); |
| 1169 | xa_erase_index(test, xa, start); | 1126 | xa_erase_index(xa, start); |
| 1170 | } | 1127 | } |
| 1171 | | 1128 | |
| 1172 | static noinline void check_store_iter(struct kunit *test) | 1129 | static noinline void check_store_iter(struct xarray *xa) |
| 1173 | { | 1130 | { |
| 1174 | struct xarray *xa = xa_param(test); | | |
| 1175 | | | |
| 1176 | unsigned int i, j; | 1131 | unsigned int i, j; |
| 1177 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1; | 1132 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1; |
| 1178 | | 1133 | |
| 1179 | for (i = 0; i < max_order; i++) { | 1134 | for (i = 0; i < max_order; i++) { |
| 1180 | unsigned int min = 1 << i; | 1135 | unsigned int min = 1 << i; |
| 1181 | unsigned int max = (2 << i) - 1; | 1136 | unsigned int max = (2 << i) - 1; |
| 1182 | __check_store_iter(test, 0, i, 0); | 1137 | __check_store_iter(xa, 0, i, 0); |
| 1183 | XA_BUG_ON(xa, !xa_empty(xa)); | 1138 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1184 | __check_store_iter(test, min, i, 0); | 1139 | __check_store_iter(xa, min, i, 0); |
| 1185 | XA_BUG_ON(xa, !xa_empty(xa)); | 1140 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1186 | | 1141 | |
| 1187 | xa_store_index(xa, min, GFP_KERNEL); | 1142 | xa_store_index(xa, min, GFP_KERNEL); |
| 1188 | __check_store_iter(test, min, i, 1); | 1143 | __check_store_iter(xa, min, i, 1); |
| 1189 | XA_BUG_ON(xa, !xa_empty(xa)); | 1144 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1190 | xa_store_index(xa, max, GFP_KERNEL); | 1145 | xa_store_index(xa, max, GFP_KERNEL); |
| 1191 | __check_store_iter(test, min, i, 1); | 1146 | __check_store_iter(xa, min, i, 1); |
| 1192 | XA_BUG_ON(xa, !xa_empty(xa)); | 1147 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1193 | | 1148 | |
| 1194 | for (j = 0; j < min; j++) | 1149 | for (j = 0; j < min; j++) |
| 1195 | xa_store_index(xa, j, GFP_KERNEL); | 1150 | xa_store_index(xa, j, GFP_KERNEL); |
| 1196 | __check_store_iter(test, 0, i, min); | 1151 | __check_store_iter(xa, 0, i, min); |
| 1197 | XA_BUG_ON(xa, !xa_empty(xa)); | 1152 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1198 | for (j = 0; j < min; j++) | 1153 | for (j = 0; j < min; j++) |
| 1199 | xa_store_index(xa, min + j, GFP_KERNEL); | 1154 | xa_store_index(xa, min + j, GFP_KERNEL); |
| 1200 | __check_store_iter(test, min, i, min); | 1155 | __check_store_iter(xa, min, i, min); |
| 1201 | XA_BUG_ON(xa, !xa_empty(xa)); | 1156 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1202 | } | 1157 | } |
| 1203 | #ifdef CONFIG_XARRAY_MULTI | 1158 | #ifdef CONFIG_XARRAY_MULTI |
| 1204 | xa_store_index(xa, 63, GFP_KERNEL); | 1159 | xa_store_index(xa, 63, GFP_KERNEL); |
| 1205 | xa_store_index(xa, 65, GFP_KERNEL); | 1160 | xa_store_index(xa, 65, GFP_KERNEL); |
| 1206 | __check_store_iter(test, 64, 2, 1); | 1161 | __check_store_iter(xa, 64, 2, 1); |
| 1207 | xa_erase_index(test, xa, 63); | 1162 | xa_erase_index(xa, 63); |
| 1208 | #endif | 1163 | #endif |
| 1209 | XA_BUG_ON(xa, !xa_empty(xa)); | 1164 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1210 | } | 1165 | } |
| 1211 | | 1166 | |
| 1212 | static noinline void check_multi_find_1(struct kunit *test, unsigned int order) | 1167 | static noinline void check_multi_find_1(struct xarray *xa, unsigned order) |
| 1213 | { | 1168 | { |
| 1214 | #ifdef CONFIG_XARRAY_MULTI | 1169 | #ifdef CONFIG_XARRAY_MULTI |
| 1215 | struct xarray *xa = xa_param(test); | | |
| 1216 | | | |
| 1217 | unsigned long multi = 3 << order; | 1170 | unsigned long multi = 3 << order; |
| 1218 | unsigned long next = 4 << order; | 1171 | unsigned long next = 4 << order; |
| 1219 | unsigned long index; | 1172 | unsigned long index; |
| @@ -1236,17 +1189,15 @@ static noinline void check_multi_find_1(struct kunit *test, unsigned int order) · 16 unmodified lines |
| 1236 | XA_BUG_ON(xa, xa_find_after(xa, &index, next, XA_PRESENT) != NULL); | 1189 | XA_BUG_ON(xa, xa_find_after(xa, &index, next, XA_PRESENT) != NULL); |
| 1237 | XA_BUG_ON(xa, index != next); | 1190 | XA_BUG_ON(xa, index != next); |
| 1238 | | 1191 | |
| 1239 | xa_erase_index(test, xa, multi); | 1192 | xa_erase_index(xa, multi); |
| 1240 | xa_erase_index(test, xa, next); | 1193 | xa_erase_index(xa, next); |
| 1241 | xa_erase_index(test, xa, next + 1); | 1194 | xa_erase_index(xa, next + 1); |
| 1242 | XA_BUG_ON(xa, !xa_empty(xa)); | 1195 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1243 | #endif | 1196 | #endif |
| 1244 | } | 1197 | } |
| 1245 | | 1198 | |
| 1246 | static noinline void check_multi_find_2(struct kunit *test) | 1199 | static noinline void check_multi_find_2(struct xarray *xa) |
| 1247 | { | 1200 | { |
| 1248 | struct xarray *xa = xa_param(test); | | |
| 1249 | | | |
| 1250 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 10 : 1; | 1201 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 10 : 1; |
| 1251 | unsigned int i, j; | 1202 | unsigned int i, j; |
| 1252 | void *entry; | 1203 | void *entry; |
| @@ -1260,19 +1211,17 @@ static noinline void check_multi_find_2(struct kunit *test) · 7 unmodified lines |
| 1260 | GFP_KERNEL); | 1211 | GFP_KERNEL); |
| 1261 | rcu_read_lock(); | 1212 | rcu_read_lock(); |
| 1262 | xas_for_each(&xas, entry, ULONG_MAX) { | 1213 | xas_for_each(&xas, entry, ULONG_MAX) { |
| 1263 | xa_erase_index(test, xa, index); | 1214 | xa_erase_index(xa, index); |
| 1264 | } | 1215 | } |
| 1265 | rcu_read_unlock(); | 1216 | rcu_read_unlock(); |
| 1266 | xa_erase_index(test, xa, index - 1); | 1217 | xa_erase_index(xa, index - 1); |
| 1267 | XA_BUG_ON(xa, !xa_empty(xa)); | 1218 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1268 | } | 1219 | } |
| 1269 | } | 1220 | } |
| 1270 | } | 1221 | } |
| 1271 | | 1222 | |
| 1272 | static noinline void check_multi_find_3(struct kunit *test) | 1223 | static noinline void check_multi_find_3(struct xarray *xa) |
| 1273 | { | 1224 | { |
| 1274 | struct xarray *xa = xa_param(test); | | |
| 1275 | | | |
| 1276 | unsigned int order; | 1225 | unsigned int order; |
| 1277 | | 1226 | |
| 1278 | for (order = 5; order < order_limit; order++) { | 1227 | for (order = 5; order < order_limit; order++) { |
| @@ -1281,14 +1230,12 @@ static noinline void check_multi_find_3(struct kunit *test) · 2 unmodified lines |
| 1281 | XA_BUG_ON(xa, !xa_empty(xa)); | 1230 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1282 | xa_store_order(xa, 0, order - 4, xa_mk_index(0), GFP_KERNEL); | 1231 | xa_store_order(xa, 0, order - 4, xa_mk_index(0), GFP_KERNEL); |
| 1283 | XA_BUG_ON(xa, xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT)); | 1232 | XA_BUG_ON(xa, xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT)); |
| 1284 | xa_erase_index(test, xa, 0); | 1233 | xa_erase_index(xa, 0); |
| 1285 | } | 1234 | } |
| 1286 | } | 1235 | } |
| 1287 | | 1236 | |
| 1288 | static noinline void check_find_1(struct kunit *test) | 1237 | static noinline void check_find_1(struct xarray *xa) |
| 1289 | { | 1238 | { |
| 1290 | struct xarray *xa = xa_param(test); | | |
| 1291 | | | |
| 1292 | unsigned long i, j, k; | 1239 | unsigned long i, j, k; |
| 1293 | | 1240 | |
| 1294 | XA_BUG_ON(xa, !xa_empty(xa)); | 1241 | XA_BUG_ON(xa, !xa_empty(xa)); |
| @@ -1325,20 +1272,18 @@ static noinline void check_find_1(struct kunit *test) · 30 unmodified lines |
| 1325 | else | 1272 | else |
| 1326 | XA_BUG_ON(xa, entry != NULL); | 1273 | XA_BUG_ON(xa, entry != NULL); |
| 1327 | } | 1274 | } |
| 1328 | xa_erase_index(test, xa, j); | 1275 | xa_erase_index(xa, j); |
| 1329 | XA_BUG_ON(xa, xa_get_mark(xa, j, XA_MARK_0)); | 1276 | XA_BUG_ON(xa, xa_get_mark(xa, j, XA_MARK_0)); |
| 1330 | XA_BUG_ON(xa, !xa_get_mark(xa, i, XA_MARK_0)); | 1277 | XA_BUG_ON(xa, !xa_get_mark(xa, i, XA_MARK_0)); |
| 1331 | } | 1278 | } |
| 1332 | xa_erase_index(test, xa, i); | 1279 | xa_erase_index(xa, i); |
| 1333 | XA_BUG_ON(xa, xa_get_mark(xa, i, XA_MARK_0)); | 1280 | XA_BUG_ON(xa, xa_get_mark(xa, i, XA_MARK_0)); |
| 1334 | } | 1281 | } |
| 1335 | XA_BUG_ON(xa, !xa_empty(xa)); | 1282 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1336 | } | 1283 | } |
| 1337 | | 1284 | |
| 1338 | static noinline void check_find_2(struct kunit *test) | 1285 | static noinline void check_find_2(struct xarray *xa) |
| 1339 | { | 1286 | { |
| 1340 | struct xarray *xa = xa_param(test); | | |
| 1341 | | | |
| 1342 | void *entry; | 1287 | void *entry; |
| 1343 | unsigned long i, j, index; | 1288 | unsigned long i, j, index; |
| 1344 | | 1289 | |
| @@ -1358,10 +1303,8 @@ static noinline void check_find_2(struct kunit *test) · 13 unmodified lines |
| 1358 | xa_destroy(xa); | 1303 | xa_destroy(xa); |
| 1359 | } | 1304 | } |
| 1360 | | 1305 | |
| 1361 | static noinline void check_find_3(struct kunit *test) | 1306 | static noinline void check_find_3(struct xarray *xa) |
| 1362 | { | 1307 | { |
| 1363 | struct xarray *xa = xa_param(test); | | |
| 1364 | | | |
| 1365 | XA_STATE(xas, xa, 0); | 1308 | XA_STATE(xas, xa, 0); |
| 1366 | unsigned long i, j, k; | 1309 | unsigned long i, j, k; |
| 1367 | void *entry; | 1310 | void *entry; |
| @@ -1385,10 +1328,8 @@ static noinline void check_find_3(struct kunit *test) · 17 unmodified lines |
| 1385 | xa_destroy(xa); | 1328 | xa_destroy(xa); |
| 1386 | } | 1329 | } |
| 1387 | | 1330 | |
| 1388 | static noinline void check_find_4(struct kunit *test) | 1331 | static noinline void check_find_4(struct xarray *xa) |
| 1389 | { | 1332 | { |
| 1390 | struct xarray *xa = xa_param(test); | | |
| 1391 | | | |
| 1392 | unsigned long index = 0; | 1333 | unsigned long index = 0; |
| 1393 | void *entry; | 1334 | void *entry; |
| 1394 | | 1335 | |
| @@ -1400,22 +1341,22 @@ static noinline void check_find_4(struct kunit *test) · 5 unmodified lines |
| 1400 | entry = xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT); | 1341 | entry = xa_find_after(xa, &index, ULONG_MAX, XA_PRESENT); |
| 1401 | XA_BUG_ON(xa, entry); | 1342 | XA_BUG_ON(xa, entry); |
| 1402 | | 1343 | |
| 1403 | xa_erase_index(test, xa, ULONG_MAX); | 1344 | xa_erase_index(xa, ULONG_MAX); |
| 1404 | } | 1345 | } |
| 1405 | | 1346 | |
| 1406 | static noinline void check_find(struct kunit *test) | 1347 | static noinline void check_find(struct xarray *xa) |
| 1407 | { | 1348 | { |
| 1408 | unsigned i; | 1349 | unsigned i; |
| 1409 | | 1350 | |
| 1410 | check_find_1(test); | 1351 | check_find_1(xa); |
| 1411 | check_find_2(test); | 1352 | check_find_2(xa); |
| 1412 | check_find_3(test); | 1353 | check_find_3(xa); |
| 1413 | check_find_4(test); | 1354 | check_find_4(xa); |
| 1414 | | 1355 | |
| 1415 | for (i = 2; i < 10; i++) | 1356 | for (i = 2; i < 10; i++) |
| 1416 | check_multi_find_1(test, i); | 1357 | check_multi_find_1(xa, i); |
| 1417 | check_multi_find_2(test); | 1358 | check_multi_find_2(xa); |
| 1418 | check_multi_find_3(test); | 1359 | check_multi_find_3(xa); |
| 1419 | } | 1360 | } |
| 1420 | | 1361 | |
| 1421 | /* See find_swap_entry() in mm/shmem.c */ | 1362 | /* See find_swap_entry() in mm/shmem.c */ |
| @@ -1441,10 +1382,8 @@ static noinline unsigned long xa_find_entry(struct xarray *xa, void *item) · 19 unmodified lines |
| 1441 | return entry ? xas.xa_index : -1; | 1382 | return entry ? xas.xa_index : -1; |
| 1442 | } | 1383 | } |
| 1443 | | 1384 | |
| 1444 | static noinline void check_find_entry(struct kunit *test) | 1385 | static noinline void check_find_entry(struct xarray *xa) |
| 1445 | { | 1386 | { |
| 1446 | struct xarray *xa = xa_param(test); | | |
| 1447 | | | |
| 1448 | #ifdef CONFIG_XARRAY_MULTI | 1387 | #ifdef CONFIG_XARRAY_MULTI |
| 1449 | unsigned int order; | 1388 | unsigned int order; |
| 1450 | unsigned long offset, index; | 1389 | unsigned long offset, index; |
| @@ -1471,14 +1410,12 @@ static noinline void check_find_entry(struct kunit *test) · 20 unmodified lines |
| 1471 | xa_store_index(xa, ULONG_MAX, GFP_KERNEL); | 1410 | xa_store_index(xa, ULONG_MAX, GFP_KERNEL); |
| 1472 | XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1); | 1411 | XA_BUG_ON(xa, xa_find_entry(xa, xa) != -1); |
| 1473 | XA_BUG_ON(xa, xa_find_entry(xa, xa_mk_index(ULONG_MAX)) != -1); | 1412 | XA_BUG_ON(xa, xa_find_entry(xa, xa_mk_index(ULONG_MAX)) != -1); |
| 1474 | xa_erase_index(test, xa, ULONG_MAX); | 1413 | xa_erase_index(xa, ULONG_MAX); |
| 1475 | XA_BUG_ON(xa, !xa_empty(xa)); | 1414 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1476 | } | 1415 | } |
| 1477 | | 1416 | |
| 1478 | static noinline void check_pause(struct kunit *test) | 1417 | static noinline void check_pause(struct xarray *xa) |
| 1479 | { | 1418 | { |
| 1480 | struct xarray *xa = xa_param(test); | | |
| 1481 | | | |
| 1482 | XA_STATE(xas, xa, 0); | 1419 | XA_STATE(xas, xa, 0); |
| 1483 | void *entry; | 1420 | void *entry; |
| 1484 | unsigned int order; | 1421 | unsigned int order; |
| @@ -1548,10 +1485,8 @@ static noinline void check_pause(struct kunit *test) · 63 unmodified lines |
| 1548 | | 1485 | |
| 1549 | } | 1486 | } |
| 1550 | | 1487 | |
| 1551 | static noinline void check_move_tiny(struct kunit *test) | 1488 | static noinline void check_move_tiny(struct xarray *xa) |
| 1552 | { | 1489 | { |
| 1553 | struct xarray *xa = xa_param(test); | | |
| 1554 | | | |
| 1555 | XA_STATE(xas, xa, 0); | 1490 | XA_STATE(xas, xa, 0); |
| 1556 | | 1491 | |
| 1557 | XA_BUG_ON(xa, !xa_empty(xa)); | 1492 | XA_BUG_ON(xa, !xa_empty(xa)); |
| @@ -1568,14 +1503,12 @@ static noinline void check_move_tiny(struct kunit *test) · 10 unmodified lines |
| 1568 | XA_BUG_ON(xa, xas_prev(&xas) != xa_mk_index(0)); | 1503 | XA_BUG_ON(xa, xas_prev(&xas) != xa_mk_index(0)); |
| 1569 | XA_BUG_ON(xa, xas_prev(&xas) != NULL); | 1504 | XA_BUG_ON(xa, xas_prev(&xas) != NULL); |
| 1570 | rcu_read_unlock(); | 1505 | rcu_read_unlock(); |
| 1571 | xa_erase_index(test, xa, 0); | 1506 | xa_erase_index(xa, 0); |
| 1572 | XA_BUG_ON(xa, !xa_empty(xa)); | 1507 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1573 | } | 1508 | } |
| 1574 | | 1509 | |
| 1575 | static noinline void check_move_max(struct kunit *test) | 1510 | static noinline void check_move_max(struct xarray *xa) |
| 1576 | { | 1511 | { |
| 1577 | struct xarray *xa = xa_param(test); | | |
| 1578 | | | |
| 1579 | XA_STATE(xas, xa, 0); | 1512 | XA_STATE(xas, xa, 0); |
| 1580 | | 1513 | |
| 1581 | xa_store_index(xa, ULONG_MAX, GFP_KERNEL); | 1514 | xa_store_index(xa, ULONG_MAX, GFP_KERNEL); |
| @@ -1591,14 +1524,12 @@ static noinline void check_move_max(struct kunit *test) · 9 unmodified lines |
| 1591 | XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != NULL); | 1524 | XA_BUG_ON(xa, xas_find(&xas, ULONG_MAX) != NULL); |
| 1592 | rcu_read_unlock(); | 1525 | rcu_read_unlock(); |
| 1593 | | 1526 | |
| 1594 | xa_erase_index(test, xa, ULONG_MAX); | 1527 | xa_erase_index(xa, ULONG_MAX); |
| 1595 | XA_BUG_ON(xa, !xa_empty(xa)); | 1528 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1596 | } | 1529 | } |
| 1597 | | 1530 | |
| 1598 | static noinline void check_move_small(struct kunit *test, unsigned long idx) | 1531 | static noinline void check_move_small(struct xarray *xa, unsigned long idx) |
| 1599 | { | 1532 | { |
| 1600 | struct xarray *xa = xa_param(test); | | |
| 1601 | | | |
| 1602 | XA_STATE(xas, xa, 0); | 1533 | XA_STATE(xas, xa, 0); |
| 1603 | unsigned long i; | 1534 | unsigned long i; |
| 1604 | | 1535 | |
| @@ -1640,15 +1571,13 @@ static noinline void check_move_small(struct kunit *test, unsigned long idx) · 35 unmodified lines |
| 1640 | XA_BUG_ON(xa, xas.xa_index != ULONG_MAX); | 1571 | XA_BUG_ON(xa, xas.xa_index != ULONG_MAX); |
| 1641 | rcu_read_unlock(); | 1572 | rcu_read_unlock(); |
| 1642 | | 1573 | |
| 1643 | xa_erase_index(test, xa, 0); | 1574 | xa_erase_index(xa, 0); |
| 1644 | xa_erase_index(test, xa, idx); | 1575 | xa_erase_index(xa, idx); |
| 1645 | XA_BUG_ON(xa, !xa_empty(xa)); | 1576 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1646 | } | 1577 | } |
| 1647 | | 1578 | |
| 1648 | static noinline void check_move(struct kunit *test) | 1579 | static noinline void check_move(struct xarray *xa) |
| 1649 | { | 1580 | { |
| 1650 | struct xarray *xa = xa_param(test); | | |
| 1651 | | | |
| 1652 | XA_STATE(xas, xa, (1 << 16) - 1); | 1581 | XA_STATE(xas, xa, (1 << 16) - 1); |
| 1653 | unsigned long i; | 1582 | unsigned long i; |
| 1654 | | 1583 | |
| @@ -1675,7 +1604,7 @@ static noinline void check_move(struct kunit *test) · 20 unmodified lines |
| 1675 | rcu_read_unlock(); | 1604 | rcu_read_unlock(); |
| 1676 | | 1605 | |
| 1677 | for (i = (1 << 8); i < (1 << 15); i++) | 1606 | for (i = (1 << 8); i < (1 << 15); i++) |
| 1678 | xa_erase_index(test, xa, i); | 1607 | xa_erase_index(xa, i); |
| 1679 | | 1608 | |
| 1680 | i = xas.xa_index; | 1609 | i = xas.xa_index; |
| 1681 | | 1610 | |
| @@ -1706,17 +1635,17 @@ static noinline void check_move(struct kunit *test) · 24 unmodified lines |
| 1706 | | 1635 | |
| 1707 | xa_destroy(xa); | 1636 | xa_destroy(xa); |
| 1708 | | 1637 | |
| 1709 | check_move_tiny(test); | 1638 | check_move_tiny(xa); |
| 1710 | check_move_max(test); | 1639 | check_move_max(xa); |
| 1711 | | 1640 | |
| 1712 | for (i = 0; i < 16; i++) | 1641 | for (i = 0; i < 16; i++) |
| 1713 | check_move_small(test, 1UL << i); | 1642 | check_move_small(xa, 1UL << i); |
| 1714 | | 1643 | |
| 1715 | for (i = 2; i < 16; i++) | 1644 | for (i = 2; i < 16; i++) |
| 1716 | check_move_small(test, (1UL << i) - 1); | 1645 | check_move_small(xa, (1UL << i) - 1); |
| 1717 | } | 1646 | } |
| 1718 | | 1647 | |
| 1719 | static noinline void xa_store_many_order(struct kunit *test, struct xarray *xa, | 1648 | static noinline void xa_store_many_order(struct xarray *xa, |
| 1720 | unsigned long index, unsigned order) | 1649 | unsigned long index, unsigned order) |
| 1721 | { | 1650 | { |
| 1722 | XA_STATE_ORDER(xas, xa, index, order); | 1651 | XA_STATE_ORDER(xas, xa, index, order); |
| @@ -1739,34 +1668,30 @@ unlock: · 16 unmodified lines |
| 1739 | XA_BUG_ON(xa, xas_error(&xas)); | 1668 | XA_BUG_ON(xa, xas_error(&xas)); |
| 1740 | } | 1669 | } |
| 1741 | | 1670 | |
| 1742 | static noinline void check_create_range_1(struct kunit *test, | 1671 | static noinline void check_create_range_1(struct xarray *xa, |
| 1743 | unsigned long index, unsigned order) | 1672 | unsigned long index, unsigned order) |
| 1744 | { | 1673 | { |
| 1745 | struct xarray *xa = xa_param(test); | | |
| 1746 | | | |
| 1747 | unsigned long i; | 1674 | unsigned long i; |
| 1748 | | 1675 | |
| 1749 | xa_store_many_order(test, xa, index, order); | 1676 | xa_store_many_order(xa, index, order); |
| 1750 | for (i = index; i < index + (1UL << order); i++) | 1677 | for (i = index; i < index + (1UL << order); i++) |
| 1751 | xa_erase_index(test, xa, i); | 1678 | xa_erase_index(xa, i); |
| 1752 | XA_BUG_ON(xa, !xa_empty(xa)); | 1679 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1753 | } | 1680 | } |
| 1754 | | 1681 | |
| 1755 | static noinline void check_create_range_2(struct kunit *test, unsigned int order) | 1682 | static noinline void check_create_range_2(struct xarray *xa, unsigned order) |
| 1756 | { | 1683 | { |
| 1757 | struct xarray *xa = xa_param(test); | | |
| 1758 | | | |
| 1759 | unsigned long i; | 1684 | unsigned long i; |
| 1760 | unsigned long nr = 1UL << order; | 1685 | unsigned long nr = 1UL << order; |
| 1761 | | 1686 | |
| 1762 | for (i = 0; i < nr * nr; i += nr) | 1687 | for (i = 0; i < nr * nr; i += nr) |
| 1763 | xa_store_many_order(test, xa, i, order); | 1688 | xa_store_many_order(xa, i, order); |
| 1764 | for (i = 0; i < nr * nr; i++) | 1689 | for (i = 0; i < nr * nr; i++) |
| 1765 | xa_erase_index(test, xa, i); | 1690 | xa_erase_index(xa, i); |
| 1766 | XA_BUG_ON(xa, !xa_empty(xa)); | 1691 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1767 | } | 1692 | } |
| 1768 | | 1693 | |
| 1769 | static noinline void check_create_range_3(struct kunit *test) | 1694 | static noinline void check_create_range_3(void) |
| 1770 | { | 1695 | { |
| 1771 | XA_STATE(xas, NULL, 0); | 1696 | XA_STATE(xas, NULL, 0); |
| 1772 | xas_set_err(&xas, -EEXIST); | 1697 | xas_set_err(&xas, -EEXIST); |
| @@ -1774,11 +1699,9 @@ static noinline void check_create_range_3(struct kunit *test) · 1 unmodified line |
| 1774 | XA_BUG_ON(NULL, xas_error(&xas) != -EEXIST); | 1699 | XA_BUG_ON(NULL, xas_error(&xas) != -EEXIST); |
| 1775 | } | 1700 | } |
| 1776 | | 1701 | |
| 1777 | static noinline void check_create_range_4(struct kunit *test, | 1702 | static noinline void check_create_range_4(struct xarray *xa, |
| 1778 | unsigned long index, unsigned order) | 1703 | unsigned long index, unsigned order) |
| 1779 | { | 1704 | { |
| 1780 | struct xarray *xa = xa_param(test); | | |
| 1781 | | | |
| 1782 | XA_STATE_ORDER(xas, xa, index, order); | 1705 | XA_STATE_ORDER(xas, xa, index, order); |
| 1783 | unsigned long base = xas.xa_index; | 1706 | unsigned long base = xas.xa_index; |
| 1784 | unsigned long i = 0; | 1707 | unsigned long i = 0; |
| @@ -1804,15 +1727,13 @@ unlock: · 19 unmodified lines |
| 1804 | XA_BUG_ON(xa, xas_error(&xas)); | 1727 | XA_BUG_ON(xa, xas_error(&xas)); |
| 1805 | | 1728 | |
| 1806 | for (i = base; i < base + (1UL << order); i++) | 1729 | for (i = base; i < base + (1UL << order); i++) |
| 1807 | xa_erase_index(test, xa, i); | 1730 | xa_erase_index(xa, i); |
| 1808 | XA_BUG_ON(xa, !xa_empty(xa)); | 1731 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1809 | } | 1732 | } |
| 1810 | | 1733 | |
| 1811 | static noinline void check_create_range_5(struct kunit *test, | 1734 | static noinline void check_create_range_5(struct xarray *xa, |
| 1812 | unsigned long index, unsigned int order) | 1735 | unsigned long index, unsigned int order) |
| 1813 | { | 1736 | { |
| 1814 | struct xarray *xa = xa_param(test); | | |
| 1815 | | | |
| 1816 | XA_STATE_ORDER(xas, xa, index, order); | 1737 | XA_STATE_ORDER(xas, xa, index, order); |
| 1817 | unsigned int i; | 1738 | unsigned int i; |
| 1818 | | 1739 | |
| @@ -1829,46 +1750,44 @@ static noinline void check_create_range_5(struct kunit *test, · 10 unmodified lines |
| 1829 | xa_destroy(xa); | 1750 | xa_destroy(xa); |
| 1830 | } | 1751 | } |
| 1831 | | 1752 | |
| 1832 | static noinline void check_create_range(struct kunit *test) | 1753 | static noinline void check_create_range(struct xarray *xa) |
| 1833 | { | 1754 | { |
| 1834 | unsigned int order; | 1755 | unsigned int order; |
| 1835 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 12 : 1; | 1756 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 12 : 1; |
| 1836 | | 1757 | |
| 1837 | for (order = 0; order < max_order; order++) { | 1758 | for (order = 0; order < max_order; order++) { |
| 1838 | check_create_range_1(test, 0, order); | 1759 | check_create_range_1(xa, 0, order); |
| 1839 | check_create_range_1(test, 1U << order, order); | 1760 | check_create_range_1(xa, 1U << order, order); |
| 1840 | check_create_range_1(test, 2U << order, order); | 1761 | check_create_range_1(xa, 2U << order, order); |
| 1841 | check_create_range_1(test, 3U << order, order); | 1762 | check_create_range_1(xa, 3U << order, order); |
| 1842 | check_create_range_1(test, 1U << 24, order); | 1763 | check_create_range_1(xa, 1U << 24, order); |
| 1843 | if (order < 10) | 1764 | if (order < 10) |
| 1844 | check_create_range_2(test, order); | 1765 | check_create_range_2(xa, order); |
| 1845 | | 1766 | |
| 1846 | check_create_range_4(test, 0, order); | 1767 | check_create_range_4(xa, 0, order); |
| 1847 | check_create_range_4(test, 1U << order, order); | 1768 | check_create_range_4(xa, 1U << order, order); |
| 1848 | check_create_range_4(test, 2U << order, order); | 1769 | check_create_range_4(xa, 2U << order, order); |
| 1849 | check_create_range_4(test, 3U << order, order); | 1770 | check_create_range_4(xa, 3U << order, order); |
| 1850 | check_create_range_4(test, 1U << 24, order); | 1771 | check_create_range_4(xa, 1U << 24, order); |
| 1851 | | 1772 | |
| 1852 | check_create_range_4(test, 1, order); | 1773 | check_create_range_4(xa, 1, order); |
| 1853 | check_create_range_4(test, (1U << order) + 1, order); | 1774 | check_create_range_4(xa, (1U << order) + 1, order); |
| 1854 | check_create_range_4(test, (2U << order) + 1, order); | 1775 | check_create_range_4(xa, (2U << order) + 1, order); |
| 1855 | check_create_range_4(test, (2U << order) - 1, order); | 1776 | check_create_range_4(xa, (2U << order) - 1, order); |
| 1856 | check_create_range_4(test, (3U << order) + 1, order); | 1777 | check_create_range_4(xa, (3U << order) + 1, order); |
| 1857 | check_create_range_4(test, (3U << order) - 1, order); | 1778 | check_create_range_4(xa, (3U << order) - 1, order); |
| 1858 | check_create_range_4(test, (1U << 24) + 1, order); | 1779 | check_create_range_4(xa, (1U << 24) + 1, order); |
| 1859 | | 1780 | |
| 1860 | check_create_range_5(test, 0, order); | 1781 | check_create_range_5(xa, 0, order); |
| 1861 | check_create_range_5(test, (1U << order), order); | 1782 | check_create_range_5(xa, (1U << order), order); |
| 1862 | } | 1783 | } |
| 1863 | | 1784 | |
| 1864 | check_create_range_3(test); | 1785 | check_create_range_3(); |
| 1865 | } | 1786 | } |
| 1866 | | 1787 | |
| 1867 | static noinline void __check_store_range(struct kunit *test, unsigned long first, | 1788 | static noinline void __check_store_range(struct xarray *xa, unsigned long first, |
| 1868 | unsigned long last) | 1789 | unsigned long last) |
| 1869 | { | 1790 | { |
| 1870 | struct xarray *xa = xa_param(test); | | |
| 1871 | | | |
| 1872 | #ifdef CONFIG_XARRAY_MULTI | 1791 | #ifdef CONFIG_XARRAY_MULTI |
| 1873 | xa_store_range(xa, first, last, xa_mk_index(first), GFP_KERNEL); | 1792 | xa_store_range(xa, first, last, xa_mk_index(first), GFP_KERNEL); |
| 1874 | | 1793 | |
| @@ -1883,28 +1802,26 @@ static noinline void __check_store_range(struct kunit *test, unsigned long first · 8 unmodified lines |
| 1883 | XA_BUG_ON(xa, !xa_empty(xa)); | 1802 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1884 | } | 1803 | } |
| 1885 | | 1804 | |
| 1886 | static noinline void check_store_range(struct kunit *test) | 1805 | static noinline void check_store_range(struct xarray *xa) |
| 1887 | { | 1806 | { |
| 1888 | unsigned long i, j; | 1807 | unsigned long i, j; |
| 1889 | | 1808 | |
| 1890 | for (i = 0; i < 128; i++) { | 1809 | for (i = 0; i < 128; i++) { |
| 1891 | for (j = i; j < 128; j++) { | 1810 | for (j = i; j < 128; j++) { |
| 1892 | __check_store_range(test, i, j); | 1811 | __check_store_range(xa, i, j); |
| 1893 | __check_store_range(test, 128 + i, 128 + j); | 1812 | __check_store_range(xa, 128 + i, 128 + j); |
| 1894 | __check_store_range(test, 4095 + i, 4095 + j); | 1813 | __check_store_range(xa, 4095 + i, 4095 + j); |
| 1895 | __check_store_range(test, 4096 + i, 4096 + j); | 1814 | __check_store_range(xa, 4096 + i, 4096 + j); |
| 1896 | __check_store_range(test, 123456 + i, 123456 + j); | 1815 | __check_store_range(xa, 123456 + i, 123456 + j); |
| 1897 | __check_store_range(test, (1 << 24) + i, (1 << 24) + j); | 1816 | __check_store_range(xa, (1 << 24) + i, (1 << 24) + j); |
| 1898 | } | 1817 | } |
| 1899 | } | 1818 | } |
| 1900 | } | 1819 | } |
| 1901 | | 1820 | |
| 1902 | #ifdef CONFIG_XARRAY_MULTI | 1821 | #ifdef CONFIG_XARRAY_MULTI |
| 1903 | static void check_split_1(struct kunit *test, unsigned long index, | 1822 | static void check_split_1(struct xarray *xa, unsigned long index, |
| 1904 | unsigned int order, unsigned int new_order) | 1823 | unsigned int order, unsigned int new_order) |
| 1905 | { | 1824 | { |
| 1906 | struct xarray *xa = xa_param(test); | | |
| 1907 | | | |
| 1908 | XA_STATE_ORDER(xas, xa, index, new_order); | 1825 | XA_STATE_ORDER(xas, xa, index, new_order); |
| 1909 | unsigned int i, found; | 1826 | unsigned int i, found; |
| 1910 | void *entry; | 1827 | void *entry; |
| @@ -1940,30 +1857,26 @@ static void check_split_1(struct kunit *test, unsigned long index, · 29 unmodified lines |
| 1940 | xa_destroy(xa); | 1857 | xa_destroy(xa); |
| 1941 | } | 1858 | } |
| 1942 | | 1859 | |
| 1943 | static noinline void check_split(struct kunit *test) | 1860 | static noinline void check_split(struct xarray *xa) |
| 1944 | { | 1861 | { |
| 1945 | struct xarray *xa = xa_param(test); | | |
| 1946 | | | |
| 1947 | unsigned int order, new_order; | 1862 | unsigned int order, new_order; |
| 1948 | | 1863 | |
| 1949 | XA_BUG_ON(xa, !xa_empty(xa)); | 1864 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 1950 | | 1865 | |
| 1951 | for (order = 1; order < 2 * XA_CHUNK_SHIFT; order++) { | 1866 | for (order = 1; order < 2 * XA_CHUNK_SHIFT; order++) { |
| 1952 | for (new_order = 0; new_order < order; new_order++) { | 1867 | for (new_order = 0; new_order < order; new_order++) { |
| 1953 | check_split_1(test, 0, order, new_order); | 1868 | check_split_1(xa, 0, order, new_order); |
| 1954 | check_split_1(test, 1UL << order, order, new_order); | 1869 | check_split_1(xa, 1UL << order, order, new_order); |
| 1955 | check_split_1(test, 3UL << order, order, new_order); | 1870 | check_split_1(xa, 3UL << order, order, new_order); |
| 1956 | } | 1871 | } |
| 1957 | } | 1872 | } |
| 1958 | } | 1873 | } |
| 1959 | #else | 1874 | #else |
| 1960 | static void check_split(struct kunit *test) { } | 1875 | static void check_split(struct xarray *xa) { } |
| 1961 | #endif | 1876 | #endif |
| 1962 | | 1877 | |
| 1963 | static void check_align_1(struct kunit *test, char *name) | 1878 | static void check_align_1(struct xarray *xa, char *name) |
| 1964 | { | 1879 | { |
| 1965 | struct xarray *xa = xa_param(test); | | |
| 1966 | | | |
| 1967 | int i; | 1880 | int i; |
| 1968 | unsigned int id; | 1881 | unsigned int id; |
| 1969 | unsigned long index; | 1882 | unsigned long index; |
| @@ -1983,10 +1896,8 @@ static void check_align_1(struct kunit *test, char *name) · 13 unmodified lines |
| 1983 | * We should always be able to store without allocating memory after | 1896 | * We should always be able to store without allocating memory after |
| 1984 | * reserving a slot. | 1897 | * reserving a slot. |
| 1985 | */ | 1898 | */ |
| 1986 | static void check_align_2(struct kunit *test, char *name) | 1899 | static void check_align_2(struct xarray *xa, char *name) |
| 1987 | { | 1900 | { |
| 1988 | struct xarray *xa = xa_param(test); | | |
| 1989 | | | |
| 1990 | int i; | 1901 | int i; |
| 1991 | | 1902 | |
| 1992 | XA_BUG_ON(xa, !xa_empty(xa)); | 1903 | XA_BUG_ON(xa, !xa_empty(xa)); |
| @@ -2005,15 +1916,15 @@ static void check_align_2(struct kunit *test, char *name) · 12 unmodified lines |
| 2005 | XA_BUG_ON(xa, !xa_empty(xa)); | 1916 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 2006 | } | 1917 | } |
| 2007 | | 1918 | |
| 2008 | static noinline void check_align(struct kunit *test) | 1919 | static noinline void check_align(struct xarray *xa) |
| 2009 | { | 1920 | { |
| 2010 | char name[] = "Motorola 68000"; | 1921 | char name[] = "Motorola 68000"; |
| 2011 | | 1922 | |
| 2012 | check_align_1(test, name); | 1923 | check_align_1(xa, name); |
| 2013 | check_align_1(test, name + 1); | 1924 | check_align_1(xa, name + 1); |
| 2014 | check_align_1(test, name + 2); | 1925 | check_align_1(xa, name + 2); |
| 2015 | check_align_1(test, name + 3); | 1926 | check_align_1(xa, name + 3); |
| 2016 | check_align_2(test, name); | 1927 | check_align_2(xa, name); |
| 2017 | } | 1928 | } |
| 2018 | | 1929 | |
| 2019 | static LIST_HEAD(shadow_nodes); | 1930 | static LIST_HEAD(shadow_nodes); |
| @@ -2029,7 +1940,7 @@ static void test_update_node(struct xa_node *node) · 9 unmodified lines |
| 2029 | } | 1940 | } |
| 2030 | } | 1941 | } |
| 2031 | | 1942 | |
| 2032 | static noinline void shadow_remove(struct kunit *test, struct xarray *xa) | 1943 | static noinline void shadow_remove(struct xarray *xa) |
| 2033 | { | 1944 | { |
| 2034 | struct xa_node *node; | 1945 | struct xa_node *node; |
| 2035 | | 1946 | |
| @@ -2043,17 +1954,8 @@ static noinline void shadow_remove(struct kunit *test, struct xarray *xa) · 7 unmodified lines |
| 2043 | xa_unlock(xa); | 1954 | xa_unlock(xa); |
| 2044 | } | 1955 | } |
| 2045 | | 1956 | |
| 2046 | struct workingset_testcase { | 1957 | static noinline void check_workingset(struct xarray *xa, unsigned long index) |
| 2047 | struct xarray *xa; | | |
| 2048 | unsigned long index; | | |
| 2049 | }; | | |
| 2050 | | | |
| 2051 | static noinline void check_workingset(struct kunit *test) | | |
| 2052 | { | 1958 | { |
| 2053 | struct workingset_testcase tc = *(struct workingset_testcase *)test->param_value; | | |
| 2054 | struct xarray *xa = tc.xa; | | |
| 2055 | unsigned long index = tc.index; | | |
| 2056 | | | |
| 2057 | XA_STATE(xas, xa, index); | 1959 | XA_STATE(xas, xa, index); |
| 2058 | xas_set_update(&xas, test_update_node); | 1960 | xas_set_update(&xas, test_update_node); |
| 2059 | | 1961 | |
| @@ -2076,7 +1978,7 @@ static noinline void check_workingset(struct kunit *test) · 16 unmodified lines |
| 2076 | xas_unlock(&xas); | 1978 | xas_unlock(&xas); |
| 2077 | XA_BUG_ON(xa, list_empty(&shadow_nodes)); | 1979 | XA_BUG_ON(xa, list_empty(&shadow_nodes)); |
| 2078 | | 1980 | |
| 2079 | shadow_remove(test, xa); | 1981 | shadow_remove(xa); |
| 2080 | XA_BUG_ON(xa, !list_empty(&shadow_nodes)); | 1982 | XA_BUG_ON(xa, !list_empty(&shadow_nodes)); |
| 2081 | XA_BUG_ON(xa, !xa_empty(xa)); | 1983 | XA_BUG_ON(xa, !xa_empty(xa)); |
| 2082 | } | 1984 | } |
| @@ -2085,11 +1987,9 @@ static noinline void check_workingset(struct kunit *test) · 2 unmodified lines |
| 2085 | * Check that the pointer / value / sibling entries are accounted the | 1987 | * Check that the pointer / value / sibling entries are accounted the |
| 2086 | * way we expect them to be. | 1988 | * way we expect them to be. |
| 2087 | */ | 1989 | */ |
| 2088 | static noinline void check_account(struct kunit *test) | 1990 | static noinline void check_account(struct xarray *xa) |
| 2089 | { | 1991 | { |
| 2090 | #ifdef CONFIG_XARRAY_MULTI | 1992 | #ifdef CONFIG_XARRAY_MULTI |
| 2091 | struct xarray *xa = xa_param(test); | | |
| 2092 | | | |
| 2093 | unsigned int order; | 1993 | unsigned int order; |
| 2094 | | 1994 | |
| 2095 | for (order = 1; order < 12; order++) { | 1995 | for (order = 1; order < 12; order++) { |
| @@ -2116,10 +2016,8 @@ static noinline void check_account(struct kunit *test) · 20 unmodified lines |
| 2116 | #endif | 2016 | #endif |
| 2117 | } | 2017 | } |
| 2118 | | 2018 | |
| 2119 | static noinline void check_get_order(struct kunit *test) | 2019 | static noinline void check_get_order(struct xarray *xa) |
| 2120 | { | 2020 | { |
| 2121 | struct xarray *xa = xa_param(test); | | |
| 2122 | | | |
| 2123 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1; | 2021 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1; |
| 2124 | unsigned int order; | 2022 | unsigned int order; |
| 2125 | unsigned long i, j; | 2023 | unsigned long i, j; |
| @@ -2138,10 +2036,8 @@ static noinline void check_get_order(struct kunit *test) · 12 unmodified lines |
| 2138 | } | 2036 | } |
| 2139 | } | 2037 | } |
| 2140 | | 2038 | |
| 2141 | static noinline void check_xas_get_order(struct kunit *test) | 2039 | static noinline void check_xas_get_order(struct xarray *xa) |
| 2142 | { | 2040 | { |
| 2143 | struct xarray *xa = xa_param(test); | | |
| 2144 | | | |
| 2145 | XA_STATE(xas, xa, 0); | 2041 | XA_STATE(xas, xa, 0); |
| 2146 | | 2042 | |
| 2147 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1; | 2043 | unsigned int max_order = IS_ENABLED(CONFIG_XARRAY_MULTI) ? 20 : 1; |
| @@ -2173,10 +2069,8 @@ static noinline void check_xas_get_order(struct kunit *test) · 25 unmodified lines |
| 2173 | } | 2069 | } |
| 2174 | } | 2070 | } |
| 2175 | | 2071 | |
| 2176 | static noinline void check_xas_conflict_get_order(struct kunit *test) | 2072 | static noinline void check_xas_conflict_get_order(struct xarray *xa) |
| 2177 | { | 2073 | { |
| 2178 | struct xarray *xa = xa_param(test); | | |
| 2179 | | | |
| 2180 | XA_STATE(xas, xa, 0); | 2074 | XA_STATE(xas, xa, 0); |
| 2181 | | 2075 | |
| 2182 | void *entry; | 2076 | void *entry; |
| @@ -2233,10 +2127,8 @@ static noinline void check_xas_conflict_get_order(struct kunit *test) · 50 unmodified lines |
| 2233 | } | 2127 | } |
| 2234 | | 2128 | |
| 2235 | | 2129 | |
| 2236 | static noinline void check_destroy(struct kunit *test) | 2130 | static noinline void check_destroy(struct xarray *xa) |
| 2237 | { | 2131 | { |
| 2238 | struct xarray *xa = xa_param(test); | | |
| 2239 | | | |
| 2240 | unsigned long index; | 2132 | unsigned long index; |
| 2241 | | 2133 | |
| 2242 | XA_BUG_ON(xa, !xa_empty(xa)); | 2134 | XA_BUG_ON(xa, !xa_empty(xa)); |
| @@ -2269,59 +2161,52 @@ static noinline void check_destroy(struct kunit *test) · 26 unmodified lines |
| 2269 | } | 2161 | } |
| 2270 | | 2162 | |
| 2271 | static DEFINE_XARRAY(array); | 2163 | static DEFINE_XARRAY(array); |
| 2272 | static struct xarray *arrays[] = { &array }; | | |
| 2273 | KUNIT_ARRAY_PARAM(array, arrays, NULL); | | |
| 2274 | | | |
| 2275 | static struct xarray *xa0s[] = { &xa0 }; | | |
| 2276 | KUNIT_ARRAY_PARAM(xa0, xa0s, NULL); | | |
| 2277 | | | |
| 2278 | static struct workingset_testcase workingset_testcases[] = { | | |
| 2279 | { &array, 0 }, | | |
| 2280 | { &array, 64 }, | | |
| 2281 | { &array, 4096 }, | | |
| 2282 | }; | | |
| 2283 | KUNIT_ARRAY_PARAM(workingset, workingset_testcases, NULL); | | |
| 2284 | | | |
| 2285 | static struct kunit_case xarray_cases[] = { | | |
| 2286 | KUNIT_CASE_PARAM(check_xa_err, array_gen_params), | | |
| 2287 | KUNIT_CASE_PARAM(check_xas_retry, array_gen_params), | | |
| 2288 | KUNIT_CASE_PARAM(check_xa_load, array_gen_params), | | |
| 2289 | KUNIT_CASE_PARAM(check_xa_mark, array_gen_params), | | |
| 2290 | KUNIT_CASE_PARAM(check_xa_shrink, array_gen_params), | | |
| 2291 | KUNIT_CASE_PARAM(check_xas_erase, array_gen_params), | | |
| 2292 | KUNIT_CASE_PARAM(check_insert, array_gen_params), | | |
| 2293 | KUNIT_CASE_PARAM(check_cmpxchg, array_gen_params), | | |
| 2294 | KUNIT_CASE_PARAM(check_cmpxchg_order, array_gen_params), | | |
| 2295 | KUNIT_CASE_PARAM(check_reserve, array_gen_params), | | |
| 2296 | KUNIT_CASE_PARAM(check_reserve, xa0_gen_params), | | |
| 2297 | KUNIT_CASE_PARAM(check_multi_store, array_gen_params), | | |
| 2298 | KUNIT_CASE_PARAM(check_multi_store_advanced, array_gen_params), | | |
| 2299 | KUNIT_CASE_PARAM(check_get_order, array_gen_params), | | |
| 2300 | KUNIT_CASE_PARAM(check_xas_get_order, array_gen_params), | | |
| 2301 | KUNIT_CASE_PARAM(check_xas_conflict_get_order, array_gen_params), | | |
| 2302 | KUNIT_CASE(check_xa_alloc), | | |
| 2303 | KUNIT_CASE_PARAM(check_find, array_gen_params), | | |
| 2304 | KUNIT_CASE_PARAM(check_find_entry, array_gen_params), | | |
| 2305 | KUNIT_CASE_PARAM(check_pause, array_gen_params), | | |
| 2306 | KUNIT_CASE_PARAM(check_account, array_gen_params), | | |
| 2307 | KUNIT_CASE_PARAM(check_destroy, array_gen_params), | | |
| 2308 | KUNIT_CASE_PARAM(check_move, array_gen_params), | | |
| 2309 | KUNIT_CASE_PARAM(check_create_range, array_gen_params), | | |
| 2310 | KUNIT_CASE_PARAM(check_store_range, array_gen_params), | | |
| 2311 | KUNIT_CASE_PARAM(check_store_iter, array_gen_params), | | |
| 2312 | KUNIT_CASE_PARAM(check_align, xa0_gen_params), | | |
| 2313 | KUNIT_CASE_PARAM(check_split, array_gen_params), | | |
| 2314 | KUNIT_CASE_PARAM(check_workingset, workingset_gen_params), | | |
| 2315 | {}, | | |
| 2316 | }; | | |
| 2317 | | | |
| 2318 | static struct kunit_suite xarray_suite = { | | |
| 2319 | .name = "xarray", | | |
| 2320 | .test_cases = xarray_cases, | | |
| 2321 | }; | | |
| 2322 | | | |
| 2323 | kunit_test_suite(xarray_suite); | | |
| 2324 | | 2164 | |
| | 2165 | static int xarray_checks(void) |
| | 2166 | { |
| | 2167 | check_xa_err(&array); |
| | 2168 | check_xas_retry(&array); |
| | 2169 | check_xa_load(&array); |
| | 2170 | check_xa_mark(&array); |
| | 2171 | check_xa_shrink(&array); |
| | 2172 | check_xas_erase(&array); |
| | 2173 | check_insert(&array); |
| | 2174 | check_cmpxchg(&array); |
| | 2175 | check_cmpxchg_order(&array); |
| | 2176 | check_reserve(&array); |
| | 2177 | check_reserve(&xa0); |
| | 2178 | check_multi_store(&array); |
| | 2179 | check_multi_store_advanced(&array); |
| | 2180 | check_get_order(&array); |
| | 2181 | check_xas_get_order(&array); |
| | 2182 | check_xas_conflict_get_order(&array); |
| | 2183 | check_xa_alloc(); |
| | 2184 | check_find(&array); |
| | 2185 | check_find_entry(&array); |
| | 2186 | check_pause(&array); |
| | 2187 | check_account(&array); |
| | 2188 | check_destroy(&array); |
| | 2189 | check_move(&array); |
| | 2190 | check_create_range(&array); |
| | 2191 | check_store_range(&array); |
| | 2192 | check_store_iter(&array); |
| | 2193 | check_align(&xa0); |
| | 2194 | check_split(&array); |
| | 2195 | |
| | 2196 | check_workingset(&array, 0); |
| | 2197 | check_workingset(&array, 64); |
| | 2198 | check_workingset(&array, 4096); |
| | 2199 | |
| | 2200 | printk("XArray: %u of %u tests passed\n", tests_passed, tests_run); |
| | 2201 | return (tests_run == tests_passed) ? 0 : -EINVAL; |
| | 2202 | } |
| | 2203 | |
| | 2204 | static void xarray_exit(void) |
| | 2205 | { |
| | 2206 | } |
| | 2207 | |
| | 2208 | module_init(xarray_checks); |
| | 2209 | module_exit(xarray_exit); |
| 2325 | MODULE_AUTHOR("Matthew Wilcox <willy@infradead.org>"); | 2210 | MODULE_AUTHOR("Matthew Wilcox <willy@infradead.org>"); |
| 2326 | MODULE_DESCRIPTION("XArray API test module"); | 2211 | MODULE_DESCRIPTION("XArray API test module"); |
| 2327 | MODULE_LICENSE("GPL"); | 2212 | MODULE_LICENSE("GPL"); |