Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9CF50606A32E for ; Tue, 1 Dec 2026 14:37:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=GJCAUBmY Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4248D10E9E0; Tue, 1 Dec 2026 14:37:19 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9CE3A10E010 for ; Tue, 1 Dec 2026 14:37:12 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 5720343F99; Tue, 1 Dec 2026 14:37:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1D4301F0092C; Tue, 1 Dec 2026 14:37:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796135832; bh=uP3sGHO3wvLHYsKvUdK3SwB/5RC548BsmC6lIKbzH6s=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=GJCAUBmYSoWx50FLhX+z/aI4RHTNAXZiImYmNNfypFsTbuLXcjTO/vbsUO8B/ksp2 KovPRLL1nHhQYx/vNxSqSO/mktaHC82YKwbpXQqR+16n4qkbhWtKZvi+AyKVsdFs0x xnnmOlBUpfB5tz28aKh716pNa4fjHQ6cnwA1jzkH/061mcWrnZiGchIcqFPx6aAYOZ j7enM9A+MbYr/jwNe0q4W2rs5WwQ2TEbJHjuiNSTI5hy9XCqhp/5HfjLRZfmH32L/I ODXKcuglYjf01rIncWTZOIoKrmhjDqSU0ts6LPmlEIA2xE8pkSnwdJMlG6ZQ+Xz+3c Fm/ovP2ySrYIg== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 3/3] Revert "drm/amdkfd: move TBA/TMA back to system memory" To: "James Zhu" , amd-gfx@lists.freedesktop.org In-Reply-To: <20261201141500.3346608-3-James.Zhu@amd.com> References: <20261201141500.3346608-1-James.Zhu@amd.com> <20261201141500.3346608-3-James.Zhu@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 01 Dec 2026 14:37:11 +0000 X-BeenThere: amd-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for AMD gfx List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "amd-gfx" X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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 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/a= md/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(struc= t kfd_process_device *pdd) > if (!dev->kfd->cwsr_enabled || !iosys_map_is_null(&qpd->cwsr_map) || !q= pd->cwsr_base) > return 0; > =20 > - if ((KFD_GC_VERSION(dev) =3D=3D IP_VERSION(9, 4, 2) || > - KFD_GC_VERSION(dev) =3D=3D IP_VERSION(9, 4, 3) || > - KFD_GC_VERSION(dev) =3D=3D IP_VERSION(9, 4, 4) || > - KFD_GC_VERSION(dev) =3D=3D IP_VERSION(9, 5, 0) || > - KFD_GC_VERSION(dev) =3D=3D IP_VERSION(12, 1, 0)) && > - !dev->adev->apu_prefer_gtt) > + if (KFD_GC_VERSION(dev) >=3D IP_VERSION(9, 4, 2) && !dev->adev->apu_pre= fer_gtt) > flags |=3D KFD_IOC_ALLOC_MEM_FLAGS_VRAM; > else > flags |=3D 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 |=3D AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED; amdgpu_bo_placement_from_domain(bo, domain); ... r =3D 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. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261201141500.3346= 608-1-James.Zhu@amd.com?part=3D3