mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-01-01 10:43:43 +00:00
XArray: Fix splitting to non-zero orders
Splitting an order-4 entry into order-2 entries would leave the array containing pointers to 000040008000c000 instead of 000044448888cccc. This is a one-character fix, but enhance the test suite to check this case. Reported-by: Zi Yan <ziy@nvidia.com> Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
This commit is contained in:
parent
12efebab09
commit
3012110d71
@ -1530,24 +1530,24 @@ static noinline void check_store_range(struct xarray *xa)
|
|||||||
|
|
||||||
#ifdef CONFIG_XARRAY_MULTI
|
#ifdef CONFIG_XARRAY_MULTI
|
||||||
static void check_split_1(struct xarray *xa, unsigned long index,
|
static void check_split_1(struct xarray *xa, unsigned long index,
|
||||||
unsigned int order)
|
unsigned int order, unsigned int new_order)
|
||||||
{
|
{
|
||||||
XA_STATE(xas, xa, index);
|
XA_STATE_ORDER(xas, xa, index, new_order);
|
||||||
void *entry;
|
unsigned int i;
|
||||||
unsigned int i = 0;
|
|
||||||
|
|
||||||
xa_store_order(xa, index, order, xa, GFP_KERNEL);
|
xa_store_order(xa, index, order, xa, GFP_KERNEL);
|
||||||
|
|
||||||
xas_split_alloc(&xas, xa, order, GFP_KERNEL);
|
xas_split_alloc(&xas, xa, order, GFP_KERNEL);
|
||||||
xas_lock(&xas);
|
xas_lock(&xas);
|
||||||
xas_split(&xas, xa, order);
|
xas_split(&xas, xa, order);
|
||||||
|
for (i = 0; i < (1 << order); i += (1 << new_order))
|
||||||
|
__xa_store(xa, index + i, xa_mk_index(index + i), 0);
|
||||||
xas_unlock(&xas);
|
xas_unlock(&xas);
|
||||||
|
|
||||||
xa_for_each(xa, index, entry) {
|
for (i = 0; i < (1 << order); i++) {
|
||||||
XA_BUG_ON(xa, entry != xa);
|
unsigned int val = index + (i & ~((1 << new_order) - 1));
|
||||||
i++;
|
XA_BUG_ON(xa, xa_load(xa, index + i) != xa_mk_index(val));
|
||||||
}
|
}
|
||||||
XA_BUG_ON(xa, i != 1 << order);
|
|
||||||
|
|
||||||
xa_set_mark(xa, index, XA_MARK_0);
|
xa_set_mark(xa, index, XA_MARK_0);
|
||||||
XA_BUG_ON(xa, !xa_get_mark(xa, index, XA_MARK_0));
|
XA_BUG_ON(xa, !xa_get_mark(xa, index, XA_MARK_0));
|
||||||
@ -1557,14 +1557,16 @@ static void check_split_1(struct xarray *xa, unsigned long index,
|
|||||||
|
|
||||||
static noinline void check_split(struct xarray *xa)
|
static noinline void check_split(struct xarray *xa)
|
||||||
{
|
{
|
||||||
unsigned int order;
|
unsigned int order, new_order;
|
||||||
|
|
||||||
XA_BUG_ON(xa, !xa_empty(xa));
|
XA_BUG_ON(xa, !xa_empty(xa));
|
||||||
|
|
||||||
for (order = 1; order < 2 * XA_CHUNK_SHIFT; order++) {
|
for (order = 1; order < 2 * XA_CHUNK_SHIFT; order++) {
|
||||||
check_split_1(xa, 0, order);
|
for (new_order = 0; new_order < order; new_order++) {
|
||||||
check_split_1(xa, 1UL << order, order);
|
check_split_1(xa, 0, order, new_order);
|
||||||
check_split_1(xa, 3UL << order, order);
|
check_split_1(xa, 1UL << order, order, new_order);
|
||||||
|
check_split_1(xa, 3UL << order, order, new_order);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -1011,7 +1011,7 @@ void xas_split_alloc(struct xa_state *xas, void *entry, unsigned int order,
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
void *sibling;
|
void *sibling = NULL;
|
||||||
struct xa_node *node;
|
struct xa_node *node;
|
||||||
|
|
||||||
node = kmem_cache_alloc(radix_tree_node_cachep, gfp);
|
node = kmem_cache_alloc(radix_tree_node_cachep, gfp);
|
||||||
@ -1021,7 +1021,7 @@ void xas_split_alloc(struct xa_state *xas, void *entry, unsigned int order,
|
|||||||
for (i = 0; i < XA_CHUNK_SIZE; i++) {
|
for (i = 0; i < XA_CHUNK_SIZE; i++) {
|
||||||
if ((i & mask) == 0) {
|
if ((i & mask) == 0) {
|
||||||
RCU_INIT_POINTER(node->slots[i], entry);
|
RCU_INIT_POINTER(node->slots[i], entry);
|
||||||
sibling = xa_mk_sibling(0);
|
sibling = xa_mk_sibling(i);
|
||||||
} else {
|
} else {
|
||||||
RCU_INIT_POINTER(node->slots[i], sibling);
|
RCU_INIT_POINTER(node->slots[i], sibling);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user