DEPT(Dependency Tracker)
Subsystems (16)
v2 cover DEPT(Dependency Tracker)
Hi Linus and folks,
I've been developing a tool for detecting deadlock possibilities by tracking wait/event rather than lock(?) acquisition order to try to cover all synchonization machanisms. It's done on v5.17-rc1 tag.
https://github.com/lgebyungchulpark/linux-dept/commits/dept1.13_on_v5.17-rc1
Benifit:
0. Works with all lock primitives.
1. Works with wait_for_completion()/complete().
2. Works with 'wait' on PG_locked.
3. Works with 'wait' on PG_writeback.
4. Works with swait/wakeup.
5. Works with waitqueue.
6. Multiple reports are allowed.
7. Deduplication control on multiple reports.
8. Withstand false positives thanks to 6.
9. Easy to tag any wait/event.
Future work:
0. To make it more stable.
1. To separates Dept from Lockdep.
2. To improves performance in terms of time and space.
3. To use Dept as a dependency engine for Lockdep.
4. To add any missing tags of wait/event in the kernel.
5. To deduplicate stack trace.
How to interpret reports:
1. E(event) in each context cannot be triggered because of the W(wait) that cannot be woken.
2. The stack trace helping find the problematic code is located in each conext's detail.
Thanks,
Byungchul
---
Changes from v1:
1. Fix coding style and typo. (feedback from Steven)
2. Distinguish each work context from another in workqueue.
3. Skip checking lock acquisition with nest_lock, which is about correct lock usage that should be checked by Lockdep.
Changes from RFC:
1. Prevent adding a wait tag at prepare_to_wait() but __schedule(). (feedback from Linus and Matthew)
2. Use try version at lockdep_acquire_cpus_lock() annotation.
3. Distinguish each syscall context from another.
---
Byungchul Park (18):
llist: Move llist_{head,node} definition to types.h
dept: Implement Dept(Dependency Tracker)
dept: Embed Dept data in Lockdep
dept: Add a API for skipping dependency check temporarily
dept: Apply Dept to spinlock
dept: Apply Dept to mutex families
dept: Apply Dept to rwlock
dept: Apply Dept to wait_for_completion()/complete()
dept: Apply Dept to seqlock
dept: Apply Dept to rwsem
dept: Add proc knobs to show stats and dependency graph
dept: Introduce split map concept and new APIs for them
dept: Apply Dept to wait/event of PG_{locked,writeback}
dept: Apply SDT to swait
dept: Apply SDT to wait(waitqueue)
locking/lockdep, cpu/hotplus: Use a weaker annotation in AP thread
dept: Distinguish each syscall context from another
dept: Distinguish each work from another
include/linux/completion.h | 42 +- include/linux/dept.h | 535 +++++++ include/linux/dept_page.h | 78 ++ include/linux/dept_sdt.h | 62 + include/linux/hardirq.h | 3 + include/linux/irqflags.h | 33 +- include/linux/llist.h | 8 - include/linux/lockdep.h | 158 ++- include/linux/lockdep_types.h | 3 + include/linux/mutex.h | 33 + include/linux/page-flags.h | 45 +- include/linux/pagemap.h | 7 +- include/linux/percpu-rwsem.h | 10 +- include/linux/rtmutex.h | 7 + include/linux/rwlock.h | 52 + include/linux/rwlock_api_smp.h | 8 +- include/linux/rwlock_types.h | 7 + include/linux/rwsem.h | 33 + include/linux/sched.h | 7 + include/linux/seqlock.h | 59 +- include/linux/spinlock.h | 26 + include/linux/spinlock_types_raw.h | 13 + include/linux/swait.h | 4 + include/linux/types.h | 8 + include/linux/wait.h | 6 +- init/init_task.c | 2 + init/main.c | 4 + kernel/Makefile | 1 + kernel/cpu.c | 2 +- kernel/dependency/Makefile | 4 + kernel/dependency/dept.c | 2710 ++++++++++++++++++++++++++++++++++++ kernel/dependency/dept_hash.h | 10 + kernel/dependency/dept_internal.h | 26 + kernel/dependency/dept_object.h | 13 + kernel/dependency/dept_proc.c | 92 ++ kernel/entry/common.c | 3 + kernel/exit.c | 1 + kernel/fork.c | 2 + kernel/locking/lockdep.c | 12 +- kernel/module.c | 2 + kernel/sched/completion.c | 12 +- kernel/sched/core.c | 3 + kernel/sched/swait.c | 10 + kernel/sched/wait.c | 16 + kernel/softirq.c | 6 +- kernel/trace/trace_preemptirq.c | 19 +- kernel/workqueue.c | 3 + lib/Kconfig.debug | 21 + mm/filemap.c | 68 + mm/page_ext.c | 5 + 50 files changed, 4237 insertions(+), 57 deletions(-) create mode 100644 include/linux/dept.h create mode 100644 include/linux/dept_page.h create mode 100644 include/linux/dept_sdt.h create mode 100644 kernel/dependency/Makefile create mode 100644 kernel/dependency/dept.c create mode 100644 kernel/dependency/dept_hash.h create mode 100644 kernel/dependency/dept_internal.h create mode 100644 kernel/dependency/dept_object.h create mode 100644 kernel/dependency/dept_proc.c
Signature · 1 line
1.9.1
PATCH v2 1/18 llist: Move llist_{head,node} definition to types.h
llist_head and llist_node can be used by very primitives. For example, Dept for tracking dependency uses llist things in its header. To avoid header dependency, move those to types.h.
--- include/linux/llist.h | 8 -------- include/linux/types.h | 8 ++++++++ 2 files changed, 8 insertions(+), 8 deletions(-)
include/linux/llist.h +0 -8
@@ -53,14 +53,6 @@#include <linux/stddef.h> #include <linux/types.h> -struct llist_head { -struct llist_node *first; -}; - -struct llist_node { -struct llist_node *next; -}; -#define LLIST_HEAD_INIT (name) { NULL }#define LLIST_HEAD (name) struct llist_head name = LLIST_HEAD_INIT(name)
include/linux/types.h +8 -0
@@ -187,6 +187,14 @@ struct hlist_node {struct hlist_node *next, **pprev; }; +struct llist_head { +struct llist_node *first; +}; + +struct llist_node { +struct llist_node *next; +}; +struct ustat {__kernel_daddr_t f_tfree;#ifdef CONFIG_ARCH_32BIT_USTAT_F_TINODE
Signature · 1 line
1.9.1
PATCH v2 2/18 dept: Implement Dept(Dependency Tracker)
In reply to Byungchul ParkCURRENT STATUS
--------------
Lockdep tracks acquisition order of locks in order to detect deadlock, and IRQ and IRQ enable/disable state as well to take accident acquisitions into account.
Lockdep should be turned off once it detects and reports a deadlock since the data structure and algorithm are not reusable after detection because of the complex design.
PROBLEM
-------
*Waits* and their *events* that never reach eventually cause deadlock. However, Lockdep is only interested in lock acquisition order, forcing to emulate lock acqusition even for just waits and events that have nothing to do with real lock.
Even worse, no one likes Lockdep's false positive detection because that prevents further one that might be more valuable. That's why all the kernel developers are sensitive to Lockdep's false positive.
Besides those, by tracking acquisition order, it cannot correctly deal with read lock and cross-event e.g. wait_for_completion()/complete() for deadlock detection. Lockdep is no longer a good tool for that purpose.
SOLUTION
--------
Again, *waits* and their *events* that never reach eventually cause deadlock. The new solution, Dept(DEPendency Tracker), focuses on waits and events themselves. Dept tracks waits and events and report it if any event would be never reachable.
Dept does:
. Works with read lock in the right way.
. Works with any wait and event e.i. cross-event. . Continue to work even after reporting multiple times. . Provides simple and intuitive APIs.
. Does exactly what dependency checker should do.
Q & A
-----
Q. Is this the first try ever to address the problem?
A. No. Cross-release feature (b09be676e0ff2 locking/lockdep: Implement
the 'crossrelease' feature) addressed it 2 years ago that was a Lockdep extension and merged but reverted shortly because:
Cross-release started to report valuable hidden problems but started to give report false positive reports as well. For sure, no one likes Lockdep's false positive reports since it makes Lockdep stop, preventing reporting further real problems.
Q. Why not Dept was developed as an extension of Lockdep? A. Lockdep definitely includes all the efforts great developers have
made for a long time so as to be quite stable enough. But I had to design and implement newly because of the following:
1) Lockdep was designed to track lock acquisition order. The APIs and implementation do not fit on wait-event model.
2) Lockdep is turned off on detection including false positive. Which is terrible and prevents developing any extension for stronger detection.
Q. Do you intend to totally replace Lockdep?
A. No. Lockdep also checks if lock usage is correct. Of course, the
dependency check routine should be replaced but the other functions should be still there.
Q. Do you mean the dependency check routine should be replaced right
away?
A. No. I admit Lockdep is stable enough thanks to great efforts kernel
developers have made. Lockdep and Dept, both should be in the kernel until Dept gets considered stable.
Q. Stronger detection capability would give more false positive report.
Which was a big problem when cross-release was introduced. Is it ok with Dept?
A. It's ok. Dept allows multiple reporting thanks to simple and quite
generalized design. Of course, false positive reports should be fixed anyway but it's no longer as a critical problem as it was.
--- include/linux/dept.h | 481 ++++++++ include/linux/dept_sdt.h | 62 + include/linux/hardirq.h | 3 + include/linux/irqflags.h | 33 +- include/linux/sched.h | 7 + init/init_task.c | 2 + init/main.c | 2 + kernel/Makefile | 1 + kernel/dependency/Makefile | 3 + kernel/dependency/dept.c | 2534 +++++++++++++++++++++++++++++++++++++++ kernel/dependency/dept_hash.h | 10 + kernel/dependency/dept_object.h | 13 + kernel/exit.c | 1 + kernel/fork.c | 2 + kernel/module.c | 2 + kernel/sched/core.c | 3 + kernel/softirq.c | 6 +- kernel/trace/trace_preemptirq.c | 19 +- lib/Kconfig.debug | 20 + 19 files changed, 3195 insertions(+), 9 deletions(-) create mode 100644 include/linux/dept.h create mode 100644 include/linux/dept_sdt.h create mode 100644 kernel/dependency/Makefile create mode 100644 kernel/dependency/dept.c create mode 100644 kernel/dependency/dept_hash.h create mode 100644 kernel/dependency/dept_object.h
include/linux/dept.h new file +481 -0
@@ -0,0 +1,481 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* DEPT(DEPendency Tracker) - runtime dependency tracker +* +* Started by Byungchul Park <[email protected]>: +* +* Copyright (c) 2020 LG Electronics, Inc., Byungchul Park +*/ + +#ifndef __LINUX_DEPT_H +#define __LINUX_DEPT_H + +#ifdef CONFIG_DEPT + +#include <linux/types.h> + +struct task_struct ; + +#define DEPT_MAX_STACK_ENTRY 16 +#define DEPT_MAX_WAIT_HIST 64 +#define DEPT_MAX_ECXT_HELD 48 + +#define DEPT_MAX_SUBCLASSES 16 +#define DEPT_MAX_SUBCLASSES_EVT 2 +#define DEPT_MAX_SUBCLASSES_USR (DEPT_MAX_SUBCLASSES / DEPT_MAX_SUBCLASSES_EVT) +#define DEPT_MAX_SUBCLASSES_CACHE 2 + +#define DEPT_SIRQ 0 +#define DEPT_HIRQ 1 +#define DEPT_IRQS_NR 2 +#define DEPT_SIRQF (1UL << DEPT_SIRQ) +#define DEPT_HIRQF (1UL << DEPT_HIRQ) + +struct dept_ecxt ; +struct dept_iecxt { +struct dept_ecxt *ecxt; +int enirq; +/* +* for preventing to add a new ecxt +*/ +bool staled; +}; + +struct dept_wait ; +struct dept_iwait { +struct dept_wait *wait; +int irq; +/* +* for preventing to add a new wait +*/ +bool staled; +bool touched; +}; + +struct dept_class { +union { +struct llist_node pool_node; + +/* +* reference counter for object management +*/ +atomic_t ref; + }; + +/* +* unique information about the class +*/ +const char *name; +unsigned long key; +int sub; + +/* +* for BFS +*/ +unsigned int bfs_gen; +int bfs_dist; +struct dept_class *bfs_parent; + +/* +* for hashing this object +*/ +struct hlist_node hash_node; + +/* +* for linking all classes +*/ +struct list_head all_node; + +/* +* for associating its dependencies +*/ +struct list_head dep_head; +struct list_head dep_rev_head; + +/* +* for tracking IRQ dependencies +*/ +struct dept_iecxt iecxt[DEPT_IRQS_NR ]; +struct dept_iwait iwait[DEPT_IRQS_NR ]; +}; + +struct dept_stack { +union { +struct llist_node pool_node; + +/* +* reference counter for object management +*/ +atomic_t ref; + }; + +/* +* backtrace entries +*/ +unsigned long raw[DEPT_MAX_STACK_ENTRY ]; +int nr; +}; + +struct dept_ecxt { +union { +struct llist_node pool_node; + +/* +* reference counter for object management +*/ +atomic_t ref; + }; + +/* +* function that entered to this ecxt +*/ +const char *ecxt_fn; + +/* +* event function +*/ +const char *event_fn; + +/* +* associated class +*/ +struct dept_class *class; + +/* +* flag indicating which IRQ has been +* enabled within the event context +*/ +unsigned long enirqf; + +/* +* where the IRQ-enabled happened +*/ +unsigned long enirq_ip[DEPT_IRQS_NR ]; +struct dept_stack *enirq_stack[DEPT_IRQS_NR ]; + +/* +* where the event context started +*/ +unsigned long ecxt_ip; +struct dept_stack *ecxt_stack; + +/* +* where the event triggered +*/ +unsigned long event_ip; +struct dept_stack *event_stack; +}; + +struct dept_wait { +union { +struct llist_node pool_node; + +/* +* reference counter for object management +*/ +atomic_t ref; + }; + +/* +* function causing this wait +*/ +const char *wait_fn; + +/* +* the associated class +*/ +struct dept_class *class; + +/* +* which IRQ the wait was placed in +*/ +unsigned long irqf; + +/* +* where the IRQ wait happened +*/ +unsigned long irq_ip[DEPT_IRQS_NR ]; +struct dept_stack *irq_stack[DEPT_IRQS_NR ]; + +/* +* where the wait happened +*/ +unsigned long wait_ip; +struct dept_stack *wait_stack; +}; + +struct dept_dep { +union { +struct llist_node pool_node; + +/* +* reference counter for object management +*/ +atomic_t ref; + }; + +/* +* key data of dependency +*/ +struct dept_ecxt *ecxt; +struct dept_wait *wait; + +/* +* This object can be referred without dept_lock +* held but with IRQ disabled, e.g. for hash +* lookup. So deferred deletion is needed. +*/ +struct rcu_head rh; + +/* +* for BFS +*/ +struct list_head bfs_node; + +/* +* for hashing this object +*/ +struct hlist_node hash_node; + +/* +* for linking to a class object +*/ +struct list_head dep_node; +struct list_head dep_rev_node; +}; + +struct dept_hash { +/* +* hash table +*/ +struct hlist_head *table; + +/* +* size of the table e.i. 2^bits +*/ +int bits; +}; + +struct dept_pool { +const char *name; + +/* +* object size +*/ +size_t obj_sz; + +/* +* the number of the static array +*/ +atomic_t obj_nr; + +/* +* offset of ->pool_node +*/ +size_t node_off; + +/* +* pointer to the pool +*/ +void *spool; +struct llist_head boot_pool; +struct llist_head __percpu *lpool; +}; + +struct dept_ecxt_held { +/* +* associated event context +*/ +struct dept_ecxt *ecxt; + +/* +* unique key for this dept_ecxt_held +*/ +unsigned long key; + +/* +* the wgen when the event context started +*/ +unsigned int wgen; + +/* +* for allowing user aware nesting +*/ +int nest; +}; + +struct dept_wait_hist { +/* +* associated wait +*/ +struct dept_wait *wait; + +/* +* unique id of all waits system-wise until wrapped +*/ +unsigned int wgen; + +/* +* local context id to identify IRQ context +*/ +unsigned int ctxt_id; +}; + +struct dept_key { +union { +/* +* Each byte-wise address will be used as its key. +*/ +char subkeys[DEPT_MAX_SUBCLASSES ]; + +/* +* for caching the main class pointer +*/ +struct dept_class *classes[DEPT_MAX_SUBCLASSES_CACHE ]; + }; +}; + +struct dept_map { +const char *name; +struct dept_key *keys; +int sub_usr; + +/* +* It's local copy for fast acces to the associated classes. And +* Also used for dept_key instance for statically defined map. +*/ +struct dept_key keys_local; + +/* +* wait timestamp associated to this map +*/ +unsigned int wgen; + +/* +* whether this map should be going to be checked or not +*/ +bool nocheck; +}; + +struct dept_task { +/* +* all event contexts that have entered and before exiting +*/ +struct dept_ecxt_held ecxt_held[DEPT_MAX_ECXT_HELD ]; +int ecxt_held_pos; + +/* +* ring buffer holding all waits that have happened +*/ +struct dept_wait_hist wait_hist[DEPT_MAX_WAIT_HIST ]; +int wait_hist_pos; + +/* +* sequential id to identify each IRQ context +*/ +unsigned int irq_id[DEPT_IRQS_NR ]; + +/* +* for tracking IRQ-enabled points with cross-event +*/ +unsigned int wgen_enirq[DEPT_IRQS_NR ]; + +/* +* for keeping up-to-date IRQ-enabled points +*/ +unsigned long enirq_ip[DEPT_IRQS_NR ]; + +/* +* current effective IRQ-enabled flag +*/ +unsigned long eff_enirqf; + +/* +* for reserving a current stack instance at each operation +*/ +struct dept_stack *stack; + +/* +* for preventing recursive call into DEPT engine +*/ +int recursive; + +/* +* for staging data to commit a wait +*/ +struct dept_map *stage_m; +unsigned long stage_w_f; +const char *stage_w_fn; +int stage_ne; + +/* +* for tracking IRQ-enable state +*/ +bool hardirqs_enabled; +bool softirqs_enabled; +}; + +#define DEPT_TASK_INITIALIZER (t) \ + .dept_task.wait_hist = { { .wait = NULL, } }, \ + .dept_task.ecxt_held_pos = 0, \ + .dept_task.wait_hist_pos = 0, \ + .dept_task.irq_id = { 0 }, \ + .dept_task.wgen_enirq = { 0 }, \ + .dept_task.enirq_ip = { 0 }, \ + .dept_task.recursive = 0, \ + .dept_task.hardirqs_enabled = false, \ + .dept_task.softirqs_enabled = false, + +extern void dept_on (void ); +extern void dept_off (void ); +extern void dept_init (void ); +extern void dept_task_init (struct task_struct *t); +extern void dept_task_exit (struct task_struct *t); +extern void dept_free_range (void *start,unsigned int sz); +extern void dept_map_init (struct dept_map *m,struct dept_key *k,int sub,const char *n); +extern void dept_map_reinit (struct dept_map *m); +extern void dept_map_nocheck (struct dept_map *m); + +extern void dept_wait (struct dept_map *m,unsigned long w_f,unsigned long ip,const char *w_fn,int ne); +extern void dept_stage_wait (struct dept_map *m,unsigned long w_f,const char *w_fn,int ne); +extern void dept_ask_event_wait_commit (unsigned long ip); +extern void dept_clean_stage (void ); +extern void dept_ecxt_enter (struct dept_map *m,unsigned long e_f,unsigned long ip,const char *c_fn,const char *e_fn,int ne); +extern void dept_ask_event (struct dept_map *m); +extern void dept_event (struct dept_map *m,unsigned long e_f,unsigned long ip,const char *e_fn); +extern void dept_ecxt_exit (struct dept_map *m,unsigned long ip); + +/* +* for users who want to manage external keys +*/ +extern void dept_key_init (struct dept_key *k); +extern void dept_key_destroy (struct dept_key *k); +#else /* !CONFIG_DEPT */ +struct dept_key { }; +struct dept_map { }; +struct dept_task { }; + +#define DEPT_TASK_INITIALIZER (t) + +#define dept_on () do { } while (0) +#define dept_off () do { } while (0) +#define dept_init () do { } while (0) +#define dept_task_init (t) do { } while (0) +#define dept_task_exit (t) do { } while (0) +#define dept_free_range (s, sz) do { } while (0) +#define dept_map_init (m, k, s, n) do { (void)(n); (void)(k); } while (0) +#define dept_map_reinit (m) do { } while (0) +#define dept_map_nocheck (m) do { } while (0) + +#define dept_wait (m, w_f, ip, w_fn, ne) do { (void)(w_fn); } while (0) +#define dept_stage_wait (m, w_f, w_fn, ne) do { (void)(w_fn); } while (0) +#define dept_ask_event_wait_commit (ip) do { } while (0) +#define dept_clean_stage () do { } while (0) +#define dept_ecxt_enter (m, e_f, ip, c_fn, e_fn, ne) do { (void)(c_fn); (void)(e_fn); } while (0) +#define dept_ask_event (m) do { } while (0) +#define dept_event (m, e_f, ip, e_fn) do { (void)(e_fn); } while (0) +#define dept_ecxt_exit (m, ip) do { } while (0) +#define dept_key_init (k) do { (void)(k); } while (0) +#define dept_key_destroy (k) do { (void)(k); } while (0) +#endif +#endif /* __LINUX_DEPT_H */
include/linux/dept_sdt.h new file +62 -0
62 lines not on this page · raw message
include/linux/hardirq.h +3 -0
@@ -5,6 +5,7 @@#include <linux/context_tracking_state.h> #include <linux/preempt.h> #include <linux/lockdep.h> +#include <linux/dept.h> #include <linux/ftrace_irq.h> #include <linux/sched.h> #include <linux/vtime.h>
@@ -114,6 +115,7 @@ static inline void rcu_nmi_exit(void) { }*/ #define __nmi_enter () \ do { \ + dept_off(); \ lockdep_off(); \ arch_nmi_enter(); \ BUG_ON(in_nmi() == NMI_MASK); \
@@ -136,6 +138,7 @@ static inline void rcu_nmi_exit(void) { }__preempt_count_sub (NMI_OFFSET +HARDIRQ_OFFSET ); \arch_nmi_exit (); \lockdep_on (); \ +dept_on (); \ }while (0 ) #define nmi_exit() \
include/linux/irqflags.h +28 -5
@@ -31,6 +31,22 @@static inline void lockdep_hardirqs_off (unsigned long ip) { }#endif +#ifdef CONFIG_DEPT +extern void dept_hardirq_enter (void ); +extern void dept_softirq_enter (void ); +extern void dept_enable_hardirq (unsigned long ip); +extern void dept_enable_softirq (unsigned long ip); +extern void dept_disable_hardirq (unsigned long ip); +extern void dept_disable_softirq (unsigned long ip); +#else +static inline void dept_hardirq_enter (void ) { } +static inline void dept_softirq_enter (void ) { } +static inline void dept_enable_hardirq (unsigned long ip) { } +static inline void dept_enable_softirq (unsigned long ip) { } +static inline void dept_disable_hardirq (unsigned long ip) { } +static inline void dept_disable_softirq (unsigned long ip) { } +#endif +#ifdef CONFIG_TRACE_IRQFLAGS /* Per-task IRQ trace events information. */
@@ -53,15 +69,19 @@ struct irqtrace_events {extern void trace_hardirqs_off_finish (void );extern void trace_hardirqs_on (void );extern void trace_hardirqs_off (void ); +extern void trace_softirqs_on_caller (unsigned long ip); +extern void trace_softirqs_off_caller (unsigned long ip);# define lockdep_hardirq_context () (raw_cpu_read(hardirq_context))# define lockdep_softirq_context (p) ((p)->softirq_context)# define lockdep_hardirqs_enabled () (this_cpu_read(hardirqs_enabled))# define lockdep_softirqs_enabled (p) ((p)->softirqs_enabled) -# define lockdep_hardirq_enter () \ -do { \ - if (__this_cpu_inc_return(hardirq_context) == 1)\ - current->hardirq_threaded = 0; \ +# define lockdep_hardirq_enter () \ +do { \ + if (__this_cpu_inc_return(hardirq_context) == 1) { \ + current->hardirq_threaded = 0; \ + dept_hardirq_enter(); \ + } \ } while (0)# define lockdep_hardirq_threaded () \ do { \
@@ -115,6 +135,8 @@ struct irqtrace_events {# define trace_hardirqs_off_finish () do { } while (0)# define trace_hardirqs_on () do { } while (0)# define trace_hardirqs_off () do { } while (0) +# define trace_softirqs_on_caller (ip) do { } while (0) +# define trace_softirqs_off_caller (ip) do { } while (0)# define lockdep_hardirq_context () 0# define lockdep_softirq_context (p) 0# define lockdep_hardirqs_enabled () 0
@@ -135,7 +157,8 @@ struct irqtrace_events {#if defined(CONFIG_TRACE_IRQFLAGS ) && !defined(CONFIG_PREEMPT_RT )# define lockdep_softirq_enter () \ do { \ - current->softirq_context++; \ + if (!current->softirq_context++) \ + dept_softirq_enter(); \ } while (0)# define lockdep_softirq_exit () \ do { \
include/linux/sched.h +7 -0
@@ -35,6 +35,7 @@#include <linux/seqlock.h> #include <linux/kcsan.h> #include <asm/kmap_size.h> +#include <linux/dept.h> /* task_struct member predeclarations (sorted alphabetically): */ struct audit_context ;
@@ -201,12 +202,16 @@*/ #define __set_current_state (state_value) \ do { \ + if (state_value == TASK_RUNNING) \ + dept_clean_stage(); \ debug_normal_state_change((state_value)); \ WRITE_ONCE(current->__state, (state_value)); \ } while (0)#define set_current_state (state_value) \ do { \ + if (state_value == TASK_RUNNING) \ + dept_clean_stage(); \ debug_normal_state_change((state_value)); \ smp_store_mb(current->__state, (state_value)); \ } while (0)
@@ -1157,6 +1162,8 @@ struct task_struct {struct held_lock held_locks[MAX_LOCK_DEPTH ];#endif +struct dept_task dept_task; +#if defined(CONFIG_UBSAN ) && !defined(CONFIG_UBSAN_TRAP )unsigned int in_ubsan;#endif
init/init_task.c +2 -0
@@ -12,6 +12,7 @@#include <linux/audit.h> #include <linux/numa.h> #include <linux/scs.h> +#include <linux/dept.h> #include <linux/uaccess.h>
@@ -193,6 +194,7 @@ struct task_struct init_task .curr_chain_key = INITIAL_CHAIN_KEY, .lockdep_recursion = 0,#endif +DEPT_TASK_INITIALIZER (init_task) #ifdef CONFIG_FUNCTION_GRAPH_TRACER .ret_stack = NULL, .tracing_graph_pause = ATOMIC_INIT(0),
init/main.c +2 -0
@@ -65,6 +65,7 @@#include <linux/debug_locks.h> #include <linux/debugobjects.h> #include <linux/lockdep.h> +#include <linux/dept.h> #include <linux/kmemleak.h> #include <linux/padata.h> #include <linux/pid_namespace.h>
@@ -1070,6 +1071,7 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void) panic_param);lockdep_init (); +dept_init ();/* * Need to run this when irqs are enabled, because it wants
kernel/Makefile +1 -0
@@ -53,6 +53,7 @@ obj-y += rcu/ obj-y += livepatch/ obj-y += dma/ obj-y += entry/ +obj-y += dependency/ obj-$(CONFIG_KCMP) += kcmp.o obj-$(CONFIG_FREEZER) += freezer.o
kernel/dependency/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_DEPT) += dept.o
kernel/dependency/dept.c new file +2534 -0
2,305 lines not on this page · raw message
kernel/dependency/dept_hash.h new file +10 -0
Lines of this file are not shown. View the raw message.
kernel/dependency/dept_object.h new file +13 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.9.1
Part of the diff is not shown here. View the raw message.
PATCH v2 3/18 dept: Embed Dept data in Lockdep
In reply to Byungchul ParkDept should work independently from Lockdep. However, there's no choise but to rely on Lockdep code and its instances for now.
--- include/linux/lockdep.h | 71 ++++++++++++++++++++++++++++++++++++++++--- include/linux/lockdep_types.h | 3 ++ kernel/locking/lockdep.c | 12 ++++---- 3 files changed, 76 insertions(+), 10 deletions(-)
include/linux/lockdep.h +67 -4
@@ -20,6 +20,33 @@extern int prove_locking;extern int lock_stat; +#ifdef CONFIG_DEPT +static inline void dept_after_copy_map (struct dept_map *to, +struct dept_map *from) +{ +int i; + +if (from->keys == &from->keys_local) + to->keys = &to->keys_local; + +if (!to->keys) +return ; + +/* +* Since the class cache can be modified concurrently we could observe +* half pointers (64bit arch using 32bit copy insns). Therefore clear +* the caches and take the performance hit. +* +* XXX it doesn't work well with lockdep_set_class_and_subclass(), since +* that relies on cache abuse. +*/ +for (i =0 ; i <DEPT_MAX_SUBCLASSES_CACHE ; i++) + to->keys->classes[i] =NULL ; +} +#else +#define dept_after_copy_map (t, f) do { } while (0) +#endif +#ifdef CONFIG_LOCKDEP #include <linux/linkage.h>
@@ -43,6 +70,8 @@ static inline void lockdep_copy_map(struct lockdep_map *to,*/ for (i =0 ; i <NR_LOCKDEP_CACHING_CLASSES ; i++) to->class_cache[i] =NULL ; + +dept_after_copy_map (&to->dmap, &from->dmap); }/*
@@ -176,8 +205,19 @@ struct held_lock { current->lockdep_recursion -=LOCKDEP_OFF ; \ }while (0 ) -extern void lockdep_register_key(struct lock_class_key *key); -extern void lockdep_unregister_key (struct lock_class_key *key); +extern void __lockdep_register_key(struct lock_class_key *key); +extern void __lockdep_unregister_key (struct lock_class_key *key); + +#define lockdep_register_key (k) \ +do { \ + __lockdep_register_key(k); \ + dept_key_init(&(k)->dkey); \ +} while (0) +#define lockdep_unregister_key (k) \ +do { \ + __lockdep_unregister_key(k); \ + dept_key_destroy(&(k)->dkey); \ +} while (0)/* * These methods are used by specific locking variants (spinlocks,
@@ -185,9 +225,18 @@ struct held_lock {* to lockdep: */ -extern void lockdep_init_map_type (struct lockdep_map *lock,const char *name, +extern void __lockdep_init_map_type (struct lockdep_map *lock,const char *name,struct lock_class_key *key,int subclass,u8 inner,u8 outer,u8 lock_type); +#define lockdep_init_map_type (l, n, k, s, i, o, t) \ +do { \ + __lockdep_init_map_type(l, n, k, s, i, o, t); \ + if ((k) == &__lockdep_no_validate__) \ + dept_map_nocheck(&(l)->dmap); \ + else \ + dept_map_init(&(l)->dmap, &(k)->dkey, s, n); \ +} while (0) +static inline void lockdep_init_map_waits (struct lockdep_map *lock,const char *name,struct lock_class_key *key,int subclass,u8 inner,u8 outer)
@@ -431,13 +480,27 @@ enum xhlock_context_t { XHLOCK_CTX_NR, }; +#ifdef CONFIG_DEPT +/* +* TODO: I found the case to use an address of other than a real key as +* _key, for instance, in workqueue. So for now, we cannot use the +* assignment like '.dmap.keys = &(_key)->dkey' unless it's fixed. +*/ +#define STATIC_DEPT_MAP_INIT (_name, _key) .dmap = { \ + .name = (_name), \ + .keys = NULL }, +#else +#define STATIC_DEPT_MAP_INIT (_name, _key) +#endif +#define lockdep_init_map_crosslock (m, n, k, s) do {} while (0)/* * To initialize a lockdep_map statically use this macro. * Note that _name must not be NULL. */ #define STATIC_LOCKDEP_MAP_INIT (_name, _key) \ - { .name = (_name), .key = (void *)(_key), } + { .name = (_name), .key = (void *)(_key), \ + STATIC_DEPT_MAP_INIT(_name, _key) }static inline void lockdep_invariant_state (bool force) {}static inline void lockdep_free_task (struct task_struct *task) {}
include/linux/lockdep_types.h +3 -0
@@ -11,6 +11,7 @@#define __LINUX_LOCKDEP_TYPES_H#include <linux/types.h> +#include <linux/dept.h> #define MAX_LOCKDEP_SUBCLASSES 8UL
@@ -76,6 +77,7 @@ struct lock_class_key {struct hlist_node hash_entry;struct lockdep_subclass_key subkeys[MAX_LOCKDEP_SUBCLASSES ]; }; +struct dept_key dkey; };extern struct lock_class_key __lockdep_no_validate__;
@@ -185,6 +187,7 @@ struct lockdep_map {int cpu;unsigned long ip;#endif +struct dept_map dmap; };struct pin_cookie {unsigned int val; };
kernel/locking/lockdep.c +6 -6
@@ -1184,7 +1184,7 @@ static inline struct hlist_head *keyhashentry(const struct lock_class_key *key) }/* Register a dynamically allocated key. */ -void lockdep_register_key (struct lock_class_key *key) +void __lockdep_register_key (struct lock_class_key *key) {struct hlist_head *hash_head;struct lock_class_key *k;
@@ -1207,7 +1207,7 @@ void lockdep_register_key(struct lock_class_key *key) restore_irqs:raw_local_irq_restore (flags); } -EXPORT_SYMBOL_GPL (lockdep_register_key); +EXPORT_SYMBOL_GPL (__lockdep_register_key);/* Check whether a key has been registered as a dynamic key. */ static bool is_dynamic_key (const struct lock_class_key *key)
@@ -4771,7 +4771,7 @@ static inline int check_wait_context(struct task_struct *curr,/* * Initialize a lock instance's lock-class mapping info: */ -void lockdep_init_map_type (struct lockdep_map *lock,const char *name, +void __lockdep_init_map_type (struct lockdep_map *lock,const char *name,struct lock_class_key *key,int subclass,u8 inner,u8 outer,u8 lock_type) {
@@ -4831,7 +4831,7 @@ void lockdep_init_map_type(struct lockdep_map *lock, const char *name,raw_local_irq_restore (flags); } } -EXPORT_SYMBOL_GPL (lockdep_init_map_type); +EXPORT_SYMBOL_GPL (__lockdep_init_map_type);struct lock_class_key __lockdep_no_validate__;EXPORT_SYMBOL_GPL (__lockdep_no_validate__);
@@ -6291,7 +6291,7 @@ void lockdep_reset_lock(struct lockdep_map *lock) }/* Unregister a dynamically allocated key. */ -void lockdep_unregister_key (struct lock_class_key *key) +void __lockdep_unregister_key (struct lock_class_key *key) {struct hlist_head *hash_head =keyhashentry (key);struct lock_class_key *k;
@@ -6326,7 +6326,7 @@ void lockdep_unregister_key(struct lock_class_key *key)/* Wait until is_dynamic_key() has finished accessing k->hash_entry. */ synchronize_rcu (); } -EXPORT_SYMBOL_GPL (lockdep_unregister_key); +EXPORT_SYMBOL_GPL (__lockdep_unregister_key);void __init lockdep_init (void ) {
Signature · 1 line
1.9.1
PATCH v2 4/18 dept: Add a API for skipping dependency check temporarily
In reply to Byungchul ParkDept would skip check for dmaps marked by dept_map_nocheck() permanently. However, sometimes it needs to skip check for some dmaps temporarily and back to normal, for instance, lock acquisition with a nest lock.
Lock usage check with regard to nest lock could be performed by Lockdep, however, dependency check is not necessary for that case. So prepared for it by adding two new APIs, dept_skip() and dept_unskip_if_skipped().
--- include/linux/dept.h | 9 +++++++++ include/linux/dept_sdt.h | 2 +- include/linux/lockdep.h | 4 +++- kernel/dependency/dept.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+), 2 deletions(-)
include/linux/dept.h +9 -0
@@ -352,6 +352,11 @@ struct dept_map {unsigned int wgen;/* +* for skipping dependency check temporarily +*/ +atomic_t skip_cnt; + +/* * whether this map should be going to be checked or not */ bool nocheck;
@@ -444,6 +449,8 @@ struct dept_task {extern void dept_ask_event (struct dept_map *m);extern void dept_event (struct dept_map *m,unsigned long e_f,unsigned long ip,const char *e_fn);extern void dept_ecxt_exit (struct dept_map *m,unsigned long ip); +extern void dept_skip (struct dept_map *m); +extern bool dept_unskip_if_skipped (struct dept_map *m);/* * for users who want to manage external keys
@@ -475,6 +482,8 @@ struct dept_task {#define dept_ask_event (m) do { } while (0)#define dept_event (m, e_f, ip, e_fn) do { (void)(e_fn); } while (0)#define dept_ecxt_exit (m, ip) do { } while (0) +#define dept_skip (m) do { } while (0) +#define dept_unskip_if_skipped (m) (false)#define dept_key_init (k) do { (void)(k); } while (0)#define dept_key_destroy (k) do { (void)(k); } while (0)#endif
include/linux/dept_sdt.h +1 -1
@@ -13,7 +13,7 @@#include <linux/dept.h> #ifdef CONFIG_DEPT -#define DEPT_SDT_MAP_INIT (dname) { .name = #dname } +#define DEPT_SDT_MAP_INIT (dname) { .name = #dname, .skip_cnt = ATOMIC_INIT(0) }/* * SDT(Single-event Dependency Tracker) APIs
include/linux/lockdep.h +3 -1
@@ -488,7 +488,9 @@ enum xhlock_context_t {*/ #define STATIC_DEPT_MAP_INIT (_name, _key) .dmap = { \ .name = (_name), \ - .keys = NULL }, + .keys = NULL, \ + .skip_cnt = ATOMIC_INIT(0), \ + },#else #define STATIC_DEPT_MAP_INIT (_name, _key)#endif
kernel/dependency/dept.c +49 -0
67 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 5/18 dept: Apply Dept to spinlock
In reply to Byungchul ParkMakes Dept able to track dependencies by spinlock.
--- include/linux/lockdep.h | 18 +++++++++++++++--- include/linux/spinlock.h | 26 ++++++++++++++++++++++++++ include/linux/spinlock_types_raw.h | 13 +++++++++++++ 3 files changed, 54 insertions(+), 3 deletions(-)
include/linux/lockdep.h +15 -3
@@ -584,9 +584,21 @@ static inline void print_irqtrace_events(struct task_struct *curr)#define lock_acquire_shared (l, s, t, n, i) lock_acquire(l, s, t, 1, 1, n, i)#define lock_acquire_shared_recursive (l, s, t, n, i) lock_acquire(l, s, t, 2, 1, n, i) -#define spin_acquire (l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) -#define spin_acquire_nest (l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i) -#define spin_release (l, i) lock_release(l, i) +#define spin_acquire (l, s, t, i) \ +do { \ + lock_acquire_exclusive(l, s, t, NULL, i); \ + dept_spin_lock(&(l)->dmap, s, t, NULL, "spin_unlock", i); \ +} while (0) +#define spin_acquire_nest (l, s, t, n, i) \ +do { \ + lock_acquire_exclusive(l, s, t, n, i); \ + dept_spin_lock(&(l)->dmap, s, t, (n) ? &(n)->dmap : NULL, "spin_unlock", i); \ +} while (0) +#define spin_release (l, i) \ +do { \ + lock_release(l, i); \ + dept_spin_unlock(&(l)->dmap, i); \ +} while (0)#define rwlock_acquire (l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)#define rwlock_acquire_read (l, s, t, i) \
include/linux/spinlock.h +26 -0
@@ -95,6 +95,32 @@# include <linux/spinlock_up.h> #endif +#ifdef CONFIG_DEPT +#define dept_spin_lock (m, ne, t, n, e_fn, ip) \ +do { \ + if (t) { \ + dept_ecxt_enter(m, 1UL, ip, __func__, e_fn, ne); \ + dept_ask_event(m); \ + } else if (n) { \ + dept_skip(m); \ + } else { \ + dept_wait(m, 1UL, ip, __func__, ne); \ + dept_ecxt_enter(m, 1UL, ip, __func__, e_fn, ne); \ + dept_ask_event(m); \ + } \ +} while (0) +#define dept_spin_unlock (m, ip) \ +do { \ + if (!dept_unskip_if_skipped(m)) { \ + dept_event(m, 1UL, ip, __func__); \ + dept_ecxt_exit(m, ip); \ + } \ +} while (0) +#else +#define dept_spin_lock (m, ne, t, n, e_fn, ip) do { } while (0) +#define dept_spin_unlock (m, ip) do { } while (0) +#endif +#ifdef CONFIG_DEBUG_SPINLOCK extern void __raw_spin_lock_init (raw_spinlock_t *lock,const char *name,struct lock_class_key *key,short inner);
include/linux/spinlock_types_raw.h +13 -0
@@ -26,16 +26,28 @@#define SPINLOCK_OWNER_INIT ((void *)-1L) +#ifdef CONFIG_DEPT +# define RAW_SPIN_DMAP_INIT (lockname) .dmap = { .name = #lockname, .skip_cnt = ATOMIC_INIT(0) }, +# define SPIN_DMAP_INIT (lockname) .dmap = { .name = #lockname, .skip_cnt = ATOMIC_INIT(0) }, +# define LOCAL_SPIN_DMAP_INIT (lockname) .dmap = { .name = #lockname, .skip_cnt = ATOMIC_INIT(0) }, +#else +# define RAW_SPIN_DMAP_INIT (lockname) +# define SPIN_DMAP_INIT (lockname) +# define LOCAL_SPIN_DMAP_INIT (lockname) +#endif +#ifdef CONFIG_DEBUG_LOCK_ALLOC # define RAW_SPIN_DEP_MAP_INIT (lockname) \ .dep_map = { \ .name = #lockname, \ .wait_type_inner = LD_WAIT_SPIN, \ + RAW_SPIN_DMAP_INIT(lockname) \ }# define SPIN_DEP_MAP_INIT (lockname) \ .dep_map = { \ .name = #lockname, \ .wait_type_inner = LD_WAIT_CONFIG, \ + SPIN_DMAP_INIT(lockname) \ }# define LOCAL_SPIN_DEP_MAP_INIT (lockname) \
@@ -43,6 +55,7 @@ .name = #lockname, \ .wait_type_inner = LD_WAIT_CONFIG, \ .lock_type = LD_LOCK_PERCPU, \ + LOCAL_SPIN_DMAP_INIT(lockname) \ }#else # define RAW_SPIN_DEP_MAP_INIT (lockname)
Signature · 1 line
1.9.1
PATCH v2 6/18 dept: Apply Dept to mutex families
In reply to Byungchul ParkMakes Dept able to track dependencies by mutex families.
--- include/linux/lockdep.h | 18 +++++++++++++++--- include/linux/mutex.h | 33 +++++++++++++++++++++++++++++++++ include/linux/rtmutex.h | 7 +++++++ 3 files changed, 55 insertions(+), 3 deletions(-)
include/linux/lockdep.h +15 -3
@@ -615,9 +615,21 @@ static inline void print_irqtrace_events(struct task_struct *curr)#define seqcount_acquire_read (l, s, t, i) lock_acquire_shared_recursive(l, s, t, NULL, i)#define seqcount_release (l, i) lock_release(l, i) -#define mutex_acquire (l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) -#define mutex_acquire_nest (l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i) -#define mutex_release (l, i) lock_release(l, i) +#define mutex_acquire (l, s, t, i) \ +do { \ + lock_acquire_exclusive(l, s, t, NULL, i); \ + dept_mutex_lock(&(l)->dmap, s, t, NULL, "mutex_unlock", i); \ +} while (0) +#define mutex_acquire_nest (l, s, t, n, i) \ +do { \ + lock_acquire_exclusive(l, s, t, n, i); \ + dept_mutex_lock(&(l)->dmap, s, t, (n) ? &(n)->dmap : NULL, "mutex_unlock", i);\ +} while (0) +#define mutex_release (l, i) \ +do { \ + lock_release(l, i); \ + dept_mutex_unlock(&(l)->dmap, i); \ +} while (0)#define rwsem_acquire (l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)#define rwsem_acquire_nest (l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i)
include/linux/mutex.h +33 -0
@@ -20,11 +20,18 @@#include <linux/osq_lock.h> #include <linux/debug_locks.h> +#ifdef CONFIG_DEPT +# define DMAP_MUTEX_INIT (lockname) .dmap = { .name = #lockname, .skip_cnt = ATOMIC_INIT(0) }, +#else +# define DMAP_MUTEX_INIT (lockname) +#endif +#ifdef CONFIG_DEBUG_LOCK_ALLOC # define __DEP_MAP_MUTEX_INITIALIZER (lockname) \ , .dep_map = { \ .name = #lockname, \ .wait_type_inner = LD_WAIT_SLEEP, \ + DMAP_MUTEX_INIT(lockname) \ }#else # define __DEP_MAP_MUTEX_INITIALIZER (lockname)
@@ -75,6 +82,32 @@ struct mutex {#endif }; +#ifdef CONFIG_DEPT +#define dept_mutex_lock (m, ne, t, n, e_fn, ip) \ +do { \ + if (t) { \ + dept_ecxt_enter(m, 1UL, ip, __func__, e_fn, ne); \ + dept_ask_event(m); \ + } else if (n) { \ + dept_skip(m); \ + } else { \ + dept_wait(m, 1UL, ip, __func__, ne); \ + dept_ecxt_enter(m, 1UL, ip, __func__, e_fn, ne); \ + dept_ask_event(m); \ + } \ +} while (0) +#define dept_mutex_unlock (m, ip) \ +do { \ + if (!dept_unskip_if_skipped(m)) { \ + dept_event(m, 1UL, ip, __func__); \ + dept_ecxt_exit(m, ip); \ + } \ +} while (0) +#else +#define dept_mutex_lock (m, ne, t, n, e_fn, ip) do { } while (0) +#define dept_mutex_unlock (m, ip) do { } while (0) +#endif +#ifdef CONFIG_DEBUG_MUTEXES #define __DEBUG_MUTEX_INITIALIZER (lockname) \
include/linux/rtmutex.h +7 -0
@@ -76,11 +76,18 @@ static inline void rt_mutex_debug_task_free(struct task_struct *tsk) { }__rt_mutex_init (mutex, __func__, &__key); \ } while (0) +#ifdef CONFIG_DEPT +#define DMAP_RT_MUTEX_INIT (mutexname) .dmap = { .name = #mutexname, .skip_cnt = ATOMIC_INIT(0) }, +#else +#define DMAP_RT_MUTEX_INIT (mutexname) +#endif +#ifdef CONFIG_DEBUG_LOCK_ALLOC #define __DEP_MAP_RT_MUTEX_INITIALIZER (mutexname) \ .dep_map = { \ .name = #mutexname, \ .wait_type_inner = LD_WAIT_SLEEP, \ + DMAP_RT_MUTEX_INIT(mutexname) \ }#else #define __DEP_MAP_RT_MUTEX_INITIALIZER (mutexname)
Signature · 1 line
1.9.1
PATCH v2 7/18 dept: Apply Dept to rwlock
In reply to Byungchul ParkMakes Dept able to track dependencies by rwlock.
--- include/linux/lockdep.h | 25 ++++++++++++++++---- include/linux/rwlock.h | 52 ++++++++++++++++++++++++++++++++++++++++++ include/linux/rwlock_api_smp.h | 8 +++---- include/linux/rwlock_types.h | 7 ++++++ 4 files changed, 83 insertions(+), 9 deletions(-)
include/linux/lockdep.h +20 -5
@@ -600,16 +600,31 @@ static inline void print_irqtrace_events(struct task_struct *curr)dept_spin_unlock (&(l)->dmap, i); \ } while (0) -#define rwlock_acquire (l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) +#define rwlock_acquire (l, s, t, i) \ +do { \ + lock_acquire_exclusive(l, s, t, NULL, i); \ + dept_rwlock_wlock(&(l)->dmap, s, t, NULL, "write_unlock", i); \ +} while (0)#define rwlock_acquire_read (l, s, t, i) \ do { \ - if (read_lock_is_recursive()) \ + if (read_lock_is_recursive()) { \ lock_acquire_shared_recursive(l, s, t, NULL, i); \ - else \ + dept_rwlock_rlock(&(l)->dmap, s, t, NULL, "read_unlock", i, 0);\ + } else { \ lock_acquire_shared(l, s, t, NULL, i); \ + dept_rwlock_rlock(&(l)->dmap, s, t, NULL, "read_unlock", i, 1);\ + } \ +} while (0) +#define rwlock_release (l, i) \ +do { \ + lock_release(l, i); \ + dept_rwlock_wunlock(&(l)->dmap, i); \ +} while (0) +#define rwlock_release_read (l, i) \ +do { \ + lock_release(l, i); \ + dept_rwlock_runlock(&(l)->dmap, i); \ } while (0) - -#define rwlock_release (l, i) lock_release(l, i)#define seqcount_acquire (l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i)#define seqcount_acquire_read (l, s, t, i) lock_acquire_shared_recursive(l, s, t, NULL, i)
include/linux/rwlock.h +52 -0
58 lines not on this page · raw message
include/linux/rwlock_api_smp.h +4 -4
@@ -228,7 +228,7 @@ static inline void __raw_write_unlock(rwlock_t *lock)static inline void __raw_read_unlock (rwlock_t *lock) { -rwlock_release (&lock->dep_map, _RET_IP_); +rwlock_release_read (&lock->dep_map, _RET_IP_);do_raw_read_unlock (lock);preempt_enable (); }
@@ -236,7 +236,7 @@ static inline void __raw_read_unlock(rwlock_t *lock)static inline void __raw_read_unlock_irqrestore (rwlock_t *lock,unsigned long flags) { -rwlock_release (&lock->dep_map, _RET_IP_); +rwlock_release_read (&lock->dep_map, _RET_IP_);do_raw_read_unlock (lock);local_irq_restore (flags);preempt_enable ();
@@ -244,7 +244,7 @@ static inline void __raw_read_unlock(rwlock_t *lock)static inline void __raw_read_unlock_irq (rwlock_t *lock) { -rwlock_release (&lock->dep_map, _RET_IP_); +rwlock_release_read (&lock->dep_map, _RET_IP_);do_raw_read_unlock (lock);local_irq_enable ();preempt_enable ();
@@ -252,7 +252,7 @@ static inline void __raw_read_unlock_irq(rwlock_t *lock)static inline void __raw_read_unlock_bh (rwlock_t *lock) { -rwlock_release (&lock->dep_map, _RET_IP_); +rwlock_release_read (&lock->dep_map, _RET_IP_);do_raw_read_unlock (lock);__local_bh_enable_ip (_RET_IP_,SOFTIRQ_LOCK_OFFSET ); }
include/linux/rwlock_types.h +7 -0
@@ -5,11 +5,18 @@# error "Do not include directly, include spinlock_types.h"#endif +#ifdef CONFIG_DEPT +# define RW_DMAP_INIT (lockname) .dmap = { .name = #lockname, .skip_cnt = ATOMIC_INIT(0) }, +#else +# define RW_DMAP_INIT (lockname) +#endif +#ifdef CONFIG_DEBUG_LOCK_ALLOC # define RW_DEP_MAP_INIT (lockname) \ .dep_map = { \ .name = #lockname, \ .wait_type_inner = LD_WAIT_CONFIG, \ + RW_DMAP_INIT(lockname) \ }#else # define RW_DEP_MAP_INIT (lockname)
Signature · 1 line
1.9.1
PATCH v2 8/18 dept: Apply Dept to wait_for_completion()/complete()
In reply to Byungchul ParkMakes Dept able to track dependencies by
wait_for_completion()/complete().
--- include/linux/completion.h | 42 ++++++++++++++++++++++++++++++++++++++++-- kernel/sched/completion.c | 12 ++++++++++-- 2 files changed, 50 insertions(+), 4 deletions(-)
include/linux/completion.h +40 -2
@@ -26,14 +26,48 @@struct completion {unsigned int done;struct swait_queue_head wait; +struct dept_map dmap; }; +#ifdef CONFIG_DEPT +#define dept_wfc_init (m, k, s, n) dept_map_init(m, k, s, n) +#define dept_wfc_reinit (m) dept_map_reinit(m) +#define dept_wfc_wait (m, ip) \ +do { \ + dept_ask_event(m); \ + dept_wait(m, 1UL, ip, __func__, 0); \ +} while (0) +#define dept_wfc_complete (m, ip) dept_event(m, 1UL, ip, __func__) +#define dept_wfc_enter (m, ip) dept_ecxt_enter(m, 1UL, ip, "completion_context_enter", "complete", 0) +#define dept_wfc_exit (m, ip) dept_ecxt_exit(m, ip) +#else +#define dept_wfc_init (m, k, s, n) do { (void)(n); (void)(k); } while (0) +#define dept_wfc_reinit (m) do { } while (0) +#define dept_wfc_wait (m, ip) do { } while (0) +#define dept_wfc_complete (m, ip) do { } while (0) +#define dept_wfc_enter (m, ip) do { } while (0) +#define dept_wfc_exit (m, ip) do { } while (0) +#endif + +#ifdef CONFIG_DEPT +#define WFC_DEPT_MAP_INIT (work) .dmap = { .name = #work, .skip_cnt = ATOMIC_INIT(0) } +#else +#define WFC_DEPT_MAP_INIT (work) +#endif + +#define init_completion (x) \ + do { \ + static struct dept_key __dkey; \ + __init_completion(x, &__dkey, #x); \ + } while (0) +#define init_completion_map (x, m) init_completion(x)static inline void complete_acquire (struct completion *x) {}static inline void complete_release (struct completion *x) {}#define COMPLETION_INITIALIZER (work) \ - { 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait) } + { 0, __SWAIT_QUEUE_HEAD_INITIALIZER((work).wait), \ + WFC_DEPT_MAP_INIT(work) }#define COMPLETION_INITIALIZER_ONSTACK_MAP (work, map) \ (*({ init_completion_map(&(work), &(map)); &(work); }))
@@ -81,9 +115,12 @@ static inline void complete_release(struct completion *x) {}* This inline function will initialize a dynamically created completion * structure. */ -static inline void init_completion (struct completion *x) +static inline void __init_completion (struct completion *x, +struct dept_key *dkey, +const char *name) { x->done =0 ; +dept_wfc_init (&x->dmap, dkey,0 , name);init_swait_queue_head (&x->wait); }
@@ -97,6 +134,7 @@ static inline void init_completion(struct completion *x)static inline void reinit_completion (struct completion *x) { x->done =0 ; +dept_wfc_reinit (&x->dmap); }extern void wait_for_completion (struct completion *);
kernel/sched/completion.c +10 -2
@@ -29,6 +29,7 @@ void complete(struct completion *x) {unsigned long flags; +dept_wfc_complete (&x->dmap, _RET_IP_);raw_spin_lock_irqsave (&x->wait.lock, flags);if (x->done !=UINT_MAX )
@@ -58,6 +59,7 @@ void complete_all(struct completion *x) {unsigned long flags; +dept_wfc_complete (&x->dmap, _RET_IP_);lockdep_assert_RT_in_threaded_ctx ();raw_spin_lock_irqsave (&x->wait.lock, flags);
@@ -112,17 +114,23 @@ void complete_all(struct completion *x) }static long __sched -wait_for_common (struct completion *x,long timeout,int state) +_wait_for_common (struct completion *x,long timeout,int state) {return __wait_for_common (x, schedule_timeout, timeout, state); }static long __sched -wait_for_common_io (struct completion *x,long timeout,int state) +_wait_for_common_io (struct completion *x,long timeout,int state) {return __wait_for_common (x, io_schedule_timeout, timeout, state); } +#define wait_for_common (x, t, s) \ +({ dept_wfc_wait(&(x)->dmap, _RET_IP_); _wait_for_common(x, t, s); }) + +#define wait_for_common_io (x, t, s) \ +({ dept_wfc_wait(&(x)->dmap, _RET_IP_); _wait_for_common_io(x, t, s); }) +/** * wait_for_completion: - waits for completion of a task * @x: holds the state of this particular completion
Signature · 1 line
1.9.1
kernel test robot
build botRe: [PATCH v2 08/18] dept: Apply Dept to wait_for_completion()/complete()
Thank you for the patch! Perhaps something to improve:
Hi Byungchul,
Thank you for the patch! Perhaps something to improve:
[auto build test WARNING on tip/sched/core]
[also build test WARNING on linux/master linus/master v5.17-rc5] [cannot apply to tip/locking/core hnaz-mm/master next-20220217] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Byungchul-Park/DEPT-Dependency-Tracker/20220220-185528 base: https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git ed3b362d54f0038cafc985248350d301af7af686 reproduce: make htmldocs
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> include/linux/completion.h:121: warning: expecting prototype for init_completion(). Prototype was for __init_completion() instead
vim +121 include/linux/completion.h
8b3db9c542e18b7 Ingo Molnar 2006-07-03 110
65eb3dc609dec17 Kevin Diggs 2008-08-26 111 /**
ee2f154a598e96d Randy Dunlap 2010-10-26 112 * init_completion - Initialize a dynamically allocated completion
c32f74ab2872994 Wolfram Sang 2013-11-14 113 * @x: pointer to completion structure that is to be initialized
65eb3dc609dec17 Kevin Diggs 2008-08-26 114 *
65eb3dc609dec17 Kevin Diggs 2008-08-26 115 * This inline function will initialize a dynamically created completion
65eb3dc609dec17 Kevin Diggs 2008-08-26 116 * structure.
65eb3dc609dec17 Kevin Diggs 2008-08-26 117 */
82b6a46bab5dcb0 Byungchul Park 2022-02-19 118 static inline void __init_completion(struct completion *x,
82b6a46bab5dcb0 Byungchul Park 2022-02-19 119 struct dept_key *dkey,
82b6a46bab5dcb0 Byungchul Park 2022-02-19 120 const char *name)
^1da177e4c3f415 Linus Torvalds 2005-04-16 @121 {
^1da177e4c3f415 Linus Torvalds 2005-04-16 122 x->done = 0;
82b6a46bab5dcb0 Byungchul Park 2022-02-19 123 dept_wfc_init(&x->dmap, dkey, 0, name);
a5c6234e10280b3 Thomas Gleixner 2020-03-21 124 init_swait_queue_head(&x->wait);
^1da177e4c3f415 Linus Torvalds 2005-04-16 125 }
^1da177e4c3f415 Linus Torvalds 2005-04-16 126 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/[email protected]
PATCH v2 9/18 dept: Apply Dept to seqlock
In reply to Byungchul ParkMakes Dept able to track dependencies by seqlock with adding wait annotation on read side of seqlock.
--- include/linux/seqlock.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-)
include/linux/seqlock.h +58 -1
@@ -23,6 +23,25 @@#include <asm/processor.h> +#ifdef CONFIG_DEPT +#define DEPT_EVT_ALL ((1UL << DEPT_MAX_SUBCLASSES_EVT) - 1) +#define dept_seq_wait (m, ip) dept_wait(m, DEPT_EVT_ALL, ip, __func__, 0) +#define dept_seq_writebegin (m, ip) \ +do { \ + dept_ecxt_enter(m, 1UL, ip, __func__, "write_seqcount_end", 0);\ + dept_ask_event(m); \ +} while (0) +#define dept_seq_writeend (m, ip) \ +do { \ + dept_event(m, 1UL, ip, __func__); \ + dept_ecxt_exit(m, ip); \ +} while (0) +#else +#define dept_seq_wait (m, ip) do { } while (0) +#define dept_seq_writebegin (m, ip) do { } while (0) +#define dept_seq_writeend (m, ip) do { } while (0) +#endif +/* * The seqlock seqcount_t interface does not prescribe a precise sequence of * read begin/retry/end. For readers, typically there is a call to
@@ -148,7 +167,7 @@ static inline void seqcount_lockdep_reader_access(const seqcount_t *s)* This lock-unlock technique must be implemented for all of PREEMPT_RT * sleeping locks. See Documentation/locking/locktypes.rst */ -#if defined(CONFIG_LOCKDEP ) || defined(CONFIG_PREEMPT_RT ) +#if defined(CONFIG_LOCKDEP ) || defined(CONFIG_DEPT ) || defined(CONFIG_PREEMPT_RT )#define __SEQ_LOCK (expr) expr#else #define __SEQ_LOCK (expr)
@@ -203,6 +222,22 @@ static inline void seqcount_lockdep_reader_access(const seqcount_t *s)__SEQ_LOCK (locktype *lock); \ } seqcount_##lockname##_t; \ \ +static __always_inline void \ +__seqprop_##lockname##_wait(const seqcount_##lockname##_t *s) \ +{ \ + __SEQ_LOCK(dept_seq_wait(&(lockmember)->dep_map.dmap, _RET_IP_));\ +} \ + \ +static __always_inline void \ +__seqprop_##lockname##_writebegin(const seqcount_##lockname##_t *s) \ +{ \ +} \ + \ +static __always_inline void \ +__seqprop_##lockname##_writeend(const seqcount_##lockname##_t *s) \ +{ \ +} \ + \ static __always_inline seqcount_t * \ __seqprop_##lockname##_ptr(seqcount_##lockname##_t *s) \ { \
@@ -271,6 +306,21 @@ static inline void __seqprop_assert(const seqcount_t *s)lockdep_assert_preemption_disabled (); } +static inline void __seqprop_wait (seqcount_t *s) +{ +dept_seq_wait (&s->dep_map.dmap, _RET_IP_); +} + +static inline void __seqprop_writebegin (seqcount_t *s) +{ +dept_seq_writebegin (&s->dep_map.dmap, _RET_IP_); +} + +static inline void __seqprop_writeend (seqcount_t *s) +{ +dept_seq_writeend (&s->dep_map.dmap, _RET_IP_); +} +#define __SEQ_RT IS_ENABLED(CONFIG_PREEMPT_RT)SEQCOUNT_LOCKNAME (raw_spinlock, raw_spinlock_t, false, s->lock, raw_spin,raw_spin_lock (s->lock))
@@ -311,6 +361,9 @@ static inline void __seqprop_assert(const seqcount_t *s)#define seqprop_sequence (s) __seqprop(s, sequence)#define seqprop_preemptible (s) __seqprop(s, preemptible)#define seqprop_assert (s) __seqprop(s, assert) +#define seqprop_dept_wait (s) __seqprop(s, wait) +#define seqprop_dept_writebegin (s) __seqprop(s, writebegin) +#define seqprop_dept_writeend (s) __seqprop(s, writeend)/** * __read_seqcount_begin() - begin a seqcount_t read section w/o barrier
@@ -360,6 +413,7 @@ static inline void __seqprop_assert(const seqcount_t *s)#define read_seqcount_begin (s) \ ({ \ seqcount_lockdep_reader_access(seqprop_ptr(s)); \ + seqprop_dept_wait(s); \ raw_read_seqcount_begin(s); \ })
@@ -512,6 +566,7 @@ static inline void do_raw_write_seqcount_end(seqcount_t *s)preempt_disable (); \ \do_write_seqcount_begin_nested (seqprop_ptr (s), subclass); \ +seqprop_dept_writebegin (s); \ }while (0 ) static inline void do_write_seqcount_begin_nested(seqcount_t *s, int subclass)
@@ -538,6 +593,7 @@ static inline void do_write_seqcount_begin_nested(seqcount_t *s, int subclass)preempt_disable (); \ \do_write_seqcount_begin (seqprop_ptr (s)); \ +seqprop_dept_writebegin (s); \ }while (0 ) static inline void do_write_seqcount_begin(seqcount_t *s)
@@ -554,6 +610,7 @@ static inline void do_write_seqcount_begin(seqcount_t *s)*/ #define write_seqcount_end (s) \ do { \ + seqprop_dept_writeend(s); \ do_write_seqcount_end(seqprop_ptr(s)); \ \ if (seqprop_preemptible(s)) \
Signature · 1 line
1.9.1
PATCH v2 10/18 dept: Apply Dept to rwsem
In reply to Byungchul ParkMakes Dept able to track dependencies by rwsem.
--- include/linux/lockdep.h | 24 ++++++++++++++++++++---- include/linux/percpu-rwsem.h | 10 +++++++++- include/linux/rwsem.h | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 5 deletions(-)
include/linux/lockdep.h +20 -4
@@ -646,10 +646,26 @@ static inline void print_irqtrace_events(struct task_struct *curr)dept_mutex_unlock (&(l)->dmap, i); \ } while (0) -#define rwsem_acquire (l, s, t, i) lock_acquire_exclusive(l, s, t, NULL, i) -#define rwsem_acquire_nest (l, s, t, n, i) lock_acquire_exclusive(l, s, t, n, i) -#define rwsem_acquire_read (l, s, t, i) lock_acquire_shared(l, s, t, NULL, i) -#define rwsem_release (l, i) lock_release(l, i) +#define rwsem_acquire (l, s, t, i) \ +do { \ + lock_acquire_exclusive(l, s, t, NULL, i); \ + dept_rwsem_lock(&(l)->dmap, s, t, NULL, "up_write", i); \ +} while (0) +#define rwsem_acquire_nest (l, s, t, n, i) \ +do { \ + lock_acquire_exclusive(l, s, t, n, i); \ + dept_rwsem_lock(&(l)->dmap, s, t, (n) ? &(n)->dmap : NULL, "up_write", i);\ +} while (0) +#define rwsem_acquire_read (l, s, t, i) \ +do { \ + lock_acquire_shared(l, s, t, NULL, i); \ + dept_rwsem_lock(&(l)->dmap, s, t, NULL, "up_read", i); \ +} while (0) +#define rwsem_release (l, i) \ +do { \ + lock_release(l, i); \ + dept_rwsem_unlock(&(l)->dmap, i); \ +} while (0)#define lock_map_acquire (l) lock_acquire_exclusive(l, 0, 0, NULL, _THIS_IP_)#define lock_map_acquire_read (l) lock_acquire_shared_recursive(l, 0, 0, NULL, _THIS_IP_)
include/linux/percpu-rwsem.h +9 -1
@@ -20,8 +20,16 @@ struct percpu_rw_semaphore {#endif }; +#ifdef CONFIG_DEPT +#define __PERCPU_RWSEM_DMAP_INIT (lockname) .dmap = { .name = #lockname, .skip_cnt = ATOMIC_INIT(0) } +#else +#define __PERCPU_RWSEM_DMAP_INIT (lockname) +#endif +#ifdef CONFIG_DEBUG_LOCK_ALLOC -#define __PERCPU_RWSEM_DEP_MAP_INIT (lockname) .dep_map = { .name = #lockname }, +#define __PERCPU_RWSEM_DEP_MAP_INIT (lockname) .dep_map = { \ + .name = #lockname, \ + __PERCPU_RWSEM_DMAP_INIT(lockname) },#else #define __PERCPU_RWSEM_DEP_MAP_INIT (lockname)#endif
include/linux/rwsem.h +33 -0
@@ -16,11 +16,18 @@#include <linux/atomic.h> #include <linux/err.h> +#ifdef CONFIG_DEPT +# define RWSEM_DMAP_INIT (lockname) .dmap = { .name = #lockname, .skip_cnt = ATOMIC_INIT(0) }, +#else +# define RWSEM_DMAP_INIT (lockname) +#endif +#ifdef CONFIG_DEBUG_LOCK_ALLOC # define __RWSEM_DEP_MAP_INIT (lockname) \ .dep_map = { \ .name = #lockname, \ .wait_type_inner = LD_WAIT_SLEEP, \ + RWSEM_DMAP_INIT(lockname) \ },#else # define __RWSEM_DEP_MAP_INIT (lockname)
@@ -32,6 +39,32 @@#include <linux/osq_lock.h> #endif +#ifdef CONFIG_DEPT +#define dept_rwsem_lock (m, ne, t, n, e_fn, ip) \ +do { \ + if (t) { \ + dept_ecxt_enter(m, 1UL, ip, __func__, e_fn, ne); \ + dept_ask_event(m); \ + } else if (n) { \ + dept_skip(m); \ + } else { \ + dept_wait(m, 1UL, ip, __func__, ne); \ + dept_ecxt_enter(m, 1UL, ip, __func__, e_fn, ne); \ + dept_ask_event(m); \ + } \ +} while (0) +#define dept_rwsem_unlock (m, ip) \ +do { \ + if (!dept_unskip_if_skipped(m)) { \ + dept_event(m, 1UL, ip, __func__); \ + dept_ecxt_exit(m, ip); \ + } \ +} while (0) +#else +#define dept_rwsem_lock (m, ne, t, n, e_fn, ip) do { } while (0) +#define dept_rwsem_unlock (m, ip) do { } while (0) +#endif +/* * For an uncontended rwsem, count and owner are the only fields a task * needs to touch when acquiring the rwsem. So they are put next to each
Signature · 1 line
1.9.1
PATCH v2 11/18 dept: Add proc knobs to show stats and dependency graph
In reply to Byungchul ParkIt'd be useful to show Dept internal stats and dependency graph on runtime via proc for better information. Introduced the knobs.
--- kernel/dependency/Makefile | 1 + kernel/dependency/dept.c | 24 ++++------ kernel/dependency/dept_internal.h | 26 +++++++++++ kernel/dependency/dept_proc.c | 92 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 128 insertions(+), 15 deletions(-) create mode 100644 kernel/dependency/dept_internal.h create mode 100644 kernel/dependency/dept_proc.c
kernel/dependency/Makefile +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_DEPT) += dept.o +obj-$(CONFIG_DEPT) += dept_proc.o
kernel/dependency/dept.c +9 -15
@@ -73,6 +73,7 @@#include <linux/hash.h> #include <linux/dept.h> #include <linux/utsname.h> +#include "dept_internal.h" static int dept_stop;static int dept_per_cpu_ready;
@@ -233,20 +234,13 @@ static inline struct dept_task *dept_task(void)* have been freed will be placed. */ -enum object_t { -#define OBJECT(id, nr) OBJECT_##id, -#include "dept_object.h" -#undef OBJECT - OBJECT_NR, -}; -#define OBJECT (id, nr) \ static struct dept_##id spool_##id[nr]; \ static DEFINE_PER_CPU(struct llist_head, lpool_##id);#include "dept_object.h" #undef OBJECT -static struct dept_pool pool[OBJECT_NR] = { +struct dept_pool dept_pool[OBJECT_NR] = { #define OBJECT(id, nr) { \ .name = #id, \ .obj_sz = sizeof(struct dept_##id), \
@@ -276,7 +270,7 @@ static void *from_pool(enum object_t t)if (DEPT_WARN_ON (!irqs_disabled ()))return NULL ; - p = &pool[t]; + p = &dept_pool[t];/* * Try local pool first.
@@ -306,7 +300,7 @@ static void *from_pool(enum object_t t)static void to_pool (void *o,enum object_t t) { -struct dept_pool *p = &pool[t]; +struct dept_pool *p = &dept_pool[t];struct llist_head *h;preempt_disable ();
@@ -1984,7 +1978,7 @@ void dept_map_nocheck(struct dept_map *m) }EXPORT_SYMBOL_GPL (dept_map_nocheck); -static LIST_HEAD (classes); +LIST_HEAD (dept_classes);static inline bool within (const void *addr,void *start,unsigned long size) {
@@ -2011,7 +2005,7 @@ void dept_free_range(void *start, unsigned int sz)while (unlikely (!dept_lock ()))cpu_relax (); -list_for_each_entry_safe (c, n, &classes, all_node) { +list_for_each_entry_safe (c, n, &dept_classes, all_node) {if (!within ((void *)c->key, start, sz) && !within (c->name, start, sz))continue ;
@@ -2080,7 +2074,7 @@ static struct dept_class *check_new_class(struct dept_key *local, c->sub = sub; c->key = (unsigned long )(k->subkeys + sub);hash_add_class (c); -list_add (&c->all_node, &classes); +list_add (&c->all_node, &dept_classes); unlock:dept_unlock (); caching:
@@ -2535,8 +2529,8 @@ static void migrate_per_cpu_pool(void)struct llist_head *from;struct llist_head *to; - from = &pool[i].boot_pool; - to =per_cpu_ptr (pool[i].lpool, boot_cpu); + from = &dept_pool[i].boot_pool; + to =per_cpu_ptr (dept_pool[i].lpool, boot_cpu);move_llist (to, from); } }
kernel/dependency/dept_internal.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Dept(DEPendency Tracker) - runtime dependency tracker internal header +* +* Started by Byungchul Park <[email protected]>: +* +* Copyright (c) 2020 LG Electronics, Inc., Byungchul Park +*/ + +#ifndef __DEPT_INTERNAL_H +#define __DEPT_INTERNAL_H + +#ifdef CONFIG_DEPT + +enum object_t { +#define OBJECT(id, nr) OBJECT_##id, +#include "dept_object.h" +#undef OBJECT + OBJECT_NR, +}; + +extern struct list_head dept_classes; +extern struct dept_pool dept_pool[]; + +#endif +#endif /* __DEPT_INTERNAL_H */
kernel/dependency/dept_proc.c new file +92 -0
92 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 12/18 dept: Introduce split map concept and new APIs for them
In reply to Byungchul ParkThere is a case where all maps used for a type of wait/event is so large in size. For instance, struct page can be a type for (un)lock_page(). The additional memory size for the maps would be 'the # of pages * sizeof(struct dept_map)' if each struct page keeps its map all the way, which might be too big to accept in some system.
It'd better to have split map, one is for each instance and the other is for the type which is commonly used, and new APIs using them. So introduced split map and new APIs for them.
--- include/linux/dept.h | 80 ++++++++++++++++++++++--------- kernel/dependency/dept.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 180 insertions(+), 22 deletions(-)
include/linux/dept.h +58 -22
@@ -362,6 +362,30 @@ struct dept_map {bool nocheck; }; +struct dept_map_each { +/* +* wait timestamp associated to this map +*/ +unsigned int wgen; +}; + +struct dept_map_common { +const char *name; +struct dept_key *keys; +int sub_usr; + +/* +* It's local copy for fast acces to the associated classes. And +* Also used for dept_key instance for statically defined map. +*/ +struct dept_key keys_local; + +/* +* whether this map should be going to be checked or not +*/ +bool nocheck; +}; +struct dept_task {/* * all event contexts that have entered and before exiting
@@ -451,6 +475,11 @@ struct dept_task {extern void dept_ecxt_exit (struct dept_map *m,unsigned long ip);extern void dept_skip (struct dept_map *m);extern bool dept_unskip_if_skipped (struct dept_map *m); +extern void dept_split_map_each_init (struct dept_map_each *me); +extern void dept_split_map_common_init (struct dept_map_common *mc,struct dept_key *k,const char *n); +extern void dept_wait_split_map (struct dept_map_each *me,struct dept_map_common *mc,unsigned long ip,const char *w_fn,int ne); +extern void dept_event_split_map (struct dept_map_each *me,struct dept_map_common *mc,unsigned long ip,const char *e_fn); +extern void dept_ask_event_split_map (struct dept_map_each *me,struct dept_map_common *mc);/* * for users who want to manage external keys
@@ -460,31 +489,38 @@ struct dept_task {#else /* !CONFIG_DEPT */ struct dept_key { };struct dept_map { }; +struct dept_map_each { }; +struct dept_map_commmon { };struct dept_task { };#define DEPT_TASK_INITIALIZER (t) -#define dept_on () do { } while (0) -#define dept_off () do { } while (0) -#define dept_init () do { } while (0) -#define dept_task_init (t) do { } while (0) -#define dept_task_exit (t) do { } while (0) -#define dept_free_range (s, sz) do { } while (0) -#define dept_map_init (m, k, s, n) do { (void)(n); (void)(k); } while (0) -#define dept_map_reinit (m) do { } while (0) -#define dept_map_nocheck (m) do { } while (0) - -#define dept_wait (m, w_f, ip, w_fn, ne) do { (void)(w_fn); } while (0) -#define dept_stage_wait (m, w_f, w_fn, ne) do { (void)(w_fn); } while (0) -#define dept_ask_event_wait_commit (ip) do { } while (0) -#define dept_clean_stage () do { } while (0) -#define dept_ecxt_enter (m, e_f, ip, c_fn, e_fn, ne) do { (void)(c_fn); (void)(e_fn); } while (0) -#define dept_ask_event (m) do { } while (0) -#define dept_event (m, e_f, ip, e_fn) do { (void)(e_fn); } while (0) -#define dept_ecxt_exit (m, ip) do { } while (0) -#define dept_skip (m) do { } while (0) -#define dept_unskip_if_skipped (m) (false) -#define dept_key_init (k) do { (void)(k); } while (0) -#define dept_key_destroy (k) do { (void)(k); } while (0) +#define dept_on () do { } while (0) +#define dept_off () do { } while (0) +#define dept_init () do { } while (0) +#define dept_task_init (t) do { } while (0) +#define dept_task_exit (t) do { } while (0) +#define dept_free_range (s, sz) do { } while (0) +#define dept_map_init (m, k, s, n) do { (void)(n); (void)(k); } while (0) +#define dept_map_reinit (m) do { } while (0) +#define dept_map_nocheck (m) do { } while (0) + +#define dept_wait (m, w_f, ip, w_fn, ne) do { (void)(w_fn); } while (0) +#define dept_stage_wait (m, w_f, w_fn, ne) do { (void)(w_fn); } while (0) +#define dept_ask_event_wait_commit (ip) do { } while (0) +#define dept_clean_stage () do { } while (0) +#define dept_ecxt_enter (m, e_f, ip, c_fn, e_fn, ne) do { (void)(c_fn); (void)(e_fn); } while (0) +#define dept_ask_event (m) do { } while (0) +#define dept_event (m, e_f, ip, e_fn) do { (void)(e_fn); } while (0) +#define dept_ecxt_exit (m, ip) do { } while (0) +#define dept_skip (m) do { } while (0) +#define dept_unskip_if_skipped (m) (false) +#define dept_split_map_each_init (me) do { } while (0) +#define dept_split_map_common_init (mc, k, n) do { (void)(n); (void)(k); } while (0) +#define dept_wait_split_map (me, mc, ip, w_fn, ne) do { } while (0) +#define dept_event_split_map (me, mc, ip, e_fn) do { } while (0) +#define dept_ask_event_split_map (me, mc) do { } while (0) +#define dept_key_init (k) do { (void)(k); } while (0) +#define dept_key_destroy (k) do { (void)(k); } while (0)#endif #endif /* __LINUX_DEPT_H */
kernel/dependency/dept.c +122 -0
128 lines not on this page · raw message
Signature · 1 line
1.9.1
PATCH v2 13/18 dept: Apply Dept to wait/event of PG_{locked,writeback}
In reply to Byungchul ParkMakes Dept able to track dependencies by PG_{locked,writeback}. For instance, (un)lock_page() generates that type of dependency.
--- include/linux/dept_page.h | 78 +++++++++++++++++++++++++++++++++++++++++ include/linux/page-flags.h | 45 ++++++++++++++++++++++-- include/linux/pagemap.h | 7 +++- init/main.c | 2 ++ kernel/dependency/dept_object.h | 2 +- lib/Kconfig.debug | 1 + mm/filemap.c | 68 +++++++++++++++++++++++++++++++++++ mm/page_ext.c | 5 +++ 8 files changed, 204 insertions(+), 4 deletions(-) create mode 100644 include/linux/dept_page.h
include/linux/dept_page.h new file +78 -0
@@ -0,0 +1,78 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_DEPT_PAGE_H +#define __LINUX_DEPT_PAGE_H + +#ifdef CONFIG_DEPT +#include <linux/dept.h> + +extern struct page_ext_operations dept_pglocked_ops; +extern struct page_ext_operations dept_pgwriteback_ops; +extern struct dept_map_common pglocked_mc; +extern struct dept_map_common pgwriteback_mc; + +extern void dept_page_init (void ); +extern struct dept_map_each *get_pglocked_me (struct page *page); +extern struct dept_map_each *get_pgwriteback_me (struct page *page); + +#define dept_pglocked_wait (f) \ +do { \ + struct dept_map_each *me = get_pglocked_me(&(f)->page); \ + \ + if (likely(me)) \ + dept_wait_split_map(me, &pglocked_mc, _RET_IP_, \ + __func__, 0); \ +} while (0) + +#define dept_pglocked_set_bit (f) \ +do { \ + struct dept_map_each *me = get_pglocked_me(&(f)->page); \ + \ + if (likely(me)) \ + dept_ask_event_split_map(me, &pglocked_mc); \ +} while (0) + +#define dept_pglocked_event (f) \ +do { \ + struct dept_map_each *me = get_pglocked_me(&(f)->page); \ + \ + if (likely(me)) \ + dept_event_split_map(me, &pglocked_mc, _RET_IP_,\ + __func__); \ +} while (0) + +#define dept_pgwriteback_wait (f) \ +do { \ + struct dept_map_each *me = get_pgwriteback_me(&(f)->page);\ + \ + if (likely(me)) \ + dept_wait_split_map(me, &pgwriteback_mc, _RET_IP_,\ + __func__, 0); \ +} while (0) + +#define dept_pgwriteback_set_bit (f) \ +do { \ + struct dept_map_each *me = get_pgwriteback_me(&(f)->page);\ + \ + if (likely(me)) \ + dept_ask_event_split_map(me, &pgwriteback_mc);\ +} while (0) + +#define dept_pgwriteback_event (f) \ +do { \ + struct dept_map_each *me = get_pgwriteback_me(&(f)->page);\ + \ + if (likely(me)) \ + dept_event_split_map(me, &pgwriteback_mc, _RET_IP_,\ + __func__); \ +} while (0) +#else +#define dept_page_init () do { } while (0) +#define dept_pglocked_wait (f) do { } while (0) +#define dept_pglocked_set_bit (f) do { } while (0) +#define dept_pglocked_event (f) do { } while (0) +#define dept_pgwriteback_wait (f) do { } while (0) +#define dept_pgwriteback_set_bit (f) do { } while (0) +#define dept_pgwriteback_event (f) do { } while (0) +#endif + +#endif /* __LINUX_DEPT_PAGE_H */
include/linux/page-flags.h +43 -2
63 lines not on this page · raw message
include/linux/pagemap.h +6 -1
@@ -15,6 +15,7 @@#include <linux/bitops.h> #include <linux/hardirq.h> /* for in_interrupt() */ #include <linux/hugetlb_inline.h> +#include <linux/dept_page.h> struct folio_batch ;
@@ -761,7 +762,11 @@ bool __folio_lock_or_retry(struct folio *folio, struct mm_struct *mm,static inline bool folio_trylock (struct folio *folio) { -return likely (!test_and_set_bit_lock (PG_locked,folio_flags (folio,0 ))); +int ret =test_and_set_bit_lock (PG_locked,folio_flags (folio,0 )); + +if (likely (!ret)) +dept_pglocked_set_bit (folio); +return likely (!ret); }/*
init/main.c +2 -0
@@ -100,6 +100,7 @@#include <linux/kcsan.h> #include <linux/init_syscalls.h> #include <linux/stackdepot.h> +#include <linux/pagemap.h> #include <asm/io.h> #include <asm/bugs.h>
@@ -1072,6 +1073,7 @@ asmlinkage __visible void __init __no_sanitize_address start_kernel(void)lockdep_init ();dept_init (); +dept_page_init ();/* * Need to run this when irqs are enabled, because it wants
kernel/dependency/dept_object.h +1 -1
@@ -6,7 +6,7 @@* nr: # of the object that should be kept in the pool. */ -OBJECT(dep, 1024 * 8) +OBJECT(dep, 1024 * 16) OBJECT(class, 1024 * 4) OBJECT(stack, 1024 * 32)OBJECT (ecxt,1024 *4 )
lib/Kconfig.debug +1 -0
@@ -1242,6 +1242,7 @@ config DEPT select DEBUG_RWSEMS select DEBUG_WW_MUTEX_SLOWPATH select DEBUG_LOCK_ALLOC + select PAGE_EXTENSION select TRACE_IRQFLAGS select STACKTRACE select FRAME_POINTER if !MIPS && !PPC && !ARM && !S390 && !MICROBLAZE && !ARC && !X86
mm/filemap.c +68 -0
95 lines not on this page · raw message
mm/page_ext.c +5 -0
@@ -9,6 +9,7 @@#include <linux/page_owner.h> #include <linux/page_idle.h> #include <linux/page_table_check.h> +#include <linux/dept_page.h> /* * struct page extension
@@ -79,6 +80,10 @@ static bool need_page_idle(void)#ifdef CONFIG_PAGE_TABLE_CHECK &page_table_check_ops,#endif +#ifdef CONFIG_DEPT + &dept_pglocked_ops, + &dept_pgwriteback_ops, +#endif };unsigned long page_ext_size =sizeof (struct page_ext );
Signature · 1 line
1.9.1
PATCH v2 14/18 dept: Apply SDT to swait
In reply to Byungchul ParkMakes SDT able to track dependencies by swait.
--- include/linux/swait.h | 4 ++++ kernel/sched/swait.c | 10 ++++++++++ 2 files changed, 14 insertions(+)
include/linux/swait.h +4 -0
@@ -6,6 +6,7 @@#include <linux/stddef.h> #include <linux/spinlock.h> #include <linux/wait.h> +#include <linux/dept_sdt.h> #include <asm/current.h> /*
@@ -43,6 +44,7 @@struct swait_queue_head {raw_spinlock_t lock;struct list_head task_list; +struct dept_map dmap; };struct swait_queue {
@@ -61,6 +63,7 @@ struct swait_queue {#define __SWAIT_QUEUE_HEAD_INITIALIZER (name) { \ .lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \ .task_list = LIST_HEAD_INIT((name).task_list), \ + .dmap = DEPT_SDT_MAP_INIT(name), \ }#define DECLARE_SWAIT_QUEUE_HEAD (name) \
@@ -72,6 +75,7 @@ extern void __init_swait_queue_head(struct swait_queue_head *q, const char *name#define init_swait_queue_head (q) \ do { \ static struct lock_class_key __key; \ + sdt_map_init(&(q)->dmap); \ __init_swait_queue_head((q), #q, &__key); \ } while (0)
kernel/sched/swait.c +10 -0
@@ -27,6 +27,7 @@ void swake_up_locked(struct swait_queue_head *q)return ; curr =list_first_entry (&q->task_list,typeof (*curr), task_list); +sdt_event (&q->dmap);wake_up_process (curr->task);list_del_init (&curr->task_list); }
@@ -69,6 +70,7 @@ void swake_up_all(struct swait_queue_head *q)while (!list_empty (&tmp)) { curr =list_first_entry (&tmp,typeof (*curr), task_list); +sdt_event (&q->dmap);wake_up_state (curr->task,TASK_NORMAL );list_del_init (&curr->task_list);
@@ -97,6 +99,9 @@ void prepare_to_swait_exclusive(struct swait_queue_head *q, struct swait_queue *__prepare_to_swait (q, wait);set_current_state (state);raw_spin_unlock_irqrestore (&q->lock, flags); + +if (state &TASK_NORMAL ) +sdt_wait_prepare (&q->dmap); }EXPORT_SYMBOL (prepare_to_swait_exclusive);
@@ -119,12 +124,16 @@ long prepare_to_swait_event(struct swait_queue_head *q, struct swait_queue *wait }raw_spin_unlock_irqrestore (&q->lock, flags); +if (!ret && state &TASK_NORMAL ) +sdt_wait_prepare (&q->dmap); +return ret; }EXPORT_SYMBOL (prepare_to_swait_event);void __finish_swait (struct swait_queue_head *q,struct swait_queue *wait) { +sdt_wait_finish ();__set_current_state (TASK_RUNNING );if (!list_empty (&wait->task_list))list_del_init (&wait->task_list);
@@ -134,6 +143,7 @@ void finish_swait(struct swait_queue_head *q, struct swait_queue *wait) {unsigned long flags; +sdt_wait_finish ();__set_current_state (TASK_RUNNING );if (!list_empty_careful (&wait->task_list)) {
Signature · 1 line
1.9.1
PATCH v2 15/18 dept: Apply SDT to wait(waitqueue)
In reply to Byungchul ParkMakes SDT able to track dependencies by wait(waitqueue).
--- include/linux/wait.h | 6 +++++- kernel/sched/wait.c | 16 ++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-)
include/linux/wait.h +5 -1
@@ -7,6 +7,7 @@#include <linux/list.h> #include <linux/stddef.h> #include <linux/spinlock.h> +#include <linux/dept_sdt.h> #include <asm/current.h> #include <uapi/linux/wait.h>
@@ -37,6 +38,7 @@ struct wait_queue_entry {struct wait_queue_head {spinlock_t lock;struct list_head head; +struct dept_map dmap; };typedef struct wait_queue_head wait_queue_head_t ;
@@ -56,7 +58,8 @@ struct wait_queue_head {#define __WAIT_QUEUE_HEAD_INITIALIZER (name) { \ .lock = __SPIN_LOCK_UNLOCKED(name.lock), \ - .head = LIST_HEAD_INIT(name.head) } + .head = LIST_HEAD_INIT(name.head), \ + .dmap = DEPT_SDT_MAP_INIT(name) }#define DECLARE_WAIT_QUEUE_HEAD (name) \ struct wait_queue_head name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
@@ -67,6 +70,7 @@ struct wait_queue_head {do { \static struct lock_class_key __key; \ \ +sdt_map_init (&(wq_head)->dmap); \ __init_waitqueue_head((wq_head), #wq_head, &__key); \ }while (0 )
kernel/sched/wait.c +16 -0
@@ -105,6 +105,7 @@ static int __wake_up_common(struct wait_queue_head *wq_head, unsigned int mode,if (flags &WQ_FLAG_BOOKMARK )continue ; +sdt_event (&wq_head->dmap); ret = curr->func (curr, mode, wake_flags, key);if (ret <0 )break ;
@@ -268,6 +269,9 @@ void __wake_up_pollfree(struct wait_queue_head *wq_head)__add_wait_queue (wq_head, wq_entry);set_current_state (state);spin_unlock_irqrestore (&wq_head->lock, flags); + +if (state &TASK_NORMAL ) +sdt_wait_prepare (&wq_head->dmap); }EXPORT_SYMBOL (prepare_to_wait);
@@ -286,6 +290,10 @@ void __wake_up_pollfree(struct wait_queue_head *wq_head) }set_current_state (state);spin_unlock_irqrestore (&wq_head->lock, flags); + +if (state &TASK_NORMAL ) +sdt_wait_prepare (&wq_head->dmap); +return was_empty; }EXPORT_SYMBOL (prepare_to_wait_exclusive);
@@ -331,6 +339,9 @@ long prepare_to_wait_event(struct wait_queue_head *wq_head, struct wait_queue_en }spin_unlock_irqrestore (&wq_head->lock, flags); +if (!ret && state &TASK_NORMAL ) +sdt_wait_prepare (&wq_head->dmap); +return ret; }EXPORT_SYMBOL (prepare_to_wait_event);
@@ -352,7 +363,9 @@ int do_wait_intr(wait_queue_head_t *wq, wait_queue_entry_t *wait)return -ERESTARTSYS ;spin_unlock (&wq->lock); +sdt_wait_prepare (&wq->dmap);schedule (); +sdt_wait_finish ();spin_lock (&wq->lock);return 0 ;
@@ -369,7 +382,9 @@ int do_wait_intr_irq(wait_queue_head_t *wq, wait_queue_entry_t *wait)return -ERESTARTSYS ;spin_unlock_irq (&wq->lock); +sdt_wait_prepare (&wq->dmap);schedule (); +sdt_wait_finish ();spin_lock_irq (&wq->lock);return 0 ;
@@ -389,6 +404,7 @@ void finish_wait(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_en {unsigned long flags; +sdt_wait_finish ();__set_current_state (TASK_RUNNING );/* * We can check for list emptiness outside the lock
Signature · 1 line
1.9.1
PATCH v2 16/18 locking/lockdep, cpu/hotplus: Use a weaker annotation in AP thread
In reply to Byungchul Parkcb92173d1f0 (locking/lockdep, cpu/hotplug: Annotate AP thread) was introduced to make lockdep_assert_cpus_held() work in AP thread.
However, the annotation is too strong for that purpose. We don't have to use more than try lock annotation for that.
Furthermore, now that Dept was introduced, false positive alarms was reported by that. Replaced it with try lock annotation.
--- kernel/cpu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/cpu.c +1 -1
@@ -355,7 +355,7 @@ int lockdep_is_cpus_held(void)static void lockdep_acquire_cpus_lock (void ) { -rwsem_acquire (&cpu_hotplug_lock.dep_map,0 ,0 , _THIS_IP_); +rwsem_acquire (&cpu_hotplug_lock.dep_map,0 ,1 , _THIS_IP_); }static void lockdep_release_cpus_lock (void )
Signature · 1 line
1.9.1
PATCH v2 17/18 dept: Distinguish each syscall context from another
In reply to Byungchul ParkIt enters kernel mode on each syscall and each syscall handling should be considered independently from the point of view of Dept. Otherwise, Dept may wrongly track dependencies across different syscalls.
That might be a real dependency from user mode. However, now that Dept just started to work, conservatively let Dept not track dependencies across different syscalls.
--- include/linux/dept.h | 39 ++++++++++++++++------------ kernel/dependency/dept.c | 67 ++++++++++++++++++++++++------------------------ kernel/entry/common.c | 3 +++ 3 files changed, 60 insertions(+), 49 deletions(-)
include/linux/dept.h +23 -16
@@ -25,11 +25,16 @@#define DEPT_MAX_SUBCLASSES_USR (DEPT_MAX_SUBCLASSES / DEPT_MAX_SUBCLASSES_EVT)#define DEPT_MAX_SUBCLASSES_CACHE 2 -#define DEPT_SIRQ 0 -#define DEPT_HIRQ 1 -#define DEPT_IRQS_NR 2 -#define DEPT_SIRQF (1UL << DEPT_SIRQ) -#define DEPT_HIRQF (1UL << DEPT_HIRQ) +enum { +DEPT_CXT_SIRQ =0 , +DEPT_CXT_HIRQ , +DEPT_CXT_IRQS_NR , +DEPT_CXT_PROCESS =DEPT_CXT_IRQS_NR , +DEPT_CXTS_NR +}; + +#define DEPT_SIRQF (1UL << DEPT_CXT_SIRQ) +#define DEPT_HIRQF (1UL << DEPT_CXT_HIRQ)struct dept_ecxt ;struct dept_iecxt {
@@ -95,8 +100,8 @@ struct dept_class {/* * for tracking IRQ dependencies */ -struct dept_iecxt iecxt[DEPT_IRQS_NR ]; -struct dept_iwait iwait[DEPT_IRQS_NR ]; +struct dept_iecxt iecxt[DEPT_CXT_IRQS_NR ]; +struct dept_iwait iwait[DEPT_CXT_IRQS_NR ]; };struct dept_stack {
@@ -150,8 +155,8 @@ struct dept_ecxt {/* * where the IRQ-enabled happened */ -unsigned long enirq_ip[DEPT_IRQS_NR ]; -struct dept_stack *enirq_stack[DEPT_IRQS_NR ]; +unsigned long enirq_ip[DEPT_CXT_IRQS_NR ]; +struct dept_stack *enirq_stack[DEPT_CXT_IRQS_NR ];/* * where the event context started
@@ -194,8 +199,8 @@ struct dept_wait {/* * where the IRQ wait happened */ -unsigned long irq_ip[DEPT_IRQS_NR ]; -struct dept_stack *irq_stack[DEPT_IRQS_NR ]; +unsigned long irq_ip[DEPT_CXT_IRQS_NR ]; +struct dept_stack *irq_stack[DEPT_CXT_IRQS_NR ];/* * where the wait happened
@@ -400,19 +405,19 @@ struct dept_task {int wait_hist_pos;/* -* sequential id to identify each IRQ context +* sequential id to identify each context */ -unsigned int irq_id[DEPT_IRQS_NR ]; +unsigned int cxt_id[DEPT_CXTS_NR ];/* * for tracking IRQ-enabled points with cross-event */ -unsigned int wgen_enirq[DEPT_IRQS_NR ]; +unsigned int wgen_enirq[DEPT_CXT_IRQS_NR ];/* * for keeping up-to-date IRQ-enabled points */ -unsigned long enirq_ip[DEPT_IRQS_NR ]; +unsigned long enirq_ip[DEPT_CXT_IRQS_NR ];/* * current effective IRQ-enabled flag
@@ -448,7 +453,7 @@ struct dept_task { .dept_task.wait_hist = { { .wait = NULL, } }, \ .dept_task.ecxt_held_pos = 0, \ .dept_task.wait_hist_pos = 0, \ - .dept_task.irq_id = { 0 }, \ + .dept_task.cxt_id = { 0 }, \ .dept_task.wgen_enirq = { 0 }, \ .dept_task.enirq_ip = { 0 }, \ .dept_task.recursive = 0, \
@@ -480,6 +485,7 @@ struct dept_task {extern void dept_wait_split_map (struct dept_map_each *me,struct dept_map_common *mc,unsigned long ip,const char *w_fn,int ne);extern void dept_event_split_map (struct dept_map_each *me,struct dept_map_common *mc,unsigned long ip,const char *e_fn);extern void dept_ask_event_split_map (struct dept_map_each *me,struct dept_map_common *mc); +extern void dept_kernel_enter (void );/* * for users who want to manage external keys
@@ -520,6 +526,7 @@ struct dept_task {#define dept_wait_split_map (me, mc, ip, w_fn, ne) do { } while (0)#define dept_event_split_map (me, mc, ip, e_fn) do { } while (0)#define dept_ask_event_split_map (me, mc) do { } while (0) +#define dept_kernel_enter () do { } while (0)#define dept_key_init (k) do { (void)(k); } while (0)#define dept_key_destroy (k) do { (void)(k); } while (0)#endif
kernel/dependency/dept.c +34 -33
197 lines not on this page · raw message
kernel/entry/common.c +3 -0
@@ -6,6 +6,7 @@#include <linux/livepatch.h> #include <linux/audit.h> #include <linux/tick.h> +#include <linux/dept.h> #include "common.h"
@@ -102,6 +103,7 @@ noinstr long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall)long ret;__enter_from_user_mode (regs); +dept_kernel_enter ();instrumentation_begin ();local_irq_enable ();
@@ -114,6 +116,7 @@ noinstr long syscall_enter_from_user_mode(struct pt_regs *regs, long syscall) noinstr void syscall_enter_from_user_mode_prepare(struct pt_regs *regs) {__enter_from_user_mode (regs); +dept_kernel_enter ();instrumentation_begin ();local_irq_enable ();instrumentation_end ();
Signature · 1 line
1.9.1
PATCH v2 18/18 dept: Distinguish each work from another
In reply to Byungchul ParkWorkqueue already provides concurrency control. By that, any wait in a work doesn't prevents events in other works with the control enabled. Thus, each work would better be considered a different context.
So let Dept assign a different context id to each work.
--- include/linux/dept.h | 2 ++ kernel/dependency/dept.c | 10 ++++++++++ kernel/workqueue.c | 3 +++ 3 files changed, 15 insertions(+)
include/linux/dept.h +2 -0
@@ -486,6 +486,7 @@ struct dept_task {extern void dept_event_split_map (struct dept_map_each *me,struct dept_map_common *mc,unsigned long ip,const char *e_fn);extern void dept_ask_event_split_map (struct dept_map_each *me,struct dept_map_common *mc);extern void dept_kernel_enter (void ); +extern void dept_work_enter (void );/* * for users who want to manage external keys
@@ -527,6 +528,7 @@ struct dept_task {#define dept_event_split_map (me, mc, ip, e_fn) do { } while (0)#define dept_ask_event_split_map (me, mc) do { } while (0)#define dept_kernel_enter () do { } while (0) +#define dept_work_enter () do { } while (0)#define dept_key_init (k) do { (void)(k); } while (0)#define dept_key_destroy (k) do { (void)(k); } while (0)#endif
kernel/dependency/dept.c +10 -0
@@ -1873,6 +1873,16 @@ void dept_disable_hardirq(unsigned long ip)dept_exit (flags); } +/* +* Assign a different context id to each work. +*/ +void dept_work_enter (void ) +{ +struct dept_task *dt =dept_task (); + + dt->cxt_id[DEPT_CXT_PROCESS ] += (1UL <<DEPT_CXTS_NR ); +} +void dept_kernel_enter (void ) {struct dept_task *dt =dept_task ();
kernel/workqueue.c +3 -0
@@ -51,6 +51,7 @@#include <linux/sched/isolation.h> #include <linux/nmi.h> #include <linux/kvm_para.h> +#include <linux/dept.h> #include "workqueue_internal.h"
@@ -2217,6 +2218,8 @@ static void process_one_work(struct worker *worker, struct work_struct *work)lockdep_copy_map (&lockdep_map, &work->lockdep_map);#endif +dept_work_enter (); +/* ensure we're on the correct CPU */ WARN_ON_ONCE (!(pool->flags &POOL_DISASSOCIATED ) &&raw_smp_processor_id () != pool->cpu);
Signature · 1 line
1.9.1