From: sashiko-bot@kernel.org
To: "Jesse Zhang" <Jesse.Zhang@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdgpu: unlink userptr bo_vas under the notifier_lock
Date: Wed, 25 Nov 2026 07:51:41 +0000 [thread overview]
Message-ID: <sashiko-outbox-232842@kernel.org> (raw)
In-Reply-To: <20261125073502.3144422-1-Jesse.Zhang@amd.com>
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/amdgpu: notifier_lock bypass for addr 0 userptr in
amdgpu_vm_bo_del()
--
commit 22400668ad8179b001864d3570debe97ad11a006
Author: Jesse Zhang <Jesse.Zhang@amd.com>
drm/amdgpu: unlink userptr bo_vas under the notifier_lock
This commit acquires adev->notifier_lock in amdgpu_vm_bo_del() when
unlinking userptr bo_vas from bo->vm_bo to serialize against concurrent
MMU notifier invalidations.
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> index 94b1cfe05e3e0..d33dcfd7059cf 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
> @@ -2252,10 +2252,18 @@ void amdgpu_vm_bo_del(struct amdgpu_device *adev,
> dma_resv_assert_held(vm->root.bo->tbo.base.resv);
>
> if (bo) {
> + /*
> + * The MMU notifier of a userptr walks bo->vm_bo under the
> + * notifier_lock, it can't take the BO reservation.
> + */
> + bool userptr = amdgpu_ttm_tt_is_userptr(bo->tbo.ttm);
> +
> dma_resv_assert_held(bo->tbo.base.resv);
> if (amdgpu_vm_is_bo_always_valid(vm, bo))
> ttm_bo_set_bulk_move(&bo->tbo, NULL);
>
> + if (userptr)
> + mutex_lock(&adev->notifier_lock);
> for (base = &bo_va->base.bo->vm_bo; *base;
> base = &(*base)->next) {
> if (*base != &bo_va->base)
> @@ -2265,6 +2273,8 @@ void amdgpu_vm_bo_del(struct amdgpu_device *adev,
> *base = bo_va->base.next;
> break;
> }
> + if (userptr)
> + mutex_unlock(&adev->notifier_lock);
> }
[Severity: High]
Can a userptr BO created at address 0 bypass adev->notifier_lock here and
still hit the use-after-free on bo_va?
amdgpu_gem_userptr_ioctl() accepts args->addr == 0 with a non-zero
page-aligned size and AMDGPU_GEM_USERPTR_REGISTER, setting gtt->userptr = 0
and registering the MMU interval notifier for [0, args->size). However,
amdgpu_ttm_tt_is_userptr() tests !gtt->userptr:
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c:amdgpu_ttm_tt_is_userptr() {
struct amdgpu_ttm_tt *gtt = ttm_to_amdgpu_ttm_tt(ttm);
if (gtt == NULL || !gtt->userptr)
return false;
return true;
}
When gtt->userptr is 0, userptr evaluates to false, so amdgpu_vm_bo_del()
skips adev->notifier_lock while an MMU invalidation on a VMA overlapping
[0, args->size) can concurrently walk bo->vm_bo in
amdgpu_hmm_invalidate_gfx() -> amdgpu_vm_bo_invalidate().
Checking amdgpu_ttm_tt_get_usermm(bo->tbo.ttm) (or gtt->usertask in
amdgpu_ttm_tt_is_userptr()) would cover userptr BOs at address 0 as well.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261125073502.3144422-1-Jesse.Zhang@amd.com?part=1
prev parent reply other threads:[~2026-11-25 7:51 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 7:34 [PATCH] drm/amdgpu: unlink userptr bo_vas under the notifier_lock Jesse Zhang
2026-11-25 7:51 ` 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-232842@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox