From owner-dev-commits-src-main@freebsd.org Tue Sep 21 16:02:59 2021 Return-Path: Delivered-To: dev-commits-src-main@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id B46256761A9; Tue, 21 Sep 2021 16:02:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HDR6C4b00z3GNk; Tue, 21 Sep 2021 16:02:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 7D2AB26EA0; Tue, 21 Sep 2021 16:02:59 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 18LG2xaP022239; Tue, 21 Sep 2021 16:02:59 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 18LG2xtt022238; Tue, 21 Sep 2021 16:02:59 GMT (envelope-from git) Date: Tue, 21 Sep 2021 16:02:59 GMT Message-Id: <202109211602.18LG2xtt022238@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Michael Tuexen Subject: git: 762ae0ec8d83 - main - sctp: Simplify stream scheduler usage MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: tuexen X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 762ae0ec8d83ed0e3c084e19174b4bd809a7ef2d Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-main@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for the main branch of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Sep 2021 16:02:59 -0000 The branch main has been updated by tuexen: URL: https://cgit.FreeBSD.org/src/commit/?id=762ae0ec8d83ed0e3c084e19174b4bd809a7ef2d commit 762ae0ec8d83ed0e3c084e19174b4bd809a7ef2d Author: Michael Tuexen AuthorDate: 2021-09-21 15:13:57 +0000 Commit: Michael Tuexen CommitDate: 2021-09-21 15:13:57 +0000 sctp: Simplify stream scheduler usage Callers are getting the stcb send lock, so just KASSERT that. No need to signal this when calling stream scheduler functions. No functional change intended. MFC after: 1 week --- sys/netinet/sctp_input.c | 4 +- sys/netinet/sctp_lock_bsd.h | 5 ++ sys/netinet/sctp_output.c | 12 +-- sys/netinet/sctp_pcb.c | 2 +- sys/netinet/sctp_ss_functions.c | 171 ++++++++++++---------------------------- sys/netinet/sctp_structs.h | 9 +-- sys/netinet/sctp_timer.c | 2 +- sys/netinet/sctp_usrreq.c | 8 +- sys/netinet/sctputil.c | 4 +- 9 files changed, 76 insertions(+), 141 deletions(-) diff --git a/sys/netinet/sctp_input.c b/sys/netinet/sctp_input.c index e2cd2cf87ac9..c0a976b84184 100644 --- a/sys/netinet/sctp_input.c +++ b/sys/netinet/sctp_input.c @@ -213,7 +213,7 @@ sctp_is_there_unsent_data(struct sctp_tcb *stcb, int so_locked) } atomic_subtract_int(&stcb->asoc.stream_queue_cnt, 1); TAILQ_REMOVE(&stcb->asoc.strmout[i].outqueue, sp, next); - stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, &asoc->strmout[i], sp, 1); + stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, &asoc->strmout[i], sp); if (sp->net) { sctp_free_remote_addr(sp->net); sp->net = NULL; @@ -302,7 +302,7 @@ sctp_process_init(struct sctp_init_chunk *cp, struct sctp_tcb *stcb) TAILQ_FOREACH_SAFE(sp, &outs->outqueue, next, nsp) { atomic_subtract_int(&stcb->asoc.stream_queue_cnt, 1); TAILQ_REMOVE(&outs->outqueue, sp, next); - stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, outs, sp, 1); + stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, outs, sp); sctp_ulp_notify(SCTP_NOTIFY_SPECIAL_SP_FAIL, stcb, 0, sp, SCTP_SO_NOT_LOCKED); if (sp->data) { diff --git a/sys/netinet/sctp_lock_bsd.h b/sys/netinet/sctp_lock_bsd.h index e7cf8b3221b9..cd20a730e5b8 100644 --- a/sys/netinet/sctp_lock_bsd.h +++ b/sys/netinet/sctp_lock_bsd.h @@ -354,6 +354,11 @@ __FBSDID("$FreeBSD$"); mtx_unlock(&(_tcb)->tcb_send_mtx); \ } while (0) +#define SCTP_TCB_SEND_LOCK_ASSERT(_tcb) do { \ + KASSERT(mtx_owned(&(_tcb)->tcb_send_mtx), \ + ("Don't own TCB send lock")); \ +} while (0) + /* * For the majority of things (once we have found the association) we will * lock the actual association mutex. This will protect all the assoiciation diff --git a/sys/netinet/sctp_output.c b/sys/netinet/sctp_output.c index 27ad92527454..36339ac0f2b1 100644 --- a/sys/netinet/sctp_output.c +++ b/sys/netinet/sctp_output.c @@ -6399,7 +6399,7 @@ sctp_msg_append(struct sctp_tcb *stcb, sctp_snd_sb_alloc(stcb, sp->length); atomic_add_int(&stcb->asoc.stream_queue_cnt, 1); TAILQ_INSERT_TAIL(&strm->outqueue, sp, next); - stcb->asoc.ss_functions.sctp_ss_add_to_stream(stcb, &stcb->asoc, strm, sp, 1); + stcb->asoc.ss_functions.sctp_ss_add_to_stream(stcb, &stcb->asoc, strm, sp); m = NULL; if (hold_stcb_lock == 0) { SCTP_TCB_SEND_UNLOCK(stcb); @@ -7213,7 +7213,7 @@ one_more_time: } atomic_subtract_int(&asoc->stream_queue_cnt, 1); TAILQ_REMOVE(&strq->outqueue, sp, next); - stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, strq, sp, 1); + stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, strq, sp); if ((strq->state == SCTP_STREAM_RESET_PENDING) && (strq->chunks_on_queues == 0) && TAILQ_EMPTY(&strq->outqueue)) { @@ -7644,7 +7644,7 @@ dont_do_it: } atomic_subtract_int(&asoc->stream_queue_cnt, 1); TAILQ_REMOVE(&strq->outqueue, sp, next); - stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, strq, sp, 1); + stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, strq, sp); if ((strq->state == SCTP_STREAM_RESET_PENDING) && (strq->chunks_on_queues == 0) && TAILQ_EMPTY(&strq->outqueue)) { @@ -12176,7 +12176,7 @@ sctp_send_str_reset_req(struct sctp_tcb *stcb, * initializing the new stuff. */ SCTP_TCB_SEND_LOCK(stcb); - stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 0, 1); + stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 0); for (i = 0; i < stcb->asoc.streamoutcnt; i++) { TAILQ_INIT(&stcb->asoc.strmout[i].outqueue); /* FIX ME FIX ME */ @@ -12207,7 +12207,7 @@ sctp_send_str_reset_req(struct sctp_tcb *stcb, } } /* now the new streams */ - stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1); + stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc); for (i = stcb->asoc.streamoutcnt; i < (stcb->asoc.streamoutcnt + adding_o); i++) { TAILQ_INIT(&stcb->asoc.strmout[i].outqueue); stcb->asoc.strmout[i].chunks_on_queues = 0; @@ -13161,7 +13161,7 @@ skip_preblock: } sp->processing = 1; TAILQ_INSERT_TAIL(&strm->outqueue, sp, next); - stcb->asoc.ss_functions.sctp_ss_add_to_stream(stcb, asoc, strm, sp, 1); + stcb->asoc.ss_functions.sctp_ss_add_to_stream(stcb, asoc, strm, sp); } else { sp = TAILQ_LAST(&strm->outqueue, sctp_streamhead); if (sp == NULL) { diff --git a/sys/netinet/sctp_pcb.c b/sys/netinet/sctp_pcb.c index fabe19c1444d..563a167b782f 100644 --- a/sys/netinet/sctp_pcb.c +++ b/sys/netinet/sctp_pcb.c @@ -4923,7 +4923,7 @@ sctp_free_assoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb, int from_inpcbfre TAILQ_FOREACH_SAFE(sp, &outs->outqueue, next, nsp) { atomic_subtract_int(&asoc->stream_queue_cnt, 1); TAILQ_REMOVE(&outs->outqueue, sp, next); - stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, outs, sp, 1); + stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, outs, sp); sctp_free_spbufspace(stcb, asoc, sp); if (sp->data) { if (so) { diff --git a/sys/netinet/sctp_ss_functions.c b/sys/netinet/sctp_ss_functions.c index 0a5a788428bc..9d877568bcf1 100644 --- a/sys/netinet/sctp_ss_functions.c +++ b/sys/netinet/sctp_ss_functions.c @@ -41,22 +41,19 @@ __FBSDID("$FreeBSD$"); static void sctp_ss_default_add(struct sctp_tcb *, struct sctp_association *, struct sctp_stream_out *, - struct sctp_stream_queue_pending *, int); + struct sctp_stream_queue_pending *); static void sctp_ss_default_remove(struct sctp_tcb *, struct sctp_association *, struct sctp_stream_out *, - struct sctp_stream_queue_pending *, int); + struct sctp_stream_queue_pending *); static void -sctp_ss_default_init(struct sctp_tcb *stcb, struct sctp_association *asoc, - int holds_lock) +sctp_ss_default_init(struct sctp_tcb *stcb, struct sctp_association *asoc) { uint16_t i; - if (holds_lock == 0) { - SCTP_TCB_SEND_LOCK(stcb); - } + SCTP_TCB_SEND_LOCK_ASSERT(stcb); asoc->ss_data.locked_on_sending = NULL; asoc->ss_data.last_out_stream = NULL; TAILQ_INIT(&asoc->ss_data.out.wheel); @@ -68,21 +65,17 @@ sctp_ss_default_init(struct sctp_tcb *stcb, struct sctp_association *asoc, for (i = 0; i < stcb->asoc.streamoutcnt; i++) { stcb->asoc.ss_functions.sctp_ss_add_to_stream(stcb, &stcb->asoc, &stcb->asoc.strmout[i], - NULL, 1); - } - if (holds_lock == 0) { - SCTP_TCB_SEND_UNLOCK(stcb); + NULL); } return; } static void sctp_ss_default_clear(struct sctp_tcb *stcb, struct sctp_association *asoc, - int clear_values SCTP_UNUSED, int holds_lock) + int clear_values SCTP_UNUSED) { - if (holds_lock == 0) { - SCTP_TCB_SEND_LOCK(stcb); - } + SCTP_TCB_SEND_LOCK_ASSERT(stcb); + while (!TAILQ_EMPTY(&asoc->ss_data.out.wheel)) { struct sctp_stream_out *strq; @@ -92,9 +85,6 @@ sctp_ss_default_clear(struct sctp_tcb *stcb, struct sctp_association *asoc, strq->ss_params.rr.next_spoke.tqe_prev = NULL; } asoc->ss_data.last_out_stream = NULL; - if (holds_lock == 0) { - SCTP_TCB_SEND_UNLOCK(stcb); - } return; } @@ -117,11 +107,10 @@ sctp_ss_default_init_stream(struct sctp_tcb *stcb, struct sctp_stream_out *strq, static void sctp_ss_default_add(struct sctp_tcb *stcb, struct sctp_association *asoc, struct sctp_stream_out *strq, - struct sctp_stream_queue_pending *sp SCTP_UNUSED, int holds_lock) + struct sctp_stream_queue_pending *sp SCTP_UNUSED) { - if (holds_lock == 0) { - SCTP_TCB_SEND_LOCK(stcb); - } + SCTP_TCB_SEND_LOCK_ASSERT(stcb); + /* Add to wheel if not already on it and stream queue not empty */ if (!TAILQ_EMPTY(&strq->outqueue) && (strq->ss_params.rr.next_spoke.tqe_next == NULL) && @@ -129,9 +118,6 @@ sctp_ss_default_add(struct sctp_tcb *stcb, struct sctp_association *asoc, TAILQ_INSERT_TAIL(&asoc->ss_data.out.wheel, strq, ss_params.rr.next_spoke); } - if (holds_lock == 0) { - SCTP_TCB_SEND_UNLOCK(stcb); - } return; } @@ -148,11 +134,10 @@ sctp_ss_default_is_empty(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_associat static void sctp_ss_default_remove(struct sctp_tcb *stcb, struct sctp_association *asoc, struct sctp_stream_out *strq, - struct sctp_stream_queue_pending *sp SCTP_UNUSED, int holds_lock) + struct sctp_stream_queue_pending *sp SCTP_UNUSED) { - if (holds_lock == 0) { - SCTP_TCB_SEND_LOCK(stcb); - } + SCTP_TCB_SEND_LOCK_ASSERT(stcb); + /* * Remove from wheel if stream queue is empty and actually is on the * wheel @@ -176,9 +161,6 @@ sctp_ss_default_remove(struct sctp_tcb *stcb, struct sctp_association *asoc, strq->ss_params.rr.next_spoke.tqe_next = NULL; strq->ss_params.rr.next_spoke.tqe_prev = NULL; } - if (holds_lock == 0) { - SCTP_TCB_SEND_UNLOCK(stcb); - } return; } @@ -302,13 +284,12 @@ sctp_ss_default_is_user_msgs_incomplete(struct sctp_tcb *stcb SCTP_UNUSED, struc static void sctp_ss_rr_add(struct sctp_tcb *stcb, struct sctp_association *asoc, struct sctp_stream_out *strq, - struct sctp_stream_queue_pending *sp SCTP_UNUSED, int holds_lock) + struct sctp_stream_queue_pending *sp SCTP_UNUSED) { struct sctp_stream_out *strqt; - if (holds_lock == 0) { - SCTP_TCB_SEND_LOCK(stcb); - } + SCTP_TCB_SEND_LOCK_ASSERT(stcb); + if (!TAILQ_EMPTY(&strq->outqueue) && (strq->ss_params.rr.next_spoke.tqe_next == NULL) && (strq->ss_params.rr.next_spoke.tqe_prev == NULL)) { @@ -326,9 +307,6 @@ sctp_ss_rr_add(struct sctp_tcb *stcb, struct sctp_association *asoc, } } } - if (holds_lock == 0) { - SCTP_TCB_SEND_UNLOCK(stcb); - } return; } @@ -394,11 +372,10 @@ rrp_again: */ static void sctp_ss_prio_clear(struct sctp_tcb *stcb, struct sctp_association *asoc, - int clear_values, int holds_lock) + int clear_values) { - if (holds_lock == 0) { - SCTP_TCB_SEND_LOCK(stcb); - } + SCTP_TCB_SEND_LOCK_ASSERT(stcb); + while (!TAILQ_EMPTY(&asoc->ss_data.out.wheel)) { struct sctp_stream_out *strq; @@ -411,9 +388,6 @@ sctp_ss_prio_clear(struct sctp_tcb *stcb, struct sctp_association *asoc, strq->ss_params.prio.next_spoke.tqe_prev = NULL; } asoc->ss_data.last_out_stream = NULL; - if (holds_lock == 0) { - SCTP_TCB_SEND_UNLOCK(stcb); - } return; } @@ -440,14 +414,12 @@ sctp_ss_prio_init_stream(struct sctp_tcb *stcb, struct sctp_stream_out *strq, st static void sctp_ss_prio_add(struct sctp_tcb *stcb, struct sctp_association *asoc, - struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp SCTP_UNUSED, - int holds_lock) + struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp SCTP_UNUSED) { struct sctp_stream_out *strqt; - if (holds_lock == 0) { - SCTP_TCB_SEND_LOCK(stcb); - } + SCTP_TCB_SEND_LOCK_ASSERT(stcb); + /* Add to wheel if not already on it and stream queue not empty */ if (!TAILQ_EMPTY(&strq->outqueue) && (strq->ss_params.prio.next_spoke.tqe_next == NULL) && @@ -466,20 +438,15 @@ sctp_ss_prio_add(struct sctp_tcb *stcb, struct sctp_association *asoc, } } } - if (holds_lock == 0) { - SCTP_TCB_SEND_UNLOCK(stcb); - } return; } static void sctp_ss_prio_remove(struct sctp_tcb *stcb, struct sctp_association *asoc, - struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp SCTP_UNUSED, - int holds_lock) + struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp SCTP_UNUSED) { - if (holds_lock == 0) { - SCTP_TCB_SEND_LOCK(stcb); - } + SCTP_TCB_SEND_LOCK_ASSERT(stcb); + /* * Remove from wheel if stream queue is empty and actually is on the * wheel @@ -502,9 +469,6 @@ sctp_ss_prio_remove(struct sctp_tcb *stcb, struct sctp_association *asoc, strq->ss_params.prio.next_spoke.tqe_next = NULL; strq->ss_params.prio.next_spoke.tqe_prev = NULL; } - if (holds_lock == 0) { - SCTP_TCB_SEND_UNLOCK(stcb); - } return; } @@ -576,8 +540,8 @@ sctp_ss_prio_set_value(struct sctp_tcb *stcb, struct sctp_association *asoc, return (-1); } strq->ss_params.prio.priority = value; - sctp_ss_prio_remove(stcb, asoc, strq, NULL, 1); - sctp_ss_prio_add(stcb, asoc, strq, NULL, 1); + sctp_ss_prio_remove(stcb, asoc, strq, NULL); + sctp_ss_prio_add(stcb, asoc, strq, NULL); return (1); } @@ -587,11 +551,10 @@ sctp_ss_prio_set_value(struct sctp_tcb *stcb, struct sctp_association *asoc, */ static void sctp_ss_fb_clear(struct sctp_tcb *stcb, struct sctp_association *asoc, - int clear_values, int holds_lock) + int clear_values) { - if (holds_lock == 0) { - SCTP_TCB_SEND_LOCK(stcb); - } + SCTP_TCB_SEND_LOCK_ASSERT(stcb); + while (!TAILQ_EMPTY(&asoc->ss_data.out.wheel)) { struct sctp_stream_out *strq; @@ -604,9 +567,6 @@ sctp_ss_fb_clear(struct sctp_tcb *stcb, struct sctp_association *asoc, strq->ss_params.fb.next_spoke.tqe_prev = NULL; } asoc->ss_data.last_out_stream = NULL; - if (holds_lock == 0) { - SCTP_TCB_SEND_UNLOCK(stcb); - } return; } @@ -633,12 +593,10 @@ sctp_ss_fb_init_stream(struct sctp_tcb *stcb, struct sctp_stream_out *strq, stru static void sctp_ss_fb_add(struct sctp_tcb *stcb, struct sctp_association *asoc, - struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp SCTP_UNUSED, - int holds_lock) + struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp SCTP_UNUSED) { - if (holds_lock == 0) { - SCTP_TCB_SEND_LOCK(stcb); - } + SCTP_TCB_SEND_LOCK_ASSERT(stcb); + if (!TAILQ_EMPTY(&strq->outqueue) && (strq->ss_params.fb.next_spoke.tqe_next == NULL) && (strq->ss_params.fb.next_spoke.tqe_prev == NULL)) { @@ -646,20 +604,15 @@ sctp_ss_fb_add(struct sctp_tcb *stcb, struct sctp_association *asoc, strq->ss_params.fb.rounds = TAILQ_FIRST(&strq->outqueue)->length; TAILQ_INSERT_TAIL(&asoc->ss_data.out.wheel, strq, ss_params.fb.next_spoke); } - if (holds_lock == 0) { - SCTP_TCB_SEND_UNLOCK(stcb); - } return; } static void sctp_ss_fb_remove(struct sctp_tcb *stcb, struct sctp_association *asoc, - struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp SCTP_UNUSED, - int holds_lock) + struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp SCTP_UNUSED) { - if (holds_lock == 0) { - SCTP_TCB_SEND_LOCK(stcb); - } + SCTP_TCB_SEND_LOCK_ASSERT(stcb); + /* * Remove from wheel if stream queue is empty and actually is on the * wheel @@ -682,9 +635,6 @@ sctp_ss_fb_remove(struct sctp_tcb *stcb, struct sctp_association *asoc, strq->ss_params.fb.next_spoke.tqe_next = NULL; strq->ss_params.fb.next_spoke.tqe_prev = NULL; } - if (holds_lock == 0) { - SCTP_TCB_SEND_UNLOCK(stcb); - } return; } @@ -765,19 +715,17 @@ sctp_ss_fb_scheduled(struct sctp_tcb *stcb, struct sctp_nets *net SCTP_UNUSED, static void sctp_ss_fcfs_add(struct sctp_tcb *stcb, struct sctp_association *asoc, struct sctp_stream_out *strq SCTP_UNUSED, - struct sctp_stream_queue_pending *sp, int holds_lock); + struct sctp_stream_queue_pending *sp); static void -sctp_ss_fcfs_init(struct sctp_tcb *stcb, struct sctp_association *asoc, - int holds_lock) +sctp_ss_fcfs_init(struct sctp_tcb *stcb, struct sctp_association *asoc) { uint32_t x, n = 0, add_more = 1; struct sctp_stream_queue_pending *sp; uint16_t i; - if (holds_lock == 0) { - SCTP_TCB_SEND_LOCK(stcb); - } + SCTP_TCB_SEND_LOCK_ASSERT(stcb); + TAILQ_INIT(&asoc->ss_data.out.list); /* * If there is data in the stream queues already, the scheduler of @@ -795,27 +743,23 @@ sctp_ss_fcfs_init(struct sctp_tcb *stcb, struct sctp_association *asoc, x++; } if (sp != NULL) { - sctp_ss_fcfs_add(stcb, &stcb->asoc, &stcb->asoc.strmout[i], sp, 1); + sctp_ss_fcfs_add(stcb, &stcb->asoc, &stcb->asoc.strmout[i], sp); add_more = 1; } } n++; } - if (holds_lock == 0) { - SCTP_TCB_SEND_UNLOCK(stcb); - } return; } static void sctp_ss_fcfs_clear(struct sctp_tcb *stcb, struct sctp_association *asoc, - int clear_values SCTP_UNUSED, int holds_lock) + int clear_values SCTP_UNUSED) { struct sctp_stream_queue_pending *sp; - if (holds_lock == 0) { - SCTP_TCB_SEND_LOCK(stcb); - } + SCTP_TCB_SEND_LOCK_ASSERT(stcb); + while (!TAILQ_EMPTY(&asoc->ss_data.out.list)) { sp = TAILQ_FIRST(&asoc->ss_data.out.list); TAILQ_REMOVE(&asoc->ss_data.out.list, sp, ss_next); @@ -823,9 +767,6 @@ sctp_ss_fcfs_clear(struct sctp_tcb *stcb, struct sctp_association *asoc, sp->ss_next.tqe_prev = NULL; } asoc->ss_data.last_out_stream = NULL; - if (holds_lock == 0) { - SCTP_TCB_SEND_UNLOCK(stcb); - } return; } @@ -847,19 +788,14 @@ sctp_ss_fcfs_init_stream(struct sctp_tcb *stcb, struct sctp_stream_out *strq, st static void sctp_ss_fcfs_add(struct sctp_tcb *stcb, struct sctp_association *asoc, - struct sctp_stream_out *strq SCTP_UNUSED, struct sctp_stream_queue_pending *sp, - int holds_lock) + struct sctp_stream_out *strq SCTP_UNUSED, struct sctp_stream_queue_pending *sp) { - if (holds_lock == 0) { - SCTP_TCB_SEND_LOCK(stcb); - } + SCTP_TCB_SEND_LOCK_ASSERT(stcb); + if (sp && (sp->ss_next.tqe_next == NULL) && (sp->ss_next.tqe_prev == NULL)) { TAILQ_INSERT_TAIL(&asoc->ss_data.out.list, sp, ss_next); } - if (holds_lock == 0) { - SCTP_TCB_SEND_UNLOCK(stcb); - } return; } @@ -875,12 +811,10 @@ sctp_ss_fcfs_is_empty(struct sctp_tcb *stcb SCTP_UNUSED, struct sctp_association static void sctp_ss_fcfs_remove(struct sctp_tcb *stcb, struct sctp_association *asoc, - struct sctp_stream_out *strq SCTP_UNUSED, struct sctp_stream_queue_pending *sp, - int holds_lock) + struct sctp_stream_out *strq SCTP_UNUSED, struct sctp_stream_queue_pending *sp) { - if (holds_lock == 0) { - SCTP_TCB_SEND_LOCK(stcb); - } + SCTP_TCB_SEND_LOCK_ASSERT(stcb); + if (sp && ((sp->ss_next.tqe_next != NULL) || (sp->ss_next.tqe_prev != NULL))) { @@ -888,9 +822,6 @@ sctp_ss_fcfs_remove(struct sctp_tcb *stcb, struct sctp_association *asoc, sp->ss_next.tqe_next = NULL; sp->ss_next.tqe_prev = NULL; } - if (holds_lock == 0) { - SCTP_TCB_SEND_UNLOCK(stcb); - } return; } diff --git a/sys/netinet/sctp_structs.h b/sys/netinet/sctp_structs.h index a22dac047971..2f0ae4c45b24 100644 --- a/sys/netinet/sctp_structs.h +++ b/sys/netinet/sctp_structs.h @@ -729,16 +729,15 @@ struct sctp_cc_functions { * for stream scheduling. */ struct sctp_ss_functions { - void (*sctp_ss_init) (struct sctp_tcb *stcb, struct sctp_association *asoc, - int holds_lock); + void (*sctp_ss_init) (struct sctp_tcb *stcb, struct sctp_association *asoc); void (*sctp_ss_clear) (struct sctp_tcb *stcb, struct sctp_association *asoc, - int clear_values, int holds_lock); + int clear_values); void (*sctp_ss_init_stream) (struct sctp_tcb *stcb, struct sctp_stream_out *strq, struct sctp_stream_out *with_strq); void (*sctp_ss_add_to_stream) (struct sctp_tcb *stcb, struct sctp_association *asoc, - struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp, int holds_lock); + struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp); int (*sctp_ss_is_empty) (struct sctp_tcb *stcb, struct sctp_association *asoc); void (*sctp_ss_remove_from_stream) (struct sctp_tcb *stcb, struct sctp_association *asoc, - struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp, int holds_lock); + struct sctp_stream_out *strq, struct sctp_stream_queue_pending *sp); struct sctp_stream_out *(*sctp_ss_select_stream) (struct sctp_tcb *stcb, struct sctp_nets *net, struct sctp_association *asoc); void (*sctp_ss_scheduled) (struct sctp_tcb *stcb, struct sctp_nets *net, diff --git a/sys/netinet/sctp_timer.c b/sys/netinet/sctp_timer.c index 72a0a2c32c88..c994b90b8353 100644 --- a/sys/netinet/sctp_timer.c +++ b/sys/netinet/sctp_timer.c @@ -1364,7 +1364,7 @@ sctp_audit_stream_queues_for_size(struct sctp_inpcb *inp, struct sctp_tcb *stcb) } if (stcb->asoc.ss_functions.sctp_ss_is_empty(stcb, &stcb->asoc)) { /* No stream scheduler information, initialize scheduler */ - stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1); + stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc); if (!stcb->asoc.ss_functions.sctp_ss_is_empty(stcb, &stcb->asoc)) { /* yep, we lost a stream or two */ SCTP_PRINTF("Found additional streams NOT managed by scheduler, corrected\n"); diff --git a/sys/netinet/sctp_usrreq.c b/sys/netinet/sctp_usrreq.c index 690cdf3a3978..65037f0734ea 100644 --- a/sys/netinet/sctp_usrreq.c +++ b/sys/netinet/sctp_usrreq.c @@ -4043,10 +4043,10 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, SCTP_FIND_STCB(inp, stcb, av->assoc_id); if (stcb) { SCTP_TCB_SEND_LOCK(stcb); - stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1); + stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1); stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value]; stcb->asoc.stream_scheduling_module = av->assoc_value; - stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1); + stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc); SCTP_TCB_SEND_UNLOCK(stcb); SCTP_TCB_UNLOCK(stcb); } else { @@ -4066,10 +4066,10 @@ sctp_setopt(struct socket *so, int optname, void *optval, size_t optsize, LIST_FOREACH(stcb, &inp->sctp_asoc_list, sctp_tcblist) { SCTP_TCB_LOCK(stcb); SCTP_TCB_SEND_LOCK(stcb); - stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1, 1); + stcb->asoc.ss_functions.sctp_ss_clear(stcb, &stcb->asoc, 1); stcb->asoc.ss_functions = sctp_ss_functions[av->assoc_value]; stcb->asoc.stream_scheduling_module = av->assoc_value; - stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc, 1); + stcb->asoc.ss_functions.sctp_ss_init(stcb, &stcb->asoc); SCTP_TCB_SEND_UNLOCK(stcb); SCTP_TCB_UNLOCK(stcb); } diff --git a/sys/netinet/sctputil.c b/sys/netinet/sctputil.c index a7eb50716cc9..cff22394dda3 100644 --- a/sys/netinet/sctputil.c +++ b/sys/netinet/sctputil.c @@ -1316,7 +1316,7 @@ sctp_init_asoc(struct sctp_inpcb *inp, struct sctp_tcb *stcb, asoc->strmout[i].last_msg_incomplete = 0; asoc->strmout[i].state = SCTP_STREAM_OPENING; } - asoc->ss_functions.sctp_ss_init(stcb, asoc, 1); + asoc->ss_functions.sctp_ss_init(stcb, asoc); SCTP_TCB_SEND_UNLOCK(stcb); /* Now the mapping array */ @@ -4325,7 +4325,7 @@ sctp_report_all_outbound(struct sctp_tcb *stcb, uint16_t error, int so_locked) TAILQ_FOREACH_SAFE(sp, &outs->outqueue, next, nsp) { atomic_subtract_int(&asoc->stream_queue_cnt, 1); TAILQ_REMOVE(&outs->outqueue, sp, next); - stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, outs, sp, 1); + stcb->asoc.ss_functions.sctp_ss_remove_from_stream(stcb, asoc, outs, sp); sctp_free_spbufspace(stcb, asoc, sp); if (sp->data) { sctp_ulp_notify(SCTP_NOTIFY_SPECIAL_SP_FAIL, stcb,