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 <[email protected]>

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/[email protected]?part=1

Reply via email to