Skip to contentSkip to conversation

drm/amdgpu: fix AGP addressing when GART is not at 0

PATCH In review Alex Deucher 4 participants 6 messages Nov 10, 2023 – Nov 16, 2023

Subsystems (2)
lore
Share & tools
lore

Alex Deucher

author maintainer
#0 lore raw

PATCH 1/1 drm/amdgpu: fix AGP addressing when GART is not at 0

This worked by luck if the GART aperture ended up at 0. When we ended up moving GART on some chips, the GART aperture ended up offsetting the the AGP address since the resource->start is a GART offset, not an MC address. Fix this by moving the AGP address setup into amdgpu_bo_gpu_offset_no_check().

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 10 +++++++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  4 +---
 2 files changed, 8 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +7 -3
index cef920a93924..1b3e97522838 100644
@@ -1527,10 +1527,14 @@ u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo)
 u64 amdgpu_bo_gpu_offset_no_check(struct amdgpu_bo *bo)
 {
 	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
-	uint64_t offset;
+	uint64_t offset, addr;
 
-	offset = (bo->tbo.resource->start << PAGE_SHIFT) +
-		 amdgpu_ttm_domain_start(adev, bo->tbo.resource->mem_type);
+	addr = amdgpu_gmc_agp_addr(&bo->tbo);
+	if (addr != AMDGPU_BO_INVALID_OFFSET)
+		offset = addr;
+	else
+		offset = (bo->tbo.resource->start << PAGE_SHIFT) +
+			amdgpu_ttm_domain_start(adev, bo->tbo.resource->mem_type);
 
 	return amdgpu_gmc_sign_extend(offset);
 }
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -3
index 05991c5c8ddb..ab4a762aed5b 100644
@@ -959,10 +959,8 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo)
 		return 0;
 
 	addr = amdgpu_gmc_agp_addr(bo);
-	if (addr != AMDGPU_BO_INVALID_OFFSET) {
-		bo->resource->start = addr >> PAGE_SHIFT;
+	if (addr != AMDGPU_BO_INVALID_OFFSET)
 		return 0;
-	}
 
 	/* allocate GART space */
 	placement.num_placement = 1;
Signature · 1 line
2.41.0
maintainer
#1 lore raw

Am 10.11.23 um 15:47 schrieb Alex Deucher:

Quoted 20 lines

This worked by luck if the GART aperture ended up at 0. When we ended up moving GART on some chips, the GART aperture ended up offsetting the the AGP address since the resource->start is a GART offset, not an MC address. Fix this by moving the AGP address setup into amdgpu_bo_gpu_offset_no_check().

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 10 +++++++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  4 +---
  2 files changed, 8 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +0 -0
index cef920a93924..1b3e97522838 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo) · line 1532

Quoted 9 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +2 -3
@@ -1527,10 +1527,14 @@ u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo)
  u64 amdgpu_bo_gpu_offset_no_check(struct amdgpu_bo *bo)
  {
  	struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
-	uint64_t offset;
+	uint64_t offset, addr;
 
-	offset = (bo->tbo.resource->start << PAGE_SHIFT) +
-		 amdgpu_ttm_domain_start(adev, bo->tbo.resource->mem_type);
+	addr = amdgpu_gmc_agp_addr(&bo->tbo);

IIRC you must check bo->tbo.resource->mem_type before calling amdgpu_gmc_agp_addr().

Regards,
Christian.

Quoted 24 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +5 -0
+	if (addr != AMDGPU_BO_INVALID_OFFSET)
+		offset = addr;
+	else
+		offset = (bo->tbo.resource->start << PAGE_SHIFT) +
+			amdgpu_ttm_domain_start(adev, bo->tbo.resource->mem_type);
 
  	return amdgpu_gmc_sign_extend(offset);
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -3
index 05991c5c8ddb..ab4a762aed5b 100644
@@ -959,10 +959,8 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo)
  		return 0;
 
  	addr = amdgpu_gmc_agp_addr(bo);
