All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michel Dänzer" <michel@daenzer.net>
To: christian.koenig@amd.com
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] drm/ttm: once more fix ttm_bo_bulk_move_lru_tail
Date: Thu, 13 Sep 2018 11:00:20 +0200	[thread overview]
Message-ID: <00457999-55d9-66c1-ae5d-3b18631d56f1@daenzer.net> (raw)
In-Reply-To: <40cbd627-5261-9695-9ebd-9dae914a5fc8@gmail.com>

On 2018-09-13 10:55 a.m., Christian König wrote:
> Am 13.09.2018 um 10:35 schrieb Michel Dänzer:
>> [ Moving to dri-devel, where TTM patches are reviewed ]
>>
>> On 2018-09-12 9:23 p.m., Christian König wrote:
>>> 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.
>>>
>>> Signed-off-by: Christian König <christian.koenig@amd.com>
>>> ---
>>>   drivers/gpu/drm/ttm/ttm_bo.c | 51
>>> ++++++++++++++++++++++++++------------------
>>>   1 file changed, 30 insertions(+), 21 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
>>> index 138c98902033..b2a33bf1ef10 100644
>>> --- a/drivers/gpu/drm/ttm/ttm_bo.c
>>> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
>>> @@ -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);
>>>
>> 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.
> 
> 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.


-- 
Earthling Michel Dänzer               |               http://www.amd.com
Libre software enthusiast             |             Mesa and X developer
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  reply	other threads:[~2018-09-13  9:00 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-12 19:23 [PATCH] drm/ttm: once more fix ttm_bo_bulk_move_lru_tail Christian König
2018-09-13  8:35 ` Michel Dänzer
2018-09-13  8:55   ` Christian König
2018-09-13  9:00     ` Michel Dänzer [this message]
     [not found] ` <20180912192355.2359-1-christian.koenig-5C7GfCeVMHo@public.gmane.org>
2018-09-12 19:42   ` Alex Deucher
2018-09-13  8:31   ` Huang Rui
2018-09-13 11:32     ` Christian König
     [not found]       ` <c2471ef9-1bc7-517e-27f6-a00236a9b40b-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2018-09-14  8:22         ` Huang Rui
2018-09-14  9:22           ` Michel Dänzer
     [not found]             ` <4bf23786-ffdb-ee6e-1446-9dbc8d8ed5d6-otUistvHUpPR7s880joybQ@public.gmane.org>
2018-09-14 10:46               ` Christian König
2018-09-17  9:40               ` Huang Rui
2018-09-13  8:35   ` Michel Dänzer
2018-09-13 14:25   ` Alex Deucher
     [not found]     ` <CADnq5_PiVfsBjGxN0wsbHL0o5rWYRuVehTeZvN396kp=GVZTNA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2018-09-13 17:29       ` Christian König

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=00457999-55d9-66c1-ae5d-3b18631d56f1@daenzer.net \
    --to=michel@daenzer.net \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.