2023-06-22 10:49:48

by Thomas Hellström

[permalink] [raw]
Subject: [PATCH 0/4] drm/ttm: Fixes around resources and bulk moves

MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

A couple of ttm fixes for issues that either were hit while developing the
xe driver or, for the resource leak patches, discovered during code
inspection.

Thomas Hellström (4):
drm/ttm: Fix ttm_lru_bulk_move_pos_tail()
drm/ttm: Don't shadow the operation context
drm/ttm: Don't leak a resource on eviction error
drm/ttm: Don't leak a resource on swapout move error

drivers/gpu/drm/ttm/ttm_bo.c | 20 ++++++++++----------
drivers/gpu/drm/ttm/ttm_resource.c | 2 ++
2 files changed, 12 insertions(+), 10 deletions(-)

--
2.40.1



2023-06-22 11:01:05

by Thomas Hellström

[permalink] [raw]
Subject: [PATCH 4/4] drm/ttm: Don't leak a resource on swapout move error

If moving the bo to system for swapout failed, we were leaking
a resource. Fix.

Fixes: bfa3357ef9ab ("drm/ttm: allocate resource object instead of embedding it v2")
Cc: Christian König <[email protected]>
Cc: "Christian König" <[email protected]>
Cc: [email protected]
Cc: <[email protected]> # v5.14+
Signed-off-by: Thomas Hellström <[email protected]>
---
drivers/gpu/drm/ttm/ttm_bo.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 89530f2a027f..d737ddd7f4c0 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1166,6 +1166,7 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx,
ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop);
if (unlikely(ret != 0)) {
WARN(ret == -EMULTIHOP, "Unexpected multihop in swaput - likely driver bug.\n");
+ ttm_resource_free(bo, &evict_mem);
goto out;
}
}
--
2.40.1


2023-06-22 11:04:52

by Thomas Hellström

[permalink] [raw]
Subject: [PATCH 3/4] drm/ttm: Don't leak a resource on eviction error

On eviction errors other than -EMULTIHOP we were leaking a resource.
Fix.

Fixes: 403797925768 ("drm/ttm: Fix multihop assert on eviction.")
Cc: Andrey Grodzovsky <[email protected]>
Cc: Christian König <[email protected]>
Cc: Christian Koenig <[email protected]>
Cc: Huang Rui <[email protected]>
Cc: [email protected]
Cc: <[email protected]> # v5.15+
Signed-off-by: Thomas Hellström <[email protected]>
---
drivers/gpu/drm/ttm/ttm_bo.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 615d30c4262d..89530f2a027f 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -462,14 +462,14 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop);
if (ret == -EMULTIHOP) {
ret = ttm_bo_bounce_temp_buffer(bo, &evict_mem, ctx, &hop);
- if (ret) {
- if (ret != -ERESTARTSYS && ret != -EINTR)
- pr_err("Buffer eviction failed\n");
- ttm_resource_free(bo, &evict_mem);
- goto out;
- }
- /* try and move to final place now. */
- goto bounce;
+ if (!ret)
+ /* try and move to final place now. */
+ goto bounce;
+ }
+ if (ret) {
+ ttm_resource_free(bo, &evict_mem);
+ if (ret != -ERESTARTSYS && ret != -EINTR)
+ pr_err("Buffer eviction failed\n");
}
out:
return ret;
--
2.40.1


2023-06-22 11:17:19

by Thomas Hellström

[permalink] [raw]
Subject: [PATCH 2/4] drm/ttm: Don't shadow the operation context

ttm_bo_swapout() shadows the ttm operation context which may cause
major confusion in driver callbacks when swapping out !TTM_PL_SYSTEM
memory. Fix this by reusing the operation context argument to
ttm_bo_swapout().

