Skip to contentSkip to conversation

drm/amdgpu: Fix vram_usage underflow

PATCH In review [email protected] 3 participants 5 messages Oct 14, 2025

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

PATCH 1/1 drm/amdgpu: Fix vram_usage underflow

From: Alysa Liu <[email protected]>

vram_usage was subtracting non-vram memory size,
which caused it to become negative.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -3
index 22c1bdc53d2e..c2fa330ff78b 100644
@@ -1961,9 +1961,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
 	 */
 	if (size) {
 		if (!is_imported &&
-		   (mem->bo->preferred_domains == AMDGPU_GEM_DOMAIN_VRAM ||
-		   (adev->apu_prefer_gtt &&
-		    mem->bo->preferred_domains == AMDGPU_GEM_DOMAIN_GTT)))
+		   mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM)
 			*size = bo_size;
 		else
 			*size = 0;
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw

[Public]

-----Original Message-----
From: Liu, Alysa <[email protected]>
Sent: Tuesday, October 14, 2025 9:43 AM
To: [email protected]
Cc: Kasiviswanathan, Harish <[email protected]>; Liu, Alysa <[email protected]>
Subject: [PATCH] drm/amdgpu: Fix vram_usage underflow

From: Alysa Liu <[email protected]>

vram_usage was subtracting non-vram memory size,
which caused it to become negative.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -3
index 22c1bdc53d2e..c2fa330ff78b 100644
@@ -1961,9 +1961,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
         */
        if (size) {
                if (!is_imported &&
-                  (mem->bo->preferred_domains == AMDGPU_GEM_DOMAIN_VRAM ||
-                  (adev->apu_prefer_gtt &&
-                   mem->bo->preferred_domains == AMDGPU_GEM_DOMAIN_GTT)))
+                  mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM)
                        *size = bo_size;
                else
                        *size = 0;

--
2.34.1

maintainer Reviewed-by
#2 lore raw
Quoted 3 lines · Harish

[Public]

This patch seems to effectively revert your earlier patch

commit f915f3af9984464c308787102990d85d4e988d2c

Author: Harish Kasiviswanathan<[email protected]>
Date:   Fri Apr 28 14:20:00 2023 -0400

drm/amdgpu: For GFX 9.4.3 APU fix vram_usage value

For GFX 9.4.3 APP APU VRAM is allocated in GTT domain. While freeing memory check for GTT domain instead of VRAM if it is APP APU

Are you sure that's the right thing to do? Are the original reasons for your patch no longer valid?

Regards,
  Felix

Quoted 37 lines

-----Original Message-----
From: Liu, Alysa<[email protected]>
Sent: Tuesday, October 14, 2025 9:43 AM
To:[email protected]
Cc: Kasiviswanathan, Harish<[email protected]>; Liu, Alysa<[email protected]>
Subject: [PATCH] drm/amdgpu: Fix vram_usage underflow

From: Alysa Liu<[email protected]>

vram_usage was subtracting non-vram memory size,
which caused it to become negative.

---
  drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +1 -4
