From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: gpu/buddy: Introduce __gpu_buddy_undo_splits() helper
Date: Mon, 25 May 2026 19:06:37 +1000 [thread overview]
Message-ID: <review-patch3-20260522092600.32818-4-francois.dugast@intel.com> (raw)
In-Reply-To: <20260522092600.32818-4-francois.dugast@intel.com>
Patch Review
**Correctness: Correct refactor, but one subtle behavioral change in `alloc_from_freetree`.**
The helper extracts the repeated pattern:
```c
static void __gpu_buddy_undo_splits(struct gpu_buddy *mm,
struct gpu_buddy_block *block)
{
struct gpu_buddy_block *buddy = __get_buddy(block);
if (buddy &&
(gpu_buddy_block_is_free(block) &&
gpu_buddy_block_is_free(buddy))) {
rbtree_remove(mm, block);
__gpu_buddy_free(mm, block, false);
}
}
```
For the three sites in `__alloc_range_bias`, `gpu_buddy_offset_aligned_allocation`, and `__alloc_range`, this is a direct extraction — those all had the `if (buddy && ...)` guard already.
**However**, in `alloc_from_freetree` (after patch 2's cleanup), the error path was:
```c
err_undo:
rbtree_remove(mm, block);
__gpu_buddy_free(mm, block, false);
```
— i.e., **unconditional** `rbtree_remove` + `__gpu_buddy_free`. Now it becomes:
```c
err_undo:
__gpu_buddy_undo_splits(mm, block);
```
which adds a **new guard** (`if buddy && both-free`). This is actually a tightening — if the buddy is not free or doesn't exist, the function now does nothing instead of unconditionally freeing.
**Is this correct?** When `split_block()` fails in `alloc_from_freetree`, the block is still FREE (split didn't complete). After the first successful split, the left child is marked free and the right child becomes `block` (via `block = block->right`). The right child is also marked free by `split_block()`. So after a failed split:
- `block` is FREE (the split that failed didn't change its state)
- `buddy` (left sibling) is FREE (created by the *previous* successful split)
So the guard `buddy && both-free` should be true in the normal case. But what about the *first* iteration failure? Then `block` is the original block from the tree — it has no buddy from splitting (the `__get_buddy` might return a pre-existing buddy). This seems safe: if there's no buddy or the buddy isn't free, we just skip the undo, and `__gpu_buddy_free` would handle the block via the `mark_free` path at the bottom anyway.
This is acceptable but the commit message could mention that `alloc_from_freetree` gains the buddy guard it previously lacked.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-05-25 9:06 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-22 9:25 [PATCH v4 0/5] gpu/buddy: Per-order free and used block scoreboards Francois Dugast
2026-05-22 9:25 ` [PATCH v4 1/5] gpu/buddy: Fix use-after-free in split_block() call sites Francois Dugast
2026-05-25 9:06 ` Claude review: " Claude Code Review Bot
2026-05-22 9:25 ` [PATCH v4 2/5] gpu/buddy: Remove redundant condition in alloc_from_freetree() error path Francois Dugast
2026-05-22 10:10 ` Matthew Auld
2026-05-25 9:06 ` Claude review: " Claude Code Review Bot
2026-05-22 9:25 ` [PATCH v4 3/5] gpu/buddy: Introduce __gpu_buddy_undo_splits() helper Francois Dugast
2026-05-25 9:06 ` Claude Code Review Bot [this message]
2026-05-22 9:25 ` [PATCH v4 4/5] gpu/buddy: Track per-order free blocks with a scoreboard Francois Dugast
2026-05-25 9:06 ` Claude review: " Claude Code Review Bot
2026-05-22 9:25 ` [PATCH v4 5/5] gpu/buddy: Track per-order used " Francois Dugast
2026-05-22 10:25 ` Arunpravin Paneer Selvam
2026-05-22 10:56 ` Matthew Auld
2026-05-25 9:06 ` Claude review: " Claude Code Review Bot
2026-05-25 9:06 ` Claude review: gpu/buddy: Per-order free and used block scoreboards 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-patch3-20260522092600.32818-4-francois.dugast@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