History

lockdep: Split header file into lockdep and lockdep_types

There is a header file inclusion loop between asm-generic/bug.h and linux/kernel.h. This causes potential compile failurs depending on the which file is included first. One way of breaking this loop is to stop spinlock_types.h from including lockdep.h. This patch splits lockdep.h into two files for this purpose.

Herbert Xu committed 6 years ago

Commit c935cd61 parent b3a9e3b4 files · +200 −177Browse files

Showing the changes to include/linux (4 of 4 files). Show all

Unified · Split

4 files
  1. include/linux/lockdep.h +2 −176
  2. include/linux/lockdep_types.h +196 −0
  3. include/linux/spinlock.h +1 −0
  4. include/linux/spinlock_types.h +1 −1
include/linux/lockdep.h+2−176
@@ -10,181 +10,20 @@ · 9 unmodified lines
10#ifndef __LINUX_LOCKDEP_H10#ifndef __LINUX_LOCKDEP_H
11#define __LINUX_LOCKDEP_H11#define __LINUX_LOCKDEP_H
12 12
13#include <linux/lockdep_types.h>
14
13struct task_struct;15struct task_struct;
14struct lockdep_map;
15 16
16/* for sysctl */17/* for sysctl */
17extern int prove_locking;18extern int prove_locking;
18extern int lock_stat;19extern int lock_stat;
19 20
20#define MAX_LOCKDEP_SUBCLASSES 8UL
21
22#include <linux/types.h>
23
24enum lockdep_wait_type {
25 LD_WAIT_INV = 0, /* not checked, catch all */
26
27 LD_WAIT_FREE, /* wait free, rcu etc.. */
28 LD_WAIT_SPIN, /* spin loops, raw_spinlock_t etc.. */
29
30#ifdef CONFIG_PROVE_RAW_LOCK_NESTING
31 LD_WAIT_CONFIG, /* CONFIG_PREEMPT_LOCK, spinlock_t etc.. */
32#else
33 LD_WAIT_CONFIG = LD_WAIT_SPIN,
34#endif
35 LD_WAIT_SLEEP, /* sleeping locks, mutex_t etc.. */
36
37 LD_WAIT_MAX, /* must be last */
38};
39
40#ifdef CONFIG_LOCKDEP21#ifdef CONFIG_LOCKDEP
41 22
42#include <linux/linkage.h>23#include <linux/linkage.h>
43#include <linux/list.h>
44#include <linux/debug_locks.h>24#include <linux/debug_locks.h>
45#include <linux/stacktrace.h>25#include <linux/stacktrace.h>
46 26
47/*
48 * We'd rather not expose kernel/lockdep_states.h this wide, but we do need
49 * the total number of states... :-(
50 */
51#define XXX_LOCK_USAGE_STATES (1+2*4)
52
53/*
54 * NR_LOCKDEP_CACHING_CLASSES ... Number of classes
55 * cached in the instance of lockdep_map
56 *
57 * Currently main class (subclass == 0) and signle depth subclass
58 * are cached in lockdep_map. This optimization is mainly targeting
59 * on rq->lock. double_rq_lock() acquires this highly competitive with
60 * single depth.
61 */
62#define NR_LOCKDEP_CACHING_CLASSES 2
63
64/*
65 * A lockdep key is associated with each lock object. For static locks we use
66 * the lock address itself as the key. Dynamically allocated lock objects can
67 * have a statically or dynamically allocated key. Dynamically allocated lock
68 * keys must be registered before being used and must be unregistered before
69 * the key memory is freed.
70 */
71struct lockdep_subclass_key {
72 char __one_byte;
73} __attribute__ ((__packed__));
74
75/* hash_entry is used to keep track of dynamically allocated keys. */
76struct lock_class_key {
77 union {
78 struct hlist_node hash_entry;
79 struct lockdep_subclass_key subkeys[MAX_LOCKDEP_SUBCLASSES];
80 };
81};
82
83extern struct lock_class_key __lockdep_no_validate__;
84
85struct lock_trace;
86
87#define LOCKSTAT_POINTS 4
88
89/*
90 * The lock-class itself. The order of the structure members matters.
91 * reinit_class() zeroes the key member and all subsequent members.
92 */
93struct lock_class {
94 /*
95 * class-hash:
96 */
97 struct hlist_node hash_entry;
98
99 /*
100 * Entry in all_lock_classes when in use. Entry in free_lock_classes
101 * when not in use. Instances that are being freed are on one of the
102 * zapped_classes lists.
103 */
104 struct list_head lock_entry;
105
106 /*
107 * These fields represent a directed graph of lock dependencies,
108 * to every node we attach a list of "forward" and a list of
109 * "backward" graph nodes.
110 */
111 struct list_head locks_after, locks_before;
112
113 const struct lockdep_subclass_key *key;
114 unsigned int subclass;
115 unsigned int dep_gen_id;
116
117 /*
118 * IRQ/softirq usage tracking bits:
119 */
120 unsigned long usage_mask;
121 const struct lock_trace *usage_traces[XXX_LOCK_USAGE_STATES];
122
123 /*
124 * Generation counter, when doing certain classes of graph walking,
125 * to ensure that we check one node only once:
126 */
127 int name_version;
128 const char *name;
129
130 short wait_type_inner;
131 short wait_type_outer;
132
133#ifdef CONFIG_LOCK_STAT
134 unsigned long contention_point[LOCKSTAT_POINTS];
135 unsigned long contending_point[LOCKSTAT_POINTS];
136#endif
137} __no_randomize_layout;
138
139#ifdef CONFIG_LOCK_STAT
140struct lock_time {
141 s64 min;
142 s64 max;
143 s64 total;
144 unsigned long nr;
145};
146
147enum bounce_type {
148 bounce_acquired_write,
149 bounce_acquired_read,
150 bounce_contended_write,
151 bounce_contended_read,
152 nr_bounce_types,
153
154 bounce_acquired = bounce_acquired_write,
155 bounce_contended = bounce_contended_write,
156};
157
158struct lock_class_stats {
159 unsigned long contention_point[LOCKSTAT_POINTS];
160 unsigned long contending_point[LOCKSTAT_POINTS];
161 struct lock_time read_waittime;
162 struct lock_time write_waittime;
163 struct lock_time read_holdtime;
164 struct lock_time write_holdtime;
165 unsigned long bounces[nr_bounce_types];
166};
167
168struct lock_class_stats lock_stats(struct lock_class *class);
169void clear_lock_stats(struct lock_class *class);
170#endif
171
172/*
173 * Map the lock object (the lock instance) to the lock-class object.
174 * This is embedded into specific lock instances:
175 */
176struct lockdep_map {
177 struct lock_class_key *key;
178 struct lock_class *class_cache[NR_LOCKDEP_CACHING_CLASSES];
179 const char *name;
180 short wait_type_outer; /* can be taken in this context */
181 short wait_type_inner; /* presents this context */
182#ifdef CONFIG_LOCK_STAT
183 int cpu;
184 unsigned long ip;
185#endif
186};
187
188static inline void lockdep_copy_map(struct lockdep_map *to,27static inline void lockdep_copy_map(struct lockdep_map *to,
189 struct lockdep_map *from)28 struct lockdep_map *from)
190{29{
@@ -440,8 +279,6 @@ static inline void lock_set_subclass(struct lockdep_map *lock, · 249 unmodified lines
440 279
441extern void lock_downgrade(struct lockdep_map *lock, unsigned long ip);280extern void lock_downgrade(struct lockdep_map *lock, unsigned long ip);
442 281
443struct pin_cookie { unsigned int val; };
444
445#define NIL_COOKIE (struct pin_cookie){ .val = 0U, }282#define NIL_COOKIE (struct pin_cookie){ .val = 0U, }
446 283
447extern struct pin_cookie lock_pin_lock(struct lockdep_map *lock);284extern struct pin_cookie lock_pin_lock(struct lockdep_map *lock);
@@ -520,10 +357,6 @@ static inline void lockdep_set_selftest_task(struct task_struct *task) · 72 unmodified lines
520# define lockdep_reset() do { debug_locks = 1; } while (0)357# define lockdep_reset() do { debug_locks = 1; } while (0)
521# define lockdep_free_key_range(start, size) do { } while (0)358# define lockdep_free_key_range(start, size) do { } while (0)
522# define lockdep_sys_exit() do { } while (0)359# define lockdep_sys_exit() do { } while (0)
523/*
524 * The class key takes no space if lockdep is disabled:
525 */
526struct lock_class_key { };
527 360
528static inline void lockdep_register_key(struct lock_class_key *key)361static inline void lockdep_register_key(struct lock_class_key *key)
529{362{
@@ -533,11 +366,6 @@ static inline void lockdep_unregister_key(struct lock_class_key *key) · 3 unmodified lines
533{366{
534}367}
535 368
536/*
537 * The lockdep_map takes no space if lockdep is disabled:
538 */
539struct lockdep_map { };
540
541#define lockdep_depth(tsk) (0)369#define lockdep_depth(tsk) (0)
542 370
543#define lockdep_is_held_type(l, r) (1)371#define lockdep_is_held_type(l, r) (1)
@@ -549,8 +377,6 @@ struct lockdep_map { }; · 5 unmodified lines
549 377
550#define lockdep_recursing(tsk) (0)378#define lockdep_recursing(tsk) (0)
551 379
552struct pin_cookie { };
553
554#define NIL_COOKIE (struct pin_cookie){ }380#define NIL_COOKIE (struct pin_cookie){ }
555 381
556#define lockdep_pin_lock(l) ({ struct pin_cookie cookie = { }; cookie; })382#define lockdep_pin_lock(l) ({ struct pin_cookie cookie = { }; cookie; })
include/linux/lockdep_types.h+196−0
@@ -0,0 +1,196 @@
1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Runtime locking correctness validator
4 *
5 * Copyright (C) 2006,2007 Red Hat, Inc., Ingo Molnar <mingo@redhat.com>
6 * Copyright (C) 2007 Red Hat, Inc., Peter Zijlstra
7 *
8 * see Documentation/locking/lockdep-design.rst for more details.
9 */
10#ifndef __LINUX_LOCKDEP_TYPES_H
11#define __LINUX_LOCKDEP_TYPES_H
12
13#include <linux/types.h>
14
15#define MAX_LOCKDEP_SUBCLASSES 8UL
16
17enum lockdep_wait_type {
18 LD_WAIT_INV = 0, /* not checked, catch all */
19
20 LD_WAIT_FREE, /* wait free, rcu etc.. */
21 LD_WAIT_SPIN, /* spin loops, raw_spinlock_t etc.. */
22
23#ifdef CONFIG_PROVE_RAW_LOCK_NESTING
24 LD_WAIT_CONFIG, /* CONFIG_PREEMPT_LOCK, spinlock_t etc.. */
25#else
26 LD_WAIT_CONFIG = LD_WAIT_SPIN,
27#endif
28 LD_WAIT_SLEEP, /* sleeping locks, mutex_t etc.. */
29
30 LD_WAIT_MAX, /* must be last */
31};
32
33#ifdef CONFIG_LOCKDEP
34
35#include <linux/list.h>
36
37/*
38 * We'd rather not expose kernel/lockdep_states.h this wide, but we do need
39 * the total number of states... :-(
40 */
41#define XXX_LOCK_USAGE_STATES (1+2*4)
42
43/*
44 * NR_LOCKDEP_CACHING_CLASSES ... Number of classes
45 * cached in the instance of lockdep_map
46 *
47 * Currently main class (subclass == 0) and signle depth subclass
48 * are cached in lockdep_map. This optimization is mainly targeting
49 * on rq->lock. double_rq_lock() acquires this highly competitive with
50 * single depth.
51 */
52#define NR_LOCKDEP_CACHING_CLASSES 2
53
54/*
55 * A lockdep key is associated with each lock object. For static locks we use
56 * the lock address itself as the key. Dynamically allocated lock objects can
57 * have a statically or dynamically allocated key. Dynamically allocated lock
58 * keys must be registered before being used and must be unregistered before
59 * the key memory is freed.
60 */
61struct lockdep_subclass_key {
62 char __one_byte;
63} __attribute__ ((__packed__));
64
65/* hash_entry is used to keep track of dynamically allocated keys. */
66struct lock_class_key {
67 union {
68 struct hlist_node hash_entry;
69 struct lockdep_subclass_key subkeys[MAX_LOCKDEP_SUBCLASSES];
70 };
71};
72
73extern struct lock_class_key __lockdep_no_validate__;
74
75struct lock_trace;
76
77#define LOCKSTAT_POINTS 4
78
79/*
80 * The lock-class itself. The order of the structure members matters.
81 * reinit_class() zeroes the key member and all subsequent members.
82 */
83struct lock_class {
84 /*
85 * class-hash:
86 */
87 struct hlist_node hash_entry;
88
89 /*
90 * Entry in all_lock_classes when in use. Entry in free_lock_classes
91 * when not in use. Instances that are being freed are on one of the
92 * zapped_classes lists.
93 */
94 struct list_head lock_entry;
95
96 /*
97 * These fields represent a directed graph of lock dependencies,
98 * to every node we attach a list of "forward" and a list of
99 * "backward" graph nodes.
100 */
101 struct list_head locks_after, locks_before;
102
103 const struct lockdep_subclass_key *key;
104 unsigned int subclass;
105 unsigned int dep_gen_id;
106
107 /*
108 * IRQ/softirq usage tracking bits:
109 */
110 unsigned long usage_mask;
111 const struct lock_trace *usage_traces[XXX_LOCK_USAGE_STATES];
112
113 /*
114 * Generation counter, when doing certain classes of graph walking,
115 * to ensure that we check one node only once:
116 */
117 int name_version;
118 const char *name;
119
120 short wait_type_inner;
121 short wait_type_outer;
122
123#ifdef CONFIG_LOCK_STAT
124 unsigned long contention_point[LOCKSTAT_POINTS];
125 unsigned long contending_point[LOCKSTAT_POINTS];
126#endif
127} __no_randomize_layout;
128
129#ifdef CONFIG_LOCK_STAT
130struct lock_time {
131 s64 min;
132 s64 max;
133 s64 total;
134 unsigned long nr;
135};
136
137enum bounce_type {
138 bounce_acquired_write,
139 bounce_acquired_read,
140 bounce_contended_write,
141 bounce_contended_read,
142 nr_bounce_types,
143
144 bounce_acquired = bounce_acquired_write,
145 bounce_contended = bounce_contended_write,
146};
147
148struct lock_class_stats {
149 unsigned long contention_point[LOCKSTAT_POINTS];
150 unsigned long contending_point[LOCKSTAT_POINTS];
151 struct lock_time read_waittime;
152 struct lock_time write_waittime;
153 struct lock_time read_holdtime;
154 struct lock_time write_holdtime;
155 unsigned long bounces[nr_bounce_types];
156};
157
158struct lock_class_stats lock_stats(struct lock_class *class);
159void clear_lock_stats(struct lock_class *class);
160#endif
161
162/*
163 * Map the lock object (the lock instance) to the lock-class object.
164 * This is embedded into specific lock instances:
165 */
166struct lockdep_map {
167 struct lock_class_key *key;
168 struct lock_class *class_cache[NR_LOCKDEP_CACHING_CLASSES];
169 const char *name;
170 short wait_type_outer; /* can be taken in this context */
171 short wait_type_inner; /* presents this context */
172#ifdef CONFIG_LOCK_STAT
173 int cpu;
174 unsigned long ip;
175#endif
176};
177
178struct pin_cookie { unsigned int val; };
179
180#else /* !CONFIG_LOCKDEP */
181
182/*
183 * The class key takes no space if lockdep is disabled:
184 */
185struct lock_class_key { };
186
187/*
188 * The lockdep_map takes no space if lockdep is disabled:
189 */
190struct lockdep_map { };
191
192struct pin_cookie { };
193
194#endif /* !LOCKDEP */
195
196#endif /* __LINUX_LOCKDEP_TYPES_H */
include/linux/spinlock.h+1−0
@@ -56,6 +56,7 @@ · 55 unmodified lines
56#include <linux/kernel.h>56#include <linux/kernel.h>
57#include <linux/stringify.h>57#include <linux/stringify.h>
58#include <linux/bottom_half.h>58#include <linux/bottom_half.h>
59#include <linux/lockdep.h>
59#include <asm/barrier.h>60#include <asm/barrier.h>
60#include <asm/mmiowb.h>61#include <asm/mmiowb.h>
61 62
include/linux/spinlock_types.h+1−1
@@ -15,7 +15,7 @@ · 14 unmodified lines
15# include <linux/spinlock_types_up.h>15# include <linux/spinlock_types_up.h>
16#endif16#endif
17 17
18#include <linux/lockdep.h>18#include <linux/lockdep_types.h>
19 19
20typedef struct raw_spinlock {20typedef struct raw_spinlock {
21 arch_spinlock_t raw_lock;21 arch_spinlock_t raw_lock;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t