| .. | .. |
|---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0+ */ |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Sleepable Read-Copy Update mechanism for mutual exclusion |
|---|
| 3 | | - * |
|---|
| 4 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 5 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 6 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 7 | | - * (at your option) any later version. |
|---|
| 8 | | - * |
|---|
| 9 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 10 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 11 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 12 | | - * GNU General Public License for more details. |
|---|
| 13 | | - * |
|---|
| 14 | | - * You should have received a copy of the GNU General Public License |
|---|
| 15 | | - * along with this program; if not, you can access it online at |
|---|
| 16 | | - * http://www.gnu.org/licenses/gpl-2.0.html. |
|---|
| 17 | 4 | * |
|---|
| 18 | 5 | * Copyright (C) IBM Corporation, 2006 |
|---|
| 19 | 6 | * Copyright (C) Fujitsu, 2012 |
|---|
| 20 | 7 | * |
|---|
| 21 | | - * Author: Paul McKenney <paulmck@us.ibm.com> |
|---|
| 8 | + * Author: Paul McKenney <paulmck@linux.ibm.com> |
|---|
| 22 | 9 | * Lai Jiangshan <laijs@cn.fujitsu.com> |
|---|
| 23 | 10 | * |
|---|
| 24 | 11 | * For detailed explanation of Read-Copy Update mechanism see - |
|---|
| .. | .. |
|---|
| 38 | 25 | |
|---|
| 39 | 26 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
|---|
| 40 | 27 | |
|---|
| 41 | | -int __init_srcu_struct(struct srcu_struct *sp, const char *name, |
|---|
| 28 | +int __init_srcu_struct(struct srcu_struct *ssp, const char *name, |
|---|
| 42 | 29 | struct lock_class_key *key); |
|---|
| 43 | 30 | |
|---|
| 44 | | -#define init_srcu_struct(sp) \ |
|---|
| 31 | +#define init_srcu_struct(ssp) \ |
|---|
| 45 | 32 | ({ \ |
|---|
| 46 | 33 | static struct lock_class_key __srcu_key; \ |
|---|
| 47 | 34 | \ |
|---|
| 48 | | - __init_srcu_struct((sp), #sp, &__srcu_key); \ |
|---|
| 35 | + __init_srcu_struct((ssp), #ssp, &__srcu_key); \ |
|---|
| 49 | 36 | }) |
|---|
| 50 | 37 | |
|---|
| 51 | 38 | #define __SRCU_DEP_MAP_INIT(srcu_name) .dep_map = { .name = #srcu_name }, |
|---|
| 52 | 39 | #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ |
|---|
| 53 | 40 | |
|---|
| 54 | | -int init_srcu_struct(struct srcu_struct *sp); |
|---|
| 41 | +int init_srcu_struct(struct srcu_struct *ssp); |
|---|
| 55 | 42 | |
|---|
| 56 | 43 | #define __SRCU_DEP_MAP_INIT(srcu_name) |
|---|
| 57 | 44 | #endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */ |
|---|
| .. | .. |
|---|
| 67 | 54 | struct srcu_struct { }; |
|---|
| 68 | 55 | #endif |
|---|
| 69 | 56 | |
|---|
| 70 | | -void call_srcu(struct srcu_struct *sp, struct rcu_head *head, |
|---|
| 57 | +void call_srcu(struct srcu_struct *ssp, struct rcu_head *head, |
|---|
| 71 | 58 | void (*func)(struct rcu_head *head)); |
|---|
| 72 | | -void _cleanup_srcu_struct(struct srcu_struct *sp, bool quiesced); |
|---|
| 73 | | -int __srcu_read_lock(struct srcu_struct *sp) __acquires(sp); |
|---|
| 74 | | -void __srcu_read_unlock(struct srcu_struct *sp, int idx) __releases(sp); |
|---|
| 75 | | -void synchronize_srcu(struct srcu_struct *sp); |
|---|
| 76 | | - |
|---|
| 77 | | -/** |
|---|
| 78 | | - * cleanup_srcu_struct - deconstruct a sleep-RCU structure |
|---|
| 79 | | - * @sp: structure to clean up. |
|---|
| 80 | | - * |
|---|
| 81 | | - * Must invoke this after you are finished using a given srcu_struct that |
|---|
| 82 | | - * was initialized via init_srcu_struct(), else you leak memory. |
|---|
| 83 | | - */ |
|---|
| 84 | | -static inline void cleanup_srcu_struct(struct srcu_struct *sp) |
|---|
| 85 | | -{ |
|---|
| 86 | | - _cleanup_srcu_struct(sp, false); |
|---|
| 87 | | -} |
|---|
| 88 | | - |
|---|
| 89 | | -/** |
|---|
| 90 | | - * cleanup_srcu_struct_quiesced - deconstruct a quiesced sleep-RCU structure |
|---|
| 91 | | - * @sp: structure to clean up. |
|---|
| 92 | | - * |
|---|
| 93 | | - * Must invoke this after you are finished using a given srcu_struct that |
|---|
| 94 | | - * was initialized via init_srcu_struct(), else you leak memory. Also, |
|---|
| 95 | | - * all grace-period processing must have completed. |
|---|
| 96 | | - * |
|---|
| 97 | | - * "Completed" means that the last synchronize_srcu() and |
|---|
| 98 | | - * synchronize_srcu_expedited() calls must have returned before the call |
|---|
| 99 | | - * to cleanup_srcu_struct_quiesced(). It also means that the callback |
|---|
| 100 | | - * from the last call_srcu() must have been invoked before the call to |
|---|
| 101 | | - * cleanup_srcu_struct_quiesced(), but you can use srcu_barrier() to help |
|---|
| 102 | | - * with this last. Violating these rules will get you a WARN_ON() splat |
|---|
| 103 | | - * (with high probability, anyway), and will also cause the srcu_struct |
|---|
| 104 | | - * to be leaked. |
|---|
| 105 | | - */ |
|---|
| 106 | | -static inline void cleanup_srcu_struct_quiesced(struct srcu_struct *sp) |
|---|
| 107 | | -{ |
|---|
| 108 | | - _cleanup_srcu_struct(sp, true); |
|---|
| 109 | | -} |
|---|
| 59 | +void cleanup_srcu_struct(struct srcu_struct *ssp); |
|---|
| 60 | +int __srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp); |
|---|
| 61 | +void __srcu_read_unlock(struct srcu_struct *ssp, int idx) __releases(ssp); |
|---|
| 62 | +void synchronize_srcu(struct srcu_struct *ssp); |
|---|
| 63 | +unsigned long get_state_synchronize_srcu(struct srcu_struct *ssp); |
|---|
| 64 | +unsigned long start_poll_synchronize_srcu(struct srcu_struct *ssp); |
|---|
| 65 | +bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie); |
|---|
| 110 | 66 | |
|---|
| 111 | 67 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
|---|
| 112 | 68 | |
|---|
| 113 | 69 | /** |
|---|
| 114 | 70 | * srcu_read_lock_held - might we be in SRCU read-side critical section? |
|---|
| 115 | | - * @sp: The srcu_struct structure to check |
|---|
| 71 | + * @ssp: The srcu_struct structure to check |
|---|
| 116 | 72 | * |
|---|
| 117 | 73 | * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an SRCU |
|---|
| 118 | 74 | * read-side critical section. In absence of CONFIG_DEBUG_LOCK_ALLOC, |
|---|
| .. | .. |
|---|
| 126 | 82 | * relies on normal RCU, it can be called from the CPU which |
|---|
| 127 | 83 | * is in the idle loop from an RCU point of view or offline. |
|---|
| 128 | 84 | */ |
|---|
| 129 | | -static inline int srcu_read_lock_held(const struct srcu_struct *sp) |
|---|
| 85 | +static inline int srcu_read_lock_held(const struct srcu_struct *ssp) |
|---|
| 130 | 86 | { |
|---|
| 131 | 87 | if (!debug_lockdep_rcu_enabled()) |
|---|
| 132 | 88 | return 1; |
|---|
| 133 | | - return lock_is_held(&sp->dep_map); |
|---|
| 89 | + return lock_is_held(&ssp->dep_map); |
|---|
| 134 | 90 | } |
|---|
| 135 | 91 | |
|---|
| 136 | 92 | #else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ |
|---|
| 137 | 93 | |
|---|
| 138 | | -static inline int srcu_read_lock_held(const struct srcu_struct *sp) |
|---|
| 94 | +static inline int srcu_read_lock_held(const struct srcu_struct *ssp) |
|---|
| 139 | 95 | { |
|---|
| 140 | 96 | return 1; |
|---|
| 141 | 97 | } |
|---|
| .. | .. |
|---|
| 145 | 101 | /** |
|---|
| 146 | 102 | * srcu_dereference_check - fetch SRCU-protected pointer for later dereferencing |
|---|
| 147 | 103 | * @p: the pointer to fetch and protect for later dereferencing |
|---|
| 148 | | - * @sp: pointer to the srcu_struct, which is used to check that we |
|---|
| 104 | + * @ssp: pointer to the srcu_struct, which is used to check that we |
|---|
| 149 | 105 | * really are in an SRCU read-side critical section. |
|---|
| 150 | 106 | * @c: condition to check for update-side use |
|---|
| 151 | 107 | * |
|---|
| .. | .. |
|---|
| 154 | 110 | * to 1. The @c argument will normally be a logical expression containing |
|---|
| 155 | 111 | * lockdep_is_held() calls. |
|---|
| 156 | 112 | */ |
|---|
| 157 | | -#define srcu_dereference_check(p, sp, c) \ |
|---|
| 158 | | - __rcu_dereference_check((p), (c) || srcu_read_lock_held(sp), __rcu) |
|---|
| 113 | +#define srcu_dereference_check(p, ssp, c) \ |
|---|
| 114 | + __rcu_dereference_check((p), (c) || srcu_read_lock_held(ssp), __rcu) |
|---|
| 159 | 115 | |
|---|
| 160 | 116 | /** |
|---|
| 161 | 117 | * srcu_dereference - fetch SRCU-protected pointer for later dereferencing |
|---|
| 162 | 118 | * @p: the pointer to fetch and protect for later dereferencing |
|---|
| 163 | | - * @sp: pointer to the srcu_struct, which is used to check that we |
|---|
| 119 | + * @ssp: pointer to the srcu_struct, which is used to check that we |
|---|
| 164 | 120 | * really are in an SRCU read-side critical section. |
|---|
| 165 | 121 | * |
|---|
| 166 | 122 | * Makes rcu_dereference_check() do the dirty work. If PROVE_RCU |
|---|
| 167 | 123 | * is enabled, invoking this outside of an RCU read-side critical |
|---|
| 168 | 124 | * section will result in an RCU-lockdep splat. |
|---|
| 169 | 125 | */ |
|---|
| 170 | | -#define srcu_dereference(p, sp) srcu_dereference_check((p), (sp), 0) |
|---|
| 126 | +#define srcu_dereference(p, ssp) srcu_dereference_check((p), (ssp), 0) |
|---|
| 171 | 127 | |
|---|
| 172 | 128 | /** |
|---|
| 173 | 129 | * srcu_dereference_notrace - no tracing and no lockdep calls from here |
|---|
| 130 | + * @p: the pointer to fetch and protect for later dereferencing |
|---|
| 131 | + * @ssp: pointer to the srcu_struct, which is used to check that we |
|---|
| 132 | + * really are in an SRCU read-side critical section. |
|---|
| 174 | 133 | */ |
|---|
| 175 | | -#define srcu_dereference_notrace(p, sp) srcu_dereference_check((p), (sp), 1) |
|---|
| 134 | +#define srcu_dereference_notrace(p, ssp) srcu_dereference_check((p), (ssp), 1) |
|---|
| 176 | 135 | |
|---|
| 177 | 136 | /** |
|---|
| 178 | 137 | * srcu_read_lock - register a new reader for an SRCU-protected structure. |
|---|
| 179 | | - * @sp: srcu_struct in which to register the new reader. |
|---|
| 138 | + * @ssp: srcu_struct in which to register the new reader. |
|---|
| 180 | 139 | * |
|---|
| 181 | 140 | * Enter an SRCU read-side critical section. Note that SRCU read-side |
|---|
| 182 | 141 | * critical sections may be nested. However, it is illegal to |
|---|
| .. | .. |
|---|
| 191 | 150 | * srcu_read_unlock() in an irq handler if the matching srcu_read_lock() |
|---|
| 192 | 151 | * was invoked in process context. |
|---|
| 193 | 152 | */ |
|---|
| 194 | | -static inline int srcu_read_lock(struct srcu_struct *sp) __acquires(sp) |
|---|
| 153 | +static inline int srcu_read_lock(struct srcu_struct *ssp) __acquires(ssp) |
|---|
| 195 | 154 | { |
|---|
| 196 | 155 | int retval; |
|---|
| 197 | 156 | |
|---|
| 198 | | - retval = __srcu_read_lock(sp); |
|---|
| 199 | | - rcu_lock_acquire(&(sp)->dep_map); |
|---|
| 157 | + retval = __srcu_read_lock(ssp); |
|---|
| 158 | + rcu_lock_acquire(&(ssp)->dep_map); |
|---|
| 200 | 159 | return retval; |
|---|
| 201 | 160 | } |
|---|
| 202 | 161 | |
|---|
| 203 | 162 | /* Used by tracing, cannot be traced and cannot invoke lockdep. */ |
|---|
| 204 | 163 | static inline notrace int |
|---|
| 205 | | -srcu_read_lock_notrace(struct srcu_struct *sp) __acquires(sp) |
|---|
| 164 | +srcu_read_lock_notrace(struct srcu_struct *ssp) __acquires(ssp) |
|---|
| 206 | 165 | { |
|---|
| 207 | 166 | int retval; |
|---|
| 208 | 167 | |
|---|
| 209 | | - retval = __srcu_read_lock(sp); |
|---|
| 168 | + retval = __srcu_read_lock(ssp); |
|---|
| 210 | 169 | return retval; |
|---|
| 211 | 170 | } |
|---|
| 212 | 171 | |
|---|
| 213 | 172 | /** |
|---|
| 214 | 173 | * srcu_read_unlock - unregister a old reader from an SRCU-protected structure. |
|---|
| 215 | | - * @sp: srcu_struct in which to unregister the old reader. |
|---|
| 174 | + * @ssp: srcu_struct in which to unregister the old reader. |
|---|
| 216 | 175 | * @idx: return value from corresponding srcu_read_lock(). |
|---|
| 217 | 176 | * |
|---|
| 218 | 177 | * Exit an SRCU read-side critical section. |
|---|
| 219 | 178 | */ |
|---|
| 220 | | -static inline void srcu_read_unlock(struct srcu_struct *sp, int idx) |
|---|
| 221 | | - __releases(sp) |
|---|
| 179 | +static inline void srcu_read_unlock(struct srcu_struct *ssp, int idx) |
|---|
| 180 | + __releases(ssp) |
|---|
| 222 | 181 | { |
|---|
| 223 | | - rcu_lock_release(&(sp)->dep_map); |
|---|
| 224 | | - __srcu_read_unlock(sp, idx); |
|---|
| 182 | + WARN_ON_ONCE(idx & ~0x1); |
|---|
| 183 | + rcu_lock_release(&(ssp)->dep_map); |
|---|
| 184 | + __srcu_read_unlock(ssp, idx); |
|---|
| 225 | 185 | } |
|---|
| 226 | 186 | |
|---|
| 227 | 187 | /* Used by tracing, cannot be traced and cannot call lockdep. */ |
|---|
| 228 | 188 | static inline notrace void |
|---|
| 229 | | -srcu_read_unlock_notrace(struct srcu_struct *sp, int idx) __releases(sp) |
|---|
| 189 | +srcu_read_unlock_notrace(struct srcu_struct *ssp, int idx) __releases(ssp) |
|---|
| 230 | 190 | { |
|---|
| 231 | | - __srcu_read_unlock(sp, idx); |
|---|
| 191 | + __srcu_read_unlock(ssp, idx); |
|---|
| 232 | 192 | } |
|---|
| 233 | 193 | |
|---|
| 234 | 194 | /** |
|---|