drm/buddy: fix issue that force_merge cannot free all roots
Subsystems (3)
PATCH 1/1 drm/buddy: fix issue that force_merge cannot free all roots
If buddy manager have more than one roots and each root have sub-block need to be free. When drm_buddy_fini called, the first loop of force_merge will merge and free all of the sub block of first root, which offset is 0x0 and size is biggest(more than have of the mm size). In subsequent force_merge rounds, if we use 0 as start and use remaining mm size as end, the block of other roots will be skipped in __force_merge function. It will cause the other roots can not be freed.
Solution: use roots' offset as the start could fix this issue.
--- drivers/gpu/drm/drm_buddy.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/drm_buddy.c +3 -2
@@ -324,7 +324,7 @@ EXPORT_SYMBOL(drm_buddy_init);*/ void drm_buddy_fini (struct drm_buddy *mm) { -u64 root_size, size; +u64 root_size, size, start;unsigned int order;int i;
@@ -332,7 +332,8 @@ void drm_buddy_fini(struct drm_buddy *mm)for (i =0 ; i < mm->n_roots; ++i) { order =ilog2 (size) -ilog2 (mm->chunk_size); -__force_merge (mm,0 , size, order); + start =drm_buddy_block_offset (mm->roots[i]); +__force_merge (mm, start, start + size, order);WARN_ON (!drm_buddy_block_is_free (mm->roots[i]));drm_block_free (mm, mm->roots[i]);
Signature · 1 line
2.45.2
Matthew Auld
maintainerQuoted 9 lines · Lin.Cao
If buddy manager have more than one roots and each root have sub-block need to be free. When
drm_buddy_finicalled, the first loop offorce_mergewill merge and free all of the sub block of first root, which offset is0x0and size is biggest(more than have of the mm size). In subsequentforce_mergerounds, if we use 0 as start and use remaining mm size as end, the block of other roots will be skipped in__force_mergefunction. It will cause the other roots can not be freed.Solution: use roots' offset as the start could fix this issue.
Were you able to take a look at the test side for this? See previous reply: https://lore.kernel.org/dri-devel/[email protected]/
Patch itself is good, but would be good to understand why the test for this is not failing, and try to improve that also.
Quoted 29 lines
Signed-off-by Lin.Cao <[email protected]>--- drivers/gpu/drm/drm_buddy.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)drivers/gpu/drm/drm_buddy.c +3
-2@@ -324,7 +324,7 @@ EXPORT_SYMBOL(drm_buddy_init);*/ void drm_buddy_fini (struct drm_buddy *mm) { -u64 root_size, size; +u64 root_size, size, start;unsigned int order;int i;@@ -332,7 +332,8 @@ void drm_buddy_fini(struct drm_buddy *mm)for (i =0 ; i < mm->n_roots; ++i) { order =ilog2 (size) -ilog2 (mm->chunk_size); -__force_merge (mm,0 , size, order); + start =drm_buddy_block_offset (mm->roots[i]); +__force_merge (mm, start, start + size, order);WARN_ON (!drm_buddy_block_is_free (mm->roots[i]));drm_block_free (mm, mm->roots[i]);