public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: drm/ttm: Fix ttm_bo_shrink() infinite LRU walk on backup failure
Date: Sat, 16 May 2026 15:07:24 +1000	[thread overview]
Message-ID: <review-patch1-20260511162443.24352-1-thomas.hellstrom@linux.intel.com> (raw)
In-Reply-To: <20260511162443.24352-1-thomas.hellstrom@linux.intel.com>

Patch Review

**The bug (before the fix):**

The old code in `ttm_bo_util.c:1115-1129` did:
```c
if (bo->bulk_move) {
    spin_lock(&bdev->lru_lock);
    ttm_resource_del_bulk_move(bo->resource, bo);
    spin_unlock(&bdev->lru_lock);
}

lret = ttm_tt_backup(...);

if (lret <= 0 && bo->bulk_move) {
    spin_lock(&bdev->lru_lock);
    ttm_resource_add_bulk_move(bo->resource, bo);
    spin_unlock(&bdev->lru_lock);
}
```

The `del_bulk_move` before backup removes the resource from the bulk_move list. If backup fails, `add_bulk_move` re-adds it, but this can reinsert the resource at a position the LRU cursor hasn't passed yet, causing the cursor to re-encounter the same BO, leading to an infinite walk. Critically, no `ttm_resource_move_to_lru_tail()` was called on failure, so the resource never moved away from the cursor.

**The fix:**

```c
lret = ttm_tt_backup(...);

if (lret > 0) {
    spin_lock(&bdev->lru_lock);
    ttm_resource_del_bulk_move_unevictable(bo->resource, bo);
    ttm_resource_move_to_lru_tail(bo->resource);
    spin_unlock(&bdev->lru_lock);
}
```

- **Failure path**: No bulk_move manipulation at all. The resource stays in place, the cursor naturally advances past it. This is correct.
- **Success path**: Uses `del_bulk_move_unevictable` then `move_to_lru_tail`. This is necessary because after successful backup, `TTM_TT_FLAG_BACKED_UP` is set (`ttm_tt.c:292`), making `ttm_resource_unevictable()` return true. The regular `ttm_resource_del_bulk_move()` would be a **no-op** here since it checks `!ttm_resource_unevictable(res, bo)` and skips unevictable resources (`ttm_resource.c:291`). The `_unevictable` variant is essential to correctly remove the resource from bulk_move tracking during this evictable-to-unevictable transition.

**Correctness: Looks correct.** The approach is sound and matches the swapout fix pattern.

**Minor observations:**

1. **Dependency not stated in the commit message.** The patch references commit b2ed01e7ad as the analogous fix but doesn't explicitly note that `ttm_resource_del_bulk_move_unevictable()` is introduced by that commit. Adding a note (e.g., a "Depends-on:" tag or a mention in the commit body) would help patch management, especially given the `Cc: stable` tag — both patches need to land together in stable.

2. **`Assisted-by: GitHub_Copilot:claude-opus-4.6`** — This tag format is non-standard. The kernel community hasn't converged on a standardized AI-assistance tag; existing conventions lean toward something with the provider name not GitHub Copilot when the model is Anthropic's Claude. This is minor and a process/policy matter, not a code issue.

3. **No `move_to_lru_tail` on failure, unlike the swapout path.** The swapout path (`ttm_bo.c:1186-1189`) calls `move_to_lru_tail` even on failure. The shrink path omits this, which is fine: in the shrink caller (`xe_shrinker.c:82-83`), any negative return aborts the walk immediately (`if (lret < 0) return lret`), and a zero return simply means no pages freed so the cursor advances normally. The LRU tail movement on failure is unnecessary here. However, if you wanted maximum consistency with the swapout path, adding `move_to_lru_tail` on failure would be a defensive improvement to ensure the resource moves to the tail even if callers change in the future.

**Verdict:** The fix is correct and necessary. The main thing to ensure is that the dependency on `ttm_resource_del_bulk_move_unevictable()` is properly tracked for stable backports.

---
Generated by Claude Code Patch Reviewer

  parent reply	other threads:[~2026-05-16  5:07 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11 16:24 [PATCH] drm/ttm: Fix ttm_bo_shrink() infinite LRU walk on backup failure Thomas Hellström
2026-05-12 13:30 ` Matthew Auld
2026-05-13  7:20 ` kernel test robot
2026-05-13 10:24 ` kernel test robot
2026-05-16  5:07 ` Claude Code Review Bot [this message]
2026-05-16  5:07 ` Claude review: " Claude Code Review Bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=review-patch1-20260511162443.24352-1-thomas.hellstrom@linux.intel.com \
    --to=claude-review@example.com \
    --cc=dri-devel-reviews@example.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox