projects/linux·commit 4ff261e7

Merge tag 'trace-rv-6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace

4ff261e7 · Linus Torvalds <[email protected]> · 2025-07-30 16:23:12 -07:00

Pull runtime verification updates from Steven Rostedt:

 - Added Linear temporal logic monitors for RT application

   Real-time applications may have design flaws causing them to have
   unexpected latency. For example, the applications may raise page
   faults, or may be blocked trying to take a mutex without priority
   inheritance.

   However, while attempting to implement DA monitors for these
   real-time rules, deterministic automaton is found to be inappropriate
   as the specification language. The automaton is complicated, hard to
   understand, and error-prone.

   For these cases, linear temporal logic is found to be more suitable.
   The LTL is more concise and intuitive.

 - Make printk_deferred() public

   The new monitors needed access to printk_deferred(). Make them
   visible for the entire kernel.

 - Add a vpanic() to allow for va_list to be passed to panic.

 - Add rtapp container monitor.

   A collection of monitors that check for common problems with
   real-time applications that cause unexpected latency.

 - Add page fault tracepoints to risc-v

   These tracepoints are necessary to for the RV monitor to run on
   risc-v.

 - Fix the behaviour of the rv tool with -s and idle tasks.

 - Allow the rv tool to gracefully terminate with SIGTERM

 - Adjusts dot2c not to create lines over 100 columns

 - Properly order nested monitors in the RV Kconfig file

 - Return the registration error in all DA monitor instead of 0

 - Update and add new sched collection monitors

   Replace tss and sncid monitors with more complete sts:

   Not only prove that switches occur in scheduling context and scheduling
   needs interrupt disabled but also that each call to the scheduler
   disables interrupts to (optionally) switch.

   New monitor: nrp
     Preemption requires need resched which is cleared by any switch
     (includes a non optimal workaround for /nested/ preemptions)

   New monitor: sssw
     suspension requires setting the task to sleepable and, after the
     switch occurs, the task requires a wakeup to come back to runnable

   New monitor: opid
      waking and need-resched operations occur with interrupts and
      preemption disabled or in IRQ without explicitly disabling
      preemption"

* tag 'trace-rv-6.17' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: (48 commits)
  rv: Add opid per-cpu monitor
  rv: Add nrp and sssw per-task monitors
  rv: Replace tss and sncid monitors with more complete sts
  sched: Adapt sched tracepoints for RV task model
  rv: Retry when da monitor detects race conditions
  rv: Adjust monitor dependencies
  rv: Use strings in da monitors tracepoints
  rv: Remove trailing whitespace from tracepoint string
  rv: Add da_handle_start_run_event_ to per-task monitors
  rv: Fix wrong type cast in reactors_show() and monitor_reactor_show()
  rv: Fix wrong type cast in monitors_show()
  rv: Remove struct rv_monitor::reacting
  rv: Remove rv_reactor's reference counter
  rv: Merge struct rv_reactor_def into struct rv_reactor
  rv: Merge struct rv_monitor_def into struct rv_monitor
  rv: Remove unused field in struct rv_monitor_def
  rv: Return init error when registering monitors
  verification/rvgen: Organise Kconfig entries for nested monitors
  tools/dot2c: Fix generated files going over 100 column limit
  tools/rv: Stop gracefully also on SIGTERM
  ...
Commit
4ff261e725d7376c12e745fdbe8a33cd6dbd5a83
Parents
d50b07d0 · 61438453

Merge commit. Changes below are compared with the first parent: d50b07d0.

Changes

99 files changed · +4880 −1285

