From mboxrd@z Thu Jan 1 00:00:00 1970 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 16548606A334 for ; Mon, 30 Nov 2026 06:48:01 +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=mqKXV1AV Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A214110E08A; Mon, 30 Nov 2026 06:47:55 +0000 (UTC) Received: from sea.source.kernel.org (sea.source.kernel.org [172.234.252.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 74ABF10E08A for ; Mon, 30 Nov 2026 06:47:49 +0000 (UTC) Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id B2FA541874; Mon, 30 Nov 2026 06:47:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 815D91F000C1; Mon, 30 Nov 2026 06:47:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796021268; bh=S0sHEGIAzFreuOi5N2sKDi0et3niSu43f00vXuql4jI=; h=From:Subject:Reply-To:To:In-Reply-To:References:Date; b=mqKXV1AV6nf6b3olR8IVtHH09BvEUmdY8+iNUbQJBLP+sOg/cT0ue9JtugLyq1hWc hKU21xFkFHB6Xo5Cyo51u5LBNYR5l+iTjDkGCzYTT+uyz5/Gg9YWiDhocx9ND9Le00 qt71ev4aWURxW1wUKBvD8Pn9pcUuiiDmRlGSxDPbrWKQTRnjJE2+GZ8+/VcCADmB/X 7MAuSmKAf0RfsMxj/yjbFCpd3By/Sik06hfehB5V0318xQF9vFIGiiGZd86hho18sN WRO0oiuYU9Ao7R0EWe0UBgOc88KLe+G37aq98eADM9wnIgW/e0NlT45enUc/sT+xkr 5XeKRH7jWdyCw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH V2 2/2] drm/amdgpu: validate the WPTR BO before handing its address to the MES To: "Jesse Zhang" , amd-gfx@lists.freedesktop.org In-Reply-To: <20261130062604.1921479-2-Jesse.Zhang@amd.com> References: <20261130062604.1921479-1-Jesse.Zhang@amd.com> <20261130062604.1921479-2-Jesse.Zhang@amd.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 06:47:48 +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/amdgpu: non-GTT WPTR BO validation in mes_userq_create_wptr_mapping() - [Medium] drm/amdgpu: WPTR BO eviction window in mes_userq_create_wptr_mapping() -- commit 119f0cb948c33ef03d377ba9eecfb939c5ae5cb0 Author: Jesse Zhang drm/amdgpu: validate the WPTR BO before handing its address to the MES This commit validates the userqueue WPTR buffer object before allocating GART space and attaches the eviction fence directly if it has not yet signaled. > diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c b/drivers/gpu/drm= /amd/amdgpu/mes_userqueue.c > index 3d4bc3a902a32..48f2e66dcb27e 100644 > --- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c > +++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c > @@ -37,10 +37,12 @@ mes_userq_create_wptr_mapping(struct amdgpu_device *a= dev, > struct amdgpu_usermode_queue *queue, > uint64_t wptr) > { > + struct ttm_operation_ctx ctx =3D { false, false }; > struct amdgpu_bo_va_mapping *wptr_mapping; > struct amdgpu_userq_obj *wptr_obj =3D &queue->wptr_obj; > struct amdgpu_bo *obj; > struct amdgpu_vm *vm =3D queue->vm; > + struct dma_fence *ev_fence; > struct drm_exec exec; > int ret; > =20 > @@ -79,12 +81,19 @@ mes_userq_create_wptr_mapping(struct amdgpu_device *a= dev, > ret =3D -EINVAL; > goto fail_map; > } > - /* Keep WPTR BO under eviction-fence control instead of pinning. */ > - ret =3D amdgpu_evf_mgr_attach_fence(&uq_mgr_to_fpriv(uq_mgr)->evf_mgr, = wptr_obj->obj); > - if (ret) { > - DRM_ERROR("Failed to attach eviction fence to wptr bo. ret %d\n", ret); > + > + /* The BO may have been evicted, it needs a GPU address for the MES */ > + amdgpu_bo_placement_from_domain(wptr_obj->obj, wptr_obj->obj->allowed_d= omains); > + ret =3D ttm_bo_validate(&wptr_obj->obj->tbo, &wptr_obj->obj->placement,= &ctx); > + if (ret) > goto fail_map; > - } [Severity: High] Does validating wptr_obj->obj against wptr_obj->obj->allowed_domains instead of AMDGPU_GEM_DOMAIN_GTT allow a non-GTT WPTR BO to bypass GART binding? Before commit 7264bc10c7c6 ("drm/amdgpu: dont pin wptr bo instead use eviction fence"), amdgpu_bo_pin(wptr_obj->obj, AMDGPU_GEM_DOMAIN_GTT) forced the BO into TTM_PL_TT. If userspace supplies a 1-page WPTR BO created with AMDGPU_GEM_DOMAIN_CPU (or AMDGPU_GEM_DOMAIN_VRAM), ttm_bo_validate() now leaves it in TTM_PL_SYSTEM (resource->start =3D=3D 0) or places it in non-contiguous TTM_PL_VRAM. amdgpu_ttm_alloc_gart() then returns 0 without binding GART because bo->resource->start is not AMDGPU_BO_INVALID_OFFSET, and amdgpu_bo_gpu_offset() triggers WARN_ON_ONCE() and hands an invalid GPU address to MES, causing page faults and GPU resets. > + > + /* The BO is already validated; only attach the eviction fence. */ > + ev_fence =3D amdgpu_evf_mgr_get_fence(&uq_mgr_to_fpriv(uq_mgr)->evf_mgr= ); > + if (!dma_fence_is_signaled(ev_fence)) > + dma_resv_add_fence(wptr_obj->obj->tbo.base.resv, ev_fence, > + DMA_RESV_USAGE_BOOKKEEP); > + dma_fence_put(ev_fence); > =20 > ret =3D amdgpu_ttm_alloc_gart(&wptr_obj->obj->tbo); > if (ret) { [Severity: Medium] When ev_fence is already signaled, can wptr_obj->obj be evicted again after drm_exec_fini() unlocks it and before amdgpu_userq_create() runs amdgpu_userq_ensure_ev_fence()? CPU0 CPU1 (GTT eviction) amdgpu_userq_create() mes_userq_mqd_create() mes_userq_create_wptr_mapping() ttm_bo_validate() /* ev_fence is signaled, not added */ amdgpu_ttm_alloc_gart() wptr_obj.gpu_addr =3D amdgpu_bo_gpu_offset() drm_exec_fini(&exec) ttm_bo_evict() /* evicts wptr_obj->obj to SYSTE= M, * freeing its GART range */ amdgpu_userq_ensure_ev_fence() amdgpu_userq_vm_validate_and_restore_queue() /* validates BO back to TTM_PL_TT with * start =3D AMDGPU_BO_INVALID_OFFSET; * queue is not in uq_mgr->userq_xa yet, * so GART re-bind is skipped */ amdgpu_userq_map_helper() mes_userq_map() <-- passes stale wptr_obj.gpu_addr to MES In amdgpu_userq_create(), xa_alloc(&uq_mgr->userq_xa, ...) runs after amdgpu_userq_ensure_ev_fence() and amdgpu_userq_map_helper(). Because amdgpu_userq_vm_validate_and_restore_queue() only re-runs amdgpu_ttm_alloc_gart() and refreshes wptr_obj.gpu_addr for queues already in uq_mgr->userq_xa: drivers/gpu/drm/amd/amdgpu/amdgpu_userq.c:amdgpu_userq_vm_validate_and_rest= ore_queue() { ... xa_for_each(&uq_mgr->userq_xa, tmp_key, queue) { bo =3D queue->wptr_obj.obj; if (!bo) { ret =3D -EINVAL; goto unlock_all; } ret =3D amdgpu_ttm_alloc_gart(&bo->tbo); ... queue->wptr_obj.gpu_addr =3D amdgpu_bo_gpu_offset(bo); } ... } the newly created queue keeps a stale, freed GART address in queue->wptr_obj.gpu_addr and hands it to MES in mes_userq_map(). --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130062604.1921= 479-1-Jesse.Zhang@amd.com?part=3D2