2001-03-28 12:44:30 +00:00
|
|
|
.\" Copyright (c) 2001 John H. Baldwin <jhb@FreeBSD.org>
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
2015-11-19 05:56:59 +00:00
|
|
|
.Dd November 18, 2015
|
2001-03-28 12:44:30 +00:00
|
|
|
.Dt WITNESS 4
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm witness
|
|
|
|
.Nd lock validation facility
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.Cd options WITNESS
|
2015-02-06 20:46:46 +00:00
|
|
|
.Cd options WITNESS_COUNT
|
2004-11-26 13:54:56 +00:00
|
|
|
.Cd options WITNESS_KDB
|
2015-02-06 20:46:46 +00:00
|
|
|
.Cd options WITNESS_NO_VNODE
|
2001-03-28 12:44:30 +00:00
|
|
|
.Cd options WITNESS_SKIPSPIN
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
module keeps track of the locks acquired and released by each thread.
|
|
|
|
It also keeps track of the order in which locks are acquired with respect
|
|
|
|
to each other.
|
|
|
|
Each time a lock is acquired,
|
|
|
|
.Nm
|
|
|
|
uses these two lists to verify that a lock is not being acquired in the
|
|
|
|
wrong order.
|
|
|
|
If a lock order violation is detected, then a message is output to the
|
2015-11-19 05:56:59 +00:00
|
|
|
kernel console or log detailing the locks involved and the locations in
|
|
|
|
question.
|
2001-03-28 12:44:30 +00:00
|
|
|
Witness can also be configured to drop into the kernel debugger when an order
|
|
|
|
violation occurs.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
code also checks various other conditions such as verifying that one
|
2012-05-30 21:02:12 +00:00
|
|
|
does not recurse on a non-recursive lock,
|
|
|
|
or attempt an upgrade on a shared lock held by another thread.
|
2001-03-28 12:44:30 +00:00
|
|
|
If any of these checks fail, then the kernel will panic.
|
|
|
|
.Pp
|
2015-02-06 20:46:46 +00:00
|
|
|
The
|
|
|
|
.Dv WITNESS_COUNT
|
|
|
|
kernel option controls the maximum number of
|
2016-06-09 06:55:00 +00:00
|
|
|
.Nm
|
2015-02-06 20:46:46 +00:00
|
|
|
entries that are tracked in the kernel.
|
|
|
|
The maximum number of entries can be queried via the
|
|
|
|
.Va debug.witness.count
|
|
|
|
sysctl.
|
|
|
|
It can also be set from the
|
|
|
|
.Xr loader 8
|
|
|
|
via the
|
|
|
|
.Va debug.witness.count
|
|
|
|
environment variable.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Dv WITNESS_NO_VNODE
|
|
|
|
kernel option tells
|
2016-06-09 06:55:00 +00:00
|
|
|
.Nm
|
2015-02-06 20:46:46 +00:00
|
|
|
to ignore locking issues between
|
|
|
|
.Xr vnode 9
|
|
|
|
objects.
|
|
|
|
.Pp
|
2001-03-28 12:44:30 +00:00
|
|
|
The flag that controls whether or not the kernel debugger is entered when a
|
|
|
|
lock order violation is detected can be set in a variety of ways.
|
2001-04-04 11:51:59 +00:00
|
|
|
By default, the flag is off, but if the
|
2004-11-26 13:54:56 +00:00
|
|
|
.Dv WITNESS_KDB
|
2001-04-04 11:51:59 +00:00
|
|
|
kernel option is
|
2001-03-28 12:44:30 +00:00
|
|
|
specified, then the flag will default to on.
|
|
|
|
It can also be set from the
|
|
|
|
.Xr loader 8
|
|
|
|
via the
|
2004-09-06 23:37:17 +00:00
|
|
|
.Va debug.witness.kdb
|
2001-03-28 12:44:30 +00:00
|
|
|
environment variable or after the kernel has booted via the
|
2004-09-06 23:37:17 +00:00
|
|
|
.Va debug.witness.kdb
|
2001-03-28 12:44:30 +00:00
|
|
|
sysctl.
|
|
|
|
If the flag is set to zero, then the debugger will not be entered.
|
|
|
|
If the flag is non-zero, then the debugger will be entered.
|
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
code can also be configured to skip all checks on spin mutexes.
|
|
|
|
By default, this flag defaults to off, but it can be turned on by
|
2001-04-04 11:51:59 +00:00
|
|
|
specifying the
|
2001-04-04 17:41:50 +00:00
|
|
|
.Dv WITNESS_SKIPSPIN
|
2001-04-04 11:51:59 +00:00
|
|
|
kernel option.
|
2001-03-28 12:44:30 +00:00
|
|
|
The flag can also be set via the
|
|
|
|
.Xr loader 8
|
|
|
|
environment variable
|
2004-09-06 23:37:17 +00:00
|
|
|
.Va debug.witness.skipspin .
|
2001-03-28 12:44:30 +00:00
|
|
|
If the variable is set to a non-zero value, then spin mutexes are skipped.
|
|
|
|
Once the kernel has booted, the status of this flag can be examined but not
|
|
|
|
set via the read-only sysctl
|
2004-09-06 23:37:17 +00:00
|
|
|
.Va debug.witness.skipspin .
|
2001-03-28 12:44:30 +00:00
|
|
|
.Pp
|
2005-04-09 14:09:54 +00:00
|
|
|
The sysctl
|
|
|
|
.Va debug.witness.watch
|
2005-07-31 03:30:48 +00:00
|
|
|
specifies the level of witness involvement in the system.
|
2005-06-15 13:31:23 +00:00
|
|
|
A value of 1 specifies that witness is enabled.
|
2008-08-30 13:37:28 +00:00
|
|
|
A value of 0 specifies that witness is disabled, but that can be enabled
|
2016-06-08 08:50:35 +00:00
|
|
|
again.
|
|
|
|
This will maintain a small amount of overhead in the system.
|
2012-05-30 21:02:12 +00:00
|
|
|
A value of -1 specifies that witness is disabled permanently and
|
2008-08-30 13:37:28 +00:00
|
|
|
cannot be enabled again.
|
2005-07-13 21:12:06 +00:00
|
|
|
The sysctl
|
2005-04-09 14:09:54 +00:00
|
|
|
.Va debug.witness.watch
|
|
|
|
can be set via
|
|
|
|
.Xr loader 8 .
|
|
|
|
.Pp
|
2015-11-19 05:56:59 +00:00
|
|
|
The sysctl
|
|
|
|
.Va debug.witness.output_channel
|
|
|
|
specifies the output channel used to display warnings emitted by
|
|
|
|
.Nm .
|
|
|
|
The possible values are
|
|
|
|
.Ql console ,
|
|
|
|
indicating that warnings are to be printed to the system console,
|
|
|
|
.Ql log ,
|
|
|
|
indicating that warnings are to be logged via
|
|
|
|
.Xr log 9 ,
|
|
|
|
and
|
|
|
|
.Ql none .
|
|
|
|
This sysctl can be set via
|
|
|
|
.Xr loader 8 .
|
|
|
|
.Pp
|
2001-03-28 12:44:30 +00:00
|
|
|
The
|
|
|
|
.Nm
|
2015-03-24 22:39:49 +00:00
|
|
|
code also provides three extra
|
2001-03-28 12:44:30 +00:00
|
|
|
.Xr ddb 4
|
|
|
|
commands if both
|
|
|
|
.Nm
|
|
|
|
and
|
|
|
|
.Xr ddb 4
|
|
|
|
are compiled into the kernel:
|
|
|
|
.Bl -ohang
|
2012-05-30 21:02:12 +00:00
|
|
|
.It Ic show locks Op thread
|
|
|
|
Outputs the list of locks held by a thread to the kernel console
|
2001-03-28 12:44:30 +00:00
|
|
|
along with the filename and line number at which each lock was last acquired
|
2012-05-30 21:02:12 +00:00
|
|
|
by the thread.
|
|
|
|
The optional
|
|
|
|
.Ar thread
|
|
|
|
argument may be either a TID,
|
|
|
|
PID,
|
|
|
|
or pointer to a thread structure.
|
|
|
|
If
|
|
|
|
.Ar thread
|
|
|
|
is not specified,
|
|
|
|
then the locks held by the current thread are displayed.
|
|
|
|
.It Ic show all locks
|
|
|
|
Outputs the list of locks held by all threads in the system to the
|
|
|
|
kernel console.
|
2001-03-28 12:44:30 +00:00
|
|
|
.It Ic show witness
|
|
|
|
Dump the current order list to the kernel console.
|
|
|
|
The code first displays the lock order tree for all of the sleep locks.
|
|
|
|
Then it displays the lock order tree for all of the spin locks.
|
|
|
|
Finally, it displays a list of locks that have not yet been acquired.
|
|
|
|
.El
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr ddb 4 ,
|
2005-07-13 21:12:06 +00:00
|
|
|
.Xr loader 8 ,
|
|
|
|
.Xr sysctl 8 ,
|
2001-03-28 12:44:30 +00:00
|
|
|
.Xr mutex 9
|
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
code first appeared in
|
2001-08-13 17:07:40 +00:00
|
|
|
.Bsx 5.0
|
|
|
|
and was imported from there into
|
2001-03-28 12:44:30 +00:00
|
|
|
.Fx 5.0 .
|