All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Perry Yuan" <perry.yuan@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH 2/2] drm/amdkfd: fix deadlock between profiler_lock and dqm->lock
Date: Mon, 23 Nov 2026 07:38:01 +0000	[thread overview]
Message-ID: <sashiko-outbox-228826@kernel.org> (raw)
In-Reply-To: <20261123072247.3612981-2-perry.yuan@amd.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/amdkfd: race in kfd_process_profiler_release() disabling
  perfcount
--

commit 887c47d311618fed50bfb8220d55513cc2a5a998
Author: Perry Yuan <perry.yuan@amd.com>

drm/amdkfd: fix deadlock between profiler_lock and dqm->lock

This commit moves the set_perfcount() call in kfd_process_profiler_release()
outside kfd->profiler_lock to avoid an ABBA lock inversion with dqm->lock.

> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_process.c b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> index 6663718fb83ce..b63535eda02b3 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_process.c
> @@ -1178,12 +1178,17 @@ static void kfd_process_free_outstanding_kfd_bos(struct kfd_process *p)
>  
>  static void kfd_process_profiler_release(struct kfd_process *p, struct kfd_process_device *pdd)
>  {
> +	bool release = false;
> +
>  	mutex_lock(&pdd->dev->kfd->profiler_lock);
>  	if (pdd->dev->kfd->profiler_process == p) {
> -		pdd->qpd.dqm->ops.set_perfcount(pdd->qpd.dqm, 0);
>  		pdd->dev->kfd->profiler_process = NULL;
> +		release = true;
>  	}
>  	mutex_unlock(&pdd->dev->kfd->profiler_lock);
> +
> +	if (release)
> +		pdd->qpd.dqm->ops.set_perfcount(pdd->qpd.dqm, 0);
>  }
>  
>  static void kfd_process_destroy_pdds(struct kfd_process *p)

[Severity: Medium]
Can clearing profiler_process and dropping profiler_lock before calling
set_perfcount(pdd->qpd.dqm, 0) race with a new profiler session?

CPU0                                  CPU1
kfd_process_profiler_release()
  mutex_lock(&kfd->profiler_lock)
  kfd->profiler_process = NULL
  mutex_unlock(&kfd->profiler_lock)
                                      kfd_profiler_pmc()
                                        profile_lock_device(..., 1)
                                          mutex_lock(&kfd->profiler_lock)
                                          kfd->profiler_process = new_p
                                          mutex_unlock(&kfd->profiler_lock)
                                        dqm->ops.set_perfcount(dqm, 1)
  dqm->ops.set_perfcount(dqm, 0)
    <-- disables perfcount for new_p

Once profiler_process is cleared and profiler_lock is released, another
process calling kfd_profiler_pmc() can claim profiler_process and enable
perfcount, only for the exiting process to overwrite it back to 0 across the
device's queues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261123072247.3612981-1-perry.yuan@amd.com?part=2

  reply	other threads:[~2026-11-23  7:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  7:22 [PATCH 1/2] drm/amdgpu: add ptl_format module parameter Perry Yuan
2026-11-23  7:22 ` [PATCH 2/2] drm/amdkfd: fix deadlock between profiler_lock and dqm->lock Perry Yuan
2026-11-23  7:38   ` sashiko-bot [this message]
2026-11-24  2:58   ` Zhang, Yifan
2026-11-24  2:59 ` [PATCH 1/2] drm/amdgpu: add ptl_format module parameter Zhang, Yifan

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-228826@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=perry.yuan@amd.com \
    --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.