Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Aug 2020 22:05:57 +0000 (UTC)
From:      Michael Tuexen <tuexen@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r364563 - stable/12/sys/netinet
Message-ID:  <202008232205.07NM5vw7085792@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: tuexen
Date: Sun Aug 23 22:05:57 2020
New Revision: 364563
URL: https://svnweb.freebsd.org/changeset/base/364563

Log:
  MFC r359234:
  Cleanup the file and add two ASSERT variants for locks, which will be
  used shortly.

Modified:
  stable/12/sys/netinet/sctp_lock_bsd.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/netinet/sctp_lock_bsd.h
==============================================================================
--- stable/12/sys/netinet/sctp_lock_bsd.h	Sun Aug 23 22:04:02 2020	(r364562)
+++ stable/12/sys/netinet/sctp_lock_bsd.h	Sun Aug 23 22:05:57 2020	(r364563)
@@ -64,10 +64,6 @@ __FBSDID("$FreeBSD$");
  * synchronize. So the CREATE_INP lock is also another one we must use
  * extreme caution in locking to make sure we don't hit a re-entrancy issue.
  *
- * For non FreeBSD 5.x we provide a bunch of EMPTY lock macros so we can
- * blatantly put locks everywhere and they reduce to nothing on
- * NetBSD/OpenBSD and FreeBSD 4.x
- *
  */
 
 /*
@@ -77,229 +73,275 @@ __FBSDID("$FreeBSD$");
  * the SCTP_BASE_INFO() list's we will do a SCTP_INP_INFO_WLOCK().
  */
 
-extern struct sctp_foo_stuff sctp_logoff[];
-extern int sctp_logoff_stuff;
-
 #define SCTP_IPI_COUNT_INIT()
 
 #define SCTP_STATLOG_INIT_LOCK()
+#define SCTP_STATLOG_DESTROY()
 #define SCTP_STATLOG_LOCK()
 #define SCTP_STATLOG_UNLOCK()
-#define SCTP_STATLOG_DESTROY()
 
-#define SCTP_INP_INFO_LOCK_DESTROY() do { \
-        if(rw_wowned(&SCTP_BASE_INFO(ipi_ep_mtx))) { \
-             rw_wunlock(&SCTP_BASE_INFO(ipi_ep_mtx)); \
-        } \
-        rw_destroy(&SCTP_BASE_INFO(ipi_ep_mtx)); \
-      }  while (0)
+#define SCTP_INP_INFO_LOCK_INIT() do {					\
+	rw_init(&SCTP_BASE_INFO(ipi_ep_mtx), "sctp-info");		\
+} while (0)
 
-#define SCTP_INP_INFO_LOCK_INIT() \
-        rw_init(&SCTP_BASE_INFO(ipi_ep_mtx), "sctp-info");
+#define SCTP_INP_INFO_LOCK_DESTROY() do { 				\
+	if (rw_wowned(&SCTP_BASE_INFO(ipi_ep_mtx))) {			\
+		rw_wunlock(&SCTP_BASE_INFO(ipi_ep_mtx));		\
+	}								\
+	rw_destroy(&SCTP_BASE_INFO(ipi_ep_mtx));			\
+} while (0)
 
+#define SCTP_INP_INFO_RLOCK() do { 					\
+	rw_rlock(&SCTP_BASE_INFO(ipi_ep_mtx));				\
+} while (0)
 
-#define SCTP_INP_INFO_RLOCK()	do { 					\
-             rw_rlock(&SCTP_BASE_INFO(ipi_ep_mtx));                         \
+#define SCTP_INP_INFO_WLOCK() do { 					\
+	rw_wlock(&SCTP_BASE_INFO(ipi_ep_mtx));				\
 } while (0)
 
-#define SCTP_MCORE_QLOCK_INIT(cpstr) do { \
-		mtx_init(&(cpstr)->que_mtx,	      \
-			 "sctp-mcore_queue","queue_lock",	\
-			 MTX_DEF|MTX_DUPOK);		\
+#define SCTP_INP_INFO_RUNLOCK() do {					\
+	rw_runlock(&SCTP_BASE_INFO(ipi_ep_mtx));			\
 } while (0)
 
-#define SCTP_MCORE_QLOCK(cpstr)  do { \
-		mtx_lock(&(cpstr)->que_mtx);	\
+#define SCTP_INP_INFO_WUNLOCK() do {					\
+	rw_wunlock(&SCTP_BASE_INFO(ipi_ep_mtx));			\
 } while (0)
 
