@@ -278,8 +278,12 @@ depot_alloc_stack(unsigned long *entries, int size, u32 hash, void **prealloc)
278
278
return NULL ;
279
279
}
280
280
281
- /* Move on to the next pool. */
282
- pool_index ++ ;
281
+ /*
282
+ * Move on to the next pool.
283
+ * WRITE_ONCE pairs with potential concurrent read in
284
+ * stack_depot_fetch().
285
+ */
286
+ WRITE_ONCE (pool_index , pool_index + 1 );
283
287
pool_offset = 0 ;
284
288
/*
285
289
* If the maximum number of pools is not reached, take note
@@ -502,6 +506,11 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle,
502
506
unsigned long * * entries )
503
507
{
504
508
union handle_parts parts = { .handle = handle };
509
+ /*
510
+ * READ_ONCE pairs with potential concurrent write in
511
+ * depot_alloc_stack.
512
+ */
513
+ int pool_index_cached = READ_ONCE (pool_index );
505
514
void * pool ;
506
515
size_t offset = parts .offset << DEPOT_STACK_ALIGN ;
507
516
struct stack_record * stack ;
@@ -510,9 +519,9 @@ unsigned int stack_depot_fetch(depot_stack_handle_t handle,
510
519
if (!handle )
511
520
return 0 ;
512
521
513
- if (parts .pool_index > pool_index ) {
522
+ if (parts .pool_index > pool_index_cached ) {
514
523
WARN (1 , "pool index %d out of bounds (%d) for stack id %08x\n" ,
515
- parts .pool_index , pool_index , handle );
524
+ parts .pool_index , pool_index_cached , handle );
516
525
return 0 ;
517
526
}
518
527
pool = stack_pools [parts .pool_index ];
0 commit comments