From mboxrd@z Thu Jan 1 00:00:00 1970 From: Claude Code Review Bot To: dri-devel-reviews@example.com Subject: Claude review: RDMA/mlx5: get tph for p2p access when registering dma-buf mr Date: Tue, 05 May 2026 09:54:40 +1000 Message-ID: In-Reply-To: <20260430200704.352228-3-zhipingz@meta.com> References: <20260430200704.352228-1-zhipingz@meta.com> <20260430200704.352228-3-zhipingz@meta.com> X-Mailer: Claude Code Patch Reviewer Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Patch Review **Double `dma_buf_get` on the same fd** `get_tph_mr_dmabuf()` calls `dma_buf_get(fd)` to temporarily resolve the fd= just to query TPH metadata: ```c dmabuf =3D dma_buf_get(fd); if (IS_ERR(dmabuf)) return; ... dma_buf_put(dmabuf); ``` The same fd is resolved again later by the main MR registration path (`ib_u= mem_dmabuf_get_pinned` or similar). This is functionally correct but does a= n unnecessary extra get/put cycle. Consider whether the dma_buf pointer cou= ld be passed from the caller instead, though I understand it may not be ava= ilable at this point in the flow. **Direct callback invocation instead of helper** The code calls `dmabuf->ops->get_tph()` directly: ```c if (!dmabuf->ops->get_tph) goto end_dbuf_put; ret =3D dmabuf->ops->get_tph(dmabuf, &steering_tag, ph, st_width); ``` This is the standard pattern for optional dma-buf callbacks (same as how `p= in`/`unpin` are called). It would be worth considering whether a `dma_buf_g= et_tph()` inline helper in `` would be better for encapsul= ation, especially if other importers will use this callback. But for an ini= tial implementation with a single consumer, this is fine. **Error handling in `get_tph_mr_dmabuf` is correct** If `mlx5_st_alloc_index_by_tag` fails, `*ph` is reset to `MLX5_IB_NO_PH`: ```c ret =3D mlx5_st_alloc_index_by_tag(dev->mdev, steering_tag, st_index); if (ret) { *ph =3D MLX5_IB_NO_PH; ... } ``` `*st_index` was never modified by the failed call, so it retains the caller= 's default (`MLX5_MKC_PCIE_TPH_NO_STEERING_TAG_INDEX`). This is correct =E2= =80=94 a failed TPH query silently falls back to no-TPH behavior. **`ret =3D 0` initialization in `mlx5_st_create` is a real fix** Looking at the existing code, when the `xa_for_each` loop finds a cached ta= g match: ```c xa_for_each(&st->idx_xa, index, idx_data) { if (tag =3D=3D idx_data->tag) { refcount_inc(&idx_data->usecount); *st_index =3D index; goto end; } } ... end: mutex_unlock(&st->lock); return ret; // <-- was uninitialized on cache hit path ``` `ret` is genuinely uninitialized on the cache-hit `goto end` path. The `ret= =3D 0` init in the refactored `mlx5_st_alloc_index_by_tag` fixes this bug.= This is correct and should be called out more prominently =E2=80=94 it's a= real bug fix, not just a clang warning suppression. **Refactoring of `mlx5_st_alloc_index` is clean** The split into `mlx5_st_alloc_index_by_tag` (takes raw tag) + `mlx5_st_allo= c_index` (wraps with `pcie_tph_get_cpu_st`) is a straightforward factoring.= The original function body moves to `_by_tag`, and the original becomes a = thin wrapper. The `#else` stub for `!CONFIG_PCIE_TPH` is correctly added. **`MODULE_IMPORT_NS("DMA_BUF")` is needed** `dma_buf_get` is exported under the `DMA_BUF` namespace, so this is require= d. --- Generated by Claude Code Patch Reviewer