All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Jesse Zhang" <Jesse.Zhang@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 1/2] drm/amdgpu: reserve a fence slot before adding the eviction fence
Date: Thu, 19 Nov 2026 10:13:22 +0000	[thread overview]
Message-ID: <sashiko-outbox-222926@kernel.org> (raw)
In-Reply-To: <20261119095652.3510341-1-Jesse.Zhang@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] drm/amdgpu: missing return value assignment in
  amdgpu_evf_mgr_attach_fence()
It also noticed 1 related pre-existing issue this patch does not
introduce:
- [High] drm/amdgpu: infinite loop in amdgpu_evf_mgr_rearm() [1]
--

commit 48f419fb19e05e772f024f2aeb82afb2c8d3447c
Author: Jesse Zhang <Jesse.Zhang@amd.com>

drm/amdgpu: reserve a fence slot before adding the eviction fence

This commit calls dma_resv_reserve_fences() in amdgpu_evf_mgr_attach_fence()
before attaching the eviction fence to a BO's reservation object.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c
> index f8652fd0525df..f01e08c4de4a2 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c
> @@ -108,13 +108,21 @@ int amdgpu_evf_mgr_attach_fence(struct amdgpu_eviction_fence_mgr *evf_mgr,
>  
>  		amdgpu_bo_placement_from_domain(bo, bo->allowed_domains);
>  		ret = ttm_bo_validate(&bo->tbo, &bo->placement, &ctx);
> -		if (!ret)
> -			dma_resv_add_fence(resv, ev_fence,
> -					   DMA_RESV_USAGE_BOOKKEEP);
> +		if (ret)
> +			goto out;
> +
> +		/* BOs prelocked by drm_exec may not have reserved fence slots. */
> +		dma_resv_reserve_fences(resv, 1);
> +		if (ret)
> +			goto out;

[Severity: High]
Should the return value of dma_resv_reserve_fences() be assigned to ret?
Because ret is already 0 from ttm_bo_validate(), an allocation failure in
dma_resv_reserve_fences() is ignored and execution proceeds to
dma_resv_add_fence() without a reserved slot, triggering the BUG_ON() in
dma_resv_add_fence() or a NULL pointer dereference if resv->fences is NULL.

> +
> +		dma_resv_add_fence(resv, ev_fence,
> +				   DMA_RESV_USAGE_BOOKKEEP);
>  	} else {
>  		ret = 0;
>  	}
>  
> +out:
>  	dma_fence_put(ev_fence);
>  	return ret;
>  }

[Severity: High]
This problem wasn't introduced by this patch, but can dropping the old
evf_mgr->ev_fence reference before updating the pointer in
amdgpu_evf_mgr_rearm() [1] trap a concurrent RCU reader in an
infinite loop?

drivers/gpu/drm/amd/amdgpu/amdgpu_eviction_fence.c:amdgpu_evf_mgr_rearm() {
    ...
	/* Remember it for newly added BOs */
	dma_fence_put(evf_mgr->ev_fence);
	evf_mgr->ev_fence = &ev_fence->base;
    ...
}

When dma_fence_put() drops the old fence's refcount to zero while
evf_mgr->ev_fence still points to it, a concurrent reader calling
dma_fence_get_rcu_safe() sees a zero refcount and an unchanged pointer:

CPU0                                CPU1
amdgpu_evf_mgr_rearm()
  dma_fence_put(evf_mgr->ev_fence)
                                    amdgpu_evf_mgr_get_fence()
                                      dma_fence_get_rcu_safe()
                                        fence = rcu_dereference(...)
                                        dma_fence_get_rcu(fence) -> NULL
                                        /* pointer unchanged, retries */
                                        <-- spins until pointer updates
  evf_mgr->ev_fence = &ev_fence->base

Because dma_fence_get_rcu_safe() loops until it either acquires a reference
or observes the pointer change, a reader that preempts CPU0 after
dma_fence_put() will spin indefinitely and cause a CPU lockup.  Updating
evf_mgr->ev_fence via rcu_replace_pointer() before calling dma_fence_put()
on the old fence would avoid this window.

[1] https://sashiko.dev/#/bug/linux-6debe0c7-cdae-40ca-8882-4e7c8c922581

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261119095652.3510341-1-Jesse.Zhang@amd.com?part=1

      parent reply	other threads:[~2026-11-19 10:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19  9:56 [PATCH 1/2] drm/amdgpu: reserve a fence slot before adding the eviction fence Jesse Zhang
2026-11-19  9:56 ` [PATCH 2/2] drm/amdgpu: don't unreserve the freed root PD in amdgpu_vm_init() Jesse Zhang
2026-11-19 14:46   ` Christian König
2026-11-19 15:54     ` Alex Deucher
2026-11-19 23:43       ` Zhang, Jesse(Jie)
2026-11-20 12:00         ` Christian König
2026-11-19 10:13 ` 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-222926@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.