FileStatusAddDelContent
Documentation/trace/rv/index.rstmodified+3−1View file
Documentation/trace/rv/linear_temporal_logic.rstadded+134−0View file
Documentation/trace/rv/monitor_rtapp.rstadded+133−0View file
Documentation/trace/rv/monitor_sched.rstmodified+269−38View file
Documentation/trace/rv/da_monitor_synthesis.rst → Documentation/trace/rv/monitor_synthesis.rstrenamed+148−24View file
arch/riscv/mm/fault.cmodified+8−0View file
include/linux/panic.hmodified+3−0View file
include/linux/printk.hmodified+7−0View file
include/linux/rv.hmodified+74−12View file
include/linux/sched.hmodified+9−6View file
include/rv/da_monitor.hmodified+86−86View file
include/rv/ltl_monitor.hadded+186−0View file
include/trace/events/sched.hmodified+8−4View file
kernel/fork.cmodified+1−4View file
kernel/panic.cmodified+13−5View file
kernel/printk/internal.hmodified+0−1View file
kernel/sched/core.cmodified+10−3View file
kernel/trace/rv/Kconfigmodified+37−6View file
kernel/trace/rv/Makefilemodified+7−2View file
kernel/trace/rv/monitors/nrp/Kconfigadded+16−0View file
kernel/trace/rv/monitors/nrp/nrp.cadded+138−0View file
kernel/trace/rv/monitors/nrp/nrp.hadded+75−0View file
kernel/trace/rv/monitors/nrp/nrp_trace.hadded+15−0View file
kernel/trace/rv/monitors/opid/Kconfigadded+19−0View file
kernel/trace/rv/monitors/opid/opid.cadded+168−0View file
kernel/trace/rv/monitors/opid/opid.hadded+104−0View file
kernel/trace/rv/monitors/sncid/sncid_trace.h → kernel/trace/rv/monitors/opid/opid_trace.hrenamed+4−4View file
kernel/trace/rv/monitors/pagefault/Kconfigadded+20−0View file
kernel/trace/rv/monitors/pagefault/pagefault.cadded+88−0View file
kernel/trace/rv/monitors/pagefault/pagefault.hadded+64−0View file
kernel/trace/rv/monitors/pagefault/pagefault_trace.hadded+14−0View file
kernel/trace/rv/monitors/rtapp/Kconfigadded+11−0View file
kernel/trace/rv/monitors/rtapp/rtapp.cadded+33−0View file
kernel/trace/rv/monitors/rtapp/rtapp.hadded+3−0View file
kernel/trace/rv/monitors/sched/Kconfigmodified+1−0View file
kernel/trace/rv/monitors/sched/sched.cmodified+1−2View file
kernel/trace/rv/monitors/sco/sco.cmodified+3−4View file
kernel/trace/rv/monitors/scpd/Kconfigmodified+1−1View file
kernel/trace/rv/monitors/scpd/scpd.cmodified+3−4View file
kernel/trace/rv/monitors/sleep/Kconfigadded+22−0View file
kernel/trace/rv/monitors/sleep/sleep.cadded+237−0View file
kernel/trace/rv/monitors/sleep/sleep.hadded+257−0View file
kernel/trace/rv/monitors/sleep/sleep_trace.hadded+14−0View file
kernel/trace/rv/monitors/sncid/sncid.cdeleted+0−96View before deletion
kernel/trace/rv/monitors/sncid/sncid.hdeleted+0−49View before deletion
kernel/trace/rv/monitors/snep/Kconfigmodified+1−1View file
kernel/trace/rv/monitors/snep/snep.cmodified+3−4View file
kernel/trace/rv/monitors/snep/snep.hmodified+12−2View file
kernel/trace/rv/monitors/snroc/snroc.cmodified+1−2View file
kernel/trace/rv/monitors/tss/Kconfig → kernel/trace/rv/monitors/sssw/Kconfigrenamed+5−4View file
kernel/trace/rv/monitors/sssw/sssw.cadded+116−0View file
kernel/trace/rv/monitors/sssw/sssw.hadded+105−0View file
kernel/trace/rv/monitors/sssw/sssw_trace.hadded+15−0View file
kernel/trace/rv/monitors/sncid/Kconfig → kernel/trace/rv/monitors/sts/Kconfigrenamed+8−4View file
kernel/trace/rv/monitors/sts/sts.cadded+156−0View file
kernel/trace/rv/monitors/sts/sts.hadded+117−0View file
kernel/trace/rv/monitors/tss/tss_trace.h → kernel/trace/rv/monitors/sts/sts_trace.hrenamed+4−4View file
kernel/trace/rv/monitors/tss/tss.cdeleted+0−91View before deletion
kernel/trace/rv/monitors/tss/tss.hdeleted+0−47View before deletion
kernel/trace/rv/monitors/wip/Kconfigmodified+1−1View file
kernel/trace/rv/monitors/wip/wip.cmodified+1−2View file
kernel/trace/rv/monitors/wwnr/wwnr.cmodified+1−2View file
kernel/trace/rv/reactor_panic.cmodified+6−2View file
kernel/trace/rv/reactor_printk.cmodified+6−2View file
kernel/trace/rv/rv.cmodified+97−123View file
kernel/trace/rv/rv.hmodified+6−33View file
kernel/trace/rv/rv_reactors.cmodified+43−95View file
kernel/trace/rv/rv_trace.hmodified+121−45View file
tools/objtool/noreturns.hmodified+1−0View file
tools/verification/dot2/dot2k.pydeleted+0−389View before deletion
tools/verification/models/rtapp/pagefault.ltladded+1−0View file
tools/verification/models/rtapp/sleep.ltladded+22−0View file
tools/verification/models/sched/nrp.dotadded+29−0View file
tools/verification/models/sched/opid.dotadded+35−0View file
tools/verification/models/sched/sncid.dotdeleted+0−18View before deletion
tools/verification/models/sched/sssw.dotadded+30−0View file
tools/verification/models/sched/sts.dotadded+38−0View file
tools/verification/models/sched/tss.dotdeleted+0−18View before deletion
tools/verification/rv/src/in_kernel.cmodified+2−2View file
tools/verification/rv/src/rv.cmodified+1−0View file
tools/verification/rvgen/.gitignoreadded+3−0View file
tools/verification/dot2/Makefile → tools/verification/rvgen/Makefilerenamed+9−8View file
tools/verification/dot2/dot2k → tools/verification/rvgen/__main__.pyrenamed+33−19View file
tools/verification/dot2/dot2c → tools/verification/rvgen/dot2crenamed+1−1View file
tools/verification/dot2/automata.py → tools/verification/rvgen/rvgen/automata.pyrenamed+0−0View file
tools/verification/rvgen/rvgen/container.pyadded+32−0View file
tools/verification/dot2/dot2c.py → tools/verification/rvgen/rvgen/dot2c.pyrenamed+12−10View file
tools/verification/rvgen/rvgen/dot2k.pyadded+129−0View file
tools/verification/rvgen/rvgen/generator.pyadded+270−0View file
tools/verification/rvgen/rvgen/ltl2ba.pyadded+566−0View file
tools/verification/rvgen/rvgen/ltl2k.pyadded+271−0View file
tools/verification/dot2/dot2k_templates/Kconfig → tools/verification/rvgen/rvgen/templates/Kconfigrenamed+0−0View file
tools/verification/rvgen/rvgen/templates/container/Kconfigadded+5−0View file
tools/verification/dot2/dot2k_templates/main_container.c → tools/verification/rvgen/rvgen/templates/container/main.crenamed+1−2View file
tools/verification/dot2/dot2k_templates/main_container.h → tools/verification/rvgen/rvgen/templates/container/main.hrenamed+0−0View file
tools/verification/dot2/dot2k_templates/main.c → tools/verification/rvgen/rvgen/templates/dot2k/main.crenamed+1−2View file
tools/verification/dot2/dot2k_templates/trace.h → tools/verification/rvgen/rvgen/templates/dot2k/trace.hrenamed+0−0View file
tools/verification/rvgen/rvgen/templates/ltl2k/main.cadded+102−0View file
tools/verification/rvgen/rvgen/templates/ltl2k/trace.hadded+14−0View file

