static inline struct maple_node *ma_to_node(const void *entry)
{
BUG_ON(!xa_is_node(entry));
- return (struct maple_node *)((unsigned long)entry - 2);
+ return (struct maple_node *)((unsigned long)entry & ~127);
}
-static inline void *ma_mk_node(const struct maple_node *node)
+static inline
+void *ma_mk_node(const struct maple_node *node, enum maple_type type)
{
BUG_ON(xa_is_node(node));
- return (void *)((unsigned long)node | 2);
+ return (void *)((unsigned long)node | (type << 2) | 2);
}
-
void mtree_init(struct maple_tree *mt) {
spin_lock_init(&mt->ma_lock);
mt->ma_flags = 0;
}
#ifdef MT_DEBUG
-void mn_dump(void *entry, unsigned long min, unsigned long max)
+void mn_dump(void *entry, unsigned long min, unsigned long max,
+ unsigned int depth)
{
if (min == max)
pr_info("%lu: ", min);
pr_info("%lu-%lu: ", min, max);
if (xa_is_node(entry)) {
- struct maple_sparse_64 *mn64 = &ma_to_node(entry)->ms64;
- unsigned long prev = min;
+ struct maple_range_64 *node = &ma_to_node(entry)->mr64;
+ unsigned long first = min;
unsigned int i;
- pr_cont("node %p parent %p contents: ", mn64, mn64->parent);
- for (i = 0; i < MAPLE_RANGE64_SLOTS; i++) {
- pr_cont("%p %lu ", mn64->slot[i], mn64->pivot[i]);
+ pr_cont("node %p depth %d parent %p contents: ", node, depth,
+ node->parent);
+ for (i = 0; i < MAPLE_RANGE64_SLOTS - 1; i++) {
+ pr_cont("%p %lu ", node->slot[i], node->pivot[i]);
}
- pr_cont("%p\n", mn64->slot[i]);
-
- for (i = 0; i < MAPLE_RANGE64_SLOTS -1; i++) {
- unsigned long next = max + 1;
- if (i < MAPLE_RANGE64_SLOTS)
- next = mn64->pivot[i];
- mn_dump(mn64->slot[i], prev, next - 1);
- if (next == 0 || (next - 1) >= max)
+ pr_cont("%p\n", node->slot[i]);
+
+ for (i = 0; i < MAPLE_RANGE64_SLOTS; i++) {
+ unsigned long last = max;
+
+ if (i < (MAPLE_RANGE64_SLOTS - 1))
+ last = node->pivot[i];
+ if (last == 0 && i > 0)
break;
- prev = next;
+ mn_dump(node->slot[i], first, last, depth + 1);
+ if (last > max) {
+ pr_err("node %p last (%lu) > max (%lu) at pivot %d!\n", node, last, max, i);
+ break;
+ }
+ first = last + 1;
}
} else if (xa_is_value(entry))
pr_cont("value %ld (0x%lx) [%p]\n", xa_to_value(entry),
pr_cont("UNKNOWN ENTRY (%p)\n", entry);
}
+unsigned long mt_max[] = {
+ MAPLE_NODE_SLOTS,
+ ULONG_MAX,
+ UINT_MAX,
+ (1UL << 16) - 1,
+ ULONG_MAX,
+ UINT_MAX,
+ (1UL << 21) - 1,
+ (1UL << 16) - 1,
+ (1UL << 9) - 1,
+ (1UL << 6) - 1,
+};
+
void mt_dump(const struct maple_tree *mt)
{
void *entry = mt->ma_root;
- unsigned long min = 0;
- unsigned long max = ULONG_MAX;
+ unsigned long max;
if (!xa_is_node(entry))
max = 0;
- pr_info("maple_tree(%p) flags %X, root %p, min %lu, max %lu\n",
- mt, mt->ma_flags, entry, min, max);
- mn_dump(entry, min, max);
+ else
+ max = mt_max[xa_to_internal(entry) & 15];
+
+ pr_info("maple_tree(%p) flags %X, root %p, max %lu\n",
+ mt, mt->ma_flags, entry, max);
+ mn_dump(entry, 0, max, 0);
}
#endif