Skip to contentSkip to conversation

drm/amdgpu: Use kvmalloc for allocating UVD/VCE/VCN BO backup memory

PATCH In review Michel Dänzer 2 participants 2 messages Aug 3, 2018 1 message not in the archive

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

PATCH 1/1 drm/amdgpu: Use kvmalloc for allocating UVD/VCE/VCN BO backup memory

From: Michel Dänzer <[email protected]>

The allocated size can be (at least?) as large as megabytes, and there's no need for it to be physically contiguous.

May avoid spurious failures to initialize / suspend the corresponding block while there's memory pressure.

Bugzilla: https://bugs.freedesktop.org/107432

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 6 +++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 6 +++---
 drivers/gpu/drm/amd/amdgpu/vce_v4_0.c   | 4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +3 -3
index 632fa5980ff4..5564e5bb03d6 100644
@@ -311,7 +311,7 @@ int amdgpu_uvd_sw_fini(struct amdgpu_device *adev)
 	for (j = 0; j < adev->uvd.num_uvd_inst; ++j) {
 		if (adev->uvd.harvest_config & (1 << j))
 			continue;
-		kfree(adev->uvd.inst[j].saved_bo);
+		kvfree(adev->uvd.inst[j].saved_bo);
 
 		amdgpu_bo_free_kernel(&adev->uvd.inst[j].vcpu_bo,
 				      &adev->uvd.inst[j].gpu_addr,
@@ -354,7 +354,7 @@ int amdgpu_uvd_suspend(struct amdgpu_device *adev)
 		size = amdgpu_bo_size(adev->uvd.inst[j].vcpu_bo);
 		ptr = adev->uvd.inst[j].cpu_addr;
 
-		adev->uvd.inst[j].saved_bo = kmalloc(size, GFP_KERNEL);
+		adev->uvd.inst[j].saved_bo = kvmalloc(size, GFP_KERNEL);
 		if (!adev->uvd.inst[j].saved_bo)
 			return -ENOMEM;
 
@@ -380,7 +380,7 @@ int amdgpu_uvd_resume(struct amdgpu_device *adev)
 
 		if (adev->uvd.inst[i].saved_bo != NULL) {
 			memcpy_toio(ptr, adev->uvd.inst[i].saved_bo, size);
-			kfree(adev->uvd.inst[i].saved_bo);
+			kvfree(adev->uvd.inst[i].saved_bo);
 			adev->uvd.inst[i].saved_bo = NULL;
 		} else {
 			const struct common_firmware_header *hdr;
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3 -3
index 798648a19710..ec2b4c3f228b 100644
@@ -129,7 +129,7 @@ int amdgpu_vcn_sw_fini(struct amdgpu_device *adev)
 {
 	int i;
 
-	kfree(adev->vcn.saved_bo);
+	kvfree(adev->vcn.saved_bo);
 
 	amdgpu_bo_free_kernel(&adev->vcn.vcpu_bo,
 			      &adev->vcn.gpu_addr,
@@ -160,7 +160,7 @@ int amdgpu_vcn_suspend(struct amdgpu_device *adev)
 	size = amdgpu_bo_size(adev->vcn.vcpu_bo);
 	ptr = adev->vcn.cpu_addr;
 
-	adev->vcn.saved_bo = kmalloc(size, GFP_KERNEL);
+	adev->vcn.saved_bo = kvmalloc(size, GFP_KERNEL);
 	if (!adev->vcn.saved_bo)
 		return -ENOMEM;
 
@@ -182,7 +182,7 @@ int amdgpu_vcn_resume(struct amdgpu_device *adev)
 
 	if (adev->vcn.saved_bo != NULL) {
 		memcpy_toio(ptr, adev->vcn.saved_bo, size);
-		kfree(adev->vcn.saved_bo);
+		kvfree(adev->vcn.saved_bo);
 		adev->vcn.saved_bo = NULL;
 	} else {
 		const struct common_firmware_header *hdr;
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +2 -2
index 65f8860169e9..d5ce6ed9ffe6 100644
@@ -438,7 +438,7 @@ static int vce_v4_0_sw_init(void *handle)
 		const struct common_firmware_header *hdr;
 		unsigned size = amdgpu_bo_size(adev->vce.vcpu_bo);
 
-		adev->vce.saved_bo = kmalloc(size, GFP_KERNEL);
+		adev->vce.saved_bo = kvmalloc(size, GFP_KERNEL);
 		if (!adev->vce.saved_bo)
 			return -ENOMEM;
 
@@ -490,7 +490,7 @@ static int vce_v4_0_sw_fini(void *handle)
 	amdgpu_virt_free_mm_table(adev);
 
 	if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
-		kfree(adev->vce.saved_bo);
+		kvfree(adev->vce.saved_bo);
 		adev->vce.saved_bo = NULL;
 	}
 
Signature · 6 lines
2.18.0

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

A message that is not in the archive (sent off-list or not yet received): 20180803152632.3871-1-michel-otUistvHUpPR7s880joybQ@public.gmane.org

Reviewed-by
#2 lore raw

Am 03.08.2018 um 17:26 schrieb Michel Dänzer:

Quoted 10 lines

From: Michel Dänzer <[email protected]>

The allocated size can be (at least?) as large as megabytes, and there's no need for it to be physically contiguous.

May avoid spurious failures to initialize / suspend the corresponding block while there's memory pressure.

Bugzilla: https://bugs.freedesktop.org/107432

Quoted 82 lines
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c | 6 +++---
  drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c | 6 +++---
  drivers/gpu/drm/amd/amdgpu/vce_v4_0.c   | 4 ++--
  3 files changed, 8 insertions(+), 8 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_uvd.c +3 -3
index 632fa5980ff4..5564e5bb03d6 100644
@@ -311,7 +311,7 @@ int amdgpu_uvd_sw_fini(struct amdgpu_device *adev)
  	for (j = 0; j < adev->uvd.num_uvd_inst; ++j) {
  		if (adev->uvd.harvest_config & (1 << j))
  			continue;
-		kfree(adev->uvd.inst[j].saved_bo);
+		kvfree(adev->uvd.inst[j].saved_bo);
 
  		amdgpu_bo_free_kernel(&adev->uvd.inst[j].vcpu_bo,
  				      &adev->uvd.inst[j].gpu_addr,
@@ -354,7 +354,7 @@ int amdgpu_uvd_suspend(struct amdgpu_device *adev)
  		size = amdgpu_bo_size(adev->uvd.inst[j].vcpu_bo);
  		ptr = adev->uvd.inst[j].cpu_addr;
 
-		adev->uvd.inst[j].saved_bo = kmalloc(size, GFP_KERNEL);
+		adev->uvd.inst[j].saved_bo = kvmalloc(size, GFP_KERNEL);
  		if (!adev->uvd.inst[j].saved_bo)
  			return -ENOMEM;
 
@@ -380,7 +380,7 @@ int amdgpu_uvd_resume(struct amdgpu_device *adev)
 
  		if (adev->uvd.inst[i].saved_bo != NULL) {
  			memcpy_toio(ptr, adev->uvd.inst[i].saved_bo, size);
-			kfree(adev->uvd.inst[i].saved_bo);
+			kvfree(adev->uvd.inst[i].saved_bo);
  			adev->uvd.inst[i].saved_bo = NULL;
  		} else {
  			const struct common_firmware_header *hdr;
drivers/gpu/drm/amd/amdgpu/amdgpu_vcn.c +3 -3
index 798648a19710..ec2b4c3f228b 100644
@@ -129,7 +129,7 @@ int amdgpu_vcn_sw_fini(struct amdgpu_device *adev)
  {
  	int i;
 
-	kfree(adev->vcn.saved_bo);
+	kvfree(adev->vcn.saved_bo);
 
  	amdgpu_bo_free_kernel(&adev->vcn.vcpu_bo,
  			      &adev->vcn.gpu_addr,
@@ -160,7 +160,7 @@ int amdgpu_vcn_suspend(struct amdgpu_device *adev)
  	size = amdgpu_bo_size(adev->vcn.vcpu_bo);
  	ptr = adev->vcn.cpu_addr;
 
-	adev->vcn.saved_bo = kmalloc(size, GFP_KERNEL);
+	adev->vcn.saved_bo = kvmalloc(size, GFP_KERNEL);
  	if (!adev->vcn.saved_bo)
  		return -ENOMEM;
 
@@ -182,7 +182,7 @@ int amdgpu_vcn_resume(struct amdgpu_device *adev)
 
  	if (adev->vcn.saved_bo != NULL) {
  		memcpy_toio(ptr, adev->vcn.saved_bo, size);
-		kfree(adev->vcn.saved_bo);
+		kvfree(adev->vcn.saved_bo);
  		adev->vcn.saved_bo = NULL;
  	} else {
  		const struct common_firmware_header *hdr;
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +1 -1
index 65f8860169e9..d5ce6ed9ffe6 100644
@@ -438,7 +438,7 @@ static int vce_v4_0_sw_init(void *handle)
  		const struct common_firmware_header *hdr;
  		unsigned size = amdgpu_bo_size(adev->vce.vcpu_bo);
 
-		adev->vce.saved_bo = kmalloc(size, GFP_KERNEL);
+		adev->vce.saved_bo = kvmalloc(size, GFP_KERNEL);
  		if (!adev->vce.saved_bo)
  			return -ENOMEM;
 

drivers/gpu/drm/amd/amdgpu/vce_v4_0.c static int vce_v4_0_sw_fini(void *handle) · line 496

Quoted 8 lines
drivers/gpu/drm/amd/amdgpu/vce_v4_0.c +1 -1
@@ -490,7 +490,7 @@ static int vce_v4_0_sw_fini(void *handle)
  	amdgpu_virt_free_mm_table(adev);
 
  	if (adev->firmware.load_type == AMDGPU_FW_LOAD_PSP) {
-		kfree(adev->vce.saved_bo);
+		kvfree(adev->vce.saved_bo);
  		adev->vce.saved_bo = NULL;
  	}
 

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