-	if (addr != AMDGPU_BO_INVALID_OFFSET) {
-		bo->resource->start = addr >> PAGE_SHIFT;
+	if (addr != AMDGPU_BO_INVALID_OFFSET)
  		return 0;
-	}
 
  	/* allocate GART space */
  	placement.num_placement = 1;
#2 lore raw
Quoted 28 lines · Christian König

Am 10.11.23 um 15:47 schrieb Alex Deucher:

Quoted 26 lines

This worked by luck if the GART aperture ended up at 0. When we ended up moving GART on some chips, the GART aperture ended up offsetting the the AGP address since the resource->start is a GART offset, not an MC address. Fix this by moving the AGP address setup into amdgpu_bo_gpu_offset_no_check().

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 10 +++++++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  4 +---
  2 files changed, 8 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
index cef920a93924..1b3e97522838 100644
@@ -1527,10 +1527,14 @@ u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo)
  u64 amdgpu_bo_gpu_offset_no_check(struct amdgpu_bo *bo)
  {
      struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
-     uint64_t offset;
+     uint64_t offset, addr;
 
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo) · line 1532

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -2
-     offset = (bo->tbo.resource->start << PAGE_SHIFT) +
-              amdgpu_ttm_domain_start(adev, bo->tbo.resource->mem_type);
+     addr = amdgpu_gmc_agp_addr(&bo->tbo);

IIRC you must check bo->tbo.resource->mem_type before calling amdgpu_gmc_agp_addr().

Yes, this was fixed in v2.

Alex

Quoted 29 lines

Regards,
Christian.

Quoted 24 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +5 -0
+     if (addr != AMDGPU_BO_INVALID_OFFSET)
+             offset = addr;
+     else
+             offset = (bo->tbo.resource->start << PAGE_SHIFT) +
+                     amdgpu_ttm_domain_start(adev, bo->tbo.resource->mem_type);
 
      return amdgpu_gmc_sign_extend(offset);
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -3
index 05991c5c8ddb..ab4a762aed5b 100644
@@ -959,10 +959,8 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo)
              return 0;
 
      addr = amdgpu_gmc_agp_addr(bo);
-     if (addr != AMDGPU_BO_INVALID_OFFSET) {
-             bo->resource->start = addr >> PAGE_SHIFT;
+     if (addr != AMDGPU_BO_INVALID_OFFSET)
              return 0;
-     }
 
      /* allocate GART space */
      placement.num_placement = 1;
#3 lore raw

[AMD Official Use Only - General]

Ping... this patch seems still not merged.

Best Regards,
Yifan

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Monday, November 13, 2023 2:13 AM
To: Koenig, Christian <[email protected]>
Cc: Deucher, Alexander <[email protected]>; [email protected]; Zhang, Yifan <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix AGP addressing when GART is not at 0

Quoted 29 lines · Christian König

Am 10.11.23 um 15:47 schrieb Alex Deucher:

Quoted 27 lines

This worked by luck if the GART aperture ended up at 0. When we ended up moving GART on some chips, the GART aperture ended up offsetting the the AGP address since the resource->start is a GART offset, not an MC address. Fix this by moving the AGP address setup into amdgpu_bo_gpu_offset_no_check().

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 10 +++++++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  4 +---
  2 files changed, 8 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
index cef920a93924..1b3e97522838 100644
@@ -1527,10 +1527,14 @@ u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo)
  u64 amdgpu_bo_gpu_offset_no_check(struct amdgpu_bo *bo)
  {
      struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
-     uint64_t offset;
+     uint64_t offset, addr;
 
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo) · line 1532

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -2
-     offset = (bo->tbo.resource->start << PAGE_SHIFT) +
-              amdgpu_ttm_domain_start(adev, bo->tbo.resource->mem_type);
+     addr = amdgpu_gmc_agp_addr(&bo->tbo);

IIRC you must check bo->tbo.resource->mem_type before calling amdgpu_gmc_agp_addr().

Yes, this was fixed in v2.

Alex

Quoted 31 lines

Regards,
Christian.

Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +6 -0
+     if (addr != AMDGPU_BO_INVALID_OFFSET)
+             offset = addr;
+     else
+             offset = (bo->tbo.resource->start << PAGE_SHIFT) +
+                     amdgpu_ttm_domain_start(adev,
+ bo->tbo.resource->mem_type);
 
      return amdgpu_gmc_sign_extend(offset);
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -3
index 05991c5c8ddb..ab4a762aed5b 100644
@@ -959,10 +959,8 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo)
              return 0;
 
      addr = amdgpu_gmc_agp_addr(bo);
-     if (addr != AMDGPU_BO_INVALID_OFFSET) {
-             bo->resource->start = addr >> PAGE_SHIFT;
+     if (addr != AMDGPU_BO_INVALID_OFFSET)
              return 0;
-     }
 
      /* allocate GART space */
      placement.num_placement = 1;
#4 lore raw
Quoted 5 lines · Yifan

[AMD Official Use Only - General]

Ping... this patch seems still not merged.

Can you confirm it fixes the AGP issues you saw?

Alex

Quoted 82 lines

Best Regards,
Yifan

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Monday, November 13, 2023 2:13 AM
To: Koenig, Christian <[email protected]>
Cc: Deucher, Alexander <[email protected]>; [email protected]; Zhang, Yifan <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix AGP addressing when GART is not at 0

Quoted 29 lines · Christian König

Am 10.11.23 um 15:47 schrieb Alex Deucher:

Quoted 27 lines

This worked by luck if the GART aperture ended up at 0. When we ended up moving GART on some chips, the GART aperture ended up offsetting the the AGP address since the resource->start is a GART offset, not an MC address. Fix this by moving the AGP address setup into amdgpu_bo_gpu_offset_no_check().

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 10 +++++++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  4 +---
  2 files changed, 8 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
index cef920a93924..1b3e97522838 100644
@@ -1527,10 +1527,14 @@ u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo)
  u64 amdgpu_bo_gpu_offset_no_check(struct amdgpu_bo *bo)
  {
      struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
-     uint64_t offset;
+     uint64_t offset, addr;
 
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo) · line 1532

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -2
-     offset = (bo->tbo.resource->start << PAGE_SHIFT) +
-              amdgpu_ttm_domain_start(adev, bo->tbo.resource->mem_type);
+     addr = amdgpu_gmc_agp_addr(&bo->tbo);

IIRC you must check bo->tbo.resource->mem_type before calling amdgpu_gmc_agp_addr().

Yes, this was fixed in v2.

Alex

Quoted 31 lines

Regards,
Christian.

Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +6 -0
+     if (addr != AMDGPU_BO_INVALID_OFFSET)
+             offset = addr;
+     else
+             offset = (bo->tbo.resource->start << PAGE_SHIFT) +
+                     amdgpu_ttm_domain_start(adev,
+ bo->tbo.resource->mem_type);
 
      return amdgpu_gmc_sign_extend(offset);
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -3
index 05991c5c8ddb..ab4a762aed5b 100644
@@ -959,10 +959,8 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo)
              return 0;
 
      addr = amdgpu_gmc_agp_addr(bo);
-     if (addr != AMDGPU_BO_INVALID_OFFSET) {
-             bo->resource->start = addr >> PAGE_SHIFT;
+     if (addr != AMDGPU_BO_INVALID_OFFSET)
              return 0;
-     }
 
      /* allocate GART space */
      placement.num_placement = 1;
#5 lore raw

[AMD Official Use Only - General]

Yes, it fixes regressions in KFDTest introduced by this commit ("b93ed51c32ca drm/amdgpu: fix AGP init order"),

e.g. KFDMemoryTest.MemoryRegister failure:

fault addr 0x00008084575a6000 is calculated by (gart_start + AGP aperture mc addr) wrongly.