Cc: "Christian König" <[email protected]>
Cc: Roger He <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]>
Cc: <[email protected]> # v4.16+
Fixes: dc947770cf34 ("drm/ttm: enable swapout for reserved BOs during allocation")
Signed-off-by: Thomas Hellström <[email protected]>
Acked-by: Matthew Brost <[email protected]>
---
drivers/gpu/drm/ttm/ttm_bo.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index bd5dae4d1624..615d30c4262d 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1154,7 +1154,6 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx,
* Move to system cached
*/
if (bo->resource->mem_type != TTM_PL_SYSTEM) {
- struct ttm_operation_ctx ctx = { false, false };
struct ttm_resource *evict_mem;
struct ttm_place hop;

@@ -1164,7 +1163,7 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx,
if (unlikely(ret))
goto out;

- ret = ttm_bo_handle_move_mem(bo, evict_mem, true, &ctx, &hop);
+ ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop);
if (unlikely(ret != 0)) {
WARN(ret == -EMULTIHOP, "Unexpected multihop in swaput - likely driver bug.\n");
goto out;
--
2.40.1


2023-06-22 12:37:19

by Nirmoy Das

[permalink] [raw]
Subject: Re: [PATCH 4/4] drm/ttm: Don't leak a resource on swapout move error


On 6/22/2023 12:14 PM, Thomas Hellström wrote:
> If moving the bo to system for swapout failed, we were leaking
> a resource. Fix.
>
> Fixes: bfa3357ef9ab ("drm/ttm: allocate resource object instead of embedding it v2")
> Cc: Christian König <[email protected]>
> Cc: "Christian König" <[email protected]>
> Cc: [email protected]
> Cc: <[email protected]> # v5.14+
> Signed-off-by: Thomas Hellström <[email protected]>
Reviewed-by: Nirmoy Das <[email protected]>
> ---
> drivers/gpu/drm/ttm/ttm_bo.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 89530f2a027f..d737ddd7f4c0 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1166,6 +1166,7 @@ int ttm_bo_swapout(struct ttm_buffer_object *bo, struct ttm_operation_ctx *ctx,
> ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop);
> if (unlikely(ret != 0)) {
> WARN(ret == -EMULTIHOP, "Unexpected multihop in swaput - likely driver bug.\n");
> + ttm_resource_free(bo, &evict_mem);
> goto out;
> }
> }

2023-06-22 12:45:46

by Nirmoy Das

[permalink] [raw]
Subject: Re: [PATCH 3/4] drm/ttm: Don't leak a resource on eviction error


On 6/22/2023 12:14 PM, Thomas Hellström wrote:
> On eviction errors other than -EMULTIHOP we were leaking a resource.
> Fix.
>
> Fixes: 403797925768 ("drm/ttm: Fix multihop assert on eviction.")
> Cc: Andrey Grodzovsky <[email protected]>
> Cc: Christian König <[email protected]>
> Cc: Christian Koenig <[email protected]>
> Cc: Huang Rui <[email protected]>
> Cc: [email protected]
> Cc: <[email protected]> # v5.15+
> Signed-off-by: Thomas Hellström <[email protected]>

Reviewed-by: Nirmoy Das <[email protected]>

> ---
> drivers/gpu/drm/ttm/ttm_bo.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 615d30c4262d..89530f2a027f 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -462,14 +462,14 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
> ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop);
> if (ret == -EMULTIHOP) {
> ret = ttm_bo_bounce_temp_buffer(bo, &evict_mem, ctx, &hop);
> - if (ret) {
> - if (ret != -ERESTARTSYS && ret != -EINTR)
> - pr_err("Buffer eviction failed\n");
> - ttm_resource_free(bo, &evict_mem);
> - goto out;
> - }
> - /* try and move to final place now. */
> - goto bounce;
> + if (!ret)
> + /* try and move to final place now. */
> + goto bounce;
> + }
> + if (ret) {
> + ttm_resource_free(bo, &evict_mem);
> + if (ret != -ERESTARTSYS && ret != -EINTR)
> + pr_err("Buffer eviction failed\n");
> }
> out:
> return ret;

2023-06-22 14:00:50

by Andi Shyti

[permalink] [raw]
Subject: Re: [Intel-gfx] [PATCH 4/4] drm/ttm: Don't leak a resource on swapout move error

