From: sashiko-bot@kernel.org
To: "Deniz Aydogan" <denizaydogan1902@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] accel/amdxdna: fix double-free on mailbox channel stop
Date: Fri, 28 Aug 2026 21:42:00 +0000 [thread overview]
Message-ID: <20260828214200.9ED281F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260828212405.13124-1-denizaydogan1902@gmail.com>
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Concurrent execution of `xdna_mailbox_send_msg` by the DRM scheduler thread and the ioctl thread leads to hardware ring buffer corruption.
--
commit f00c302142d5de5c06245223cfbc1a367c1aef38
Author: Deniz Aydogan <denizaydogan1902@gmail.com>
accel/amdxdna: fix double-free on mailbox channel stop
This commit fixes a double-free issue when stopping a mailbox channel. The
previous implementation used two xarray iterators that could overlap and
release the same message twice. It replaces them with a single iterator to
ensure each message is freed exactly once.
> diff --git a/drivers/accel/amdxdna/amdxdna_mailbox.c b/drivers/accel/amdxdna/amdxdna_mailbox.c
> index cc8865f4e79c9..27161734753d0 100644
> --- a/drivers/accel/amdxdna/amdxdna_mailbox.c
> +++ b/drivers/accel/amdxdna/amdxdna_mailbox.c
> @@ -556,9 +556,7 @@ void xdna_mailbox_stop_channel(struct mailbox_channel *mb_chann)
> drain_workqueue(mb_chann->work_q);
>
> /* We can clean up and release resources */
> - xa_for_each_start(&mb_chann->chan_xa, msg_id, mb_msg, mb_chann->next_msgid)
> - mailbox_release_msg(mb_chann, mb_msg);
> - xa_for_each_range(&mb_chann->chan_xa, msg_id, mb_msg, 0, mb_chann->next_msgid - 1)
> + xa_for_each(&mb_chann->chan_xa, msg_id, mb_msg)
> mailbox_release_msg(mb_chann, mb_msg);
> xa_destroy(&mb_chann->chan_xa);
[Severity: High]
This is a pre-existing issue, but while reviewing the mailbox channel code in
drivers/accel/amdxdna/amdxdna_mailbox.c, I noticed a potential data
corruption issue with concurrent messages.
Can concurrent execution of xdna_mailbox_send_msg() lead to hardware ring
buffer corruption?
The DRM scheduler thread can submit jobs without holding the device lock,
calling:
drivers/accel/amdxdna/aie2_message.c:aie2_execbuf() -> xdna_mailbox_send_msg()
Concurrently, the ioctl thread can configure the same hardware context and
channel while holding the device lock, calling:
drivers/accel/amdxdna/aie2_message.c:aie2_config_cu() -> xdna_mailbox_send_msg()
Inside mailbox_send_msg() in drivers/accel/amdxdna/amdxdna_mailbox.c, the tail
pointer is read locklessly:
tail = mb_chann->x2i_tail;
And it is updated locklessly after the message is written:
mailbox_set_tailptr(mb_chann, tail + mb_msg->pkg_size);
Since there is no common lock held between the DRM scheduler thread and the
ioctl thread for the mailbox channel, can they race to read the same tail
pointer, overwrite each other's messages in the ring buffer, and write
conflicting tail pointers to the hardware?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260828212405.13124-1-denizaydogan1902@gmail.com?part=1
next prev parent reply other threads:[~2026-08-28 21:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-28 21:24 [PATCH] accel/amdxdna: fix double-free on mailbox channel stop Deniz Aydogan
2026-08-28 21:42 ` sashiko-bot [this message]
2026-08-31 21:28 ` Lizhi Hou
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=20260828214200.9ED281F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=denizaydogan1902@gmail.com \
--cc=dri-devel@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.