* [PATCH] accel/habanalabs: Fix timestamp record release on reset
@ 2026-12-05 6:36 Praneeth Balasubramanian
2026-12-05 6:58 ` sashiko-bot
2026-12-05 12:25 ` Greg KH
0 siblings, 2 replies; 3+ messages in thread
From: Praneeth Balasubramanian @ 2026-12-05 6:36 UTC (permalink / raw)
To: Konstantin Sinyuk, Koby Elbaz, Oded Gabbay
Cc: Praneeth Balasubramanian, stable, dri-devel, linux-kernel
On reset, wake_pending_user_interrupt_threads() releases the pending
timestamp registrations. For each record, under ts_list_lock, it unlinks
the record, puts its timestamp buffer and then puts its CQ buffer. This
has three problems:
- The record is part of the kernel buffer of the timestamp buffer. If
that put drops the last reference, the buffer is freed, and reading
pend->ts_reg_info.cq_cb for the next put is a use-after-free.
- The last put frees the buffer with vfree(), which may sleep, while the
spinlock is held with interrupts off. The interrupt handler path
defers these puts to a workqueue for this reason.
- ts_reg_info.in_use stays set. A compute reset can leave the process
running. If it then registers the same timestamp offset again,
unregister_timestamp_node() sees in_use, unlinks the record a second
time and puts both buffers again.
Do what unregister_timestamp_node() does: under the lock, take the
pointers, unlink the record and clear in_use. Then drop the lock and put
the references.
This was found by an LLM-based audit that checks code against the rules
stated in kernel comments.
Fixes: 9158bf69e74f ("habanalabs: Timestamps buffers registration")
Fixes: 1157b5d6b3b0 ("accel/habanalabs: optimize timestamp registration handler")
Cc: stable@vger.kernel.org
Signed-off-by: Praneeth Balasubramanian <praneethb2002@gmail.com>
---
Notes:
This was found by an LLM-based audit, part of research at UCSB SecLab.
An LLM turned a kernel comment into a rule, and three LLM votes checked
the code against it. The fix and changelog were drafted with GLM-5.3,
then checked against the source and partly rewritten with Claude Opus
5.5. I reviewed the patch and take responsibility for it.
Testing: builds without new warnings with W=1 (x86_64 allmodconfig),
clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no
reproducer. I do not have this hardware.
The kernel-doc of hl_mmap_mem_buf_put() says it "Shall be called from an
interrupt context", but its release may sleep, as the comment above
handle_registration_node() in irq.c says. It may be meant to say "not".
This patch does not change that comment.
.../habanalabs/common/command_submission.c | 22 ++++++++++++++++---
1 file changed, 19 insertions(+), 3 deletions(-)
diff --git a/drivers/accel/habanalabs/common/command_submission.c b/drivers/accel/habanalabs/common/command_submission.c
index 8a3febc2089e..8bff77bf42f8 100644
--- a/drivers/accel/habanalabs/common/command_submission.c
+++ b/drivers/accel/habanalabs/common/command_submission.c
@@ -1098,6 +1098,8 @@ static void
wake_pending_user_interrupt_threads(struct hl_user_interrupt *interrupt)
{
struct hl_user_pending_interrupt *pend, *temp;
+ struct hl_mmap_mem_buf *buf;
+ struct hl_cb *cq_cb;
unsigned long flags;
spin_lock_irqsave(&interrupt->wait_list_lock, flags);
@@ -1108,10 +1110,24 @@ wake_pending_user_interrupt_threads(struct hl_user_interrupt *interrupt)
spin_unlock_irqrestore(&interrupt->wait_list_lock, flags);
spin_lock_irqsave(&interrupt->ts_list_lock, flags);
- list_for_each_entry_safe(pend, temp, &interrupt->ts_list_head, list_node) {
+ while (!list_empty(&interrupt->ts_list_head)) {
+ pend = list_first_entry(&interrupt->ts_list_head,
+ struct hl_user_pending_interrupt, list_node);
+ buf = pend->ts_reg_info.buf;
+ cq_cb = pend->ts_reg_info.cq_cb;
list_del(&pend->list_node);
- hl_mmap_mem_buf_put(pend->ts_reg_info.buf);
- hl_cb_put(pend->ts_reg_info.cq_cb);
+ pend->ts_reg_info.in_use = false;
+ spin_unlock_irqrestore(&interrupt->ts_list_lock, flags);
+
+ /*
+ * As in unregister_timestamp_node(), put the references without
+ * the lock: the release may sleep, and it may free the buffer
+ * that holds pend.
+ */
+ hl_mmap_mem_buf_put(buf);
+ hl_cb_put(cq_cb);
+
+ spin_lock_irqsave(&interrupt->ts_list_lock, flags);
}
spin_unlock_irqrestore(&interrupt->ts_list_lock, flags);
}
base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9
--
2.25.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] accel/habanalabs: Fix timestamp record release on reset
2026-12-05 6:36 [PATCH] accel/habanalabs: Fix timestamp record release on reset Praneeth Balasubramanian
@ 2026-12-05 6:58 ` sashiko-bot
2026-12-05 12:25 ` Greg KH
1 sibling, 0 replies; 3+ messages in thread
From: sashiko-bot @ 2026-12-05 6:58 UTC (permalink / raw)
To: Praneeth Balasubramanian; +Cc: dri-devel
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] accel/habanalabs: inaccurate comment citing
unregister_timestamp_node()
--
commit 456b437299ee89a714b14ad80b2c00f226137c89
Author: Praneeth Balasubramanian <praneethb2002@gmail.com>
accel/habanalabs: Fix timestamp record release on reset
This commit updates wake_pending_user_interrupt_threads() to unlink each
pending timestamp record, clear ts_reg_info.in_use, and save the buffer
pointers before dropping ts_list_lock to release the timestamp and CQ
buffer references.
> diff --git a/drivers/accel/habanalabs/common/command_submission.c b/drivers/accel/habanalabs/common/command_submission.c
> index 8a3febc2089ed..8bff77bf42f89 100644
> --- a/drivers/accel/habanalabs/common/command_submission.c
> +++ b/drivers/accel/habanalabs/common/command_submission.c
[ ... ]
> @@ -1108,10 +1110,24 @@ wake_pending_user_interrupt_threads(struct hl_user_interrupt *interrupt)
> spin_unlock_irqrestore(&interrupt->wait_list_lock, flags);
>
> spin_lock_irqsave(&interrupt->ts_list_lock, flags);
> - list_for_each_entry_safe(pend, temp, &interrupt->ts_list_head, list_node) {
> + while (!list_empty(&interrupt->ts_list_head)) {
> + pend = list_first_entry(&interrupt->ts_list_head,
> + struct hl_user_pending_interrupt, list_node);
> + buf = pend->ts_reg_info.buf;
> + cq_cb = pend->ts_reg_info.cq_cb;
> list_del(&pend->list_node);
> - hl_mmap_mem_buf_put(pend->ts_reg_info.buf);
> - hl_cb_put(pend->ts_reg_info.cq_cb);
> + pend->ts_reg_info.in_use = false;
> + spin_unlock_irqrestore(&interrupt->ts_list_lock, flags);
> +
> + /*
> + * As in unregister_timestamp_node(), put the references without
> + * the lock: the release may sleep, and it may free the buffer
> + * that holds pend.
> + */
[Severity: Low]
Are this comment and the commit message accurate in saying
unregister_timestamp_node() snapshots the pointers and drops ts_list_lock
before putting the references?
In unregister_timestamp_node(), ts_list_lock is only dropped when
need_lock is true (ts_get_and_handle_kernel_record() calls it with
need_lock == false), and the buffer pointers are read directly from
record rather than saved under the lock:
drivers/accel/habanalabs/common/command_submission.c:unregister_timestamp_node() {
...
if (need_lock)
spin_unlock_irqrestore(&interrupt->ts_list_lock, flags);
/* Put refcounts that were taken when we registered the event */
if (ts_rec_found) {
hl_mmap_mem_buf_put(record->ts_reg_info.buf);
hl_cb_put(record->ts_reg_info.cq_cb);
}
}
Describing why wake_pending_user_interrupt_threads() drops the lock and
saves the pointers without citing unregister_timestamp_node() as a
precedent would avoid obscuring that discrepancy.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261205063651.2523441-1-praneethb2002@gmail.com?part=1
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] accel/habanalabs: Fix timestamp record release on reset
2026-12-05 6:36 [PATCH] accel/habanalabs: Fix timestamp record release on reset Praneeth Balasubramanian
2026-12-05 6:58 ` sashiko-bot
@ 2026-12-05 12:25 ` Greg KH
1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2026-12-05 12:25 UTC (permalink / raw)
To: Praneeth Balasubramanian
Cc: Konstantin Sinyuk, Koby Elbaz, Oded Gabbay, stable, dri-devel,
linux-kernel
On Fri, Dec 04, 2026 at 10:36:51PM -0800, Praneeth Balasubramanian wrote:
> Notes:
> This was found by an LLM-based audit, part of research at UCSB SecLab.
> An LLM turned a kernel comment into a rule, and three LLM votes checked
> the code against it. The fix and changelog were drafted with GLM-5.3,
> then checked against the source and partly rewritten with Claude Opus
> 5.5. I reviewed the patch and take responsibility for it.
Note, your "audit" was pretty bad, yet you sent out a ton of patches
without verifying anything first.
Please respond to each one, and ask for them to not be applied. Then
take the time to do this properly, i.e. do one patch, that you have
tested on real hardware, and get accepted, before attempting to send out
any more.
greg k-h
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-12-05 20:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-05 6:36 [PATCH] accel/habanalabs: Fix timestamp record release on reset Praneeth Balasubramanian
2026-12-05 6:58 ` sashiko-bot
2026-12-05 12:25 ` Greg KH
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.