On Wed, Jul 05, 2023 at 03:41:31AM +0000, Visa Hankala wrote: > Initialize stack-based mutexed using mtx_init(). This removes the need > of the NOWITNESS kludge and lets the lock checker do its job with these > mutexes. > > At the moment, static initialization of locks inside functions does not > work correctly with WITNESS. A lock initializer sets up a struct that > gets permanently referenced by the lock checker. Inside a function, > the static initializers put these structs on the stack, which causes > trouble when the function returns. In principle, this might be solvable > by using a compile-time expression that chooses the correct way of > initialization based on the scope of usage.
OK bluhm@ > Index: dev/ic/mfi.c > =================================================================== > RCS file: src/sys/dev/ic/mfi.c,v > retrieving revision 1.189 > diff -u -p -r1.189 mfi.c > --- dev/ic/mfi.c 25 May 2023 19:35:58 -0000 1.189 > +++ dev/ic/mfi.c 5 Jul 2023 02:56:57 -0000 > @@ -925,8 +925,9 @@ mfi_poll(struct mfi_softc *sc, struct mf > void > mfi_exec(struct mfi_softc *sc, struct mfi_ccb *ccb) > { > - struct mutex m = MUTEX_INITIALIZER_FLAGS(IPL_BIO, __MTX_NAME, > - MTX_NOWITNESS); > + struct mutex m; > + > + mtx_init(&m, IPL_BIO); > > #ifdef DIAGNOSTIC > if (ccb->ccb_cookie != NULL || ccb->ccb_done != NULL) > Index: dev/ic/mpi.c > =================================================================== > RCS file: src/sys/dev/ic/mpi.c,v > retrieving revision 1.225 > diff -u -p -r1.225 mpi.c > --- dev/ic/mpi.c 25 May 2023 19:35:58 -0000 1.225 > +++ dev/ic/mpi.c 5 Jul 2023 02:56:57 -0000 > @@ -1263,10 +1263,11 @@ mpi_poll_done(struct mpi_ccb *ccb) > void > mpi_wait(struct mpi_softc *sc, struct mpi_ccb *ccb) > { > - struct mutex cookie = MUTEX_INITIALIZER_FLAGS( > - IPL_BIO, __MTX_NAME, MTX_NOWITNESS); > + struct mutex cookie; > void (*done)(struct mpi_ccb *); > > + mtx_init(&cookie, IPL_BIO); > + > done = ccb->ccb_done; > ccb->ccb_done = mpi_wait_done; > ccb->ccb_cookie = &cookie; > Index: dev/pci/mfii.c > =================================================================== > RCS file: src/sys/dev/pci/mfii.c,v > retrieving revision 1.88 > diff -u -p -r1.88 mfii.c > --- dev/pci/mfii.c 25 May 2023 19:35:58 -0000 1.88 > +++ dev/pci/mfii.c 5 Jul 2023 02:56:57 -0000 > @@ -1764,8 +1764,9 @@ mfii_poll_done(struct mfii_softc *sc, st > int > mfii_exec(struct mfii_softc *sc, struct mfii_ccb *ccb) > { > - struct mutex m = MUTEX_INITIALIZER_FLAGS(IPL_BIO, __MTX_NAME, > - MTX_NOWITNESS); > + struct mutex m; > + > + mtx_init(&m, IPL_BIO); > > #ifdef DIAGNOSTIC > if (ccb->ccb_cookie != NULL || ccb->ccb_done != NULL) > Index: dev/pci/mpii.c > =================================================================== > RCS file: src/sys/dev/pci/mpii.c,v > retrieving revision 1.145 > diff -u -p -r1.145 mpii.c > --- dev/pci/mpii.c 25 May 2023 19:35:58 -0000 1.145 > +++ dev/pci/mpii.c 5 Jul 2023 02:56:57 -0000 > @@ -2857,11 +2857,12 @@ mpii_init_queues(struct mpii_softc *sc) > void > mpii_wait(struct mpii_softc *sc, struct mpii_ccb *ccb) > { > - struct mutex mtx = MUTEX_INITIALIZER_FLAGS(IPL_BIO, > - __MTX_NAME, MTX_NOWITNESS); > + struct mutex mtx; > void (*done)(struct mpii_ccb *); > void *cookie; > > + mtx_init(&mtx, IPL_BIO); > + > done = ccb->ccb_done; > cookie = ccb->ccb_cookie; > > Index: scsi/scsi_base.c > =================================================================== > RCS file: src/sys/scsi/scsi_base.c,v > retrieving revision 1.281 > diff -u -p -r1.281 scsi_base.c > --- scsi/scsi_base.c 25 May 2023 19:35:58 -0000 1.281 > +++ scsi/scsi_base.c 5 Jul 2023 02:56:57 -0000 > @@ -1497,10 +1497,11 @@ scsi_done(struct scsi_xfer *xs) > int > scsi_xs_sync(struct scsi_xfer *xs) > { > - struct mutex cookie = MUTEX_INITIALIZER_FLAGS(IPL_BIO, __MTX_NAME, > - MTX_NOWITNESS); > + struct mutex cookie; > int error; > > + mtx_init(&cookie, IPL_BIO); > + > #ifdef DIAGNOSTIC > if (xs->cookie != NULL) > panic("xs->cookie != NULL in scsi_xs_sync");