From: sashiko-bot@kernel.org
To: "Jesse Zhang" <Jesse.Zhang@amd.com>, amd-gfx@lists.freedesktop.org
Subject: Re: [v2 1/3] drm/amdkfd: leave the devices a process has no VM on out of debugging
Date: Thu, 19 Nov 2026 09:26:31 +0000 [thread overview]
Message-ID: <sashiko-outbox-222831@kernel.org> (raw)
In-Reply-To: <20261119090557.3494649-1-Jesse.Zhang@amd.com>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] drm/amdkfd: debug VMID hijack on non-active device in
pm_map_process_v9()
- [Medium] drm/amdkfd: stale CWSR TMA debug flag in
kfd_process_device_init_cwsr_dgpu()
--
commit 53d7a0d14fffa554af576ebf0d12a4cd46c01696
Author: Jesse Zhang <Jesse.Zhang@amd.com>
drm/amdkfd: leave the devices a process has no VM on out of debugging
This commit activates and runs debug operations only on devices where the
target process has acquired a VM, tracking per-device activation in
pdd->debug_active.
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_debug.c b/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
> index 71b34a57c2cc2..d5699c2e1f7fe 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_debug.c
[ ... ]
> @@ -626,12 +631,9 @@ void kfd_dbg_trap_deactivate(struct kfd_process *target, bool unwind, int unwind
> for (i = 0; i < target->n_pdds; i++) {
> struct kfd_process_device *pdd = target->pdds[i];
>
> - /* If this is an unwind, and we have unwound the required
> - * enable calls on the pdd list, we need to stop now
> - * otherwise we may mess up another debugger session.
> - */
> - if (unwind && i == unwind_count)
> - break;
> + if (!pdd->debug_active)
> + continue;
> + pdd->debug_active = false;
>
> kfd_process_set_trap_debug_flag(&pdd->qpd, false);
[Severity: Medium]
Can this leave the CWSR TMA debug flag permanently enabled on a device
where pdd->debug_active is false?
When a process acquires a VM on a device, kfd_process_device_init_vm() ->
kfd_process_device_init_cwsr_dgpu() sets the TMA flag from the
process-wide debug_trap_enabled flag rather than pdd->debug_active:
drivers/gpu/drm/amd/amdkfd/kfd_process.c:kfd_process_device_init_cwsr_dgpu() {
...
kfd_process_set_trap_debug_flag(&pdd->qpd,
pdd->process->debug_trap_enabled);
...
}
If a debugged process acquires a VM on an additional device after
kfd_dbg_trap_activate() has already run, pdd->debug_active remains false
on that device while the TMA debug flag is set to true, and
kfd_dbg_trap_deactivate() will now skip clearing it on detach. The same
happens if a debugger attaches before runtime enable, the process acquires
a VM, and either the debugger detaches before runtime enable or
kfd_dbg_trap_activate() fails before reaching that device.
Should kfd_process_device_init_cwsr_dgpu() pass pdd->debug_active instead
of pdd->process->debug_trap_enabled?
[ ... ]
> @@ -727,6 +729,9 @@ int kfd_dbg_trap_activate(struct kfd_process *target)
> for (i = 0; i < target->n_pdds; i++) {
> struct kfd_process_device *pdd = target->pdds[i];
>
> + if (!pdd->drm_priv)
> + continue;
> +
> if (!kfd_dbg_is_per_vmid_supported(pdd->dev)) {
> r = reserve_debug_trap_vmid(pdd->dev->dqm, &pdd->qpd);
>
> @@ -739,6 +744,8 @@ int kfd_dbg_trap_activate(struct kfd_process *target)
> }
> }
>
> + pdd->debug_active = true;
[Severity: High]
If a debugged process later acquires a VM and creates a queue on a
non-per-VMID device that was skipped here, can pm_map_process_v9() hijack
another process's reserved trap_debug_vmid on that device?
drivers/gpu/drm/amd/amdkfd/kfd_packet_manager_v9.c:pm_map_process_v9() {
...
if (kfd->dqm->trap_debug_vmid && pdd->process->debug_trap_enabled &&
pdd->process->runtime_info.runtime_state == DEBUG_RUNTIME_STATE_ENABLED) {
packet->bitfields2.debug_vmid = kfd->dqm->trap_debug_vmid;
packet->bitfields2.new_debug = 1;
}
...
}
When process A is debugged only on a dGPU (so A has debug_trap_enabled
and runtime_state == DEBUG_RUNTIME_STATE_ENABLED, but pdd->debug_active is
false on the iGPU) and process B reserves kfd->dqm->trap_debug_vmid on
the iGPU, process A creating a queue on the iGPU will map its process
context with new_debug = 1 and process B's debug_vmid.
In addition, pm_map_process_aldebaran(), create_queue_cpsch(), and
add_queue_mes() still check process->debug_trap_enabled instead of
pdd->debug_active, applying single_memops, is_dbg_wa, and
skip_process_ctx_clear to devices where debugging was not activated.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261119090557.3494649-1-Jesse.Zhang@amd.com?part=1
next prev parent reply other threads:[~2026-11-19 9:26 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 9:04 [v2 1/3] drm/amdkfd: leave the devices a process has no VM on out of debugging Jesse Zhang
2026-11-19 9:04 ` [v2 2/3] drm/amdkfd: return the memory violation data to the debugger Jesse Zhang
2026-11-19 9:04 ` [v2 3/3] drm/amdkfd: don't keep the debugger pointer when DBG_TRAP_ENABLE fails Jesse Zhang
2026-11-19 18:46 ` Kim, Jonathan
2026-11-20 8:17 ` Zhang, Jesse(Jie)
2026-11-19 9:26 ` sashiko-bot [this message]
2026-11-19 17:17 ` [v2 1/3] drm/amdkfd: leave the devices a process has no VM on out of debugging Kim, Jonathan
2026-11-20 7:58 ` Zhang, Jesse(Jie)
2026-11-20 14:25 ` Kim, Jonathan
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-222831@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.