xarray.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. #ifndef _LINUX_XARRAY_H
  3. #define _LINUX_XARRAY_H
  4. /*
  5. * eXtensible Arrays
  6. * Copyright (c) 2017 Microsoft Corporation
  7. * Author: Matthew Wilcox <willy@infradead.org>
  8. *
  9. * See Documentation/core-api/xarray.rst for how to use the XArray.
  10. */
  11. #include <linux/bug.h>
  12. #include <linux/compiler.h>
  13. #include <linux/gfp.h>
  14. #include <linux/kconfig.h>
  15. #include <linux/kernel.h>
  16. #include <linux/rcupdate.h>
  17. #include <linux/spinlock.h>
  18. #include <linux/types.h>
  19. /*
  20. * The bottom two bits of the entry determine how the XArray interprets
  21. * the contents:
  22. *
  23. * 00: Pointer entry
  24. * 10: Internal entry
  25. * x1: Value entry or tagged pointer
  26. *
  27. * Attempting to store internal entries in the XArray is a bug.
  28. *
  29. * Most internal entries are pointers to the next node in the tree.
  30. * The following internal entries have a special meaning:
  31. *
  32. * 0-62: Sibling entries
  33. * 256: Zero entry
  34. * 257: Retry entry
  35. *
  36. * Errors are also represented as internal entries, but use the negative
  37. * space (-4094 to -2). They're never stored in the slots array; only
  38. * returned by the normal API.
  39. */
  40. #define BITS_PER_XA_VALUE (BITS_PER_LONG - 1)
  41. /**
  42. * xa_mk_value() - Create an XArray entry from an integer.
  43. * @v: Value to store in XArray.
  44. *
  45. * Context: Any context.
  46. * Return: An entry suitable for storing in the XArray.
  47. */
  48. static inline void *xa_mk_value(unsigned long v)
  49. {
  50. WARN_ON((long)v < 0);
  51. return (void *)((v << 1) | 1);
  52. }
  53. /**
  54. * xa_to_value() - Get value stored in an XArray entry.
  55. * @entry: XArray entry.
  56. *
  57. * Context: Any context.
  58. * Return: The value stored in the XArray entry.
  59. */
  60. static inline unsigned long xa_to_value(const void *entry)
  61. {
  62. return (unsigned long)entry >> 1;
  63. }
  64. /**
  65. * xa_is_value() - Determine if an entry is a value.
  66. * @entry: XArray entry.
  67. *
  68. * Context: Any context.
  69. * Return: True if the entry is a value, false if it is a pointer.
  70. */
  71. static inline bool xa_is_value(const void *entry)
  72. {
  73. return (unsigned long)entry & 1;
  74. }
  75. /**
  76. * xa_tag_pointer() - Create an XArray entry for a tagged pointer.
  77. * @p: Plain pointer.
  78. * @tag: Tag value (0, 1 or 3).
  79. *
  80. * If the user of the XArray prefers, they can tag their pointers instead
  81. * of storing value entries. Three tags are available (0, 1 and 3).
  82. * These are distinct from the xa_mark_t as they are not replicated up
  83. * through the array and cannot be searched for.
  84. *
  85. * Context: Any context.
  86. * Return: An XArray entry.
  87. */
  88. static inline void *xa_tag_pointer(void *p, unsigned long tag)
  89. {
  90. return (void *)((unsigned long)p | tag);
  91. }
  92. /**
  93. * xa_untag_pointer() - Turn an XArray entry into a plain pointer.
  94. * @entry: XArray entry.
  95. *
  96. * If you have stored a tagged pointer in the XArray, call this function
  97. * to get the untagged version of the pointer.
  98. *
  99. * Context: Any context.
  100. * Return: A pointer.
  101. */
  102. static inline void *xa_untag_pointer(void *entry)
  103. {
  104. return (void *)((unsigned long)entry & ~3UL);
  105. }
  106. /**
  107. * xa_pointer_tag() - Get the tag stored in an XArray entry.
  108. * @entry: XArray entry.
  109. *
  110. * If you have stored a tagged pointer in the XArray, call this function
  111. * to get the tag of that pointer.
  112. *
  113. * Context: Any context.
  114. * Return: A tag.
  115. */
  116. static inline unsigned int xa_pointer_tag(void *entry)
  117. {
  118. return (unsigned long)entry & 3UL;
  119. }
  120. /*
  121. * xa_mk_internal() - Create an internal entry.
  122. * @v: Value to turn into an internal entry.
  123. *
  124. * Context: Any context.
  125. * Return: An XArray internal entry corresponding to this value.
  126. */
  127. static inline void *xa_mk_internal(unsigned long v)
  128. {
  129. return (void *)((v << 2) | 2);
  130. }
  131. /*
  132. * xa_to_internal() - Extract the value from an internal entry.
  133. * @entry: XArray entry.
  134. *
  135. * Context: Any context.
  136. * Return: The value which was stored in the internal entry.
  137. */
  138. static inline unsigned long xa_to_internal(const void *entry)
  139. {
  140. return (unsigned long)entry >> 2;
  141. }
  142. /*
  143. * xa_is_internal() - Is the entry an internal entry?
  144. * @entry: XArray entry.
  145. *
  146. * Context: Any context.
  147. * Return: %true if the entry is an internal entry.
  148. */
  149. static inline bool xa_is_internal(const void *entry)
  150. {
  151. return ((unsigned long)entry & 3) == 2;
  152. }
  153. /**
  154. * xa_is_err() - Report whether an XArray operation returned an error
  155. * @entry: Result from calling an XArray function
  156. *
  157. * If an XArray operation cannot complete an operation, it will return
  158. * a special value indicating an error. This function tells you
  159. * whether an error occurred; xa_err() tells you which error occurred.
  160. *
  161. * Context: Any context.
  162. * Return: %true if the entry indicates an error.
  163. */
  164. static inline bool xa_is_err(const void *entry)
  165. {
  166. return unlikely(xa_is_internal(entry));
  167. }
  168. /**
  169. * xa_err() - Turn an XArray result into an errno.
  170. * @entry: Result from calling an XArray function.
  171. *
  172. * If an XArray operation cannot complete an operation, it will return
  173. * a special pointer value which encodes an errno. This function extracts
  174. * the errno from the pointer value, or returns 0 if the pointer does not
  175. * represent an errno.
  176. *
  177. * Context: Any context.
  178. * Return: A negative errno or 0.
  179. */
  180. static inline int xa_err(void *entry)
  181. {
  182. /* xa_to_internal() would not do sign extension. */
  183. if (xa_is_err(entry))
  184. return (long)entry >> 2;
  185. return 0;
  186. }
  187. typedef unsigned __bitwise xa_mark_t;
  188. #define XA_MARK_0 ((__force xa_mark_t)0U)
  189. #define XA_MARK_1 ((__force xa_mark_t)1U)
  190. #define XA_MARK_2 ((__force xa_mark_t)2U)
  191. #define XA_PRESENT ((__force xa_mark_t)8U)
  192. #define XA_MARK_MAX XA_MARK_2
  193. enum xa_lock_type {
  194. XA_LOCK_IRQ = 1,
  195. XA_LOCK_BH = 2,
  196. };
  197. /*
  198. * Values for xa_flags. The radix tree stores its GFP flags in the xa_flags,
  199. * and we remain compatible with that.
  200. */
  201. #define XA_FLAGS_LOCK_IRQ ((__force gfp_t)XA_LOCK_IRQ)
  202. #define XA_FLAGS_LOCK_BH ((__force gfp_t)XA_LOCK_BH)
  203. #define XA_FLAGS_MARK(mark) ((__force gfp_t)((1U << __GFP_BITS_SHIFT) << \
  204. (__force unsigned)(mark)))
  205. /**
  206. * struct xarray - The anchor of the XArray.
  207. * @xa_lock: Lock that protects the contents of the XArray.
  208. *
  209. * To use the xarray, define it statically or embed it in your data structure.
  210. * It is a very small data structure, so it does not usually make sense to
  211. * allocate it separately and keep a pointer to it in your data structure.
  212. *
  213. * You may use the xa_lock to protect your own data structures as well.
  214. */
  215. /*
  216. * If all of the entries in the array are NULL, @xa_head is a NULL pointer.
  217. * If the only non-NULL entry in the array is at index 0, @xa_head is that
  218. * entry. If any other entry in the array is non-NULL, @xa_head points
  219. * to an @xa_node.
  220. */
  221. struct xarray {
  222. spinlock_t xa_lock;
  223. /* private: The rest of the data structure is not to be used directly. */
  224. gfp_t xa_flags;
  225. void __rcu * xa_head;
  226. };
  227. #define XARRAY_INIT(name, flags) { \
  228. .xa_lock = __SPIN_LOCK_UNLOCKED(name.xa_lock), \
  229. .xa_flags = flags, \
  230. .xa_head = NULL, \
  231. }
  232. /**
  233. * DEFINE_XARRAY_FLAGS() - Define an XArray with custom flags.
  234. * @name: A string that names your XArray.
  235. * @flags: XA_FLAG values.
  236. *
  237. * This is intended for file scope definitions of XArrays. It declares
  238. * and initialises an empty XArray with the chosen name and flags. It is
  239. * equivalent to calling xa_init_flags() on the array, but it does the
  240. * initialisation at compiletime instead of runtime.
  241. */
  242. #define DEFINE_XARRAY_FLAGS(name, flags) \
  243. struct xarray name = XARRAY_INIT(name, flags)
  244. /**
  245. * DEFINE_XARRAY() - Define an XArray.
  246. * @name: A string that names your XArray.
  247. *
  248. * This is intended for file scope definitions of XArrays. It declares
  249. * and initialises an empty XArray with the chosen name. It is equivalent
  250. * to calling xa_init() on the array, but it does the initialisation at
  251. * compiletime instead of runtime.
  252. */
  253. #define DEFINE_XARRAY(name) DEFINE_XARRAY_FLAGS(name, 0)
  254. void xa_init_flags(struct xarray *, gfp_t flags);
  255. void *xa_load(struct xarray *, unsigned long index);
  256. void *xa_store(struct xarray *, unsigned long index, void *entry, gfp_t);
  257. void *xa_cmpxchg(struct xarray *, unsigned long index,
  258. void *old, void *entry, gfp_t);
  259. int xa_reserve(struct xarray *, unsigned long index, gfp_t);
  260. bool xa_get_mark(struct xarray *, unsigned long index, xa_mark_t);
  261. void xa_set_mark(struct xarray *, unsigned long index, xa_mark_t);
  262. void xa_clear_mark(struct xarray *, unsigned long index, xa_mark_t);
  263. void *xa_find(struct xarray *xa, unsigned long *index,
  264. unsigned long max, xa_mark_t) __attribute__((nonnull(2)));
  265. void *xa_find_after(struct xarray *xa, unsigned long *index,
  266. unsigned long max, xa_mark_t) __attribute__((nonnull(2)));
  267. unsigned int xa_extract(struct xarray *, void **dst, unsigned long start,
  268. unsigned long max, unsigned int n, xa_mark_t);
  269. void xa_destroy(struct xarray *);
  270. /**
  271. * xa_init() - Initialise an empty XArray.
  272. * @xa: XArray.
  273. *
  274. * An empty XArray is full of NULL entries.
  275. *
  276. * Context: Any context.
  277. */
  278. static inline void xa_init(struct xarray *xa)
  279. {
  280. xa_init_flags(xa, 0);
  281. }
  282. /**
  283. * xa_empty() - Determine if an array has any present entries.
  284. * @xa: XArray.
  285. *
  286. * Context: Any context.
  287. * Return: %true if the array contains only NULL pointers.
  288. */
  289. static inline bool xa_empty(const struct xarray *xa)
  290. {
  291. return xa->xa_head == NULL;
  292. }
  293. /**
  294. * xa_marked() - Inquire whether any entry in this array has a mark set
  295. * @xa: Array
  296. * @mark: Mark value
  297. *
  298. * Context: Any context.
  299. * Return: %true if any entry has this mark set.
  300. */
  301. static inline bool xa_marked(const struct xarray *xa, xa_mark_t mark)
  302. {
  303. return xa->xa_flags & XA_FLAGS_MARK(mark);
  304. }
  305. /**
  306. * xa_erase() - Erase this entry from the XArray.
  307. * @xa: XArray.
  308. * @index: Index of entry.
  309. *
  310. * This function is the equivalent of calling xa_store() with %NULL as
  311. * the third argument. The XArray does not need to allocate memory, so
  312. * the user does not need to provide GFP flags.
  313. *
  314. * Context: Process context. Takes and releases the xa_lock.
  315. * Return: The entry which used to be at this index.
  316. */
  317. static inline void *xa_erase(struct xarray *xa, unsigned long index)
  318. {
  319. return xa_store(xa, index, NULL, 0);
  320. }
  321. /**
  322. * xa_insert() - Store this entry in the XArray unless another entry is
  323. * already present.
  324. * @xa: XArray.
  325. * @index: Index into array.
  326. * @entry: New entry.
  327. * @gfp: Memory allocation flags.
  328. *
  329. * If you would rather see the existing entry in the array, use xa_cmpxchg().
  330. * This function is for users who don't care what the entry is, only that
  331. * one is present.
  332. *
  333. * Context: Process context. Takes and releases the xa_lock.
  334. * May sleep if the @gfp flags permit.
  335. * Return: 0 if the store succeeded. -EEXIST if another entry was present.
  336. * -ENOMEM if memory could not be allocated.
  337. */
  338. static inline int xa_insert(struct xarray *xa, unsigned long index,
  339. void *entry, gfp_t gfp)
  340. {
  341. void *curr = xa_cmpxchg(xa, index, NULL, entry, gfp);
  342. if (!curr)
  343. return 0;
  344. if (xa_is_err(curr))
  345. return xa_err(curr);
  346. return -EEXIST;
  347. }
  348. /**
  349. * xa_release() - Release a reserved entry.
  350. * @xa: XArray.
  351. * @index: Index of entry.
  352. *
  353. * After calling xa_reserve(), you can call this function to release the
  354. * reservation. If the entry at @index has been stored to, this function
  355. * will do nothing.
  356. */
  357. static inline void xa_release(struct xarray *xa, unsigned long index)
  358. {
  359. xa_cmpxchg(xa, index, NULL, NULL, 0);
  360. }
  361. /**
  362. * xa_for_each() - Iterate over a portion of an XArray.
  363. * @xa: XArray.
  364. * @entry: Entry retrieved from array.
  365. * @index: Index of @entry.
  366. * @max: Maximum index to retrieve from array.
  367. * @filter: Selection criterion.
  368. *
  369. * Initialise @index to the lowest index you want to retrieve from the
  370. * array. During the iteration, @entry will have the value of the entry
  371. * stored in @xa at @index. The iteration will skip all entries in the
  372. * array which do not match @filter. You may modify @index during the
  373. * iteration if you want to skip or reprocess indices. It is safe to modify
  374. * the array during the iteration. At the end of the iteration, @entry will
  375. * be set to NULL and @index will have a value less than or equal to max.
  376. *
  377. * xa_for_each() is O(n.log(n)) while xas_for_each() is O(n). You have
  378. * to handle your own locking with xas_for_each(), and if you have to unlock
  379. * after each iteration, it will also end up being O(n.log(n)). xa_for_each()
  380. * will spin if it hits a retry entry; if you intend to see retry entries,
  381. * you should use the xas_for_each() iterator instead. The xas_for_each()
  382. * iterator will expand into more inline code than xa_for_each().
  383. *
  384. * Context: Any context. Takes and releases the RCU lock.
  385. */
  386. #define xa_for_each(xa, entry, index, max, filter) \
  387. for (entry = xa_find(xa, &index, max, filter); entry; \
  388. entry = xa_find_after(xa, &index, max, filter))
  389. #define xa_trylock(xa) spin_trylock(&(xa)->xa_lock)
  390. #define xa_lock(xa) spin_lock(&(xa)->xa_lock)
  391. #define xa_unlock(xa) spin_unlock(&(xa)->xa_lock)
  392. #define xa_lock_bh(xa) spin_lock_bh(&(xa)->xa_lock)
  393. #define xa_unlock_bh(xa) spin_unlock_bh(&(xa)->xa_lock)
  394. #define xa_lock_irq(xa) spin_lock_irq(&(xa)->xa_lock)
  395. #define xa_unlock_irq(xa) spin_unlock_irq(&(xa)->xa_lock)
  396. #define xa_lock_irqsave(xa, flags) \
  397. spin_lock_irqsave(&(xa)->xa_lock, flags)
  398. #define xa_unlock_irqrestore(xa, flags) \
  399. spin_unlock_irqrestore(&(xa)->xa_lock, flags)
  400. /*
  401. * Versions of the normal API which require the caller to hold the
  402. * xa_lock. If the GFP flags allow it, they will drop the lock to
  403. * allocate memory, then reacquire it afterwards. These functions
  404. * may also re-enable interrupts if the XArray flags indicate the
  405. * locking should be interrupt safe.
  406. */
  407. void *__xa_erase(struct xarray *, unsigned long index);
  408. void *__xa_store(struct xarray *, unsigned long index, void *entry, gfp_t);
  409. void *__xa_cmpxchg(struct xarray *, unsigned long index, void *old,
  410. void *entry, gfp_t);
  411. void __xa_set_mark(struct xarray *, unsigned long index, xa_mark_t);
  412. void __xa_clear_mark(struct xarray *, unsigned long index, xa_mark_t);
  413. /**
  414. * __xa_insert() - Store this entry in the XArray unless another entry is
  415. * already present.
  416. * @xa: XArray.
  417. * @index: Index into array.
  418. * @entry: New entry.
  419. * @gfp: Memory allocation flags.
  420. *
  421. * If you would rather see the existing entry in the array, use __xa_cmpxchg().
  422. * This function is for users who don't care what the entry is, only that
  423. * one is present.
  424. *
  425. * Context: Any context. Expects xa_lock to be held on entry. May
  426. * release and reacquire xa_lock if the @gfp flags permit.
  427. * Return: 0 if the store succeeded. -EEXIST if another entry was present.
  428. * -ENOMEM if memory could not be allocated.
  429. */
  430. static inline int __xa_insert(struct xarray *xa, unsigned long index,
  431. void *entry, gfp_t gfp)
  432. {
  433. void *curr = __xa_cmpxchg(xa, index, NULL, entry, gfp);
  434. if (!curr)
  435. return 0;
  436. if (xa_is_err(curr))
  437. return xa_err(curr);
  438. return -EEXIST;
  439. }
  440. /**
  441. * xa_erase_bh() - Erase this entry from the XArray.
  442. * @xa: XArray.
  443. * @index: Index of entry.
  444. *
  445. * This function is the equivalent of calling xa_store() with %NULL as
  446. * the third argument. The XArray does not need to allocate memory, so
  447. * the user does not need to provide GFP flags.
  448. *
  449. * Context: Process context. Takes and releases the xa_lock while
  450. * disabling softirqs.
  451. * Return: The entry which used to be at this index.
  452. */
  453. static inline void *xa_erase_bh(struct xarray *xa, unsigned long index)
  454. {
  455. void *entry;
  456. xa_lock_bh(xa);
  457. entry = __xa_erase(xa, index);
  458. xa_unlock_bh(xa);
  459. return entry;
  460. }
  461. /**
  462. * xa_erase_irq() - Erase this entry from the XArray.
  463. * @xa: XArray.
  464. * @index: Index of entry.
  465. *
  466. * This function is the equivalent of calling xa_store() with %NULL as
  467. * the third argument. The XArray does not need to allocate memory, so
  468. * the user does not need to provide GFP flags.
  469. *
  470. * Context: Process context. Takes and releases the xa_lock while
  471. * disabling interrupts.
  472. * Return: The entry which used to be at this index.
  473. */
  474. static inline void *xa_erase_irq(struct xarray *xa, unsigned long index)
  475. {
  476. void *entry;
  477. xa_lock_irq(xa);
  478. entry = __xa_erase(xa, index);
  479. xa_unlock_irq(xa);
  480. return entry;
  481. }
  482. /* Everything below here is the Advanced API. Proceed with caution. */
  483. /*
  484. * The xarray is constructed out of a set of 'chunks' of pointers. Choosing
  485. * the best chunk size requires some tradeoffs. A power of two recommends
  486. * itself so that we can walk the tree based purely on shifts and masks.
  487. * Generally, the larger the better; as the number of slots per level of the
  488. * tree increases, the less tall the tree needs to be. But that needs to be
  489. * balanced against the memory consumption of each node. On a 64-bit system,
  490. * xa_node is currently 576 bytes, and we get 7 of them per 4kB page. If we
  491. * doubled the number of slots per node, we'd get only 3 nodes per 4kB page.
  492. */
  493. #ifndef XA_CHUNK_SHIFT
  494. #define XA_CHUNK_SHIFT (CONFIG_BASE_SMALL ? 4 : 6)
  495. #endif
  496. #define XA_CHUNK_SIZE (1UL << XA_CHUNK_SHIFT)
  497. #define XA_CHUNK_MASK (XA_CHUNK_SIZE - 1)
  498. #define XA_MAX_MARKS 3
  499. #define XA_MARK_LONGS DIV_ROUND_UP(XA_CHUNK_SIZE, BITS_PER_LONG)
  500. /*
  501. * @count is the count of every non-NULL element in the ->slots array
  502. * whether that is a value entry, a retry entry, a user pointer,
  503. * a sibling entry or a pointer to the next level of the tree.
  504. * @nr_values is the count of every element in ->slots which is
  505. * either a value entry or a sibling of a value entry.
  506. */
  507. struct xa_node {
  508. unsigned char shift; /* Bits remaining in each slot */
  509. unsigned char offset; /* Slot offset in parent */
  510. unsigned char count; /* Total entry count */
  511. unsigned char nr_values; /* Value entry count */
  512. struct xa_node __rcu *parent; /* NULL at top of tree */
  513. struct xarray *array; /* The array we belong to */
  514. union {
  515. struct list_head private_list; /* For tree user */
  516. struct rcu_head rcu_head; /* Used when freeing node */
  517. };
  518. void __rcu *slots[XA_CHUNK_SIZE];
  519. union {
  520. unsigned long tags[XA_MAX_MARKS][XA_MARK_LONGS];
  521. unsigned long marks[XA_MAX_MARKS][XA_MARK_LONGS];
  522. };
  523. };
  524. void xa_dump(const struct xarray *);
  525. void xa_dump_node(const struct xa_node *);
  526. #ifdef XA_DEBUG
  527. #define XA_BUG_ON(xa, x) do { \
  528. if (x) { \
  529. xa_dump(xa); \
  530. BUG(); \
  531. } \
  532. } while (0)
  533. #define XA_NODE_BUG_ON(node, x) do { \
  534. if (x) { \
  535. if (node) xa_dump_node(node); \
  536. BUG(); \
  537. } \
  538. } while (0)
  539. #else
  540. #define XA_BUG_ON(xa, x) do { } while (0)
  541. #define XA_NODE_BUG_ON(node, x) do { } while (0)
  542. #endif
  543. /* Private */
  544. static inline void *xa_head(const struct xarray *xa)
  545. {
  546. return rcu_dereference_check(xa->xa_head,
  547. lockdep_is_held(&xa->xa_lock));
  548. }
  549. /* Private */
  550. static inline void *xa_head_locked(const struct xarray *xa)
  551. {
  552. return rcu_dereference_protected(xa->xa_head,
  553. lockdep_is_held(&xa->xa_lock));
  554. }
  555. /* Private */
  556. static inline void *xa_entry(const struct xarray *xa,
  557. const struct xa_node *node, unsigned int offset)
  558. {
  559. XA_NODE_BUG_ON(node, offset >= XA_CHUNK_SIZE);
  560. return rcu_dereference_check(node->slots[offset],
  561. lockdep_is_held(&xa->xa_lock));
  562. }
  563. /* Private */
  564. static inline void *xa_entry_locked(const struct xarray *xa,
  565. const struct xa_node *node, unsigned int offset)
  566. {
  567. XA_NODE_BUG_ON(node, offset >= XA_CHUNK_SIZE);
  568. return rcu_dereference_protected(node->slots[offset],
  569. lockdep_is_held(&xa->xa_lock));
  570. }
  571. /* Private */
  572. static inline struct xa_node *xa_parent(const struct xarray *xa,
  573. const struct xa_node *node)
  574. {
  575. return rcu_dereference_check(node->parent,
  576. lockdep_is_held(&xa->xa_lock));
  577. }
  578. /* Private */
  579. static inline struct xa_node *xa_parent_locked(const struct xarray *xa,
  580. const struct xa_node *node)
  581. {
  582. return rcu_dereference_protected(node->parent,
  583. lockdep_is_held(&xa->xa_lock));
  584. }
  585. /* Private */
  586. static inline void *xa_mk_node(const struct xa_node *node)
  587. {
  588. return (void *)((unsigned long)node | 2);
  589. }
  590. /* Private */
  591. static inline struct xa_node *xa_to_node(const void *entry)
  592. {
  593. return (struct xa_node *)((unsigned long)entry - 2);
  594. }
  595. /* Private */
  596. static inline bool xa_is_node(const void *entry)
  597. {
  598. return xa_is_internal(entry) && (unsigned long)entry > 4096;
  599. }
  600. /* Private */
  601. static inline void *xa_mk_sibling(unsigned int offset)
  602. {
  603. return xa_mk_internal(offset);
  604. }
  605. /* Private */
  606. static inline unsigned long xa_to_sibling(const void *entry)
  607. {
  608. return xa_to_internal(entry);
  609. }
  610. /**
  611. * xa_is_sibling() - Is the entry a sibling entry?
  612. * @entry: Entry retrieved from the XArray
  613. *
  614. * Return: %true if the entry is a sibling entry.
  615. */
  616. static inline bool xa_is_sibling(const void *entry)
  617. {
  618. return IS_ENABLED(CONFIG_XARRAY_MULTI) && xa_is_internal(entry) &&
  619. (entry < xa_mk_sibling(XA_CHUNK_SIZE - 1));
  620. }
  621. #define XA_ZERO_ENTRY xa_mk_internal(256)
  622. #define XA_RETRY_ENTRY xa_mk_internal(257)
  623. /**
  624. * xa_is_zero() - Is the entry a zero entry?
  625. * @entry: Entry retrieved from the XArray
  626. *
  627. * Return: %true if the entry is a zero entry.
  628. */
  629. static inline bool xa_is_zero(const void *entry)
  630. {
  631. return unlikely(entry == XA_ZERO_ENTRY);
  632. }
  633. /**
  634. * xa_is_retry() - Is the entry a retry entry?
  635. * @entry: Entry retrieved from the XArray
  636. *
  637. * Return: %true if the entry is a retry entry.
  638. */
  639. static inline bool xa_is_retry(const void *entry)
  640. {
  641. return unlikely(entry == XA_RETRY_ENTRY);
  642. }
  643. /**
  644. * typedef xa_update_node_t - A callback function from the XArray.
  645. * @node: The node which is being processed
  646. *
  647. * This function is called every time the XArray updates the count of
  648. * present and value entries in a node. It allows advanced users to
  649. * maintain the private_list in the node.
  650. *
  651. * Context: The xa_lock is held and interrupts may be disabled.
  652. * Implementations should not drop the xa_lock, nor re-enable
  653. * interrupts.
  654. */
  655. typedef void (*xa_update_node_t)(struct xa_node *node);
  656. /*
  657. * The xa_state is opaque to its users. It contains various different pieces
  658. * of state involved in the current operation on the XArray. It should be
  659. * declared on the stack and passed between the various internal routines.
  660. * The various elements in it should not be accessed directly, but only
  661. * through the provided accessor functions. The below documentation is for
  662. * the benefit of those working on the code, not for users of the XArray.
  663. *
  664. * @xa_node usually points to the xa_node containing the slot we're operating
  665. * on (and @xa_offset is the offset in the slots array). If there is a
  666. * single entry in the array at index 0, there are no allocated xa_nodes to
  667. * point to, and so we store %NULL in @xa_node. @xa_node is set to
  668. * the value %XAS_RESTART if the xa_state is not walked to the correct
  669. * position in the tree of nodes for this operation. If an error occurs
  670. * during an operation, it is set to an %XAS_ERROR value. If we run off the
  671. * end of the allocated nodes, it is set to %XAS_BOUNDS.
  672. */
  673. struct xa_state {
  674. struct xarray *xa;
  675. unsigned long xa_index;
  676. unsigned char xa_shift;
  677. unsigned char xa_sibs;
  678. unsigned char xa_offset;
  679. unsigned char xa_pad; /* Helps gcc generate better code */
  680. struct xa_node *xa_node;
  681. struct xa_node *xa_alloc;
  682. xa_update_node_t xa_update;
  683. };
  684. /*
  685. * We encode errnos in the xas->xa_node. If an error has happened, we need to
  686. * drop the lock to fix it, and once we've done so the xa_state is invalid.
  687. */
  688. #define XA_ERROR(errno) ((struct xa_node *)(((unsigned long)errno << 2) | 2UL))
  689. #define XAS_BOUNDS ((struct xa_node *)1UL)
  690. #define XAS_RESTART ((struct xa_node *)3UL)
  691. #define __XA_STATE(array, index, shift, sibs) { \
  692. .xa = array, \
  693. .xa_index = index, \
  694. .xa_shift = shift, \
  695. .xa_sibs = sibs, \
  696. .xa_offset = 0, \
  697. .xa_pad = 0, \
  698. .xa_node = XAS_RESTART, \
  699. .xa_alloc = NULL, \
  700. .xa_update = NULL \
  701. }
  702. /**
  703. * XA_STATE() - Declare an XArray operation state.
  704. * @name: Name of this operation state (usually xas).
  705. * @array: Array to operate on.
  706. * @index: Initial index of interest.
  707. *
  708. * Declare and initialise an xa_state on the stack.
  709. */
  710. #define XA_STATE(name, array, index) \
  711. struct xa_state name = __XA_STATE(array, index, 0, 0)
  712. /**
  713. * XA_STATE_ORDER() - Declare an XArray operation state.
  714. * @name: Name of this operation state (usually xas).
  715. * @array: Array to operate on.
  716. * @index: Initial index of interest.
  717. * @order: Order of entry.
  718. *
  719. * Declare and initialise an xa_state on the stack. This variant of
  720. * XA_STATE() allows you to specify the 'order' of the element you
  721. * want to operate on.`
  722. */
  723. #define XA_STATE_ORDER(name, array, index, order) \
  724. struct xa_state name = __XA_STATE(array, \
  725. (index >> order) << order, \
  726. order - (order % XA_CHUNK_SHIFT), \
  727. (1U << (order % XA_CHUNK_SHIFT)) - 1)
  728. #define xas_marked(xas, mark) xa_marked((xas)->xa, (mark))
  729. #define xas_trylock(xas) xa_trylock((xas)->xa)
  730. #define xas_lock(xas) xa_lock((xas)->xa)
  731. #define xas_unlock(xas) xa_unlock((xas)->xa)
  732. #define xas_lock_bh(xas) xa_lock_bh((xas)->xa)
  733. #define xas_unlock_bh(xas) xa_unlock_bh((xas)->xa)
  734. #define xas_lock_irq(xas) xa_lock_irq((xas)->xa)
  735. #define xas_unlock_irq(xas) xa_unlock_irq((xas)->xa)
  736. #define xas_lock_irqsave(xas, flags) \
  737. xa_lock_irqsave((xas)->xa, flags)
  738. #define xas_unlock_irqrestore(xas, flags) \
  739. xa_unlock_irqrestore((xas)->xa, flags)
  740. /**
  741. * xas_error() - Return an errno stored in the xa_state.
  742. * @xas: XArray operation state.
  743. *
  744. * Return: 0 if no error has been noted. A negative errno if one has.
  745. */
  746. static inline int xas_error(const struct xa_state *xas)
  747. {
  748. return xa_err(xas->xa_node);
  749. }
  750. /**
  751. * xas_set_err() - Note an error in the xa_state.
  752. * @xas: XArray operation state.
  753. * @err: Negative error number.
  754. *
  755. * Only call this function with a negative @err; zero or positive errors
  756. * will probably not behave the way you think they should. If you want
  757. * to clear the error from an xa_state, use xas_reset().
  758. */
  759. static inline void xas_set_err(struct xa_state *xas, long err)
  760. {
  761. xas->xa_node = XA_ERROR(err);
  762. }
  763. /**
  764. * xas_invalid() - Is the xas in a retry or error state?
  765. * @xas: XArray operation state.
  766. *
  767. * Return: %true if the xas cannot be used for operations.
  768. */
  769. static inline bool xas_invalid(const struct xa_state *xas)
  770. {
  771. return (unsigned long)xas->xa_node & 3;
  772. }
  773. /**
  774. * xas_valid() - Is the xas a valid cursor into the array?
  775. * @xas: XArray operation state.
  776. *
  777. * Return: %true if the xas can be used for operations.
  778. */
  779. static inline bool xas_valid(const struct xa_state *xas)
  780. {
  781. return !xas_invalid(xas);
  782. }
  783. /**
  784. * xas_is_node() - Does the xas point to a node?
  785. * @xas: XArray operation state.
  786. *
  787. * Return: %true if the xas currently references a node.
  788. */
  789. static inline bool xas_is_node(const struct xa_state *xas)
  790. {
  791. return xas_valid(xas) && xas->xa_node;
  792. }
  793. /* True if the pointer is something other than a node */
  794. static inline bool xas_not_node(struct xa_node *node)
  795. {
  796. return ((unsigned long)node & 3) || !node;
  797. }
  798. /* True if the node represents RESTART or an error */
  799. static inline bool xas_frozen(struct xa_node *node)
  800. {
  801. return (unsigned long)node & 2;
  802. }
  803. /* True if the node represents head-of-tree, RESTART or BOUNDS */
  804. static inline bool xas_top(struct xa_node *node)
  805. {
  806. return node <= XAS_RESTART;
  807. }
  808. /**
  809. * xas_reset() - Reset an XArray operation state.
  810. * @xas: XArray operation state.
  811. *
  812. * Resets the error or walk state of the @xas so future walks of the
  813. * array will start from the root. Use this if you have dropped the
  814. * xarray lock and want to reuse the xa_state.
  815. *
  816. * Context: Any context.
  817. */
  818. static inline void xas_reset(struct xa_state *xas)
  819. {
  820. xas->xa_node = XAS_RESTART;
  821. }
  822. /**
  823. * xas_retry() - Retry the operation if appropriate.
  824. * @xas: XArray operation state.
  825. * @entry: Entry from xarray.
  826. *
  827. * The advanced functions may sometimes return an internal entry, such as
  828. * a retry entry or a zero entry. This function sets up the @xas to restart
  829. * the walk from the head of the array if needed.
  830. *
  831. * Context: Any context.
  832. * Return: true if the operation needs to be retried.
  833. */
  834. static inline bool xas_retry(struct xa_state *xas, const void *entry)
  835. {
  836. if (xa_is_zero(entry))
  837. return true;
  838. if (!xa_is_retry(entry))
  839. return false;
  840. xas_reset(xas);
  841. return true;
  842. }
  843. void *xas_load(struct xa_state *);
  844. void *xas_store(struct xa_state *, void *entry);
  845. void *xas_find(struct xa_state *, unsigned long max);
  846. void *xas_find_conflict(struct xa_state *);
  847. bool xas_get_mark(const struct xa_state *, xa_mark_t);
  848. void xas_set_mark(const struct xa_state *, xa_mark_t);
  849. void xas_clear_mark(const struct xa_state *, xa_mark_t);
  850. void *xas_find_marked(struct xa_state *, unsigned long max, xa_mark_t);
  851. void xas_init_marks(const struct xa_state *);
  852. bool xas_nomem(struct xa_state *, gfp_t);
  853. void xas_pause(struct xa_state *);
  854. void xas_create_range(struct xa_state *);
  855. /**
  856. * xas_reload() - Refetch an entry from the xarray.
  857. * @xas: XArray operation state.
  858. *
  859. * Use this function to check that a previously loaded entry still has
  860. * the same value. This is useful for the lockless pagecache lookup where
  861. * we walk the array with only the RCU lock to protect us, lock the page,
  862. * then check that the page hasn't moved since we looked it up.
  863. *
  864. * The caller guarantees that @xas is still valid. If it may be in an
  865. * error or restart state, call xas_load() instead.
  866. *
  867. * Return: The entry at this location in the xarray.
  868. */
  869. static inline void *xas_reload(struct xa_state *xas)
  870. {
  871. struct xa_node *node = xas->xa_node;
  872. if (node)
  873. return xa_entry(xas->xa, node, xas->xa_offset);
  874. return xa_head(xas->xa);
  875. }
  876. /**
  877. * xas_set() - Set up XArray operation state for a different index.
  878. * @xas: XArray operation state.
  879. * @index: New index into the XArray.
  880. *
  881. * Move the operation state to refer to a different index. This will
  882. * have the effect of starting a walk from the top; see xas_next()
  883. * to move to an adjacent index.
  884. */
  885. static inline void xas_set(struct xa_state *xas, unsigned long index)
  886. {
  887. xas->xa_index = index;
  888. xas->xa_node = XAS_RESTART;
  889. }
  890. /**
  891. * xas_set_order() - Set up XArray operation state for a multislot entry.
  892. * @xas: XArray operation state.
  893. * @index: Target of the operation.
  894. * @order: Entry occupies 2^@order indices.
  895. */
  896. static inline void xas_set_order(struct xa_state *xas, unsigned long index,
  897. unsigned int order)
  898. {
  899. #ifdef CONFIG_XARRAY_MULTI
  900. xas->xa_index = order < BITS_PER_LONG ? (index >> order) << order : 0;
  901. xas->xa_shift = order - (order % XA_CHUNK_SHIFT);
  902. xas->xa_sibs = (1 << (order % XA_CHUNK_SHIFT)) - 1;
  903. xas->xa_node = XAS_RESTART;
  904. #else
  905. BUG_ON(order > 0);
  906. xas_set(xas, index);
  907. #endif
  908. }
  909. /**
  910. * xas_set_update() - Set up XArray operation state for a callback.
  911. * @xas: XArray operation state.
  912. * @update: Function to call when updating a node.
  913. *
  914. * The XArray can notify a caller after it has updated an xa_node.
  915. * This is advanced functionality and is only needed by the page cache.
  916. */
  917. static inline void xas_set_update(struct xa_state *xas, xa_update_node_t update)
  918. {
  919. xas->xa_update = update;
  920. }
  921. /**
  922. * xas_next_entry() - Advance iterator to next present entry.
  923. * @xas: XArray operation state.
  924. * @max: Highest index to return.
  925. *
  926. * xas_next_entry() is an inline function to optimise xarray traversal for
  927. * speed. It is equivalent to calling xas_find(), and will call xas_find()
  928. * for all the hard cases.
  929. *
  930. * Return: The next present entry after the one currently referred to by @xas.
  931. */
  932. static inline void *xas_next_entry(struct xa_state *xas, unsigned long max)
  933. {
  934. struct xa_node *node = xas->xa_node;
  935. void *entry;
  936. if (unlikely(xas_not_node(node) || node->shift ||
  937. xas->xa_offset != (xas->xa_index & XA_CHUNK_MASK)))
  938. return xas_find(xas, max);
  939. do {
  940. if (unlikely(xas->xa_index >= max))
  941. return xas_find(xas, max);
  942. if (unlikely(xas->xa_offset == XA_CHUNK_MASK))
  943. return xas_find(xas, max);
  944. entry = xa_entry(xas->xa, node, xas->xa_offset + 1);
  945. if (unlikely(xa_is_internal(entry)))
  946. return xas_find(xas, max);
  947. xas->xa_offset++;
  948. xas->xa_index++;
  949. } while (!entry);
  950. return entry;
  951. }
  952. /* Private */
  953. static inline unsigned int xas_find_chunk(struct xa_state *xas, bool advance,
  954. xa_mark_t mark)
  955. {
  956. unsigned long *addr = xas->xa_node->marks[(__force unsigned)mark];
  957. unsigned int offset = xas->xa_offset;
  958. if (advance)
  959. offset++;
  960. if (XA_CHUNK_SIZE == BITS_PER_LONG) {
  961. if (offset < XA_CHUNK_SIZE) {
  962. unsigned long data = *addr & (~0UL << offset);
  963. if (data)
  964. return __ffs(data);
  965. }
  966. return XA_CHUNK_SIZE;
  967. }
  968. return find_next_bit(addr, XA_CHUNK_SIZE, offset);
  969. }
  970. /**
  971. * xas_next_marked() - Advance iterator to next marked entry.
  972. * @xas: XArray operation state.
  973. * @max: Highest index to return.
  974. * @mark: Mark to search for.
  975. *
  976. * xas_next_marked() is an inline function to optimise xarray traversal for
  977. * speed. It is equivalent to calling xas_find_marked(), and will call
  978. * xas_find_marked() for all the hard cases.
  979. *
  980. * Return: The next marked entry after the one currently referred to by @xas.
  981. */
  982. static inline void *xas_next_marked(struct xa_state *xas, unsigned long max,
  983. xa_mark_t mark)
  984. {
  985. struct xa_node *node = xas->xa_node;
  986. unsigned int offset;
  987. if (unlikely(xas_not_node(node) || node->shift))
  988. return xas_find_marked(xas, max, mark);
  989. offset = xas_find_chunk(xas, true, mark);
  990. xas->xa_offset = offset;
  991. xas->xa_index = (xas->xa_index & ~XA_CHUNK_MASK) + offset;
  992. if (xas->xa_index > max)
  993. return NULL;
  994. if (offset == XA_CHUNK_SIZE)
  995. return xas_find_marked(xas, max, mark);
  996. return xa_entry(xas->xa, node, offset);
  997. }
  998. /*
  999. * If iterating while holding a lock, drop the lock and reschedule
  1000. * every %XA_CHECK_SCHED loops.
  1001. */
  1002. enum {
  1003. XA_CHECK_SCHED = 4096,
  1004. };
  1005. /**
  1006. * xas_for_each() - Iterate over a range of an XArray.
  1007. * @xas: XArray operation state.
  1008. * @entry: Entry retrieved from the array.
  1009. * @max: Maximum index to retrieve from array.
  1010. *
  1011. * The loop body will be executed for each entry present in the xarray
  1012. * between the current xas position and @max. @entry will be set to
  1013. * the entry retrieved from the xarray. It is safe to delete entries
  1014. * from the array in the loop body. You should hold either the RCU lock
  1015. * or the xa_lock while iterating. If you need to drop the lock, call
  1016. * xas_pause() first.
  1017. */
  1018. #define xas_for_each(xas, entry, max) \
  1019. for (entry = xas_find(xas, max); entry; \
  1020. entry = xas_next_entry(xas, max))
  1021. /**
  1022. * xas_for_each_marked() - Iterate over a range of an XArray.
  1023. * @xas: XArray operation state.
  1024. * @entry: Entry retrieved from the array.
  1025. * @max: Maximum index to retrieve from array.
  1026. * @mark: Mark to search for.
  1027. *
  1028. * The loop body will be executed for each marked entry in the xarray
  1029. * between the current xas position and @max. @entry will be set to
  1030. * the entry retrieved from the xarray. It is safe to delete entries
  1031. * from the array in the loop body. You should hold either the RCU lock
  1032. * or the xa_lock while iterating. If you need to drop the lock, call
  1033. * xas_pause() first.
  1034. */
  1035. #define xas_for_each_marked(xas, entry, max, mark) \
  1036. for (entry = xas_find_marked(xas, max, mark); entry; \
  1037. entry = xas_next_marked(xas, max, mark))
  1038. /**
  1039. * xas_for_each_conflict() - Iterate over a range of an XArray.
  1040. * @xas: XArray operation state.
  1041. * @entry: Entry retrieved from the array.
  1042. *
  1043. * The loop body will be executed for each entry in the XArray that lies
  1044. * within the range specified by @xas. If the loop completes successfully,
  1045. * any entries that lie in this range will be replaced by @entry. The caller
  1046. * may break out of the loop; if they do so, the contents of the XArray will
  1047. * be unchanged. The operation may fail due to an out of memory condition.
  1048. * The caller may also call xa_set_err() to exit the loop while setting an
  1049. * error to record the reason.
  1050. */
  1051. #define xas_for_each_conflict(xas, entry) \
  1052. while ((entry = xas_find_conflict(xas)))
  1053. void *__xas_next(struct xa_state *);
  1054. void *__xas_prev(struct xa_state *);
  1055. /**
  1056. * xas_prev() - Move iterator to previous index.
  1057. * @xas: XArray operation state.
  1058. *
  1059. * If the @xas was in an error state, it will remain in an error state
  1060. * and this function will return %NULL. If the @xas has never been walked,
  1061. * it will have the effect of calling xas_load(). Otherwise one will be
  1062. * subtracted from the index and the state will be walked to the correct
  1063. * location in the array for the next operation.
  1064. *
  1065. * If the iterator was referencing index 0, this function wraps
  1066. * around to %ULONG_MAX.
  1067. *
  1068. * Return: The entry at the new index. This may be %NULL or an internal
  1069. * entry.
  1070. */
  1071. static inline void *xas_prev(struct xa_state *xas)
  1072. {
  1073. struct xa_node *node = xas->xa_node;
  1074. if (unlikely(xas_not_node(node) || node->shift ||
  1075. xas->xa_offset == 0))
  1076. return __xas_prev(xas);
  1077. xas->xa_index--;
  1078. xas->xa_offset--;
  1079. return xa_entry(xas->xa, node, xas->xa_offset);
  1080. }
  1081. /**
  1082. * xas_next() - Move state to next index.
  1083. * @xas: XArray operation state.
  1084. *
  1085. * If the @xas was in an error state, it will remain in an error state
  1086. * and this function will return %NULL. If the @xas has never been walked,
  1087. * it will have the effect of calling xas_load(). Otherwise one will be
  1088. * added to the index and the state will be walked to the correct
  1089. * location in the array for the next operation.
  1090. *
  1091. * If the iterator was referencing index %ULONG_MAX, this function wraps
  1092. * around to 0.
  1093. *
  1094. * Return: The entry at the new index. This may be %NULL or an internal
  1095. * entry.
  1096. */
  1097. static inline void *xas_next(struct xa_state *xas)
  1098. {
  1099. struct xa_node *node = xas->xa_node;
  1100. if (unlikely(xas_not_node(node) || node->shift ||
  1101. xas->xa_offset == XA_CHUNK_MASK))
  1102. return __xas_next(xas);
  1103. xas->xa_index++;
  1104. xas->xa_offset++;
  1105. return xa_entry(xas->xa, node, xas->xa_offset);
  1106. }
  1107. #endif /* _LINUX_XARRAY_H */