Hi Thomas,

On Thu, Jun 22, 2023 at 12:14:12PM +0200, Thomas Hellstr?m wrote:
> If moving the bo to system for swapout failed, we were leaking
> a resource. Fix.
>
> Fixes: bfa3357ef9ab ("drm/ttm: allocate resource object instead of embedding it v2")
> Cc: Christian K?nig <[email protected]>
> Cc: "Christian K?nig" <[email protected]>
> Cc: [email protected]
> Cc: <[email protected]> # v5.14+
> Signed-off-by: Thomas Hellstr?m <[email protected]>

Reviewed-by: Andi Shyti <[email protected]>

Andi

2023-06-22 14:01:46

by Andi Shyti

[permalink] [raw]
Subject: Re: [Intel-gfx] [PATCH 3/4] drm/ttm: Don't leak a resource on eviction error

Hi Thomas,

On Thu, Jun 22, 2023 at 12:14:11PM +0200, Thomas Hellstr?m wrote:
> On eviction errors other than -EMULTIHOP we were leaking a resource.
> Fix.
>
> Fixes: 403797925768 ("drm/ttm: Fix multihop assert on eviction.")
> Cc: Andrey Grodzovsky <[email protected]>
> Cc: Christian K?nig <[email protected]>
> Cc: Christian Koenig <[email protected]>
> Cc: Huang Rui <[email protected]>
> Cc: [email protected]
> Cc: <[email protected]> # v5.15+
> Signed-off-by: Thomas Hellstr?m <[email protected]>
> ---
> drivers/gpu/drm/ttm/ttm_bo.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 615d30c4262d..89530f2a027f 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -462,14 +462,14 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
> ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop);
> if (ret == -EMULTIHOP) {
> ret = ttm_bo_bounce_temp_buffer(bo, &evict_mem, ctx, &hop);
> - if (ret) {
> - if (ret != -ERESTARTSYS && ret != -EINTR)
> - pr_err("Buffer eviction failed\n");
> - ttm_resource_free(bo, &evict_mem);
> - goto out;
> - }
> - /* try and move to final place now. */
> - goto bounce;
> + if (!ret)
> + /* try and move to final place now. */
> + goto bounce;

As we are at this, can't we replace this with a while()? Goto's
used instead of a while loop are a fist in the eye...

It looks even better:

while (1) {
ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop);
if (!ret)
break;

if (ret == -EMULTIHOP)
ret = ttm_bo_bounce_temp_buffer(bo, &evict_mem,
ctx, &hop);

/* try again */
if (!ret)
continue;

ttm_resource_free(bo, &evict_mem);
if (ret != -ERESTARTSYS && ret != -EINTR)
pr_err("Buffer eviction failed\n");

break;
}

Andi

> + }
> + if (ret) {
> + ttm_resource_free(bo, &evict_mem);
> + if (ret != -ERESTARTSYS && ret != -EINTR)
> + pr_err("Buffer eviction failed\n");
> }
> out:
> return ret;
> --
> 2.40.1

2023-06-22 14:52:37

by Thomas Hellström

[permalink] [raw]
Subject: Re: [Intel-gfx] [PATCH 3/4] drm/ttm: Don't leak a resource on eviction error