-#define SCTP_MCORE_QUNLOCK(cpstr)  do { \
-		mtx_unlock(&(cpstr)->que_mtx);	\
+
+#define SCTP_MCORE_QLOCK_INIT(cpstr) do {				\
+	mtx_init(&(cpstr)->que_mtx, "sctp-mcore_queue","queue_lock",	\
+	         MTX_DEF | MTX_DUPOK);					\
 } while (0)
 
-#define SCTP_MCORE_QDESTROY(cpstr)  do { \
-	if(mtx_owned(&(cpstr)->core_mtx)) {	\
-		mtx_unlock(&(cpstr)->que_mtx);	\
-        } \
-	mtx_destroy(&(cpstr)->que_mtx);	\
+#define SCTP_MCORE_QDESTROY(cpstr) do {					\
+	if (mtx_owned(&(cpstr)->core_mtx)) {				\
+		mtx_unlock(&(cpstr)->que_mtx);				\
+	}								\
+	mtx_destroy(&(cpstr)->que_mtx);					\
 } while (0)
 
+#define SCTP_MCORE_QLOCK(cpstr) do {					\
+	mtx_lock(&(cpstr)->que_mtx);					\
+} while (0)
 
-#define SCTP_MCORE_LOCK_INIT(cpstr) do { \
-		mtx_init(&(cpstr)->core_mtx,	      \
-			 "sctp-cpulck","cpu_proc_lock",	\
-			 MTX_DEF|MTX_DUPOK);		\
+#define SCTP_MCORE_QUNLOCK(cpstr) do {					\
+	mtx_unlock(&(cpstr)->que_mtx);					\
 } while (0)
 
-#define SCTP_MCORE_LOCK(cpstr)  do { \
-		mtx_lock(&(cpstr)->core_mtx);	\
+
+#define SCTP_MCORE_LOCK_INIT(cpstr) do {				\
+	mtx_init(&(cpstr)->core_mtx, "sctp-cpulck","cpu_proc_lock",	\
+	         MTX_DEF | MTX_DUPOK);					\
 } while (0)
 
-#define SCTP_MCORE_UNLOCK(cpstr)  do { \
-		mtx_unlock(&(cpstr)->core_mtx);	\
+#define SCTP_MCORE_DESTROY(cpstr) do {					\
+	if (mtx_owned(&(cpstr)->core_mtx)) {				\
+		mtx_unlock(&(cpstr)->core_mtx);				\
+	}								\
+	mtx_destroy(&(cpstr)->core_mtx);				\
 } while (0)
 
-#define SCTP_MCORE_DESTROY(cpstr)  do { \
-	if(mtx_owned(&(cpstr)->core_mtx)) {	\
-		mtx_unlock(&(cpstr)->core_mtx);	\
-        } \
-	mtx_destroy(&(cpstr)->core_mtx);	\
+#define SCTP_MCORE_LOCK(cpstr) do {					\
+	mtx_lock(&(cpstr)->core_mtx);					\
 } while (0)
 
-#define SCTP_INP_INFO_WLOCK()	do { 					\
-            rw_wlock(&SCTP_BASE_INFO(ipi_ep_mtx));                         \
+#define SCTP_MCORE_UNLOCK(cpstr) do {					\
+	mtx_unlock(&(cpstr)->core_mtx);					\
 } while (0)
 
 
-#define SCTP_INP_INFO_RUNLOCK()		rw_runlock(&SCTP_BASE_INFO(ipi_ep_mtx))
-#define SCTP_INP_INFO_WUNLOCK()		rw_wunlock(&SCTP_BASE_INFO(ipi_ep_mtx))
+#define SCTP_IPI_ADDR_INIT() do {					\
+	rw_init(&SCTP_BASE_INFO(ipi_addr_mtx), "sctp-addr");		\
+} while (0)
 
+#define SCTP_IPI_ADDR_DESTROY() do {					\
+	if (rw_wowned(&SCTP_BASE_INFO(ipi_addr_mtx))) {			\
+		rw_wunlock(&SCTP_BASE_INFO(ipi_addr_mtx));		\
+	}								\
+	rw_destroy(&SCTP_BASE_INFO(ipi_addr_mtx));			\
+}  while (0)
 
-#define SCTP_IPI_ADDR_INIT()								\
-        rw_init(&SCTP_BASE_INFO(ipi_addr_mtx), "sctp-addr")
-#define SCTP_IPI_ADDR_DESTROY() do  { \
-        if(rw_wowned(&SCTP_BASE_INFO(ipi_addr_mtx))) { \
-             rw_wunlock(&SCTP_BASE_INFO(ipi_addr_mtx)); \
-        } \
-	rw_destroy(&SCTP_BASE_INFO(ipi_addr_mtx)); \
-      }  while (0)
 #define SCTP_IPI_ADDR_RLOCK()	do { 					\
