From: sashiko-bot@kernel.org
To: "Jesse Zhang" <Jesse.Zhang@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdgpu: validate the WPTR BO before handing its address to the MES
Date: Fri, 27 Nov 2026 10:37:11 +0000 [thread overview]
Message-ID: <sashiko-outbox-237145@kernel.org> (raw)
In-Reply-To: <20261127100941.738014-1-Jesse.Zhang@amd.com>
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
prev parent reply other threads:[~2026-11-27 10:37 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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 message]
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-237145@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=Jesse.Zhang@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.