linux/include/linux/kcsan.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: GPL-2.0 */
   2/*
   3 * The Kernel Concurrency Sanitizer (KCSAN) infrastructure. Public interface and
   4 * data structures to set up runtime. See kcsan-checks.h for explicit checks and
   5 * modifiers. For more info please see Documentation/dev-tools/kcsan.rst.
   6 *
   7 * Copyright (C) 2019, Google LLC.
   8 */
   9
  10#ifndef _LINUX_KCSAN_H
  11#define _LINUX_KCSAN_H
  12
  13#include <linux/kcsan-checks.h>
  14#include <linux/types.h>
  15
  16#ifdef CONFIG_KCSAN
  17
  18/*
  19 * Context for each thread of execution: for tasks, this is stored in
  20 * task_struct, and interrupts access internal per-CPU storage.
  21 */
  22struct kcsan_ctx {
  23        int disable_count; /* disable counter */
  24        int atomic_next; /* number of following atomic ops */
  25
  26        /*
  27         * We distinguish between: (a) nestable atomic regions that may contain
  28         * other nestable regions; and (b) flat atomic regions that do not keep
  29         * track of nesting. Both (a) and (b) are entirely independent of each
  30         * other, and a flat region may be started in a nestable region or
  31         * vice-versa.
  32         *
  33         * This is required because, for example, in the annotations for
  34         * seqlocks, we declare seqlock writer critical sections as (a) nestable
  35         * atomic regions, but reader critical sections as (b) flat atomic
  36         * regions, but have encountered cases where seqlock reader critical
  37         * sections are contained within writer critical sections (the opposite
  38         * may be possible, too).
  39         *
  40         * To support these cases, we independently track the depth of nesting
  41         * for (a), and whether the leaf level is flat for (b).
  42         */
  43        int atomic_nest_count;
  44        bool in_flat_atomic;
  45
  46        /*
  47         * Access mask for all accesses if non-zero.
  48         */
  49        unsigned long access_mask;
  50
  51        /* List of scoped accesses. */
  52        struct list_head scoped_accesses;
  53};
  54
  55/**
  56 * kcsan_init - initialize KCSAN runtime
  57 */
  58void kcsan_init(void);
  59
  60#else /* CONFIG_KCSAN */
  61
  62static inline void kcsan_init(void)                     { }
  63
  64#endif /* CONFIG_KCSAN */
  65
  66#endif /* _LINUX_KCSAN_H */
  67