2016-03-18 00:21:45 +03:00
# include <linux/gfp.h>
# include <linux/types.h>
# include <linux/radix-tree.h>
# include <linux/rcupdate.h>
struct item {
unsigned long index ;
2016-12-15 02:08:23 +03:00
unsigned int order ;
2016-03-18 00:21:45 +03:00
} ;
2016-12-15 02:08:23 +03:00
struct item * item_create ( unsigned long index , unsigned int order ) ;
int __item_insert ( struct radix_tree_root * root , struct item * item ) ;
2016-03-18 00:21:45 +03:00
int item_insert ( struct radix_tree_root * root , unsigned long index ) ;
2016-05-21 03:02:14 +03:00
int item_insert_order ( struct radix_tree_root * root , unsigned long index ,
unsigned order ) ;
2016-03-18 00:21:45 +03:00
int item_delete ( struct radix_tree_root * root , unsigned long index ) ;
struct item * item_lookup ( struct radix_tree_root * root , unsigned long index ) ;
void item_check_present ( struct radix_tree_root * root , unsigned long index ) ;
void item_check_absent ( struct radix_tree_root * root , unsigned long index ) ;
void item_gang_check_present ( struct radix_tree_root * root ,
unsigned long start , unsigned long nr ,
int chunk , int hop ) ;
void item_full_scan ( struct radix_tree_root * root , unsigned long start ,
unsigned long nr , int chunk ) ;
void item_kill_tree ( struct radix_tree_root * root ) ;
2016-12-15 02:08:55 +03:00
int tag_tagged_items ( struct radix_tree_root * , pthread_mutex_t * ,
unsigned long start , unsigned long end , unsigned batch ,
unsigned iftag , unsigned thentag ) ;
2016-12-15 02:08:52 +03:00
unsigned long find_item ( struct radix_tree_root * , void * item ) ;
2016-03-18 00:21:45 +03:00
void tag_check ( void ) ;
2016-05-21 03:02:14 +03:00
void multiorder_checks ( void ) ;
radix-tree tests: add iteration test
There are four cases I can see where we could end up with a NULL 'slot' in
radix_tree_next_slot(). This unit test exercises all four of them, making
sure that if in the future we have an unsafe path through
radix_tree_next_slot(), we'll catch it.
Here are details on the four cases:
1) radix_tree_iter_retry() via a non-tagged iteration like
radix_tree_for_each_slot(). In this case we currently aren't seeing a bug
because radix_tree_iter_retry() sets
iter->next_index = iter->index;
which means that in in the else case in radix_tree_next_slot(), 'count' is
zero, so we skip over the while() loop and effectively just return NULL
without ever dereferencing 'slot'.
2) radix_tree_iter_retry() via tagged iteration like
radix_tree_for_each_tagged(). This case was giving us NULL pointer
dereferences in testing, and was fixed with this commit:
commit 3cb9185c6730 ("radix-tree: fix radix_tree_iter_retry() for tagged
iterators.")
This fix doesn't explicitly check for 'slot' being NULL, though, it works
around the NULL pointer dereference by instead zeroing iter->tags in
radix_tree_iter_retry(), which makes us bail out of the if() case in
radix_tree_next_slot() before we dereference 'slot'.
3) radix_tree_iter_next() via via a non-tagged iteration like
radix_tree_for_each_slot(). This currently happens in shmem_tag_pins()
and shmem_partial_swap_usage().
As with non-tagged iteration, 'count' in the else case of
radix_tree_next_slot() is zero, so we skip over the while() loop and
effectively just return NULL without ever dereferencing 'slot'.
4) radix_tree_iter_next() via tagged iteration like
radix_tree_for_each_tagged(). This happens in shmem_wait_for_pins().
radix_tree_iter_next() zeros out iter->tags, so we end up exiting
radix_tree_next_slot() here:
if (flags & RADIX_TREE_ITER_TAGGED) {
void *canon = slot;
iter->tags >>= 1;
if (unlikely(!iter->tags))
return NULL;
Link: http://lkml.kernel.org/r/20160815194237.25967-3-ross.zwisler@linux.intel.com
Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Andrey Ryabinin <aryabinin@virtuozzo.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Shuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2016-10-11 23:51:21 +03:00
void iteration_test ( void ) ;
2016-12-15 02:08:14 +03:00
void benchmark ( void ) ;
2016-03-18 00:21:45 +03:00
struct item *
item_tag_set ( struct radix_tree_root * root , unsigned long index , int tag ) ;
struct item *
item_tag_clear ( struct radix_tree_root * root , unsigned long index , int tag ) ;
int item_tag_get ( struct radix_tree_root * root , unsigned long index , int tag ) ;
void tree_verify_min_height ( struct radix_tree_root * root , int maxindex ) ;
void verify_tag_consistency ( struct radix_tree_root * root , unsigned int tag ) ;
extern int nr_allocated ;
/* Normally private parts of lib/radix-tree.c */
2016-12-15 02:08:49 +03:00
struct radix_tree_node * entry_to_node ( void * ptr ) ;
2016-05-21 03:02:55 +03:00
void radix_tree_dump ( struct radix_tree_root * root ) ;
2016-03-18 00:21:45 +03:00
int root_tag_get ( struct radix_tree_root * root , unsigned int tag ) ;
2016-05-21 03:03:16 +03:00
unsigned long node_maxindex ( struct radix_tree_node * ) ;
unsigned long shift_maxindex ( unsigned int shift ) ;
2016-12-15 02:08:05 +03:00
int radix_tree_cpu_dead ( unsigned int cpu ) ;
2016-12-15 02:09:04 +03:00
struct radix_tree_preload {
unsigned nr ;
struct radix_tree_node * nodes ;
} ;
extern struct radix_tree_preload radix_tree_preloads ;