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: iommufd: take dma_resv lock before dma_buf_unpin() in release path
Date: Wed, 27 May 2026 14:56:39 +1000	[thread overview]
Message-ID: <review-patch1-20260526111034.4079-1-Ankit.Soni@amd.com> (raw)
In-Reply-To: <20260526111034.4079-1-Ankit.Soni@amd.com>

Patch Review

**Correctness: Good.**

The patch adds the missing `dma_resv_lock()`/`dma_resv_unlock()` bracket around `dma_buf_unpin()`:

```c
+		dma_resv_lock(dmabuf->resv, NULL);
 		dma_buf_unpin(pages->dmabuf.attach);
+		dma_resv_unlock(dmabuf->resv);
 		dma_buf_detach(dmabuf, pages->dmabuf.attach);
```

This is correct for several reasons:

1. **`dma_buf_unpin()` requires the lock** — confirmed by `dma_resv_assert_held(dmabuf->resv)` at `drivers/dma-buf/dma-buf.c:1136`.

2. **`dma_buf_detach()` is correctly kept outside the locked region** — it acquires `dma_resv_lock` internally (`dma-buf.c:1078`), so holding it around `dma_buf_detach()` would deadlock since `dma_resv_lock` is not recursive.

3. **Symmetry with `iopt_map_dmabuf()`** — the pin path at `pages.c:1495-1513` holds `dma_resv_lock` around `dma_buf_pin()` and releases it before `dma_buf_detach()` in the error path (`pages.c:1519-1523`). This patch mirrors that exact pattern.

4. **`dma_resv_lock()` return value** — `dma_resv_lock(resv, NULL)` with a NULL context cannot return `-EDEADLK` (that only occurs with ww_acquire_ctx-based contention management). It can only block or succeed, so ignoring the return value is acceptable here. This is consistent with how `iopt_map_dmabuf()` and `dma_buf_detach()` both call it.

5. **No ordering concern with `pages->mutex`** — the function is called from `kref_put`, meaning the refcount has hit zero. No other code path can hold `pages->mutex` for this object simultaneously, so there's no lock ordering issue in practice. The lockdep annotation in `iopt_map_dmabuf()` (taking `pages->mutex` inside `dma_resv_lock`) is satisfied trivially since the mutex isn't held here.

**Minor observations (not blocking):**

- The `Fixes:` tag references `8c5f9645c389 ("iommufd: Add dma_buf_pin()")` which is appropriate — that's the commit that introduced the `dma_buf_unpin()` call in this path without the required locking.

- The patch has both `Reported-by` and `Signed-off-by` from the same author, which is fine — the author found and fixed the bug.

- A `Cc: stable@vger.kernel.org` tag could be appropriate given the `Fixes:` tag, but the maintainer can add that at merge time.

**No issues found. The fix is minimal, correct, and well-justified.**

---
Generated by Claude Code Patch Reviewer

      parent reply	other threads:[~2026-05-27  4:56 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-26 11:10 [PATCH] iommufd: take dma_resv lock before dma_buf_unpin() in release path Ankit Soni
2026-05-26 12:26 ` Jason Gunthorpe
2026-05-26 15:34   ` Ankit Soni
2026-05-27  4:56 ` Claude review: " Claude Code Review Bot
2026-05-27  4:56 ` 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-20260526111034.4079-1-Ankit.Soni@amd.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