Commit 7475851f authored by Konstantin Khlebnikov's avatar Konstantin Khlebnikov Committed by Linus Torvalds

radix-tree tests: add test for radix_tree_iter_next

Without fix test crashes inside tagged iteration.
Signed-off-by: default avatarKonstantin Khlebnikov <koct9i@gmail.com>
Cc: Matthew Wilcox <willy@linux.intel.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 2d6f45b8
...@@ -5,6 +5,10 @@ ...@@ -5,6 +5,10 @@
* In following radix_tree_next_slot current chunk size becomes zero. * In following radix_tree_next_slot current chunk size becomes zero.
* This isn't checked and it tries to dereference null pointer in slot. * This isn't checked and it tries to dereference null pointer in slot.
* *
* Helper radix_tree_iter_next reset slot to NULL and next_index to index + 1,
* for tagger iteraction it also must reset cached tags in iterator to abort
* next radix_tree_next_slot and go to slow-path into radix_tree_next_chunk.
*
* Running: * Running:
* This test should run to completion immediately. The above bug would * This test should run to completion immediately. The above bug would
* cause it to segfault. * cause it to segfault.
...@@ -24,26 +28,27 @@ ...@@ -24,26 +28,27 @@
void regression3_test(void) void regression3_test(void)
{ {
RADIX_TREE(root, GFP_KERNEL); RADIX_TREE(root, GFP_KERNEL);
void *ptr = (void *)4ul; void *ptr0 = (void *)4ul;
void *ptr = (void *)8ul;
struct radix_tree_iter iter; struct radix_tree_iter iter;
void **slot; void **slot;
bool first; bool first;
printf("running regression test 3 (should take milliseconds)\n"); printf("running regression test 3 (should take milliseconds)\n");
radix_tree_insert(&root, 0, ptr); radix_tree_insert(&root, 0, ptr0);
radix_tree_tag_set(&root, 0, 0); radix_tree_tag_set(&root, 0, 0);
first = true; first = true;
radix_tree_for_each_tagged(slot, &root, &iter, 0, 0) { radix_tree_for_each_tagged(slot, &root, &iter, 0, 0) {
// printk("tagged %ld %p\n", iter.index, *slot); printf("tagged %ld %p\n", iter.index, *slot);
if (first) { if (first) {
radix_tree_insert(&root, 1, ptr); radix_tree_insert(&root, 1, ptr);
radix_tree_tag_set(&root, 1, 0); radix_tree_tag_set(&root, 1, 0);
first = false; first = false;
} }
if (radix_tree_deref_retry(*slot)) { if (radix_tree_deref_retry(*slot)) {
// printk("retry %ld\n", iter.index); printf("retry at %ld\n", iter.index);
slot = radix_tree_iter_retry(&iter); slot = radix_tree_iter_retry(&iter);
continue; continue;
} }
...@@ -52,13 +57,13 @@ void regression3_test(void) ...@@ -52,13 +57,13 @@ void regression3_test(void)
first = true; first = true;
radix_tree_for_each_slot(slot, &root, &iter, 0) { radix_tree_for_each_slot(slot, &root, &iter, 0) {
// printk("slot %ld %p\n", iter.index, *slot); printf("slot %ld %p\n", iter.index, *slot);
if (first) { if (first) {
radix_tree_insert(&root, 1, ptr); radix_tree_insert(&root, 1, ptr);
first = false; first = false;
} }
if (radix_tree_deref_retry(*slot)) { if (radix_tree_deref_retry(*slot)) {
// printk("retry %ld\n", iter.index); printk("retry at %ld\n", iter.index);
slot = radix_tree_iter_retry(&iter); slot = radix_tree_iter_retry(&iter);
continue; continue;
} }
...@@ -67,18 +72,44 @@ void regression3_test(void) ...@@ -67,18 +72,44 @@ void regression3_test(void)
first = true; first = true;
radix_tree_for_each_contig(slot, &root, &iter, 0) { radix_tree_for_each_contig(slot, &root, &iter, 0) {
// printk("contig %ld %p\n", iter.index, *slot); printk("contig %ld %p\n", iter.index, *slot);
if (first) { if (first) {
radix_tree_insert(&root, 1, ptr); radix_tree_insert(&root, 1, ptr);
first = false; first = false;
} }
if (radix_tree_deref_retry(*slot)) { if (radix_tree_deref_retry(*slot)) {
// printk("retry %ld\n", iter.index); printk("retry at %ld\n", iter.index);
slot = radix_tree_iter_retry(&iter); slot = radix_tree_iter_retry(&iter);
continue; continue;
} }
} }
radix_tree_for_each_slot(slot, &root, &iter, 0) {
printf("slot %ld %p\n", iter.index, *slot);
if (!iter.index) {
printf("next at %ld\n", iter.index);
slot = radix_tree_iter_next(&iter);
}
}
radix_tree_for_each_contig(slot, &root, &iter, 0) {
printf("contig %ld %p\n", iter.index, *slot);
if (!iter.index) {
printf("next at %ld\n", iter.index);
slot = radix_tree_iter_next(&iter);
}
}
radix_tree_tag_set(&root, 0, 0);
radix_tree_tag_set(&root, 1, 0);
radix_tree_for_each_tagged(slot, &root, &iter, 0, 0) {
printf("tagged %ld %p\n", iter.index, *slot);
if (!iter.index) {
printf("next at %ld\n", iter.index);
slot = radix_tree_iter_next(&iter);
}
}
radix_tree_delete(&root, 0); radix_tree_delete(&root, 0);
radix_tree_delete(&root, 1); radix_tree_delete(&root, 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment