Skip to contentSkip to conversation

drm/ttm: Put BO in its memory manager's lru list

PATCH In review xinhui pan 4 participants 14 messages Nov 9, 2021 – Jan 12, 2022

Subsystems (4)
lore
Share & tools
lore

xinhui pan

author
#0 lore raw

PATCH 1/1 drm/ttm: Put BO in its memory manager's lru list

After we move BO to a new memory region, we should put it to the new memory manager's lru list regardless we unlock the resv or not.

---
 drivers/gpu/drm/ttm/ttm_bo.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +2 -0
index f1367107925b..e307004f0b28 100644
@@ -701,6 +701,8 @@ int ttm_mem_evict_first(struct ttm_device *bdev,
 	ret = ttm_bo_evict(bo, ctx);
 	if (locked)
 		ttm_bo_unreserve(bo);
+	else
+		ttm_bo_move_to_lru_tail_unlocked(bo);
 
 	ttm_bo_put(bo);
 	return ret;
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Am 09.11.21 um 12:19 schrieb xinhui pan:

Quoted 4 lines

After we move BO to a new memory region, we should put it to the new memory manager's lru list regardless we unlock the resv or not.

Interesting find, did you trigger that somehow or did you just stumbled over it by reading the code?

Patch is Reviewed-by: Christian König <[email protected]>, I will pick that up for drm-misc-next.

Thanks,
Christian.

Quoted 17 lines
---
  drivers/gpu/drm/ttm/ttm_bo.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +2 -0
index f1367107925b..e307004f0b28 100644
@@ -701,6 +701,8 @@ int ttm_mem_evict_first(struct ttm_device *bdev,
  	ret = ttm_bo_evict(bo, ctx);
  	if (locked)
  		ttm_bo_unreserve(bo);
+	else
+		ttm_bo_move_to_lru_tail_unlocked(bo);
 
  	ttm_bo_put(bo);
  	return ret;
#2 lore raw

[AMD Official Use Only]

I hit vulkan cts test hang with navi23.

dmesg says gmc page fault with address 0x0, 0x1000, 0x2000....
And some debug log also says amdgu copy one BO from system Domain to system Domain which is really weird.
________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:20
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Am 09.11.21 um 12:19 schrieb xinhui pan:

Quoted 4 lines

After we move BO to a new memory region, we should put it to the new memory manager's lru list regardless we unlock the resv or not.

Interesting find, did you trigger that somehow or did you just stumbled over it by reading the code?

Patch is Reviewed-by: Christian König <[email protected]>, I will pick that up for drm-misc-next.

Thanks,
Christian.

Quoted 17 lines
---
  drivers/gpu/drm/ttm/ttm_bo.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +2 -0
index f1367107925b..e307004f0b28 100644
@@ -701,6 +701,8 @@ int ttm_mem_evict_first(struct ttm_device *bdev,
      ret = ttm_bo_evict(bo, ctx);
      if (locked)
              ttm_bo_unreserve(bo);
+     else
+             ttm_bo_move_to_lru_tail_unlocked(bo);
 
      ttm_bo_put(bo);
      return ret;
maintainer
#3 lore raw

Mhm, I'm not sure what the rational behind that is.

Not moving the BO would make things less efficient, but should never cause a crash.

Maybe we should add a CC: stable tag and push it to -fixes instead?

Christian.

Am 09.11.21 um 13:28 schrieb Pan, Xinhui:

Quoted 44 lines

[AMD Official Use Only]

I hit vulkan cts test hang with navi23.

dmesg says gmc page fault with address 0x0, 0x1000, 0x2000....
And some debug log also says amdgu copy one BO from system Domain to system Domain which is really weird.
________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:20
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Am 09.11.21 um 12:19 schrieb xinhui pan:

Quoted 4 lines

After we move BO to a new memory region, we should put it to the new memory manager's lru list regardless we unlock the resv or not.

Interesting find, did you trigger that somehow or did you just stumbled over it by reading the code?

Patch is Reviewed-by: Christian König <[email protected]>, I will pick that up for drm-misc-next.

Thanks,
Christian.

Quoted 17 lines
---
   drivers/gpu/drm/ttm/ttm_bo.c | 2 ++
   1 file changed, 2 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +2 -0
index f1367107925b..e307004f0b28 100644
@@ -701,6 +701,8 @@ int ttm_mem_evict_first(struct ttm_device *bdev,
       ret = ttm_bo_evict(bo, ctx);
       if (locked)
               ttm_bo_unreserve(bo);
+     else
+             ttm_bo_move_to_lru_tail_unlocked(bo);
 
       ttm_bo_put(bo);
       return ret;
#4 lore raw

[AMD Official Use Only]

Yes, a stable tag is needed. vulkan guys say 5.14 hit this issue too.

I think that amdgpu_bo_move() does support copy from sysMem to sysMem correctly. maybe something below is needed.

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
index c83ef42ca702..aa63ae7ddf1e 100644
@@ -485,7 +485,8 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
        }
        if (old_mem->mem_type == TTM_PL_SYSTEM &&
            (new_mem->mem_type == TTM_PL_TT ||
-            new_mem->mem_type == AMDGPU_PL_PREEMPT)) {
+            new_mem->mem_type == AMDGPU_PL_PREEMPT ||
+            new_mem->mem_type == TTM_PL_SYSTEM)) {
                ttm_bo_move_null(bo, new_mem);
                goto out;
        }

otherwise, amdgpu_move_blit() is called to do the system memory copy which use a wrong address.
206 /* Map only what can't be accessed directly */
207 if (!tmz && mem->start != AMDGPU_BO_INVALID_OFFSET) {
208 *addr = amdgpu_ttm_domain_start(adev, mem->mem_type) +
209 mm_cur->start;
210 return 0;
211 }

line 208, *addr is zero. So when amdgpu_copy_buffer submit job with such addr, page fault happens.

________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:35
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Mhm, I'm not sure what the rational behind that is.

Not moving the BO would make things less efficient, but should never cause a crash.

Maybe we should add a CC: stable tag and push it to -fixes instead?

Christian.

Am 09.11.21 um 13:28 schrieb Pan, Xinhui:

Quoted 44 lines

[AMD Official Use Only]

I hit vulkan cts test hang with navi23.

dmesg says gmc page fault with address 0x0, 0x1000, 0x2000....
And some debug log also says amdgu copy one BO from system Domain to system Domain which is really weird.
________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:20
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Am 09.11.21 um 12:19 schrieb xinhui pan:

Quoted 4 lines

After we move BO to a new memory region, we should put it to the new memory manager's lru list regardless we unlock the resv or not.

Interesting find, did you trigger that somehow or did you just stumbled over it by reading the code?

Patch is Reviewed-by: Christian König <[email protected]>, I will pick that up for drm-misc-next.

Thanks,
Christian.

Quoted 17 lines
---
   drivers/gpu/drm/ttm/ttm_bo.c | 2 ++
   1 file changed, 2 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +2 -0
index f1367107925b..e307004f0b28 100644
@@ -701,6 +701,8 @@ int ttm_mem_evict_first(struct ttm_device *bdev,
       ret = ttm_bo_evict(bo, ctx);
       if (locked)
               ttm_bo_unreserve(bo);
+     else
+             ttm_bo_move_to_lru_tail_unlocked(bo);
 
       ttm_bo_put(bo);
       return ret;
#5 lore raw

[AMD Official Use Only]

Actually this patch does not totally fix the mismatch of lru list with mem_type as mem_type is changed in ->move() and lru list is changed after that.

During this small period, another eviction could still happed and evict this mismatched BO from sMam(say, its lru list is on vram domain) to sMem.
________________________________________
发件人: Pan, Xinhui <[email protected]>
发送时间: 2021年11月9日 21:05
收件人: Koenig, Christian; [email protected]
抄送: [email protected]
主题: 回复: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Yes, a stable tag is needed. vulkan guys say 5.14 hit this issue too.

I think that amdgpu_bo_move() does support copy from sysMem to sysMem correctly. maybe something below is needed.

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
index c83ef42ca702..aa63ae7ddf1e 100644
@@ -485,7 +485,8 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
        }
        if (old_mem->mem_type == TTM_PL_SYSTEM &&
            (new_mem->mem_type == TTM_PL_TT ||
-            new_mem->mem_type == AMDGPU_PL_PREEMPT)) {
+            new_mem->mem_type == AMDGPU_PL_PREEMPT ||
+            new_mem->mem_type == TTM_PL_SYSTEM)) {
                ttm_bo_move_null(bo, new_mem);
                goto out;
        }

otherwise, amdgpu_move_blit() is called to do the system memory copy which use a wrong address.
206 /* Map only what can't be accessed directly */
207 if (!tmz && mem->start != AMDGPU_BO_INVALID_OFFSET) {
208 *addr = amdgpu_ttm_domain_start(adev, mem->mem_type) +
209 mm_cur->start;
210 return 0;
211 }

line 208, *addr is zero. So when amdgpu_copy_buffer submit job with such addr, page fault happens.

________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:35
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Mhm, I'm not sure what the rational behind that is.

Not moving the BO would make things less efficient, but should never cause a crash.

Maybe we should add a CC: stable tag and push it to -fixes instead?

Christian.

Am 09.11.21 um 13:28 schrieb Pan, Xinhui:

Quoted 44 lines

[AMD Official Use Only]

I hit vulkan cts test hang with navi23.

dmesg says gmc page fault with address 0x0, 0x1000, 0x2000....
And some debug log also says amdgu copy one BO from system Domain to system Domain which is really weird.
________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:20
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Am 09.11.21 um 12:19 schrieb xinhui pan:

Quoted 4 lines

After we move BO to a new memory region, we should put it to the new memory manager's lru list regardless we unlock the resv or not.

Interesting find, did you trigger that somehow or did you just stumbled over it by reading the code?

Patch is Reviewed-by: Christian König <[email protected]>, I will pick that up for drm-misc-next.

Thanks,
Christian.

Quoted 17 lines
---
   drivers/gpu/drm/ttm/ttm_bo.c | 2 ++
   1 file changed, 2 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +2 -0
index f1367107925b..e307004f0b28 100644
@@ -701,6 +701,8 @@ int ttm_mem_evict_first(struct ttm_device *bdev,
       ret = ttm_bo_evict(bo, ctx);
       if (locked)
               ttm_bo_unreserve(bo);
+     else
+             ttm_bo_move_to_lru_tail_unlocked(bo);
 
       ttm_bo_put(bo);
       return ret;
maintainer
#6 lore raw

Exactly that's the reason why we should have the double check in TTM I've mentioned in the other mail.

Christian.

Am 09.11.21 um 14:16 schrieb Pan, Xinhui:

Quoted 103 lines

[AMD Official Use Only]

Actually this patch does not totally fix the mismatch of lru list with mem_type as mem_type is changed in ->move() and lru list is changed after that.

During this small period, another eviction could still happed and evict this mismatched BO from sMam(say, its lru list is on vram domain) to sMem.
________________________________________
发件人: Pan, Xinhui <[email protected]>
发送时间: 2021年11月9日 21:05
收件人: Koenig, Christian; [email protected]
抄送: [email protected]
主题: 回复: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Yes, a stable tag is needed. vulkan guys say 5.14 hit this issue too.

I think that amdgpu_bo_move() does support copy from sysMem to sysMem correctly. maybe something below is needed.

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
index c83ef42ca702..aa63ae7ddf1e 100644
@@ -485,7 +485,8 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
         }
         if (old_mem->mem_type == TTM_PL_SYSTEM &&
             (new_mem->mem_type == TTM_PL_TT ||
-            new_mem->mem_type == AMDGPU_PL_PREEMPT)) {
+            new_mem->mem_type == AMDGPU_PL_PREEMPT ||
+            new_mem->mem_type == TTM_PL_SYSTEM)) {
                 ttm_bo_move_null(bo, new_mem);
                 goto out;
         }

otherwise, amdgpu_move_blit() is called to do the system memory copy which use a wrong address.
206 /* Map only what can't be accessed directly */
207 if (!tmz && mem->start != AMDGPU_BO_INVALID_OFFSET) {
208 *addr = amdgpu_ttm_domain_start(adev, mem->mem_type) +
209 mm_cur->start;
210 return 0;
211 }

line 208, *addr is zero. So when amdgpu_copy_buffer submit job with such addr, page fault happens.

________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:35
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Mhm, I'm not sure what the rational behind that is.

Not moving the BO would make things less efficient, but should never cause a crash.

Maybe we should add a CC: stable tag and push it to -fixes instead?

Christian.

Am 09.11.21 um 13:28 schrieb Pan, Xinhui:

Quoted 44 lines

[AMD Official Use Only]

I hit vulkan cts test hang with navi23.

dmesg says gmc page fault with address 0x0, 0x1000, 0x2000....
And some debug log also says amdgu copy one BO from system Domain to system Domain which is really weird.
________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:20
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Am 09.11.21 um 12:19 schrieb xinhui pan:

Quoted 4 lines

After we move BO to a new memory region, we should put it to the new memory manager's lru list regardless we unlock the resv or not.

Interesting find, did you trigger that somehow or did you just stumbled over it by reading the code?

Patch is Reviewed-by: Christian König <[email protected]>, I will pick that up for drm-misc-next.

Thanks,
Christian.

Quoted 17 lines
---
    drivers/gpu/drm/ttm/ttm_bo.c | 2 ++
    1 file changed, 2 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +2 -0
index f1367107925b..e307004f0b28 100644
@@ -701,6 +701,8 @@ int ttm_mem_evict_first(struct ttm_device *bdev,
        ret = ttm_bo_evict(bo, ctx);
        if (locked)
                ttm_bo_unreserve(bo);
+     else
+             ttm_bo_move_to_lru_tail_unlocked(bo);
 
        ttm_bo_put(bo);
        return ret;
#7 lore raw

[AMD Official Use Only]

yes, a double check is needed.
how about change below.

As long as we detect such mismatch, it indicates another eviction is on going. return false here is reasonable.

@@ -1335,6 +1336,8 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,

        struct dma_fence *f;
        int i;

+ if (bo->resource->mem_type != place->mem_type)

+               return false;
        /* Swapout? */
        if (bo->resource->mem_type == TTM_PL_SYSTEM)
                return true;

________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 21:18
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: 回复: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Exactly that's the reason why we should have the double check in TTM I've mentioned in the other mail.

Christian.

Am 09.11.21 um 14:16 schrieb Pan, Xinhui:

Quoted 103 lines

[AMD Official Use Only]

Actually this patch does not totally fix the mismatch of lru list with mem_type as mem_type is changed in ->move() and lru list is changed after that.

During this small period, another eviction could still happed and evict this mismatched BO from sMam(say, its lru list is on vram domain) to sMem.
________________________________________
发件人: Pan, Xinhui <[email protected]>
发送时间: 2021年11月9日 21:05
收件人: Koenig, Christian; [email protected]
抄送: [email protected]
主题: 回复: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Yes, a stable tag is needed. vulkan guys say 5.14 hit this issue too.

I think that amdgpu_bo_move() does support copy from sysMem to sysMem correctly. maybe something below is needed.

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
index c83ef42ca702..aa63ae7ddf1e 100644
@@ -485,7 +485,8 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
         }
         if (old_mem->mem_type == TTM_PL_SYSTEM &&
             (new_mem->mem_type == TTM_PL_TT ||
-            new_mem->mem_type == AMDGPU_PL_PREEMPT)) {
+            new_mem->mem_type == AMDGPU_PL_PREEMPT ||
+            new_mem->mem_type == TTM_PL_SYSTEM)) {
                 ttm_bo_move_null(bo, new_mem);
                 goto out;
         }

otherwise, amdgpu_move_blit() is called to do the system memory copy which use a wrong address.
206 /* Map only what can't be accessed directly */
207 if (!tmz && mem->start != AMDGPU_BO_INVALID_OFFSET) {
208 *addr = amdgpu_ttm_domain_start(adev, mem->mem_type) +
209 mm_cur->start;
210 return 0;
211 }

line 208, *addr is zero. So when amdgpu_copy_buffer submit job with such addr, page fault happens.

________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:35
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Mhm, I'm not sure what the rational behind that is.

Not moving the BO would make things less efficient, but should never cause a crash.

Maybe we should add a CC: stable tag and push it to -fixes instead?

Christian.

Am 09.11.21 um 13:28 schrieb Pan, Xinhui:

Quoted 44 lines

[AMD Official Use Only]

I hit vulkan cts test hang with navi23.

dmesg says gmc page fault with address 0x0, 0x1000, 0x2000....
And some debug log also says amdgu copy one BO from system Domain to system Domain which is really weird.
________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:20
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Am 09.11.21 um 12:19 schrieb xinhui pan:

Quoted 4 lines

After we move BO to a new memory region, we should put it to the new memory manager's lru list regardless we unlock the resv or not.

Interesting find, did you trigger that somehow or did you just stumbled over it by reading the code?

Patch is Reviewed-by: Christian König <[email protected]>, I will pick that up for drm-misc-next.

Thanks,
Christian.

Quoted 17 lines
---
    drivers/gpu/drm/ttm/ttm_bo.c | 2 ++
    1 file changed, 2 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +2 -0
index f1367107925b..e307004f0b28 100644
@@ -701,6 +701,8 @@ int ttm_mem_evict_first(struct ttm_device *bdev,
        ret = ttm_bo_evict(bo, ctx);
        if (locked)
                ttm_bo_unreserve(bo);
+     else
+             ttm_bo_move_to_lru_tail_unlocked(bo);
 
        ttm_bo_put(bo);
        return ret;
maintainer
#8 lore raw

In general the correct idea, but the wrong place to check that.

Calling amdgpu_ttm_bo_eviction_valuable() is only optional, but that check must be mandatory for correct operation.

This needs to be inside ttm_bo_evict_swapout_allowable().

Christian.

Am 09.11.21 um 14:41 schrieb Pan, Xinhui:

Quoted 133 lines

[AMD Official Use Only]

yes, a double check is needed.
how about change below.

As long as we detect such mismatch, it indicates another eviction is on going. return false here is reasonable.

(quoted diff) +2 -0
@@ -1335,6 +1336,8 @@ static bool amdgpu_ttm_bo_eviction_valuable(struct ttm_buffer_object *bo,
         struct dma_fence *f;
         int i;
 
+       if (bo->resource->mem_type != place->mem_type)
+               return false;
         /* Swapout? */
         if (bo->resource->mem_type == TTM_PL_SYSTEM)
                 return true;

________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 21:18
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: 回复: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Exactly that's the reason why we should have the double check in TTM I've mentioned in the other mail.

Christian.

Am 09.11.21 um 14:16 schrieb Pan, Xinhui:

Quoted 103 lines

[AMD Official Use Only]

Actually this patch does not totally fix the mismatch of lru list with mem_type as mem_type is changed in ->move() and lru list is changed after that.

During this small period, another eviction could still happed and evict this mismatched BO from sMam(say, its lru list is on vram domain) to sMem.
________________________________________
发件人: Pan, Xinhui <[email protected]>
发送时间: 2021年11月9日 21:05
收件人: Koenig, Christian; [email protected]
抄送: [email protected]
主题: 回复: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Yes, a stable tag is needed. vulkan guys say 5.14 hit this issue too.

I think that amdgpu_bo_move() does support copy from sysMem to sysMem correctly. maybe something below is needed.

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
index c83ef42ca702..aa63ae7ddf1e 100644
@@ -485,7 +485,8 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
          }
          if (old_mem->mem_type == TTM_PL_SYSTEM &&
              (new_mem->mem_type == TTM_PL_TT ||
-            new_mem->mem_type == AMDGPU_PL_PREEMPT)) {
+            new_mem->mem_type == AMDGPU_PL_PREEMPT ||
+            new_mem->mem_type == TTM_PL_SYSTEM)) {
                  ttm_bo_move_null(bo, new_mem);
                  goto out;
          }

otherwise, amdgpu_move_blit() is called to do the system memory copy which use a wrong address.
206 /* Map only what can't be accessed directly */

   207         if (!tmz && mem->start != AMDGPU_BO_INVALID_OFFSET) {
   208                 *addr = amdgpu_ttm_domain_start(adev, mem->mem_type) +
   209                         mm_cur->start;
   210                 return 0;
   211         }

line 208, *addr is zero. So when amdgpu_copy_buffer submit job with such addr, page fault happens.

________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:35
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Mhm, I'm not sure what the rational behind that is.

Not moving the BO would make things less efficient, but should never cause a crash.

Maybe we should add a CC: stable tag and push it to -fixes instead?

Christian.

Am 09.11.21 um 13:28 schrieb Pan, Xinhui:

Quoted 44 lines

[AMD Official Use Only]

I hit vulkan cts test hang with navi23.

dmesg says gmc page fault with address 0x0, 0x1000, 0x2000....
And some debug log also says amdgu copy one BO from system Domain to system Domain which is really weird.
________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:20
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Am 09.11.21 um 12:19 schrieb xinhui pan:

Quoted 4 lines

After we move BO to a new memory region, we should put it to the new memory manager's lru list regardless we unlock the resv or not.

Interesting find, did you trigger that somehow or did you just stumbled over it by reading the code?

Patch is Reviewed-by: Christian König <[email protected]>, I will pick that up for drm-misc-next.

Thanks,
Christian.

Quoted 17 lines
---
     drivers/gpu/drm/ttm/ttm_bo.c | 2 ++
     1 file changed, 2 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +2 -0