On 6/22/23 15:55, Andi Shyti wrote:
> Hi Thomas,
>
> On Thu, Jun 22, 2023 at 12:14:11PM +0200, Thomas Hellström wrote:
>> On eviction errors other than -EMULTIHOP we were leaking a resource.
>> Fix.
>>
>> Fixes: 403797925768 ("drm/ttm: Fix multihop assert on eviction.")
>> Cc: Andrey Grodzovsky <[email protected]>
>> Cc: Christian König <[email protected]>
>> Cc: Christian Koenig <[email protected]>
>> Cc: Huang Rui <[email protected]>
>> Cc: [email protected]
>> Cc: <[email protected]> # v5.15+
>> Signed-off-by: Thomas Hellström <[email protected]>
>> ---
>> drivers/gpu/drm/ttm/ttm_bo.c | 16 ++++++++--------
>> 1 file changed, 8 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
>> index 615d30c4262d..89530f2a027f 100644
>> --- a/drivers/gpu/drm/ttm/ttm_bo.c
>> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
>> @@ -462,14 +462,14 @@ static int ttm_bo_evict(struct ttm_buffer_object *bo,
>> ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop);
>> if (ret == -EMULTIHOP) {
>> ret = ttm_bo_bounce_temp_buffer(bo, &evict_mem, ctx, &hop);
>> - if (ret) {
>> - if (ret != -ERESTARTSYS && ret != -EINTR)
>> - pr_err("Buffer eviction failed\n");
>> - ttm_resource_free(bo, &evict_mem);
>> - goto out;
>> - }
>> - /* try and move to final place now. */
>> - goto bounce;
>> + if (!ret)
>> + /* try and move to final place now. */
>> + goto bounce;
> As we are at this, can't we replace this with a while()? Goto's
> used instead of a while loop are a fist in the eye...

I'm completely OK with that. this patch already did away with one of
them. Let's hear Christian's opinion first, though.

Thanks,

Thomas





>
> It looks even better:
>
> while (1) {
> ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop);
> if (!ret)
> break;
>
> if (ret == -EMULTIHOP)
> ret = ttm_bo_bounce_temp_buffer(bo, &evict_mem,
> ctx, &hop);
>
> /* try again */
> if (!ret)
> continue;
>
> ttm_resource_free(bo, &evict_mem);
> if (ret != -ERESTARTSYS && ret != -EINTR)
> pr_err("Buffer eviction failed\n");
>
> break;
> }
>
> Andi
>
>> + }
>> + if (ret) {
>> + ttm_resource_free(bo, &evict_mem);
>> + if (ret != -ERESTARTSYS && ret != -EINTR)
>> + pr_err("Buffer eviction failed\n");
>> }
>> out:
>> return ret;
>> --
>> 2.40.1

2023-06-22 14:58:44

by Christian König

[permalink] [raw]
Subject: Re: [Intel-gfx] [PATCH 3/4] drm/ttm: Don't leak a resource on eviction error



Am 22.06.23 um 16:08 schrieb Thomas Hellström:
>
> On 6/22/23 15:55, Andi Shyti wrote:
>> Hi Thomas,
>>
>> On Thu, Jun 22, 2023 at 12:14:11PM +0200, Thomas Hellström wrote:
>>> On eviction errors other than -EMULTIHOP we were leaking a resource.
>>> Fix.
>>>
>>> Fixes: 403797925768 ("drm/ttm: Fix multihop assert on eviction.")
>>> Cc: Andrey Grodzovsky <[email protected]>
>>> Cc: Christian König <[email protected]>
>>> Cc: Christian Koenig <[email protected]>
>>> Cc: Huang Rui <[email protected]>
>>> Cc: [email protected]
>>> Cc: <[email protected]> # v5.15+
>>> Signed-off-by: Thomas Hellström <[email protected]>
>>> ---
>>>   drivers/gpu/drm/ttm/ttm_bo.c | 16 ++++++++--------
>>>   1 file changed, 8 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c
>>> b/drivers/gpu/drm/ttm/ttm_bo.c
>>> index 615d30c4262d..89530f2a027f 100644
>>> --- a/drivers/gpu/drm/ttm/ttm_bo.c
>>> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
>>> @@ -462,14 +462,14 @@ static int ttm_bo_evict(struct
>>> ttm_buffer_object *bo,
>>>       ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop);
>>>       if (ret == -EMULTIHOP) {
>>>           ret = ttm_bo_bounce_temp_buffer(bo, &evict_mem, ctx, &hop);
>>> -        if (ret) {
>>> -            if (ret != -ERESTARTSYS && ret != -EINTR)
>>> -                pr_err("Buffer eviction failed\n");
>>> -            ttm_resource_free(bo, &evict_mem);
>>> -            goto out;
>>> -        }
>>> -        /* try and move to final place now. */
>>> -        goto bounce;
>>> +        if (!ret)
>>> +            /* try and move to final place now. */
>>> +            goto bounce;
>> As we are at this, can't we replace this with a while()? Goto's
>> used instead of a while loop are a fist in the eye...
>
> I'm completely OK with that. this patch already did away with one of
> them. Let's hear Christian's opinion first, though.

I'm not a fan of that goto either, but could we somehow avoid the
while(1) ? E.g. something like do { } while (!ret) after handling the
multihop?

Christian.

>
> Thanks,
>
> Thomas
>
>
>
>
>
>>
>> It looks even better:
>>
>>     while (1) {
>>         ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop);
>>         if (!ret)
>>             break;
>>
>>         if (ret == -EMULTIHOP)
>>             ret = ttm_bo_bounce_temp_buffer(bo, &evict_mem,
>>                             ctx, &hop);
>>
>>         /* try again */
>>         if (!ret)
>>             continue;
>>
>>         ttm_resource_free(bo, &evict_mem);
>>         if (ret != -ERESTARTSYS && ret != -EINTR)
>>             pr_err("Buffer eviction failed\n");
>>
>>         break;
>>     }
>>
>> Andi
>>
>>> +    }
>>> +    if (ret) {
>>> +        ttm_resource_free(bo, &evict_mem);
>>> +        if (ret != -ERESTARTSYS && ret != -EINTR)
>>> +            pr_err("Buffer eviction failed\n");
>>>       }
>>>   out:
>>>       return ret;
>>> --
>>> 2.40.1


