diff options
author | Matthew Wilcox (Oracle) <willy@infradead.org> | 2019-07-01 17:03:29 -0400 |
---|---|---|
committer | Matthew Wilcox (Oracle) <willy@infradead.org> | 2019-07-01 17:11:16 -0400 |
commit | 91abab83839aa2eba073e4a63c729832fdb27ea1 (patch) | |
tree | 3a083d68dc7d4fdca445313c74852943fafbf7f4 /lib | |
parent | 6fbc7275c7a9ba97877050335f290341a1fd8dbf (diff) |
XArray: Fix xas_next() with a single entry at 0
If there is only a single entry at 0, the first time we call xas_next(),
we return the entry. Unfortunately, all subsequent times we call
xas_next(), we also return the entry at 0 instead of noticing that the
xa_index is now greater than zero. This broke find_get_pages_contig().
Fixes: 64d3e9a9e0cc ("xarray: Step through an XArray")
Reported-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/test_xarray.c | 24 | ||||
-rw-r--r-- | lib/xarray.c | 4 |
2 files changed, 28 insertions, 0 deletions
diff --git a/lib/test_xarray.c b/lib/test_xarray.c index 9d631a7b6a70..7df4f7f395bf 100644 --- a/lib/test_xarray.c +++ b/lib/test_xarray.c | |||
@@ -1110,6 +1110,28 @@ static noinline void check_find_entry(struct xarray *xa) | |||
1110 | XA_BUG_ON(xa, !xa_empty(xa)); | 1110 | XA_BUG_ON(xa, !xa_empty(xa)); |
1111 | } | 1111 | } |
1112 | 1112 | ||
1113 | static noinline void check_move_tiny(struct xarray *xa) | ||
1114 | { | ||
1115 | XA_STATE(xas, xa, 0); | ||
1116 | |||
1117 | XA_BUG_ON(xa, !xa_empty(xa)); | ||
1118 | rcu_read_lock(); | ||
1119 | XA_BUG_ON(xa, xas_next(&xas) != NULL); | ||
1120 | XA_BUG_ON(xa, xas_next(&xas) != NULL); | ||
1121 | rcu_read_unlock(); | ||
1122 | xa_store_index(xa, 0, GFP_KERNEL); | ||
1123 | rcu_read_lock(); | ||
1124 | xas_set(&xas, 0); | ||
1125 | XA_BUG_ON(xa, xas_next(&xas) != xa_mk_index(0)); | ||
1126 | XA_BUG_ON(xa, xas_next(&xas) != NULL); | ||
1127 | xas_set(&xas, 0); | ||
1128 | XA_BUG_ON(xa, xas_prev(&xas) != xa_mk_index(0)); | ||
1129 | XA_BUG_ON(xa, xas_prev(&xas) != NULL); | ||
1130 | rcu_read_unlock(); | ||
1131 | xa_erase_index(xa, 0); | ||
1132 | XA_BUG_ON(xa, !xa_empty(xa)); | ||
1133 | } | ||
1134 | |||
1113 | static noinline void check_move_small(struct xarray *xa, unsigned long idx) | 1135 | static noinline void check_move_small(struct xarray *xa, unsigned long idx) |
1114 | { | 1136 | { |
1115 | XA_STATE(xas, xa, 0); | 1137 | XA_STATE(xas, xa, 0); |
@@ -1217,6 +1239,8 @@ static noinline void check_move(struct xarray *xa) | |||
1217 | 1239 | ||
1218 | xa_destroy(xa); | 1240 | xa_destroy(xa); |
1219 | 1241 | ||
1242 | check_move_tiny(xa); | ||
1243 | |||
1220 | for (i = 0; i < 16; i++) | 1244 | for (i = 0; i < 16; i++) |
1221 | check_move_small(xa, 1UL << i); | 1245 | check_move_small(xa, 1UL << i); |
1222 | 1246 | ||
diff --git a/lib/xarray.c b/lib/xarray.c index 446b956c9188..1237c213f52b 100644 --- a/lib/xarray.c +++ b/lib/xarray.c | |||
@@ -994,6 +994,8 @@ void *__xas_prev(struct xa_state *xas) | |||
994 | 994 | ||
995 | if (!xas_frozen(xas->xa_node)) | 995 | if (!xas_frozen(xas->xa_node)) |
996 | xas->xa_index--; | 996 | xas->xa_index--; |
997 | if (!xas->xa_node) | ||
998 | return set_bounds(xas); | ||
997 | if (xas_not_node(xas->xa_node)) | 999 | if (xas_not_node(xas->xa_node)) |
998 | return xas_load(xas); | 1000 | return xas_load(xas); |
999 | 1001 | ||
@@ -1031,6 +1033,8 @@ void *__xas_next(struct xa_state *xas) | |||
1031 | 1033 | ||
1032 | if (!xas_frozen(xas->xa_node)) | 1034 | if (!xas_frozen(xas->xa_node)) |
1033 | xas->xa_index++; | 1035 | xas->xa_index++; |
1036 | if (!xas->xa_node) | ||
1037 | return set_bounds(xas); | ||
1034 | if (xas_not_node(xas->xa_node)) | 1038 | if (xas_not_node(xas->xa_node)) |
1035 | return xas_load(xas); | 1039 | return xas_load(xas); |
1036 | 1040 | ||