index f1367107925b..e307004f0b28 100644
@@ -701,6 +701,8 @@ int ttm_mem_evict_first(struct ttm_device *bdev,
         ret = ttm_bo_evict(bo, ctx);
         if (locked)
                 ttm_bo_unreserve(bo);
+     else
+             ttm_bo_move_to_lru_tail_unlocked(bo);
 
         ttm_bo_put(bo);
         return ret;
#9 lore raw
In reply to Pan, Xinhui

[Public]

Hi Christian,

Looks this patch still missed in 5.16 kernel. Is it intentional?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/ttm/ttm_bo.c?h=v5.16

Regards,
Guchun

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Pan, Xinhui
Sent: Tuesday, November 9, 2021 9:16 PM
To: Koenig, Christian <[email protected]>; [email protected]
Cc: [email protected]
Subject: 回复: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

[AMD Official Use Only]

[AMD Official Use Only]

Actually this patch does not totally fix the mismatch of lru list with mem_type as mem_type is changed in ->move() and lru list is changed after that.

During this small period, another eviction could still happed and evict this mismatched BO from sMam(say, its lru list is on vram domain) to sMem.
________________________________________
发件人: Pan, Xinhui <[email protected]>
发送时间: 2021年11月9日 21:05
收件人: Koenig, Christian; [email protected]
抄送: [email protected]
主题: 回复: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Yes, a stable tag is needed. vulkan guys say 5.14 hit this issue too.

I think that amdgpu_bo_move() does support copy from sysMem to sysMem correctly. maybe something below is needed.

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
index c83ef42ca702..aa63ae7ddf1e 100644
@@ -485,7 +485,8 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
        }
        if (old_mem->mem_type == TTM_PL_SYSTEM &&
            (new_mem->mem_type == TTM_PL_TT ||
-            new_mem->mem_type == AMDGPU_PL_PREEMPT)) {
+            new_mem->mem_type == AMDGPU_PL_PREEMPT ||
+            new_mem->mem_type == TTM_PL_SYSTEM)) {
                ttm_bo_move_null(bo, new_mem);
                goto out;
        }

otherwise, amdgpu_move_blit() is called to do the system memory copy which use a wrong address.
206 /* Map only what can't be accessed directly */
207 if (!tmz && mem->start != AMDGPU_BO_INVALID_OFFSET) {
208 *addr = amdgpu_ttm_domain_start(adev, mem->mem_type) +
209 mm_cur->start;
210 return 0;
211 }

line 208, *addr is zero. So when amdgpu_copy_buffer submit job with such addr, page fault happens.

________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:35
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Mhm, I'm not sure what the rational behind that is.

Not moving the BO would make things less efficient, but should never cause a crash.

Maybe we should add a CC: stable tag and push it to -fixes instead?

Christian.

Am 09.11.21 um 13:28 schrieb Pan, Xinhui:

Quoted 45 lines

[AMD Official Use Only]

I hit vulkan cts test hang with navi23.

dmesg says gmc page fault with address 0x0, 0x1000, 0x2000....
And some debug log also says amdgu copy one BO from system Domain to system Domain which is really weird.
________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:20
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Am 09.11.21 um 12:19 schrieb xinhui pan:

Quoted 4 lines

After we move BO to a new memory region, we should put it to the new memory manager's lru list regardless we unlock the resv or not.

Interesting find, did you trigger that somehow or did you just stumbled over it by reading the code?

Patch is Reviewed-by: Christian König <[email protected]>, I will pick that up for drm-misc-next.

Thanks,
Christian.

Quoted 18 lines
---
   drivers/gpu/drm/ttm/ttm_bo.c | 2 ++
   1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/ttm/ttm_bo.c index f1367107925b..e307004f0b28 100644

drivers/gpu/drm/ttm/ttm_bo.c +2 -0
@@ -701,6 +701,8 @@ int ttm_mem_evict_first(struct ttm_device *bdev,
       ret = ttm_bo_evict(bo, ctx);
       if (locked)
               ttm_bo_unreserve(bo);
+     else
+             ttm_bo_move_to_lru_tail_unlocked(bo);
 
       ttm_bo_put(bo);
       return ret;
#10 lore raw

IIRC we have completely dropped this patch in favor of a check at a different place.

Regards,
Christian.

Am 11.01.22 um 09:47 schrieb Chen, Guchun:

Quoted 122 lines

[Public]

Hi Christian,

Looks this patch still missed in 5.16 kernel. Is it intentional?
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/ttm/ttm_bo.c?h=v5.16

Regards,
Guchun

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Pan, Xinhui
Sent: Tuesday, November 9, 2021 9:16 PM
To: Koenig, Christian <[email protected]>; [email protected]
Cc: [email protected]
Subject: 回复: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

[AMD Official Use Only]

[AMD Official Use Only]

Actually this patch does not totally fix the mismatch of lru list with mem_type as mem_type is changed in ->move() and lru list is changed after that.

During this small period, another eviction could still happed and evict this mismatched BO from sMam(say, its lru list is on vram domain) to sMem.
________________________________________
发件人: Pan, Xinhui <[email protected]>
发送时间: 2021年11月9日 21:05
收件人: Koenig, Christian; [email protected]
抄送: [email protected]
主题: 回复: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Yes, a stable tag is needed. vulkan guys say 5.14 hit this issue too.

I think that amdgpu_bo_move() does support copy from sysMem to sysMem correctly. maybe something below is needed.

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
index c83ef42ca702..aa63ae7ddf1e 100644
@@ -485,7 +485,8 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
         }
         if (old_mem->mem_type == TTM_PL_SYSTEM &&
             (new_mem->mem_type == TTM_PL_TT ||
-            new_mem->mem_type == AMDGPU_PL_PREEMPT)) {
+            new_mem->mem_type == AMDGPU_PL_PREEMPT ||
+            new_mem->mem_type == TTM_PL_SYSTEM)) {
                 ttm_bo_move_null(bo, new_mem);
                 goto out;
         }

