Skip to content

Commit 8583840

Browse files
committed
witness: Record the first acquired file and line for recursable locks
and the last acquired file and line to witness object. For recursable locks, unfortunately current implementation records only the recurse count and the last acquired file and line, but does not restore the previous acquired file and line on unlock. Hence it is possible to report false acquired file and line, and that may mislead developers and make the report by users a little harder to analyse. Since subsequent recurse locks do not affect how witness order check, record the first acquired file and line so that the logic is much clear. Reported by: bz Reviewed by: kib (previous version), markj See also: https://lists.freebsd.org/archives/freebsd-current/2025-June/007944.html MFC after: 2 weeks Differential Revision: https://reviews.freebsd.org/D52496 (cherry picked from commit 2d85bc8) (cherry picked from commit 3dc9f96) (cherry picked from commit 7838ad8)
1 parent b4a079d commit 8583840

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

sys/kern/subr_witness.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1512,22 +1512,20 @@ witness_lock(struct lock_object *lock, int flags, const char *file, int line)
15121512
else
15131513
lock_list = PCPU_PTR(spinlocks);
15141514

1515+
/* Update per-witness last file and line acquire. */
1516+
w->w_file = file;
1517+
w->w_line = line;
1518+
15151519
/* Check to see if we are recursing on a lock we already own. */
15161520
instance = find_instance(*lock_list, lock);
15171521
if (instance != NULL) {
15181522
instance->li_flags++;
15191523
CTR4(KTR_WITNESS, "%s: pid %d recursed on %s r=%d", __func__,
15201524
td->td_proc->p_pid, lock->lo_name,
15211525
instance->li_flags & LI_RECURSEMASK);
1522-
instance->li_file = file;
1523-
instance->li_line = line;
15241526
return;
15251527
}
15261528

1527-
/* Update per-witness last file and line acquire. */
1528-
w->w_file = file;
1529-
w->w_line = line;
1530-
15311529
/* Find the next open lock instance in the list and fill it. */
15321530
lle = *lock_list;
15331531
if (lle == NULL || lle->ll_count == LOCK_NCHILDREN) {

0 commit comments

Comments
 (0)