Skip to content

amdgpu: phytium: update phytium amdgpu controller driver support to 6.6.0.4#1666

Open
zhangfuxiang123 wants to merge 2 commits intodeepin-community:linux-6.6.yfrom
zhangfuxiang123:amdgpu-6.6.y
Open

amdgpu: phytium: update phytium amdgpu controller driver support to 6.6.0.4#1666
zhangfuxiang123 wants to merge 2 commits intodeepin-community:linux-6.6.yfrom
zhangfuxiang123:amdgpu-6.6.y

Conversation

@zhangfuxiang123
Copy link
Copy Markdown
Contributor

@zhangfuxiang123 zhangfuxiang123 commented May 7, 2026

This patches updates the support for phytium amdgpu controller driver.

  1. Add VM_ALLOW_ANY_UNCACHED flag to mmap
  2. amd gpu memory visibility for vm guest

Summary by Sourcery

Update the Phytium-specific amdgpu driver handling for GEM mappings and TTM page management.

Bug Fixes:

  • Increment and decrement TTM page references during populate and unpopulate to ensure correct lifetime management of amdgpu pages.

Enhancements:

  • Enable VM_ALLOW_ANY_UNCACHED for GEM mmap on Phytium SoCs to avoid bad address issues with D3D11 API remoting.

In Phyfusion DirectX 11 API remoting, bad address error occurs in
qemu  when running some d3d11 demos. The patch fixed this issue.

Signed-off-by: Zhang Fuxiang <zhangfuxiang2144@phytium.com.cn>
Signed-off-by: Liu Tao <liutao@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
With phytium virtual gpu acceleration method in qemu windows guest OS,
guest OS driver needs to share GPU device memory with host and requires
the shared buffer mapping remains valid, but the ttm map implemenataion
did not account for this usecase. So we add a ref count for every pages
of the shared buffer.

Signed-off-by: Zhang Fuxiang <zhangfuxiang2144@phytium.com.cn>
Signed-off-by: Liu Tao <liutao@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
@deepin-ci-robot
Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign opsiff for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 7, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the Phytium-specific AMDGPU GEM mmap behavior to allow uncached mappings on Phytium SoCs and adjusts TTM page handling by explicitly managing page reference counts when populating/unpopulating TTM translation tables, improving compatibility with kernel 6.6.0.4 and VM guest visibility.

Sequence diagram for updated amdgpu_gem_object_mmap behavior on Phytium SoCs

sequenceDiagram
    actor UserProcess
    participant VFS
    participant DRMCore
    participant amdgpu_gem_object_mmap
    participant is_phytium_soc
    participant drm_gem_ttm_mmap

    UserProcess->>VFS: mmap on amdgpu GEM file
    VFS->>DRMCore: drm_gem_mmap
    DRMCore->>amdgpu_gem_object_mmap: amdgpu_gem_object_mmap(obj, vma)
    amdgpu_gem_object_mmap->>amdgpu_gem_object_mmap: check VM_SHARED and VM_ACCESS_FLAGS

    alt CONFIG_ARCH_PHYTIUM enabled
        amdgpu_gem_object_mmap->>is_phytium_soc: is_phytium_soc()
        alt running_on_phytium_soc
            is_phytium_soc-->>amdgpu_gem_object_mmap: true
            amdgpu_gem_object_mmap->>amdgpu_gem_object_mmap: vm_flags_set(vma, VM_ALLOW_ANY_UNCACHED)
        else not_phytium_soc
            is_phytium_soc-->>amdgpu_gem_object_mmap: false
        end
    end

    amdgpu_gem_object_mmap->>drm_gem_ttm_mmap: drm_gem_ttm_mmap(obj, vma)
    drm_gem_ttm_mmap-->>DRMCore: mmap result
    DRMCore-->>VFS: mmap result
    VFS-->>UserProcess: mapping established
Loading

File-Level Changes

