Skip to content

Amd: phytium: update phytium amd controller driver support to 6.6.0.4 - #2242

Open
wangchenlu2236 wants to merge 2 commits into
deepin-community:linux-6.6.yfrom
wangchenlu2236:amd-6.6.y
Open

wangchenlu2236 wants to merge 2 commits into
deepin-community:linux-6.6.yfrom
wangchenlu2236:amd-6.6.y

Conversation

@wangchenlu2236

@wangchenlu2236 wangchenlu2236 commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

This patches updates the support for phytium amd controller driver.
1.amd-ttm: amd gpu memory visibility for vm guest
2.amd-gem: Add VM_ALLOW_ANY_UNCACHED flag to mmap

Summary by Sourcery

Improve AMDGPU support on Phytium platforms by addressing guest memory visibility and GPU memory mapping compatibility.

New Features:

  • Enable uncached GEM mappings on Phytium SoCs to improve compatibility with D3D11 API remoting.

Bug Fixes:

  • Improve AMD GPU memory page lifetime handling during TTM population and unpopulation.

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.

Mainline: NA
Signed-off-by: Liu Tao <liutao@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Signed-off-by: Wang Chenlu <wangchenlu2236@phytium.com.cn>
In Phyfusion DirectX 11 API remoting, bad address error occurs in
qemu  when running some d3d11 demos. The patch fixed this issue.

Mainline: NA
Signed-off-by: Liu Tao <liutao@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Signed-off-by: Wang Chenlu <wangchenlu2236@phytium.com.cn>
@sourcery-ai

sourcery-ai Bot commented Nov 4, 2026 •

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

Reviewer's Guide

Updates the AMD GPU support for Phytium 6.6.0.4 by adding a SoC-specific uncached mmap workaround and balancing page references around TTM page population, helping guest memory visibility while avoiding address errors in D3D11 remoting.

Sequence diagram for Phytium AMD GPU mmap workaround

sequenceDiagram
    participant App as D3D11 remoting
    participant GEM as amdgpu_gem_object_mmap
    participant SoC as Phytium SoC
    participant TTM as drm_gem_ttm_mmap

    App->>GEM: amdgpu_gem_object_mmap
    GEM->>SoC: is_phytium_soc()
    alt Phytium SoC
        GEM->>GEM: vm_flags_set(VM_ALLOW_ANY_UNCACHED)
    end
    GEM->>TTM: drm_gem_ttm_mmap
    TTM-->>App: GPU buffer mapping
Loading

File-Level Changes

Change Details Files
Adds Phytium-specific uncached mmap handling for AMD GEM objects.
  • Includes the Phytium CPU-type interface only on Phytium builds.
  • Sets VM_ALLOW_ANY_UNCACHED for Phytium SoCs to support D3D11 API remoting address mappings.
drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
Adjusts AMD TTM page lifetime management during population and unpopulation.
  • Increments page references when assigning the device mapping during population.
  • Clears the mapping and decrements page references during unpopulation.
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

[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 dongert 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

@deepin-ci-robot

Copy link
Copy Markdown

Hi @wangchenlu2236. 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.

@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 found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c" line_range="269" />
<code_context>
+#ifdef CONFIG_ARCH_PHYTIUM
+	/*lt: workaround for bad address error with d3d11 api remoting*/
+	if (is_phytium_soc())
+		vm_flags_set(vma, VM_ALLOW_ANY_UNCACHED);
+#endif
 	return drm_gem_ttm_mmap(obj, vma);
</code_context>
<issue_to_address>
**Unsafe device memory attributes crash host**

When a guest maps a device PFN from an AMDGPU GEM buffer whose backing is unsafe for Normal-NC access on a Phytium host, `amdgpu_gem_object_mmap()` sets `VM_ALLOW_ANY_UNCACHED`, so KVM maps the device PFN as Normal-NC; guest access triggers an uncontained hardware fault and crashes the host.

Set `VM_ALLOW_ANY_UNCACHED` only for mappings whose backing is safe for Normal-NC access.
</issue_to_address>

### Comment 2
<location path="drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c" line_range="1208" />
<code_context>
-	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]);
+	}

</code_context>
<issue_to_address>
**Shared mappings see reused pages**

When a host or guest mapping remains active when TTM unpopulates its pages, `amdgpu_ttm_tt_unpopulate()` drops the added reference before `ttm_pool_free()` returns, clears, reuses, or frees the pages without waiting for external references, so the mapping sees changed contents or reclaimed memory.

Keep pages unavailable to the pool and defer freeing them until external mappings are gone.

Also at `drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:1174`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 Critical · Unsafe device memory attributes crash host

When a guest maps a device PFN from an AMDGPU GEM buffer whose backing is unsafe for Normal-NC access on a Phytium host, amdgpu_gem_object_mmap() sets VM_ALLOW_ANY_UNCACHED, so KVM maps the device PFN as Normal-NC; guest access triggers an uncontained hardware fault and crashes the host.

Set VM_ALLOW_ANY_UNCACHED only for mappings whose backing is safe for Normal-NC access.

Prompt for AI agents
In `drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c` at line 269:

**Unsafe device memory attributes crash host**

When a guest maps a device PFN from an AMDGPU GEM buffer whose backing is unsafe for Normal-NC access on a Phytium host, `amdgpu_gem_object_mmap()` sets `VM_ALLOW_ANY_UNCACHED`, so KVM maps the device PFN as Normal-NC; guest access triggers an uncontained hardware fault and crashes the host.

Set `VM_ALLOW_ANY_UNCACHED` only for mappings whose backing is safe for Normal-NC access.

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]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Shared mappings see reused pages

When a host or guest mapping remains active when TTM unpopulates its pages, amdgpu_ttm_tt_unpopulate() drops the added reference before ttm_pool_free() returns, clears, reuses, or frees the pages without waiting for external references, so the mapping sees changed contents or reclaimed memory.

Keep pages unavailable to the pool and defer freeing them until external mappings are gone.

Also at drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:1174.

Prompt for AI agents
In `drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c` at line 1208:

**Shared mappings see reused pages**

When a host or guest mapping remains active when TTM unpopulates its pages, `amdgpu_ttm_tt_unpopulate()` drops the added reference before `ttm_pool_free()` returns, clears, reuses, or frees the pages without waiting for external references, so the mapping sees changed contents or reclaimed memory.

Keep pages unavailable to the pool and defer freeing them until external mappings are gone.

Also at `drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:1174`.

Copilot AI 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.

🟡 Changes recommended

TTM can recycle higher-order blocks while KVM still holds non-head-page references, allowing a later put_page() to free pool-owned memory and cause corruption.

1 open issue
What changed in this PR

Updates AMDGPU’s memory-management paths to support GPU memory access from virtual-machine guests and improve D3D11 API remoting compatibility on Phytium platforms.

Changes:

  • Add page-reference increments and decrements during TTM population and unpopulation.
  • Set VM_ALLOW_ANY_UNCACHED for GEM mappings on detected Phytium SoCs.
File Description
drivers/​gpu/​drm/​amd/​amdgpu/​amdgpu_ttm.c Adjust page references around allocation-pool use to support guest memory access.
drivers/​gpu/​drm/​amd/​amdgpu/​amdgpu_gem.c Allow additional uncached KVM mapping types on Phytium systems.

Review effort: Max

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]);
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