-             rw_rlock(&SCTP_BASE_INFO(ipi_addr_mtx));                         \
+	rw_rlock(&SCTP_BASE_INFO(ipi_addr_mtx));			\
 } while (0)
+
 #define SCTP_IPI_ADDR_WLOCK()	do { 					\
-             rw_wlock(&SCTP_BASE_INFO(ipi_addr_mtx));                         \
+	rw_wlock(&SCTP_BASE_INFO(ipi_addr_mtx));			\
 } while (0)
 
-#define SCTP_IPI_ADDR_RUNLOCK()		rw_runlock(&SCTP_BASE_INFO(ipi_addr_mtx))
-#define SCTP_IPI_ADDR_WUNLOCK()		rw_wunlock(&SCTP_BASE_INFO(ipi_addr_mtx))
+#define SCTP_IPI_ADDR_RUNLOCK() do {					\
+	rw_runlock(&SCTP_BASE_INFO(ipi_addr_mtx));			\
+} while (0)
 
+#define SCTP_IPI_ADDR_WUNLOCK() do {					\
+	rw_wunlock(&SCTP_BASE_INFO(ipi_addr_mtx));			\
+} while (0)
 
-#define SCTP_IPI_ITERATOR_WQ_INIT() \
-        mtx_init(&sctp_it_ctl.ipi_iterator_wq_mtx, "sctp-it-wq", "sctp_it_wq", MTX_DEF)
 
-#define SCTP_IPI_ITERATOR_WQ_DESTROY() \
-	mtx_destroy(&sctp_it_ctl.ipi_iterator_wq_mtx)
+#define SCTP_IPI_ITERATOR_WQ_INIT() do {				\
+	mtx_init(&sctp_it_ctl.ipi_iterator_wq_mtx, "sctp-it-wq",	\
+	         "sctp_it_wq", MTX_DEF);				\
+} while (0)
 
-#define SCTP_IPI_ITERATOR_WQ_LOCK()	do { 					\
-             mtx_lock(&sctp_it_ctl.ipi_iterator_wq_mtx);                \
+#define SCTP_IPI_ITERATOR_WQ_DESTROY() do {				\
+	mtx_destroy(&sctp_it_ctl.ipi_iterator_wq_mtx);			\
 } while (0)
 
-#define SCTP_IPI_ITERATOR_WQ_UNLOCK()		mtx_unlock(&sctp_it_ctl.ipi_iterator_wq_mtx)
+#define SCTP_IPI_ITERATOR_WQ_LOCK() do { 				\
+	mtx_lock(&sctp_it_ctl.ipi_iterator_wq_mtx);			\
+} while (0)
 
+#define SCTP_IPI_ITERATOR_WQ_UNLOCK() do {				\
+	mtx_unlock(&sctp_it_ctl.ipi_iterator_wq_mtx);			\
+} while (0)
 
-#define SCTP_IP_PKTLOG_INIT() \
-        mtx_init(&SCTP_BASE_INFO(ipi_pktlog_mtx), "sctp-pktlog", "packetlog", MTX_DEF)
 
+#define SCTP_IP_PKTLOG_INIT() do {					\
+	mtx_init(&SCTP_BASE_INFO(ipi_pktlog_mtx), "sctp-pktlog",	\
+	         "packetlog", MTX_DEF);					\
+} while (0)
 
-#define SCTP_IP_PKTLOG_LOCK()	do { 			\
-             mtx_lock(&SCTP_BASE_INFO(ipi_pktlog_mtx));     \
+#define SCTP_IP_PKTLOG_DESTROY() do {					\
+	mtx_destroy(&SCTP_BASE_INFO(ipi_pktlog_mtx));			\
 } while (0)
 
-#define SCTP_IP_PKTLOG_UNLOCK()	mtx_unlock(&SCTP_BASE_INFO(ipi_pktlog_mtx))
+#define SCTP_IP_PKTLOG_LOCK()	do { 					\
+	mtx_lock(&SCTP_BASE_INFO(ipi_pktlog_mtx));			\
+} while (0)
 
-#define SCTP_IP_PKTLOG_DESTROY() \
-	mtx_destroy(&SCTP_BASE_INFO(ipi_pktlog_mtx))
+#define SCTP_IP_PKTLOG_UNLOCK() do {					\
+	mtx_unlock(&SCTP_BASE_INFO(ipi_pktlog_mtx));			\
+} while (0)
 
 
-
-
-
 /*
  * The INP locks we will use for locking an SCTP endpoint, so for example if
  * we want to change something at the endpoint level for example random_store
  * or cookie secrets we lock the INP level.
  */
 
-#define SCTP_INP_READ_INIT(_inp) \
-	mtx_init(&(_inp)->inp_rdata_mtx, "sctp-read", "inpr", MTX_DEF | MTX_DUPOK)
+#define SCTP_INP_READ_INIT(_inp) do {					\
+	mtx_init(&(_inp)->inp_rdata_mtx, "sctp-read", "inpr",		\
+	         MTX_DEF | MTX_DUPOK);					\
+} while (0)
 
-#define SCTP_INP_READ_DESTROY(_inp) \
-	mtx_destroy(&(_inp)->inp_rdata_mtx)
+#define SCTP_INP_READ_DESTROY(_inp) do {				\
+	mtx_destroy(&(_inp)->inp_rdata_mtx);				\
+} while (0)
 
-#define SCTP_INP_READ_LOCK(_inp)	do { \
-        mtx_lock(&(_inp)->inp_rdata_mtx);    \
+#define SCTP_INP_READ_LOCK(_inp) do {					\
+	mtx_lock(&(_inp)->inp_rdata_mtx);				\
 } while (0)
 
+#define SCTP_INP_READ_UNLOCK(_inp) do {					\
+	mtx_unlock(&(_inp)->inp_rdata_mtx);				\
+} while (0)
 
-#define SCTP_INP_READ_UNLOCK(_inp) mtx_unlock(&(_inp)->inp_rdata_mtx)
 
+#define SCTP_INP_LOCK_INIT(_inp) do {					\
+	mtx_init(&(_inp)->inp_mtx, "sctp-inp", "inp",			\
+	         MTX_DEF | MTX_DUPOK);					\
+} while (0)
 
-#define SCTP_INP_LOCK_INIT(_inp) \
-	mtx_init(&(_inp)->inp_mtx, "sctp-inp", "inp", MTX_DEF | MTX_DUPOK)
-#define SCTP_ASOC_CREATE_LOCK_INIT(_inp) \
-	mtx_init(&(_inp)->inp_create_mtx, "sctp-create", "inp_create", \
-		 MTX_DEF | MTX_DUPOK)
+#define SCTP_INP_LOCK_DESTROY(_inp) do {				\
+	mtx_destroy(&(_inp)->inp_mtx);					\
+} while (0)
 
-#define SCTP_INP_LOCK_DESTROY(_inp) \
-	mtx_destroy(&(_inp)->inp_mtx)
+#define SCTP_INP_LOCK_CONTENDED(_inp)					\
+	((_inp)->inp_mtx.mtx_lock & MTX_CONTESTED)
 
-#define SCTP_INP_LOCK_CONTENDED(_inp) ((_inp)->inp_mtx.mtx_lock & MTX_CONTESTED)
+#define SCTP_INP_READ_CONTENDED(_inp)					\
+	((_inp)->inp_rdata_mtx.mtx_lock & MTX_CONTESTED)
 
-#define SCTP_INP_READ_CONTENDED(_inp) ((_inp)->inp_rdata_mtx.mtx_lock & MTX_CONTESTED)
-
-#define SCTP_ASOC_CREATE_LOCK_CONTENDED(_inp) ((_inp)->inp_create_mtx.mtx_lock & MTX_CONTESTED)
-
-
-#define SCTP_ASOC_CREATE_LOCK_DESTROY(_inp) \
-	mtx_destroy(&(_inp)->inp_create_mtx)
-
-
 #ifdef SCTP_LOCK_LOGGING
 #define SCTP_INP_RLOCK(_inp)	do { 					\
-	if(SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) sctp_log_lock(_inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_INP);\
-        mtx_lock(&(_inp)->inp_mtx);                                     \
+	if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) \
+		sctp_log_lock(_inp, NULL, SCTP_LOG_LOCK_INP);		\
+	mtx_lock(&(_inp)->inp_mtx);					\
 } while (0)
 
 #define SCTP_INP_WLOCK(_inp)	do { 					\
-	if(SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) sctp_log_lock(_inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_INP);\
-        mtx_lock(&(_inp)->inp_mtx);                                     \
+	if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) \
+		sctp_log_lock(_inp, NULL, SCTP_LOG_LOCK_INP);		\
+	mtx_lock(&(_inp)->inp_mtx);					\
 } while (0)
-
 #else
-
-#define SCTP_INP_RLOCK(_inp)	do { 					\
-        mtx_lock(&(_inp)->inp_mtx);                                     \
+#define SCTP_INP_RLOCK(_inp) do { 					\
+	mtx_lock(&(_inp)->inp_mtx);					\
 } while (0)
 
