The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=96759ab67a42226679675e24e35549aea2aa49e0
commit 96759ab67a42226679675e24e35549aea2aa49e0 Author: Konstantin Belousov <[email protected]> AuthorDate: 2026-06-15 00:59:46 +0000 Commit: Konstantin Belousov <[email protected]> CommitDate: 2026-06-15 12:56:40 +0000 ntsync(9): properly handle timeouts Reported by: Alex S <[email protected]> Sponsored by: The FreeBSD Foundation MFC after: 3 days --- sys/dev/ntsync/ntsync.c | 16 ++++++++++++---- sys/dev/ntsync/ntsyncvar.h | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/sys/dev/ntsync/ntsync.c b/sys/dev/ntsync/ntsync.c index a7b002de7cb6..2d3054e0a4ee 100644 --- a/sys/dev/ntsync/ntsync.c +++ b/sys/dev/ntsync/ntsync.c @@ -215,7 +215,7 @@ ntsync_wait_locked(struct ntsync_wait_state *state, struct thread *td) if (state->ready) break; error = msleep_sbt(state, &state->owner->lock, - PCATCH, "ntsync", state->sb, 0, + PCATCH, "ntsync", state->sb, state->prec, C_ABSOLUTE /* | C_HARDCLOCK XXXKIB */); /* @@ -1195,7 +1195,6 @@ ntsync_wait_state_get(struct ntsync_wait_args *nwa, u_long cmd, { struct ntsync_wait_state *state; struct ntsync_obj *obj; - struct bintime btb; int error, i, j; if (nwa->count > NTSYNC_MAX_WAIT_COUNT) @@ -1270,14 +1269,23 @@ ntsync_wait_state_get(struct ntsync_wait_args *nwa, u_long cmd, } } + state->prec = 0; if (nwa->timeout == UINT64_MAX) { state->sb = 0; } else { state->sb = nstosbt(nwa->timeout); if ((nwa->flags & NTSYNC_WAIT_REALTIME) != 0) { - getboottimebin(&btb); - state->sb += bttosbt(btb); + struct bintime btb; + + bintime(&btb); + state->sb -= bttosbt(btb); + } else { + struct timespec ts; + + nanouptime(&ts); + state->sb -= tstosbt(ts); } + state->sb += sbinuptime(); } *statep = state; diff --git a/sys/dev/ntsync/ntsyncvar.h b/sys/dev/ntsync/ntsyncvar.h index fd875588e889..97828c99bb7d 100644 --- a/sys/dev/ntsync/ntsyncvar.h +++ b/sys/dev/ntsync/ntsyncvar.h @@ -81,6 +81,7 @@ struct ntsync_wait_state { struct ntsync_obj *objs[NTSYNC_MAX_WAIT_COUNT + 1]; struct ntsync_obj_event *alert_event; sbintime_t sb; + sbintime_t prec; int error; int index; bool any;
