All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Daniel Charles" <daniel.charles@intel.com>,
	intel-xe@lists.freedesktop.org
Subject: Re: [PATCH 1/3] drm/xe: Read scheduler message opcode under lock
Date: Tue, 13 Oct 2026 03:00:33 +0000	[thread overview]
Message-ID: <sashiko-outbox-168882@kernel.org> (raw)
In-Reply-To: <20261013023442.206915-2-daniel.charles@intel.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [Medium] drm/xe: data race on msg->opcode in tracepoint
- [Medium] drm/xe: memory leak of dynamically allocated scheduler messages
--

commit f8887f43a6b200067866b162e2ad500eb6e16175
Author: Matthew Brost <matthew.brost@intel.com>

drm/xe: Read scheduler message opcode under lock

For static scheduler messages, the opcode is only guaranteed to remain
stable while the message is on the pending message list. Read the opcode
under the message lock before removing the message from the pending list,
and pass it through the processing pipeline.

> diff --git a/drivers/gpu/drm/xe/xe_gpu_scheduler.c b/drivers/gpu/drm/xe/xe_gpu_scheduler.c
> index 9c8004d5dd915..d656db758cb3c 100644
> --- a/drivers/gpu/drm/xe/xe_gpu_scheduler.c
> +++ b/drivers/gpu/drm/xe/xe_gpu_scheduler.c

[ ... ]

> @@ -42,13 +46,14 @@ static void xe_sched_process_msg_work(struct work_struct *w)
>  	struct xe_gpu_scheduler *sched =
>  		container_of(w, struct xe_gpu_scheduler, work_process_msg);
>  	struct xe_sched_msg *msg;
> +	unsigned int opcode;
>  
>  	if (drm_sched_is_stopped(&sched->base))
>  		return;

[Severity: Medium]
When the scheduler is stopped, does this early return leak dynamically
allocated messages?

If untrusted userspace triggers an error path by queuing property change
messages (like SET_SCHED_PROPS) and then causes the queue to hang, wedge, or
close during teardown, this worker exits without draining or freeing pending
dynamically allocated messages.

During queue teardown, xe_sched_fini() and other cleanup paths fail to
traverse sched->msgs and kfree() dynamically allocated messages before the
list and lock are destroyed.

> -	msg = xe_sched_get_msg(sched);
> +	msg = xe_sched_get_msg(sched, &opcode);
>  	if (msg) {
> -		sched->ops->process_msg(msg);
> +		sched->ops->process_msg(msg, opcode);
>  
>  		xe_sched_process_msg_queue_if_ready(sched);
>  	}

[ ... ]

> diff --git a/drivers/gpu/drm/xe/xe_guc_submit.c b/drivers/gpu/drm/xe/xe_guc_submit.c
> index 7ce73489c35fc..c4ef3e9bf7a18 100644
> --- a/drivers/gpu/drm/xe/xe_guc_submit.c
> +++ b/drivers/gpu/drm/xe/xe_guc_submit.c
> @@ -2056,16 +2056,17 @@ static void __guc_exec_queue_process_msg_cgp_sync(struct xe_sched_msg *msg,
>  #define MSG_HEAD	BIT(9)
>  #define MSG_PM_REF	BIT(10)
>  
> -static void guc_exec_queue_process_msg(struct xe_sched_msg *msg)
> +static void guc_exec_queue_process_msg(struct xe_sched_msg *msg,
> +				       unsigned int opcode)
>  {
>  	struct xe_device *xe = guc_to_xe(exec_queue_to_guc(msg->private_data));
>  	int idx;
> -	bool pm_ref = !!(msg->opcode & MSG_PM_REF);
> +	bool pm_ref = !!(opcode & MSG_PM_REF);
>  	bool bound = drm_dev_enter(&xe->drm, &idx);
>  
>  	trace_xe_sched_msg_recv(msg);

[Severity: Medium]
Does this tracepoint still contain a data race by reading the unstable
msg->opcode?

The patch addresses a data race by extracting msg->opcode into a local
variable under msg_lock, because static messages can be concurrently
re-enqueued modifying their opcode outside the lock. However,
trace_xe_sched_msg_recv(msg) continues to read msg->opcode directly via the
xe_sched_msg event class:

drivers/gpu/drm/xe/xe_trace.h:DECLARE_EVENT_CLASS(xe_sched_msg) {
    ...
    __entry->opcode = msg->opcode;
    ...
}

Because trace_xe_sched_msg_recv() is called here with the message pointer,
rather than the stable extracted opcode, this leaves a data race where the
tracepoint may log an incorrect opcode or trigger KCSAN warnings.

> -	switch (msg->opcode & OPCODE_MASK) {
> +	switch (opcode & OPCODE_MASK) {
>  	case CLEANUP:
>  		__guc_exec_queue_process_msg_cleanup(msg, bound);
>  		break;

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261013023442.206915-1-daniel.charles@intel.com?part=1

  reply	other threads:[~2026-10-13  3:00 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-13  2:34 [PATCH 0/3] FD close cleanup for XE Daniel Charles
2026-10-13  2:34 ` [PATCH 1/3] drm/xe: Read scheduler message opcode under lock Daniel Charles
2026-10-13  3:00   ` sashiko-bot [this message]
2026-10-13  3:09     ` Matthew Brost
2026-10-13  2:34 ` [PATCH 2/3] drm/xe: Disable scheduling early on FD close to avoid CAT error cascade Daniel Charles
2026-10-13 14:46   ` Cavitt, Jonathan
2026-10-13  2:34 ` [PATCH 3/3] drm/xe: Synchronously wait for queue kill on FD close Daniel Charles
2026-10-13  2:59   ` sashiko-bot
2026-10-13  3:07     ` Matthew Brost
2026-10-13  3:17   ` Matthew Brost
2026-10-13 18:11     ` Daniel Charles
2026-10-13 18:31       ` Matthew Brost
2026-10-13  2:54 ` ✗ CI.checkpatch: warning for FD close cleanup for XE Patchwork
2026-10-13  2:56 ` ✓ CI.KUnit: success " Patchwork
2026-10-13  6:19 ` ✓ Xe.CI.BAT: " Patchwork
2026-10-13 15:32 ` ✗ Xe.CI.FULL: 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=sashiko-outbox-168882@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=daniel.charles@intel.com \
    --cc=intel-xe@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.