Change Details Files
Allow uncached GEM mmap mappings on Phytium SoCs to work around bad address errors.
  • Conditionally include Phytium CPU type header when CONFIG_ARCH_PHYTIUM is enabled.
  • In amdgpu_gem_object_mmap, when running on a Phytium SoC, set VM_ALLOW_ANY_UNCACHED on the VMA before delegating to drm_gem_ttm_mmap.
  • Keep existing access flag checks and behavior unchanged for non-Phytium platforms.
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
Explicitly manage page reference counts for TTM pages used by AMDGPU, aligning populate/unpopulate with expected lifetime semantics.
  • In amdgpu_ttm_tt_populate, wrap the page mapping assignment loop in braces and increment the reference count for each page after assigning the device mapping.
  • In amdgpu_ttm_tt_unpopulate, wrap the page unmapping loop in braces and decrement the reference count for each page after clearing the device mapping.
  • Leave external TTM buffer handling unchanged by early-returning when TTM_TT_FLAG_EXTERNAL is set.
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.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

@deepin-ci-robot
Copy link
Copy Markdown

Hi @zhangfuxiang123. Thanks for your PR.

I'm waiting for a deepin-community member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The addition of VM_ALLOW_ANY_UNCACHED under CONFIG_ARCH_PHYTIUM is tightly coupled to is_phytium_soc(); consider adding a brief comment explaining why the generic flag is safe for all Phytium SoCs and not gated on more specific hardware capabilities to avoid future misuse.
  • In amdgpu_ttm_tt_populate/unpopulate, the new page_ref_inc/dec() calls assume every entry in ttm->pages[] is non-NULL and valid; if there are code paths where sparse or partially populated arrays are possible, you may want to guard these calls with a NULL check or document the invariant.
  • The explicit page_ref_inc/dec() in the TTM populate/unpopulate paths change the lifetime semantics of these pages; consider adding a short code comment summarizing the ownership model (who holds the extra ref and when it’s dropped) to avoid future double-free or leak regressions if this code is refactored.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The addition of VM_ALLOW_ANY_UNCACHED under CONFIG_ARCH_PHYTIUM is tightly coupled to is_phytium_soc(); consider adding a brief comment explaining why the generic flag is safe for all Phytium SoCs and not gated on more specific hardware capabilities to avoid future misuse.
- In amdgpu_ttm_tt_populate/unpopulate, the new page_ref_inc/dec() calls assume every entry in ttm->pages[] is non-NULL and valid; if there are code paths where sparse or partially populated arrays are possible, you may want to guard these calls with a NULL check or document the invariant.
- The explicit page_ref_inc/dec() in the TTM populate/unpopulate paths change the lifetime semantics of these pages; consider adding a short code comment summarizing the ownership model (who holds the extra ref and when it’s dropped) to avoid future double-free or leak regressions if this code is refactored.

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.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates AMDGPU’s Phytium-specific handling around GEM mmap flags and TTM page lifecycle management, aiming to improve VM guest memory visibility and avoid mmap “bad address” issues on Phytium SoCs.

Changes:

  • Adds per-page refcount adjustments during TTM TT populate/unpopulate.
  • Sets VM_ALLOW_ANY_UNCACHED on GEM mmap for Phytium platforms (guarded by CONFIG_ARCH_PHYTIUM).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c Adds page refcount inc/dec in TTM populate/unpopulate paths.
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c Adds Phytium-specific mmap flag handling and a new arch header include.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +1151 to +1154
for (i = 0; i < ttm->num_pages; ++i) {
ttm->pages[i]->mapping = bdev->dev_mapping;
page_ref_inc(ttm->pages[i]);
}
for (i = 0; i < ttm->num_pages; ++i)
for (i = 0; i < ttm->num_pages; ++i) {
ttm->pages[i]->mapping = NULL;
page_ref_dec(ttm->pages[i]);
Comment on lines +46 to +49
#ifdef CONFIG_ARCH_PHYTIUM
#include <asm/phytium_cputype.h>
#endif


#ifdef CONFIG_ARCH_PHYTIUM
/*lt: workaround for bad address error with d3d11 api remoting*/
if (is_phytium_soc())
vm_flags_clear(vma, VM_MAYWRITE);

#ifdef CONFIG_ARCH_PHYTIUM
/*lt: workaround for bad address error with d3d11 api remoting*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants