Skip to contentSkip to conversation

drm/ttm: Should to return the evict error

PATCH Superseded Emily Deng 4 participants 10 messages May 21, 2025 – Jun 2, 2025

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Emily Deng

author
#0 lore raw

PATCH v2 1/1 drm/ttm: Should to return the evict error

For the evict fail case, the evict error should be returned.

v2: Consider ENOENT case.

---
 drivers/gpu/drm/ttm/ttm_resource.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_resource.c +4 -4
index 097716bd248a..abf104ae9d35 100644
@@ -511,12 +511,12 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev,
 		.force_alloc = true
 	};
 	struct dma_fence *fence;
-	int ret;
+	int ret, evict_ret = 0;
 
 	do {
-		ret = ttm_bo_evict_first(bdev, man, &ctx);
+		evict_ret = ttm_bo_evict_first(bdev, man, &ctx);
 		cond_resched();
-	} while (!ret);
+	} while (!evict_ret);
 
 	spin_lock(&man->move_lock);
 	fence = dma_fence_get(man->move);
@@ -529,7 +529,7 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev,
 			return ret;
 	}
 
-	return 0;
+	return (evict_ret == -ENOENT) ? 0 : evict_ret;
 }
 EXPORT_SYMBOL(ttm_resource_manager_evict_all);
 
Signature · 1 line
2.34.1
#1 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

Ping......

Emily Deng
Best Wishes

Quoted 48 lines

-----Original Message-----
From: Emily Deng <[email protected]>
Sent: Wednesday, May 21, 2025 11:57 AM
To: [email protected]
Cc: Deng, Emily <[email protected]>
Subject: [PATCH v2] drm/ttm: Should to return the evict error

For the evict fail case, the evict error should be returned.

v2: Consider ENOENT case.

---
drivers/gpu/drm/ttm/ttm_resource.c | 8 ++++----

1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_resource.c +3 -3
index 097716bd248a..abf104ae9d35 100644
@@ -511,12 +511,12 @@ int ttm_resource_manager_evict_all(struct ttm_device
 *bdev,
              .force_alloc = true
      };
      struct dma_fence *fence;
-      int ret;
+      int ret, evict_ret = 0;
 
      do {
-              ret = ttm_bo_evict_first(bdev, man, &ctx);
+              evict_ret = ttm_bo_evict_first(bdev, man, &ctx);
              cond_resched();
-      } while (!ret);
+      } while (!evict_ret);
 
      spin_lock(&man->move_lock);
      fence = dma_fence_get(man->move);
drivers/gpu/drm/ttm/ttm_resource.c +1 -2
@@ -529,7 +529,7 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev,
                      return ret;
      }
 
-      return 0;
+      return (evict_ret == -ENOENT) ? 0 : evict_ret;
 }
 EXPORT_SYMBOL(ttm_resource_manager_evict_all);
 
--

2.34.1

#2 lore raw
Quoted 52 lines · Emily

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

Ping......

Emily Deng
Best Wishes

Quoted 41 lines

-----Original Message-----
From: Emily Deng<[email protected]>
Sent: Wednesday, May 21, 2025 11:57 AM To:[email protected]
Cc: Deng, Emily<[email protected]>
Subject: [PATCH v2] drm/ttm: Should to return the evict error

For the evict fail case, the evict error should be returned.

v2: Consider ENOENT case.

---
drivers/gpu/drm/ttm/ttm_resource.c | 8 ++++----

1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_resource.c +3 -3
index 097716bd248a..abf104ae9d35 100644
@@ -511,12 +511,12 @@ int ttm_resource_manager_evict_all(struct ttm_device
 *bdev,
               .force_alloc = true
       };
       struct dma_fence *fence;
-      int ret;
+      int ret, evict_ret = 0;
 
       do {
-              ret = ttm_bo_evict_first(bdev, man, &ctx);
+              evict_ret = ttm_bo_evict_first(bdev, man, &ctx);
               cond_resched();
-      } while (!ret);
+      } while (!evict_ret);
 
       spin_lock(&man->move_lock);
       fence = dma_fence_get(man->move);
drivers/gpu/drm/ttm/ttm_resource.c +0 -0
@@ -529,7 +529,7 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev,
                       return ret;
       }
 
Quoted 3 lines

drivers/gpu/drm/ttm/ttm_resource.c int ttm_resource_manager_evict_all(struct ttm_device *bdev, · line 533

Quoted 3 lines
drivers/gpu/drm/ttm/ttm_resource.c +1 -1
-      return 0;
+      return (evict_ret == -ENOENT) ? 0 : evict_ret;
 }

Can you explain why you care ENOENT(No such file or directory) specifically?

Regards

Xiaogang

Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/ttm/ttm_resource.c +0 -1
 EXPORT_SYMBOL(ttm_resource_manager_evict_all);
 
--

2.34.1

#3 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

From: Chen, Xiaogang <[email protected]>
Sent: Friday, May 23, 2025 6:27 AM
To: Deng, Emily <[email protected]>; [email protected]
Subject: Re: [PATCH v2] drm/ttm: Should to return the evict error

On 5/21/2025 9:42 PM, Deng, Emily wrote:

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

Ping......

Emily Deng

Best Wishes

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

From: Emily Deng <[email protected]><mailto:[email protected]>

Sent: Wednesday, May 21, 2025 11:57 AM

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

Cc Deng, Emily <[email protected]><mailto:[email protected]>

Subject: [PATCH v2] drm/ttm: Should to return the evict error

For the evict fail case, the evict error should be returned.

v2: Consider ENOENT case.

---

drivers/gpu/drm/ttm/ttm_resource.c | 8 ++++----

1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_resource.c +0 -0

index 097716bd248a..abf104ae9d35 100644

--- a/drivers/gpu/drm/ttm/ttm_resource.c

+++ b/drivers/gpu/drm/ttm/ttm_resource.c

@@ -511,12 +511,12 @@ int ttm_resource_manager_evict_all(struct ttm_device

*bdev,

              .force_alloc = true

      };

      struct dma_fence *fence;

- int ret;

+ int ret, evict_ret = 0;

      do {

- ret = ttm_bo_evict_first(bdev, man, &ctx);

+ evict_ret = ttm_bo_evict_first(bdev, man, &ctx);

              cond_resched();

- } while (!ret);

+ } while (!evict_ret);

      spin_lock(&man->move_lock);

      fence = dma_fence_get(man->move);

@@ -529,7 +529,7 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev,

                      return ret;

      }

- return 0;

+ return (evict_ret == -ENOENT) ? 0 : evict_ret;

}

Can you explain why you care ENOENT(No such file or directory) specifically?

Regards

Xiaogang

For ENOENT, it simply means the resource or file doesn't exist—it doesn't indicate an error during eviction. We only need to focus on actual eviction-related errors.

Emily Deng
Best Wishes

EXPORT_SYMBOL(ttm_resource_manager_evict_all);

--

2.34.1

#4 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

From: amd-gfx <[email protected]> On Behalf Of Deng, Emily
Sent: Monday, May 26, 2025 9:51 AM
To: Chen, Xiaogang <[email protected]>; [email protected]
Subject: RE: [PATCH v2] drm/ttm: Should to return the evict error

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

From: Chen, Xiaogang <[email protected]<mailto:[email protected]>>
Sent: Friday, May 23, 2025 6:27 AM
To: Deng, Emily <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]>
Subject: Re: [PATCH v2] drm/ttm: Should to return the evict error

On 5/21/2025 9:42 PM, Deng, Emily wrote:

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

Ping......

Emily Deng

Best Wishes

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

From: Emily Deng <[email protected]><mailto:[email protected]>

Sent: Wednesday, May 21, 2025 11:57 AM

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

Cc Deng, Emily <[email protected]><mailto:[email protected]>

Subject: [PATCH v2] drm/ttm: Should to return the evict error

For the evict fail case, the evict error should be returned.

v2: Consider ENOENT case.

---

drivers/gpu/drm/ttm/ttm_resource.c | 8 ++++----

1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_resource.c +0 -0

index 097716bd248a..abf104ae9d35 100644

--- a/drivers/gpu/drm/ttm/ttm_resource.c

+++ b/drivers/gpu/drm/ttm/ttm_resource.c

@@ -511,12 +511,12 @@ int ttm_resource_manager_evict_all(struct ttm_device

*bdev,

              .force_alloc = true

      };

      struct dma_fence *fence;

- int ret;

+ int ret, evict_ret = 0;

      do {

- ret = ttm_bo_evict_first(bdev, man, &ctx);

+ evict_ret = ttm_bo_evict_first(bdev, man, &ctx);

              cond_resched();

- } while (!ret);

+ } while (!evict_ret);

      spin_lock(&man->move_lock);

      fence = dma_fence_get(man->move);

@@ -529,7 +529,7 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev,

                      return ret;

      }

- return 0;