-#define SCTP_INP_WLOCK(_inp)	do { 					\
-        mtx_lock(&(_inp)->inp_mtx);                                     \
+#define SCTP_INP_WLOCK(_inp) do { 					\
+	mtx_lock(&(_inp)->inp_mtx);					\
 } while (0)
-
 #endif
 
+#define SCTP_INP_RUNLOCK(_inp) do {					\
+	mtx_unlock(&(_inp)->inp_mtx);					\
+} while (0)
 
-#define SCTP_TCB_SEND_LOCK_INIT(_tcb) \
-	mtx_init(&(_tcb)->tcb_send_mtx, "sctp-send-tcb", "tcbs", MTX_DEF | MTX_DUPOK)
+#define SCTP_INP_WUNLOCK(_inp) do {					\
+	mtx_unlock(&(_inp)->inp_mtx);					\
+} while (0)
 
-#define SCTP_TCB_SEND_LOCK_DESTROY(_tcb) mtx_destroy(&(_tcb)->tcb_send_mtx)
+#define SCTP_INP_RLOCK_ASSERT(_inp) do {				\
+	KASSERT(mtx_owned(&(_inp)->inp_mtx),				\
+	        ("Don't own INP read lock"));				\
+} while (0)
 
-#define SCTP_TCB_SEND_LOCK(_tcb)  do { \
-	mtx_lock(&(_tcb)->tcb_send_mtx); \
+#define SCTP_INP_WLOCK_ASSERT(_inp) do {				\
+	KASSERT(mtx_owned(&(_inp)->inp_mtx),				\
+	        ("Don't own INP write lock"));				\
 } while (0)
 
-#define SCTP_TCB_SEND_UNLOCK(_tcb) mtx_unlock(&(_tcb)->tcb_send_mtx)
-
 #define SCTP_INP_INCR_REF(_inp) atomic_add_int(&((_inp)->refcount), 1)
 #define SCTP_INP_DECR_REF(_inp) atomic_add_int(&((_inp)->refcount), -1)
 
+#define SCTP_ASOC_CREATE_LOCK_INIT(_inp) do {				\
+	mtx_init(&(_inp)->inp_create_mtx, "sctp-create", "inp_create",	\
+		 MTX_DEF | MTX_DUPOK);					\
+} while (0)
 
+#define SCTP_ASOC_CREATE_LOCK_DESTROY(_inp) do {			\
+	mtx_destroy(&(_inp)->inp_create_mtx);				\
+} while (0)
+
 #ifdef SCTP_LOCK_LOGGING
-#define SCTP_ASOC_CREATE_LOCK(_inp) \
-	do {								\
-	if(SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) sctp_log_lock(_inp, (struct sctp_tcb *)NULL, SCTP_LOG_LOCK_CREATE); \
-		mtx_lock(&(_inp)->inp_create_mtx);			\
-	} while (0)
+#define SCTP_ASOC_CREATE_LOCK(_inp) do {				\
+	if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) \
+		sctp_log_lock(_inp, NULL, SCTP_LOG_LOCK_CREATE);	\
+	mtx_lock(&(_inp)->inp_create_mtx);				\
+} while (0)
 #else
-
-#define SCTP_ASOC_CREATE_LOCK(_inp) \
-	do {								\
-		mtx_lock(&(_inp)->inp_create_mtx);			\
-	} while (0)
+#define SCTP_ASOC_CREATE_LOCK(_inp) do {				\
+	mtx_lock(&(_inp)->inp_create_mtx);				\
+} while (0)
 #endif
 
-#define SCTP_INP_RUNLOCK(_inp)		mtx_unlock(&(_inp)->inp_mtx)
-#define SCTP_INP_WUNLOCK(_inp)		mtx_unlock(&(_inp)->inp_mtx)
-#define SCTP_ASOC_CREATE_UNLOCK(_inp)	mtx_unlock(&(_inp)->inp_create_mtx)
+#define SCTP_ASOC_CREATE_UNLOCK(_inp) do {				\
+	mtx_unlock(&(_inp)->inp_create_mtx);				\
+} while (0)
 
