From: Matthew Auld <matthew.auld@intel.com>
To: Mika Kuoppala <mika.kuoppala@linux.intel.com>,
intel-xe@lists.freedesktop.org
Cc: Dominik Grzegorzek <dominik.grzegorzek@intel.com>
Subject: Re: [PATCH 13/18] drm/xe: Debug metadata create/destroy ioctls
Date: Tue, 1 Oct 2024 17:25:56 +0100 [thread overview]
Message-ID: <7b0e1435-a6d8-4148-9e99-2085aa2208bb@intel.com> (raw)
In-Reply-To: <20241001144306.1991001-14-mika.kuoppala@linux.intel.com>
Hi,
On 01/10/2024 15:43, Mika Kuoppala wrote:
> From: Dominik Grzegorzek <dominik.grzegorzek@intel.com>
>
> Ad a part of eu debug feature introduce debug metadata objects.
> These are to be used to pass metadata between client and debugger,
> by attaching them to vm_bind operations.
>
> todo: WORK_IN_PROGRESS_* defines need to be reworded/refined when
> the real usage and need is established by l0+gdb.
>
> v2: - include uapi/drm/xe_drm.h
> - metadata behind kconfig (Mika)
>
> Signed-off-by: Dominik Grzegorzek <dominik.grzegorzek@intel.com>
> Signed-off-by: Mika Kuoppala <mika.kuoppala@linux.intel.com>
> ---
> drivers/gpu/drm/xe/Makefile | 3 +-
> drivers/gpu/drm/xe/xe_debug_metadata.c | 108 +++++++++++++++++++
> drivers/gpu/drm/xe/xe_debug_metadata.h | 50 +++++++++
> drivers/gpu/drm/xe/xe_debug_metadata_types.h | 28 +++++
> drivers/gpu/drm/xe/xe_device.c | 5 +
> drivers/gpu/drm/xe/xe_device.h | 2 +
> drivers/gpu/drm/xe/xe_device_types.h | 7 ++
> drivers/gpu/drm/xe/xe_eudebug.c | 13 +++
> include/uapi/drm/xe_drm.h | 53 ++++++++-
> 9 files changed, 267 insertions(+), 2 deletions(-)
> create mode 100644 drivers/gpu/drm/xe/xe_debug_metadata.c
> create mode 100644 drivers/gpu/drm/xe/xe_debug_metadata.h
> create mode 100644 drivers/gpu/drm/xe/xe_debug_metadata_types.h
>
> diff --git a/drivers/gpu/drm/xe/Makefile b/drivers/gpu/drm/xe/Makefile
> index 660c1dbba8d0..a94f771529a4 100644
> --- a/drivers/gpu/drm/xe/Makefile
> +++ b/drivers/gpu/drm/xe/Makefile
> @@ -114,7 +114,8 @@ xe-y += xe_bb.o \
> xe_wa.o \
> xe_wopcm.o
>
> -xe-$(CONFIG_DRM_XE_EUDEBUG) += xe_eudebug.o
> +xe-$(CONFIG_DRM_XE_EUDEBUG) += xe_eudebug.o \
> + xe_debug_metadata.o
>
> xe-$(CONFIG_HMM_MIRROR) += xe_hmm.o
>
> diff --git a/drivers/gpu/drm/xe/xe_debug_metadata.c b/drivers/gpu/drm/xe/xe_debug_metadata.c
> new file mode 100644
> index 000000000000..72a00b628475
> --- /dev/null
> +++ b/drivers/gpu/drm/xe/xe_debug_metadata.c
> @@ -0,0 +1,108 @@
> +// SPDX-License-Identifier: MIT
> +/*
> + * Copyright © 2023 Intel Corporation
> + */
> +#include "xe_debug_metadata.h"
> +
> +#include <drm/drm_device.h>
> +#include <drm/drm_file.h>
> +#include <uapi/drm/xe_drm.h>
> +
> +#include "xe_device.h"
> +#include "xe_macros.h"
> +
> +static void xe_debug_metadata_release(struct kref *ref)
> +{
> + struct xe_debug_metadata *mdata = container_of(ref, struct xe_debug_metadata, refcount);
> +
> + kvfree(mdata->ptr);
> + kfree(mdata);
> +}
> +
> +void xe_debug_metadata_put(struct xe_debug_metadata *mdata)
> +{
> + kref_put(&mdata->refcount, xe_debug_metadata_release);
> +}
> +
> +int xe_debug_metadata_create_ioctl(struct drm_device *dev,
> + void *data,
> + struct drm_file *file)
> +{
> + struct xe_device *xe = to_xe_device(dev);
> + struct xe_file *xef = to_xe_file(file);
> + struct drm_xe_debug_metadata_create *args = data;
> + struct xe_debug_metadata *mdata;
> + int err;
> + u32 id;
> +
> + if (XE_IOCTL_DBG(xe, args->extensions))
> + return -EINVAL;
> +
> + if (XE_IOCTL_DBG(xe, args->type > DRM_XE_DEBUG_METADATA_PROGRAM_MODULE))
> + return -EINVAL;
> +
> + if (XE_IOCTL_DBG(xe, !args->user_addr || !args->len))
> + return -EINVAL;
> +
> + if (XE_IOCTL_DBG(xe, !access_ok(u64_to_user_ptr(args->user_addr), args->len)))
> + return -EFAULT;
> +
> + mdata = kzalloc(sizeof(*mdata), GFP_KERNEL);
> + if (!mdata)
> + return -ENOMEM;
> +
> + mdata->len = args->len;
> + mdata->type = args->type;
> +
> + mdata->ptr = kvmalloc(mdata->len, GFP_KERNEL);
> + if (!mdata->ptr) {
> + kfree(mdata);
> + return -ENOMEM;
> + }
> + kref_init(&mdata->refcount);
> +
> + err = copy_from_user(mdata->ptr, u64_to_user_ptr(args->user_addr), mdata->len);
> + if (err) {
> + err = -EFAULT;
> + goto put_mdata;
> + }
> +
> + mutex_lock(&xef->eudebug.metadata.lock);
> + err = xa_alloc(&xef->eudebug.metadata.xa, &id, mdata, xa_limit_32b, GFP_KERNEL);
> + mutex_unlock(&xef->eudebug.metadata.lock);
> +
> + args->metadata_id = id;
Just some drive-by-comments. Potentially this is passing uninitialised
data from the stack back to userspace, assuming the xa_alloc here fails?
Maybe safer to leave metadata_id zeroed on err?
> + mdata->id = id;
It looks like mdata can go out of scope since user can technically guess
the id and call the destroy ioctl before this ioctl returns. I think
publishing the id needs to go last or needs some kind of locking.
Also are we sure we need to store the user id in mdata in the first
place? Usually for user id kmd doesn't need to track it in such a way.
next prev parent reply other threads:[~2024-10-01 16:26 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-01 14:42 [PATCH 00/18] GPU debug support (eudebug) v2 Mika Kuoppala
2024-10-01 14:42 ` [PATCH 01/18] ptrace: export ptrace_may_access Mika Kuoppala
2024-10-01 14:42 ` [PATCH 02/18] drm/xe/eudebug: Introduce eudebug support Mika Kuoppala
2024-10-01 14:42 ` [PATCH 03/18] drm/xe/eudebug: Introduce discovery for resources Mika Kuoppala
2024-10-03 0:41 ` Matthew Brost
2024-10-03 7:27 ` Mika Kuoppala
2024-10-03 16:32 ` Matthew Brost
2024-10-01 14:42 ` [PATCH 04/18] drm/xe/eudebug: Introduce exec_queue events Mika Kuoppala
2024-10-01 14:42 ` [PATCH 05/18] drm/xe/eudebug: hw enablement for eudebug Mika Kuoppala
2024-10-01 14:42 ` [PATCH 06/18] drm/xe: Add EUDEBUG_ENABLE exec queue property Mika Kuoppala
2024-10-01 14:42 ` [PATCH 07/18] drm/xe/eudebug: Introduce per device attention scan worker Mika Kuoppala
2024-10-01 14:42 ` [PATCH 08/18] drm/xe/eudebug: Introduce EU control interface Mika Kuoppala
2024-10-01 14:42 ` [PATCH 09/18] drm/xe/eudebug: Add vm bind and vm bind ops Mika Kuoppala
2024-10-01 14:42 ` [PATCH 10/18] drm/xe/eudebug: Add UFENCE events with acks Mika Kuoppala
2024-10-01 14:42 ` [PATCH 11/18] drm/xe/eudebug: vm open/pread/pwrite Mika Kuoppala
2024-10-01 14:43 ` [PATCH 12/18] drm/xe/eudebug: implement userptr_vma access Mika Kuoppala
2024-10-05 3:48 ` Matthew Brost
2024-10-12 2:39 ` Matthew Brost
2024-10-12 2:55 ` Matthew Brost
2024-10-20 18:16 ` Matthew Brost
2024-10-21 9:54 ` Hajda, Andrzej
2024-10-21 22:34 ` Matthew Brost
2024-10-23 11:32 ` Hajda, Andrzej
2024-10-24 16:06 ` Matthew Brost
2024-10-25 13:20 ` Hajda, Andrzej
2024-10-25 18:23 ` Matthew Brost
2024-10-28 16:19 ` [PATCH 1/2] drm/xe: keep list of system pages in xe_userptr Andrzej Hajda
2024-10-28 16:19 ` [PATCH 2/2] drm/xe/eudebug: implement userptr_vma access Andrzej Hajda
2024-10-28 16:55 ` Hajda, Andrzej
2024-10-01 14:43 ` [PATCH 13/18] drm/xe: Debug metadata create/destroy ioctls Mika Kuoppala
2024-10-01 16:25 ` Matthew Auld [this message]
2024-10-02 13:59 ` Grzegorzek, Dominik
2024-10-01 14:43 ` [PATCH 14/18] drm/xe: Attach debug metadata to vma Mika Kuoppala
2024-10-01 14:43 ` [PATCH 15/18] drm/xe/eudebug: Add debug metadata support for xe_eudebug Mika Kuoppala
2024-10-01 14:43 ` [PATCH 16/18] drm/xe/eudebug: Implement vm_bind_op discovery Mika Kuoppala
2024-10-01 14:43 ` [PATCH 17/18] drm/xe/eudebug: Dynamically toggle debugger functionality Mika Kuoppala
2024-10-01 14:43 ` [PATCH 18/18] drm/xe/eudebug_test: Introduce xe_eudebug wa kunit test Mika Kuoppala
2024-10-01 15:02 ` ✓ CI.Patch_applied: success for GPU debug support (eudebug) (rev2) Patchwork
2024-10-01 15:03 ` ✗ CI.checkpatch: warning " Patchwork
2024-10-01 15:03 ` ✗ CI.KUnit: failure " Patchwork
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=7b0e1435-a6d8-4148-9e99-2085aa2208bb@intel.com \
--to=matthew.auld@intel.com \
--cc=dominik.grzegorzek@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=mika.kuoppala@linux.intel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox