* [PATCH] drm/amdgpu: validate the WPTR BO before handing its address to the MES
@ 2026-11-27 10:09 Jesse Zhang
2026-11-27 10:37 ` sashiko-bot
0 siblings, 1 reply; 2+ messages in thread
From: Jesse Zhang @ 2026-11-27 10:09 UTC (permalink / raw)
To: amd-gfx; +Cc: Alexander.Deucher, Christian Koenig, Sunil Khatri, Jesse Zhang
The unpinned WPTR BO can be evicted to SYSTEM before queue creation.
amdgpu_evf_mgr_attach_fence() skips validation when the eviction fence
is already signaled, leaving the BO in SYSTEM. Since resource->start
is zero, amdgpu_ttm_alloc_gart() also returns success without allocating
or binding GART space. mes_userq_create_wptr_mapping() then passes an
invalid GPU address to MES.
On Navi31, creating SDMA user queues during GTT eviction triggers:
WARNING: amdgpu_object.c:1550 at amdgpu_bo_gpu_offset
mes_userq_create_wptr_mapping
mes_userq_mqd_create
amdgpu_userq_ioctl
followed by page faults at address 0 and GPU resets.
Validate the BO into its allowed domains before allocating GART space,
as the restore path does. This removes the warning and address-zero
faults in the same test.
Fixes: 7264bc10c7c6 ("drm/amdgpu: dont pin wptr bo instead use eviction fence")
Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
---
drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
index 7abb9d95ef59..105c9866b2a3 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
@@ -37,6 +37,7 @@ mes_userq_create_wptr_mapping(struct amdgpu_device *adev,
struct amdgpu_usermode_queue *queue,
uint64_t wptr)
{
+ struct ttm_operation_ctx ctx = { false, false };
struct amdgpu_bo_va_mapping *wptr_mapping;
struct amdgpu_userq_obj *wptr_obj = &queue->wptr_obj;
struct amdgpu_bo *obj;
@@ -84,6 +85,12 @@ mes_userq_create_wptr_mapping(struct amdgpu_device *adev,
goto fail_map;
}
+ /* 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_domains);
+ ret = ttm_bo_validate(&wptr_obj->obj->tbo, &wptr_obj->obj->placement, &ctx);
+ if (ret)
+ goto fail_map;
+
ret = amdgpu_ttm_alloc_gart(&wptr_obj->obj->tbo);
if (ret) {
DRM_ERROR("Failed to bind wptr bo to GART. ret %d\n", ret);
--
2.50.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] drm/amdgpu: validate the WPTR BO before handing its address to the MES
2026-11-27 10:09 [PATCH] drm/amdgpu: validate the WPTR BO before handing its address to the MES Jesse Zhang
@ 2026-11-27 10:37 ` sashiko-bot
0 siblings, 0 replies; 2+ messages in thread
From: sashiko-bot @ 2026-11-27 10:37 UTC (permalink / raw)
To: Jesse Zhang, amd-gfx
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/amdgpu: missing userptr and domain checks in
mes_userq_create_wptr_mapping()
--
commit c8808f07dff4b49d4c3e4db4a9b93588681aeec7
Author: Jesse Zhang <Jesse.Zhang@amd.com>
drm/amdgpu: validate the WPTR BO before handing its address to the MES
This commit validates wptr_obj->obj into its allowed domains before calling
amdgpu_ttm_alloc_gart() in mes_userq_create_wptr_mapping().
> diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
> index 7abb9d95ef59a..105c9866b2a3f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
> +++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
> @@ -37,6 +37,7 @@ mes_userq_create_wptr_mapping(struct amdgpu_device *adev,
> struct amdgpu_usermode_queue *queue,
> uint64_t wptr)
> {
> + struct ttm_operation_ctx ctx = { false, false };
> struct amdgpu_bo_va_mapping *wptr_mapping;
> struct amdgpu_userq_obj *wptr_obj = &queue->wptr_obj;
> struct amdgpu_bo *obj;
> @@ -84,6 +85,12 @@ mes_userq_create_wptr_mapping(struct amdgpu_device *adev,
> goto fail_map;
> }
>
> + /* 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_domains);
> + ret = ttm_bo_validate(&wptr_obj->obj->tbo, &wptr_obj->obj->placement, &ctx);
> + if (ret)
> + goto fail_map;
[Severity: High]
Can calling ttm_bo_validate() with wptr_obj->obj->allowed_domains cause a
NULL pointer dereference in amdgpu_ttm_tt_pin_userptr() or leave
wptr_obj->obj outside GTT?
Before 7264bc10c7c6 ("drm/amdgpu: dont pin wptr bo instead use eviction fence"),
amdgpu_bo_pin(wptr_obj->obj, AMDGPU_GEM_DOMAIN_GTT) rejected userptr BOs
via amdgpu_ttm_tt_get_usermm() and validated the BO into
AMDGPU_GEM_DOMAIN_GTT.
If userspace registers a userptr BO without AMDGPU_GEM_USERPTR_VALIDATE
while the eviction fence is in its initial signaled stub state, the BO
stays in TTM_PL_SYSTEM with allowed_domains = AMDGPU_GEM_DOMAIN_GTT and
ttm->pages[0] == NULL. Validating it directly here moves it to TTM_PL_TT
without fetching user pages via amdgpu_ttm_tt_get_user_pages(), so
amdgpu_bo_move() -> amdgpu_ttm_backend_bind() ->
amdgpu_ttm_tt_pin_userptr() passes the unpopulated ttm->pages array to
sg_alloc_table_from_pages() and dma_map_sgtable().
In addition, if wptr_obj->obj was created with AMDGPU_GEM_DOMAIN_CPU or
non-contiguous AMDGPU_GEM_DOMAIN_VRAM, validating into allowed_domains
leaves it in TTM_PL_SYSTEM or TTM_PL_VRAM, causing amdgpu_ttm_alloc_gart()
to return 0 without binding GART space and amdgpu_bo_gpu_offset() to warn
and pass an invalid GPU address to MES.
Should mes_userq_create_wptr_mapping() reject userptr BOs and require
AMDGPU_GEM_DOMAIN_GTT placement?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261127100941.738014-1-Jesse.Zhang@amd.com?part=1
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-27 10:37 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-27 10:09 [PATCH] drm/amdgpu: validate the WPTR BO before handing its address to the MES Jesse Zhang
2026-11-27 10:37 ` sashiko-bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox