Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/kern Fix "restart" semantics -- restart is terminal, so ...



details:   https://anonhg.NetBSD.org/src/rev/9aa8b149cd9d
branches:  trunk
changeset: 1026424:9aa8b149cd9d
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Wed Nov 24 16:35:33 2021 +0000

description:
Fix "restart" semantics -- restart is terminal, so don't clear the
condition when previous waiters have drained.  ("restart" is a bad
name for that this function does, fwiw.)

This should address a kernel assertion failure reported by Chavdar Ivanov
on current-users.

diffstat:

 sys/kern/sys_eventfd.c |  23 ++++++-----------------
 sys/kern/sys_timerfd.c |  23 ++++++-----------------
 2 files changed, 12 insertions(+), 34 deletions(-)

diffs (167 lines):

diff -r dd83029269ef -r 9aa8b149cd9d sys/kern/sys_eventfd.c
--- a/sys/kern/sys_eventfd.c    Wed Nov 24 15:05:15 2021 +0000
+++ b/sys/kern/sys_eventfd.c    Wed Nov 24 16:35:33 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_eventfd.c,v 1.7 2021/09/27 00:40:49 thorpej Exp $  */
+/*     $NetBSD: sys_eventfd.c,v 1.8 2021/11/24 16:35:33 thorpej Exp $  */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_eventfd.c,v 1.7 2021/09/27 00:40:49 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_eventfd.c,v 1.8 2021/11/24 16:35:33 thorpej Exp $");
 
 /*
  * eventfd
@@ -64,7 +64,6 @@
        kmutex_t        efd_lock;
        kcondvar_t      efd_read_wait;
        kcondvar_t      efd_write_wait;
-       kcondvar_t      efd_restart_wait;
        struct selinfo  efd_read_sel;
        struct selinfo  efd_write_sel;
        eventfd_t       efd_val;
@@ -97,7 +96,6 @@
        mutex_init(&efd->efd_lock, MUTEX_DEFAULT, IPL_NONE);
        cv_init(&efd->efd_read_wait, "efdread");
        cv_init(&efd->efd_write_wait, "efdwrite");
-       cv_init(&efd->efd_restart_wait, "efdrstrt");
        selinit(&efd->efd_read_sel);
        selinit(&efd->efd_write_sel);
        efd->efd_val = val;
@@ -119,13 +117,11 @@
 {
 
        KASSERT(efd->efd_nwaiters == 0);
-       KASSERT(efd->efd_restarting == false);
        KASSERT(efd->efd_has_read_waiters == false);
        KASSERT(efd->efd_has_write_waiters == false);
 
        cv_destroy(&efd->efd_read_wait);
        cv_destroy(&efd->efd_write_wait);
-       cv_destroy(&efd->efd_restart_wait);
 
        seldestroy(&efd->efd_read_sel);
        seldestroy(&efd->efd_write_sel);
@@ -152,11 +148,10 @@
        }
 
        /*
-        * We're going to block.  If there is a restart in-progress,
-        * wait for that to complete first.
+        * We're going to block.  Check if we need to return ERESTART.
         */
-       while (efd->efd_restarting) {
-               cv_wait(&efd->efd_restart_wait, &efd->efd_lock);
+       if (efd->efd_restarting) {
+               return ERESTART;
        }
 
        if (is_write) {
@@ -175,18 +170,12 @@
 
        /*
         * If a restart was triggered while we were asleep, we need
-        * to return ERESTART if no other error was returned.  If we
-        * are the last waiter coming out of the restart drain, clear
-        * the condition.
+        * to return ERESTART if no other error was returned.
         */
        if (efd->efd_restarting) {
                if (error == 0) {
                        error = ERESTART;
                }
-               if (efd->efd_nwaiters == 0) {
-                       efd->efd_restarting = false;
-                       cv_broadcast(&efd->efd_restart_wait);
-               }
        }
 
        return error;
diff -r dd83029269ef -r 9aa8b149cd9d sys/kern/sys_timerfd.c
--- a/sys/kern/sys_timerfd.c    Wed Nov 24 15:05:15 2021 +0000
+++ b/sys/kern/sys_timerfd.c    Wed Nov 24 16:35:33 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sys_timerfd.c,v 1.6 2021/09/27 00:40:49 thorpej Exp $  */
+/*     $NetBSD: sys_timerfd.c,v 1.7 2021/11/24 16:35:33 thorpej Exp $  */
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_timerfd.c,v 1.6 2021/09/27 00:40:49 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_timerfd.c,v 1.7 2021/11/24 16:35:33 thorpej Exp $");
 
 /*
  * timerfd
@@ -71,7 +71,6 @@
 struct timerfd {
        struct itimer   tfd_itimer;
        kcondvar_t      tfd_read_wait;
-       kcondvar_t      tfd_restart_wait;
        struct selinfo  tfd_read_sel;
        int64_t         tfd_nwaiters;
        bool            tfd_cancel_on_set;
@@ -162,7 +161,6 @@
        KASSERT(clock_id == CLOCK_REALTIME || clock_id == CLOCK_MONOTONIC);
 
        cv_init(&tfd->tfd_read_wait, "tfdread");
-       cv_init(&tfd->tfd_restart_wait, "tfdrstrt");
        selinit(&tfd->tfd_read_sel);
        getnanotime(&tfd->tfd_btime);
 
@@ -188,14 +186,12 @@
 {
 
        KASSERT(tfd->tfd_nwaiters == 0);
-       KASSERT(tfd->tfd_restarting == false);
 
        itimer_lock();
        itimer_poison(&tfd->tfd_itimer);
        itimer_fini(&tfd->tfd_itimer);  /* drops itimer lock */
 
        cv_destroy(&tfd->tfd_read_wait);
-       cv_destroy(&tfd->tfd_restart_wait);
 
        seldestroy(&tfd->tfd_read_sel);
 
@@ -219,11 +215,10 @@
        }
 
        /*
-        * We're going to block.  If there is a restart in-progress,
-        * wait for that to complete first.
+        * We're going to block.  Check if we need to return ERESTART.
         */
-       while (tfd->tfd_restarting) {
-               cv_wait(&tfd->tfd_restart_wait, &itimer_mutex);
+       if (tfd->tfd_restarting) {
+               return ERESTART;
        }
 
        tfd->tfd_nwaiters++;
@@ -234,18 +229,12 @@
 
        /*
         * If a restart was triggered while we were asleep, we need
-        * to return ERESTART if no other error was returned.  If we
-        * are the last waiter coming out of the restart drain, clear
-        * the condition.
+        * to return ERESTART if no other error was returned.
         */
        if (tfd->tfd_restarting) {
                if (error == 0) {
                        error = ERESTART;
                }
-               if (tfd->tfd_nwaiters == 0) {
-                       tfd->tfd_restarting = false;
-                       cv_broadcast(&tfd->tfd_restart_wait);
-               }
        }
 
        return error;



Home | Main Index | Thread Index | Old Index