From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: udmabuf: Do not create malformed scatterlists
Date: Sat, 14 Mar 2026 06:43:42 +1000 [thread overview]
Message-ID: <review-patch1-0-v1-42779f29381a+4b9-udmabuf_sg_jgg@nvidia.com> (raw)
In-Reply-To: <0-v1-42779f29381a+4b9-udmabuf_sg_jgg@nvidia.com>
Patch Review
**Correctness of the core fix:**
The key change in `get_sg_table()` replaces:
```c
ret = sg_alloc_table(sg, ubuf->pagecount, GFP_KERNEL);
...
for_each_sg(sg->sgl, sgl, ubuf->pagecount, i)
sg_set_folio(sgl, ubuf->folios[i], PAGE_SIZE, ubuf->offsets[i]);
```
with:
```c
ret = sg_alloc_table_from_pages(sg, ubuf->pages, ubuf->pagecount, 0,
ubuf->pagecount << PAGE_SHIFT, GFP_KERNEL);
```
This is correct. `sg_alloc_table_from_pages()` will merge contiguous pages into single scatterlist entries, which is the expected behavior. The old code allocated one SG entry per 4K page and set each individually, which produced a valid-looking but semantically broken scatterlist (no coalescing, and the `sg_set_folio()` offset bug on large folios).
**Data structure change:**
Replacing `struct folio **folios` + `pgoff_t *offsets` with `struct page **pages` is appropriate. The page pointers are obtained via `folio_page()` in `udmabuf_pin_folios()`:
```c
ubuf->pages[upgcnt] = folio_page(folios[cur_folio],
subpgoff >> PAGE_SHIFT);
```
This correctly extracts the tail page at the right sub-page offset within the folio. The folio pin tracking remains via the separate `pinned_folios` array, which is unchanged — this is fine since `unpin_folio()` works on the head folio.
**vmap_udmabuf simplification:**
The old code allocated a temporary `pages` array and populated it from `folios[]`+`offsets[]` just to call `vm_map_ram()`. Now it passes `ubuf->pages` directly. This is a nice cleanup that removes an allocation and avoids a potential `-ENOMEM` failure path.
**Comment nit (very minor):**
The comment update at line 31-32 says:
```c
* Unlike pages, pinned_folios is only used for unpin.
```
The grammar "Unlike pages" is slightly awkward — it could be read as "pages are used for unpin too" when the intent is "pages is used for more than just unpin; pinned_folios is only for unpin." This is a pre-existing comment pattern that was just mechanically updated from "folios" to "pages", so not really an issue introduced by this patch.
**No issues found.** The patch is a clean, correct fix for a real bug with a good Fixes tag and proper attribution.
---
Generated by Claude Code Patch Reviewer
prev parent reply other threads:[~2026-03-13 20:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-13 17:41 [PATCH] udmabuf: Do not create malformed scatterlists Jason Gunthorpe
2026-03-13 20:43 ` Claude review: " Claude Code Review Bot
2026-03-13 20:43 ` Claude Code Review Bot [this message]
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-0-v1-42779f29381a+4b9-udmabuf_sg_jgg@nvidia.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