[   46.662856] amdgpu 0000:c2:00.0: amdgpu: [gfxhub] page fault (src_id:0 ring:169 vmid:0 pasid:0, for process  pid 0 thread  pid 0)
[   46.662890] amdgpu 0000:c2:00.0: amdgpu:   in page starting at address 0x00008084575a6000 from client 10
[   46.662909] amdgpu 0000:c2:00.0: amdgpu: GCVM_L2_PROTECTION_FAULT_STATUS:0x00040B52
[   46.662923] amdgpu 0000:c2:00.0: amdgpu:      Faulty UTCL2 client ID: CPC (0x5)
[   46.662936] amdgpu 0000:c2:00.0: amdgpu:      MORE_FAULTS: 0x0
[   46.662947] amdgpu 0000:c2:00.0: amdgpu:      WALKER_ERROR: 0x1
[   46.662957] amdgpu 0000:c2:00.0: amdgpu:      PERMISSION_FAULTS: 0x5
[   46.662968] amdgpu 0000:c2:00.0: amdgpu:      MAPPING_ERROR: 0x1
[   46.662979] amdgpu 0000:c2:00.0: amdgpu:      RW: 0x1

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Thursday, November 16, 2023 10:26 PM
To: Zhang, Yifan <[email protected]>
Cc: Koenig, Christian <[email protected]>; Deucher, Alexander <[email protected]>; [email protected]; Zhang, Jesse(Jie) <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix AGP addressing when GART is not at 0

Quoted 5 lines · Yifan

[AMD Official Use Only - General]

Ping... this patch seems still not merged.

Can you confirm it fixes the AGP issues you saw?

Alex

Quoted 85 lines

Best Regards,
Yifan

-----Original Message-----
From: Alex Deucher <[email protected]>
Sent: Monday, November 13, 2023 2:13 AM
To: Koenig, Christian <[email protected]>
Cc: Deucher, Alexander <[email protected]>; [email protected]; Zhang, Yifan <[email protected]>; Zhang, Jesse(Jie) <[email protected]>
Subject: Re: [PATCH] drm/amdgpu: fix AGP addressing when GART is not at 0

Quoted 29 lines · Christian König

Am 10.11.23 um 15:47 schrieb Alex Deucher:

Quoted 27 lines

This worked by luck if the GART aperture ended up at 0. When we ended up moving GART on some chips, the GART aperture ended up offsetting the the AGP address since the resource->start is a GART offset, not an MC address. Fix this by moving the AGP address setup into amdgpu_bo_gpu_offset_no_check().

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_object.c | 10 +++++++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  4 +---
  2 files changed, 8 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -1
index cef920a93924..1b3e97522838 100644
@@ -1527,10 +1527,14 @@ u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo)
  u64 amdgpu_bo_gpu_offset_no_check(struct amdgpu_bo *bo)
  {
      struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
-     uint64_t offset;
+     uint64_t offset, addr;
 
Quoted 6 lines

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c u64 amdgpu_bo_gpu_offset(struct amdgpu_bo *bo) · line 1532

Quoted 3 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +1 -2
-     offset = (bo->tbo.resource->start << PAGE_SHIFT) +
-              amdgpu_ttm_domain_start(adev, bo->tbo.resource->mem_type);
+     addr = amdgpu_gmc_agp_addr(&bo->tbo);

IIRC you must check bo->tbo.resource->mem_type before calling amdgpu_gmc_agp_addr().

Yes, this was fixed in v2.

Alex

Quoted 31 lines

Regards,
Christian.

Quoted 26 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_object.c +6 -0
+     if (addr != AMDGPU_BO_INVALID_OFFSET)
+             offset = addr;
+     else
+             offset = (bo->tbo.resource->start << PAGE_SHIFT) +
+                     amdgpu_ttm_domain_start(adev,
+ bo->tbo.resource->mem_type);
 
      return amdgpu_gmc_sign_extend(offset);
  }
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -3
index 05991c5c8ddb..ab4a762aed5b 100644
@@ -959,10 +959,8 @@ int amdgpu_ttm_alloc_gart(struct ttm_buffer_object *bo)
              return 0;
 
      addr = amdgpu_gmc_agp_addr(bo);
-     if (addr != AMDGPU_BO_INVALID_OFFSET) {
-             bo->resource->start = addr >> PAGE_SHIFT;
+     if (addr != AMDGPU_BO_INVALID_OFFSET)
              return 0;
-     }
 
      /* allocate GART space */
      placement.num_placement = 1;