AMD-GFX Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "James Zhu" <James.Zhu@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 3/3] Revert "drm/amdkfd: move TBA/TMA back to system memory"
Date: Tue, 01 Dec 2026 14:37:11 +0000	[thread overview]
Message-ID: <sashiko-outbox-243500@kernel.org> (raw)
In-Reply-To: <20261201141500.3346608-3-James.Zhu@amd.com>

Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/amdkfd: stale GPUVM PTEs and SDMA race in
  kfd_process_device_init_cwsr_dgpu()
- [High] drm/amdkfd: missing HDP flush after VRAM CWSR writes in
  kfd_process.c
--

commit 38f74754f766d51b400ed1883826540572c8a9ac
Author: James Zhu <James.Zhu@amd.com>

Revert "drm/amdkfd: move TBA/TMA back to system memory"

This commit reverts moving the CWSR TBA/TMA buffer to system memory,
placing it back in VRAM for all GFX 9.4.2 and newer GPUs unless
apu_prefer_gtt is set.

Link: https://gitlab.freedesktop.org/drm/amd/-/work_items/6116

> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> index 4508fbd5626c0..ebae27e75575c 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> @@ -1657,12 +1657,7 @@ static int kfd_process_device_init_cwsr_dgpu(struct kfd_process_device *pdd)
>  	if (!dev->kfd->cwsr_enabled || !iosys_map_is_null(&qpd->cwsr_map) || !qpd->cwsr_base)
>  		return 0;
>  
> -	if ((KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 2) ||
> -	     KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 3) ||
> -	     KFD_GC_VERSION(dev) == IP_VERSION(9, 4, 4) ||
> -	     KFD_GC_VERSION(dev) == IP_VERSION(9, 5, 0) ||
> -	     KFD_GC_VERSION(dev) == IP_VERSION(12, 1, 0)) &&
> -	    !dev->adev->apu_prefer_gtt)
> +	if (KFD_GC_VERSION(dev) >= IP_VERSION(9, 4, 2) && !dev->adev->apu_prefer_gtt)
>  		flags |= KFD_IOC_ALLOC_MEM_FLAGS_VRAM;
>  	else
>  		flags |= KFD_IOC_ALLOC_MEM_FLAGS_GTT;

[Severity: High]
Can this leave the GPUVM PTEs for qpd->cwsr_base pointing to freed
invisible VRAM on GFX10, GFX11, or GFX12.0 dGPUs running with a small BAR?

kfd_process_device_init_cwsr_dgpu() sets KFD_IOC_ALLOC_MEM_FLAGS_VRAM
without KFD_IOC_ALLOC_MEM_FLAGS_PUBLIC.  In kfd_process_alloc_gpuvm(),
amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu() creates the BO without
AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED, so TTM places it top-down in
CPU-invisible VRAM (above visible_pfn), and
amdgpu_amdkfd_gpuvm_map_memory_to_gpu() programs the process GPUVM PTEs
with that invisible-VRAM address.

Immediately after, kfd_process_alloc_gpuvm() calls
amdgpu_amdkfd_gpuvm_map_bo_to_kernel() -> amdgpu_bo_pin():

drivers/gpu/drm/amd/amdgpu/amdgpu_object.c:amdgpu_bo_pin() {
	...
	/* force to pin into visible video ram */
	if (!(bo->flags & AMDGPU_GEM_CREATE_NO_CPU_ACCESS))
		bo->flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
	amdgpu_bo_placement_from_domain(bo, domain);
	...
	r = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
}

ttm_bo_validate() migrates the BO to visible VRAM via an asynchronous SDMA
blit and frees the invisible-VRAM blocks, but nothing updates the GPUVM
PTEs afterward or waits for the move fence before
kfd_process_device_fill_cwsr() writes the trap handler via MMIO.  The CPU
writes can race with the SDMA move, and wave preemption or trap execution
will fetch TBA/TMA from the stale invisible-VRAM address, causing VM
faults or GPU hangs.  Passing KFD_IOC_ALLOC_MEM_FLAGS_PUBLIC when
allocating in VRAM would place the BO in visible VRAM from the start.

[Severity: High]
Should CPU writes to qpd->cwsr_map flush HDP when the CWSR buffer is in
VRAM?

In kfd_process_restore_cwsr(), the driver flushes HDP after
kfd_process_device_fill_cwsr() so the GPU sees the CPU MMIO writes to
VRAM.  However, kfd_process_device_init_cwsr_dgpu(),
kfd_process_set_trap_handler(), and kfd_process_set_trap_debug_flag()
write the trap handler ISA and first-level TMA fields through
qpd->cwsr_map without calling amdgpu_device_flush_hdp().  On GFX10, GFX11,
and GFX12.0 dGPUs (which this patch switches from GTT to VRAM), MQDs live
in GTT rather than VRAM, so queue creation and debugger attach/detach do
not flush HDP either, allowing the SQ to read stale or uninitialized
TBA/TMA contents from VRAM.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261201141500.3346608-1-James.Zhu@amd.com?part=3

  reply	other threads:[~2026-12-01 14:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 14:14 [PATCH 1/3] drm/amdgpu: clear in_runpm when runtime suspend fails in prepare James Zhu
2026-12-01 14:14 ` [PATCH 2/3] drm/amdkfd: rebuild CWSR TBA/TMA in VRAM after system resume James Zhu
2026-12-01 14:15 ` [PATCH 3/3] Revert "drm/amdkfd: move TBA/TMA back to system memory" James Zhu
2026-12-01 14:37   ` sashiko-bot [this message]
2026-12-01 14:28 ` [PATCH 1/3] drm/amdgpu: clear in_runpm when runtime suspend fails in prepare sashiko-bot

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=sashiko-outbox-243500@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=James.Zhu@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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