+ return (evict_ret == -ENOENT) ? 0 : evict_ret;

}

Can you explain why you care ENOENT(No such file or directory) specifically?

Regards

Xiaogang

For ENOENT, it simply means the resource or file doesn't exist—it doesn't indicate an error during eviction. We only need to focus on actual eviction-related errors.

Emily Deng
Best Wishes

EXPORT_SYMBOL(ttm_resource_manager_evict_all);

--

2.34.1

#5 lore raw
Quoted 104 lines · Emily

[AMD Official Use Only - AMD Internal Distribution Only]

*From:*amd-gfx <[email protected]> *On Behalf Of *Deng, Emily *Sent:* Monday, May 26, 2025 9:51 AM
*To:* Chen, Xiaogang <[email protected]>; [email protected] *Subject:* RE: [PATCH v2] drm/ttm: Should to return the evict error

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

*From:*Chen, Xiaogang <[email protected]>
*Sent:* Friday, May 23, 2025 6:27 AM
*To:* Deng, Emily <[email protected]>; [email protected] *Subject:* Re: [PATCH v2] drm/ttm: Should to return the evict error

On 5/21/2025 9:42 PM, Deng, Emily wrote:

    [AMD Official Use Only - AMD Internal Distribution Only]

    [AMD Official Use Only - AMD Internal Distribution Only]

    Ping......

    Emily Deng

    Best Wishes

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

        From: Emily Deng<[email protected]> <mailto:[email protected]>

        Sent: Wednesday, May 21, 2025 11:57 AM

        To:[email protected]

        Cc: Deng, Emily<[email protected]> <mailto:[email protected]>

        Subject: [PATCH v2] drm/ttm: Should to return the evict error

        For the evict fail case, the evict error should be returned.

        v2: Consider ENOENT case.

        Signed-off-by: Emily Deng<[email protected]> <mailto:[email protected]>

        ---

        drivers/gpu/drm/ttm/ttm_resource.c | 8 ++++----

        1 file changed, 4 insertions(+), 4 deletions(-)

        diff --git a/drivers/gpu/drm/ttm/ttm_resource.c b/drivers/gpu/drm/ttm/ttm_resource.c

        index 097716bd248a..abf104ae9d35 100644

        --- a/drivers/gpu/drm/ttm/ttm_resource.c

        +++ b/drivers/gpu/drm/ttm/ttm_resource.c

        @@ -511,12 +511,12 @@ int ttm_resource_manager_evict_all(struct ttm_device

        *bdev,

                       .force_alloc = true

               };

               struct dma_fence *fence;

        -      int ret;

        +      int ret, evict_ret = 0;

               do {

        -              ret = ttm_bo_evict_first(bdev, man, &ctx);

        +              evict_ret = ttm_bo_evict_first(bdev, man, &ctx);

                       cond_resched();

        -      } while (!ret);

        +      } while (!evict_ret);

               spin_lock(&man->move_lock);

               fence = dma_fence_get(man->move);

        @@ -529,7 +529,7 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev,

                               return ret;

               }

        -      return 0;

        +      return (evict_ret == -ENOENT) ? 0 : evict_ret;

        }
Quoted 8 lines

Can you explain why you care ENOENT(No such file or directory) specifically?

Regards

Xiaogang

For ENOENT, it simply means the resource or file doesn't exist—it doesn't indicate an error during eviction. We only need to focus on actual eviction-related errors.

I think I know what you mean. But I have a different view on that. ttm_resource_manager_evict_all release all resources associated with a ttm_resource_manager(man). It is part of memory manager cleanup sequence. Even it fail(no matter what reason is) I think the following memory manager cleanup should still continue going, then the returned error value should not be used to stop following clean up.

I think @Christian König can give judgment on it.

Regards

Xiaogang

Quoted 10 lines

Emily Deng

Best Wishes

        EXPORT_SYMBOL(ttm_resource_manager_evict_all);

        --

        2.34.1
#6 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

From: Chen, Xiaogang <[email protected]>
Sent: Thursday, May 29, 2025 5:15 AM
To: Deng, Emily <[email protected]>; Zhang, Owen(SRDC) <[email protected]>
Cc: [email protected]
Subject: Re: [PATCH v2] drm/ttm: Should to return the evict error

On 5/28/2025 1:19 AM, Deng, Emily wrote:

[AMD Official Use Only - AMD Internal Distribution Only]

From: amd-gfx <[email protected]><mailto:[email protected]> On Behalf Of Deng, Emily
Sent: Monday, May 26, 2025 9:51 AM
To: Chen, Xiaogang <[email protected]><mailto:[email protected]>; [email protected]<mailto:[email protected]>
Subject: RE: [PATCH v2] drm/ttm: Should to return the evict error

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

From: Chen, Xiaogang <[email protected]<mailto:[email protected]>>
Sent: Friday, May 23, 2025 6:27 AM
To: Deng, Emily <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]>
Subject: Re: [PATCH v2] drm/ttm: Should to return the evict error

On 5/21/2025 9:42 PM, Deng, Emily wrote:

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

Ping......

Emily Deng

Best Wishes

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

From: Emily Deng <[email protected]><mailto:[email protected]>

Sent: Wednesday, May 21, 2025 11:57 AM

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

Cc Deng, Emily <[email protected]><mailto:[email protected]>

Subject: [PATCH v2] drm/ttm: Should to return the evict error

For the evict fail case, the evict error should be returned.

v2: Consider ENOENT case.

---

drivers/gpu/drm/ttm/ttm_resource.c | 8 ++++----

1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_resource.c +0 -0

index 097716bd248a..abf104ae9d35 100644

--- a/drivers/gpu/drm/ttm/ttm_resource.c

+++ b/drivers/gpu/drm/ttm/ttm_resource.c

@@ -511,12 +511,12 @@ int ttm_resource_manager_evict_all(struct ttm_device

*bdev,

              .force_alloc = true

      };

      struct dma_fence *fence;

- int ret;

+ int ret, evict_ret = 0;

      do {

- ret = ttm_bo_evict_first(bdev, man, &ctx);

+ evict_ret = ttm_bo_evict_first(bdev, man, &ctx);

              cond_resched();

- } while (!ret);

+ } while (!evict_ret);

      spin_lock(&man->move_lock);

      fence = dma_fence_get(man->move);

@@ -529,7 +529,7 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev,

                      return ret;

      }

- return 0;

+ return (evict_ret == -ENOENT) ? 0 : evict_ret;

}

Can you explain why you care ENOENT(No such file or directory) specifically?

Regards

Xiaogang

For ENOENT, it simply means the resource or file doesn't exist—it doesn't indicate an error during eviction. We only need to focus on actual eviction-related errors.

I think I know what you mean. But I have a different view on that. ttm_resource_manager_evict_all release all resources associated with a ttm_resource_manager(man). It is part of memory manager cleanup sequence. Even it fail(no matter what reason is) I think the following memory manager cleanup should still continue going, then the returned error value should not be used to stop following clean up.

I think @Christian König can give judgment on it.

Whether needs to stop following steps depends on the detail use case. For example, for amdgpu_device_suspend, if the evict fail, then need to stop suspend.

Regards

Xiaogang

Emily Deng
Best Wishes

EXPORT_SYMBOL(ttm_resource_manager_evict_all);

--

2.34.1

#7 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

@Koenig, Christian<mailto:[email protected]> can give judgment on it? Thanks.

Emily Deng
Best Wishes
From: amd-gfx <[email protected]> On Behalf Of Deng, Emily
Sent: Thursday, May 29, 2025 11:37 AM
To: Chen, Xiaogang <[email protected]>; Zhang, Owen(SRDC) <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH v2] drm/ttm: Should to return the evict error

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

From: Chen, Xiaogang <[email protected]<mailto:[email protected]>>
Sent: Thursday, May 29, 2025 5:15 AM
To: Deng, Emily <[email protected]<mailto:[email protected]>>; Zhang, Owen(SRDC) <[email protected]<mailto:[email protected]>>
Cc: [email protected]<mailto:[email protected]>
Subject: Re: [PATCH v2] drm/ttm: Should to return the evict error

On 5/28/2025 1:19 AM, Deng, Emily wrote:

[AMD Official Use Only - AMD Internal Distribution Only]

From: amd-gfx <[email protected]><mailto:[email protected]> On Behalf Of Deng, Emily
Sent: Monday, May 26, 2025 9:51 AM
To: Chen, Xiaogang <[email protected]><mailto:[email protected]>; [email protected]<mailto:[email protected]>
Subject: RE: [PATCH v2] drm/ttm: Should to return the evict error

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

From: Chen, Xiaogang <[email protected]<mailto:[email protected]>>
Sent: Friday, May 23, 2025 6:27 AM
To: Deng, Emily <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]>
Subject: Re: [PATCH v2] drm/ttm: Should to return the evict error

