No description
Find a file
Andrey Konovalov a7ed6cc7b7 UPSTREAM: kcov: remote coverage support
(Upstream commit eec028c9386ed1a692aa01a85b55952202b41619.)

Patch series " kcov: collect coverage from usb and vhost", v3.

This patchset extends kcov to allow collecting coverage from backgound
kernel threads.  This extension requires custom annotations for each of
the places where coverage collection is desired.  This patchset
implements this for hub events in the USB subsystem and for vhost
workers.  See the first patch description for details about the kcov
extension.  The other two patches apply this kcov extension to USB and
vhost.

Examples of other subsystems that might potentially benefit from this
when custom annotations are added (the list is based on
process_one_work() callers for bugs recently reported by syzbot):

1. fs: writeback wb_workfn() worker,
2. net: addrconf_dad_work()/addrconf_verify_work() workers,
3. net: neigh_periodic_work() worker,
4. net/p9: p9_write_work()/p9_read_work() workers,
5. block: blk_mq_run_work_fn() worker.

These patches have been used to enable coverage-guided USB fuzzing with
syzkaller for the last few years, see the details here:

  https://github.com/google/syzkaller/blob/master/docs/linux/external_fuzzing_usb.md

This patchset has been pushed to the public Linux kernel Gerrit
instance:

  https://linux-review.googlesource.com/c/linux/kernel/git/torvalds/linux/+/1524

This patch (of 3):

Add background thread coverage collection ability to kcov.

With KCOV_ENABLE coverage is collected only for syscalls that are issued
from the current process.  With KCOV_REMOTE_ENABLE it's possible to
collect coverage for arbitrary parts of the kernel code, provided that
those parts are annotated with kcov_remote_start()/kcov_remote_stop().

This allows to collect coverage from two types of kernel background
threads: the global ones, that are spawned during kernel boot in a
limited number of instances (e.g.  one USB hub_event() worker thread is
spawned per USB HCD); and the local ones, that are spawned when a user
interacts with some kernel interface (e.g.  vhost workers).

To enable collecting coverage from a global background thread, a unique
global handle must be assigned and passed to the corresponding
kcov_remote_start() call.  Then a userspace process can pass a list of
such handles to the KCOV_REMOTE_ENABLE ioctl in the handles array field
of the kcov_remote_arg struct.  This will attach the used kcov device to
the code sections, that are referenced by those handles.

Since there might be many local background threads spawned from
different userspace processes, we can't use a single global handle per
annotation.  Instead, the userspace process passes a non-zero handle
through the common_handle field of the kcov_remote_arg struct.  This
common handle gets saved to the kcov_handle field in the current
task_struct and needs to be passed to the newly spawned threads via
custom annotations.  Those threads should in turn be annotated with
kcov_remote_start()/kcov_remote_stop().

Internally kcov stores handles as u64 integers.  The top byte of a
handle is used to denote the id of a subsystem that this handle belongs
to, and the lower 4 bytes are used to denote the id of a thread instance
within that subsystem.  A reserved value 0 is used as a subsystem id for
common handles as they don't belong to a particular subsystem.  The
bytes 4-7 are currently reserved and must be zero.  In the future the
number of bytes used for the subsystem or handle ids might be increased.

When a particular userspace process collects coverage by via a common
handle, kcov will collect coverage for each code section that is
annotated to use the common handle obtained as kcov_handle from the
current task_struct.  However non common handles allow to collect
coverage selectively from different subsystems.

Link: http://lkml.kernel.org/r/e90e315426a384207edbec1d6aa89e43008e4caf.1572366574.git.andreyknvl@google.com
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Alan Stern <stern@rowland.harvard.edu>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: David Windsor <dwindsor@gmail.com>
Cc: Elena Reshetova <elena.reshetova@intel.com>
Cc: Anders Roxell <anders.roxell@linaro.org>
Cc: Alexander Potapenko <glider@google.com>
Cc: Marco Elver <elver@google.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Andrey Konovalov <andreyknvl@google.com>
Bug: 147413187
Change-Id: I868c4846a412bfbae16086017e113813571df377
2020-01-15 14:51:23 +00:00
arch GKI: enable CONFIG_NETFILTER_XT_MATCH_QUOTA2_LOG=y 2020-01-15 02:11:28 +00:00
block BACKPORT: FROMLIST: Update Inline Encryption from v5 to v6 of patch series 2020-01-13 07:11:38 -08:00
certs export.h: remove VMLINUX_SYMBOL() and VMLINUX_SYMBOL_STR() 2018-08-22 23:21:44 +09:00
crypto This is the 4.19.89 stable release 2019-12-13 10:01:10 +01:00
Documentation UPSTREAM: kcov: remote coverage support 2020-01-15 14:51:23 +00:00
drivers This is the 4.19.96 stable release 2020-01-15 08:57:09 +01:00
firmware kbuild: remove all dummy assignments to obj- 2017-11-18 11:46:06 +09:00
fs This is the 4.19.96 stable release 2020-01-15 08:57:09 +01:00
include UPSTREAM: kcov: remote coverage support 2020-01-15 14:51:23 +00:00
init ANDROID: Kconfig.gki: Add Hidden SPRD DRM configs 2019-12-26 17:46:51 +00:00
ipc This is the 4.19.65 stable release 2019-08-06 20:08:18 +02:00
kernel UPSTREAM: kcov: remote coverage support 2020-01-15 14:51:23 +00:00
lib UPSTREAM: kcov: improve CONFIG_ARCH_HAS_KCOV help text 2020-01-15 14:51:12 +00:00
LICENSES LICENSES: Remove CC-BY-SA-4.0 license text 2018-10-18 11:28:50 +02:00
mm This is the 4.19.94 stable release 2020-01-09 16:14:43 +01:00
net This is the 4.19.96 stable release 2020-01-15 08:57:09 +01:00
samples samples: bpf: fix syscall_tp due to unused syscall 2020-01-12 12:17:13 +01:00
scripts This is the 4.19.95 stable release 2020-01-12 12:29:19 +01:00
security BACKPORT: perf_event: Add support for LSM and SELinux checks 2020-01-10 15:18:52 +00:00
sound This is the 4.19.96 stable release 2020-01-15 08:57:09 +01:00
tools This is the 4.19.95 stable release 2020-01-12 12:29:19 +01:00
usr kbuild: clean compressed initramfs image 2019-10-07 18:57:16 +02:00
virt KVM: arm/arm64: vgic: Don't rely on the wrong pending table 2019-12-13 08:52:45 +01:00
.clang-format clang-format: Set IndentWrappedFunctionNames false 2018-08-01 18:38:51 +02:00
.cocciconfig
.get_maintainer.ignore
.gitattributes .gitattributes: set git diff driver for C source code files 2016-10-07 18:46:30 -07:00
.gitignore Kbuild updates for v4.17 (2nd) 2018-04-15 17:21:30 -07:00
.mailmap libnvdimm-for-4.19_misc 2018-08-25 18:13:10 -07:00
abi_gki_aarch64.xml BACKPORT: FROMLIST: Update Inline Encryption from v5 to v6 of patch series 2020-01-13 07:11:38 -08:00
abi_gki_aarch64_whitelist ANDROID: add initial ABI whitelist for android-4.19 2019-12-18 12:44:33 +00:00
build.config.aarch64 ANDROID: refactor build.config files to remove duplication 2019-10-22 18:27:12 -07:00
build.config.allmodconfig ANDROID: Don't base allmodconfig on gki_defconfig 2019-12-05 12:48:26 +00:00
build.config.allmodconfig.aarch64 ANDROID: Add allmodconfig build.configs for x86_64 and aarch64 2019-11-12 20:55:23 +00:00
build.config.allmodconfig.x86_64 ANDROID: Add allmodconfig build.configs for x86_64 and aarch64 2019-11-12 20:55:23 +00:00
build.config.common ANDROID: clang: update to 10.0.1 2019-11-27 12:37:18 -08:00
build.config.gki ANDROID: refactor build.config files to remove duplication 2019-10-22 18:27:12 -07:00
build.config.gki.aarch64 ANDROID: add initial ABI whitelist for android-4.19 2019-12-18 12:44:33 +00:00
build.config.gki.x86_64 ANDROID: refactor build.config files to remove duplication 2019-10-22 18:27:12 -07:00
build.config.x86_64 ANDROID: refactor build.config files to remove duplication 2019-10-22 18:27:12 -07:00
COPYING COPYING: use the new text with points to the license files 2018-03-23 12:41:45 -06:00
CREDITS 9p: remove Ron Minnich from MAINTAINERS 2018-08-17 16:20:26 -07:00
Kbuild Kbuild updates for v4.15 2017-11-17 17:45:29 -08:00
Kconfig kconfig: move the "Executable file formats" menu to fs/Kconfig.binfmt 2018-08-02 08:06:55 +09:00
MAINTAINERS This is the 4.19.80 stable release 2019-10-17 15:33:07 -07:00
Makefile This is the 4.19.96 stable release 2020-01-15 08:57:09 +01:00
README Docs: Added a pointer to the formatted docs to README 2018-03-21 09:02:53 -06:00

Linux kernel
============

There are several guides for kernel developers and users. These guides can
be rendered in a number of formats, like HTML and PDF. Please read
Documentation/admin-guide/README.rst first.

In order to build the documentation, use ``make htmldocs`` or
``make pdfdocs``.  The formatted documentation can also be read online at:

    https://www.kernel.org/doc/html/latest/

There are various text files in the Documentation/ subdirectory,
several of them using the Restructured Text markup notation.
See Documentation/00-INDEX for a list of what is contained in each file.

Please read the Documentation/process/changes.rst file, as it contains the
requirements for building and running the kernel, and information about
the problems which may result by upgrading your kernel.