Skip to contentSkip to conversation

amd/amdkfd:fix overflowed constant in the function svm_migrate_copy_to_ram

PATCH In review Jesse Zhang 2 participants 3 messages May 30, 2024 – May 31, 2024

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

PATCH 4/8 amd/amdkfd:fix overflowed constant in the function svm_migrate_copy_to_ram

If the svm migration copy memory gart fails or the dma mapping page fails for the first time. But the variable i is still 0, and executing i-- will overflow.

---
 drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +2 -1
index 8ee3d07ffbdf..3620eabf13c7 100644
@@ -650,9 +650,10 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange,
 out_oom:
 	if (r) {
 		pr_debug("failed %d copy to ram\n", r);
-		while (i--) {
+		while (i) {
 			svm_migrate_put_sys_page(dst[i]);
 			migrate->dst[i] = 0;
+			i--;
 		}
 	}
 
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Am 30.05.24 um 05:48 schrieb Jesse Zhang:

Quoted 13 lines

If the svm migration copy memory gart fails or the dma mapping page fails for the first time. But the variable i is still 0, and executing i-- will overflow.

---
  drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +0 -0
index 8ee3d07ffbdf..3620eabf13c7 100644

drivers/gpu/drm/amd/amdkfd/kfd_migrate.c svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange, · line 656

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +2 -1
@@ -650,9 +650,10 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange,
  out_oom:
  	if (r) {
  		pr_debug("failed %d copy to ram\n", r);
-		while (i--) {
+		while (i) {
  			svm_migrate_put_sys_page(dst[i]);
  			migrate->dst[i] = 0;
+			i--;

That looks incorrect to me.

"i" is usually the entry which failed and doesn't need to cleanup. So using "while (i---) ...." is a very common and correct way to clean things up.

With the code changed as above 0 for example would never be cleaned up.

Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +0 -0
  		}
  	}
 
#2 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Hi Christian and Felix

Thanks for your comment, we will ignore these similar Coverity warnings.

Regards
Jesse

-----Original Message-----
From: Koenig, Christian <[email protected]>
Sent: Thursday, May 30, 2024 10:11 PM
To: Zhang, Jesse(Jie) <[email protected]>; [email protected]
Cc: Deucher, Alexander <[email protected]>; Kuehling, Felix <[email protected]>; Kim, Jonathan <[email protected]>; Huang, Tim <[email protected]>
Subject: Re: [PATCH 4/8] amd/amdkfd:fix overflowed constant in the function svm_migrate_copy_to_ram

Am 30.05.24 um 05:48 schrieb Jesse Zhang:

Quoted 14 lines

If the svm migration copy memory gart fails or the dma mapping page fails for the first time. But the variable i is still 0, and executing i-- will overflow.

---
  drivers/gpu/drm/amd/amdkfd/kfd_migrate.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +0 -0
index 8ee3d07ffbdf..3620eabf13c7 100644

drivers/gpu/drm/amd/amdkfd/kfd_migrate.c svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange, · line 656

Quoted 8 lines
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +2 -1
@@ -650,9 +650,10 @@ svm_migrate_copy_to_ram(struct amdgpu_device *adev, struct svm_range *prange,
  out_oom:
      if (r) {
              pr_debug("failed %d copy to ram\n", r);
-             while (i--) {
+             while (i) {
                      svm_migrate_put_sys_page(dst[i]);
                      migrate->dst[i] = 0;
+                     i--;

That looks incorrect to me.

"i" is usually the entry which failed and doesn't need to cleanup. So using "while (i---) ...." is a very common and correct way to clean things up.

With the code changed as above 0 for example would never be cleaned up.

Christian.

Quoted 3 lines
drivers/gpu/drm/amd/amdkfd/kfd_migrate.c +0 -0
              }
      }