lockdep: Refactor IRQ trace events fields into struct
Subsystems (5)
Marco Elver
maintainerPATCH v2 1/2 lockdep: Refactor IRQ trace events fields into struct
Refactor the IRQ trace events fields, used for printing information about the IRQ trace events, into a separate struct 'irqtrace_events'.
This improves readability by separating the information only used in reporting, as well as enables (simplified) storing/restoring of irqtrace_events snapshots.
No functional change intended.
---
v2:
* Introduce patch, as pre-requisite to "kcsan: Improve IRQ state trace reporting".
--- include/linux/irqflags.h | 13 +++++++++ include/linux/sched.h | 11 ++------ kernel/fork.c | 16 ++++------- kernel/locking/lockdep.c | 58 +++++++++++++++++++++------------------- 4 files changed, 50 insertions(+), 48 deletions(-)
include/linux/irqflags.h +13 -0
@@ -33,6 +33,19 @@#ifdef CONFIG_TRACE_IRQFLAGS +/* Per-task IRQ trace events information. */ +struct irqtrace_events { +unsigned int irq_events; +unsigned long hardirq_enable_ip; +unsigned long hardirq_disable_ip; +unsigned int hardirq_enable_event; +unsigned int hardirq_disable_event; +unsigned long softirq_disable_ip; +unsigned long softirq_enable_ip; +unsigned int softirq_disable_event; +unsigned int softirq_enable_event; +}; +DECLARE_PER_CPU (int, hardirqs_enabled);DECLARE_PER_CPU (int, hardirq_context);
include/linux/sched.h +2 -9
@@ -18,6 +18,7 @@#include <linux/mutex.h> #include <linux/plist.h> #include <linux/hrtimer.h> +#include <linux/irqflags.h> #include <linux/seccomp.h> #include <linux/nodemask.h> #include <linux/rcupdate.h>
@@ -980,17 +981,9 @@ struct task_struct {#endif #ifdef CONFIG_TRACE_IRQFLAGS -unsigned int irq_events; +struct irqtrace_events irqtrace;unsigned int hardirq_threaded; -unsigned long hardirq_enable_ip; -unsigned long hardirq_disable_ip; -unsigned int hardirq_enable_event; -unsigned int hardirq_disable_event;u64 hardirq_chain_key; -unsigned long softirq_disable_ip; -unsigned long softirq_enable_ip; -unsigned int softirq_disable_event; -unsigned int softirq_enable_event;int softirqs_enabled;int softirq_context;int irq_config;
kernel/fork.c +5 -11
@@ -2035,17 +2035,11 @@ static __latent_entropy struct task_struct *copy_process(seqcount_init (&p->mems_allowed_seq);#endif #ifdef CONFIG_TRACE_IRQFLAGS - p->irq_events =0 ; - p->hardirq_enable_ip =0 ; - p->hardirq_enable_event =0 ; - p->hardirq_disable_ip = _THIS_IP_; - p->hardirq_disable_event =0 ; - p->softirqs_enabled =1 ; - p->softirq_enable_ip = _THIS_IP_; - p->softirq_enable_event =0 ; - p->softirq_disable_ip =0 ; - p->softirq_disable_event =0 ; - p->softirq_context =0 ; +memset (&p->irqtrace,0 ,sizeof (p->irqtrace)); + p->irqtrace.hardirq_disable_ip = _THIS_IP_; + p->irqtrace.softirq_enable_ip = _THIS_IP_; + p->softirqs_enabled =1 ; + p->softirq_context =0 ;#endif p->pagefault_disabled =0 ;
kernel/locking/lockdep.c +30 -28
135 lines not on this page · raw message
Signature · 1 line
2.28.0.rc0.142.g3c755180ce-goog
Marco Elver
maintainerPATCH v2 2/2 kcsan: Improve IRQ state trace reporting
To improve the general usefulness of the IRQ state trace events with KCSAN enabled, save and restore the trace information when entering and exiting the KCSAN runtime as well as when generating a KCSAN report.
Without this, reporting the IRQ trace events (whether via a KCSAN report or outside of KCSAN via a lockdep report) is rather useless due to continuously being touched by KCSAN. This is because if KCSAN is enabled, every instrumented memory access causes changes to IRQ trace events (either by KCSAN disabling/enabling interrupts or taking report_lock when generating a report).
Before "lockdep: Prepare for NMI IRQ state tracking", KCSAN avoided touching the IRQ trace events via raw_local_irq_save/restore() and lockdep_off/on().
---
v2:
* Use simple struct copy, now that the IRQ trace events are in a struct.
Depends on: "lockdep: Prepare for NMI IRQ state tracking"
--- include/linux/sched.h | 4 ++++ kernel/kcsan/core.c | 23 +++++++++++++++++++++++ kernel/kcsan/kcsan.h | 7 +++++++ kernel/kcsan/report.c | 3 +++ 4 files changed, 37 insertions(+)
include/linux/sched.h +4 -0
@@ -1184,8 +1184,12 @@ struct task_struct {#ifdef CONFIG_KASAN unsigned int kasan_depth;#endif +#ifdef CONFIG_KCSAN struct kcsan_ctx kcsan_ctx; +#ifdef CONFIG_TRACE_IRQFLAGS +struct irqtrace_events kcsan_save_irqtrace; +#endif #endif #ifdef CONFIG_FUNCTION_GRAPH_TRACER
kernel/kcsan/core.c +23 -0
@@ -291,6 +291,20 @@ static inline unsigned int get_delay(void) 0); } +void kcsan_save_irqtrace (struct task_struct *task) +{ +#ifdef CONFIG_TRACE_IRQFLAGS + task->kcsan_save_irqtrace = task->irqtrace; +#endif +} + +void kcsan_restore_irqtrace (struct task_struct *task) +{ +#ifdef CONFIG_TRACE_IRQFLAGS + task->irqtrace = task->kcsan_save_irqtrace; +#endif +} +/* * Pull everything together: check_access() below contains the performance * critical operations; the fast-path (including check_access) functions should
@@ -336,9 +350,11 @@ static noinline void kcsan_found_watchpoint(const volatile void *ptr, flags =user_access_save ();if (consumed) { +kcsan_save_irqtrace (current);kcsan_report (ptr, size, type,KCSAN_VALUE_CHANGE_MAYBE ,KCSAN_REPORT_CONSUMED_WATCHPOINT , watchpoint - watchpoints); +kcsan_restore_irqtrace (current); }else {/* * The other thread may not print any diagnostics, as it has
@@ -396,6 +412,12 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type) goto out; } +/* +* Save and restore the IRQ state trace touched by KCSAN, since KCSAN's +* runtime is entered for every memory access, and potentially useful +* information is lost if dirtied by KCSAN. +*/ +kcsan_save_irqtrace (current);if (!kcsan_interrupt_watcher)local_irq_save (irq_flags);
@@ -539,6 +561,7 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type) out_unlock:if (!kcsan_interrupt_watcher)local_irq_restore (irq_flags); +kcsan_restore_irqtrace (current); out:user_access_restore (ua_flags); }
kernel/kcsan/kcsan.h +7 -0
@@ -9,6 +9,7 @@#define _KERNEL_KCSAN_KCSAN_H#include <linux/kcsan.h> +#include <linux/sched.h> /* The number of adjacent watchpoints to check. */ #define KCSAN_CHECK_ADJACENT 1
@@ -22,6 +23,12 @@ extern unsigned int kcsan_udelay_interrupt;*/ extern bool kcsan_enabled; +/* +* Save/restore IRQ flags state trace dirtied by KCSAN. +*/ +void kcsan_save_irqtrace (struct task_struct *task); +void kcsan_restore_irqtrace (struct task_struct *task); +/* * Initialize debugfs file. */
kernel/kcsan/report.c +3 -0
@@ -308,6 +308,9 @@ static void print_verbose_info(struct task_struct *task)if (!task)return ; +/* Restore IRQ state trace for printing. */ +kcsan_restore_irqtrace (task); +pr_err ("\n" );debug_show_held_locks (task);print_irqtrace_events (task);
Signature · 1 line
2.28.0.rc0.142.g3c755180ce-goog
[tip: locking/core] kcsan: Improve IRQ state trace reporting
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 47490fdd411675707624fdfbf7bcfcd5f6a5e706 Gitweb: https://git.kernel.org/tip/47490fdd411675707624fdfbf7bcfcd5f6a5e706 Author: Marco Elver <[email protected]> AuthorDate: Wed, 29 Jul 2020 13:09:16 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 29 Jul 2020 16:30:41 +02:00
kcsan: Improve IRQ state trace reporting
To improve the general usefulness of the IRQ state trace events with KCSAN enabled, save and restore the trace information when entering and exiting the KCSAN runtime as well as when generating a KCSAN report.
Without this, reporting the IRQ trace events (whether via a KCSAN report or outside of KCSAN via a lockdep report) is rather useless due to continuously being touched by KCSAN. This is because if KCSAN is enabled, every instrumented memory access causes changes to IRQ trace events (either by KCSAN disabling/enabling interrupts or taking report_lock when generating a report).
Before "lockdep: Prepare for NMI IRQ state tracking", KCSAN avoided touching the IRQ trace events via raw_local_irq_save/restore() and lockdep_off/on().
--- include/linux/sched.h | 4 ++++ kernel/kcsan/core.c | 23 +++++++++++++++++++++++ kernel/kcsan/kcsan.h | 7 +++++++ kernel/kcsan/report.c | 3 +++ 4 files changed, 37 insertions(+)
include/linux/sched.h +4 -0
@@ -1184,8 +1184,12 @@ struct task_struct {#ifdef CONFIG_KASAN unsigned int kasan_depth;#endif +#ifdef CONFIG_KCSAN struct kcsan_ctx kcsan_ctx; +#ifdef CONFIG_TRACE_IRQFLAGS +struct irqtrace_events kcsan_save_irqtrace; +#endif #endif #ifdef CONFIG_FUNCTION_GRAPH_TRACER
kernel/kcsan/core.c +23 -0
@@ -291,6 +291,20 @@ static inline unsigned int get_delay(void) 0); } +void kcsan_save_irqtrace (struct task_struct *task) +{ +#ifdef CONFIG_TRACE_IRQFLAGS + task->kcsan_save_irqtrace = task->irqtrace; +#endif +} + +void kcsan_restore_irqtrace (struct task_struct *task) +{ +#ifdef CONFIG_TRACE_IRQFLAGS + task->irqtrace = task->kcsan_save_irqtrace; +#endif +} +/* * Pull everything together: check_access() below contains the performance * critical operations; the fast-path (including check_access) functions should
@@ -336,9 +350,11 @@ static noinline void kcsan_found_watchpoint(const volatile void *ptr, flags =user_access_save ();if (consumed) { +kcsan_save_irqtrace (current);kcsan_report (ptr, size, type,KCSAN_VALUE_CHANGE_MAYBE ,KCSAN_REPORT_CONSUMED_WATCHPOINT , watchpoint - watchpoints); +kcsan_restore_irqtrace (current); }else {/* * The other thread may not print any diagnostics, as it has
@@ -396,6 +412,12 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type) goto out; } +/* +* Save and restore the IRQ state trace touched by KCSAN, since KCSAN's +* runtime is entered for every memory access, and potentially useful +* information is lost if dirtied by KCSAN. +*/ +kcsan_save_irqtrace (current);if (!kcsan_interrupt_watcher)local_irq_save (irq_flags);
@@ -539,6 +561,7 @@ kcsan_setup_watchpoint(const volatile void *ptr, size_t size, int type) out_unlock:if (!kcsan_interrupt_watcher)local_irq_restore (irq_flags); +kcsan_restore_irqtrace (current); out:user_access_restore (ua_flags); }
kernel/kcsan/kcsan.h +7 -0
@@ -9,6 +9,7 @@#define _KERNEL_KCSAN_KCSAN_H#include <linux/kcsan.h> +#include <linux/sched.h> /* The number of adjacent watchpoints to check. */ #define KCSAN_CHECK_ADJACENT 1
@@ -23,6 +24,12 @@ extern unsigned int kcsan_udelay_interrupt;extern bool kcsan_enabled;/* +* Save/restore IRQ flags state trace dirtied by KCSAN. +*/ +void kcsan_save_irqtrace (struct task_struct *task); +void kcsan_restore_irqtrace (struct task_struct *task); + +/* * Initialize debugfs file. */ void kcsan_debugfs_init (void );
kernel/kcsan/report.c +3 -0
@@ -308,6 +308,9 @@ static void print_verbose_info(struct task_struct *task)if (!task)return ; +/* Restore IRQ state trace for printing. */ +kcsan_restore_irqtrace (task); +pr_err ("\n" );debug_show_held_locks (task);print_irqtrace_events (task);
The following commit has been merged into the locking/core branch of tip:
The following commit has been merged into the locking/core branch of tip:
Commit-ID: 9cd8b723f823d007bd70a3252e681fde07143f6d Gitweb: https://git.kernel.org/tip/9cd8b723f823d007bd70a3252e681fde07143f6d Author: Marco Elver <[email protected]> AuthorDate: Wed, 29 Jul 2020 13:09:15 +02:00 Committer: Ingo Molnar <[email protected]> CommitterDate: Wed, 29 Jul 2020 16:30:40 +02:00
lockdep: Refactor IRQ trace events fields into struct
Refactor the IRQ trace events fields, used for printing information about the IRQ trace events, into a separate struct 'irqtrace_events'.
This improves readability by separating the information only used in reporting, as well as enables (simplified) storing/restoring of irqtrace_events snapshots.
No functional change intended.
--- include/linux/irqflags.h | 13 +++++++++- include/linux/sched.h | 11 +------ kernel/fork.c | 16 +++-------- kernel/locking/lockdep.c | 58 ++++++++++++++++++++------------------- 4 files changed, 50 insertions(+), 48 deletions(-)
include/linux/irqflags.h +13 -0
@@ -33,6 +33,19 @@#ifdef CONFIG_TRACE_IRQFLAGS +/* Per-task IRQ trace events information. */ +struct irqtrace_events { +unsigned int irq_events; +unsigned long hardirq_enable_ip; +unsigned long hardirq_disable_ip; +unsigned int hardirq_enable_event; +unsigned int hardirq_disable_event; +unsigned long softirq_disable_ip; +unsigned long softirq_enable_ip; +unsigned int softirq_disable_event; +unsigned int softirq_enable_event; +}; +DECLARE_PER_CPU (int, hardirqs_enabled);DECLARE_PER_CPU (int, hardirq_context);
include/linux/sched.h +2 -9
@@ -18,6 +18,7 @@#include <linux/mutex.h> #include <linux/plist.h> #include <linux/hrtimer.h> +#include <linux/irqflags.h> #include <linux/seccomp.h> #include <linux/nodemask.h> #include <linux/rcupdate.h>
@@ -980,17 +981,9 @@ struct task_struct {#endif #ifdef CONFIG_TRACE_IRQFLAGS -unsigned int irq_events; +struct irqtrace_events irqtrace;unsigned int hardirq_threaded; -unsigned long hardirq_enable_ip; -unsigned long hardirq_disable_ip; -unsigned int hardirq_enable_event; -unsigned int hardirq_disable_event;u64 hardirq_chain_key; -unsigned long softirq_disable_ip; -unsigned long softirq_enable_ip; -unsigned int softirq_disable_event; -unsigned int softirq_enable_event;int softirqs_enabled;int softirq_context;int irq_config;
kernel/fork.c +5 -11
@@ -2035,17 +2035,11 @@ static __latent_entropy struct task_struct *copy_process(seqcount_spinlock_init (&p->mems_allowed_seq, &p->alloc_lock);#endif #ifdef CONFIG_TRACE_IRQFLAGS - p->irq_events =0 ; - p->hardirq_enable_ip =0 ; - p->hardirq_enable_event =0 ; - p->hardirq_disable_ip = _THIS_IP_; - p->hardirq_disable_event =0 ; - p->softirqs_enabled =1 ; - p->softirq_enable_ip = _THIS_IP_; - p->softirq_enable_event =0 ; - p->softirq_disable_ip =0 ; - p->softirq_disable_event =0 ; - p->softirq_context =0 ; +memset (&p->irqtrace,0 ,sizeof (p->irqtrace)); + p->irqtrace.hardirq_disable_ip = _THIS_IP_; + p->irqtrace.softirq_enable_ip = _THIS_IP_; + p->softirqs_enabled =1 ; + p->softirq_context =0 ;#endif p->pagefault_disabled =0 ;
kernel/locking/lockdep.c +30 -28
135 lines not on this page · raw message