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 AA659606A32C for ; Fri, 4 Dec 2026 20:39:55 +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=M4vsgQd1 Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4DCDE10E85A; Fri, 4 Dec 2026 20:39:50 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 239C910E85A for ; Fri, 4 Dec 2026 20:39:44 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id 0733F44824; Fri, 4 Dec 2026 20:39:44 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CC59F1F0093B; Fri, 4 Dec 2026 20:39:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796416783; bh=Zn2rUzO4u2pxmvIsMI0cAN+XKnk7LDOSxr6DqjPv3cg=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=M4vsgQd1/0adxR4o96CeLOPeBLYK3iUQ9piYI0ag31JAPRIo8qKT95k60A8GarCbK lEGG31x+Bg/1xdo+tegfKCrzFOQMEJxppGxqVT/ICLNyN5rfmYqXXDKawdJTX0xOaI qyrE3vNR6JnURrH63H0qnVA66vOJVSPLoou0wao16njb5uw4TWSdHInFhqigv54/KX 1/78g8y/ly6ydMqrEiJ3j9PcOjZcBtC/eGnb0gMolpZub20pLy8TzaqH8FMYKJlvUy QwBn8XDm4mOIeNYd/3xDWl2tOvW3wXksv28IJE8Vsb3prOAH1RsCZp+6YDXdDLu2J4 WOGU0X0+bJ/bQ== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] drm/amdgpu: wait for PT updates in amdgpu_vm_make_compute To: "Amir Shetaia" , amd-gfx@lists.freedesktop.org In-Reply-To: <20261204201649.375581-1-amir.shetaia@amd.com> References: <20261204201649.375581-1-amir.shetaia@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Fri, 04 Dec 2026 20:39:43 +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=-16.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,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: - [Medium] drm/amdgpu: BOOKKEEP wait in amdgpu_vm_make_compute() evicts KGD userqs - [Low] drm/amdgpu: Fixes tag cites 4247084057cf instead of 926c79ad6ecd -- commit f7d48a981689f9a016015e4327294adae6c1d421 Author: Amir Shetaia > drm/amdgpu: wait for PT updates in amdgpu_vm_make_compute > > amdgpu_vm_make_compute() switches a VM to CPU page table updates when > compute VMs use the CPU path (vm_update_mode, the default when all of > VRAM is CPU visible). Before switching it waits for the last SDMA > update/clear of the root PD with amdgpu_bo_sync_wait(). > > That helper goes through amdgpu_sync_resv(), which only iterates > DMA_RESV_USAGE_READ fences. Since commit 4247084057cf > ("drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP v2") page table updates add > their fence to the root reservation with DMA_RESV_USAGE_BOOKKEEP, so the > wait no longer covers the clear of the root PD issued at VM creation. > > A process that maps memory right after AMDKFD_IOC_ACQUIRE_VM can then > write a root PDE with the CPU before the pending SDMA clear of the root > PD has executed, and the clear wipes the entry. The GPU later takes a > not-present fault on the mapped address. We hit this as a CPC fault on a > user queue's write pointer page; walking the VM with UMR while the fault > was pending showed the root entry as 0x8000000000000000. Adding a short > delay after ACQUIRE_VM made the fault go away. > > Wait for all fences on the root reservation, including BOOKKEEP, before > switching to CPU updates. The dma_resv_wait_timeout() result is kept in > a long, since MAX_SCHEDULE_TIMEOUT does not fit in an int. > > Tested on gfx1201 with a v7.0 based kernel and a reproducer that > acquires a VM, maps buffers and creates an SDMA queue right away: > 8 of 8 runs faulted without this patch, 0 of 8 with it. > > Fixes: 4247084057cf ("drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP v2") > Signed-off-by: Amir Shetaia [Severity: Low] Should the Fixes tag (and commit message) cite 926c79ad6ecd ("drm/amdgpu: promote the implicit sync to the dependent read fences") instead of 4247084057cf ("drm/amdgpu: use DMA_RESV_USAGE_BOOKKEEP v2")? amdgpu_sync_resv() still iterated DMA_RESV_USAGE_BOOKKEEP fences until the 2025 commit changed it to DMA_RESV_USAGE_READ, so amdgpu_bo_sync_wait() kept waiting on PT updates prior to that. Citing the earlier commit can cause stable backport tooling to flag unaffected LTS kernels. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd= /amdgpu/amdgpu_vm.c > index a3758c654dd42..130dbcbf3c85c 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c [ ... ] > @@ -2721,11 +2722,16 @@ int amdgpu_vm_make_compute(struct amdgpu_device *= adev, struct amdgpu_vm *vm) > "CPU update of VM recommended only for large BAR system\n"); > =20 > if (vm->use_cpu_for_update) { > - /* Sync with last SDMA update/clear before switching to CPU */ > - r =3D amdgpu_bo_sync_wait(vm->root.bo, > - AMDGPU_FENCE_OWNER_UNDEFINED, true); > - if (r) > + /* Sync with last SDMA update/clear before switching to CPU. > + * PT updates are BOOKKEEP fences, amdgpu_bo_sync_wait() skips them. > + */ > + wait =3D dma_resv_wait_timeout(vm->root.bo->tbo.base.resv, > + DMA_RESV_USAGE_BOOKKEEP, true, > + MAX_SCHEDULE_TIMEOUT); > + if (wait < 0) { > + r =3D wait; > goto unreserve_bo; > + } [Severity: Medium] Can waiting on all DMA_RESV_USAGE_BOOKKEEP fences here trigger an unintended eviction of active KGD user queues? If a process creates a KGD user queue on a DRM render fd before calling AMDKFD_IOC_ACQUIRE_VM on it, amdgpu_evf_mgr_attach_fence() attaches an unsignaled amdgpu_eviction_fence to vm->root.bo with DMA_RESV_USAGE_BOOKKEEP. Waiting on that fence enables signaling and schedules suspend_work -> amdgpu_userq_evict(), draining every active user queue's last_fence uninterruptibly and unmapping all user queues via MES while vm->root.bo is reserved, stalling AMDKFD_IOC_ACQUIRE_VM until they are evicted and later remapped. Switching to amdgpu_vm_cpu_funcs only needs to wait for kernel/move fences and pending SDMA PT updates (AMDGPU_FENCE_OWNER_VM), and can skip waiting for SDMA updates when vm->update_funcs is already &amdgpu_vm_cpu_funcs. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261204201649.3755= 81-1-amir.shetaia@amd.com?part=3D1