index 22c1bdc53d2e..c2fa330ff78b 100644
@@ -1961,9 +1961,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(
          */
         if (size) {
                 if (!is_imported &&
-                  (mem->bo->preferred_domains == AMDGPU_GEM_DOMAIN_VRAM ||
-                  (adev->apu_prefer_gtt &&
-                   mem->bo->preferred_domains == AMDGPU_GEM_DOMAIN_GTT)))
+                  mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM)
                         *size = bo_size;
                 else
                         *size = 0;
--

2.34.1

Reviewed-by Reviewed-by Felix Kuehling
#3 lore raw

[Public]

With the original patch accounting underflows. Allocations are accounted in kfd_chardev.c doesn’t account for GTT allocations. However, free accounts for both GTT and VRAM.

Use of flags is more reliable. I think flags should have used in the first place, but I believe originally when vram_usage was first introduced the mem->alloc_flags wasn’t used in the free_ function

Best Regards,
Harish

From: Kuehling, Felix <[email protected]>
Sent: Tuesday, October 14, 2025 3:16 PM
To: Kasiviswanathan, Harish <[email protected]>; Liu, Alysa <[email protected]>; [email protected]
Subject: Re: [PATCH] drm/amdgpu: Fix vram_usage underflow

On 2025-10-14 13:52, Kasiviswanathan, Harish wrote:

[Public]

This patch seems to effectively revert your earlier patch

commit f915f3af9984464c308787102990d85d4e988d2c

Author: Harish Kasiviswanathan <[email protected]><mailto:[email protected]>

Date: Fri Apr 28 14:20:00 2023 -0400

drm/amdgpu: For GFX 9.4.3 APU fix vram_usage value

For GFX 9.4.3 APP APU VRAM is allocated in GTT domain. While freeing

memory check for GTT domain instead of VRAM if it is APP APU

Are you sure that's the right thing to do? Are the original reasons for your patch no longer valid?

Regards,
Felix

-----Original Message-----

From: Liu, Alysa <[email protected]><mailto:[email protected]>

Sent: Tuesday, October 14, 2025 9:43 AM

To: [email protected]<mailto:[email protected]>

Cc Kasiviswanathan, Harish <[email protected]><mailto:[email protected]>; Liu, Alysa <[email protected]><mailto:[email protected]>

Subject: [PATCH] drm/amdgpu: Fix vram_usage underflow

From: Alysa Liu <[email protected]><mailto:[email protected]>

vram_usage was subtracting non-vram memory size,

which caused it to become negative.

---

 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c +0 -0

index 22c1bdc53d2e..c2fa330ff78b 100644

--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

@@ -1961,9 +1961,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(

         */

        if (size) {

                if (!is_imported &&

- (mem->bo->preferred_domains == AMDGPU_GEM_DOMAIN_VRAM ||

- (adev->apu_prefer_gtt &&

- mem->bo->preferred_domains == AMDGPU_GEM_DOMAIN_GTT)))

+ mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM)

                        *size = bo_size;

                else

                        *size = 0;

--

2.34.1

maintainer Acked-by
#4 lore raw
Quoted 8 lines · Harish

[Public]

With the original patch accounting underflows. Allocations are accounted in kfd_chardev.c doesn’t account for GTT allocations. However, free accounts for both GTT and VRAM.

Use of flags is more reliable. I think flags should have used in the first place, but I believe originally when vram_usage was first introduced the mem->alloc_flags wasn’t used in the free_ function

Makes sense. Though it seems at allocation time the accounting has used the allocation flags as far back as 2020. I wonder it there should be a Fixes: tag here, but not sure which change exactly introduced the regression. Sounds like it was something that happened after your patch in 2023.

Either way, the patch is

Quoted 94 lines

Best Regards,

Harish

*From:*Kuehling, Felix <[email protected]>
*Sent:* Tuesday, October 14, 2025 3:16 PM
*To:* Kasiviswanathan, Harish <[email protected]>; Liu, Alysa <[email protected]>; [email protected] *Subject:* Re: [PATCH] drm/amdgpu: Fix vram_usage underflow

On 2025-10-14 13:52, Kasiviswanathan, Harish wrote:

[Public]

This patch seems to effectively revert your earlier patch

commit f915f3af9984464c308787102990d85d4e988d2c
Author: Harish Kasiviswanathan<[email protected]> <mailto:[email protected]> Date:   Fri Apr 28 14:20:00 2023 -0400
    drm/amdgpu: For GFX 9.4.3 APU fix vram_usage value

    For GFX 9.4.3 APP APU VRAM is allocated in GTT domain. While freeing memory check for GTT domain instead of VRAM if it is APP APU

Are you sure that's the right thing to do? Are the original reasons for your patch no longer valid?

Regards,
  Felix

    -----Original Message-----

    From: Liu, Alysa<[email protected]> <mailto:[email protected]>

    Sent: Tuesday, October 14, 2025 9:43 AM

    To:[email protected]

    Cc: Kasiviswanathan, Harish<[email protected]> <mailto:[email protected]>; Liu, Alysa<[email protected]> <mailto:[email protected]>

    Subject: [PATCH] drm/amdgpu: Fix vram_usage underflow

    From: Alysa Liu<[email protected]> <mailto:[email protected]>

    vram_usage was subtracting non-vram memory size,

    which caused it to become negative.

    Signed-off-by: Alysa Liu<[email protected]> <mailto:[email protected]>

    ---

      drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 4 +---

      1 file changed, 1 insertion(+), 3 deletions(-)

    diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

    index 22c1bdc53d2e..c2fa330ff78b 100644

    --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

    +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c

    @@ -1961,9 +1961,7 @@ int amdgpu_amdkfd_gpuvm_free_memory_of_gpu(

              */

             if (size) {

                     if (!is_imported &&

    -                  (mem->bo->preferred_domains == AMDGPU_GEM_DOMAIN_VRAM ||

    -                  (adev->apu_prefer_gtt &&

    -                   mem->bo->preferred_domains == AMDGPU_GEM_DOMAIN_GTT)))

    +                  mem->alloc_flags & KFD_IOC_ALLOC_MEM_FLAGS_VRAM)

                             *size = bo_size;

                     else

                             *size = 0;

    --

    2.34.1