otherwise, amdgpu_move_blit() is called to do the system memory copy which use a wrong address.
206 /* Map only what can't be accessed directly */
207 if (!tmz && mem->start != AMDGPU_BO_INVALID_OFFSET) {
208 *addr = amdgpu_ttm_domain_start(adev, mem->mem_type) +
209 mm_cur->start;
210 return 0;
211 }

line 208, *addr is zero. So when amdgpu_copy_buffer submit job with such addr, page fault happens.

________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:35
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Mhm, I'm not sure what the rational behind that is.

Not moving the BO would make things less efficient, but should never cause a crash.

Maybe we should add a CC: stable tag and push it to -fixes instead?

Christian.

Am 09.11.21 um 13:28 schrieb Pan, Xinhui:

Quoted 45 lines

[AMD Official Use Only]

I hit vulkan cts test hang with navi23.

dmesg says gmc page fault with address 0x0, 0x1000, 0x2000....
And some debug log also says amdgu copy one BO from system Domain to system Domain which is really weird.
________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:20
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Am 09.11.21 um 12:19 schrieb xinhui pan:

Quoted 4 lines

After we move BO to a new memory region, we should put it to the new memory manager's lru list regardless we unlock the resv or not.

Interesting find, did you trigger that somehow or did you just stumbled over it by reading the code?

Patch is Reviewed-by: Christian König <[email protected]>, I will pick that up for drm-misc-next.

Thanks,
Christian.

Quoted 18 lines
---
    drivers/gpu/drm/ttm/ttm_bo.c | 2 ++
    1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/ttm/ttm_bo.c index f1367107925b..e307004f0b28 100644

drivers/gpu/drm/ttm/ttm_bo.c +2 -0
@@ -701,6 +701,8 @@ int ttm_mem_evict_first(struct ttm_device *bdev,
        ret = ttm_bo_evict(bo, ctx);
        if (locked)
                ttm_bo_unreserve(bo);
+     else
+             ttm_bo_move_to_lru_tail_unlocked(bo);
 
        ttm_bo_put(bo);
        return ret;
#11 lore raw

[Public]

Hi Christian,

My BAD, I checked that discussion history of this just now. So If I read it correctly, the double check at a different place to skip evict is: " drm/ttm: Double check mem_type of BO while eviction"? It is in 5.16 kernel.

Regards,
Guchun

-----Original Message-----
From: Christian König <[email protected]>
Sent: Tuesday, January 11, 2022 7:27 PM
To: Chen, Guchun <[email protected]>; Pan, Xinhui <[email protected]>; Koenig, Christian <[email protected]>; [email protected]
Cc: [email protected]
Subject: Re: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

IIRC we have completely dropped this patch in favor of a check at a different place.

Regards,
Christian.

Am 11.01.22 um 09:47 schrieb Chen, Guchun:

Quoted 133 lines

[Public]

Hi Christian,

Looks this patch still missed in 5.16 kernel. Is it intentional?
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.
kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git%2 Ftree%2Fdrivers%2Fgpu%2Fdrm%2Fttm%2Fttm_bo.c%3Fh%3Dv5.16&amp;data=04%7 C01%7CGuchun.Chen%40amd.com%7Cf3b7f4971dc8405b0c2908d9d4f55547%7C3dd89 61fe4884e608e11a82d994e183d%7C0%7C0%7C637774972434004088%7CUnknown%7CT WFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI 6Mn0%3D%7C3000&amp;sdata=vbuBPHO40J2HGt7abzfzC0nC1DQa62qal5S6TXBRj4w%3 D&amp;reserved=0

Regards,
Guchun

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Pan, Xinhui
Sent: Tuesday, November 9, 2021 9:16 PM
To: Koenig, Christian <[email protected]>; [email protected]
Cc: [email protected]
Subject: 回复: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

[AMD Official Use Only]

[AMD Official Use Only]

Actually this patch does not totally fix the mismatch of lru list with mem_type as mem_type is changed in ->move() and lru list is changed after that.

During this small period, another eviction could still happed and evict this mismatched BO from sMam(say, its lru list is on vram domain) to sMem.
________________________________________
发件人: Pan, Xinhui <[email protected]>
发送时间: 2021年11月9日 21:05
收件人: Koenig, Christian; [email protected]
抄送: [email protected]
主题: 回复: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Yes, a stable tag is needed. vulkan guys say 5.14 hit this issue too.

I think that amdgpu_bo_move() does support copy from sysMem to sysMem correctly. maybe something below is needed.

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
index c83ef42ca702..aa63ae7ddf1e 100644
@@ -485,7 +485,8 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
         }
         if (old_mem->mem_type == TTM_PL_SYSTEM &&
             (new_mem->mem_type == TTM_PL_TT ||
-            new_mem->mem_type == AMDGPU_PL_PREEMPT)) {
+            new_mem->mem_type == AMDGPU_PL_PREEMPT ||
+            new_mem->mem_type == TTM_PL_SYSTEM)) {
                 ttm_bo_move_null(bo, new_mem);
                 goto out;
         }

otherwise, amdgpu_move_blit() is called to do the system memory copy which use a wrong address.
206 /* Map only what can't be accessed directly */
207 if (!tmz && mem->start != AMDGPU_BO_INVALID_OFFSET) {
208 *addr = amdgpu_ttm_domain_start(adev, mem->mem_type) +
209 mm_cur->start;
210 return 0;
211 }

line 208, *addr is zero. So when amdgpu_copy_buffer submit job with such addr, page fault happens.

________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:35
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Mhm, I'm not sure what the rational behind that is.

Not moving the BO would make things less efficient, but should never cause a crash.

Maybe we should add a CC: stable tag and push it to -fixes instead?

Christian.

Am 09.11.21 um 13:28 schrieb Pan, Xinhui:

Quoted 45 lines

[AMD Official Use Only]

I hit vulkan cts test hang with navi23.

dmesg says gmc page fault with address 0x0, 0x1000, 0x2000....
And some debug log also says amdgu copy one BO from system Domain to system Domain which is really weird.
________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:20
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Am 09.11.21 um 12:19 schrieb xinhui pan:

Quoted 4 lines

After we move BO to a new memory region, we should put it to the new memory manager's lru list regardless we unlock the resv or not.

Interesting find, did you trigger that somehow or did you just stumbled over it by reading the code?

Patch is Reviewed-by: Christian König <[email protected]>, I will pick that up for drm-misc-next.

Thanks,
Christian.

Quoted 18 lines
---
    drivers/gpu/drm/ttm/ttm_bo.c | 2 ++
    1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/ttm/ttm_bo.c index f1367107925b..e307004f0b28 100644

drivers/gpu/drm/ttm/ttm_bo.c +2 -0
@@ -701,6 +701,8 @@ int ttm_mem_evict_first(struct ttm_device *bdev,
        ret = ttm_bo_evict(bo, ctx);
        if (locked)
                ttm_bo_unreserve(bo);
+     else
+             ttm_bo_move_to_lru_tail_unlocked(bo);
 
        ttm_bo_put(bo);
        return ret;
maintainer
#12 lore raw

Yeah, that should probably be the right one.

Christian.

Am 12.01.22 um 03:19 schrieb Chen, Guchun:

Quoted 155 lines

[Public]

Hi Christian,

My BAD, I checked that discussion history of this just now. So If I read it correctly, the double check at a different place to skip evict is: " drm/ttm: Double check mem_type of BO while eviction"? It is in 5.16 kernel.

Regards,
Guchun

-----Original Message-----
From: Christian König <[email protected]>
Sent: Tuesday, January 11, 2022 7:27 PM
To: Chen, Guchun <[email protected]>; Pan, Xinhui <[email protected]>; Koenig, Christian <[email protected]>; [email protected]
Cc: [email protected]
Subject: Re: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

IIRC we have completely dropped this patch in favor of a check at a different place.

Regards,
Christian.

Am 11.01.22 um 09:47 schrieb Chen, Guchun:

Quoted 133 lines

[Public]

Hi Christian,

Looks this patch still missed in 5.16 kernel. Is it intentional?
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.
kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git%2 Ftree%2Fdrivers%2Fgpu%2Fdrm%2Fttm%2Fttm_bo.c%3Fh%3Dv5.16&amp;data=04%7 C01%7CGuchun.Chen%40amd.com%7Cf3b7f4971dc8405b0c2908d9d4f55547%7C3dd89 61fe4884e608e11a82d994e183d%7C0%7C0%7C637774972434004088%7CUnknown%7CT WFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI 6Mn0%3D%7C3000&amp;sdata=vbuBPHO40J2HGt7abzfzC0nC1DQa62qal5S6TXBRj4w%3 D&amp;reserved=0

Regards,
Guchun

-----Original Message-----
From: amd-gfx <[email protected]> On Behalf Of Pan, Xinhui
Sent: Tuesday, November 9, 2021 9:16 PM
To: Koenig, Christian <[email protected]>; [email protected]
Cc: [email protected]
Subject: 回复: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

[AMD Official Use Only]

[AMD Official Use Only]

Actually this patch does not totally fix the mismatch of lru list with mem_type as mem_type is changed in ->move() and lru list is changed after that.

During this small period, another eviction could still happed and evict this mismatched BO from sMam(say, its lru list is on vram domain) to sMem.
________________________________________
发件人: Pan, Xinhui <[email protected]>
发送时间: 2021年11月9日 21:05
收件人: Koenig, Christian; [email protected]
抄送: [email protected]
主题: 回复: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Yes, a stable tag is needed. vulkan guys say 5.14 hit this issue too.

I think that amdgpu_bo_move() does support copy from sysMem to sysMem correctly. maybe something below is needed.

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
index c83ef42ca702..aa63ae7ddf1e 100644
@@ -485,7 +485,8 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
          }
          if (old_mem->mem_type == TTM_PL_SYSTEM &&
              (new_mem->mem_type == TTM_PL_TT ||
-            new_mem->mem_type == AMDGPU_PL_PREEMPT)) {
+            new_mem->mem_type == AMDGPU_PL_PREEMPT ||
+            new_mem->mem_type == TTM_PL_SYSTEM)) {
                  ttm_bo_move_null(bo, new_mem);
                  goto out;
          }

otherwise, amdgpu_move_blit() is called to do the system memory copy which use a wrong address.
206 /* Map only what can't be accessed directly */

   207         if (!tmz && mem->start != AMDGPU_BO_INVALID_OFFSET) {
   208                 *addr = amdgpu_ttm_domain_start(adev, mem->mem_type) +
   209                         mm_cur->start;
   210                 return 0;
   211         }

