Skip to contentSkip to conversation

drm/amdgpu: clean up the amdgpu_cs_parser_bos

PATCH In review Sunil Khatri 4 participants 5 messages Feb 3 – Feb 4

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: clean up the amdgpu_cs_parser_bos

In low memory conditions when kmalloc can fail and hence we need to clean up the memory and unlock the mutex for clean exit.

Fixes 737da5363cc0 ("drm/amdgpu: update the functions to use amdgpu version of hmm")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +4 -1
index d591dce0f3b3..831063971f71 100644
@@ -892,8 +892,11 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 		struct amdgpu_bo *bo = e->bo;
 
 		e->range = amdgpu_hmm_range_alloc(NULL);
-		if (unlikely(!e->range))
+		if (unlikely(!e->range)) {
+			mutex_unlock(&p->bo_list->bo_list_mutex);
+			amdgpu_bo_list_put(p->bo_list)
 			return -ENOMEM;
+		}
 
 		r = amdgpu_ttm_tt_get_user_pages(bo, e->range);
 		if (r)
Signature · 1 line
2.34.1
#1 lore raw
Quoted 19 lines · Sunil Khatri

In low memory conditions when kmalloc can fail and hence we need to clean up the memory and unlock the mutex for clean exit.

Fixes 737da5363cc0 ("drm/amdgpu: update the functions to use amdgpu version of hmm")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
index d591dce0f3b3..831063971f71 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, · line 898

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -1
@@ -892,8 +892,11 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
                struct amdgpu_bo *bo = e->bo;
 
                e->range = amdgpu_hmm_range_alloc(NULL);
-               if (unlikely(!e->range))
+               if (unlikely(!e->range)) {
+                       mutex_unlock(&p->bo_list->bo_list_mutex);
+                       amdgpu_bo_list_put(p->bo_list)
                        return -ENOMEM;

I think this should probably be:
r = -ENOMEM;
goto out_free_user_pages;

Also, does that error path need amdgpu_bo_list_put()?

Alex

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
+               }
 
                r = amdgpu_ttm_tt_get_user_pages(bo, e->range);
                if (r)
--

2.34.1

#2 lore raw
Quoted 21 lines · Alex Deucher
Quoted 20 lines · Sunil Khatri

In low memory conditions when kmalloc can fail and hence we need to clean up the memory and unlock the mutex for clean exit.

Fixes 737da5363cc0 ("drm/amdgpu: update the functions to use amdgpu version of hmm")
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
index d591dce0f3b3..831063971f71 100644
@@ -892,8 +892,11 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
                 struct amdgpu_bo *bo = e->bo;
 
Quoted 9 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, · line 898

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -1
                 e->range = amdgpu_hmm_range_alloc(NULL);
-               if (unlikely(!e->range))
+               if (unlikely(!e->range)) {
+                       mutex_unlock(&p->bo_list->bo_list_mutex);
+                       amdgpu_bo_list_put(p->bo_list)
                         return -ENOMEM;

I think this should probably be:
r = -ENOMEM;
goto out_free_user_pages;

Agree, that's cleaner.

Quoted 2 lines

Also, does that error path need amdgpu_bo_list_put()?

Yes we do need that i guess.

we are doing amdgpu_bo_list_get or amdgpu_bo_list_create which needs to be cleaned if we failed here. Let me push a new patch based on those changes.

Regards
Sunil Khatri

Quoted 10 lines

Alex

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -1
+               }
 
                 r = amdgpu_ttm_tt_get_user_pages(bo, e->range);
                 if (r)
--

2.34.1

maintainer
#3 lore raw
In reply to Sunil Khatri
Quoted 18 lines · Sunil Khatri

In low memory conditions when kmalloc can fail and hence we need to clean up the memory and unlock the mutex for clean exit.

Fixes 737da5363cc0 ("drm/amdgpu: update the functions to use amdgpu version of hmm")
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
index d591dce0f3b3..831063971f71 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, · line 898

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -1
@@ -892,8 +892,11 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
 		struct amdgpu_bo *bo = e->bo;
 
 		e->range = amdgpu_hmm_range_alloc(NULL);
-		if (unlikely(!e->range))
+		if (unlikely(!e->range)) {
+			mutex_unlock(&p->bo_list->bo_list_mutex);
 
+			amdgpu_bo_list_put(p->bo_list)

The call to amdgpu_bo_list_put() is always done by amdgpu_cs_parser_fini(), so that here would drop the reference twice.

Apart from that looks correct to me.

Regards,
Christian.

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -0
 			return -ENOMEM;
+		}
 
 		r = amdgpu_ttm_tt_get_user_pages(bo, e->range);

if (r)

#4 lore raw
Quoted 21 lines · Christian König
Quoted 20 lines · Sunil Khatri

In low memory conditions when kmalloc can fail and hence we need to clean up the memory and unlock the mutex for clean exit.

Fixes 737da5363cc0 ("drm/amdgpu: update the functions to use amdgpu version of hmm")
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +0 -0
index d591dce0f3b3..831063971f71 100644
@@ -892,8 +892,11 @@ static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p,
  		struct amdgpu_bo *bo = e->bo;
 
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c static int amdgpu_cs_parser_bos(struct amdgpu_cs_parser *p, · line 897

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +3 -1
  		e->range = amdgpu_hmm_range_alloc(NULL);
-		if (unlikely(!e->range))
+		if (unlikely(!e->range)) {
+			mutex_unlock(&p->bo_list->bo_list_mutex);
+			amdgpu_bo_list_put(p->bo_list)

The call to amdgpu_bo_list_put() is always done by amdgpu_cs_parser_fini(), so that here would drop the reference twice.

Ah yes, i dint realise it is freed in the parent function. Pushed V5 with final change as expected. Thanks
Sunil

Quoted 11 lines

Apart from that looks correct to me.

Regards,
Christian.

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c +1 -0
  			return -ENOMEM;
+		}
 
  		r = amdgpu_ttm_tt_get_user_pages(bo, e->range);
  		if (r)