@@ -38,6 +38,15 @@ as a regular user, and install it with
38
38
39
39
sudo make install
40
40
41
+ Supplemental documentation
42
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43
+
44
+ For supplemental documentation refer to the wiki:
45
+
46
+ https://bottest.wiki.kernel.org/coccicheck
47
+
48
+ The wiki documentation always refers to the linux-next version of the script.
49
+
41
50
Using Coccinelle on the Linux kernel
42
51
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
43
52
@@ -94,11 +103,26 @@ To enable verbose messages set the V= variable, for example:
94
103
95
104
make coccicheck MODE=report V=1
96
105
106
+ Coccinelle parallelization
107
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
108
+
97
109
By default, coccicheck tries to run as parallel as possible. To change
98
110
the parallelism, set the J= variable. For example, to run across 4 CPUs:
99
111
100
112
make coccicheck MODE=report J=4
101
113
114
+ As of Coccinelle 1.0.2 Coccinelle uses Ocaml parmap for parallelization,
115
+ if support for this is detected you will benefit from parmap parallelization.
116
+
117
+ When parmap is enabled coccicheck will enable dynamic load balancing by using
118
+ '--chunksize 1' argument, this ensures we keep feeding threads with work
119
+ one by one, so that we avoid the situation where most work gets done by only
120
+ a few threads. With dynamic load balancing, if a thread finishes early we keep
121
+ feeding it more work.
122
+
123
+ When parmap is enabled, if an error occurs in Coccinelle, this error
124
+ value is propagated back, the return value of the 'make coccicheck'
125
+ captures this return value.
102
126
103
127
Using Coccinelle with a single semantic patch
104
128
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -142,15 +166,118 @@ semantic patch as shown in the previous section.
142
166
The "report" mode is the default. You can select another one with the
143
167
MODE variable explained above.
144
168
169
+ Debugging Coccinelle SmPL patches
170
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
171
+
172
+ Using coccicheck is best as it provides in the spatch command line
173
+ include options matching the options used when we compile the kernel.
174
+ You can learn what these options are by using V=1, you could then
175
+ manually run Coccinelle with debug options added.
176
+
177
+ Alternatively you can debug running Coccinelle against SmPL patches
178
+ by asking for stderr to be redirected to stderr, by default stderr
179
+ is redirected to /dev/null, if you'd like to capture stderr you
180
+ can specify the DEBUG_FILE="file.txt" option to coccicheck. For
181
+ instance:
182
+
183
+ rm -f cocci.err
184
+ make coccicheck COCCI=scripts/coccinelle/free/kfree.cocci MODE=report DEBUG_FILE=cocci.err
185
+ cat cocci.err
186
+
187
+ You can use SPFLAGS to add debugging flags, for instance you may want to
188
+ add both --profile --show-trying to SPFLAGS when debugging. For instance
189
+ you may want to use:
190
+
191
+ rm -f err.log
192
+ export COCCI=scripts/coccinelle/misc/irqf_oneshot.cocci
193
+ make coccicheck DEBUG_FILE="err.log" MODE=report SPFLAGS="--profile --show-trying" M=./drivers/mfd/arizona-irq.c
194
+
195
+ err.log will now have the profiling information, while stdout will
196
+ provide some progress information as Coccinelle moves forward with
197
+ work.
198
+
199
+ DEBUG_FILE support is only supported when using coccinelle >= 1.2.
200
+
201
+ .cocciconfig support
202
+ ~~~~~~~~~~~~~~~~~~~~~~
203
+
204
+ Coccinelle supports reading .cocciconfig for default Coccinelle options that
205
+ should be used every time spatch is spawned, the order of precedence for
206
+ variables for .cocciconfig is as follows:
207
+
208
+ o Your current user's home directory is processed first
209
+ o Your directory from which spatch is called is processed next
210
+ o The directory provided with the --dir option is processed last, if used
211
+
212
+ Since coccicheck runs through make, it naturally runs from the kernel
213
+ proper dir, as such the second rule above would be implied for picking up a
214
+ .cocciconfig when using 'make coccicheck'.
215
+
216
+ 'make coccicheck' also supports using M= targets.If you do not supply
217
+ any M= target, it is assumed you want to target the entire kernel.
218
+ The kernel coccicheck script has:
219
+
220
+ if [ "$KBUILD_EXTMOD" = "" ] ; then
221
+ OPTIONS="--dir $srctree $COCCIINCLUDE"
222
+ else
223
+ OPTIONS="--dir $KBUILD_EXTMOD $COCCIINCLUDE"
224
+ fi
225
+
226
+ KBUILD_EXTMOD is set when an explicit target with M= is used. For both cases
227
+ the spatch --dir argument is used, as such third rule applies when whether M=
228
+ is used or not, and when M= is used the target directory can have its own
229
+ .cocciconfig file. When M= is not passed as an argument to coccicheck the
230
+ target directory is the same as the directory from where spatch was called.
231
+
232
+ If not using the kernel's coccicheck target, keep the above precedence
233
+ order logic of .cocciconfig reading. If using the kernel's coccicheck target,
234
+ override any of the kernel's .coccicheck's settings using SPFLAGS.
235
+
236
+ We help Coccinelle when used against Linux with a set of sensible defaults
237
+ options for Linux with our own Linux .cocciconfig. This hints to coccinelle
238
+ git can be used for 'git grep' queries over coccigrep. A timeout of 200
239
+ seconds should suffice for now.
240
+
241
+ The options picked up by coccinelle when reading a .cocciconfig do not appear
242
+ as arguments to spatch processes running on your system, to confirm what
243
+ options will be used by Coccinelle run:
244
+
245
+ spatch --print-options-only
246
+
247
+ You can override with your own preferred index option by using SPFLAGS. Take
248
+ note that when there are conflicting options Coccinelle takes precedence for
249
+ the last options passed. Using .cocciconfig is possible to use idutils, however
250
+ given the order of precedence followed by Coccinelle, since the kernel now
251
+ carries its own .cocciconfig, you will need to use SPFLAGS to use idutils if
252
+ desired. See below section "Additional flags" for more details on how to use
253
+ idutils.
254
+
145
255
Additional flags
146
256
~~~~~~~~~~~~~~~~~~
147
257
148
258
Additional flags can be passed to spatch through the SPFLAGS
149
- variable.
259
+ variable. This works as Coccinelle respects the last flags
260
+ given to it when options are in conflict.
150
261
151
262
make SPFLAGS=--use-glimpse coccicheck
263
+
264
+ Coccinelle supports idutils as well but requires coccinelle >= 1.0.6.
265
+ When no ID file is specified coccinelle assumes your ID database file
266
+ is in the file .id-utils.index on the top level of the kernel, coccinelle
267
+ carries a script scripts/idutils_index.sh which creates the database with
268
+
269
+ mkid -i C --output .id-utils.index
270
+
271
+ If you have another database filename you can also just symlink with this
272
+ name.
273
+
152
274
make SPFLAGS=--use-idutils coccicheck
153
275
276
+ Alternatively you can specify the database filename explicitly, for
277
+ instance:
278
+
279
+ make SPFLAGS="--use-idutils /full-path/to/ID" coccicheck
280
+
154
281
See spatch --help to learn more about spatch options.
155
282
156
283
Note that the '--use-glimpse' and '--use-idutils' options
@@ -159,6 +286,25 @@ thus active by default. However, by indexing the code with
159
286
one of these tools, and according to the cocci file used,
160
287
spatch could proceed the entire code base more quickly.
161
288
289
+ SmPL patch specific options
290
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
291
+
292
+ SmPL patches can have their own requirements for options passed
293
+ to Coccinelle. SmPL patch specific options can be provided by
294
+ providing them at the top of the SmPL patch, for instance:
295
+
296
+ // Options: --no-includes --include-headers
297
+
298
+ SmPL patch Coccinelle requirements
299
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
300
+
301
+ As Coccinelle features get added some more advanced SmPL patches
302
+ may require newer versions of Coccinelle. If an SmPL patch requires
303
+ at least a version of Coccinelle, this can be specified as follows,
304
+ as an example if requiring at least Coccinelle >= 1.0.5:
305
+
306
+ // Requires: 1.0.5
307
+
162
308
Proposing new semantic patches
163
309
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
164
310
0 commit comments