Skip to content

Commit 1fa4df3

Browse files
dennisszhouhtejun
authored andcommitted
percpu: fix iteration to prevent skipping over block
The iterator functions pcpu_next_md_free_region and pcpu_next_fit_region use the block offset to determine if they have checked the area in the prior iteration. However, this causes an issue when the block offset is greater than subsequent block contig hints. If within the iterator it moves to check subsequent blocks, it may fail in the second predicate due to the block offset not being cleared. Thus, this causes the allocator to skip over blocks leading to false failures when allocating from the reserved chunk. While this happens in the general case as well, it will only fail if it cannot allocate a new chunk. This patch resets the block offset to 0 to pass the second predicate when checking subseqent blocks within the iterator function. Signed-off-by: Dennis Zhou <[email protected]> Reported-and-tested-by: Luis Henriques <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 2e08d20 commit 1fa4df3

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

mm/percpu.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,8 @@ static void pcpu_next_md_free_region(struct pcpu_chunk *chunk, int *bit_off,
353353
block->contig_hint_start);
354354
return;
355355
}
356+
/* reset to satisfy the second predicate above */
357+
block_off = 0;
356358

357359
*bits = block->right_free;
358360
*bit_off = (i + 1) * PCPU_BITMAP_BLOCK_BITS - block->right_free;
@@ -407,6 +409,8 @@ static void pcpu_next_fit_region(struct pcpu_chunk *chunk, int alloc_bits,
407409
*bit_off = pcpu_block_off_to_off(i, block->first_free);
408410
return;
409411
}
412+
/* reset to satisfy the second predicate above */
413+
block_off = 0;
410414

411415
*bit_off = ALIGN(PCPU_BITMAP_BLOCK_BITS - block->right_free,
412416
align);

0 commit comments

Comments
 (0)