On 5/21/2025 9:42 PM, Deng, Emily wrote:

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

Ping......

Emily Deng

Best Wishes

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

From: Emily Deng <[email protected]><mailto:[email protected]>

Sent: Wednesday, May 21, 2025 11:57 AM

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

Cc Deng, Emily <[email protected]><mailto:[email protected]>

Subject: [PATCH v2] drm/ttm: Should to return the evict error

For the evict fail case, the evict error should be returned.

v2: Consider ENOENT case.

---

drivers/gpu/drm/ttm/ttm_resource.c | 8 ++++----

1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_resource.c +0 -0

index 097716bd248a..abf104ae9d35 100644

--- a/drivers/gpu/drm/ttm/ttm_resource.c

+++ b/drivers/gpu/drm/ttm/ttm_resource.c

@@ -511,12 +511,12 @@ int ttm_resource_manager_evict_all(struct ttm_device

*bdev,

              .force_alloc = true

      };

      struct dma_fence *fence;

- int ret;

+ int ret, evict_ret = 0;

      do {

- ret = ttm_bo_evict_first(bdev, man, &ctx);

+ evict_ret = ttm_bo_evict_first(bdev, man, &ctx);

              cond_resched();

- } while (!ret);

+ } while (!evict_ret);

      spin_lock(&man->move_lock);

      fence = dma_fence_get(man->move);

@@ -529,7 +529,7 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev,

                      return ret;

      }

- return 0;

+ return (evict_ret == -ENOENT) ? 0 : evict_ret;

}

Can you explain why you care ENOENT(No such file or directory) specifically?

Regards

Xiaogang

For ENOENT, it simply means the resource or file doesn't exist—it doesn't indicate an error during eviction. We only need to focus on actual eviction-related errors.

I think I know what you mean. But I have a different view on that. ttm_resource_manager_evict_all release all resources associated with a ttm_resource_manager(man). It is part of memory manager cleanup sequence. Even it fail(no matter what reason is) I think the following memory manager cleanup should still continue going, then the returned error value should not be used to stop following clean up.

I think @Christian König can give judgment on it.

Whether needs to stop following steps depends on the detail use case. For example, for amdgpu_device_suspend, if the evict fail, then need to stop suspend.

Regards

Xiaogang

Emily Deng
Best Wishes

EXPORT_SYMBOL(ttm_resource_manager_evict_all);

--

2.34.1

#8 lore raw

[AMD Official Use Only - AMD Internal Distribution Only]

@Koenig, Christian<mailto:[email protected]>… can you pls provide your expertise? Thanks for support.

Rgds/Owen

From: Deng, Emily <[email protected]>
Sent: Friday, May 30, 2025 9:41 AM
To: Deng, Emily <[email protected]>; Chen, Xiaogang <[email protected]>; Zhang, Owen(SRDC) <[email protected]>; Koenig, Christian <[email protected]>
Cc: [email protected]
Subject: RE: [PATCH v2] drm/ttm: Should to return the evict error

[AMD Official Use Only - AMD Internal Distribution Only]

@Koenig, Christian<mailto:[email protected]> can give judgment on it? Thanks.

Emily Deng
Best Wishes
From: amd-gfx <[email protected]<mailto:[email protected]>> On Behalf Of Deng, Emily
Sent: Thursday, May 29, 2025 11:37 AM
To: Chen, Xiaogang <[email protected]<mailto:[email protected]>>; Zhang, Owen(SRDC) <[email protected]<mailto:[email protected]>>
Cc: [email protected]<mailto:[email protected]>
Subject: RE: [PATCH v2] drm/ttm: Should to return the evict error

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

From: Chen, Xiaogang <[email protected]<mailto:[email protected]>>
Sent: Thursday, May 29, 2025 5:15 AM
To: Deng, Emily <[email protected]<mailto:[email protected]>>; Zhang, Owen(SRDC) <[email protected]<mailto:[email protected]>>
Cc: [email protected]<mailto:[email protected]>
Subject: Re: [PATCH v2] drm/ttm: Should to return the evict error

On 5/28/2025 1:19 AM, Deng, Emily wrote:

[AMD Official Use Only - AMD Internal Distribution Only]

From: amd-gfx <[email protected]><mailto:[email protected]> On Behalf Of Deng, Emily
Sent: Monday, May 26, 2025 9:51 AM
To: Chen, Xiaogang <[email protected]><mailto:[email protected]>; [email protected]<mailto:[email protected]>
Subject: RE: [PATCH v2] drm/ttm: Should to return the evict error

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

From: Chen, Xiaogang <[email protected]<mailto:[email protected]>>
Sent: Friday, May 23, 2025 6:27 AM
To: Deng, Emily <[email protected]<mailto:[email protected]>>; [email protected]<mailto:[email protected]>
Subject: Re: [PATCH v2] drm/ttm: Should to return the evict error

On 5/21/2025 9:42 PM, Deng, Emily wrote:

[AMD Official Use Only - AMD Internal Distribution Only]

[AMD Official Use Only - AMD Internal Distribution Only]

Ping......

Emily Deng

Best Wishes

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

From: Emily Deng <[email protected]><mailto:[email protected]>

Sent: Wednesday, May 21, 2025 11:57 AM

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

Cc Deng, Emily <[email protected]><mailto:[email protected]>

Subject: [PATCH v2] drm/ttm: Should to return the evict error

For the evict fail case, the evict error should be returned.

v2: Consider ENOENT case.

---

drivers/gpu/drm/ttm/ttm_resource.c | 8 ++++----

1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_resource.c +0 -0

index 097716bd248a..abf104ae9d35 100644

--- a/drivers/gpu/drm/ttm/ttm_resource.c

+++ b/drivers/gpu/drm/ttm/ttm_resource.c

@@ -511,12 +511,12 @@ int ttm_resource_manager_evict_all(struct ttm_device

*bdev,

              .force_alloc = true

      };

      struct dma_fence *fence;

- int ret;

+ int ret, evict_ret = 0;

      do {

- ret = ttm_bo_evict_first(bdev, man, &ctx);

+ evict_ret = ttm_bo_evict_first(bdev, man, &ctx);

              cond_resched();

- } while (!ret);

+ } while (!evict_ret);

      spin_lock(&man->move_lock);

      fence = dma_fence_get(man->move);

@@ -529,7 +529,7 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev,

                      return ret;

      }

- return 0;

+ return (evict_ret == -ENOENT) ? 0 : evict_ret;

}

Can you explain why you care ENOENT(No such file or directory) specifically?

Regards

Xiaogang

For ENOENT, it simply means the resource or file doesn't exist—it doesn't indicate an error during eviction. We only need to focus on actual eviction-related errors.

I think I know what you mean. But I have a different view on that. ttm_resource_manager_evict_all release all resources associated with a ttm_resource_manager(man). It is part of memory manager cleanup sequence. Even it fail(no matter what reason is) I think the following memory manager cleanup should still continue going, then the returned error value should not be used to stop following clean up.

I think @Christian König can give judgment on it.

Whether needs to stop following steps depends on the detail use case. For example, for amdgpu_device_suspend, if the evict fail, then need to stop suspend.

Regards

Xiaogang

Emily Deng
Best Wishes

EXPORT_SYMBOL(ttm_resource_manager_evict_all);

--

2.34.1

#9 lore raw
In reply to Emily Deng
Quoted 16 lines · Emily Deng

For the evict fail case, the evict error should be returned.

v2: Consider ENOENT case.

---
 drivers/gpu/drm/ttm/ttm_resource.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/ttm/ttm_resource.c +0 -0
index 097716bd248a..abf104ae9d35 100644
@@ -511,12 +511,12 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev,
 		.force_alloc = true
 	};

drivers/gpu/drm/ttm/ttm_resource.c int ttm_resource_manager_evict_all(struct ttm_device *bdev, · line 519

Quoted 10 lines
drivers/gpu/drm/ttm/ttm_resource.c +3 -3
 	struct dma_fence *fence;
-	int ret;
+	int ret, evict_ret = 0;
 
 	do {
-		ret = ttm_bo_evict_first(bdev, man, &ctx);
+		evict_ret = ttm_bo_evict_first(bdev, man, &ctx);
 		cond_resched();
-	} while (!ret);
+	} while (!evict_ret);

We should probably abort here directly when the eviction failed for some reason (except for -ENOENT) and not wait for the move to finish.

Regards,
Christian.

Quoted 12 lines
drivers/gpu/drm/ttm/ttm_resource.c +1 -1
 	spin_lock(&man->move_lock);
 	fence = dma_fence_get(man->move);
@@ -529,7 +529,7 @@ int ttm_resource_manager_evict_all(struct ttm_device *bdev,
 			return ret;
 	}
 
-	return 0;
+	return (evict_ret == -ENOENT) ? 0 : evict_ret;
 }
 EXPORT_SYMBOL(ttm_resource_manager_evict_all);