2023-06-22 17:20:48

by Thomas Hellström

[permalink] [raw]
Subject: Re: [Intel-gfx] [PATCH 3/4] drm/ttm: Don't leak a resource on eviction error


On 6/22/23 16:48, Christian König wrote:
>
>
> Am 22.06.23 um 16:08 schrieb Thomas Hellström:
>>
>> On 6/22/23 15:55, Andi Shyti wrote:
>>> Hi Thomas,
>>>
>>> On Thu, Jun 22, 2023 at 12:14:11PM +0200, Thomas Hellström wrote:
>>>> On eviction errors other than -EMULTIHOP we were leaking a resource.
>>>> Fix.
>>>>
>>>> Fixes: 403797925768 ("drm/ttm: Fix multihop assert on eviction.")
>>>> Cc: Andrey Grodzovsky <[email protected]>
>>>> Cc: Christian König <[email protected]>
>>>> Cc: Christian Koenig <[email protected]>
>>>> Cc: Huang Rui <[email protected]>
>>>> Cc: [email protected]
>>>> Cc: <[email protected]> # v5.15+
>>>> Signed-off-by: Thomas Hellström <[email protected]>
>>>> ---
>>>>   drivers/gpu/drm/ttm/ttm_bo.c | 16 ++++++++--------
>>>>   1 file changed, 8 insertions(+), 8 deletions(-)
>>>>
>>>> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c
>>>> b/drivers/gpu/drm/ttm/ttm_bo.c
>>>> index 615d30c4262d..89530f2a027f 100644
>>>> --- a/drivers/gpu/drm/ttm/ttm_bo.c
>>>> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
>>>> @@ -462,14 +462,14 @@ static int ttm_bo_evict(struct
>>>> ttm_buffer_object *bo,
>>>>       ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop);
>>>>       if (ret == -EMULTIHOP) {
>>>>           ret = ttm_bo_bounce_temp_buffer(bo, &evict_mem, ctx, &hop);
>>>> -        if (ret) {
>>>> -            if (ret != -ERESTARTSYS && ret != -EINTR)
>>>> -                pr_err("Buffer eviction failed\n");
>>>> -            ttm_resource_free(bo, &evict_mem);
>>>> -            goto out;
>>>> -        }
>>>> -        /* try and move to final place now. */
>>>> -        goto bounce;
>>>> +        if (!ret)
>>>> +            /* try and move to final place now. */
>>>> +            goto bounce;
>>> As we are at this, can't we replace this with a while()? Goto's
>>> used instead of a while loop are a fist in the eye...
>>
>> I'm completely OK with that. this patch already did away with one of
>> them. Let's hear Christian's opinion first, though.
>
> I'm not a fan of that goto either, but could we somehow avoid the
> while(1) ? E.g. something like do { } while (!ret) after handling the
> multihop?

I think the construct that makes it most obvious what's happening,
although it needs two tests for -EMULTIHOP is something like

do {
....
   if (ret != -EMULTIHOP)
      break;
   ....
} while (ret ==-EMULTIHOP);

Will be out tomorrow, though, so I don't have time to respin before Monday.

/Thomas


>
> Christian.
>
>>
>> Thanks,
>>
>> Thomas
>>
>>
>>
>>
>>
>>>
>>> It looks even better:
>>>
>>>     while (1) {
>>>         ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop);
>>>         if (!ret)
>>>             break;
>>>
>>>         if (ret == -EMULTIHOP)
>>>             ret = ttm_bo_bounce_temp_buffer(bo, &evict_mem,
>>>                             ctx, &hop);
>>>
>>>         /* try again */
>>>         if (!ret)
>>>             continue;
>>>
>>>         ttm_resource_free(bo, &evict_mem);
>>>         if (ret != -ERESTARTSYS && ret != -EINTR)
>>>             pr_err("Buffer eviction failed\n");
>>>
>>>         break;
>>>     }
>>>
>>> Andi
>>>
>>>> +    }
>>>> +    if (ret) {
>>>> +        ttm_resource_free(bo, &evict_mem);
>>>> +        if (ret != -ERESTARTSYS && ret != -EINTR)
>>>> +            pr_err("Buffer eviction failed\n");
>>>>       }
>>>>   out:
>>>>       return ret;
>>>> --
>>>> 2.40.1
>

