pipex(4) layer is completely mp-safe, move the pipex_timer() timeout(9)
authormvs <mvs@openbsd.org>
Fri, 1 Dec 2023 20:30:22 +0000 (20:30 +0000)
committermvs <mvs@openbsd.org>
Fri, 1 Dec 2023 20:30:22 +0000 (20:30 +0000)
handler out of kernel lock.

ok bluhm

sys/net/pipex.c

index ac42168..299d190 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: pipex.c,v 1.150 2023/11/28 13:23:20 bluhm Exp $ */
+/*     $OpenBSD: pipex.c,v 1.151 2023/12/01 20:30:22 mvs Exp $ */
 
 /*-
  * Copyright (c) 2009 Internet Initiative Japan Inc.
@@ -716,7 +716,8 @@ pipex_lookup_by_session_id(int protocol, int session_id)
 void
 pipex_timer_start(void)
 {
-       timeout_set_proc(&pipex_timer_ch, pipex_timer, NULL);
+       timeout_set_flags(&pipex_timer_ch, pipex_timer, NULL,
+           KCLOCK_NONE, TIMEOUT_PROC | TIMEOUT_MPSAFE);
        timeout_add_sec(&pipex_timer_ch, pipex_prune);
 }
 
@@ -731,8 +732,6 @@ pipex_timer(void *ignored_arg)
 {
        struct pipex_session *session, *session_tmp;
 
-       timeout_add_sec(&pipex_timer_ch, pipex_prune);
-
        mtx_enter(&pipex_list_mtx);
        /* walk through */
        LIST_FOREACH_SAFE(session, &pipex_session_list, session_list,
@@ -767,6 +766,9 @@ pipex_timer(void *ignored_arg)
                }
        }
 
+       if (LIST_FIRST(&pipex_session_list))
+               timeout_add_sec(&pipex_timer_ch, pipex_prune);
+
        mtx_leave(&pipex_list_mtx);
 }