-/* The IDR tag is stored in the low bits of the GFP flags */+/* The IDR tag is stored in the low bits of xa_flags */ #define ROOT_IS_IDR ((__force gfp_t)4)-/* The top bits of gfp_mask are used to store the root tags */+/* The top bits of xa_flags are used to store the root tags */ #define ROOT_TAG_SHIFT (__GFP_BITS_SHIFT)

+/**+ * struct xarray - The anchor of the XArray.+ * @xa_lock: Lock that protects the contents of the XArray.+ *+ * To use the xarray, define it statically or embed it in your data structure.+ * It is a very small data structure, so it does not usually make sense to+ * allocate it separately and keep a pointer to it in your data structure.+ *+ * You may use the xa_lock to protect your own data structures as well.+ */+/*+ * If all of the entries in the array are NULL, @xa_head is a NULL pointer.+ * If the only non-NULL entry in the array is at index 0, @xa_head is that+ * entry. If any other entry in the array is non-NULL, @xa_head points+ * to an @xa_node.+ */+struct xarray {+ spinlock_t xa_lock;+/* private: The rest of the data structure is not to be used directly. */+ gfp_t xa_flags;+ void __rcu * xa_head;+};++#define XARRAY_INIT_FLAGS(name, flags) { \+ .xa_lock = __SPIN_LOCK_UNLOCKED(name.xa_lock), \+ .xa_flags = flags, \+ .xa_head = NULL, \+}++#define XARRAY_INIT(name) XARRAY_INIT_FLAGS(name, 0)++/**+ * DEFINE_XARRAY() - Define an XArray+ * @name: A string that names your XArray+ *+ * This is intended for file scope definitions of XArrays. It declares+ * and initialises an empty XArray with the chosen name. It is equivalent+ * to calling xa_init() on the array, but it does the initialisation at+ * compiletime instead of runtime.+ */+#define DEFINE_XARRAY(name) struct xarray name = XARRAY_INIT(name)+#define DEFINE_XARRAY_FLAGS(name, flags) \+ struct xarray name = XARRAY_INIT_FLAGS(name, flags)++void xa_init_flags(struct xarray *, gfp_t flags);++/**+ * xa_init() - Initialise an empty XArray.+ * @xa: XArray.+ *+ * An empty XArray is full of NULL entries.+ *+ * Context: Any context.+ */+static inline void xa_init(struct xarray *xa)+{+ xa_init_flags(xa, 0);+}+ #define xa_trylock(xa) spin_trylock(&(xa)->xa_lock) #define xa_lock(xa) spin_lock(&(xa)->xa_lock) #define xa_unlock(xa) spin_unlock(&(xa)->xa_lock)diff --git a/lib/Makefile b/lib/Makefileindex f3503f8074ad..4c517b2066cc 100644--- a/lib/Makefile+++ b/lib/Makefile@@ -18,7 +18,7 @@ KCOV_INSTRUMENT_debugobjects.o := n KCOV_INSTRUMENT_dynamic_debug.o := n

if (!radix_tree_is_internal_node(node))@@ -687,9 +687,9 @@ static inline bool radix_tree_shrink(struct radix_tree_root *root, * moving the node from one part of the tree to another: if it * was safe to dereference the old pointer to it * (node->slots[0]), it will be safe to dereference the new- * one (root->rnode) as far as dependent read barriers go.+ * one (root->xa_head) as far as dependent read barriers go. */- root->rnode = (void __rcu *)child;+ root->xa_head = (void __rcu *)child; if (is_idr(root) && !tag_get(node, IDR_FREE, 0)) root_tag_clear(root, IDR_FREE);

while (shift > order) {@@ -996,7 +995,7 @@ EXPORT_SYMBOL(__radix_tree_insert); * tree @root. * * Until there is more than one item in the tree, no nodes are- * allocated and @root->rnode is used as a direct slot instead of+ * allocated and @root->xa_head is used as a direct slot instead of * pointing to a node, in which case *@nodep will be NULL. */ void *__radix_tree_lookup(const struct radix_tree_root *root,@@ -1009,7 +1008,7 @@ void *__radix_tree_lookup(const struct radix_tree_root *root,