Skip to contentSkip to conversation

drm/amdgpu: Use fw vram offset when allocating stolen vga memory.

PATCH In review Yongqiang Sun 3 participants 6 messages Mar 14, 2022

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

PATCH 1/2 drm/amdgpu: Use fw vram offset when allocating stolen vga memory.

[Why]
Memory access violation will happen in case of allocate stolen vga memory with size isn't 0.

[How]
when allocating stolen vga memory, use fw vram offset as the start point instead of hard code value 0.

Change-Id I7c555a6c1fb4b3fa8685753b4bdcbe215f89ea1e
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 31 +++++++++++++++++++------
 1 file changed, 24 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +24 -7
index 41d6f604813d..1f635fdb0395 100644
@@ -1708,6 +1708,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
 	uint64_t gtt_size;
 	int r;
 	u64 vis_vram_limit;
+	u64 memory_offset = adev->mman.fw_vram_usage_start_offset + adev->mman.fw_vram_usage_size;
 
 	mutex_init(&adev->mman.gtt_window_lock);
 
@@ -1774,24 +1775,40 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
 	 * This is used for VGA emulation and pre-OS scanout buffers to
 	 * avoid display artifacts while transitioning between pre-OS
 	 * and driver.  */
-	r = amdgpu_bo_create_kernel_at(adev, 0, adev->mman.stolen_vga_size,
+	r = amdgpu_bo_create_kernel_at(adev,
+					   memory_offset,
+			           adev->mman.stolen_vga_size,
 				       AMDGPU_GEM_DOMAIN_VRAM,
 				       &adev->mman.stolen_vga_memory,
 				       NULL);
 	if (r)
 		return r;
-	r = amdgpu_bo_create_kernel_at(adev, adev->mman.stolen_vga_size,
+
+	memory_offset += adev->mman.stolen_vga_size;
+
+	r = amdgpu_bo_create_kernel_at(adev,
+					   memory_offset,
 				       adev->mman.stolen_extended_size,
 				       AMDGPU_GEM_DOMAIN_VRAM,
 				       &adev->mman.stolen_extended_memory,
 				       NULL);
 	if (r)
 		return r;
-	r = amdgpu_bo_create_kernel_at(adev, adev->mman.stolen_reserved_offset,
-				       adev->mman.stolen_reserved_size,
-				       AMDGPU_GEM_DOMAIN_VRAM,
-				       &adev->mman.stolen_reserved_memory,
-				       NULL);
+
+	memory_offset += adev->mman.stolen_extended_size;
+
+	if (adev->mman.stolen_reserved_offset > memory_offset)
+		r = amdgpu_bo_create_kernel_at(adev, adev->mman.stolen_reserved_offset,
+						   adev->mman.stolen_reserved_size,
+						   AMDGPU_GEM_DOMAIN_VRAM,
+						   &adev->mman.stolen_reserved_memory,
+						   NULL);
+	else if (adev->mman.stolen_reserved_offset + adev->mman.stolen_reserved_size > memory_offset)
+		r = amdgpu_bo_create_kernel_at(adev, memory_offset,
+						adev->mman.stolen_reserved_offset + adev->mman.stolen_reserved_size - memory_offset,
+						   AMDGPU_GEM_DOMAIN_VRAM,
+						   &adev->mman.stolen_reserved_memory,
+						   NULL);
 	if (r)
 		return r;
 
Signature · 1 line
2.25.1
#1 lore raw

PATCH 2/2 drm/amdgpu: Add stolen reserved memory for MI25 SRIOV.

[Why]
MI25 SRIOV guest driver loading failed due to allocate memory overlaps with private memory area.

[How]
1. Allocate stolen reserved memory for MI25 SRIOV specifically to avoid the memory overlap.
2. Move allocate reserve allocation to vbios allocation since both the two functions are doing similar asic type check and no need to have seperate functions.

Change-Id I142127513047a3e81573eb983c510d763b548a24
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 37 ++++++++++++-------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h |  1 -
 drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c  |  1 -
 3 files changed, 18 insertions(+), 21 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +18 -19
index 7c2a9555b7cc..f7f4f00dd2b2 100644
@@ -626,6 +626,11 @@ void amdgpu_gmc_get_vbios_allocations(struct amdgpu_device *adev)
 {
 	unsigned size;
 
+	/* Some ASICs need to reserve a region of video memory to avoid access
+	 * from driver */
+	adev->mman.stolen_reserved_offset = 0;
+	adev->mman.stolen_reserved_size = 0;
+
 	/*
 	 * TODO:
 	 * Currently there is a bug where some memory client outside
@@ -635,11 +640,24 @@ void amdgpu_gmc_get_vbios_allocations(struct amdgpu_device *adev)
 	 * Keep the stolen memory reservation until the while this is not solved.
 	 */
 	switch (adev->asic_type) {
+
 	case CHIP_VEGA10:
+		adev->mman.keep_stolen_vga_memory = true;
+		if (amdgpu_sriov_vf(adev)) {
+			adev->mman.stolen_reserved_offset = 0x100000;
+			adev->mman.stolen_reserved_size = 0x600000;
+		}
+		break;
 	case CHIP_RAVEN:
 	case CHIP_RENOIR:
 		adev->mman.keep_stolen_vga_memory = true;
 		break;
+	case CHIP_YELLOW_CARP:
+		if (amdgpu_discovery == 0) {
+			adev->mman.stolen_reserved_offset = 0x1ffb0000;
+			adev->mman.stolen_reserved_size = 64 * PAGE_SIZE;
+		}
+		break;
 	default:
 		adev->mman.keep_stolen_vga_memory = false;
 		break;
@@ -760,25 +778,6 @@ uint64_t amdgpu_gmc_vram_cpu_pa(struct amdgpu_device *adev, struct amdgpu_bo *bo
 	return amdgpu_bo_gpu_offset(bo) - adev->gmc.vram_start + adev->gmc.aper_base;
 }
 
-void amdgpu_gmc_get_reserved_allocation(struct amdgpu_device *adev)
-{
-	/* Some ASICs need to reserve a region of video memory to avoid access
-	 * from driver */
-	adev->mman.stolen_reserved_offset = 0;
-	adev->mman.stolen_reserved_size = 0;
-
-	switch (adev->asic_type) {
-	case CHIP_YELLOW_CARP:
-		if (amdgpu_discovery == 0) {
-			adev->mman.stolen_reserved_offset = 0x1ffb0000;
-			adev->mman.stolen_reserved_size = 64 * PAGE_SIZE;
-		}
-		break;
-	default:
-		break;
-	}
-}
-
 int amdgpu_gmc_vram_checking(struct amdgpu_device *adev)
 {
 	struct amdgpu_bo *vram_bo = NULL;
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +0 -1
index 93505bb0a36c..032b0313f277 100644
@@ -331,7 +331,6 @@ amdgpu_gmc_set_vm_fault_masks(struct amdgpu_device *adev, int hub_type,
 			      bool enable);
 
 void amdgpu_gmc_get_vbios_allocations(struct amdgpu_device *adev);
-void amdgpu_gmc_get_reserved_allocation(struct amdgpu_device *adev);
 
 void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev);
 uint64_t amdgpu_gmc_vram_mc2pa(struct amdgpu_device *adev, uint64_t mc_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +0 -1
index f60b7bd4dbf5..3c1d440824a7 100644
@@ -948,7 +948,6 @@ static int gmc_v10_0_sw_init(void *handle)
 		return r;
 
 	amdgpu_gmc_get_vbios_allocations(adev);
-	amdgpu_gmc_get_reserved_allocation(adev);
 
 	/* Memory manager */
 	r = amdgpu_bo_init(adev);
Signature · 1 line
2.25.1
#2 lore raw

Re: [PATCH 2/2] drm/amdgpu: Add stolen reserved memory for MI25 SRIOV.

Am 14.03.22 um 19:54 schrieb Yongqiang Sun:

Quoted 36 lines

[Why]
MI25 SRIOV guest driver loading failed due to allocate memory overlaps with private memory area.

[How]
1. Allocate stolen reserved memory for MI25 SRIOV specifically to avoid the memory overlap.
2. Move allocate reserve allocation to vbios allocation since both the two functions are doing similar asic type check and no need to have seperate functions.

Change-Id I142127513047a3e81573eb983c510d763b548a24
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 37 ++++++++++++-------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h |  1 -
  drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c  |  1 -
  3 files changed, 18 insertions(+), 21 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +5 -0
index 7c2a9555b7cc..f7f4f00dd2b2 100644
@@ -626,6 +626,11 @@ void amdgpu_gmc_get_vbios_allocations(struct amdgpu_device *adev)
  {
  	unsigned size;
 
+	/* Some ASICs need to reserve a region of video memory to avoid access
+	 * from driver */
+	adev->mman.stolen_reserved_offset = 0;
+	adev->mman.stolen_reserved_size = 0;
+
  	/*
  	 * TODO:
  	 * Currently there is a bug where some memory client outside

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_get_vbios_allocations(struct amdgpu_device *adev) · line 644

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -0
@@ -635,11 +640,24 @@ void amdgpu_gmc_get_vbios_allocations(struct amdgpu_device *adev)
  	 * Keep the stolen memory reservation until the while this is not solved.
  	 */
  	switch (adev->asic_type) {
+
  	case CHIP_VEGA10:

Please don't add empty lines between switch and case. Good practice is to check your patches with checkpatch.pl before sending it out.

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +6 -0
+		adev->mman.keep_stolen_vga_memory = true;
+		if (amdgpu_sriov_vf(adev)) {
+			adev->mman.stolen_reserved_offset = 0x100000;
+			adev->mman.stolen_reserved_size = 0x600000;
+		}
+		break;

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_get_vbios_allocations(struct amdgpu_device *adev) · line 660

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +6 -0
  	case CHIP_RAVEN:
  	case CHIP_RENOIR:
  		adev->mman.keep_stolen_vga_memory = true;
  		break;
+	case CHIP_YELLOW_CARP:
+		if (amdgpu_discovery == 0) {
+			adev->mman.stolen_reserved_offset = 0x1ffb0000;
+			adev->mman.stolen_reserved_size = 64 * PAGE_SIZE;
+		}
+		break;

That looks like this is somehow mixed up. The stolen memory is for VGA emulation, but under SRIOV we should not have VGA emulation as far as I know.

Alex, what's going on here?

Regards,
Christian.

Quoted 53 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -19
  	default:
  		adev->mman.keep_stolen_vga_memory = false;
  		break;
@@ -760,25 +778,6 @@ uint64_t amdgpu_gmc_vram_cpu_pa(struct amdgpu_device *adev, struct amdgpu_bo *bo
  	return amdgpu_bo_gpu_offset(bo) - adev->gmc.vram_start + adev->gmc.aper_base;
  }
 
-void amdgpu_gmc_get_reserved_allocation(struct amdgpu_device *adev)
-{
-	/* Some ASICs need to reserve a region of video memory to avoid access
-	 * from driver */
-	adev->mman.stolen_reserved_offset = 0;
-	adev->mman.stolen_reserved_size = 0;
-
-	switch (adev->asic_type) {
-	case CHIP_YELLOW_CARP:
-		if (amdgpu_discovery == 0) {
-			adev->mman.stolen_reserved_offset = 0x1ffb0000;
-			adev->mman.stolen_reserved_size = 64 * PAGE_SIZE;
-		}
-		break;
-	default:
-		break;
-	}
-}
-
  int amdgpu_gmc_vram_checking(struct amdgpu_device *adev)
  {
  	struct amdgpu_bo *vram_bo = NULL;
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +0 -1
index 93505bb0a36c..032b0313f277 100644
@@ -331,7 +331,6 @@ amdgpu_gmc_set_vm_fault_masks(struct amdgpu_device *adev, int hub_type,
  			      bool enable);
 
  void amdgpu_gmc_get_vbios_allocations(struct amdgpu_device *adev);
-void amdgpu_gmc_get_reserved_allocation(struct amdgpu_device *adev);
 
  void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev);
  uint64_t amdgpu_gmc_vram_mc2pa(struct amdgpu_device *adev, uint64_t mc_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +0 -1
index f60b7bd4dbf5..3c1d440824a7 100644
@@ -948,7 +948,6 @@ static int gmc_v10_0_sw_init(void *handle)
  		return r;
 
  	amdgpu_gmc_get_vbios_allocations(adev);
-	amdgpu_gmc_get_reserved_allocation(adev);
 
  	/* Memory manager */
  	r = amdgpu_bo_init(adev);
#3 lore raw

Re: [PATCH 2/2] drm/amdgpu: Add stolen reserved memory for MI25 SRIOV.

Quoted 64 lines · Christian König

Am 14.03.22 um 19:54 schrieb Yongqiang Sun:

Quoted 36 lines

[Why]
MI25 SRIOV guest driver loading failed due to allocate memory overlaps with private memory area.

[How]
1. Allocate stolen reserved memory for MI25 SRIOV specifically to avoid the memory overlap.
2. Move allocate reserve allocation to vbios allocation since both the two functions are doing similar asic type check and no need to have seperate functions.

Change-Id I142127513047a3e81573eb983c510d763b548a24
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c | 37 ++++++++++++-------------
  drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h |  1 -
  drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c  |  1 -
  3 files changed, 18 insertions(+), 21 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +5 -0
index 7c2a9555b7cc..f7f4f00dd2b2 100644
@@ -626,6 +626,11 @@ void amdgpu_gmc_get_vbios_allocations(struct amdgpu_device *adev)
  {
      unsigned size;
 
+     /* Some ASICs need to reserve a region of video memory to avoid access
+      * from driver */
+     adev->mman.stolen_reserved_offset = 0;
+     adev->mman.stolen_reserved_size = 0;
+
      /*
       * TODO:
       * Currently there is a bug where some memory client outside

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_get_vbios_allocations(struct amdgpu_device *adev) · line 644

Quoted 5 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +1 -0
@@ -635,11 +640,24 @@ void amdgpu_gmc_get_vbios_allocations(struct amdgpu_device *adev)
       * Keep the stolen memory reservation until the while this is not solved.
       */
      switch (adev->asic_type) {
+
      case CHIP_VEGA10:

Please don't add empty lines between switch and case. Good practice is to check your patches with checkpatch.pl before sending it out.

Quoted 6 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +6 -0
+             adev->mman.keep_stolen_vga_memory = true;
+             if (amdgpu_sriov_vf(adev)) {
+                     adev->mman.stolen_reserved_offset = 0x100000;
+                     adev->mman.stolen_reserved_size = 0x600000;
+             }
+             break;

drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c void amdgpu_gmc_get_vbios_allocations(struct amdgpu_device *adev) · line 660

Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +6 -0
      case CHIP_RAVEN:
      case CHIP_RENOIR:
              adev->mman.keep_stolen_vga_memory = true;
              break;
+     case CHIP_YELLOW_CARP:
+             if (amdgpu_discovery == 0) {
+                     adev->mman.stolen_reserved_offset = 0x1ffb0000;
+                     adev->mman.stolen_reserved_size = 64 * PAGE_SIZE;
+             }
+             break;
Quoted 5 lines

That looks like this is somehow mixed up. The stolen memory is for VGA emulation, but under SRIOV we should not have VGA emulation as far as I know.

Alex, what's going on here?

I suggested calling amdgpu_gmc_get_reserved_allocation() from amdgpu_gmc_get_vbios_allocations() rather calling amdgpu_gmc_get_reserved_allocation() in every gmc file since it handles additional reserved areas used allocated by firmware, etc. My understanding is that there is some additional reserved area set up in the hypervisor that we want reserved in the guest. The idea was to just use stolen_reserved_offset for that similar to what we do for the bring up case for yellow carp.

Alex

Quoted 58 lines

Regards,
Christian.

Quoted 53 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.c +0 -19
      default:
              adev->mman.keep_stolen_vga_memory = false;
              break;
@@ -760,25 +778,6 @@ uint64_t amdgpu_gmc_vram_cpu_pa(struct amdgpu_device *adev, struct amdgpu_bo *bo
      return amdgpu_bo_gpu_offset(bo) - adev->gmc.vram_start + adev->gmc.aper_base;
  }
 
-void amdgpu_gmc_get_reserved_allocation(struct amdgpu_device *adev)
-{
-     /* Some ASICs need to reserve a region of video memory to avoid access
-      * from driver */
-     adev->mman.stolen_reserved_offset = 0;
-     adev->mman.stolen_reserved_size = 0;
-
-     switch (adev->asic_type) {
-     case CHIP_YELLOW_CARP:
-             if (amdgpu_discovery == 0) {
-                     adev->mman.stolen_reserved_offset = 0x1ffb0000;
-                     adev->mman.stolen_reserved_size = 64 * PAGE_SIZE;
-             }
-             break;
-     default:
-             break;
-     }
-}
-
  int amdgpu_gmc_vram_checking(struct amdgpu_device *adev)
  {
      struct amdgpu_bo *vram_bo = NULL;
drivers/gpu/drm/amd/amdgpu/amdgpu_gmc.h +0 -1
index 93505bb0a36c..032b0313f277 100644
@@ -331,7 +331,6 @@ amdgpu_gmc_set_vm_fault_masks(struct amdgpu_device *adev, int hub_type,
                            bool enable);
 
  void amdgpu_gmc_get_vbios_allocations(struct amdgpu_device *adev);
-void amdgpu_gmc_get_reserved_allocation(struct amdgpu_device *adev);
 
  void amdgpu_gmc_init_pdb0(struct amdgpu_device *adev);
  uint64_t amdgpu_gmc_vram_mc2pa(struct amdgpu_device *adev, uint64_t mc_addr);
drivers/gpu/drm/amd/amdgpu/gmc_v10_0.c +0 -1
index f60b7bd4dbf5..3c1d440824a7 100644
@@ -948,7 +948,6 @@ static int gmc_v10_0_sw_init(void *handle)
              return r;
 
      amdgpu_gmc_get_vbios_allocations(adev);
-     amdgpu_gmc_get_reserved_allocation(adev);
 
      /* Memory manager */
      r = amdgpu_bo_init(adev);
#4 lore raw
In reply to Yongqiang Sun

Am 14.03.22 um 19:54 schrieb Yongqiang Sun:

Quoted 7 lines

[Why]
Memory access violation will happen in case of allocate stolen vga memory with size isn't 0.

[How]
when allocating stolen vga memory, use fw vram offset as the start point instead of hard code value 0.

Please stop separating commit message into [Why] and [How], that is not well received everywhere.

Apart from that the patch is a certain NAK, you are messing things quite up here.

Quoted 20 lines
Change-Id I7c555a6c1fb4b3fa8685753b4bdcbe215f89ea1e
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 31 +++++++++++++++++++------
  1 file changed, 24 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -0
index 41d6f604813d..1f635fdb0395 100644
@@ -1708,6 +1708,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
  	uint64_t gtt_size;
  	int r;
  	u64 vis_vram_limit;
+	u64 memory_offset = adev->mman.fw_vram_usage_start_offset + adev->mman.fw_vram_usage_size;
 
  	mutex_init(&adev->mman.gtt_window_lock);
 

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c int amdgpu_ttm_init(struct amdgpu_device *adev) · line 1780

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -1
@@ -1774,24 +1775,40 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
  	 * This is used for VGA emulation and pre-OS scanout buffers to
  	 * avoid display artifacts while transitioning between pre-OS
  	 * and driver.  */
-	r = amdgpu_bo_create_kernel_at(adev, 0, adev->mman.stolen_vga_size,
+	r = amdgpu_bo_create_kernel_at(adev,
+					   memory_offset,
+			           adev->mman.stolen_vga_size,

That is certainly incorrect. See function amdgpu_ttm_fw_reserve_vram_init().

The stolen VGA buffer always started at offset 0 and is independent of the range defined by fw_vram_usage_start_offset and fw_vram_usage_size.

Regards,
Christian.

Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +20 -6
  				       AMDGPU_GEM_DOMAIN_VRAM,
  				       &adev->mman.stolen_vga_memory,
  				       NULL);
  	if (r)
  		return r;
-	r = amdgpu_bo_create_kernel_at(adev, adev->mman.stolen_vga_size,
+
+	memory_offset += adev->mman.stolen_vga_size;
+
+	r = amdgpu_bo_create_kernel_at(adev,
+					   memory_offset,
  				       adev->mman.stolen_extended_size,
  				       AMDGPU_GEM_DOMAIN_VRAM,
  				       &adev->mman.stolen_extended_memory,
  				       NULL);
  	if (r)
  		return r;
-	r = amdgpu_bo_create_kernel_at(adev, adev->mman.stolen_reserved_offset,
-				       adev->mman.stolen_reserved_size,
-				       AMDGPU_GEM_DOMAIN_VRAM,
-				       &adev->mman.stolen_reserved_memory,
-				       NULL);
+
+	memory_offset += adev->mman.stolen_extended_size;
+
+	if (adev->mman.stolen_reserved_offset > memory_offset)
+		r = amdgpu_bo_create_kernel_at(adev, adev->mman.stolen_reserved_offset,
+						   adev->mman.stolen_reserved_size,
+						   AMDGPU_GEM_DOMAIN_VRAM,
+						   &adev->mman.stolen_reserved_memory,
+						   NULL);
+	else if (adev->mman.stolen_reserved_offset + adev->mman.stolen_reserved_size > memory_offset)
+		r = amdgpu_bo_create_kernel_at(adev, memory_offset,
+						adev->mman.stolen_reserved_offset + adev->mman.stolen_reserved_size - memory_offset,
+						   AMDGPU_GEM_DOMAIN_VRAM,
+						   &adev->mman.stolen_reserved_memory,
+						   NULL);
  	if (r)
  		return r;
 
#5 lore raw
Quoted 46 lines · Christian König

Am 14.03.22 um 19:54 schrieb Yongqiang Sun:

Quoted 7 lines

[Why]
Memory access violation will happen in case of allocate stolen vga memory with size isn't 0.

[How]
when allocating stolen vga memory, use fw vram offset as the start point instead of hard code value 0.

Please stop separating commit message into [Why] and [How], that is not well received everywhere.

Apart from that the patch is a certain NAK, you are messing things quite up here.

Quoted 20 lines
Change-Id I7c555a6c1fb4b3fa8685753b4bdcbe215f89ea1e
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 31 +++++++++++++++++++------
  1 file changed, 24 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +1 -0
index 41d6f604813d..1f635fdb0395 100644
@@ -1708,6 +1708,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
      uint64_t gtt_size;
      int r;
      u64 vis_vram_limit;
+     u64 memory_offset = adev->mman.fw_vram_usage_start_offset + adev->mman.fw_vram_usage_size;
 
      mutex_init(&adev->mman.gtt_window_lock);
 

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c int amdgpu_ttm_init(struct amdgpu_device *adev) · line 1780

Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -1
@@ -1774,24 +1775,40 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
       * This is used for VGA emulation and pre-OS scanout buffers to
       * avoid display artifacts while transitioning between pre-OS
       * and driver.  */
-     r = amdgpu_bo_create_kernel_at(adev, 0, adev->mman.stolen_vga_size,
+     r = amdgpu_bo_create_kernel_at(adev,
+                                        memory_offset,
+                                adev->mman.stolen_vga_size,

That is certainly incorrect. See function amdgpu_ttm_fw_reserve_vram_init().

Quoted 3 lines

The stolen VGA buffer always started at offset 0 and is independent of the range defined by fw_vram_usage_start_offset and fw_vram_usage_size.

Yeah these are separate ranges. I just had a chat with Yongqiang and there was some confusion around this, but this patch can be dropped.

Alex

Quoted 44 lines

Regards,
Christian.

Quoted 40 lines
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +20 -6
                                     AMDGPU_GEM_DOMAIN_VRAM,
                                     &adev->mman.stolen_vga_memory,
                                     NULL);
      if (r)
              return r;
-     r = amdgpu_bo_create_kernel_at(adev, adev->mman.stolen_vga_size,
+
+     memory_offset += adev->mman.stolen_vga_size;
+
+     r = amdgpu_bo_create_kernel_at(adev,
+                                        memory_offset,
                                     adev->mman.stolen_extended_size,
                                     AMDGPU_GEM_DOMAIN_VRAM,
                                     &adev->mman.stolen_extended_memory,
                                     NULL);
      if (r)
              return r;
-     r = amdgpu_bo_create_kernel_at(adev, adev->mman.stolen_reserved_offset,
-                                    adev->mman.stolen_reserved_size,
-                                    AMDGPU_GEM_DOMAIN_VRAM,
-                                    &adev->mman.stolen_reserved_memory,
-                                    NULL);
+
+     memory_offset += adev->mman.stolen_extended_size;
+
+     if (adev->mman.stolen_reserved_offset > memory_offset)
+             r = amdgpu_bo_create_kernel_at(adev, adev->mman.stolen_reserved_offset,
+                                                adev->mman.stolen_reserved_size,
+                                                AMDGPU_GEM_DOMAIN_VRAM,
+                                                &adev->mman.stolen_reserved_memory,
+                                                NULL);
+     else if (adev->mman.stolen_reserved_offset + adev->mman.stolen_reserved_size > memory_offset)
+             r = amdgpu_bo_create_kernel_at(adev, memory_offset,
+                                             adev->mman.stolen_reserved_offset + adev->mman.stolen_reserved_size - memory_offset,
+                                                AMDGPU_GEM_DOMAIN_VRAM,
+                                                &adev->mman.stolen_reserved_memory,
+                                                NULL);
      if (r)
              return r;