Skip to content

drm: img: implement imported dmabuf re-export#40

Merged
RevySR merged 1 commit into
revyos:th1520-ltsfrom
Icenowy:th1520-img-gpu-re-export-dmabuf
Jan 8, 2026
Merged

drm: img: implement imported dmabuf re-export#40
RevySR merged 1 commit into
revyos:th1520-ltsfrom
Icenowy:th1520-img-gpu-re-export-dmabuf

Conversation

@Icenowy

@Icenowy Icenowy commented Dec 31, 2025

Copy link
Copy Markdown

This allows re-exporting dmabufs that is exported to PVRSRV, which is needed by Zink renderonly.

The logic here is like drm_gem_prime_handle_to_fd().

Summary by Sourcery

Allow re-exporting dma-bufs that originate from imported dma-buf PMRs in the IMG Rogue DRM driver.

New Features:

  • Support re-exporting dma-bufs backed by PMRs of type PMR_TYPE_DMABUF, enabling external dma-buf reuse.

Enhancements:

  • Adjust PMR reference handling to distinguish between internally exported and externally imported dma-bufs, avoiding unnecessary unref operations.

This allows re-exporting dmabufs that is exported to PVRSRV, which is
needed by Zink renderonly.

The logic here is like drm_gem_prime_handle_to_fd().

Signed-off-by: Icenowy Zheng <uwu@icenowy.me>
@sourcery-ai

sourcery-ai Bot commented Dec 31, 2025

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Enable re-exporting imported dmabuf-backed PMRs by special-casing PMR_TYPE_DMABUF in PhysmemExportDmaBuf, reusing the existing dma_buf instead of creating a new export, while preserving refcounting and cleanup semantics based on whether the dma_buf is external or internally exported.

Sequence diagram for re-exporting imported dmabuf-backed PMR

sequenceDiagram
  participant Caller
  participant PhysmemExportDmaBuf
  participant PMR
  participant PMRWrapper
  participant dma_buf

  Caller->>PhysmemExportDmaBuf: request export for psPMR
  PhysmemExportDmaBuf->>PMR: PMR_IsExportable(psPMR)
  PMR-->>PhysmemExportDmaBuf: status
  PhysmemExportDmaBuf->>PMRWrapper: PhysmemGetOrCreatePMRWrapper(psPMR)
  PMRWrapper-->>PhysmemExportDmaBuf: psPMRWrapper

  PhysmemExportDmaBuf->>PMR: PMR_GetType(psPMR)
  PMR-->>PhysmemExportDmaBuf: PMR_TYPE_DMABUF
  PhysmemExportDmaBuf->>PMR: PhysmemGetDmaBuf(psPMR)
  PMR-->>PhysmemExportDmaBuf: psDmaBuf
  PhysmemExportDmaBuf->>dma_buf: get_dma_buf(psDmaBuf)
  Note over PhysmemExportDmaBuf,dma_buf: Reuse existing dma_buf and bump refcount

  PhysmemExportDmaBuf->>Caller: return file descriptor for reused dma_buf

  alt later failure while exporting fd
    PhysmemExportDmaBuf->>dma_buf: dma_buf_put(psDmaBuf)
    Note over PhysmemExportDmaBuf,PMR: PMRUnrefPMR is skipped because bIsExternalDmaBuf is true
  end
Loading

File-Level Changes

Change Details Files
Allow re-export of imported dmabufs instead of rejecting PMR_TYPE_DMABUF PMRs outright.
  • Remove the hard failure when attempting to export a PMR of type PMR_TYPE_DMABUF
  • Introduce a bIsExternalDmaBuf flag to distinguish imported dmabufs from internally exported ones
  • When PMR_GetType indicates PMR_TYPE_DMABUF, fetch the existing dma_buf via PhysmemGetDmaBuf and take a reference with get_dma_buf instead of exporting a new dma_buf
  • Skip PMRRefPMR for external dmabuf-backed PMRs and ensure PMRUnrefPMR is only called for non-external PMRs on failure paths
drivers/gpu/drm/img-rogue/physmem_dmabuf.c
Retain the existing export path for non-dmabuf PMRs while adjusting error handling and refcounting flow.
  • Move PMRRefPMR into the non-PMR_TYPE_DMABUF branch after creating or retrieving the PMR wrapper
  • Keep using DEFINE_DMA_BUF_EXPORT_INFO and dma_buf_export for non-external PMRs
  • Guard the fail_export cleanup to avoid unref on external dmabuf PMRs
drivers/gpu/drm/img-rogue/physmem_dmabuf.c

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@RevySR RevySR merged commit 42f0e03 into revyos:th1520-lts Jan 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants