diff options
author | Kent Overstreet <kent.overstreet@linux.dev> | 2023-05-20 20:57:55 -0400 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@linux.dev> | 2023-10-22 17:10:01 -0400 |
commit | 0d2234a79e877b1bfa71b2c8c712a155be419827 (patch) | |
tree | 3ddf278178dc2b05ce81e20b0ed79dde52b8890d /fs/bcachefs/six.h | |
parent | 01bf56a9771466147d94a013bc5678d0ed1b1382 (diff) | |
download | linux-0d2234a79e877b1bfa71b2c8c712a155be419827.tar.gz linux-0d2234a79e877b1bfa71b2c8c712a155be419827.tar.bz2 linux-0d2234a79e877b1bfa71b2c8c712a155be419827.zip |
six locks: Kill six_lock_pcpu_(alloc|free)
six_lock_pcpu_alloc() is an unsafe interface: it's not safe to allocate
or free the percpu reader count on an existing lock that's in use, the
only safe time to allocate percpu readers is when the lock is first
being initialized.
This patch adds a flags parameter to six_lock_init(), and instead of
six_lock_pcpu_free() we now expose six_lock_exit(), which does the same
thing but is less likely to be misused.
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/six.h')
-rw-r--r-- | fs/bcachefs/six.h | 27 |
1 files changed, 10 insertions, 17 deletions
diff --git a/fs/bcachefs/six.h b/fs/bcachefs/six.h index 6b53818ae97a..2c8424bd7d2f 100644 --- a/fs/bcachefs/six.h +++ b/fs/bcachefs/six.h @@ -132,24 +132,20 @@ struct six_lock_waiter { typedef int (*six_lock_should_sleep_fn)(struct six_lock *lock, void *); -static __always_inline void __six_lock_init(struct six_lock *lock, - const char *name, - struct lock_class_key *key) -{ - atomic64_set(&lock->state.counter, 0); - raw_spin_lock_init(&lock->wait_lock); - INIT_LIST_HEAD(&lock->wait_list); -#ifdef CONFIG_DEBUG_LOCK_ALLOC - debug_check_no_locks_freed((void *) lock, sizeof(*lock)); - lockdep_init_map(&lock->dep_map, name, key, 0); -#endif -} +void six_lock_exit(struct six_lock *lock); -#define six_lock_init(lock) \ +enum six_lock_init_flags { + SIX_LOCK_INIT_PCPU = 1U << 0, +}; + +void __six_lock_init(struct six_lock *lock, const char *name, + struct lock_class_key *key, enum six_lock_init_flags flags); + +#define six_lock_init(lock, flags) \ do { \ static struct lock_class_key __key; \ \ - __six_lock_init((lock), #lock, &__key); \ + __six_lock_init((lock), #lock, &__key, flags); \ } while (0) #define __SIX_LOCK(type) \ @@ -248,9 +244,6 @@ void six_lock_increment(struct six_lock *, enum six_lock_type); void six_lock_wakeup_all(struct six_lock *); -void six_lock_pcpu_free(struct six_lock *); -void six_lock_pcpu_alloc(struct six_lock *); - struct six_lock_count { unsigned n[3]; }; |