From: sashiko-bot@kernel.org
To: "Mike Lothian" <mike@fireburn.co.uk>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v3] drm/amdgpu: hold a runtime PM reference for P2P dma-buf attachments
Date: Fri, 11 Sep 2026 18:46:13 +0000 [thread overview]
Message-ID: <20260911184613.77DA11F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260911183825.935140-1-mike@fireburn.co.uk>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] Incorrect handling of negative return values from pm_runtime_get_if_active() causes a runtime PM usage count underflow.
--
commit ea3c97ff59ae3ca0f3d8bdf4b2a1ca3b95cda6f8
Author: Mike Lothian <mike@fireburn.co.uk>
drm/amdgpu: hold a runtime PM reference for P2P dma-buf attachments
This commit takes a runtime PM reference in amdgpu_dma_buf_attach() and drops
it in amdgpu_dma_buf_detach() to prevent P2P dma-buf attachments from falling
back to GTT when the exporting device is suspended. It uses
pm_runtime_get_if_active() to avoid deadlocks against the resume path.
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
> index b33c300e26e2e..fae695c3e5315 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_dma_buf.c
[ ... ]
> @@ -100,15 +101,50 @@ static int amdgpu_dma_buf_attach(struct dma_buf *dmabuf,
> pci_p2pdma_distance(adev->pdev, attach->dev, false) < 0)
> attach->peer2peer = false;
>
> + /*
> + * P2P access needs the exporter awake for the lifetime of the
> + * attachment. pm_runtime_get_if_active() never resumes the device,
> + * so it cannot deadlock against the reservation taken during resume.
> + * A negative return means runtime PM is disabled and the device
> + * cannot suspend, in which case the put in detach is a no-op.
> + */
> + if (attach->peer2peer &&
> + !pm_runtime_get_if_active(adev_to_drm(adev)->dev))
> + attach->peer2peer = false;
[Severity: High]
The comment states that the put in detach is a no-op, but is this accurate?
pm_runtime_get_if_active() can return a negative error code (such as -EINVAL
when runtime PM is disabled). In that case, !pm_runtime_get_if_active()
evaluates to false, bypassing the attach->peer2peer = false assignment.
Since the reference was not actually acquired, but attach->peer2peer remains
true, wouldn't the unbalanced pm_runtime_put_autosuspend() calls in
err_pm_put and amdgpu_dma_buf_detach() cause a PM usage count underflow
rather than acting as a no-op?
> +
> r = dma_resv_lock(bo->tbo.base.resv, NULL);
> if (r)
> - return r;
> + goto err_pm_put;
>
> amdgpu_vm_bo_update_shared(bo);
>
> dma_resv_unlock(bo->tbo.base.resv);
>
> return 0;
> +
> +err_pm_put:
> + if (attach->peer2peer)
> + pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
> + return r;
> +}
> +
> +/**
> + * amdgpu_dma_buf_detach - &dma_buf_ops.detach implementation
> + *
> + * @dmabuf: DMA-buf where we remove the attachment from
> + * @attach: the attachment to remove
> + *
> + * Drop the runtime PM reference taken in amdgpu_dma_buf_attach().
> + */
> +static void amdgpu_dma_buf_detach(struct dma_buf *dmabuf,
> + struct dma_buf_attachment *attach)
> +{
> + struct drm_gem_object *obj = dmabuf->priv;
> + struct amdgpu_bo *bo = gem_to_amdgpu_bo(obj);
> + struct amdgpu_device *adev = amdgpu_ttm_adev(bo->tbo.bdev);
> +
> + if (attach->peer2peer)
> + pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
> }
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260911183825.935140-1-mike@fireburn.co.uk?part=1
next prev parent reply other threads:[~2026-09-11 18:46 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-09 2:08 [PATCH] drm/amdgpu: don't migrate a dma-buf into VRAM while runtime suspended Mike Lothian
2026-09-09 2:23 ` sashiko-bot
2026-09-09 9:46 ` [PATCH v2] " Mike Lothian
2026-09-09 12:46 ` Christian König
2026-09-10 0:15 ` Mike Lothian
2026-09-10 9:27 ` Christian König
2026-09-11 18:38 ` [PATCH v3] drm/amdgpu: hold a runtime PM reference for P2P dma-buf attachments Mike Lothian
2026-09-11 18:46 ` sashiko-bot [this message]
2026-09-11 23:29 ` [PATCH v4] " Mike Lothian
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=20260911184613.77DA11F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=mike@fireburn.co.uk \
--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