Skip to contentSkip to conversation

drm/ttm: Don't add swapped BOs to swap-LRU list

PATCH In review Felix Kuehling 5 participants 6 messages Jan 18, 2018 – Jan 19, 2018 2 messages not in the archive

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

PATCH 1/2 drm/ttm: Don't add swapped BOs to swap-LRU list

A BO that's already swapped would be added back to the swap-LRU list for example if its validation failed under high memory pressure. This could later lead to swapping it out again and leaking previous swap storage.

This commit adds a condition to prevent that from happening.

v2: Check page_flags instead of swap_storage

---
 drivers/gpu/drm/ttm/ttm_bo.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo.c +2 -1
index 2eb71ff..62518b6 100644
@@ -170,7 +170,8 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
 		list_add_tail(&bo->lru, &man->lru[bo->priority]);
 		kref_get(&bo->list_kref);
 
-		if (bo->ttm && !(bo->ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		if (bo->ttm && !(bo->ttm->page_flags &
+				 (TTM_PAGE_FLAG_SG | TTM_PAGE_FLAG_SWAPPED))) {
 			list_add_tail(&bo->swap,
 				      &bo->glob->swap_lru[bo->priority]);
 			kref_get(&bo->list_kref);
Signature · 6 lines
2.7.4

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

A message that is not in the archive (sent off-list or not yet received): 1516294577-29078-1-git-send-email-Felix.Kuehling-5C7GfCeVMHo@public.gmane.org

#2 lore raw

PATCH 2/2 drm/ttm: Don't unreserve swapped BOs that were previously reserved

If ttm_bo_swapout doesn't own the lock, don't release it. Someone else probably depends on it still being locked.

---
 drivers/gpu/drm/ttm/ttm_bo.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +2 -2
index 62518b6..893003f 100644
@@ -1780,8 +1780,8 @@ int ttm_bo_swapout(struct ttm_bo_global *glob, struct ttm_operation_ctx *ctx)
 	 * Unreserve without putting on LRU to avoid swapping out an
 	 * already swapped buffer.
 	 */
-
-	reservation_object_unlock(bo->resv);
+	if (locked)
+		reservation_object_unlock(bo->resv);
 	kref_put(&bo->list_kref, ttm_bo_release_list);
 	return ret;
 }
Signature · 6 lines
2.7.4

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

RE: [PATCH 2/2] drm/ttm: Don't unreserve swapped BOs that were previously reserved

good catch!

Thanks
Roger(Hongbo.He)
-----Original Message-----
From: Kuehling, Felix
Sent: Friday, January 19, 2018 12:56 AM
To: [email protected]; [email protected]; Koenig, Christian <[email protected]>; He, Roger <[email protected]>
Cc: Kuehling, Felix <[email protected]>
Subject: [PATCH 2/2] drm/ttm: Don't unreserve swapped BOs that were previously reserved

If ttm_bo_swapout doesn't own the lock, don't release it. Someone else probably depends on it still being locked.

---
 drivers/gpu/drm/ttm/ttm_bo.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/ttm/ttm_bo.c +2 -2
@@ -1780,8 +1780,8 @@ int ttm_bo_swapout(struct ttm_bo_global *glob, struct ttm_operation_ctx *ctx)
 	 * Unreserve without putting on LRU to avoid swapping out an
 	 * already swapped buffer.
 	 */
-
-	reservation_object_unlock(bo->resv);
+	if (locked)
+		reservation_object_unlock(bo->resv);
 	kref_put(&bo->list_kref, ttm_bo_release_list);
 	return ret;
 }

--
2.7.4

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

Reviewed-by on v1 1/2
#4 lore raw
In reply to Felix Kuehling

Am 18.01.2018 um 17:56 schrieb Felix Kuehling:

Quoted 10 lines

A BO that's already swapped would be added back to the swap-LRU list for example if its validation failed under high memory pressure. This could later lead to swapping it out again and leaking previous swap storage.

This commit adds a condition to prevent that from happening.

v2: Check page_flags instead of swap_storage

Quoted 9 lines
---
  drivers/gpu/drm/ttm/ttm_bo.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/ttm/ttm_bo.c +0 -0
index 2eb71ff..62518b6 100644

drivers/gpu/drm/ttm/ttm_bo.c void ttm_bo_add_to_lru(struct ttm_buffer_object *bo) · line 177

Quoted 9 lines
drivers/gpu/drm/ttm/ttm_bo.c +2 -1
@@ -170,7 +170,8 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
  		list_add_tail(&bo->lru, &man->lru[bo->priority]);
  		kref_get(&bo->list_kref);
 
-		if (bo->ttm && !(bo->ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+		if (bo->ttm && !(bo->ttm->page_flags &
+				 (TTM_PAGE_FLAG_SG | TTM_PAGE_FLAG_SWAPPED))) {
  			list_add_tail(&bo->swap,
  				      &bo->glob->swap_lru[bo->priority]);
  			kref_get(&bo->list_kref);

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

#5 lore raw
Quoted 6 lines · Christian König

Am 18.01.2018 um 17:56 schrieb Felix Kuehling:

Quoted 5 lines

A BO that's already swapped would be added back to the swap-LRU list for example if its validation failed under high memory pressure. This could later lead to swapping it out again and leaking previous swap storage.

Quoted 7 lines
Quoted 5 lines

This commit adds a condition to prevent that from happening.

v2: Check page_flags instead of swap_storage

Thanks. I pushed them to amd-staging-drm-next. I think patch 1 should also go to -fixes. Alex?

Regards,
  Felix

Quoted 5 lines
Quoted 5 lines

---
  drivers/gpu/drm/ttm/ttm_bo.c | 3 ++-

  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines

drivers/gpu/drm/ttm/ttm_bo.c void ttm_bo_add_to_lru(struct ttm_buffer_object *bo) · line 177

Quoted 13 lines
drivers/gpu/drm/ttm/ttm_bo.c +2 -0
index 2eb71ff..62518b6 100644
@@ -170,7 +170,8 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
           list_add_tail(&bo->lru, &man->lru[bo->priority]);
           kref_get(&bo->list_kref);
   -        if (bo->ttm && !(bo->ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+        if (bo->ttm && !(bo->ttm->page_flags &
+                 (TTM_PAGE_FLAG_SG | TTM_PAGE_FLAG_SWAPPED))) {
               list_add_tail(&bo->swap,
                         &bo->glob->swap_lru[bo->priority]);
               kref_get(&bo->list_kref);

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

A message that is not in the archive (sent off-list or not yet received): 117acb40-1cc5-9ea0-0e64-5db554c8cf9b-5C7GfCeVMHo@public.gmane.org

#7 lore raw

________________________________
From: Kuehling, Felix
Sent: Thursday, January 18, 2018 4:12 PM
To: Koenig, Christian; [email protected]; [email protected]; He, Roger; Deucher, Alexander
Subject: Re: [PATCH 1/2] drm/ttm: Don't add swapped BOs to swap-LRU list

Quoted 6 lines · Christian König

Am 18.01.2018 um 17:56 schrieb Felix Kuehling:

Quoted 5 lines

A BO that's already swapped would be added back to the swap-LRU list for example if its validation failed under high memory pressure. This could later lead to swapping it out again and leaking previous swap storage.

Quoted 7 lines
Quoted 5 lines

This commit adds a condition to prevent that from happening.

v2: Check page_flags instead of swap_storage

Thanks. I pushed them to amd-staging-drm-next. I think patch 1 should also go to -fixes. Alex?

Yup, already planning on it.

Alex

Regards,
Felix

Quoted 5 lines
Quoted 5 lines
---
  drivers/gpu/drm/ttm/ttm_bo.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
Quoted 14 lines

drivers/gpu/drm/ttm/ttm_bo.c void ttm_bo_add_to_lru(struct ttm_buffer_object *bo) · line 177

Quoted 13 lines
drivers/gpu/drm/ttm/ttm_bo.c +2 -0
index 2eb71ff..62518b6 100644
@@ -170,7 +170,8 @@ void ttm_bo_add_to_lru(struct ttm_buffer_object *bo)
          list_add_tail(&bo->lru, &man->lru[bo->priority]);
          kref_get(&bo->list_kref);
  -        if (bo->ttm && !(bo->ttm->page_flags & TTM_PAGE_FLAG_SG)) {
+        if (bo->ttm && !(bo->ttm->page_flags &
+                 (TTM_PAGE_FLAG_SG | TTM_PAGE_FLAG_SWAPPED))) {
              list_add_tail(&bo->swap,
                        &bo->glob->swap_lru[bo->priority]);
              kref_get(&bo->list_kref);

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