drm/ttm: once more fix ttm_bo_bulk_move_lru_tail
Subsystems (3)
PATCH 1/1 drm/ttm: once more fix ttm_bo_bulk_move_lru_tail
While cutting the lists we sometimes accidentally added a list_head from the stack to the LRUs, effectively corrupting the list.
Remove the list cutting and use explicit list manipulation instead.
--- drivers/gpu/drm/ttm/ttm_bo.c | 51 ++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 21 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +30 -21
@@ -247,23 +247,18 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_move_to_lru_tail); -static void ttm_bo_bulk_move_helper (struct ttm_lru_bulk_move_pos *pos, -struct list_head *lru,bool is_swap) +static void ttm_list_move_bulk_tail (struct list_head *list, +struct list_head *first, +struct list_head *last) { -struct list_head *list; -LIST_HEAD (entries); -LIST_HEAD (before); + first->prev->next = last->next; + last->next->prev = first->prev; -reservation_object_assert_held (pos->last->resv); - list = is_swap ? &pos->last->swap : &pos->last->lru; -list_cut_position (&entries, lru, list); + list->prev->next = first; + first->prev = list->prev; -reservation_object_assert_held (pos->first->resv); - list = is_swap ? pos->first->swap.prev : pos->first->lru.prev; -list_cut_position (&before, &entries, list); - -list_splice (&before, lru); -list_splice_tail (&entries, lru); + last->next = list; + list->prev = last; }void ttm_bo_bulk_move_lru_tail (struct ttm_lru_bulk_move *bulk)
@@ -271,23 +266,33 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)unsigned i;for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->tt[i];struct ttm_mem_type_manager *man; -if (!bulk->tt[i].first) +if (!pos->first)continue ; - man = &bulk->tt[i].first->bdev->man[TTM_PL_TT ]; -ttm_bo_bulk_move_helper (&bulk->tt[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_TT ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->vram[i];struct ttm_mem_type_manager *man; -if (!bulk->vram[i].first) +if (!pos->first)continue ; - man = &bulk->vram[i].first->bdev->man[TTM_PL_VRAM ]; -ttm_bo_bulk_move_helper (&bulk->vram[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_VRAM ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {
@@ -297,8 +302,12 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)if (!pos->first)continue ; +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + lru = &pos->first->bdev->glob->swap_lru[i]; -ttm_bo_bulk_move_helper (&bulk->swap[i], lru, true); +ttm_list_move_bulk_tail (lru, &pos->first->swap, + &pos->last->swap); } }EXPORT_SYMBOL (ttm_bo_bulk_move_lru_tail);
Signature · 6 lines
2.14.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 20180912192355.2359-1-christian.koenig-5C7GfCeVMHo@public.gmane.org
Alex Deucher
Acked-byQuoted 7 lines · Christian König
While cutting the lists we sometimes accidentally added a
list_headfrom the stack to the LRUs, effectively corrupting the list.Remove the list cutting and use explicit list manipulation instead.
Signed-off-by Christian König <[email protected]>
Quoted 98 lines
--- drivers/gpu/drm/ttm/ttm_bo.c | 51 ++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +30
-22@@ -247,23 +247,18 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_move_to_lru_tail); -static void ttm_bo_bulk_move_helper (struct ttm_lru_bulk_move_pos *pos, -struct list_head *lru,bool is_swap) +static void ttm_list_move_bulk_tail (struct list_head *list, +struct list_head *first, +struct list_head *last) { -struct list_head *list; -LIST_HEAD (entries); -LIST_HEAD (before); + first->prev->next = last->next; + last->next->prev = first->prev; -reservation_object_assert_held (pos->last->resv); - list = is_swap ? &pos->last->swap : &pos->last->lru; -list_cut_position (&entries, lru, list); + list->prev->next = first; + first->prev = list->prev; -reservation_object_assert_held (pos->first->resv); - list = is_swap ? pos->first->swap.prev : pos->first->lru.prev; -list_cut_position (&before, &entries, list); - -list_splice (&before, lru); -list_splice_tail (&entries, lru); + last->next = list; + list->prev = last; }void ttm_bo_bulk_move_lru_tail (struct ttm_lru_bulk_move *bulk)@@ -271,23 +266,33 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)unsigned i;for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->tt[i];struct ttm_mem_type_manager *man; -if (!bulk->tt[i].first) +if (!pos->first)continue ; - man = &bulk->tt[i].first->bdev->man[TTM_PL_TT ]; -ttm_bo_bulk_move_helper (&bulk->tt[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_TT ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->vram[i];struct ttm_mem_type_manager *man; -if (!bulk->vram[i].first) +if (!pos->first)continue ; - man = &bulk->vram[i].first->bdev->man[TTM_PL_VRAM ]; -ttm_bo_bulk_move_helper (&bulk->vram[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_VRAM ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {@@ -297,8 +302,12 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)if (!pos->first)continue ; +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + lru = &pos->first->bdev->glob->swap_lru[i]; -ttm_bo_bulk_move_helper (&bulk->swap[i], lru, true); +ttm_list_move_bulk_tail (lru, &pos->first->swap, + &pos->last->swap); } }EXPORT_SYMBOL (ttm_bo_bulk_move_lru_tail); --2.14.1
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 4 lines · Christian König
While cutting the lists we sometimes accidentally added a
list_headfrom the stack to the LRUs, effectively corrupting the list.Remove the list cutting and use explicit list manipulation instead.
This patch actually fixes the corruption bug. Was it a defect of list_cut_position or list_splice handlers?
Reviewed-and-Tested: Huang Rui <[email protected]>
Quoted 104 lines
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 51 ++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +30
-21@@ -247,23 +247,18 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_move_to_lru_tail); -static void ttm_bo_bulk_move_helper (struct ttm_lru_bulk_move_pos *pos, -struct list_head *lru,bool is_swap) +static void ttm_list_move_bulk_tail (struct list_head *list, +struct list_head *first, +struct list_head *last) { -struct list_head *list; -LIST_HEAD (entries); -LIST_HEAD (before); + first->prev->next = last->next; + last->next->prev = first->prev; -reservation_object_assert_held (pos->last->resv); - list = is_swap ? &pos->last->swap : &pos->last->lru; -list_cut_position (&entries, lru, list); + list->prev->next = first; + first->prev = list->prev; -reservation_object_assert_held (pos->first->resv); - list = is_swap ? pos->first->swap.prev : pos->first->lru.prev; -list_cut_position (&before, &entries, list); - -list_splice (&before, lru); -list_splice_tail (&entries, lru); + last->next = list; + list->prev = last; }void ttm_bo_bulk_move_lru_tail (struct ttm_lru_bulk_move *bulk)@@ -271,23 +266,33 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)unsigned i;for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->tt[i];struct ttm_mem_type_manager *man; -if (!bulk->tt[i].first) +if (!pos->first)continue ; - man = &bulk->tt[i].first->bdev->man[TTM_PL_TT ]; -ttm_bo_bulk_move_helper (&bulk->tt[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_TT ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->vram[i];struct ttm_mem_type_manager *man; -if (!bulk->vram[i].first) +if (!pos->first)continue ; - man = &bulk->vram[i].first->bdev->man[TTM_PL_VRAM ]; -ttm_bo_bulk_move_helper (&bulk->vram[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_VRAM ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {@@ -297,8 +302,12 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)if (!pos->first)continue ; +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + lru = &pos->first->bdev->glob->swap_lru[i]; -ttm_bo_bulk_move_helper (&bulk->swap[i], lru, true); +ttm_list_move_bulk_tail (lru, &pos->first->swap, + &pos->last->swap); } }EXPORT_SYMBOL (ttm_bo_bulk_move_lru_tail);Signature · 6 lines
2.14.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Am 13.09.2018 um 10:31 schrieb Huang Rui:
Quoted 7 lines · Christian König
Quoted 4 lines
While cutting the lists we sometimes accidentally added a
list_headfrom the stack to the LRUs, effectively corrupting the list.Remove the list cutting and use explicit list manipulation instead.
This patch actually fixes the corruption bug. Was it a defect of
list_cut_positionorlist_splicehandlers?
We somehow did something illegal with list_cut_position. I haven't narrowed it down till the end, but we ended up with list_heads from the stack to the lru.
Anyway adding a specialized list bulk move function is much simpler and avoids the issue.
I've just split that up as Michel suggested and send it out to the mailing lists, please review that version once more.
Thanks,
Christian.
Quoted 102 lines
Reviewed-and-Tested: Huang Rui <[email protected]>
Quoted 99 lines
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 51 ++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +30
-21@@ -247,23 +247,18 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_move_to_lru_tail); -static void ttm_bo_bulk_move_helper (struct ttm_lru_bulk_move_pos *pos, -struct list_head *lru,bool is_swap) +static void ttm_list_move_bulk_tail (struct list_head *list, +struct list_head *first, +struct list_head *last) { -struct list_head *list; -LIST_HEAD (entries); -LIST_HEAD (before); + first->prev->next = last->next; + last->next->prev = first->prev; -reservation_object_assert_held (pos->last->resv); - list = is_swap ? &pos->last->swap : &pos->last->lru; -list_cut_position (&entries, lru, list); + list->prev->next = first; + first->prev = list->prev; -reservation_object_assert_held (pos->first->resv); - list = is_swap ? pos->first->swap.prev : pos->first->lru.prev; -list_cut_position (&before, &entries, list); - -list_splice (&before, lru); -list_splice_tail (&entries, lru); + last->next = list; + list->prev = last; }void ttm_bo_bulk_move_lru_tail (struct ttm_lru_bulk_move *bulk)@@ -271,23 +266,33 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)unsigned i;for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->tt[i];struct ttm_mem_type_manager *man; -if (!bulk->tt[i].first) +if (!pos->first)continue ; - man = &bulk->tt[i].first->bdev->man[TTM_PL_TT ]; -ttm_bo_bulk_move_helper (&bulk->tt[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_TT ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->vram[i];struct ttm_mem_type_manager *man; -if (!bulk->vram[i].first) +if (!pos->first)continue ; - man = &bulk->vram[i].first->bdev->man[TTM_PL_VRAM ]; -ttm_bo_bulk_move_helper (&bulk->vram[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_VRAM ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {@@ -297,8 +302,12 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)if (!pos->first)continue ; +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + lru = &pos->first->bdev->glob->swap_lru[i]; -ttm_bo_bulk_move_helper (&bulk->swap[i], lru, true); +ttm_list_move_bulk_tail (lru, &pos->first->swap, + &pos->last->swap); } }EXPORT_SYMBOL (ttm_bo_bulk_move_lru_tail);Signature · 1 line
2.14.1
Quoted 4 lines
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): c2471ef9-1bc7-517e-27f6-a00236a9b40b-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
Quoted 5 lines · Christian König
Am 13.09.2018 um 10:31 schrieb Huang Rui:
Quoted 4 lines · Christian König
Quoted 3 lines
While cutting the lists we sometimes accidentally added a
list_headfrom the stack to the LRUs, effectively corrupting the list.
Quoted 8 lines
Quoted 3 lines
Quoted 1 line
Remove the list cutting and use explicit list manipulation instead.
This patch actually fixes the corruption bug. Was it a defect of
list_cut_positionorlist_splicehandlers?We somehow did something illegal with
list_cut_position. I haven't narrowed it down till the end, but we ended up withlist_headsfrom the stack to the lru.
I am confused, in theory, even we do any manipulation with list helper, it should not trigger the list corruption. The usage of those helpers should ensure the list operation safely...
Quoted 6 lines
Anyway adding a specialized list bulk move function is much simpler and avoids the issue.
I've just split that up as Michel suggested and send it out to the mailing lists, please review that version once more.
Sure, already reviewed.
Quoted 105 lines
Thanks,
Christian.Quoted 102 lines
Reviewed-and-Tested: Huang Rui <[email protected]>
Quoted 99 lines
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 51 ++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +30
-21@@ -247,23 +247,18 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_move_to_lru_tail); -static void ttm_bo_bulk_move_helper (struct ttm_lru_bulk_move_pos *pos, -struct list_head *lru,bool is_swap) +static void ttm_list_move_bulk_tail (struct list_head *list, +struct list_head *first, +struct list_head *last) { -struct list_head *list; -LIST_HEAD (entries); -LIST_HEAD (before); + first->prev->next = last->next; + last->next->prev = first->prev; -reservation_object_assert_held (pos->last->resv); - list = is_swap ? &pos->last->swap : &pos->last->lru; -list_cut_position (&entries, lru, list); + list->prev->next = first; + first->prev = list->prev; -reservation_object_assert_held (pos->first->resv); - list = is_swap ? pos->first->swap.prev : pos->first->lru.prev; -list_cut_position (&before, &entries, list); - -list_splice (&before, lru); -list_splice_tail (&entries, lru); + last->next = list; + list->prev = last; }void ttm_bo_bulk_move_lru_tail (struct ttm_lru_bulk_move *bulk)@@ -271,23 +266,33 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)unsigned i;for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->tt[i];struct ttm_mem_type_manager *man; -if (!bulk->tt[i].first) +if (!pos->first)continue ; - man = &bulk->tt[i].first->bdev->man[TTM_PL_TT ]; -ttm_bo_bulk_move_helper (&bulk->tt[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_TT ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->vram[i];struct ttm_mem_type_manager *man; -if (!bulk->vram[i].first) +if (!pos->first)continue ; - man = &bulk->vram[i].first->bdev->man[TTM_PL_VRAM ]; -ttm_bo_bulk_move_helper (&bulk->vram[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_VRAM ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {@@ -297,8 +302,12 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)if (!pos->first)continue ; +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + lru = &pos->first->bdev->glob->swap_lru[i]; -ttm_bo_bulk_move_helper (&bulk->swap[i], lru, true); +ttm_list_move_bulk_tail (lru, &pos->first->swap, + &pos->last->swap); } }EXPORT_SYMBOL (ttm_bo_bulk_move_lru_tail);Signature · 1 line
2.14.1
Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 10 lines · Huang Rui
Quoted 9 lines · Christian König
Am 13.09.2018 um 10:31 schrieb Huang Rui:
Quoted 7 lines · Christian König
Quoted 4 lines
While cutting the lists we sometimes accidentally added a
list_headfrom the stack to the LRUs, effectively corrupting the list.Remove the list cutting and use explicit list manipulation instead.
This patch actually fixes the corruption bug. Was it a defect of
list_cut_positionorlist_splicehandlers?
Quoted 7 lines
Quoted 3 lines
We somehow did something illegal with
list_cut_position. I haven't narrowed it down till the end, but we ended up withlist_headsfrom the stack to the lru.I am confused, in theory, even we do any manipulation with list helper, it should not trigger the list corruption. The usage of those helpers should ensure the list operation safely...
There's nothing the helpers can do about being passed in pointers to stack memory. It's a bug in the code using the helpers.
Signature · 6 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): 4bf23786-ffdb-ee6e-1446-9dbc8d8ed5d6-otUistvHUpPR7s880joybQ@public.gmane.org
Am 14.09.2018 um 11:22 schrieb Michel Dänzer:
Quoted 10 lines · Huang Rui
Quoted 9 lines · Christian König
Quoted 8 lines
Am 13.09.2018 um 10:31 schrieb Huang Rui:
Quoted 7 lines · Christian König
Quoted 4 lines
While cutting the lists we sometimes accidentally added a
list_headfrom the stack to the LRUs, effectively corrupting the list.Remove the list cutting and use explicit list manipulation instead.
This patch actually fixes the corruption bug. Was it a defect of
list_cut_positionorlist_splicehandlers?
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
We somehow did something illegal with
list_cut_position. I haven't narrowed it down till the end, but we ended up withlist_headsfrom the stack to the lru.I am confused, in theory, even we do any manipulation with list helper, it should not trigger the list corruption. The usage of those helpers should ensure the list operation safely...
There's nothing the helpers can do about being passed in pointers to stack memory. It's a bug in the code using the helpers.
Actually I'm not 100% sure of that. To me it looks like we hit a corner case list_cut_position doesn't support.
Or we indeed had a logic error in how we called it, anyway the explicit implementation only uses 6 assignments and so is much easier to handle.
Christian.
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 15 lines · Michel Dänzer
Quoted 14 lines · Huang Rui
Quoted 12 lines · Christian König
Am 13.09.2018 um 10:31 schrieb Huang Rui:
Quoted 7 lines · Christian König
Quoted 4 lines
While cutting the lists we sometimes accidentally added a
list_headfrom the stack to the LRUs, effectively corrupting the list.Remove the list cutting and use explicit list manipulation instead.
This patch actually fixes the corruption bug. Was it a defect of
list_cut_positionorlist_splicehandlers?We somehow did something illegal with
list_cut_position. I haven't narrowed it down till the end, but we ended up withlist_headsfrom the stack to the lru.
Quoted 7 lines
Quoted 3 lines
I am confused, in theory, even we do any manipulation with list helper, it should not trigger the list corruption. The usage of those helpers should ensure the list operation safely...
There's nothing the helpers can do about being passed in pointers to stack memory. It's a bug in the code using the helpers.
Actually, I was checking carefully with list cut and splice in our case, and it didn't find any illegal use. However, I also agree with the explicit list manipulation is more clear and simple for now.
Thanks,
Ray
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[ Moving to dri-devel, where TTM patches are reviewed ]
Quoted 92 lines · Christian König
While cutting the lists we sometimes accidentally added a
list_headfrom the stack to the LRUs, effectively corrupting the list.Remove the list cutting and use explicit list manipulation instead.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 51 ++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +25
-20@@ -247,23 +247,18 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_move_to_lru_tail); -static void ttm_bo_bulk_move_helper (struct ttm_lru_bulk_move_pos *pos, -struct list_head *lru,bool is_swap) +static void ttm_list_move_bulk_tail (struct list_head *list, +struct list_head *first, +struct list_head *last) { -struct list_head *list; -LIST_HEAD (entries); -LIST_HEAD (before); + first->prev->next = last->next; + last->next->prev = first->prev; -reservation_object_assert_held (pos->last->resv); - list = is_swap ? &pos->last->swap : &pos->last->lru; -list_cut_position (&entries, lru, list); + list->prev->next = first; + first->prev = list->prev; -reservation_object_assert_held (pos->first->resv); - list = is_swap ? pos->first->swap.prev : pos->first->lru.prev; -list_cut_position (&before, &entries, list); - -list_splice (&before, lru); -list_splice_tail (&entries, lru); + last->next = list; + list->prev = last; }void ttm_bo_bulk_move_lru_tail (struct ttm_lru_bulk_move *bulk)@@ -271,23 +266,33 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)unsigned i;for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->tt[i];struct ttm_mem_type_manager *man; -if (!bulk->tt[i].first) +if (!pos->first)continue ; - man = &bulk->tt[i].first->bdev->man[TTM_PL_TT ]; -ttm_bo_bulk_move_helper (&bulk->tt[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_TT ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->vram[i];struct ttm_mem_type_manager *man; -if (!bulk->vram[i].first) +if (!pos->first)continue ; - man = &bulk->vram[i].first->bdev->man[TTM_PL_VRAM ]; -ttm_bo_bulk_move_helper (&bulk->vram[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_VRAM ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {@@ -297,8 +302,12 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)if (!pos->first)continue ;
drivers/gpu/drm/ttm/ttm_bo.c void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk) · line 313
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +5
-1+reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + lru = &pos->first->bdev->glob->swap_lru[i]; -ttm_bo_bulk_move_helper (&bulk->swap[i], lru, true); +ttm_list_move_bulk_tail (lru, &pos->first->swap, + &pos->last->swap); } }EXPORT_SYMBOL (ttm_bo_bulk_move_lru_tail);
Seems like more code could be kept in / moved into the shared helper function. That would keep the ttm_bo_bulk_move_lru_tail code leaner, and might make the helper function changes easier to review as well.
Signature · 6 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 7 lines · Christian König
While cutting the lists we sometimes accidentally added a
list_headfrom the stack to the LRUs, effectively corrupting the list.Remove the list cutting and use explicit list manipulation instead.
Signed-off-by Christian König <[email protected]>
Can you apply this patch first and then do the clean up as a later series or temporarily disable the feature? I want to send out a -next pull this week and I don't want to leave this broken.
Alex
Quoted 98 lines
--- drivers/gpu/drm/ttm/ttm_bo.c | 51 ++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +30
-22@@ -247,23 +247,18 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_move_to_lru_tail); -static void ttm_bo_bulk_move_helper (struct ttm_lru_bulk_move_pos *pos, -struct list_head *lru,bool is_swap) +static void ttm_list_move_bulk_tail (struct list_head *list, +struct list_head *first, +struct list_head *last) { -struct list_head *list; -LIST_HEAD (entries); -LIST_HEAD (before); + first->prev->next = last->next; + last->next->prev = first->prev; -reservation_object_assert_held (pos->last->resv); - list = is_swap ? &pos->last->swap : &pos->last->lru; -list_cut_position (&entries, lru, list); + list->prev->next = first; + first->prev = list->prev; -reservation_object_assert_held (pos->first->resv); - list = is_swap ? pos->first->swap.prev : pos->first->lru.prev; -list_cut_position (&before, &entries, list); - -list_splice (&before, lru); -list_splice_tail (&entries, lru); + last->next = list; + list->prev = last; }void ttm_bo_bulk_move_lru_tail (struct ttm_lru_bulk_move *bulk)@@ -271,23 +266,33 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)unsigned i;for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->tt[i];struct ttm_mem_type_manager *man; -if (!bulk->tt[i].first) +if (!pos->first)continue ; - man = &bulk->tt[i].first->bdev->man[TTM_PL_TT ]; -ttm_bo_bulk_move_helper (&bulk->tt[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_TT ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->vram[i];struct ttm_mem_type_manager *man; -if (!bulk->vram[i].first) +if (!pos->first)continue ; - man = &bulk->vram[i].first->bdev->man[TTM_PL_VRAM ]; -ttm_bo_bulk_move_helper (&bulk->vram[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_VRAM ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {@@ -297,8 +302,12 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)if (!pos->first)continue ; +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + lru = &pos->first->bdev->glob->swap_lru[i]; -ttm_bo_bulk_move_helper (&bulk->swap[i], lru, true); +ttm_list_move_bulk_tail (lru, &pos->first->swap, + &pos->last->swap); } }EXPORT_SYMBOL (ttm_bo_bulk_move_lru_tail); --2.14.1
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
A message that is not in the archive (sent off-list or not yet received): CADnq5_PiVfsBjGxN0wsbHL0o5rWYRuVehTeZvN396kp=GVZTNA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Am 13.09.2018 um 16:25 schrieb Alex Deucher:
Quoted 11 lines
Quoted 6 lines · Christian König
While cutting the lists we sometimes accidentally added a
list_headfrom the stack to the LRUs, effectively corrupting the list.Remove the list cutting and use explicit list manipulation instead.
Signed-off-by Christian König <[email protected]>Can you apply this patch first and then do the clean up as a later series or temporarily disable the feature? I want to send out a -next pull this week and I don't want to leave this broken.
Yeah, that should work as well.
Christian.
Quoted 101 lines
Alex
Quoted 98 lines
--- drivers/gpu/drm/ttm/ttm_bo.c | 51 ++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +30
-22@@ -247,23 +247,18 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_move_to_lru_tail); -static void ttm_bo_bulk_move_helper (struct ttm_lru_bulk_move_pos *pos, -struct list_head *lru,bool is_swap) +static void ttm_list_move_bulk_tail (struct list_head *list, +struct list_head *first, +struct list_head *last) { -struct list_head *list; -LIST_HEAD (entries); -LIST_HEAD (before); + first->prev->next = last->next; + last->next->prev = first->prev; -reservation_object_assert_held (pos->last->resv); - list = is_swap ? &pos->last->swap : &pos->last->lru; -list_cut_position (&entries, lru, list); + list->prev->next = first; + first->prev = list->prev; -reservation_object_assert_held (pos->first->resv); - list = is_swap ? pos->first->swap.prev : pos->first->lru.prev; -list_cut_position (&before, &entries, list); - -list_splice (&before, lru); -list_splice_tail (&entries, lru); + last->next = list; + list->prev = last; }void ttm_bo_bulk_move_lru_tail (struct ttm_lru_bulk_move *bulk)@@ -271,23 +266,33 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)unsigned i;for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->tt[i];struct ttm_mem_type_manager *man; -if (!bulk->tt[i].first) +if (!pos->first)continue ; - man = &bulk->tt[i].first->bdev->man[TTM_PL_TT ]; -ttm_bo_bulk_move_helper (&bulk->tt[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_TT ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->vram[i];struct ttm_mem_type_manager *man; -if (!bulk->vram[i].first) +if (!pos->first)continue ; - man = &bulk->vram[i].first->bdev->man[TTM_PL_VRAM ]; -ttm_bo_bulk_move_helper (&bulk->vram[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_VRAM ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {@@ -297,8 +302,12 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)if (!pos->first)continue ; +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + lru = &pos->first->bdev->glob->swap_lru[i]; -ttm_bo_bulk_move_helper (&bulk->swap[i], lru, true); +ttm_list_move_bulk_tail (lru, &pos->first->swap, + &pos->last->swap); } }EXPORT_SYMBOL (ttm_bo_bulk_move_lru_tail); --2.14.1
Quoted 4 lines
Quoted 4 lines
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
[ Moving to dri-devel, where TTM patches are reviewed ]
Quoted 92 lines · Christian König
While cutting the lists we sometimes accidentally added a
list_headfrom the stack to the LRUs, effectively corrupting the list.Remove the list cutting and use explicit list manipulation instead.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 51 ++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +25
-20@@ -247,23 +247,18 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_move_to_lru_tail); -static void ttm_bo_bulk_move_helper (struct ttm_lru_bulk_move_pos *pos, -struct list_head *lru,bool is_swap) +static void ttm_list_move_bulk_tail (struct list_head *list, +struct list_head *first, +struct list_head *last) { -struct list_head *list; -LIST_HEAD (entries); -LIST_HEAD (before); + first->prev->next = last->next; + last->next->prev = first->prev; -reservation_object_assert_held (pos->last->resv); - list = is_swap ? &pos->last->swap : &pos->last->lru; -list_cut_position (&entries, lru, list); + list->prev->next = first; + first->prev = list->prev; -reservation_object_assert_held (pos->first->resv); - list = is_swap ? pos->first->swap.prev : pos->first->lru.prev; -list_cut_position (&before, &entries, list); - -list_splice (&before, lru); -list_splice_tail (&entries, lru); + last->next = list; + list->prev = last; }void ttm_bo_bulk_move_lru_tail (struct ttm_lru_bulk_move *bulk)@@ -271,23 +266,33 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)unsigned i;for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->tt[i];struct ttm_mem_type_manager *man; -if (!bulk->tt[i].first) +if (!pos->first)continue ; - man = &bulk->tt[i].first->bdev->man[TTM_PL_TT ]; -ttm_bo_bulk_move_helper (&bulk->tt[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_TT ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->vram[i];struct ttm_mem_type_manager *man; -if (!bulk->vram[i].first) +if (!pos->first)continue ; - man = &bulk->vram[i].first->bdev->man[TTM_PL_VRAM ]; -ttm_bo_bulk_move_helper (&bulk->vram[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_VRAM ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {@@ -297,8 +302,12 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)if (!pos->first)continue ;
drivers/gpu/drm/ttm/ttm_bo.c void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk) · line 313
Quoted 10 lines
drivers/gpu/drm/ttm/ttm_bo.c +5
-1+reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + lru = &pos->first->bdev->glob->swap_lru[i]; -ttm_bo_bulk_move_helper (&bulk->swap[i], lru, true); +ttm_list_move_bulk_tail (lru, &pos->first->swap, + &pos->last->swap); } }EXPORT_SYMBOL (ttm_bo_bulk_move_lru_tail);
Seems like more code could be kept in / moved into the shared helper function. That would keep the ttm_bo_bulk_move_lru_tail code leaner, and might make the helper function changes easier to review as well.
Signature · 6 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
Am 13.09.2018 um 10:35 schrieb Michel Dänzer:
Quoted 94 lines
[ Moving to dri-devel, where TTM patches are reviewed ]
Quoted 91 lines · Christian König
While cutting the lists we sometimes accidentally added a
list_headfrom the stack to the LRUs, effectively corrupting the list.Remove the list cutting and use explicit list manipulation instead.
Signed-off-by Christian König <[email protected]>--- drivers/gpu/drm/ttm/ttm_bo.c | 51 ++++++++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +25
-20@@ -247,23 +247,18 @@ void ttm_bo_move_to_lru_tail(struct ttm_buffer_object *bo, }EXPORT_SYMBOL (ttm_bo_move_to_lru_tail); -static void ttm_bo_bulk_move_helper (struct ttm_lru_bulk_move_pos *pos, -struct list_head *lru,bool is_swap) +static void ttm_list_move_bulk_tail (struct list_head *list, +struct list_head *first, +struct list_head *last) { -struct list_head *list; -LIST_HEAD (entries); -LIST_HEAD (before); + first->prev->next = last->next; + last->next->prev = first->prev; -reservation_object_assert_held (pos->last->resv); - list = is_swap ? &pos->last->swap : &pos->last->lru; -list_cut_position (&entries, lru, list); + list->prev->next = first; + first->prev = list->prev; -reservation_object_assert_held (pos->first->resv); - list = is_swap ? pos->first->swap.prev : pos->first->lru.prev; -list_cut_position (&before, &entries, list); - -list_splice (&before, lru); -list_splice_tail (&entries, lru); + last->next = list; + list->prev = last; }void ttm_bo_bulk_move_lru_tail (struct ttm_lru_bulk_move *bulk)@@ -271,23 +266,33 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)unsigned i;for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->tt[i];struct ttm_mem_type_manager *man; -if (!bulk->tt[i].first) +if (!pos->first)continue ; - man = &bulk->tt[i].first->bdev->man[TTM_PL_TT ]; -ttm_bo_bulk_move_helper (&bulk->tt[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_TT ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) { +struct ttm_lru_bulk_move_pos *pos = &bulk->vram[i];struct ttm_mem_type_manager *man; -if (!bulk->vram[i].first) +if (!pos->first)continue ; - man = &bulk->vram[i].first->bdev->man[TTM_PL_VRAM ]; -ttm_bo_bulk_move_helper (&bulk->vram[i], &man->lru[i], false); +reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_VRAM ]; +ttm_list_move_bulk_tail (&man->lru[i], &pos->first->lru, + &pos->last->lru); }for (i =0 ; i <TTM_MAX_BO_PRIORITY ; ++i) {@@ -297,8 +302,12 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)if (!pos->first)continue ;
Quoted 14 lines
drivers/gpu/drm/ttm/ttm_bo.c void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk) · line 313
Quoted 11 lines
drivers/gpu/drm/ttm/ttm_bo.c +5
-1+reservation_object_assert_held (pos->first->resv); +reservation_object_assert_held (pos->last->resv); + lru = &pos->first->bdev->glob->swap_lru[i]; -ttm_bo_bulk_move_helper (&bulk->swap[i], lru, true); +ttm_list_move_bulk_tail (lru, &pos->first->swap, + &pos->last->swap); } }EXPORT_SYMBOL (ttm_bo_bulk_move_lru_tail);Seems like more code could be kept in / moved into the shared helper function. That would keep the
ttm_bo_bulk_move_lru_tailcode leaner, and might make the helper function changes easier to review as well.
Yeah, actually only wanted to send that to Rui and you for testing.
Going to clean that up and send it for upstream review today.
Christian.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Quoted 103 lines · Christian König
Am 13.09.2018 um 10:35 schrieb Michel Dänzer:
Quoted 93 lines
[ Moving to dri-devel, where TTM patches are reviewed ]
Quoted 90 lines · Christian König
While cutting the lists we sometimes accidentally added a
list_headfrom the stack to the LRUs, effectively corrupting the list.Remove the list cutting and use explicit list manipulation instead.
Signed-off-by Christian König <[email protected]>---
drivers/gpu/drm/ttm/ttm_bo.c| 51
++++++++++++++++++++++++++------------------1 file changed, 30 insertions(+), 21 deletions(-)drivers/gpu/drm/ttm/ttm_bo.c +0
-0@@ -247,23 +247,18 @@ void ttm_bo_move_to_lru_tail(structttm_buffer_object *bo, } EXPORT_SYMBOL(ttm_bo_move_to_lru_tail);-static void ttm_bo_bulk_move_helper(struct
ttm_lru_bulk_move_pos*pos,
- structlist_head*lru, boolis_swap) +static void ttm_list_move_bulk_tail(structlist_head*list, + structlist_head*first,
+ structlist_head*last)
{
- structlist_head*list;
-LIST_HEAD(entries);
-LIST_HEAD(before);
+first->prev->next=last->next;
+last->next->prev=first->prev;
-reservation_object_assert_held(pos->last->resv); - list =is_swap?&pos->last->swap:&pos->last->lru; -list_cut_position(&entries, lru, list);
+list->prev->next= first;
+first->prev=list->prev;
-reservation_object_assert_held(pos->first->resv); - list =is_swap?pos->first->swap.prev:pos->first->lru.prev; -list_cut_position(&before, &entries, list);
-
-list_splice(&before, lru);
-list_splice_tail(&entries, lru);
+last->next= list;
+list->prev= last;
}
voidttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)drivers/gpu/drm/ttm/ttm_bo.c +19
-3@@ -271,23 +266,33 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk) unsigned i; for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) { + struct ttm_lru_bulk_move_pos *pos = &bulk->tt[i]; struct ttm_mem_type_manager *man; - if (!bulk->tt[i].first) + if (!pos->first) continue; - man = &bulk->tt[i].first->bdev->man[TTM_PL_TT]; - ttm_bo_bulk_move_helper(&bulk->tt[i], &man->lru[i], false); + reservation_object_assert_held(pos->first->resv); + reservation_object_assert_held(pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_TT]; + ttm_list_move_bulk_tail(&man->lru[i], &pos->first->lru, + &pos->last->lru); } for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) { + struct ttm_lru_bulk_move_pos *pos = &bulk->vram[i]; struct ttm_mem_type_manager *man; - if (!bulk->vram[i].first) + if (!pos->first) continue; - man = &bulk->vram[i].first->bdev->man[TTM_PL_VRAM]; - ttm_bo_bulk_move_helper(&bulk->vram[i], &man->lru[i], false); + reservation_object_assert_held(pos->first->resv); + reservation_object_assert_held(pos->last->resv); + + man = &pos->first->bdev->man[TTM_PL_VRAM]; + ttm_list_move_bulk_tail(&man->lru[i], &pos->first->lru, + &pos->last->lru); } for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {@@ -297,8 +302,12 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk) if (!pos->first) continue; + reservation_object_assert_held(pos->first->resv); + reservation_object_assert_held(pos->last->resv); + lru = &pos->first->bdev->glob->swap_lru[i]; - ttm_bo_bulk_move_helper(&bulk->swap[i], lru, true); + ttm_list_move_bulk_tail(lru, &pos->first->swap,Quoted 8 lines
Quoted 5 lines
drivers/gpu/drm/ttm/ttm_bo.c +1
-0+ &pos->last->swap); } }
EXPORT_SYMBOL(ttm_bo_bulk_move_lru_tail);Seems like more code could be kept in / moved into the shared helper function. That would keep the
ttm_bo_bulk_move_lru_tailcode leaner, and might make the helper function changes easier to review as well.
Quoted 3 lines
Yeah, actually only wanted to send that to Rui and you for testing.
Going to clean that up and send it for upstream review today.
Sounds good, but Tom needs to test it as well.
Signature · 6 lines
Earthling Michel Dänzer | http://www.amd.com Libre software enthusiast | Mesa and X developer _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel