From: Kornel Dulęba <[email protected]>

When running CtsCameraTestCases on a memory constrained, 4GB device the
following list corruption oops was consistently observed:

list_del corruption. prev->next should be ffff9ebe1ce42ea8, but was 
ffff9ebdf741fea8. (prev=ffff9ebe1ce43aa8)

After adding printfs in multiple places it was concluded that
bo->pinned_link was already a part of a list when xe_bo_pin_external
tried adding it to xe->pinned.late.external.
To fix this add a list_empty check and a WARN_ONCE in case the list is
in fact not empty.
With this addition the CtsCameraTestCases can now complete with no
kernel crashes.

Test: atest CtsCameraTestCases
Signed-off-by: Kornel Dulęba <[email protected]>
---
 drivers/gpu/drm/xe/xe_bo.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index c5989db950f7..cc5a4ff64791 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -2762,7 +2762,14 @@ int xe_bo_pin_external(struct xe_bo *bo, bool in_place, 
struct drm_exec *exec)
                }
 
                spin_lock(&xe->pinned.lock);
-               list_add_tail(&bo->pinned_link, &xe->pinned.late.external);
+               if (list_empty(&bo->pinned_link)) {
+                       list_add_tail(&bo->pinned_link,
+                                     &xe->pinned.late.external);
+               } else {
+                       WARN_ONCE(true,
+                                 "pinned_link already added to a list, 
bo->ttm.pin_count: %d\n",
+                                 bo->ttm.pin_count);
+               }
                spin_unlock(&xe->pinned.lock);
        }
 
-- 
2.34.1

Reply via email to