Skip to contentSkip to conversation

drm/amdgpu: Fix amdgpu_vm_alloc_pts failed

PATCH In review Rex Zhu 3 participants 6 messages Oct 23, 2018 4 messages not in the archive

Subsystems (2)
lore
Share & tools
lore

Rex Zhu

author
#0 lore raw

PATCH 1/1 drm/amdgpu: Fix amdgpu_vm_alloc_pts failed

when the VA address located in the last PD entries, the alloc_pts will faile.

Use the right PD mask instand of hardcode, suggested by jerry.zhang.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -1
index 054633b..3939013 100644
@@ -202,8 +202,11 @@ static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev,
 static uint32_t amdgpu_vm_entries_mask(struct amdgpu_device *adev,
 				       unsigned int level)
 {
+	unsigned shift = amdgpu_vm_level_shift(adev,
+					       adev->vm_manager.root_level);
+
 	if (level <= adev->vm_manager.root_level)
-		return 0xffffffff;
+		return (round_up(adev->vm_manager.max_pfn, 1 << shift) >> shift) - 1;
 	else if (level != AMDGPU_VM_PTB)
 		return 0x1ff;
 	else
Signature · 6 lines
1.9.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Reviewed-by Junwei Zhang
#2 lore raw
In reply to a message not in the archive
Quoted 7 lines · Rex Zhu

when the VA address located in the last PD entries, the alloc_pts will faile.

Use the right PD mask instand of hardcode, suggested by jerry.zhang.

Thanks to verify that.
Feel free to add

Also like to get to know some background about these two functions from Christian. Perhaps we may make it more simple, e.g. merging them together.

Regards,
Jerry

Quoted 11 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
index 054633b..3939013 100644
@@ -202,8 +202,11 @@ static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev,
  static uint32_t amdgpu_vm_entries_mask(struct amdgpu_device *adev,
  				       unsigned int level)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev, · line 212

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -1
  {
+	unsigned shift = amdgpu_vm_level_shift(adev,
+					       adev->vm_manager.root_level);
+
  	if (level <= adev->vm_manager.root_level)
-		return 0xffffffff;
+		return (round_up(adev->vm_manager.max_pfn, 1 << shift) >> shift) - 1;
  	else if (level != AMDGPU_VM_PTB)
  		return 0x1ff;
  	else

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

#4 lore raw
In reply to a message not in the archive
Quoted 7 lines · Jerry(Junwei)
Quoted 6 lines · Rex Zhu

when the VA address located in the last PD entries, the alloc_pts will faile.

Use the right PD mask instand of hardcode, suggested by jerry.zhang.

Quoted 8 lines
Quoted 1 line

Thanks to verify that.
Feel free to add

Also like to get to know some background about these two functions from Christian. Perhaps we may make it more simple, e.g. merging them together.

If we really needs them all, we may simplify that like:

```
amdgpu_vm_entries_mask(struct amdgpu_device *adev, unsigned int level)
{
    return amdgpu_vm_num_entries(adev, level) - 1;
}
```

Jerry

Quoted 24 lines

Regards,
Jerry

Quoted 20 lines

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 ++++-

  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -1
index 054633b..3939013 100644
@@ -202,8 +202,11 @@ static unsigned amdgpu_vm_num_entries(struct 
 amdgpu_device *adev,
   static uint32_t amdgpu_vm_entries_mask(struct amdgpu_device *adev,
                          unsigned int level)
   {
+    unsigned shift = amdgpu_vm_level_shift(adev,
+                           adev->vm_manager.root_level);
+
       if (level <= adev->vm_manager.root_level)
-        return 0xffffffff;
+        return (round_up(adev->vm_manager.max_pfn, 1 << shift) >> 
 shift) - 1;
Quoted 8 lines
Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
       else if (level != AMDGPU_VM_PTB)

          return 0x1ff;
      else

_______________________________________________
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

author Reviewed-by Junwei Zhang
#5 lore raw
In reply to a message not in the archive

No, if the vm size is small, there may only on root pd entry.

we need to make sure the mask >= 0;

Maybe this change revert Christian's commit:

commit 72af632549b97ead9251bb155f08fefd1fb6f5c3

Author: Christian König <[email protected]>
Date:   Sat Sep 15 10:02:13 2018 +0200

drm/amdgpu: add amdgpu_vm_entries_mask v2

We can't get the mask for the root directory from the number of entries.

So add a new function to avoid that problem.

Best Regards

Rex

________________________________
From: amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org> on behalf of Zhang, Jerry(Junwei) <[email protected]>
Sent: Tuesday, October 23, 2018 1:12 PM
To: Zhu, Rex; [email protected]; Deucher, Alexander; Koenig, Christian
Subject: Re: [PATCH] drm/amdgpu: Fix amdgpu_vm_alloc_pts failed

Quoted 7 lines · Rex Zhu

when the VA address located in the last PD entries, the alloc_pts will faile.

Use the right PD mask instand of hardcode, suggested by jerry.zhang.

Thanks to verify that.
Feel free to add

Also like to get to know some background about these two functions from Christian.
Perhaps we may make it more simple, e.g. merging them together.

Regards,
Jerry

Quoted 11 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
index 054633b..3939013 100644
@@ -202,8 +202,11 @@ static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev,
  static uint32_t amdgpu_vm_entries_mask(struct amdgpu_device *adev,
                                      unsigned int level)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev, · line 212

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -1
  {
+     unsigned shift = amdgpu_vm_level_shift(adev,
+                                            adev->vm_manager.root_level);
+
       if (level <= adev->vm_manager.root_level)
-             return 0xffffffff;
+             return (round_up(adev->vm_manager.max_pfn, 1 << shift) >> shift) - 1;
       else if (level != AMDGPU_VM_PTB)
               return 0x1ff;
       else

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
amd-gfx Info Page - freedesktop.org<https://lists.freedesktop.org/mailman/listinfo/amd-gfx>
lists.freedesktop.org
To see the collection of prior postings to the list, visit the amd-gfx Archives.. Using amd-gfx: To post a message to all the list members, send email to [email protected] You can subscribe to the list, or change your existing subscription, in the sections below.

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

#7 lore raw
In reply to a message not in the archive

Hi guys,

yeah the root PD doesn't necessarily have a power of two entries.

But what exactly was the problem with the original code? Why does 0xffffffff doesn't work?

The only possible explanation I can see is that somebody tried to use an address which is above max_pfn, or how did that trigger?

Thanks,
Christian.

Am 23.10.18 um 07:42 schrieb Zhu, Rex:

Quoted 86 lines

No, if the vm size is small, there may only on root pd entry.

we need to make sure the mask >= 0;

Maybe this change revert Christian's commit:

commit 72af632549b97ead9251bb155f08fefd1fb6f5c3
Author: Christian König <[email protected]> Date:   Sat Sep 15 10:02:13 2018 +0200

    drm/amdgpu: add amdgpu_vm_entries_mask v2

    We can't get the mask for the root directory from the number of entries.

    So add a new function to avoid that problem.

Best Regards

Rex

------------------------------------------------------------------------
*From:* amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org> on behalf of Zhang, Jerry(Junwei) <[email protected]> *Sent:* Tuesday, October 23, 2018 1:12 PM
*To:* Zhu, Rex; [email protected]; Deucher, Alexander; Koenig, Christian
*Subject:* Re: [PATCH] drm/amdgpu: Fix amdgpu_vm_alloc_pts failed

Quoted 7 lines · Rex Zhu

when the VA address located in the last PD entries, the alloc_pts will faile.

Use the right PD mask instand of hardcode, suggested by jerry.zhang.

Thanks to verify that.
Feel free to add

Also like to get to know some background about these two functions from Christian.
Perhaps we may make it more simple, e.g. merging them together.

Regards,
Jerry

Review

Quoted 5 lines

---
   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 ++++-

   1 file changed, 4 insertions(+), 1 deletion(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static unsigned amdgpu_vm_num_entries(struct

Quoted 4 lines

index 054633b..3939013 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
@@ -202,8 +202,11 @@ static unsigned amdgpu_vm_num_entries(struct 

amdgpu_device *adev,

Quoted 12 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -1
    static uint32_t amdgpu_vm_entries_mask(struct amdgpu_device *adev,
                                        unsigned int level)
    {
+     unsigned shift = amdgpu_vm_level_shift(adev,
+ adev->vm_manager.root_level);
+
         if (level <= adev->vm_manager.root_level)
-             return 0xffffffff;
+             return (round_up(adev->vm_manager.max_pfn, 1 << shift) 
 > shift) - 1;
         else if (level != AMDGPU_VM_PTB)
                 return 0x1ff;
Quoted 1 line

        else

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
amd-gfx Info Page - freedesktop.org <https://lists.freedesktop.org/mailman/listinfo/amd-gfx>
lists.freedesktop.org
To see the collection of prior postings to the list, visit the amd-gfx Archives.. Using amd-gfx: To post a message to all the list members, send email to [email protected] You can subscribe to the list, or change your existing subscription, in the sections below.

Quoted 4 lines

_______________________________________________
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

author Reviewed-by Junwei Zhang
#9 lore raw
In reply to a message not in the archive

Hi Christian,

You can reproduce this issue by allocate CSA buffer in baremetal and map them to reserved VM address.

Please see the attached patch.

Best Regards

Rex

________________________________
From: Christian König <[email protected]>
Sent: Tuesday, October 23, 2018 5:01 PM
To: Zhu, Rex; Zhang, Jerry; [email protected]; Deucher, Alexander; Koenig, Christian
Subject: Re: [PATCH] drm/amdgpu: Fix amdgpu_vm_alloc_pts failed

Hi guys,

yeah the root PD doesn't necessarily have a power of two entries.

But what exactly was the problem with the original code? Why does 0xffffffff doesn't work?

The only possible explanation I can see is that somebody tried to use an address which is above max_pfn, or how did that trigger?

Thanks,
Christian.

Am 23.10.18 um 07:42 schrieb Zhu, Rex:

No, if the vm size is small, there may only on root pd entry.

we need to make sure the mask >= 0;

Maybe this change revert Christian's commit:

commit 72af632549b97ead9251bb155f08fefd1fb6f5c3

Author: Christian König <[email protected]><mailto:[email protected]>
Date:   Sat Sep 15 10:02:13 2018 +0200

drm/amdgpu: add amdgpu_vm_entries_mask v2

We can't get the mask for the root directory from the number of entries.

So add a new function to avoid that problem.

Best Regards

Rex

________________________________
From: amd-gfx <amd-gfx-bounces-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org><mailto:[email protected]> on behalf of Zhang, Jerry(Junwei) <[email protected]><mailto:[email protected]>
Sent: Tuesday, October 23, 2018 1:12 PM
To: Zhu, Rex; [email protected]<mailto:[email protected]>; Deucher, Alexander; Koenig, Christian
Subject: Re: [PATCH] drm/amdgpu: Fix amdgpu_vm_alloc_pts failed

Quoted 7 lines · Rex Zhu

when the VA address located in the last PD entries, the alloc_pts will faile.

Use the right PD mask instand of hardcode, suggested by jerry.zhang.

Thanks to verify that.
Feel free to add

Also like to get to know some background about these two functions from Christian.
Perhaps we may make it more simple, e.g. merging them together.

Regards,
Jerry

Quoted 11 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +0 -0
index 054633b..3939013 100644
@@ -202,8 +202,11 @@ static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev,
  static uint32_t amdgpu_vm_entries_mask(struct amdgpu_device *adev,
                                      unsigned int level)

drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c static unsigned amdgpu_vm_num_entries(struct amdgpu_device *adev, · line 212

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c +4 -1
  {
+     unsigned shift = amdgpu_vm_level_shift(adev,
+                                            adev->vm_manager.root_level);
+
       if (level <= adev->vm_manager.root_level)
-             return 0xffffffff;
+             return (round_up(adev->vm_manager.max_pfn, 1 << shift) >> shift) - 1;
       else if (level != AMDGPU_VM_PTB)
               return 0x1ff;
       else

_______________________________________________
amd-gfx mailing list
[email protected]<mailto:[email protected]>
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
amd-gfx Info Page - freedesktop.org<https://lists.freedesktop.org/mailman/listinfo/amd-gfx>
lists.freedesktop.org
To see the collection of prior postings to the list, visit the amd-gfx Archives.. Using amd-gfx: To post a message to all the list members, send email to [email protected]<mailto:[email protected]>. You can subscribe to the list, or change your existing subscription, in the sections below.

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

From a68c029e2bc5f60fd26d1b0705fee2be80b6f604 Mon Sep 17 00:00:00 2001
From: Rex Zhu <[email protected]>
Date: Tue, 23 Oct 2018 17:07:12 +0800
Subject: [PATCH] debug: create and map csa buffer

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c    | 8 ++++----
 2 files changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c +2 -2
index 450b0b7..e0d46b9 100644
@@ -1658,7 +1658,7 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
 			adev->ip_blocks[i].status.hw = true;
 
 			/* right after GMC hw init, we create CSA */
-			if (amdgpu_sriov_vf(adev)) {
+//			if (amdgpu_sriov_vf(adev)) {
 				r = amdgpu_allocate_static_csa(adev, &adev->virt.csa_obj,
 								AMDGPU_GEM_DOMAIN_VRAM,
 								AMDGPU_CSA_SIZE);
@@ -1666,7 +1666,7 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
 					DRM_ERROR("allocate CSA failed %d\n", r);
 					return r;
 				}
-			}
+//			}
 		}
 	}
 
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +4 -4
index f2ef9a1..b332262 100644
@@ -977,13 +977,13 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)
 		goto error_vm;
 	}
 
-	if (amdgpu_sriov_vf(adev)) {
+//	if (amdgpu_sriov_vf(adev)) {
 		uint64_t csa_addr = amdgpu_csa_vaddr(adev, 1) & AMDGPU_GMC_HOLE_MASK;
 		r = amdgpu_map_static_csa(adev, &fpriv->vm, adev->virt.csa_obj,
 						&fpriv->csa_va, csa_addr, AMDGPU_CSA_SIZE);
 		if (r)
 			goto error_vm;
-	}
+//	}
 
 	mutex_init(&fpriv->bo_list_lock);
 	idr_init(&fpriv->bo_list_handles);
@@ -1043,13 +1043,13 @@ void amdgpu_driver_postclose_kms(struct drm_device *dev,
 
 	amdgpu_vm_bo_rmv(adev, fpriv->prt_va);
 
-	if (amdgpu_sriov_vf(adev)) {
+//	if (amdgpu_sriov_vf(adev)) {
 		/* TODO: how to handle reserve failure */
 		BUG_ON(amdgpu_bo_reserve(adev->virt.csa_obj, true));
 		amdgpu_vm_bo_rmv(adev, fpriv->csa_va);
 		fpriv->csa_va = NULL;
 		amdgpu_bo_unreserve(adev->virt.csa_obj);
-	}
+//	}
 
 	pasid = fpriv->vm.pasid;
 	pd = amdgpu_bo_ref(fpriv->vm.root.base.bo);
Signature · 1 line
1.9.1

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