xref: /freebsd/share/man/man4/witness.4 (revision 6829dae12bb055451fa467da4589c43bd03b1e64)
1.\" Copyright (c) 2001 John H. Baldwin <jhb@FreeBSD.org>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.\" $FreeBSD$
26.\"
27.Dd November 18, 2015
28.Dt WITNESS 4
29.Os
30.Sh NAME
31.Nm witness
32.Nd lock validation facility
33.Sh SYNOPSIS
34.Cd options WITNESS
35.Cd options WITNESS_COUNT
36.Cd options WITNESS_KDB
37.Cd options WITNESS_NO_VNODE
38.Cd options WITNESS_SKIPSPIN
39.Sh DESCRIPTION
40The
41.Nm
42module keeps track of the locks acquired and released by each thread.
43It also keeps track of the order in which locks are acquired with respect
44to each other.
45Each time a lock is acquired,
46.Nm
47uses these two lists to verify that a lock is not being acquired in the
48wrong order.
49If a lock order violation is detected, then a message is output to the
50kernel console or log detailing the locks involved and the locations in
51question.
52Witness can also be configured to drop into the kernel debugger when an order
53violation occurs.
54.Pp
55The
56.Nm
57code also checks various other conditions such as verifying that one
58does not recurse on a non-recursive lock,
59or attempt an upgrade on a shared lock held by another thread.
60If any of these checks fail, then the kernel will panic.
61.Pp
62The
63.Dv WITNESS_COUNT
64kernel option controls the maximum number of
65.Nm
66entries that are tracked in the kernel.
67The maximum number of entries can be queried via the
68.Va debug.witness.count
69sysctl.
70It can also be set from the
71.Xr loader 8
72via the
73.Va debug.witness.count
74environment variable.
75.Pp
76The
77.Dv WITNESS_NO_VNODE
78kernel option tells
79.Nm
80to ignore locking issues between
81.Xr vnode 9
82objects.
83.Pp
84The flag that controls whether or not the kernel debugger is entered when a
85lock order violation is detected can be set in a variety of ways.
86By default, the flag is off, but if the
87.Dv WITNESS_KDB
88kernel option is
89specified, then the flag will default to on.
90It can also be set from the
91.Xr loader 8
92via the
93.Va debug.witness.kdb
94environment variable or after the kernel has booted via the
95.Va debug.witness.kdb
96sysctl.
97If the flag is set to zero, then the debugger will not be entered.
98If the flag is non-zero, then the debugger will be entered.
99.Pp
100The
101.Nm
102code can also be configured to skip all checks on spin mutexes.
103By default, this flag defaults to off, but it can be turned on by
104specifying the
105.Dv WITNESS_SKIPSPIN
106kernel option.
107The flag can also be set via the
108.Xr loader 8
109environment variable
110.Va debug.witness.skipspin .
111If the variable is set to a non-zero value, then spin mutexes are skipped.
112Once the kernel has booted, the status of this flag can be examined but not
113set via the read-only sysctl
114.Va debug.witness.skipspin .
115.Pp
116The sysctl
117.Va debug.witness.watch
118specifies the level of witness involvement in the system.
119A value of 1 specifies that witness is enabled.
120A value of 0 specifies that witness is disabled, but that can be enabled
121again.
122This will maintain a small amount of overhead in the system.
123A value of -1 specifies that witness is disabled permanently and
124cannot be enabled again.
125The sysctl
126.Va debug.witness.watch
127can be set via
128.Xr loader 8 .
129.Pp
130The sysctl
131.Va debug.witness.output_channel
132specifies the output channel used to display warnings emitted by
133.Nm .
134The possible values are
135.Ql console ,
136indicating that warnings are to be printed to the system console,
137.Ql log ,
138indicating that warnings are to be logged via
139.Xr log 9 ,
140and
141.Ql none .
142This sysctl can be set via
143.Xr loader 8 .
144.Pp
145The
146.Nm
147code also provides three extra
148.Xr ddb 4
149commands if both
150.Nm
151and
152.Xr ddb 4
153are compiled into the kernel:
154.Bl -ohang
155.It Ic show locks Op thread
156Outputs the list of locks held by a thread to the kernel console
157along with the filename and line number at which each lock was last acquired
158by the thread.
159The optional
160.Ar thread
161argument may be either a TID,
162PID,
163or pointer to a thread structure.
164If
165.Ar thread
166is not specified,
167then the locks held by the current thread are displayed.
168.It Ic show all locks
169Outputs the list of locks held by all threads in the system to the
170kernel console.
171.It Ic show witness
172Dump the current order list to the kernel console.
173The code first displays the lock order tree for all of the sleep locks.
174Then it displays the lock order tree for all of the spin locks.
175Finally, it displays a list of locks that have not yet been acquired.
176.El
177.Sh SEE ALSO
178.Xr ddb 4 ,
179.Xr loader 8 ,
180.Xr sysctl 8 ,
181.Xr mutex 9
182.Sh HISTORY
183The
184.Nm
185code first appeared in
186.Bsx 5.0
187and was imported from there into
188.Fx 5.0 .
189