Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'xarray-5.4' of git://git.infradead.org/users/willy/linux-dax

Pull XArray fixes from Matthew Wilcox:
"These all fix various bugs, some of which people have tripped over and
some of which have been caught by automatic tools"

* tag 'xarray-5.4' of git://git.infradead.org/users/willy/linux-dax:
idr: Fix idr_alloc_u32 on 32-bit systems
idr: Fix integer overflow in idr_for_each_entry
radix tree: Remove radix_tree_iter_find
idr: Fix idr_get_next_ul race with idr_remove
XArray: Fix xas_next() with a single entry at 0

+41 -40
+1 -1
include/linux/idr.h
··· 185 185 * is convenient for a "not found" value. 186 186 */ 187 187 #define idr_for_each_entry(idr, entry, id) \ 188 - for (id = 0; ((entry) = idr_get_next(idr, &(id))) != NULL; ++id) 188 + for (id = 0; ((entry) = idr_get_next(idr, &(id))) != NULL; id += 1U) 189 189 190 190 /** 191 191 * idr_for_each_entry_ul() - Iterate over an IDR's elements of a given type.
-18
include/linux/radix-tree.h
··· 316 316 } 317 317 318 318 /** 319 - * radix_tree_iter_find - find a present entry 320 - * @root: radix tree root 321 - * @iter: iterator state 322 - * @index: start location 323 - * 324 - * This function returns the slot containing the entry with the lowest index 325 - * which is at least @index. If @index is larger than any present entry, this 326 - * function returns NULL. The @iter is updated to describe the entry found. 327 - */ 328 - static inline void __rcu ** 329 - radix_tree_iter_find(const struct radix_tree_root *root, 330 - struct radix_tree_iter *iter, unsigned long index) 331 - { 332 - radix_tree_iter_init(iter, index); 333 - return radix_tree_next_chunk(root, iter, 0); 334 - } 335 - 336 - /** 337 319 * radix_tree_iter_retry - retry this chunk of the iteration 338 320 * @iter: iterator state 339 321 *
+11 -20
lib/idr.c
··· 215 215 EXPORT_SYMBOL(idr_for_each); 216 216 217 217 /** 218 - * idr_get_next() - Find next populated entry. 218 + * idr_get_next_ul() - Find next populated entry. 219 219 * @idr: IDR handle. 220 220 * @nextid: Pointer to an ID. 221 221 * ··· 224 224 * to the ID of the found value. To use in a loop, the value pointed to by 225 225 * nextid must be incremented by the user. 226 226 */ 227 - void *idr_get_next(struct idr *idr, int *nextid) 227 + void *idr_get_next_ul(struct idr *idr, unsigned long *nextid) 228 228 { 229 229 struct radix_tree_iter iter; 230 230 void __rcu **slot; ··· 245 245 } 246 246 if (!slot) 247 247 return NULL; 248 - id = iter.index + base; 249 248 250 - if (WARN_ON_ONCE(id > INT_MAX)) 251 - return NULL; 252 - 253 - *nextid = id; 249 + *nextid = iter.index + base; 254 250 return entry; 255 251 } 256 - EXPORT_SYMBOL(idr_get_next); 252 + EXPORT_SYMBOL(idr_get_next_ul); 257 253 258 254 /** 259 - * idr_get_next_ul() - Find next populated entry. 255 + * idr_get_next() - Find next populated entry. 260 256 * @idr: IDR handle. 261 257 * @nextid: Pointer to an ID. 262 258 * ··· 261 265 * to the ID of the found value. To use in a loop, the value pointed to by 262 266 * nextid must be incremented by the user. 263 267 */ 264 - void *idr_get_next_ul(struct idr *idr, unsigned long *nextid) 268 + void *idr_get_next(struct idr *idr, int *nextid) 265 269 { 266 - struct radix_tree_iter iter; 267 - void __rcu **slot; 268 - unsigned long base = idr->idr_base; 269 270 unsigned long id = *nextid; 271 + void *entry = idr_get_next_ul(idr, &id); 270 272 271 - id = (id < base) ? 0 : id - base; 272 - slot = radix_tree_iter_find(&idr->idr_rt, &iter, id); 273 - if (!slot) 273 + if (WARN_ON_ONCE(id > INT_MAX)) 274 274 return NULL; 275 - 276 - *nextid = iter.index + base; 277 - return rcu_dereference_raw(*slot); 275 + *nextid = id; 276 + return entry; 278 277 } 279 - EXPORT_SYMBOL(idr_get_next_ul); 278 + EXPORT_SYMBOL(idr_get_next); 280 279 281 280 /** 282 281 * idr_replace() - replace pointer for given ID.
+1 -1
lib/radix-tree.c
··· 1529 1529 offset = radix_tree_find_next_bit(node, IDR_FREE, 1530 1530 offset + 1); 1531 1531 start = next_index(start, node, offset); 1532 - if (start > max) 1532 + if (start > max || start == 0) 1533 1533 return ERR_PTR(-ENOSPC); 1534 1534 while (offset == RADIX_TREE_MAP_SIZE) { 1535 1535 offset = node->offset + 1;
+24
lib/test_xarray.c
··· 1110 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 1135 static noinline void check_move_small(struct xarray *xa, unsigned long idx) 1114 1136 { 1115 1137 XA_STATE(xas, xa, 0); ··· 1238 1216 rcu_read_unlock(); 1239 1217 1240 1218 xa_destroy(xa); 1219 + 1220 + check_move_tiny(xa); 1241 1221 1242 1222 for (i = 0; i < 16; i++) 1243 1223 check_move_small(xa, 1UL << i);
+4
lib/xarray.c
··· 994 994 995 995 if (!xas_frozen(xas->xa_node)) 996 996 xas->xa_index--; 997 + if (!xas->xa_node) 998 + return set_bounds(xas); 997 999 if (xas_not_node(xas->xa_node)) 998 1000 return xas_load(xas); 999 1001 ··· 1033 1031 1034 1032 if (!xas_frozen(xas->xa_node)) 1035 1033 xas->xa_index++; 1034 + if (!xas->xa_node) 1035 + return set_bounds(xas); 1036 1036 if (xas_not_node(xas->xa_node)) 1037 1037 return xas_load(xas); 1038 1038