Only the first 600 diff lines are shown. Download the complete patch.

Documentation/trace/rv/index.rst

View file
diff --git a/Documentation/trace/rv/index.rst b/Documentation/trace/rv/index.rst
index e80e005..a2812ac 100644
--- a/Documentation/trace/rv/index.rst
+++ b/Documentation/trace/rv/index.rst
@@ -8,8 +8,10 @@ Runtime Verification
runtime-verification.rst
deterministic_automata.rst
- da_monitor_synthesis.rst
+ linear_temporal_logic.rst
+ monitor_synthesis.rst
da_monitor_instrumentation.rst
monitor_wip.rst
monitor_wwnr.rst
monitor_sched.rst
+ monitor_rtapp.rst

Documentation/trace/rv/linear_temporal_logic.rst

View file
diff --git a/Documentation/trace/rv/linear_temporal_logic.rst b/Documentation/trace/rv/linear_temporal_logic.rst
new file mode 100644
index 0000000..9eee09d
--- /dev/null
+++ b/Documentation/trace/rv/linear_temporal_logic.rst
@@ -0,0 +1,134 @@
+Linear temporal logic
+=====================
+
+Introduction
+------------
+
+Runtime verification monitor is a verification technique which checks that the
+kernel follows a specification. It does so by using tracepoints to monitor the
+kernel's execution trace, and verifying that the execution trace sastifies the
+specification.
+
+Initially, the specification can only be written in the form of deterministic
+automaton (DA). However, while attempting to implement DA monitors for some
+complex specifications, deterministic automaton is found to be inappropriate as
+the specification language. The automaton is complicated, hard to understand,
+and error-prone.
+
+Thus, RV monitors based on linear temporal logic (LTL) are introduced. This type
+of monitor uses LTL as specification instead of DA. For some cases, writing the
+specification as LTL is more concise and intuitive.
+
+Many materials explain LTL in details. One book is::
+
+ Christel Baier and Joost-Pieter Katoen: Principles of Model Checking, The MIT
+ Press, 2008.
+
+Grammar
+-------
+
+Unlike some existing syntax, kernel's implementation of LTL is more verbose.
+This is motivated by considering that the people who read the LTL specifications
+may not be well-versed in LTL.
+
+Grammar:
+ ltl ::= opd | ( ltl ) | ltl binop ltl | unop ltl
+
+Operands (opd):
+ true, false, user-defined names consisting of upper-case characters, digits,
+ and underscore.
+
+Unary Operators (unop):
+ always
+ eventually
+ next
+ not
+
+Binary Operators (binop):
+ until
+ and
+ or
+ imply
+ equivalent
+
+This grammar is ambiguous: operator precedence is not defined. Parentheses must
+be used.
+
+Example linear temporal logic
+-----------------------------
+.. code-block::
+
+ RAIN imply (GO_OUTSIDE imply HAVE_UMBRELLA)
+
+means: if it is raining, going outside means having an umbrella.
+
+.. code-block::
+
+ RAIN imply (WET until not RAIN)
+
+means: if it is raining, it is going to be wet until the rain stops.
+
+.. code-block::
+
+ RAIN imply eventually not RAIN
+
+means: if it is raining, rain will eventually stop.
+
+The above examples are referring to the current time instance only. For kernel
+verification, the `always` operator is usually desirable, to specify that
+something is always true at the present and for all future. For example::
+
+ always (RAIN imply eventually not RAIN)
+
+means: *all* rain eventually stops.
+
+In the above examples, `RAIN`, `GO_OUTSIDE`, `HAVE_UMBRELLA` and `WET` are the
+"atomic propositions".
+
+Monitor synthesis
+-----------------
+
+To synthesize an LTL into a kernel monitor, the `rvgen` tool can be used:
+`tools/verification/rvgen`. The specification needs to be provided as a file,
+and it must have a "RULE = LTL" assignment. For example::
+
+ RULE = always (ACQUIRE imply ((not KILLED and not CRASHED) until RELEASE))
+
+which says: if `ACQUIRE`, then `RELEASE` must happen before `KILLED` or
+`CRASHED`.
+
+The LTL can be broken down using sub-expressions. The above is equivalent to:
+
+ .. code-block::
+
+ RULE = always (ACQUIRE imply (ALIVE until RELEASE))
+ ALIVE = not KILLED and not CRASHED
+
+From this specification, `rvgen` generates the C implementation of a Buchi
+automaton - a non-deterministic state machine which checks the satisfiability of
+the LTL. See Documentation/trace/rv/monitor_synthesis.rst for details on using
+`rvgen`.
+
+References
+----------
+
+One book covering model checking and linear temporal logic is::
+
+ Christel Baier and Joost-Pieter Katoen: Principles of Model Checking, The MIT
+ Press, 2008.
+
+For an example of using linear temporal logic in software testing, see::
+
+ Ruijie Meng, Zhen Dong, Jialin Li, Ivan Beschastnikh, and Abhik Roychoudhury.
+ 2022. Linear-time temporal logic guided greybox fuzzing. In Proceedings of the
+ 44th International Conference on Software Engineering (ICSE '22). Association
+ for Computing Machinery, New York, NY, USA, 1343–1355.
+ https://doi.org/10.1145/3510003.3510082
+
+The kernel's LTL monitor implementation is based on::
+
+ Gerth, R., Peled, D., Vardi, M.Y., Wolper, P. (1996). Simple On-the-fly
+ Automatic Verification of Linear Temporal Logic. In: Dembiński, P., Średniawa,
+ M. (eds) Protocol Specification, Testing and Verification XV. PSTV 1995. IFIP
+ Advances in Information and Communication Technology. Springer, Boston, MA.
+ https://doi.org/10.1007/978-0-387-34892-6_1

Documentation/trace/rv/monitor_rtapp.rst

View file
diff --git a/Documentation/trace/rv/monitor_rtapp.rst b/Documentation/trace/rv/monitor_rtapp.rst
new file mode 100644
index 0000000..c8104ed
--- /dev/null
+++ b/Documentation/trace/rv/monitor_rtapp.rst
@@ -0,0 +1,133 @@
+Real-time application monitors
+==============================
+
+- Name: rtapp
+- Type: container for multiple monitors
+- Author: Nam Cao <[email protected]>
+
+Description
+-----------
+
+Real-time applications may have design flaws such that they experience
+unexpected latency and fail to meet their time requirements. Often, these flaws
+follow a few patterns:
+
+ - Page faults: A real-time thread may access memory that does not have a
+ mapped physical backing or must first be copied (such as for copy-on-write).
+ Thus a page fault is raised and the kernel must first perform the expensive
+ action. This causes significant delays to the real-time thread
+ - Priority inversion: A real-time thread blocks waiting for a lower-priority
+ thread. This causes the real-time thread to effectively take on the
+ scheduling priority of the lower-priority thread. For example, the real-time
+ thread needs to access a shared resource that is protected by a
+ non-pi-mutex, but the mutex is currently owned by a non-real-time thread.
+
+The `rtapp` monitor detects these patterns. It aids developers to identify
+reasons for unexpected latency with real-time applications. It is a container of
+multiple sub-monitors described in the following sections.
+
+Monitor pagefault
++++++++++++++++++
+
+The `pagefault` monitor reports real-time tasks raising page faults. Its
+specification is::
+
+ RULE = always (RT imply not PAGEFAULT)
+
+To fix warnings reported by this monitor, `mlockall()` or `mlock()` can be used
+to ensure physical backing for memory.
+
+This monitor may have false negatives because the pages used by the real-time
+threads may just happen to be directly available during testing. To minimize
+this, the system can be put under memory pressure (e.g. invoking the OOM killer
+using a program that does `ptr = malloc(SIZE_OF_RAM); memset(ptr, 0,
+SIZE_OF_RAM);`) so that the kernel executes aggressive strategies to recycle as
+much physical memory as possible.
+
+Monitor sleep
++++++++++++++
+
+The `sleep` monitor reports real-time threads sleeping in a manner that may
+cause undesirable latency. Real-time applications should only put a real-time
+thread to sleep for one of the following reasons:
+
+ - Cyclic work: real-time thread sleeps waiting for the next cycle. For this
+ case, only the `clock_nanosleep` syscall should be used with `TIMER_ABSTIME`
+ (to avoid time drift) and `CLOCK_MONOTONIC` (to avoid the clock being
+ changed). No other method is safe for real-time. For example, threads
+ waiting for timerfd can be woken by softirq which provides no real-time
+ guarantee.
+ - Real-time thread waiting for something to happen (e.g. another thread
+ releasing shared resources, or a completion signal from another thread). In
+ this case, only futexes (FUTEX_LOCK_PI, FUTEX_LOCK_PI2 or one of
+ FUTEX_WAIT_*) should be used. Applications usually do not use futexes
+ directly, but use PI mutexes and PI condition variables which are built on
+ top of futexes. Be aware that the C library might not implement conditional
+ variables as safe for real-time. As an alternative, the librtpi library
+ exists to provide a conditional variable implementation that is correct for
+ real-time applications in Linux.
+
+Beside the reason for sleeping, the eventual waker should also be
+real-time-safe. Namely, one of:
+
+ - An equal-or-higher-priority thread
+ - Hard interrupt handler
+ - Non-maskable interrupt handler
+
+This monitor's warning usually means one of the following:
+
+ - Real-time thread is blocked by a non-real-time thread (e.g. due to
+ contention on a mutex without priority inheritance). This is priority
+ inversion.
+ - Time-critical work waits for something which is not safe for real-time (e.g.
+ timerfd).
+ - The work executed by the real-time thread does not need to run at real-time
+ priority at all. This is not a problem for the real-time thread itself, but
+ it is potentially taking the CPU away from other important real-time work.
+
+Application developers may purposely choose to have their real-time application
+sleep in a way that is not safe for real-time. It is debatable whether that is a
+problem. Application developers must analyze the warnings to make a proper
+assessment.
+
+The monitor's specification is::
+
+ RULE = always ((RT and SLEEP) imply (RT_FRIENDLY_SLEEP or ALLOWLIST))
+
+ RT_FRIENDLY_SLEEP = (RT_VALID_SLEEP_REASON or KERNEL_THREAD)
+ and ((not WAKE) until RT_FRIENDLY_WAKE)
+
+ RT_VALID_SLEEP_REASON = FUTEX_WAIT
+ or RT_FRIENDLY_NANOSLEEP
+
+ RT_FRIENDLY_NANOSLEEP = CLOCK_NANOSLEEP
+ and NANOSLEEP_TIMER_ABSTIME
+ and NANOSLEEP_CLOCK_MONOTONIC
+
+ RT_FRIENDLY_WAKE = WOKEN_BY_EQUAL_OR_HIGHER_PRIO
+ or WOKEN_BY_HARDIRQ
+ or WOKEN_BY_NMI
+ or KTHREAD_SHOULD_STOP
+
+ ALLOWLIST = BLOCK_ON_RT_MUTEX
+ or FUTEX_LOCK_PI
+ or TASK_IS_RCU
+ or TASK_IS_MIGRATION
+
+Beside the scenarios described above, this specification also handle some
+special cases:
+
+ - `KERNEL_THREAD`: kernel tasks do not have any pattern that can be recognized
+ as valid real-time sleeping reasons. Therefore sleeping reason is not
+ checked for kernel tasks.
+ - `KTHREAD_SHOULD_STOP`: a non-real-time thread may stop a real-time kernel
+ thread by waking it and waiting for it to exit (`kthread_stop()`). This
+ wakeup is safe for real-time.
+ - `ALLOWLIST`: to handle known false positives with the kernel.
+ - `BLOCK_ON_RT_MUTEX` is included in the allowlist due to its implementation.
+ In the release path of rt_mutex, a boosted task is de-boosted before waking
+ the rt_mutex's waiter. Consequently, the monitor may see a real-time-unsafe
+ wakeup (e.g. non-real-time task waking real-time task). This is actually
+ real-time-safe because preemption is disabled for the duration.
+ - `FUTEX_LOCK_PI` is included in the allowlist for the same reason as
+ `BLOCK_ON_RT_MUTEX`.

Documentation/trace/rv/monitor_sched.rst

View file
diff --git a/Documentation/trace/rv/monitor_sched.rst b/Documentation/trace/rv/monitor_sched.rst
index 24b2c62..3f8381a 100644
--- a/Documentation/trace/rv/monitor_sched.rst
+++ b/Documentation/trace/rv/monitor_sched.rst
@@ -40,26 +40,6 @@ defined in by Daniel Bristot in [1].
Currently we included the following:
-Monitor tss
-~~~~~~~~~~~
-
-The task switch while scheduling (tss) monitor ensures a task switch happens
-only in scheduling context, that is inside a call to `__schedule`::
-
- |
- |
- v
- +-----------------+
- | thread | <+
- +-----------------+ |
- | |
- | schedule_entry | schedule_exit
- v |
- sched_switch |
- +--------------- |
- | sched |
- +--------------> -+
-
Monitor sco
~~~~~~~~~~~
@@ -144,26 +124,277 @@ does not enable preemption::
|
scheduling_contex -+
-Monitor sncid
-~~~~~~~~~~~~~
+Monitor sts
+~~~~~~~~~~~
-The schedule not called with interrupt disabled (sncid) monitor ensures
-schedule is not called with interrupt disabled::
+The schedule implies task switch (sts) monitor ensures a task switch happens
+only in scheduling context and up to once, as well as scheduling occurs with
+interrupts enabled but no task switch can happen before interrupts are
+disabled. When the next task picked for execution is the same as the previously
+running one, no real task switch occurs but interrupts are disabled nonetheless::
- |
- |
- v
- schedule_entry +--------------+
- schedule_exit | |
- +----------------- | can_sched |
- | | |
- +----------------> | | <+
- +--------------+ |
- | |
- | irq_disable | irq_enable
- v |
- |
- cant_sched -+
+ irq_entry |
+ +----+ |
+ v | v
+ +------------+ irq_enable #===================# irq_disable
+ | | ------------> H H irq_entry
+ | cant_sched | <------------ H H irq_enable
+ | | irq_disable H can_sched H --------------+
+ +------------+ H H |
+ H H |
+ +---------------> H H <-------------+
+ | #===================#
+ | |
+ schedule_exit | schedule_entry
+ | v
+ | +-------------------+ irq_enable
+ | | scheduling | <---------------+
+ | +-------------------+ |
+ | | |
+ | | irq_disable +--------+ irq_entry
+ | v | | --------+
+ | +-------------------+ irq_entry | in_irq | |
+ | | | -----------> | | <-------+
+ | | disable_to_switch | +--------+
+ | | | --+
+ | +-------------------+ |
+ | | |
+ | | sched_switch |
+ | v |
+ | +-------------------+ |
+ | | switching | | irq_enable
+ | +-------------------+ |
+ | | |
+ | | irq_enable |
+ | v |
+ | +-------------------+ |
+ +-- | enable_to_exit | <-+
+ +-------------------+
+ ^ | irq_disable
+ | | irq_entry
+ +---------------+ irq_enable
+
+Monitor nrp
+-----------
+
+The need resched preempts (nrp) monitor ensures preemption requires
+``need_resched``. Only kernel preemption is considered, since preemption
+while returning to userspace, for this monitor, is indistinguishable from
+``sched_switch_yield`` (described in the sssw monitor).
+A kernel preemption is whenever ``__schedule`` is called with the preemption
+flag set to true (e.g. from preempt_enable or exiting from interrupts). This
+type of preemption occurs after the need for ``rescheduling`` has been set.
+This is not valid for the *lazy* variant of the flag, which causes only
+userspace preemption.
+A ``schedule_entry_preempt`` may involve a task switch or not, in the latter
+case, a task goes through the scheduler from a preemption context but it is
+picked as the next task to run. Since the scheduler runs, this clears the need
+to reschedule. The ``any_thread_running`` state does not imply the monitored
+task is not running as this monitor does not track the outcome of scheduling.
+
+In theory, a preemption can only occur after the ``need_resched`` flag is set. In
+practice, however, it is possible to see a preemption where the flag is not
+set. This can happen in one specific condition::
+
+ need_resched
+ preempt_schedule()
+ preempt_schedule_irq()
+ __schedule()
+ !need_resched
+ __schedule()
+
+In the situation above, standard preemption starts (e.g. from preempt_enable
+when the flag is set), an interrupt occurs before scheduling and, on its exit
+path, it schedules, which clears the ``need_resched`` flag.
+When the preempted task runs again, the standard preemption started earlier
+resumes, although the flag is no longer set. The monitor considers this a
+``nested_preemption``, this allows another preemption without re-setting the
+flag. This condition relaxes the monitor constraints and may catch false
+negatives (i.e. no real ``nested_preemptions``) but makes the monitor more
+robust and able to validate other scenarios.
+For simplicity, the monitor starts in ``preempt_irq``, although no interrupt
+occurred, as the situation above is hard to pinpoint::
+
+ schedule_entry
+ irq_entry #===========================================#
+ +-------------------------- H H
+ | H H
+ +-------------------------> H any_thread_running H
+ H H
+ +-------------------------> H H
+ | #===========================================#
+ | schedule_entry | ^
+ | schedule_entry_preempt | sched_need_resched | schedule_entry
+ | | schedule_entry_preempt
+ | v |
+ | +----------------------+ |
+ | +--- | | |
+ | sched_need_resched | | rescheduling | -+
+ | +--> | |
+ | +----------------------+
+ | | irq_entry
+ | v
+ | +----------------------+
+ | | | ---+
+ | ---> | | | sched_need_resched
+ | | preempt_irq | | irq_entry
+ | | | <--+
+ | | | <--+
+ | +----------------------+ |
+ | | schedule_entry | sched_need_resched
+ | | schedule_entry_preempt |
+ | v |
+ | +-----------------------+ |
+ +-------------------------- | nested_preempt | --+
+ +-----------------------+
+ ^ irq_entry |
+ +-------------------+
+
+Due to how the ``need_resched`` flag on the preemption count works on arm64,
+this monitor is unstable on that architecture, as it often records preemption
+when the flag is not set, even in presence of the workaround above.
+For the time being, the monitor is disabled by default on arm64.
+
+Monitor sssw
+------------
+
+The set state sleep and wakeup (sssw) monitor ensures ``set_state`` to
+sleepable leads to sleeping and sleeping tasks require wakeup. It includes the
+following types of switch:
+
+* ``switch_suspend``:
+ a task puts itself to sleep, this can happen only after explicitly setting
+ the task to ``sleepable``. After a task is suspended, it needs to be woken up
+ (``waking`` state) before being switched in again.
+ Setting the task's state to ``sleepable`` can be reverted before switching if it
+ is woken up or set to ``runnable``.
+* ``switch_blocking``:
+ a special case of a ``switch_suspend`` where the task is waiting on a
+ sleeping RT lock (``PREEMPT_RT`` only), it is common to see wakeup and set
+ state events racing with each other and this leads the model to perceive this
+ type of switch when the task is not set to sleepable. This is a limitation of
+ the model in SMP system and workarounds may slow down the system.
+* ``switch_preempt``:
+ a task switch as a result of kernel preemption (``schedule_entry_preempt`` in
+ the nrp model).
+* ``switch_yield``:
+ a task explicitly calls the scheduler or is preempted while returning to
+ userspace. It can happen after a ``yield`` system call, from the idle task or
+ if the ``need_resched`` flag is set. By definition, a task cannot yield while
+ ``sleepable`` as that would be a suspension. A special case of a yield occurs
+ when a task in ``TASK_INTERRUPTIBLE`` calls the scheduler while a signal is
+ pending. The task doesn't go through the usual blocking/waking and is set
+ back to runnable, the resulting switch (if there) looks like a yield to the
+ ``signal_wakeup`` state and is followed by the signal delivery. From this
+ state, the monitor expects a signal even if it sees a wakeup event, although
+ not necessary, to rule out false negatives.
+
+This monitor doesn't include a running state, ``sleepable`` and ``runnable``
+are only referring to the task's desired state, which could be scheduled out
+(e.g. due to preemption). However, it does include the event
+``sched_switch_in`` to represent when a task is allowed to become running. This
+can be triggered also by preemption, but cannot occur after the task got to
+``sleeping`` before a ``wakeup`` occurs::
+
+ +--------------------------------------------------------------------------+
+ | |
+ | |
+ | switch_suspend | |
+ | switch_blocking | |
+ v v |
+ +----------+ #==========================# set_state_runnable |
+ | | H H wakeup |
+ | | H H switch_in |
+ | | H H switch_yield |
+ | sleeping | H H switch_preempt |
+ | | H H signal_deliver |
+ | | switch_ H H ------+ |
+ | | _blocking H runnable H | |
+ | | <----------- H H <-----+ |
+ +----------+ H H |
+ | wakeup H H |
+ +---------------------> H H |
+ H H |
+ +---------> H H |
+ | #==========================# |
+ | | ^ |
+ | | | set_state_runnable |
+ | | | wakeup |
+ | set_state_sleepable | +------------------------+
+ | v | |
+ | +--------------------------+ set_state_sleepable
+ | | | switch_in
+ | | | switch_preempt
+ signal_deliver | sleepable | signal_deliver
+ | | | ------+
+ | | | |
+ | | | <-----+
+ | +--------------------------+
+ | | ^
+ | switch_yield | set_state_sleepable
+ | v |
+ | +---------------+ |
+ +---------- | signal_wakeup | -+
+ +---------------+
+ ^ | switch_in
+ | | switch_preempt
+ | | switch_yield
+ +-----------+ wakeup
+
+Monitor opid
+------------
+
+The operations with preemption and irq disabled (opid) monitor ensures
+operations like ``wakeup`` and ``need_resched`` occur with interrupts and
+preemption disabled or during interrupt context, in such case preemption may
+not be disabled explicitly.
+``need_resched`` can be set by some RCU internals functions, in which case it
+doesn't match a task wakeup and might occur with only interrupts disabled::
+
+ | sched_need_resched
+ | sched_waking
+ | irq_entry
+ | +--------------------+
+ v v |
+ +------------------------------------------------------+
+ +----------- | disabled | <+
+ | +------------------------------------------------------+ |
+ | | ^ |
+ | | preempt_disable sched_need_resched |
+ | preempt_enable | +--------------------+ |
+ | v | v | |
+ | +------------------------------------------------------+ |
+ | | irq_disabled | |
+ | +------------------------------------------------------+ |
+ | | | ^ |
+ | irq_entry irq_entry | | |
+ | sched_need_resched v | irq_disable |
+ | sched_waking +--------------+ | | |
+ | +----- | | irq_enable | |
+ | | | in_irq | | | |
+ | +----> | | | | |
+ | +--------------+ | | irq_disable
+ | | | | |
+ | irq_enable | irq_enable | | |

This diff is incomplete. Download the complete patch.

Documentation/trace/rv/monitor_synthesis.rst

View file

This diff is incomplete. Download the complete patch.

arch/riscv/mm/fault.c

View file

This diff is incomplete. Download the complete patch.

include/linux/panic.h

View file

This diff is incomplete. Download the complete patch.

include/linux/printk.h

View file

This diff is incomplete. Download the complete patch.

include/linux/rv.h

View file

This diff is incomplete. Download the complete patch.

include/linux/sched.h

View file

This diff is incomplete. Download the complete patch.

include/rv/da_monitor.h

View file

This diff is incomplete. Download the complete patch.

include/rv/ltl_monitor.h

View file

This diff is incomplete. Download the complete patch.

include/trace/events/sched.h

View file

This diff is incomplete. Download the complete patch.

kernel/fork.c

View file

This diff is incomplete. Download the complete patch.

kernel/panic.c

View file

This diff is incomplete. Download the complete patch.

kernel/printk/internal.h

View file

This diff is incomplete. Download the complete patch.

kernel/sched/core.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/Kconfig

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/Makefile

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/nrp/Kconfig

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/nrp/nrp.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/nrp/nrp.h

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/nrp/nrp_trace.h

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/opid/Kconfig

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/opid/opid.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/opid/opid.h

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/opid/opid_trace.h

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/pagefault/Kconfig

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/pagefault/pagefault.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/pagefault/pagefault.h

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/pagefault/pagefault_trace.h

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/rtapp/Kconfig

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/rtapp/rtapp.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/rtapp/rtapp.h

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sched/Kconfig

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sched/sched.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sco/sco.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/scpd/Kconfig

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/scpd/scpd.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sleep/Kconfig

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sleep/sleep.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sleep/sleep.h

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sleep/sleep_trace.h

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sncid/sncid.c

View before deletion

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sncid/sncid.h

View before deletion

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/snep/Kconfig

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/snep/snep.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/snep/snep.h

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/snroc/snroc.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sssw/Kconfig

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sssw/sssw.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sssw/sssw.h

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sssw/sssw_trace.h

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sts/Kconfig

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sts/sts.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sts/sts.h

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/sts/sts_trace.h

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/tss/tss.c

View before deletion

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/tss/tss.h

View before deletion

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/wip/Kconfig

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/wip/wip.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/monitors/wwnr/wwnr.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/reactor_panic.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/reactor_printk.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/rv.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/rv.h

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/rv_reactors.c

View file

This diff is incomplete. Download the complete patch.

kernel/trace/rv/rv_trace.h

View file

This diff is incomplete. Download the complete patch.

tools/objtool/noreturns.h

View file

This diff is incomplete. Download the complete patch.

tools/verification/dot2/dot2k.py

View before deletion

This diff is incomplete. Download the complete patch.

tools/verification/models/rtapp/pagefault.ltl

View file

This diff is incomplete. Download the complete patch.

tools/verification/models/rtapp/sleep.ltl

View file

This diff is incomplete. Download the complete patch.

tools/verification/models/sched/nrp.dot

View file

This diff is incomplete. Download the complete patch.

tools/verification/models/sched/opid.dot

View file

This diff is incomplete. Download the complete patch.

tools/verification/models/sched/sncid.dot

View before deletion

This diff is incomplete. Download the complete patch.

tools/verification/models/sched/sssw.dot

View file

This diff is incomplete. Download the complete patch.

tools/verification/models/sched/sts.dot

View file

This diff is incomplete. Download the complete patch.

tools/verification/models/sched/tss.dot

View before deletion

This diff is incomplete. Download the complete patch.

tools/verification/rv/src/in_kernel.c

View file

This diff is incomplete. Download the complete patch.

tools/verification/rv/src/rv.c

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/.gitignore

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/Makefile

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/__main__.py

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/dot2c

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/rvgen/automata.py

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/rvgen/container.py

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/rvgen/dot2c.py

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/rvgen/dot2k.py

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/rvgen/generator.py

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/rvgen/ltl2ba.py

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/rvgen/ltl2k.py

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/rvgen/templates/Kconfig

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/rvgen/templates/container/Kconfig

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/rvgen/templates/container/main.c

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/rvgen/templates/container/main.h

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/rvgen/templates/dot2k/main.c

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/rvgen/templates/dot2k/trace.h

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/rvgen/templates/ltl2k/main.c

View file

This diff is incomplete. Download the complete patch.

tools/verification/rvgen/rvgen/templates/ltl2k/trace.h

View file

This diff is incomplete. Download the complete patch.