1
0
Fork 0
alistair23-linux/tools/testing/radix-tree
Matthew Wilcox (Oracle) 07378b0991 xarray: Fix early termination of xas_for_each_marked
commit 7e934cf5ac upstream.

xas_for_each_marked() is using entry == NULL as a termination condition
of the iteration. When xas_for_each_marked() is used protected only by
RCU, this can however race with xas_store(xas, NULL) in the following
way:

TASK1                                   TASK2
page_cache_delete()         	        find_get_pages_range_tag()
                                          xas_for_each_marked()
                                            xas_find_marked()
                                              off = xas_find_chunk()

  xas_store(&xas, NULL)
    xas_init_marks(&xas);
    ...
    rcu_assign_pointer(*slot, NULL);
                                              entry = xa_entry(off);

And thus xas_for_each_marked() terminates prematurely possibly leading
to missed entries in the iteration (translating to missing writeback of
some pages or a similar problem).

If we find a NULL entry that has been marked, skip it (unless we're trying
to allocate an entry).

Reported-by: Jan Kara <jack@suse.cz>
CC: stable@vger.kernel.org
Fixes: ef8e5717db ("page cache: Convert delete_batch to XArray")
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-04-17 10:50:18 +02:00
..
generated radix tree: Remove multiorder support 2018-10-21 10:46:48 -04:00
linux rcu: Don't return a value from rcu_assign_pointer() 2019-06-13 15:38:34 -07:00
.gitignore xarray: Add XArray load operation 2018-10-21 10:45:57 -04:00
Makefile xarray: Fix early termination of xas_for_each_marked 2020-04-17 10:50:18 +02:00
benchmark.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 288 2019-06-05 17:36:37 +02:00
bitmap.c xarray: Add XArray unconditional store operations 2018-10-21 10:45:57 -04:00
idr-test.c XArray updates for 5.2-rc6 2019-06-29 17:14:57 +08:00
iteration_check.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 288 2019-06-05 17:36:37 +02:00
iteration_check_2.c xarray: Fix early termination of xas_for_each_marked 2020-04-17 10:50:18 +02:00
linux.c radix tree test suite: Fix build 2018-02-25 06:00:11 -05:00
main.c xarray: Fix early termination of xas_for_each_marked 2020-04-17 10:50:18 +02:00
multiorder.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 288 2019-06-05 17:36:37 +02:00
regression.h radix tree: Don't return retry entries from lookup 2018-12-06 08:26:16 -05:00
regression1.c radix tree test suite: Convert tag_tagged_items to XArray 2018-10-21 10:46:45 -04:00
regression2.c radix tree test suite: Convert tag_tagged_items to XArray 2018-10-21 10:46:45 -04:00
regression3.c page cache: Convert find_get_pages_contig to XArray 2018-10-21 10:46:34 -04:00
regression4.c radix tree: Don't return retry entries from lookup 2018-12-06 08:26:16 -05:00
tag_check.c radix tree test suite: Convert tag_tagged_items to XArray 2018-10-21 10:46:45 -04:00
test.c radix tree tests: Convert item_delete_rcu to XArray 2018-10-21 10:46:48 -04:00
test.h xarray: Fix early termination of xas_for_each_marked 2020-04-17 10:50:18 +02:00
xarray.c xarray: Add XArray load operation 2018-10-21 10:45:57 -04:00