Skip to contentSkip to conversation

drm/amdgpu: add rcu_barrier after entity fini

PATCH In review Emily Deng 3 participants 8 messages May 17, 2018 – May 21, 2018 7 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Emily Deng

author
#0 lore raw

PATCH 1/1 drm/amdgpu: add rcu_barrier after entity fini

To free the fence from the amdgpu_fence_slab, need twice call_rcu, to avoid the amdgpu_fence_slab_fini call kmem_cache_destroy(amdgpu_fence_slab) before kmem_cache_free(amdgpu_fence_slab, fence), add rcu_barrier after drm_sched_entity_fini.

The kmem_cache_free(amdgpu_fence_slab, fence)'s call trace as below:
1.drm_sched_entity_fini ->
drm_sched_entity_cleanup -> dma_fence_put(entity->last_scheduled) -> drm_sched_fence_release_finished -> drm_sched_fence_release_scheduled -> call_rcu(&fence->finished.rcu, drm_sched_fence_free)

2.drm_sched_fence_free ->
dma_fence_put(fence->parent) ->
amdgpu_fence_release ->
call_rcu(&f->rcu, amdgpu_fence_free) ->
kmem_cache_free(amdgpu_fence_slab, fence);

v2:put the barrier before the kmem_cache_destroy

Change-Id I8dcadd3372f97e72461bf46b41cc26d90f09b8df
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1 -0
index 39ec6b8..42be65b 100644
@@ -69,6 +69,7 @@ int amdgpu_fence_slab_init(void)
 void amdgpu_fence_slab_fini(void)
 {
 	rcu_barrier();
+	rcu_barrier();
 	kmem_cache_destroy(amdgpu_fence_slab);
 }
 /*
Signature · 6 lines
2.7.4

_______________________________________________
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): 1526551432-12599-1-git-send-email-Emily.Deng-5C7GfCeVMHo@public.gmane.org

#2 lore raw

Am 17.05.2018 um 12:03 schrieb Emily Deng:

Quoted 31 lines

To free the fence from the amdgpu_fence_slab, need twice call_rcu, to avoid the amdgpu_fence_slab_fini call kmem_cache_destroy(amdgpu_fence_slab) before kmem_cache_free(amdgpu_fence_slab, fence), add rcu_barrier after drm_sched_entity_fini.

The kmem_cache_free(amdgpu_fence_slab, fence)'s call trace as below:
1.drm_sched_entity_fini ->
drm_sched_entity_cleanup -> dma_fence_put(entity->last_scheduled) -> drm_sched_fence_release_finished -> drm_sched_fence_release_scheduled -> call_rcu(&fence->finished.rcu, drm_sched_fence_free)

2.drm_sched_fence_free ->
dma_fence_put(fence->parent) ->
amdgpu_fence_release ->
call_rcu(&f->rcu, amdgpu_fence_free) ->
kmem_cache_free(amdgpu_fence_slab, fence);

v2:put the barrier before the kmem_cache_destroy

Change-Id I8dcadd3372f97e72461bf46b41cc26d90f09b8df
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
index 39ec6b8..42be65b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_slab_init(void) · line 72

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1 -0
@@ -69,6 +69,7 @@ int amdgpu_fence_slab_init(void)
  void amdgpu_fence_slab_fini(void)
  {
  	rcu_barrier();
+	rcu_barrier();

Well, you should have noted that there is already an rcu_barrier here and adding another one shouldn't have any additional effect. So your explanation and the proposed solution doesn't make to much sense.

I think the problem you run into is rather that the fence is reference counted and might live longer than the module who created it.

Complicated issue, one possible solution would be to release fence->parent earlier in the scheduler fence but that doesn't sound like a general purpose solution.

Christian.

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_slab_init(void) · line 75

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
  	kmem_cache_destroy(amdgpu_fence_slab);
  }
  /*

_______________________________________________
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): ec5de5ac-f9b8-53e5-0db4-3e0791469b40-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#4 lore raw

Hi Christian,
Yes, it has already one rcu_barrier, but it has called twice call_rcu, so the one rcu_barrier just could barrier one call_rcu some time.
After I added another rcu_barrier, the kernel issue will disappear.

Best Wishes,
Emily Deng

Quoted 50 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Thursday, May 17, 2018 7:08 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: add rcu_barrier after entity fini

Am 17.05.2018 um 12:03 schrieb Emily Deng:

Quoted 3 lines

To free the fence from the amdgpu_fence_slab, need twice call_rcu, to avoid the amdgpu_fence_slab_fini call kmem_cache_destroy(amdgpu_fence_slab) before

kmem_cache_free(amdgpu_fence_slab, fence), add rcu_barrier after drm_sched_entity_fini.

Quoted 6 lines

The kmem_cache_free(amdgpu_fence_slab, fence)'s call trace as below:
1.drm_sched_entity_fini ->
drm_sched_entity_cleanup -> dma_fence_put(entity->last_scheduled) -> drm_sched_fence_release_finished ->

drm_sched_fence_release_scheduled

Quoted 22 lines

-> call_rcu(&fence->finished.rcu, drm_sched_fence_free)

2.drm_sched_fence_free ->
dma_fence_put(fence->parent) ->
amdgpu_fence_release ->
call_rcu(&f->rcu, amdgpu_fence_free) ->
kmem_cache_free(amdgpu_fence_slab, fence);

v2:put the barrier before the kmem_cache_destroy

Change-Id I8dcadd3372f97e72461bf46b41cc26d90f09b8df
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
index 39ec6b8..42be65b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_slab_init(void) · line 72

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1 -0
@@ -69,6 +69,7 @@ int amdgpu_fence_slab_init(void)
  void amdgpu_fence_slab_fini(void)
  {
  	rcu_barrier();
+	rcu_barrier();

Well, you should have noted that there is already an rcu_barrier here and adding another one shouldn't have any additional effect. So your explanation and the proposed solution doesn't make to much sense.

Quoted 12 lines

I think the problem you run into is rather that the fence is reference counted and might live longer than the module who created it.

Complicated issue, one possible solution would be to release fence->parent earlier in the scheduler fence but that doesn't sound like a general purpose solution.

Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
  	kmem_cache_destroy(amdgpu_fence_slab);
  }
  /*

_______________________________________________
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): CY4PR12MB112526B02190A3D892CCB84F8F900-rpdhrqHFk07v2MZdTKcfDgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#6 lore raw

Ping......

Best Wishes,
Emily Deng

Quoted 76 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Deng, Emily
Sent: Friday, May 18, 2018 11:20 AM
To: Koenig, Christian <[email protected]>; amd- [email protected]
Subject: RE: [PATCH] drm/amdgpu: add rcu_barrier after entity fini

Hi Christian,
Yes, it has already one rcu_barrier, but it has called twice call_rcu, so the
one rcu_barrier just could barrier one call_rcu some time.
After I added another rcu_barrier, the kernel issue will disappear.

Best Wishes,
Emily Deng

Quoted 60 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Thursday, May 17, 2018 7:08 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: add rcu_barrier after entity fini

Am 17.05.2018 um 12:03 schrieb Emily Deng:

Quoted 3 lines

To free the fence from the amdgpu_fence_slab, need twice call_rcu, to avoid the amdgpu_fence_slab_fini call kmem_cache_destroy(amdgpu_fence_slab) before

kmem_cache_free(amdgpu_fence_slab, fence), add rcu_barrier after drm_sched_entity_fini.

Quoted 6 lines

The kmem_cache_free(amdgpu_fence_slab, fence)'s call trace as below:
1.drm_sched_entity_fini ->
drm_sched_entity_cleanup -> dma_fence_put(entity->last_scheduled) -> drm_sched_fence_release_finished ->

drm_sched_fence_release_scheduled

Quoted 22 lines

-> call_rcu(&fence->finished.rcu, drm_sched_fence_free)

2.drm_sched_fence_free ->
dma_fence_put(fence->parent) ->
amdgpu_fence_release ->
call_rcu(&f->rcu, amdgpu_fence_free) ->
kmem_cache_free(amdgpu_fence_slab, fence);

v2:put the barrier before the kmem_cache_destroy

Change-Id I8dcadd3372f97e72461bf46b41cc26d90f09b8df
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 1 +
  1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
index 39ec6b8..42be65b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_slab_init(void) · line 72

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1 -0
@@ -69,6 +69,7 @@ int amdgpu_fence_slab_init(void)
  void amdgpu_fence_slab_fini(void)
  {
  	rcu_barrier();
+	rcu_barrier();

Well, you should have noted that there is already an rcu_barrier here and adding another one shouldn't have any additional effect. So your explanation and the proposed solution doesn't make to much sense.

I think the problem you run into is rather that the fence is reference counted and might live longer than the module who created it.

Complicated issue, one possible solution would be to release fence->parent earlier in the scheduler fence but that doesn't sound fence->like
a general purpose solution.

Christian.

Quoted 8 lines
Quoted 3 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_slab_init(void) · line 75

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
  	kmem_cache_destroy(amdgpu_fence_slab);
  }
  /*

_______________________________________________
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): BN6PR12MB11210121E65A155D901B94AE8F900-/b2+HYfkarSgw6z4+5+8kgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#8 lore raw

Ok, I'm lost where do we use call_rcu() twice? Cause that sounds incorrect in the first place.

Christian.

Am 18.05.2018 um 11:41 schrieb Deng, Emily:

Quoted 89 lines

Ping......

Best Wishes,
Emily Deng

Quoted 81 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On Behalf Of Deng, Emily
Sent: Friday, May 18, 2018 11:20 AM
To: Koenig, Christian <[email protected]>; amd- [email protected]
Subject: RE: [PATCH] drm/amdgpu: add rcu_barrier after entity fini

Hi Christian,
Yes, it has already one rcu_barrier, but it has called twice call_rcu, so the
one rcu_barrier just could barrier one call_rcu some time.
After I added another rcu_barrier, the kernel issue will disappear.

Best Wishes,
Emily Deng

Quoted 51 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Thursday, May 17, 2018 7:08 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: add rcu_barrier after entity fini

Am 17.05.2018 um 12:03 schrieb Emily Deng:

Quoted 3 lines

To free the fence from the amdgpu_fence_slab, need twice call_rcu, to avoid the amdgpu_fence_slab_fini call kmem_cache_destroy(amdgpu_fence_slab) before

kmem_cache_free(amdgpu_fence_slab, fence), add rcu_barrier after drm_sched_entity_fini.

Quoted 5 lines

The kmem_cache_free(amdgpu_fence_slab, fence)'s call trace as below:
1.drm_sched_entity_fini ->
drm_sched_entity_cleanup -> dma_fence_put(entity->last_scheduled) -> drm_sched_fence_release_finished ->

drm_sched_fence_release_scheduled

Quoted 22 lines

-> call_rcu(&fence->finished.rcu, drm_sched_fence_free)

2.drm_sched_fence_free ->
dma_fence_put(fence->parent) ->
amdgpu_fence_release ->
call_rcu(&f->rcu, amdgpu_fence_free) ->
kmem_cache_free(amdgpu_fence_slab, fence);

v2:put the barrier before the kmem_cache_destroy

Change-Id I8dcadd3372f97e72461bf46b41cc26d90f09b8df
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 1 +
   1 file changed, 1 insertion(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
index 39ec6b8..42be65b 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_slab_init(void) · line 72

Quoted 4 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1 -0
@@ -69,6 +69,7 @@ int amdgpu_fence_slab_init(void)
   void amdgpu_fence_slab_fini(void)
   {
   	rcu_barrier();
+	rcu_barrier();

Well, you should have noted that there is already an rcu_barrier here and adding another one shouldn't have any additional effect. So your explanation and the proposed solution doesn't make to much sense.

I think the problem you run into is rather that the fence is reference counted and might live longer than the module who created it.

Quoted 10 lines

Complicated issue, one possible solution would be to release fence->parent earlier in the scheduler fence but that doesn't sound fence->like
a general purpose solution.

Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
   	kmem_cache_destroy(amdgpu_fence_slab);
   }
   /*

_______________________________________________
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): 3f9070bd-ebce-77d4-5979-6ce383885064-5C7GfCeVMHo@public.gmane.org

#10 lore raw

Hi Christian,
When we free an IB fence, we first call one call_rcu in drm_sched_fence_release_scheduled as the call trace one, then after the call trace one,
we call the call_rcu second in the amdgpu_fence_release in call trace two, as below.

The kmem_cache_free(amdgpu_fence_slab, fence)'s call trace as below:

    1.drm_sched_entity_fini ->
    drm_sched_entity_cleanup ->
    dma_fence_put(entity->last_scheduled) ->
    drm_sched_fence_release_finished ->
    drm_sched_fence_release_scheduled ->
    call_rcu(&fence->finished.rcu, drm_sched_fence_free)

    2.drm_sched_fence_free ->
    dma_fence_put(fence->parent) ->
    amdgpu_fence_release ->
    call_rcu(&f->rcu, amdgpu_fence_free) ->
    kmem_cache_free(amdgpu_fence_slab, fence);
Quoted 85 lines

-----Original Message-----
From: Koenig, Christian
Sent: Friday, May 18, 2018 5:46 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: add rcu_barrier after entity fini

Ok, I'm lost where do we use call_rcu() twice? Cause that sounds incorrect in the first place.

Christian.

Am 18.05.2018 um 11:41 schrieb Deng, Emily:

Quoted 28 lines

Ping......

Best Wishes,
Emily Deng

Quoted 20 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On
Behalf Of Deng, Emily
Sent: Friday, May 18, 2018 11:20 AM
To: Koenig, Christian <[email protected]<mailto:[email protected]>>; amd- [email protected]<mailto:[email protected]>
Subject: RE: [PATCH] drm/amdgpu: add rcu_barrier after entity fini

Hi Christian,
Yes, it has already one rcu_barrier, but it has called twice
call_rcu, so the one rcu_barrier just could barrier one call_rcu some time.
After I added another rcu_barrier, the kernel issue will disappear.

Best Wishes,
Emily Deng

Quoted 4 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Thursday, May 17, 2018 7:08 PM
To: Deng, Emily <[email protected]<mailto:[email protected]>>; amd-<mailto:[email protected]>

[email protected]

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Subject: Re: [PATCH] drm/amdgpu: add rcu_barrier after entity fini

Am 17.05.2018 um 12:03 schrieb Emily Deng:

Quoted 3 lines

To free the fence from the amdgpu_fence_slab, need twice call_rcu, to avoid the amdgpu_fence_slab_fini call kmem_cache_destroy(amdgpu_fence_slab) before

kmem_cache_free(amdgpu_fence_slab, fence), add rcu_barrier after drm_sched_entity_fini.

Quoted 1 line

The kmem_cache_free(amdgpu_fence_slab, fence)'s call trace as

below:

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 4 lines

1.drm_sched_entity_fini ->
drm_sched_entity_cleanup ->
dma_fence_put(entity->last_scheduled) ->
drm_sched_fence_release_finished ->

drm_sched_fence_release_scheduled

Quoted 16 lines

-> call_rcu(&fence->finished.rcu, drm_sched_fence_free)

2.drm_sched_fence_free ->
dma_fence_put(fence->parent) ->
amdgpu_fence_release ->
call_rcu(&f->rcu, amdgpu_fence_free) ->
kmem_cache_free(amdgpu_fence_slab, fence);

v2:put the barrier before the kmem_cache_destroy

Change-Id I8dcadd3372f97e72461bf46b41cc26d90f09b8df
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 1 +
   1 file changed, 1 insertion(+)
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
index 39ec6b8..42be65b 100644
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_slab_init(void) · line 72

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1 -0
@@ -69,6 +69,7 @@ int amdgpu_fence_slab_init(void)
   void amdgpu_fence_slab_fini(void)
   {
         rcu_barrier();
+        rcu_barrier();

Well, you should have noted that there is already an rcu_barrier here and adding another one shouldn't have any additional effect. So your explanation and the proposed solution doesn't make to much

Quoted 19 lines

sense.

Quoted 18 lines
Quoted 18 lines
Quoted 4 lines

I think the problem you run into is rather that the fence is reference counted and might live longer than the module who created it.

Quoted 10 lines

Complicated issue, one possible solution would be to release fence->parent earlier in the scheduler fence but that doesn't sound fence->like
a general purpose solution.

Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
         kmem_cache_destroy(amdgpu_fence_slab);
   }
   /*

_______________________________________________
amd-gfx mailing list [email protected]<mailto:[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): BN6PR12MB1121DDBFDB283E01AC198B038F900-/b2+HYfkarSgw6z4+5+8kgdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org

#12 lore raw

Ah! So we have one RCU grace period caused by the scheduler fence and another one from the hardware fence.

Thanks for explaining that once more, that was really not obvious from reading the code.

But this means we could we also fix it by moving the "dma_fence_put(fence->parent);" from drm_sched_fence_free() into drm_sched_fence_release_scheduled() directly before the call_rcu(), can't we?

I think that would be cleaner, cause otherwise every driver using the GPU scheduler would need that workaround.

And drm_sched_fence_release_scheduled() is only called when the reference count becomes zero, so when anybody accesses the structure after that then that would be a bug as well.

Thanks,
Christian.

Am 18.05.2018 um 11:56 schrieb Deng, Emily:

Quoted 48 lines

Hi Christian,
        When we free an IB fence, we first call one call_rcu in drm_sched_fence_release_scheduled as the call trace one, then after the call trace one, we call the call_rcu second in the  amdgpu_fence_release in call trace two, as below.
The kmem_cache_free(amdgpu_fence_slab, fence)'s call trace as below:
    1.drm_sched_entity_fini ->
    drm_sched_entity_cleanup ->
    dma_fence_put(entity->last_scheduled) ->
    drm_sched_fence_release_finished ->
    drm_sched_fence_release_scheduled ->
    call_rcu(&fence->finished.rcu, drm_sched_fence_free)
    2.drm_sched_fence_free ->
    dma_fence_put(fence->parent) ->
    amdgpu_fence_release ->
    call_rcu(&f->rcu, amdgpu_fence_free) ->
    kmem_cache_free(amdgpu_fence_slab, fence);

Quoted 33 lines

-----Original Message-----
From: Koenig, Christian
Sent: Friday, May 18, 2018 5:46 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: add rcu_barrier after entity fini

Ok, I'm lost where do we use call_rcu() twice? Cause that sounds incorrect in the first place.

Christian.

Am 18.05.2018 um 11:41 schrieb Deng, Emily:

Quoted 21 lines

Ping......

Best Wishes,
Emily Deng

Quoted 13 lines

-----Original Message-----
From: amd-gfx [mailto:amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org] On
Behalf Of Deng, Emily
Sent: Friday, May 18, 2018 11:20 AM
To: Koenig, Christian <[email protected] <mailto:[email protected]>>; amd- [email protected] <mailto:[email protected]>
Subject: RE: [PATCH] drm/amdgpu: add rcu_barrier after entity fini

Hi Christian,
       Yes, it has already one rcu_barrier, but it has called twice call_rcu, so the one rcu_barrier just could barrier one call_rcu some time. After I added another rcu_barrier, the kernel issue will disappear.

Quoted 72 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

Best Wishes,
Emily Deng

Quoted 4 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Thursday, May 17, 2018 7:08 PM
To: Deng, Emily <[email protected] <mailto:[email protected]>>; amd-

<mailto:[email protected]>

Quoted 64 lines

[email protected]

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Subject: Re: [PATCH] drm/amdgpu: add rcu_barrier after entity fini

Am 17.05.2018 um 12:03 schrieb Emily Deng:

Quoted 3 lines

To free the fence from the amdgpu_fence_slab, need twice call_rcu, to avoid the amdgpu_fence_slab_fini call kmem_cache_destroy(amdgpu_fence_slab) before

kmem_cache_free(amdgpu_fence_slab, fence), add rcu_barrier after drm_sched_entity_fini.

Quoted 1 line

The kmem_cache_free(amdgpu_fence_slab, fence)'s call trace as

below:

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 4 lines

1.drm_sched_entity_fini ->
drm_sched_entity_cleanup ->
dma_fence_put(entity->last_scheduled) ->
drm_sched_fence_release_finished ->

drm_sched_fence_release_scheduled

Quoted 16 lines

-> call_rcu(&fence->finished.rcu, drm_sched_fence_free)

2.drm_sched_fence_free ->
dma_fence_put(fence->parent) ->
amdgpu_fence_release ->
call_rcu(&f->rcu, amdgpu_fence_free) ->
kmem_cache_free(amdgpu_fence_slab, fence);

v2:put the barrier before the kmem_cache_destroy

Change-Id I8dcadd3372f97e72461bf46b41cc26d90f09b8df
Signed-off-by Emily Deng <[email protected] <mailto:[email protected]>>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 1 +
    1 file changed, 1 insertion(+)
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
index 39ec6b8..42be65b 100644
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_slab_init(void) · line 72

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1 -0
@@ -69,6 +69,7 @@ int amdgpu_fence_slab_init(void)
     void amdgpu_fence_slab_fini(void)
     {
            rcu_barrier();
+        rcu_barrier();

Well, you should have noted that there is already an rcu_barrier here and adding another one shouldn't have any additional effect. So your explanation and the proposed solution doesn't make to much

sense.

Quoted 18 lines
Quoted 18 lines
Quoted 4 lines

I think the problem you run into is rather that the fence is reference counted and might live longer than the module who created it.

Quoted 10 lines

Complicated issue, one possible solution would be to release fence->parent earlier in the scheduler fence but that doesn't sound fence->like
a general purpose solution.

Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
         kmem_cache_destroy(amdgpu_fence_slab);
     }
     /*

_______________________________________________
amd-gfx mailing list
[email protected] <mailto:[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): bc3fbefd-957a-9b89-8096-22b44f6dc3d2-5C7GfCeVMHo@public.gmane.org

#14 lore raw

Hi Christian,
Thanks for your advice, will send a modify patch later.

Best Wishes,
Emily Deng
From: Koenig, Christian
Sent: Friday, May 18, 2018 6:36 PM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: add rcu_barrier after entity fini

Ah! So we have one RCU grace period caused by the scheduler fence and another one from the hardware fence.

Thanks for explaining that once more, that was really not obvious from reading the code.

But this means we could we also fix it by moving the "dma_fence_put(fence->parent);" from drm_sched_fence_free() into drm_sched_fence_release_scheduled() directly before the call_rcu(), can't we?

I think that would be cleaner, cause otherwise every driver using the GPU scheduler would need that workaround.

And drm_sched_fence_release_scheduled() is only called when the reference count becomes zero, so when anybody accesses the structure after that then that would be a bug as well.

Thanks,
Christian.

Am 18.05.2018 um 11:56 schrieb Deng, Emily:
Hi Christian,
When we free an IB fence, we first call one call_rcu in drm_sched_fence_release_scheduled as the call trace one, then after the call trace one,
we call the call_rcu second in the amdgpu_fence_release in call trace two, as below.

The kmem_cache_free(amdgpu_fence_slab, fence)'s call trace as below:

    1.drm_sched_entity_fini ->
    drm_sched_entity_cleanup ->
    dma_fence_put(entity->last_scheduled) ->
    drm_sched_fence_release_finished ->
    drm_sched_fence_release_scheduled ->
    call_rcu(&fence->finished.rcu, drm_sched_fence_free)

    2.drm_sched_fence_free ->
    dma_fence_put(fence->parent) ->
    amdgpu_fence_release ->
    call_rcu(&f->rcu, amdgpu_fence_free) ->
    kmem_cache_free(amdgpu_fence_slab, fence);
Quoted 85 lines

-----Original Message-----
From: Koenig, Christian
Sent: Friday, May 18, 2018 5:46 PM
To: Deng, Emily <[email protected]><mailto:[email protected]>; [email protected]<mailto:[email protected]>
Subject: Re: [PATCH] drm/amdgpu: add rcu_barrier after entity fini

Ok, I'm lost where do we use call_rcu() twice? Cause that sounds incorrect in the first place.

Christian.

Am 18.05.2018 um 11:41 schrieb Deng, Emily:

Quoted 28 lines

Ping......

Best Wishes,
Emily Deng

Quoted 20 lines

-----Original Message-----
From: amd-gfx [mailto:[email protected]] On
Behalf Of Deng, Emily
Sent: Friday, May 18, 2018 11:20 AM
To: Koenig, Christian <[email protected]<mailto:[email protected]>>; amd- [email protected]<mailto:[email protected]>
Subject: RE: [PATCH] drm/amdgpu: add rcu_barrier after entity fini

Hi Christian,
Yes, it has already one rcu_barrier, but it has called twice
call_rcu, so the one rcu_barrier just could barrier one call_rcu some time.
After I added another rcu_barrier, the kernel issue will disappear.

Best Wishes,
Emily Deng

Quoted 4 lines

-----Original Message-----
From: Christian König [mailto:[email protected]]
Sent: Thursday, May 17, 2018 7:08 PM
To: Deng, Emily <[email protected]<mailto:[email protected]>>; amd-<mailto:[email protected]>

[email protected]<mailto:[email protected]>

Quoted 9 lines
Quoted 9 lines
Quoted 9 lines

Subject: Re: [PATCH] drm/amdgpu: add rcu_barrier after entity fini

Am 17.05.2018 um 12:03 schrieb Emily Deng:

Quoted 3 lines

To free the fence from the amdgpu_fence_slab, need twice call_rcu, to avoid the amdgpu_fence_slab_fini call kmem_cache_destroy(amdgpu_fence_slab) before

kmem_cache_free(amdgpu_fence_slab, fence), add rcu_barrier after drm_sched_entity_fini.

Quoted 1 line

The kmem_cache_free(amdgpu_fence_slab, fence)'s call trace as

below:

Quoted 21 lines
Quoted 21 lines
Quoted 21 lines
Quoted 4 lines

1.drm_sched_entity_fini ->
drm_sched_entity_cleanup ->
dma_fence_put(entity->last_scheduled) ->
drm_sched_fence_release_finished ->

drm_sched_fence_release_scheduled

Quoted 16 lines

-> call_rcu(&fence->finished.rcu, drm_sched_fence_free)

2.drm_sched_fence_free ->
dma_fence_put(fence->parent) ->
amdgpu_fence_release ->
call_rcu(&f->rcu, amdgpu_fence_free) ->
kmem_cache_free(amdgpu_fence_slab, fence);

v2:put the barrier before the kmem_cache_destroy

Change-Id I8dcadd3372f97e72461bf46b41cc26d90f09b8df
---
   drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c | 1 +
   1 file changed, 1 insertion(+)
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
index 39ec6b8..42be65b 100644
Quoted 8 lines
Quoted 8 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c int amdgpu_fence_slab_init(void) · line 72

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +1 -0
@@ -69,6 +69,7 @@ int amdgpu_fence_slab_init(void)
   void amdgpu_fence_slab_fini(void)
   {
          rcu_barrier();
+        rcu_barrier();

Well, you should have noted that there is already an rcu_barrier here and adding another one shouldn't have any additional effect. So your explanation and the proposed solution doesn't make to much

Quoted 19 lines

sense.

Quoted 18 lines
Quoted 18 lines
Quoted 4 lines

I think the problem you run into is rather that the fence is reference counted and might live longer than the module who created it.

Quoted 10 lines

Complicated issue, one possible solution would be to release fence->parent earlier in the scheduler fence but that doesn't sound fence->like
a general purpose solution.

Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_fence.c +0 -0
          kmem_cache_destroy(amdgpu_fence_slab);
   }
   /*

_______________________________________________
amd-gfx mailing list [email protected]<mailto:[email protected]>
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx