Skip to content

Commit 33afd4b

Browse files
committed
Merge tag 'mm-nonmm-stable-2023-04-27-16-01' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
Pull non-MM updates from Andrew Morton: "Mainly singleton patches all over the place. Series of note are: - updates to scripts/gdb from Glenn Washburn - kexec cleanups from Bjorn Helgaas" * tag 'mm-nonmm-stable-2023-04-27-16-01' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (50 commits) mailmap: add entries for Paul Mackerras libgcc: add forward declarations for generic library routines mailmap: add entry for Oleksandr ocfs2: reduce ioctl stack usage fs/proc: add Kthread flag to /proc/$pid/status ia64: fix an addr to taddr in huge_pte_offset() checkpatch: introduce proper bindings license check epoll: rename global epmutex scripts/gdb: add GDB convenience functions $lx_dentry_name() and $lx_i_dentry() scripts/gdb: create linux/vfs.py for VFS related GDB helpers uapi/linux/const.h: prefer ISO-friendly __typeof__ delayacct: track delays from IRQ/SOFTIRQ scripts/gdb: timerlist: convert int chunks to str scripts/gdb: print interrupts scripts/gdb: raise error with reduced debugging information scripts/gdb: add a Radix Tree Parser lib/rbtree: use '+' instead of '|' for setting color. proc/stat: remove arch_idle_time() checkpatch: check for misuse of the link tags checkpatch: allow Closes tags with links ...
2 parents 7fa8a8e + d88f2f7 commit 33afd4b

68 files changed

Lines changed: 1032 additions & 377 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.mailmap

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ Nicolas Pitre <nico@fluxnic.net> <nico@linaro.org>
360360
Nicolas Saenz Julienne <nsaenz@kernel.org> <nsaenzjulienne@suse.de>
361361
Nicolas Saenz Julienne <nsaenz@kernel.org> <nsaenzjulienne@suse.com>
362362
Niklas Söderlund <niklas.soderlund+renesas@ragnatech.se>
363+
Oleksandr Natalenko <oleksandr@natalenko.name> <oleksandr@redhat.com>
363364
Oleksij Rempel <linux@rempel-privat.de> <bug-track@fisher-privat.net>
364365
Oleksij Rempel <linux@rempel-privat.de> <external.Oleksij.Rempel@de.bosch.com>
365366
Oleksij Rempel <linux@rempel-privat.de> <fixed-term.Oleksij.Rempel@de.bosch.com>
@@ -375,6 +376,8 @@ Paul E. McKenney <paulmck@kernel.org> <paul.mckenney@linaro.org>
375376
Paul E. McKenney <paulmck@kernel.org> <paulmck@linux.ibm.com>
376377
Paul E. McKenney <paulmck@kernel.org> <paulmck@linux.vnet.ibm.com>
377378
Paul E. McKenney <paulmck@kernel.org> <paulmck@us.ibm.com>
379+
Paul Mackerras <paulus@ozlabs.org> <paulus@samba.org>
380+
Paul Mackerras <paulus@ozlabs.org> <paulus@au1.ibm.com>
378381
Peter A Jonsson <pj@ludd.ltu.se>
379382
Peter Oruba <peter.oruba@amd.com>
380383
Peter Oruba <peter@oruba.de>

Documentation/accounting/delay-accounting.rst

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ d) memory reclaim
1616
e) thrashing
1717
f) direct compact
1818
g) write-protect copy
19+
h) IRQ/SOFTIRQ
1920

2021
and makes these statistics available to userspace through
2122
the taskstats interface.
@@ -49,7 +50,7 @@ this structure. See
4950
for a description of the fields pertaining to delay accounting.
5051
It will generally be in the form of counters returning the cumulative
5152
delay seen for cpu, sync block I/O, swapin, memory reclaim, thrash page
52-
cache, direct compact, write-protect copy etc.
53+
cache, direct compact, write-protect copy, IRQ/SOFTIRQ etc.
5354

5455
Taking the difference of two successive readings of a given
5556
counter (say cpu_delay_total) for a task will give the delay
@@ -109,17 +110,19 @@ Get sum of delays, since system boot, for all pids with tgid 5::
109110
CPU count real total virtual total delay total delay average
110111
8 7000000 6872122 3382277 0.423ms
111112
IO count delay total delay average
112-
0 0 0ms
113+
0 0 0.000ms
113114
SWAP count delay total delay average
114-
0 0 0ms
115+
0 0 0.000ms
115116
RECLAIM count delay total delay average
116-
0 0 0ms
117+
0 0 0.000ms
117118
THRASHING count delay total delay average
118-
0 0 0ms
119+
0 0 0.000ms
119120
COMPACT count delay total delay average
120-
0 0 0ms
121-
WPCOPY count delay total delay average
122-
0 0 0ms
121+
0 0 0.000ms
122+
WPCOPY count delay total delay average
123+
0 0 0.000ms
124+
IRQ count delay total delay average
125+
0 0 0.000ms
123126

124127
Get IO accounting for pid 1, it works only with -p::
125128

Documentation/dev-tools/kcov.rst

Lines changed: 102 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,50 @@
1-
kcov: code coverage for fuzzing
1+
KCOV: code coverage for fuzzing
22
===============================
33

4-
kcov exposes kernel code coverage information in a form suitable for coverage-
5-
guided fuzzing (randomized testing). Coverage data of a running kernel is
6-
exported via the "kcov" debugfs file. Coverage collection is enabled on a task
7-
basis, and thus it can capture precise coverage of a single system call.
4+
KCOV collects and exposes kernel code coverage information in a form suitable
5+
for coverage-guided fuzzing. Coverage data of a running kernel is exported via
6+
the ``kcov`` debugfs file. Coverage collection is enabled on a task basis, and
7+
thus KCOV can capture precise coverage of a single system call.
88

9-
Note that kcov does not aim to collect as much coverage as possible. It aims
10-
to collect more or less stable coverage that is function of syscall inputs.
11-
To achieve this goal it does not collect coverage in soft/hard interrupts
12-
and instrumentation of some inherently non-deterministic parts of kernel is
13-
disabled (e.g. scheduler, locking).
9+
Note that KCOV does not aim to collect as much coverage as possible. It aims
10+
to collect more or less stable coverage that is a function of syscall inputs.
11+
To achieve this goal, it does not collect coverage in soft/hard interrupts
12+
(unless remove coverage collection is enabled, see below) and from some
13+
inherently non-deterministic parts of the kernel (e.g. scheduler, locking).
1414

15-
kcov is also able to collect comparison operands from the instrumented code
16-
(this feature currently requires that the kernel is compiled with clang).
15+
Besides collecting code coverage, KCOV can also collect comparison operands.
16+
See the "Comparison operands collection" section for details.
17+
18+
Besides collecting coverage data from syscall handlers, KCOV can also collect
19+
coverage for annotated parts of the kernel executing in background kernel
20+
tasks or soft interrupts. See the "Remote coverage collection" section for
21+
details.
1722

1823
Prerequisites
1924
-------------
2025

21-
Configure the kernel with::
26+
KCOV relies on compiler instrumentation and requires GCC 6.1.0 or later
27+
or any Clang version supported by the kernel.
2228

23-
CONFIG_KCOV=y
29+
Collecting comparison operands is supported with GCC 8+ or with Clang.
2430

25-
CONFIG_KCOV requires gcc 6.1.0 or later.
31+
To enable KCOV, configure the kernel with::
2632

27-
If the comparison operands need to be collected, set::
33+
CONFIG_KCOV=y
34+
35+
To enable comparison operands collection, set::
2836

2937
CONFIG_KCOV_ENABLE_COMPARISONS=y
3038

31-
Profiling data will only become accessible once debugfs has been mounted::
39+
Coverage data only becomes accessible once debugfs has been mounted::
3240

3341
mount -t debugfs none /sys/kernel/debug
3442

3543
Coverage collection
3644
-------------------
3745

38-
The following program demonstrates coverage collection from within a test
39-
program using kcov:
46+
The following program demonstrates how to use KCOV to collect coverage for a
47+
single syscall from within a test program:
4048

4149
.. code-block:: c
4250
@@ -84,7 +92,7 @@ program using kcov:
8492
perror("ioctl"), exit(1);
8593
/* Reset coverage from the tail of the ioctl() call. */
8694
__atomic_store_n(&cover[0], 0, __ATOMIC_RELAXED);
87-
/* That's the target syscal call. */
95+
/* Call the target syscall call. */
8896
read(-1, NULL, 0);
8997
/* Read number of PCs collected. */
9098
n = __atomic_load_n(&cover[0], __ATOMIC_RELAXED);
@@ -103,7 +111,7 @@ program using kcov:
103111
return 0;
104112
}
105113
106-
After piping through addr2line output of the program looks as follows::
114+
After piping through ``addr2line`` the output of the program looks as follows::
107115

108116
SyS_read
109117
fs/read_write.c:562
@@ -121,12 +129,13 @@ After piping through addr2line output of the program looks as follows::
121129
fs/read_write.c:562
122130

123131
If a program needs to collect coverage from several threads (independently),
124-
it needs to open /sys/kernel/debug/kcov in each thread separately.
132+
it needs to open ``/sys/kernel/debug/kcov`` in each thread separately.
125133

126134
The interface is fine-grained to allow efficient forking of test processes.
127-
That is, a parent process opens /sys/kernel/debug/kcov, enables trace mode,
128-
mmaps coverage buffer and then forks child processes in a loop. Child processes
129-
only need to enable coverage (disable happens automatically on thread end).
135+
That is, a parent process opens ``/sys/kernel/debug/kcov``, enables trace mode,
136+
mmaps coverage buffer, and then forks child processes in a loop. The child
137+
processes only need to enable coverage (it gets disabled automatically when
138+
a thread exits).
130139

131140
Comparison operands collection
132141
------------------------------
@@ -205,52 +214,78 @@ Comparison operands collection is similar to coverage collection:
205214
return 0;
206215
}
207216
208-
Note that the kcov modes (coverage collection or comparison operands) are
209-
mutually exclusive.
217+
Note that the KCOV modes (collection of code coverage or comparison operands)
218+
are mutually exclusive.
210219

211220
Remote coverage collection
212221
--------------------------
213222

214-
With KCOV_ENABLE coverage is collected only for syscalls that are issued
215-
from the current process. With KCOV_REMOTE_ENABLE it's possible to collect
216-
coverage for arbitrary parts of the kernel code, provided that those parts
217-
are annotated with kcov_remote_start()/kcov_remote_stop().
218-
219-
This allows to collect coverage from two types of kernel background
220-
threads: the global ones, that are spawned during kernel boot in a limited
221-
number of instances (e.g. one USB hub_event() worker thread is spawned per
222-
USB HCD); and the local ones, that are spawned when a user interacts with
223-
some kernel interface (e.g. vhost workers); as well as from soft
224-
interrupts.
225-
226-
To enable collecting coverage from a global background thread or from a
227-
softirq, a unique global handle must be assigned and passed to the
228-
corresponding kcov_remote_start() call. Then a userspace process can pass
229-
a list of such handles to the KCOV_REMOTE_ENABLE ioctl in the handles
230-
array field of the kcov_remote_arg struct. This will attach the used kcov
231-
device to the code sections, that are referenced by those handles.
232-
233-
Since there might be many local background threads spawned from different
234-
userspace processes, we can't use a single global handle per annotation.
235-
Instead, the userspace process passes a non-zero handle through the
236-
common_handle field of the kcov_remote_arg struct. This common handle gets
237-
saved to the kcov_handle field in the current task_struct and needs to be
238-
passed to the newly spawned threads via custom annotations. Those threads
239-
should in turn be annotated with kcov_remote_start()/kcov_remote_stop().
240-
241-
Internally kcov stores handles as u64 integers. The top byte of a handle
242-
is used to denote the id of a subsystem that this handle belongs to, and
243-
the lower 4 bytes are used to denote the id of a thread instance within
244-
that subsystem. A reserved value 0 is used as a subsystem id for common
245-
handles as they don't belong to a particular subsystem. The bytes 4-7 are
246-
currently reserved and must be zero. In the future the number of bytes
247-
used for the subsystem or handle ids might be increased.
248-
249-
When a particular userspace process collects coverage via a common
250-
handle, kcov will collect coverage for each code section that is annotated
251-
to use the common handle obtained as kcov_handle from the current
252-
task_struct. However non common handles allow to collect coverage
253-
selectively from different subsystems.
223+
Besides collecting coverage data from handlers of syscalls issued from a
224+
userspace process, KCOV can also collect coverage for parts of the kernel
225+
executing in other contexts - so-called "remote" coverage.
226+
227+
Using KCOV to collect remote coverage requires:
228+
229+
1. Modifying kernel code to annotate the code section from where coverage
230+
should be collected with ``kcov_remote_start`` and ``kcov_remote_stop``.
231+
232+
2. Using ``KCOV_REMOTE_ENABLE`` instead of ``KCOV_ENABLE`` in the userspace
233+
process that collects coverage.
234+
235+
Both ``kcov_remote_start`` and ``kcov_remote_stop`` annotations and the
236+
``KCOV_REMOTE_ENABLE`` ioctl accept handles that identify particular coverage
237+
collection sections. The way a handle is used depends on the context where the
238+
matching code section executes.
239+
240+
KCOV supports collecting remote coverage from the following contexts:
241+
242+
1. Global kernel background tasks. These are the tasks that are spawned during
243+
kernel boot in a limited number of instances (e.g. one USB ``hub_event``
244+
worker is spawned per one USB HCD).
245+
246+
2. Local kernel background tasks. These are spawned when a userspace process
247+
interacts with some kernel interface and are usually killed when the process
248+
exits (e.g. vhost workers).
249+
250+
3. Soft interrupts.
251+
252+
For #1 and #3, a unique global handle must be chosen and passed to the
253+
corresponding ``kcov_remote_start`` call. Then a userspace process must pass
254+
this handle to ``KCOV_REMOTE_ENABLE`` in the ``handles`` array field of the
255+
``kcov_remote_arg`` struct. This will attach the used KCOV device to the code
256+
section referenced by this handle. Multiple global handles identifying
257+
different code sections can be passed at once.
258+
259+
For #2, the userspace process instead must pass a non-zero handle through the
260+
``common_handle`` field of the ``kcov_remote_arg`` struct. This common handle
261+
gets saved to the ``kcov_handle`` field in the current ``task_struct`` and
262+
needs to be passed to the newly spawned local tasks via custom kernel code
263+
modifications. Those tasks should in turn use the passed handle in their
264+
``kcov_remote_start`` and ``kcov_remote_stop`` annotations.
265+
266+
KCOV follows a predefined format for both global and common handles. Each
267+
handle is a ``u64`` integer. Currently, only the one top and the lower 4 bytes
268+
are used. Bytes 4-7 are reserved and must be zero.
269+
270+
For global handles, the top byte of the handle denotes the id of a subsystem
271+
this handle belongs to. For example, KCOV uses ``1`` as the USB subsystem id.
272+
The lower 4 bytes of a global handle denote the id of a task instance within
273+
that subsystem. For example, each ``hub_event`` worker uses the USB bus number
274+
as the task instance id.
275+
276+
For common handles, a reserved value ``0`` is used as a subsystem id, as such
277+
handles don't belong to a particular subsystem. The lower 4 bytes of a common
278+
handle identify a collective instance of all local tasks spawned by the
279+
userspace process that passed a common handle to ``KCOV_REMOTE_ENABLE``.
280+
281+
In practice, any value can be used for common handle instance id if coverage
282+
is only collected from a single userspace process on the system. However, if
283+
common handles are used by multiple processes, unique instance ids must be
284+
used for each process. One option is to use the process id as the common
285+
handle instance id.
286+
287+
The following program demonstrates using KCOV to collect coverage from both
288+
local tasks spawned by the process and the global task that handles USB bus #1:
254289

255290
.. code-block:: c
256291

Documentation/filesystems/proc.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ read the file /proc/PID/status::
179179
Gid: 100 100 100 100
180180
FDSize: 256
181181
Groups: 100 14 16
182+
Kthread: 0
182183
VmPeak: 5004 kB
183184
VmSize: 5004 kB
184185
VmLck: 0 kB
@@ -256,6 +257,7 @@ It's slow but very precise.
256257
NSpid descendant namespace process ID hierarchy
257258
NSpgid descendant namespace process group ID hierarchy
258259
NSsid descendant namespace session ID hierarchy
260+
Kthread kernel thread flag, 1 is yes, 0 is no
259261
VmPeak peak virtual memory size
260262
VmSize total program size
261263
VmLck locked memory size

Documentation/process/5.Posting.rst

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ the patch::
207207
Fixes: 1f2e3d4c5b6a ("The first line of the commit specified by the first 12 characters of its SHA-1 ID")
208208

209209
Another tag is used for linking web pages with additional backgrounds or
210-
details, for example a report about a bug fixed by the patch or a document
211-
with a specification implemented by the patch::
210+
details, for example an earlier discussion which leads to the patch or a
211+
document with a specification implemented by the patch::
212212

213213
Link: https://example.com/somewhere.html optional-other-stuff
214214

@@ -217,7 +217,17 @@ latest public review posting of the patch; often this is automatically done
217217
by tools like b4 or a git hook like the one described in
218218
'Documentation/maintainer/configure-git.rst'.
219219

220-
A third kind of tag is used to document who was involved in the development of
220+
If the URL points to a public bug report being fixed by the patch, use the
221+
"Closes:" tag instead::
222+
223+
Closes: https://example.com/issues/1234 optional-other-stuff
224+
225+
Some bug trackers have the ability to close issues automatically when a
226+
commit with such a tag is applied. Some bots monitoring mailing lists can
227+
also track such tags and take certain actions. Private bug trackers and
228+
invalid URLs are forbidden.
229+
230+
Another kind of tag is used to document who was involved in the development of
221231
the patch. Each of these uses this format::
222232

223233
tag: Full Name <email address> optional-other-stuff
@@ -251,8 +261,10 @@ The tags in common use are:
251261
- Reported-by: names a user who reported a problem which is fixed by this
252262
patch; this tag is used to give credit to the (often underappreciated)
253263
people who test our code and let us know when things do not work
254-
correctly. Note, this tag should be followed by a Link: tag pointing to the
255-
report, unless the report is not available on the web.
264+
correctly. Note, this tag should be followed by a Closes: tag pointing to
265+
the report, unless the report is not available on the web. The Link: tag
266+
can be used instead of Closes: if the patch fixes a part of the issue(s)
267+
being reported.
256268

257269
- Cc: the named person received a copy of the patch and had the
258270
opportunity to comment on it.

Documentation/process/submitting-patches.rst

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,9 @@ there is no collision with your six-character ID now, that condition may
113113
change five years from now.
114114

115115
If related discussions or any other background information behind the change
116-
can be found on the web, add 'Link:' tags pointing to it. In case your patch
117-
fixes a bug, for example, add a tag with a URL referencing the report in the
118-
mailing list archives or a bug tracker; if the patch is a result of some
119-
earlier mailing list discussion or something documented on the web, point to
120-
it.
116+
can be found on the web, add 'Link:' tags pointing to it. If the patch is a
117+
result of some earlier mailing list discussions or something documented on the
118+
web, point to it.
121119

122120
When linking to mailing list archives, preferably use the lore.kernel.org
123121
message archiver service. To create the link URL, use the contents of the
@@ -134,6 +132,16 @@ resources. In addition to giving a URL to a mailing list archive or bug,
134132
summarize the relevant points of the discussion that led to the
135133
patch as submitted.
136134

135+
In case your patch fixes a bug, use the 'Closes:' tag with a URL referencing
136+
the report in the mailing list archives or a public bug tracker. For example::
137+
138+
Closes: https://example.com/issues/1234
139+
140+
Some bug trackers have the ability to close issues automatically when a
141+
commit with such a tag is applied. Some bots monitoring mailing lists can
142+
also track such tags and take certain actions. Private bug trackers and
143+
invalid URLs are forbidden.
144+
137145
If your patch fixes a bug in a specific commit, e.g. you found an issue using
138146
``git bisect``, please use the 'Fixes:' tag with the first 12 characters of
139147
the SHA-1 ID, and the one line summary. Do not split the tag across multiple
@@ -495,9 +503,11 @@ Using Reported-by:, Tested-by:, Reviewed-by:, Suggested-by: and Fixes:
495503
The Reported-by tag gives credit to people who find bugs and report them and it
496504
hopefully inspires them to help us again in the future. The tag is intended for
497505
bugs; please do not use it to credit feature requests. The tag should be
498-
followed by a Link: tag pointing to the report, unless the report is not
499-
available on the web. Please note that if the bug was reported in private, then
500-
ask for permission first before using the Reported-by tag.
506+
followed by a Closes: tag pointing to the report, unless the report is not
507+
available on the web. The Link: tag can be used instead of Closes: if the patch
508+
fixes a part of the issue(s) being reported. Please note that if the bug was
509+
reported in private, then ask for permission first before using the Reported-by
510+
tag.
501511

502512
A Tested-by: tag indicates that the patch has been successfully tested (in
503513
some environment) by the person named. This tag informs maintainers that

0 commit comments

Comments
 (0)