diff options
author | Taylor Brandstetter <deadbeef@google.com> | 2020-02-02 14:05:24 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-02 23:05:24 +0100 |
commit | bee946a606752a443bd70bca1cb296527fed706d (patch) | |
tree | 6b61f0f1588c347de69704f66a29c3a2207c20f5 | |
parent | aa10d60bc209028b7dd0370b2d5af9f14051fd23 (diff) | |
download | usrsctp-bee946a606752a443bd70bca1cb296527fed706d.tar.gz |
Revert series of callout guard commits (#423)
* Revert "Fix callout stop deadlock"
This reverts commit 21943f41104efcd40e801d6542b110b5440b498d.
* Revert "Fix for missing timer wait wakeups"
This reverts commit faf6330b91d7e9768aa10f3f22484885a83e0f02.
* Revert "Fix for rescheduling a timer that is currently in progress."
This reverts commit d225e88dcafbbfc865c67589353c6a9ae3ce9bc8.
* Revert "Pull in missing guard for the currently executing callout (v2)"
This reverts commit 164ca603a26ebb870418fa5709f09bab9b61a3ab.
* Revert "Pull in missing guard for the currently executing callout"
This reverts commit a7c290275a0f8a164c132396b34f46e295c193f7.
-rwxr-xr-x | usrsctplib/netinet/sctp_callout.c | 100 | ||||
-rwxr-xr-x | usrsctplib/netinet/sctp_callout.h | 13 | ||||
-rwxr-xr-x | usrsctplib/netinet/sctp_os_userspace.h | 5 | ||||
-rwxr-xr-x | usrsctplib/netinet/sctp_pcb.c | 3 | ||||
-rwxr-xr-x | usrsctplib/netinet/sctp_userspace.c | 26 |
5 files changed, 1 insertions, 146 deletions
diff --git a/usrsctplib/netinet/sctp_callout.c b/usrsctplib/netinet/sctp_callout.c index a08d6408..c6cffc78 100755 --- a/usrsctplib/netinet/sctp_callout.c +++ b/usrsctplib/netinet/sctp_callout.c @@ -77,27 +77,8 @@ uint32_t sctp_get_tick_count(void) { * SCTP_TIMERQ_LOCK protects: * - SCTP_BASE_INFO(callqueue) * - sctp_os_timer_next: next timer to check - * - sctp_os_timer_current: current callout callback in progress - * - sctp_os_timer_current_tid: current callout thread id in progress - * - sctp_os_timer_waiting: some thread is waiting for callout to complete - * - sctp_os_timer_wait_ctr: incremented every time a thread wants to wait - * for a callout to complete. */ static sctp_os_timer_t *sctp_os_timer_next = NULL; -static sctp_os_timer_t *sctp_os_timer_current = NULL; -static int sctp_os_timer_waiting = 0; -static int sctp_os_timer_wait_ctr = 0; -static userland_thread_id_t sctp_os_timer_current_tid; - -/* - * SCTP_TIMERWAIT_LOCK (sctp_os_timerwait_mtx) protects: - * - sctp_os_timer_wait_cond: waiting for callout to complete - * - sctp_os_timer_done_ctr: value of "wait_ctr" after triggering "waiting" - */ -userland_mutex_t sctp_os_timerwait_mtx; -static userland_cond_t sctp_os_timer_wait_cond; -static int sctp_os_timer_done_ctr = 0; - void sctp_os_timer_init(sctp_os_timer_t *c) @@ -115,21 +96,6 @@ sctp_os_timer_start(sctp_os_timer_t *c, uint32_t to_ticks, void (*ftn) (void *), SCTP_TIMERQ_LOCK(); /* check to see if we're rescheduling a timer */ - if (c == sctp_os_timer_current) { - /* - * We're being asked to reschedule a callout which is - * currently in progress. - */ - if (sctp_os_timer_waiting) { - /* - * This callout is already being stopped. - * callout. Don't reschedule. - */ - SCTP_TIMERQ_UNLOCK(); - return; - } - } - if (c->c_flags & SCTP_CALLOUT_PENDING) { if (c == sctp_os_timer_next) { sctp_os_timer_next = TAILQ_NEXT(c, tqe); @@ -161,51 +127,13 @@ sctp_os_timer_start(sctp_os_timer_t *c, uint32_t to_ticks, void (*ftn) (void *), int sctp_os_timer_stop(sctp_os_timer_t *c) { - int wakeup_cookie; - SCTP_TIMERQ_LOCK(); /* * Don't attempt to delete a callout that's not on the queue. */ if (!(c->c_flags & SCTP_CALLOUT_PENDING)) { c->c_flags &= ~SCTP_CALLOUT_ACTIVE; - if (sctp_os_timer_current != c) { - SCTP_TIMERQ_UNLOCK(); - return (0); - } else { - /* - * Deleting the callout from the currently running - * callout from the same thread, so just return - */ - userland_thread_id_t tid; - sctp_userspace_thread_id(&tid); - if (sctp_userspace_thread_equal(tid, - sctp_os_timer_current_tid)) { - SCTP_TIMERQ_UNLOCK(); - return (0); - } - - /* need to wait until the callout is finished */ - sctp_os_timer_waiting = 1; - wakeup_cookie = ++sctp_os_timer_wait_ctr; - SCTP_TIMERQ_UNLOCK(); - SCTP_TIMERWAIT_LOCK(); - /* - * wait only if sctp_handle_tick didn't do a wakeup - * in between the lock dance - */ - if (wakeup_cookie - sctp_os_timer_done_ctr > 0) { -#if defined (__Userspace_os_Windows) - SleepConditionVariableCS(&sctp_os_timer_wait_cond, - &sctp_os_timerwait_mtx, - INFINITE); -#else - pthread_cond_wait(&sctp_os_timer_wait_cond, - &sctp_os_timerwait_mtx); -#endif - } - SCTP_TIMERWAIT_UNLOCK(); - } + SCTP_TIMERQ_UNLOCK(); return (0); } c->c_flags &= ~(SCTP_CALLOUT_ACTIVE | SCTP_CALLOUT_PENDING); @@ -223,7 +151,6 @@ sctp_handle_tick(uint32_t elapsed_ticks) sctp_os_timer_t *c; void (*c_func)(void *); void *c_arg; - int wakeup_cookie; SCTP_TIMERQ_LOCK(); /* update our tick count */ @@ -236,26 +163,9 @@ sctp_handle_tick(uint32_t elapsed_ticks) c_func = c->c_func; c_arg = c->c_arg; c->c_flags &= ~SCTP_CALLOUT_PENDING; - sctp_os_timer_current = c; - sctp_userspace_thread_id(&sctp_os_timer_current_tid); SCTP_TIMERQ_UNLOCK(); c_func(c_arg); SCTP_TIMERQ_LOCK(); - sctp_os_timer_current = NULL; - if (sctp_os_timer_waiting) { - wakeup_cookie = sctp_os_timer_wait_ctr; - SCTP_TIMERQ_UNLOCK(); - SCTP_TIMERWAIT_LOCK(); -#if defined (__Userspace_os_Windows) - WakeAllConditionVariable(&sctp_os_timer_wait_cond); -#else - pthread_cond_broadcast(&sctp_os_timer_wait_cond); -#endif - sctp_os_timer_done_ctr = wakeup_cookie; - SCTP_TIMERWAIT_UNLOCK(); - SCTP_TIMERQ_LOCK(); - sctp_os_timer_waiting = 0; - } c = sctp_os_timer_next; } else { c = TAILQ_NEXT(c, tqe); @@ -310,14 +220,6 @@ sctp_start_timer(void) */ int rc; -#if defined(__Userspace_os_Windows) - InitializeConditionVariable(&sctp_os_timer_wait_cond); -#else - rc = pthread_cond_init(&sctp_os_timer_wait_cond, NULL); - if (rc) - SCTP_PRINTF("ERROR; return code from pthread_cond_init is %d\n", rc); -#endif - rc = sctp_userspace_thread_create(&SCTP_BASE_VAR(timer_thread), user_sctp_timer_iterate); if (rc) { SCTP_PRINTF("ERROR; return code from sctp_thread_create() is %d\n", rc); diff --git a/usrsctplib/netinet/sctp_callout.h b/usrsctplib/netinet/sctp_callout.h index 0f4dc6b4..13279da0 100755 --- a/usrsctplib/netinet/sctp_callout.h +++ b/usrsctplib/netinet/sctp_callout.h @@ -52,35 +52,22 @@ __FBSDID("$FreeBSD$"); #define SCTP_TICKS_PER_FASTTIMO 20 /* called about every 20ms */ -extern userland_mutex_t sctp_os_timerwait_mtx; - #if defined(__Userspace__) #if defined(__Userspace_os_Windows) #define SCTP_TIMERQ_LOCK() EnterCriticalSection(&SCTP_BASE_VAR(timer_mtx)) #define SCTP_TIMERQ_UNLOCK() LeaveCriticalSection(&SCTP_BASE_VAR(timer_mtx)) #define SCTP_TIMERQ_LOCK_INIT() InitializeCriticalSection(&SCTP_BASE_VAR(timer_mtx)) #define SCTP_TIMERQ_LOCK_DESTROY() DeleteCriticalSection(&SCTP_BASE_VAR(timer_mtx)) - -#define SCTP_TIMERWAIT_LOCK() EnterCriticalSection(&sctp_os_timerwait_mtx) -#define SCTP_TIMERWAIT_UNLOCK() LeaveCriticalSection(&sctp_os_timerwait_mtx) -#define SCTP_TIMERWAIT_LOCK_INIT() InitializeCriticalSection(&sctp_os_timerwait_mtx) -#define SCTP_TIMERWAIT_LOCK_DESTROY() DeleteCriticalSection(&sctp_os_timerwait_mtx) #else #ifdef INVARIANTS #define SCTP_TIMERQ_LOCK() KASSERT(pthread_mutex_lock(&SCTP_BASE_VAR(timer_mtx)) == 0, ("%s: timer_mtx already locked", __func__)) #define SCTP_TIMERQ_UNLOCK() KASSERT(pthread_mutex_unlock(&SCTP_BASE_VAR(timer_mtx)) == 0, ("%s: timer_mtx not locked", __func__)) -#define SCTP_TIMERWAIT_LOCK() KASSERT(pthread_mutex_lock(&sctp_os_timerwait_mtx) == 0, ("%s: sctp_os_timerwait_mtx already locked", __func__)) -#define SCTP_TIMERWAIT_UNLOCK() KASSERT(pthread_mutex_unlock(&sctp_os_timerwait_mtx) == 0, ("%s: sctp_os_timerwait_mtx not locked", __func__)) #else #define SCTP_TIMERQ_LOCK() (void)pthread_mutex_lock(&SCTP_BASE_VAR(timer_mtx)) #define SCTP_TIMERQ_UNLOCK() (void)pthread_mutex_unlock(&SCTP_BASE_VAR(timer_mtx)) -#define SCTP_TIMERWAIT_LOCK() (void)pthread_mutex_lock(&sctp_os_timerwait_mtx) -#define SCTP_TIMERWAIT_UNLOCK() (void)pthread_mutex_unlock(&sctp_os_timerwait_mtx) #endif #define SCTP_TIMERQ_LOCK_INIT() (void)pthread_mutex_init(&SCTP_BASE_VAR(timer_mtx), &SCTP_BASE_VAR(mtx_attr)) #define SCTP_TIMERQ_LOCK_DESTROY() (void)pthread_mutex_destroy(&SCTP_BASE_VAR(timer_mtx)) -#define SCTP_TIMERWAIT_LOCK_INIT() (void)pthread_mutex_init(&sctp_os_timerwait_mtx, &SCTP_BASE_VAR(mtx_attr)) -#define SCTP_TIMERWAIT_LOCK_DESTROY() (void)pthread_mutex_destroy(&sctp_os_timerwait_mtx) #endif #endif diff --git a/usrsctplib/netinet/sctp_os_userspace.h b/usrsctplib/netinet/sctp_os_userspace.h index 9bc190d3..f09cb8da 100755 --- a/usrsctplib/netinet/sctp_os_userspace.h +++ b/usrsctplib/netinet/sctp_os_userspace.h @@ -76,7 +76,6 @@ void WakeAllXPConditionVariable(userland_cond_t *); typedef CONDITION_VARIABLE userland_cond_t; #endif typedef HANDLE userland_thread_t; -typedef DWORD userland_thread_id_t; #define ADDRESS_FAMILY unsigned __int8 #define IPVERSION 4 #define MAXTTL 255 @@ -284,7 +283,6 @@ typedef char* caddr_t; typedef pthread_mutex_t userland_mutex_t; typedef pthread_cond_t userland_cond_t; typedef pthread_t userland_thread_t; -typedef pthread_t userland_thread_id_t; #endif #if defined(__Userspace_os_Windows) || defined(__Userspace_os_NaCl) @@ -1037,9 +1035,6 @@ sctp_userspace_thread_create(userland_thread_t *thread, start_routine_t start_ro void sctp_userspace_set_threadname(const char *name); -int sctp_userspace_thread_id(userland_thread_id_t *thread); -int sctp_userspace_thread_equal(userland_thread_id_t t1, userland_thread_id_t t2); - /* * SCTP protocol specific mbuf flags. */ diff --git a/usrsctplib/netinet/sctp_pcb.c b/usrsctplib/netinet/sctp_pcb.c index 2220862f..02779e53 100755 --- a/usrsctplib/netinet/sctp_pcb.c +++ b/usrsctplib/netinet/sctp_pcb.c @@ -6845,7 +6845,6 @@ sctp_pcb_init(void) #if defined(_SCTP_NEEDS_CALLOUT_) || defined(_USER_SCTP_NEEDS_CALLOUT_) /* allocate the lock for the callout/timer queue */ SCTP_TIMERQ_LOCK_INIT(); - SCTP_TIMERWAIT_LOCK_INIT(); TAILQ_INIT(&SCTP_BASE_INFO(callqueue)); #endif #if defined(__Userspace__) @@ -7041,7 +7040,6 @@ retry: /* free the locks and mutexes */ #if defined(__APPLE__) SCTP_TIMERQ_LOCK_DESTROY(); - SCTP_TIMERWAIT_LOCK_DESTROY(); #endif #ifdef SCTP_PACKET_LOGGING SCTP_IP_PKTLOG_DESTROY(); @@ -7068,7 +7066,6 @@ retry: #endif #if defined(__Userspace__) SCTP_TIMERQ_LOCK_DESTROY(); - SCTP_TIMERWAIT_LOCK_DESTROY(); SCTP_ZONE_DESTROY(zone_mbuf); SCTP_ZONE_DESTROY(zone_clust); SCTP_ZONE_DESTROY(zone_ext_refcnt); diff --git a/usrsctplib/netinet/sctp_userspace.c b/usrsctplib/netinet/sctp_userspace.c index 7ff8a2d4..28922b6a 100755 --- a/usrsctplib/netinet/sctp_userspace.c +++ b/usrsctplib/netinet/sctp_userspace.c @@ -68,19 +68,6 @@ sctp_userspace_thread_create(userland_thread_t *thread, start_routine_t start_ro return 0; } -int -sctp_userspace_thread_id(userland_thread_id_t *thread) -{ - *thread = GetCurrentThreadId(); - return 0; -} - -int -sctp_userspace_thread_equal(userland_thread_id_t t1, userland_thread_id_t t2) -{ - return (t1 == t2); -} - #if defined(__MINGW32__) #pragma GCC diagnostic pop #endif @@ -91,19 +78,6 @@ sctp_userspace_thread_create(userland_thread_t *thread, start_routine_t start_ro { return pthread_create(thread, NULL, start_routine, NULL); } - -int -sctp_userspace_thread_id(userland_thread_id_t *thread) -{ - *thread = pthread_self(); - return 0; -} - -int -sctp_userspace_thread_equal(userland_thread_id_t t1, userland_thread_id_t t2) -{ - return pthread_equal(t1, t2); -} #endif void |