+#define SCTP_ASOC_CREATE_LOCK_CONTENDED(_inp)				\
+	((_inp)->inp_create_mtx.mtx_lock & MTX_CONTESTED)
+
+
+#define SCTP_TCB_SEND_LOCK_INIT(_tcb) do {				\
+	mtx_init(&(_tcb)->tcb_send_mtx, "sctp-send-tcb", "tcbs",	\
+	         MTX_DEF | MTX_DUPOK);					\
+} while (0)
+
+#define SCTP_TCB_SEND_LOCK_DESTROY(_tcb) do {				\
+	mtx_destroy(&(_tcb)->tcb_send_mtx);				\
+} while (0)
+
+#define SCTP_TCB_SEND_LOCK(_tcb) do {					\
+	mtx_lock(&(_tcb)->tcb_send_mtx);				\
+} while (0)
+
+#define SCTP_TCB_SEND_UNLOCK(_tcb) do {					\
+	mtx_unlock(&(_tcb)->tcb_send_mtx);				\
+} 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
@@ -308,168 +350,154 @@ extern int sctp_logoff_stuff;
  * extra SOCKBUF_LOCK(&so->so_rcv) even though the association is locked.
  */
 
-#define SCTP_TCB_LOCK_INIT(_tcb) \
-	mtx_init(&(_tcb)->tcb_mtx, "sctp-tcb", "tcb", MTX_DEF | MTX_DUPOK)
+#define SCTP_TCB_LOCK_INIT(_tcb) do {					\
+	mtx_init(&(_tcb)->tcb_mtx, "sctp-tcb", "tcb",			\
+	         MTX_DEF | MTX_DUPOK);					\
+} while (0)
 
-#define SCTP_TCB_LOCK_DESTROY(_tcb)	mtx_destroy(&(_tcb)->tcb_mtx)
+#define SCTP_TCB_LOCK_DESTROY(_tcb) do {				\
+	mtx_destroy(&(_tcb)->tcb_mtx);					\
+} while (0)
 
 #ifdef SCTP_LOCK_LOGGING
-#define SCTP_TCB_LOCK(_tcb)  do {					\
-	if(SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE)  sctp_log_lock(_tcb->sctp_ep, _tcb, SCTP_LOG_LOCK_TCB);          \
-	mtx_lock(&(_tcb)->tcb_mtx);                                     \
+#define SCTP_TCB_LOCK(_tcb) do {					\
+	if (SCTP_BASE_SYSCTL(sctp_logging_level) & SCTP_LOCK_LOGGING_ENABLE) \
+		sctp_log_lock(_tcb->sctp_ep, _tcb, SCTP_LOG_LOCK_TCB);	\
+	mtx_lock(&(_tcb)->tcb_mtx);					\
 } while (0)
-
 #else
-#define SCTP_TCB_LOCK(_tcb)  do {					\
-	mtx_lock(&(_tcb)->tcb_mtx);                                     \
+#define SCTP_TCB_LOCK(_tcb) do {					\
+	mtx_lock(&(_tcb)->tcb_mtx);					\
 } while (0)
 
 #endif
 
+#define SCTP_TCB_TRYLOCK(_tcb) 						\
+	mtx_trylock(&(_tcb)->tcb_mtx)
 
-#define SCTP_TCB_TRYLOCK(_tcb) 	mtx_trylock(&(_tcb)->tcb_mtx)
+#define SCTP_TCB_UNLOCK(_tcb) do {					\
+	mtx_unlock(&(_tcb)->tcb_mtx);					\
+} while (0)
 
-#define SCTP_TCB_UNLOCK(_tcb)		mtx_unlock(&(_tcb)->tcb_mtx)
+#define SCTP_TCB_UNLOCK_IFOWNED(_tcb) do {				\
+	if (mtx_owned(&(_tcb)->tcb_mtx))				\
+		mtx_unlock(&(_tcb)->tcb_mtx);				\
+} while (0)
 
-#define SCTP_TCB_UNLOCK_IFOWNED(_tcb)	      do { \
-                                                if (mtx_owned(&(_tcb)->tcb_mtx)) \
-                                                     mtx_unlock(&(_tcb)->tcb_mtx); \
-                                              } while (0)
+#define SCTP_TCB_LOCK_ASSERT(_tcb) do {					\
+	KASSERT(mtx_owned(&(_tcb)->tcb_mtx),				\
+	        ("Don't own TCB lock"));				\
+} while (0)
 
 
+#define SCTP_ITERATOR_LOCK_INIT() do {					\
+	mtx_init(&sctp_it_ctl.it_mtx, "sctp-it", "iterator", MTX_DEF);	\
+} while (0)
 
-#ifdef INVARIANTS
-#define SCTP_TCB_LOCK_ASSERT(_tcb) do { \
-                            if (mtx_owned(&(_tcb)->tcb_mtx) == 0) \
-                                panic("Don't own TCB lock"); \
-                            } while (0)
-#else
-#define SCTP_TCB_LOCK_ASSERT(_tcb)
-#endif
+#define SCTP_ITERATOR_LOCK_DESTROY() do {				\
+	mtx_destroy(&sctp_it_ctl.it_mtx);				\
+} while (0)
 
-#define SCTP_ITERATOR_LOCK_INIT() \
-        mtx_init(&sctp_it_ctl.it_mtx, "sctp-it", "iterator", MTX_DEF)
-
-#ifdef INVARIANTS
 #define SCTP_ITERATOR_LOCK() \
 	do {								\
-		if (mtx_owned(&sctp_it_ctl.it_mtx))			\
-			panic("Iterator Lock");				\
+		KASSERT(!mtx_owned(&sctp_it_ctl.it_mtx),		\
+		        ("Own the iterator lock"));			\
 		mtx_lock(&sctp_it_ctl.it_mtx);				\
 	} while (0)
-#else
-#define SCTP_ITERATOR_LOCK() \
-	do {								\
-		mtx_lock(&sctp_it_ctl.it_mtx);				\
-	} while (0)
 
-#endif
+#define SCTP_ITERATOR_UNLOCK() do {					\
+	mtx_unlock(&sctp_it_ctl.it_mtx);				\
+} while (0)
 
-#define SCTP_ITERATOR_UNLOCK()	        mtx_unlock(&sctp_it_ctl.it_mtx)
-#define SCTP_ITERATOR_LOCK_DESTROY()	mtx_destroy(&sctp_it_ctl.it_mtx)
 
+#define SCTP_WQ_ADDR_INIT() do {					\
+	mtx_init(&SCTP_BASE_INFO(wq_addr_mtx),				\
+	         "sctp-addr-wq","sctp_addr_wq", MTX_DEF);		\
+} while (0)
 
-#define SCTP_WQ_ADDR_INIT() do { \
-        mtx_init(&SCTP_BASE_INFO(wq_addr_mtx), "sctp-addr-wq","sctp_addr_wq",MTX_DEF); \
- } while (0)
+#define SCTP_WQ_ADDR_DESTROY() do  {					\
+	if (mtx_owned(&SCTP_BASE_INFO(wq_addr_mtx))) {			\
+		mtx_unlock(&SCTP_BASE_INFO(wq_addr_mtx));		\
+	}								\
+	mtx_destroy(&SCTP_BASE_INFO(wq_addr_mtx)); \
+} while (0)
 
-#define SCTP_WQ_ADDR_DESTROY() do  { \
-        if(mtx_owned(&SCTP_BASE_INFO(wq_addr_mtx))) { \
-             mtx_unlock(&SCTP_BASE_INFO(wq_addr_mtx)); \
-        } \
-	    mtx_destroy(&SCTP_BASE_INFO(wq_addr_mtx)); \
-      }  while (0)
+#define SCTP_WQ_ADDR_LOCK()	do {					\
+	mtx_lock(&SCTP_BASE_INFO(wq_addr_mtx));				\
+} while (0)
 
-#define SCTP_WQ_ADDR_LOCK()	do { \
-             mtx_lock(&SCTP_BASE_INFO(wq_addr_mtx));  \
+#define SCTP_WQ_ADDR_UNLOCK() do {					\
+		mtx_unlock(&SCTP_BASE_INFO(wq_addr_mtx));		\
 } while (0)
-#define SCTP_WQ_ADDR_UNLOCK() do { \
-		mtx_unlock(&SCTP_BASE_INFO(wq_addr_mtx)); \
+
+#define SCTP_WQ_ADDR_LOCK_ASSERT() do {					\
+	KASSERT(mtx_owned(&SCTP_BASE_INFO(wq_addr_mtx)),		\
+	        ("Don't own the ADDR-WQ lock"));			\
 } while (0)
 
+#define SCTP_INCR_EP_COUNT() do {					\
+	atomic_add_int(&SCTP_BASE_INFO(ipi_count_ep), 1);		\
+} while (0)
 
+#define SCTP_DECR_EP_COUNT() do {					\
+	atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_ep), 1);		\
+} while (0)
 
-#define SCTP_INCR_EP_COUNT() \
-                do { \
-		       atomic_add_int(&SCTP_BASE_INFO(ipi_count_ep), 1); \
-	        } while (0)
+#define SCTP_INCR_ASOC_COUNT() do {					\
+	atomic_add_int(&SCTP_BASE_INFO(ipi_count_asoc), 1);		\
+} while (0)
 
-#define SCTP_DECR_EP_COUNT() \
-                do { \
-		       atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_ep), 1); \
-	        } while (0)
+#define SCTP_DECR_ASOC_COUNT() do {					\
+	atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_asoc), 1);	\
+} while (0)
 
-#define SCTP_INCR_ASOC_COUNT() \
-                do { \
-	               atomic_add_int(&SCTP_BASE_INFO(ipi_count_asoc), 1); \
-	        } while (0)
+#define SCTP_INCR_LADDR_COUNT() do {					\
+	atomic_add_int(&SCTP_BASE_INFO(ipi_count_laddr), 1);		\
+} while (0)
 
-#define SCTP_DECR_ASOC_COUNT() \
-                do { \
-	               atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_asoc), 1); \
-	        } while (0)
+#define SCTP_DECR_LADDR_COUNT() do {					\
+	atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_laddr), 1); 	\
+} while (0)
 
-#define SCTP_INCR_LADDR_COUNT() \
-                do { \
-	               atomic_add_int(&SCTP_BASE_INFO(ipi_count_laddr), 1); \
-	        } while (0)
+#define SCTP_INCR_RADDR_COUNT() do {					\
+	atomic_add_int(&SCTP_BASE_INFO(ipi_count_raddr), 1);		\
+} while (0)
 
-#define SCTP_DECR_LADDR_COUNT() \
-                do { \
-	               atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_laddr), 1); \
-	        } while (0)
+#define SCTP_DECR_RADDR_COUNT() do {					\
+	atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_raddr),1);	\
+} while (0)
 
-#define SCTP_INCR_RADDR_COUNT() \
-                do { \
- 	               atomic_add_int(&SCTP_BASE_INFO(ipi_count_raddr), 1); \
-	        } while (0)
+#define SCTP_INCR_CHK_COUNT() do {					\
+	atomic_add_int(&SCTP_BASE_INFO(ipi_count_chunk), 1);		\
+} while (0)
 
-#define SCTP_DECR_RADDR_COUNT() \
-                do { \
- 	               atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_raddr),1); \
-	        } while (0)
+#define SCTP_DECR_CHK_COUNT() do {					\
+	KASSERT(SCTP_BASE_INFO(ipi_count_chunk) > 0,			\
+	        ("ipi_count_chunk would become negative"));		\
+	if (SCTP_BASE_INFO(ipi_count_chunk) != 0)			\
+		atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_chunk),	\
+		                    1);					\
+} while (0)
 
-#define SCTP_INCR_CHK_COUNT() \
-                do { \
-  	               atomic_add_int(&SCTP_BASE_INFO(ipi_count_chunk), 1); \
-	        } while (0)
-#ifdef INVARIANTS
-#define SCTP_DECR_CHK_COUNT() \
-                do { \
-                       if(SCTP_BASE_INFO(ipi_count_chunk) == 0) \
-                             panic("chunk count to 0?");    \
-  	               atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_chunk), 1); \
-	        } while (0)
-#else
-#define SCTP_DECR_CHK_COUNT() \
-                do { \
-                       if(SCTP_BASE_INFO(ipi_count_chunk) != 0) \
-  	               atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_chunk), 1); \
-	        } while (0)
-#endif
-#define SCTP_INCR_READQ_COUNT() \
-                do { \
-		       atomic_add_int(&SCTP_BASE_INFO(ipi_count_readq),1); \
-	        } while (0)
+#define SCTP_INCR_READQ_COUNT() do {					\
+	atomic_add_int(&SCTP_BASE_INFO(ipi_count_readq), 1);		\
+} while (0)
 
-#define SCTP_DECR_READQ_COUNT() \
-                do { \
-		       atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_readq), 1); \
-	        } while (0)
+#define SCTP_DECR_READQ_COUNT() do {					\
+	atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_readq), 1);	\
+} while (0)
 
-#define SCTP_INCR_STRMOQ_COUNT() \
-                do { \
-		       atomic_add_int(&SCTP_BASE_INFO(ipi_count_strmoq), 1); \
-	        } while (0)
+#define SCTP_INCR_STRMOQ_COUNT() do {					\
+	atomic_add_int(&SCTP_BASE_INFO(ipi_count_strmoq), 1);		\
+} while (0)
 
-#define SCTP_DECR_STRMOQ_COUNT() \
-                do { \
-		       atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_strmoq), 1); \
-	        } while (0)
+#define SCTP_DECR_STRMOQ_COUNT() do {					\
+	atomic_subtract_int(&SCTP_BASE_INFO(ipi_count_strmoq), 1);	\
+} while (0)
 
-
 #if defined(SCTP_SO_LOCK_TESTING)
-#define SCTP_INP_SO(sctpinp)	(sctpinp)->ip_inp.inp.inp_socket
+#define SCTP_INP_SO(sctpinp)						\
+	(sctpinp)->ip_inp.inp.inp_socket
 #define SCTP_SOCKET_LOCK(so, refcnt)
 #define SCTP_SOCKET_UNLOCK(so, refcnt)
 #endif



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202008232205.07NM5vw7085792>