* [PATCH] accel/habanalabs: Fix timestamp record release on reset
@ 2026-12-05 6:36 Praneeth Balasubramanian
2026-12-05 12:25 ` Greg KH
0 siblings, 1 reply; 2+ 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] 2+ 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 12:25 ` Greg KH
0 siblings, 0 replies; 2+ 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] 2+ messages in thread
end of thread, other threads:[~2026-12-05 20:43 UTC | newest]
Thread overview: 2+ 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 12:25 ` Greg KH
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox