All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Kuehling, Felix" <felix.kuehling@amd.com>
To: Zhu Lingshan <lingshan.zhu@amd.com>, alexander.deucher@amd.com
Cc: ray.huang@amd.com, amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH V4 17/18] amdkfd: set_debug_trap ioctl only works on a primary kfd_process target
Date: Wed, 24 Sep 2025 17:50:11 -0400	[thread overview]
Message-ID: <08ecb504-abb8-4ad8-bbbb-a18e19daffbe@amd.com> (raw)
In-Reply-To: <20250923072608.252345-18-lingshan.zhu@amd.com>

On 2025-09-23 03:26, Zhu Lingshan wrote:
> The user space program pass down a pid to kfd
> through set_debug_trap ioctl, which can help
> find the corresponding user space program and
> its mm struct.
>
> However, these information is insufficient to
> locate a specific kfd process among the
> multiple kfd_process that belong to the
> same user space program.
>
> For correctness and backward compatibilities,
> this commit only allow set_debut_trap ioctl
> work for a user space program which does not
> own any secondary kfd_process.

What happens if a secondary context is created after the debugger 
attaches to a process?

It may be simpler and more consistent to allow debugging of the primary 
context, even if secondary contexts exist. Just ignore any secondary 
contexts for the purpose of the debug API.

Regards,
   Felix


>
> Signed-off-by: Zhu Lingshan <lingshan.zhu@amd.com>
> ---
>   drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 29 ++++++++++++++++++++++++
>   1 file changed, 29 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> index 662b181f1fd2..2df095e25c2e 100644
> --- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> +++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
> @@ -36,6 +36,7 @@
>   #include <linux/ptrace.h>
>   #include <linux/dma-buf.h>
>   #include <linux/processor.h>
> +#include <linux/fdtable.h>
>   #include "kfd_priv.h"
>   #include "kfd_device_queue_manager.h"
>   #include "kfd_svm.h"
> @@ -2918,6 +2919,25 @@ static int kfd_ioctl_runtime_enable(struct file *filep, struct kfd_process *p, v
>   	return r;
>   }
>   
> +static int kfd_process_count_cb(const void *num, struct file *filep, unsigned int n)
> +{
> +	u16 *ret = (u16 *)num;
> +
> +	if (filep->f_op == &kfd_fops)
> +		(*ret)++;
> +
> +	return 0;
> +}
> +
> +static u16 kfd_process_count(struct task_struct *thread)
> +{
> +	u16 count = 0;
> +
> +	iterate_fd(thread->files, 0, kfd_process_count_cb, (const void *)&count);
> +
> +	return count;
> +}
> +
>   static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, void *data)
>   {
>   	struct kfd_ioctl_dbg_trap_args *args = data;
> @@ -2927,6 +2947,7 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v
>   	struct kfd_process *target = NULL;
>   	struct kfd_process_device *pdd = NULL;
>   	int r = 0;
> +	u16 process_count = 0;
>   
>   	if (sched_policy == KFD_SCHED_POLICY_NO_HWS) {
>   		pr_err("Debugging does not support sched_policy %i", sched_policy);
> @@ -2984,6 +3005,14 @@ static int kfd_ioctl_set_debug_trap(struct file *filep, struct kfd_process *p, v
>   	if (r)
>   		goto out;
>   
> +	process_count = kfd_process_count(thread);
> +	/* The user space program has secondary contexts */
> +	if (process_count > 1) {
> +		pr_err("Detect multiple kfd_process owned by PID %i, please consider close any secondary kfd_process and try again\n", args->pid);
> +		r = -EINVAL;
> +		goto out;
> +	}
> +
>   	mutex_lock(&target->mutex);
>   
>   	if (args->op != KFD_IOC_DBG_TRAP_ENABLE && !target->debug_trap_enabled) {

  reply	other threads:[~2025-09-24 21:50 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-23  7:25 [PATCH V4 00/18] amdkfd: Implement kfd multiple contexts Zhu Lingshan
2025-09-23  7:25 ` [PATCH V4 01/18] amdkfd: enlarge the hashtable of kfd_process Zhu Lingshan
2025-09-23  7:25 ` [PATCH V4 02/18] amdkfd: mark the first kfd_process as the primary one Zhu Lingshan
2025-09-23  7:25 ` [PATCH V4 03/18] amdkfd: find_process_by_mm always return the primary context Zhu Lingshan
2025-09-23  7:25 ` [PATCH V4 04/18] amdkfd: Introduce kfd_create_process_sysfs as a separate function Zhu Lingshan
2025-09-23  7:25 ` [PATCH V4 05/18] amdkfd: destroy kfd secondary contexts through fd close Zhu Lingshan
2025-09-23  7:25 ` [PATCH V4 06/18] amdkfd: process svm ioctl only on the primary kfd process Zhu Lingshan
2025-09-23  7:25 ` [PATCH V4 07/18] amdkfd: process USERPTR allocation " Zhu Lingshan
2025-09-23  7:25 ` [PATCH V4 08/18] amdkfd: identify a secondary kfd process by its id Zhu Lingshan
2025-09-24 21:41   ` Kuehling, Felix
2025-09-26  2:58     ` Zhu, Lingshan
2025-09-23  7:25 ` [PATCH V4 09/18] amdkfd: find kfd_process by filep->private_data in kfd_mmap Zhu Lingshan
2025-09-23  7:26 ` [PATCH V4 10/18] amdkfd: remove DIQ support Zhu Lingshan
2025-09-24 21:41   ` Kuehling, Felix
2025-09-23  7:26 ` [PATCH V4 11/18] amdkfd: process pointer of a HIQ should be NULL Zhu Lingshan
2025-09-24 21:43   ` Kuehling, Felix
2025-09-23  7:26 ` [PATCH V4 12/18] amdkfd: remove test_kq Zhu Lingshan
2025-09-23  7:26 ` [PATCH V4 13/18] amdkfd: introduce new helper kfd_lookup_process_by_id Zhu Lingshan
2025-09-23  7:26 ` [PATCH V4 14/18] amdkfd: record kfd process id into kfd process_info Zhu Lingshan
2025-09-24 21:45   ` Kuehling, Felix
2025-09-26  2:51     ` Zhu, Lingshan
2025-09-23  7:26 ` [PATCH V4 15/18] amdkfd: record kfd process id in amdkfd_fence Zhu Lingshan
2025-09-23  7:26 ` [PATCH V4 16/18] amdkfd: fence handler evict and restore a kfd process by its id Zhu Lingshan
2025-09-23  7:26 ` [PATCH V4 17/18] amdkfd: set_debug_trap ioctl only works on a primary kfd_process target Zhu Lingshan
2025-09-24 21:50   ` Kuehling, Felix [this message]
2025-09-26  2:49     ` Zhu, Lingshan
2025-10-01  5:42       ` Kuehling, Felix
2025-09-23  7:26 ` [PATCH V4 18/18] amdkfd: introduce new ioctl AMDKFD_IOC_CREATE_PROCESS Zhu Lingshan

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=08ecb504-abb8-4ad8-bbbb-a18e19daffbe@amd.com \
    --to=felix.kuehling@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=lingshan.zhu@amd.com \
    --cc=ray.huang@amd.com \
    /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.