Move SCHED_LOCK after sleep_signal_check.
authorclaudio <claudio@openbsd.org>
Wed, 16 Aug 2023 07:55:52 +0000 (07:55 +0000)
committerclaudio <claudio@openbsd.org>
Wed, 16 Aug 2023 07:55:52 +0000 (07:55 +0000)
sleep_signal_check() is there to look for pending signals / single thread
requests which were posted before sleep_setup() finished. Once p_stat
is set to SSLEEP the wakeup and delivery of signals is taken care of
by ptsignal and single_thread_set().

Moving the SCHED_LOCK further down allows to cleanup cursig() and to
remove a SCHED_LOCK recursion in single_thread_check().

OK mpi@

sys/kern/kern_sig.c
sys/kern/kern_synch.c

index eaa7266..af0e0d7 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_sig.c,v 1.312 2023/08/13 15:53:31 claudio Exp $  */
+/*     $OpenBSD: kern_sig.c,v 1.313 2023/08/16 07:55:52 claudio Exp $  */
 /*     $NetBSD: kern_sig.c,v 1.54 1996/04/22 01:38:32 christos Exp $   */
 
 /*
@@ -1251,7 +1251,6 @@ cursig(struct proc *p, struct sigctx *sctx)
 {
        struct process *pr = p->p_p;
        int signum, mask, prop;
-       int dolock = (p->p_flag & P_SINTR) == 0;
        sigset_t ps_siglist;
        int s;
 
@@ -1294,11 +1293,9 @@ cursig(struct proc *p, struct sigctx *sctx)
                        single_thread_set(p, SINGLE_SUSPEND, 0);
                        pr->ps_xsig = signum;
 
-                       if (dolock)
-                               SCHED_LOCK(s);
+                       SCHED_LOCK(s);
                        proc_stop(p, 1);
-                       if (dolock)
-                               SCHED_UNLOCK(s);
+                       SCHED_UNLOCK(s);
 
                        /*
                         * re-take the signal before releasing
@@ -1371,11 +1368,9 @@ cursig(struct proc *p, struct sigctx *sctx)
                                    prop & SA_TTYSTOP))
                                        break;  /* == ignore */
                                pr->ps_xsig = signum;
-                               if (dolock)
-                                       SCHED_LOCK(s);
+                               SCHED_LOCK(s);
                                proc_stop(p, 1);
-                               if (dolock)
-                                       SCHED_UNLOCK(s);
+                               SCHED_UNLOCK(s);
                                break;
                        } else if (prop & SA_IGNORE) {
                                /*
index 591fa77..624bf52 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: kern_synch.c,v 1.197 2023/08/14 08:33:24 mpi Exp $    */
+/*     $OpenBSD: kern_synch.c,v 1.198 2023/08/16 07:55:52 claudio Exp $        */
 /*     $NetBSD: kern_synch.c,v 1.37 1996/04/22 01:38:37 christos Exp $ */
 
 /*
@@ -373,7 +373,6 @@ sleep_finish(int timo, int do_sleep)
                timeout_add(&p->p_sleep_to, timo);
        }
 
-       SCHED_LOCK(s);
        if (catch != 0) {
                /*
                 * We put ourselves on the sleep queue and start our
@@ -390,6 +389,7 @@ sleep_finish(int timo, int do_sleep)
                }
        }
 
+       SCHED_LOCK(s);
        /*
         * If the wakeup happens while going to sleep, p->p_wchan
         * will be NULL. In that case unwind immediately but still