2023-06-23 08:09:42

by Andi Shyti

[permalink] [raw]
Subject: Re: [Intel-gfx] [PATCH 3/4] drm/ttm: Don't leak a resource on eviction error

Hi Christian and Thomas,

> > > > > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c
> > > > > b/drivers/gpu/drm/ttm/ttm_bo.c
> > > > > index 615d30c4262d..89530f2a027f 100644
> > > > > --- a/drivers/gpu/drm/ttm/ttm_bo.c
> > > > > +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> > > > > @@ -462,14 +462,14 @@ static int ttm_bo_evict(struct
> > > > > ttm_buffer_object *bo,
> > > > > ????? ret = ttm_bo_handle_move_mem(bo, evict_mem, true, ctx, &hop);
> > > > > ????? if (ret == -EMULTIHOP) {
> > > > > ????????? ret = ttm_bo_bounce_temp_buffer(bo, &evict_mem, ctx, &hop);
> > > > > -??????? if (ret) {
> > > > > -??????????? if (ret != -ERESTARTSYS && ret != -EINTR)
> > > > > -??????????????? pr_err("Buffer eviction failed\n");
> > > > > -??????????? ttm_resource_free(bo, &evict_mem);
> > > > > -??????????? goto out;
> > > > > -??????? }
> > > > > -??????? /* try and move to final place now. */
> > > > > -??????? goto bounce;
> > > > > +??????? if (!ret)
> > > > > +??????????? /* try and move to final place now. */
> > > > > +??????????? goto bounce;
> > > > As we are at this, can't we replace this with a while()? Goto's
> > > > used instead of a while loop are a fist in the eye...
> > >
> > > I'm completely OK with that. this patch already did away with one of
> > > them. Let's hear Christian's opinion first, though.
> >
> > I'm not a fan of that goto either, but could we somehow avoid the
> > while(1) ? E.g. something like do { } while (!ret) after handling the
> > multihop?
>
> I think the construct that makes it most obvious what's happening, although
> it needs two tests for -EMULTIHOP is something like
>
> do {
> ....
> ?? if (ret != -EMULTIHOP)
> ????? break;
> ?? ....
> } while (ret ==-EMULTIHOP);

even better :)

Thank you!
Andi