line 208, *addr is zero. So when amdgpu_copy_buffer submit job with such addr, page fault happens.

________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:35
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Mhm, I'm not sure what the rational behind that is.

Not moving the BO would make things less efficient, but should never cause a crash.

Maybe we should add a CC: stable tag and push it to -fixes instead?

Christian.

Am 09.11.21 um 13:28 schrieb Pan, Xinhui:

Quoted 45 lines

[AMD Official Use Only]

I hit vulkan cts test hang with navi23.

dmesg says gmc page fault with address 0x0, 0x1000, 0x2000....
And some debug log also says amdgu copy one BO from system Domain to system Domain which is really weird.
________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:20
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Am 09.11.21 um 12:19 schrieb xinhui pan:

Quoted 4 lines

After we move BO to a new memory region, we should put it to the new memory manager's lru list regardless we unlock the resv or not.

Interesting find, did you trigger that somehow or did you just stumbled over it by reading the code?

Patch is Reviewed-by: Christian König <[email protected]>, I will pick that up for drm-misc-next.

Thanks,
Christian.

Quoted 18 lines
---
     drivers/gpu/drm/ttm/ttm_bo.c | 2 ++
     1 file changed, 2 insertions(+)
(quoted diff) +0 -0

b/drivers/gpu/drm/ttm/ttm_bo.c index f1367107925b..e307004f0b28 100644

drivers/gpu/drm/ttm/ttm_bo.c +2 -0
@@ -701,6 +701,8 @@ int ttm_mem_evict_first(struct ttm_device *bdev,
         ret = ttm_bo_evict(bo, ctx);
         if (locked)
                 ttm_bo_unreserve(bo);
+     else
+             ttm_bo_move_to_lru_tail_unlocked(bo);
 
         ttm_bo_put(bo);
         return ret;
maintainer
#13 lore raw
In reply to Pan, Xinhui

Yeah, but that should never happen in the first place.

Even when the BO is on the wrong LRU TTM should check that beforehand.

In other words when we pick a BO from the LRU we should still double check bo->resource->mem_type to make sure it is what we are searching for.

Christian.

Am 09.11.21 um 14:05 schrieb Pan, Xinhui:

Quoted 93 lines

[AMD Official Use Only]

Yes, a stable tag is needed. vulkan guys say 5.14 hit this issue too.

I think that amdgpu_bo_move() does support copy from sysMem to sysMem correctly. maybe something below is needed.

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +2 -1
index c83ef42ca702..aa63ae7ddf1e 100644
@@ -485,7 +485,8 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
         }
         if (old_mem->mem_type == TTM_PL_SYSTEM &&
             (new_mem->mem_type == TTM_PL_TT ||
-            new_mem->mem_type == AMDGPU_PL_PREEMPT)) {
+            new_mem->mem_type == AMDGPU_PL_PREEMPT ||
+            new_mem->mem_type == TTM_PL_SYSTEM)) {
                 ttm_bo_move_null(bo, new_mem);
                 goto out;
         }

otherwise, amdgpu_move_blit() is called to do the system memory copy which use a wrong address.
206 /* Map only what can't be accessed directly */
207 if (!tmz && mem->start != AMDGPU_BO_INVALID_OFFSET) {
208 *addr = amdgpu_ttm_domain_start(adev, mem->mem_type) +
209 mm_cur->start;
210 return 0;
211 }

line 208, *addr is zero. So when amdgpu_copy_buffer submit job with such addr, page fault happens.

________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:35
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: 回复: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Mhm, I'm not sure what the rational behind that is.

Not moving the BO would make things less efficient, but should never cause a crash.

Maybe we should add a CC: stable tag and push it to -fixes instead?

Christian.

Am 09.11.21 um 13:28 schrieb Pan, Xinhui:

Quoted 44 lines

[AMD Official Use Only]

I hit vulkan cts test hang with navi23.

dmesg says gmc page fault with address 0x0, 0x1000, 0x2000....
And some debug log also says amdgu copy one BO from system Domain to system Domain which is really weird.
________________________________________
发件人: Koenig, Christian <[email protected]>
发送时间: 2021年11月9日 20:20
收件人: Pan, Xinhui; [email protected]
抄送: [email protected]
主题: Re: [PATCH] drm/ttm: Put BO in its memory manager's lru list

Am 09.11.21 um 12:19 schrieb xinhui pan:

Quoted 4 lines

After we move BO to a new memory region, we should put it to the new memory manager's lru list regardless we unlock the resv or not.

Interesting find, did you trigger that somehow or did you just stumbled over it by reading the code?

Patch is Reviewed-by: Christian König <[email protected]>, I will pick that up for drm-misc-next.

Thanks,
Christian.

Quoted 17 lines
---
    drivers/gpu/drm/ttm/ttm_bo.c | 2 ++
    1 file changed, 2 insertions(+)
drivers/gpu/drm/ttm/ttm_bo.c +2 -0
index f1367107925b..e307004f0b28 100644
@@ -701,6 +701,8 @@ int ttm_mem_evict_first(struct ttm_device *bdev,
        ret = ttm_bo_evict(bo, ctx);
        if (locked)
                ttm_bo_unreserve(bo);
+     else
+             ttm_bo_move_to_lru_tail_unlocked(bo);
 
        ttm_bo_put(bo);
        return ret;