Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'locking-urgent-2021-03-21' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull locking fixes from Ingo Molnar:

- Get static calls & modules right. Hopefully.

- WW mutex fixes

* tag 'locking-urgent-2021-03-21' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip:
static_call: Fix static_call_update() sanity check
static_call: Align static_call_is_init() patching condition
static_call: Fix static_call_set_init()
locking/ww_mutex: Fix acquire/release imbalance in ww_acquire_init()/ww_acquire_fini()
locking/ww_mutex: Simplify use_ww_ctx & ww_ctx handling

+49 -31
+3 -2
include/linux/ww_mutex.h
··· 173 173 */ 174 174 static inline void ww_acquire_fini(struct ww_acquire_ctx *ctx) 175 175 { 176 - #ifdef CONFIG_DEBUG_MUTEXES 176 + #ifdef CONFIG_DEBUG_LOCK_ALLOC 177 177 mutex_release(&ctx->dep_map, _THIS_IP_); 178 - 178 + #endif 179 + #ifdef CONFIG_DEBUG_MUTEXES 179 180 DEBUG_LOCKS_WARN_ON(ctx->acquired); 180 181 if (!IS_ENABLED(CONFIG_PROVE_LOCKING)) 181 182 /*
+8
kernel/jump_label.c
··· 407 407 return false; 408 408 409 409 if (!kernel_text_address(jump_entry_code(entry))) { 410 + /* 411 + * This skips patching built-in __exit, which 412 + * is part of init_section_contains() but is 413 + * not part of kernel_text_address(). 414 + * 415 + * Skipping built-in __exit is fine since it 416 + * will never be executed. 417 + */ 410 418 WARN_ONCE(!jump_entry_is_init(entry), 411 419 "can't patch jump_label at %pS", 412 420 (void *)jump_entry_code(entry));
+14 -11
kernel/locking/mutex.c
··· 626 626 */ 627 627 static __always_inline bool 628 628 mutex_optimistic_spin(struct mutex *lock, struct ww_acquire_ctx *ww_ctx, 629 - const bool use_ww_ctx, struct mutex_waiter *waiter) 629 + struct mutex_waiter *waiter) 630 630 { 631 631 if (!waiter) { 632 632 /* ··· 702 702 #else 703 703 static __always_inline bool 704 704 mutex_optimistic_spin(struct mutex *lock, struct ww_acquire_ctx *ww_ctx, 705 - const bool use_ww_ctx, struct mutex_waiter *waiter) 705 + struct mutex_waiter *waiter) 706 706 { 707 707 return false; 708 708 } ··· 922 922 struct ww_mutex *ww; 923 923 int ret; 924 924 925 + if (!use_ww_ctx) 926 + ww_ctx = NULL; 927 + 925 928 might_sleep(); 926 929 927 930 #ifdef CONFIG_DEBUG_MUTEXES ··· 932 929 #endif 933 930 934 931 ww = container_of(lock, struct ww_mutex, base); 935 - if (use_ww_ctx && ww_ctx) { 932 + if (ww_ctx) { 936 933 if (unlikely(ww_ctx == READ_ONCE(ww->ctx))) 937 934 return -EALREADY; 938 935 ··· 949 946 mutex_acquire_nest(&lock->dep_map, subclass, 0, nest_lock, ip); 950 947 951 948 if (__mutex_trylock(lock) || 952 - mutex_optimistic_spin(lock, ww_ctx, use_ww_ctx, NULL)) { 949 + mutex_optimistic_spin(lock, ww_ctx, NULL)) { 953 950 /* got the lock, yay! */ 954 951 lock_acquired(&lock->dep_map, ip); 955 - if (use_ww_ctx && ww_ctx) 952 + if (ww_ctx) 956 953 ww_mutex_set_context_fastpath(ww, ww_ctx); 957 954 preempt_enable(); 958 955 return 0; ··· 963 960 * After waiting to acquire the wait_lock, try again. 964 961 */ 965 962 if (__mutex_trylock(lock)) { 966 - if (use_ww_ctx && ww_ctx) 963 + if (ww_ctx) 967 964 __ww_mutex_check_waiters(lock, ww_ctx); 968 965 969 966 goto skip_wait; ··· 1016 1013 goto err; 1017 1014 } 1018 1015 1019 - if (use_ww_ctx && ww_ctx) { 1016 + if (ww_ctx) { 1020 1017 ret = __ww_mutex_check_kill(lock, &waiter, ww_ctx); 1021 1018 if (ret) 1022 1019 goto err; ··· 1029 1026 * ww_mutex needs to always recheck its position since its waiter 1030 1027 * list is not FIFO ordered. 1031 1028 */ 1032 - if ((use_ww_ctx && ww_ctx) || !first) { 1029 + if (ww_ctx || !first) { 1033 1030 first = __mutex_waiter_is_first(lock, &waiter); 1034 1031 if (first) 1035 1032 __mutex_set_flag(lock, MUTEX_FLAG_HANDOFF); ··· 1042 1039 * or we must see its unlock and acquire. 1043 1040 */ 1044 1041 if (__mutex_trylock(lock) || 1045 - (first && mutex_optimistic_spin(lock, ww_ctx, use_ww_ctx, &waiter))) 1042 + (first && mutex_optimistic_spin(lock, ww_ctx, &waiter))) 1046 1043 break; 1047 1044 1048 1045 spin_lock(&lock->wait_lock); ··· 1051 1048 acquired: 1052 1049 __set_current_state(TASK_RUNNING); 1053 1050 1054 - if (use_ww_ctx && ww_ctx) { 1051 + if (ww_ctx) { 1055 1052 /* 1056 1053 * Wound-Wait; we stole the lock (!first_waiter), check the 1057 1054 * waiters as anyone might want to wound us. ··· 1071 1068 /* got the lock - cleanup and rejoice! */ 1072 1069 lock_acquired(&lock->dep_map, ip); 1073 1070 1074 - if (use_ww_ctx && ww_ctx) 1071 + if (ww_ctx) 1075 1072 ww_mutex_lock_acquired(ww, ww_ctx); 1076 1073 1077 1074 spin_unlock(&lock->wait_lock);
+24 -18
kernel/static_call.c
··· 35 35 return (void *)((long)site->addr + (long)&site->addr); 36 36 } 37 37 38 + static inline unsigned long __static_call_key(const struct static_call_site *site) 39 + { 40 + return (long)site->key + (long)&site->key; 41 + } 38 42 39 43 static inline struct static_call_key *static_call_key(const struct static_call_site *site) 40 44 { 41 - return (struct static_call_key *) 42 - (((long)site->key + (long)&site->key) & ~STATIC_CALL_SITE_FLAGS); 45 + return (void *)(__static_call_key(site) & ~STATIC_CALL_SITE_FLAGS); 43 46 } 44 47 45 48 /* These assume the key is word-aligned. */ 46 49 static inline bool static_call_is_init(struct static_call_site *site) 47 50 { 48 - return ((long)site->key + (long)&site->key) & STATIC_CALL_SITE_INIT; 51 + return __static_call_key(site) & STATIC_CALL_SITE_INIT; 49 52 } 50 53 51 54 static inline bool static_call_is_tail(struct static_call_site *site) 52 55 { 53 - return ((long)site->key + (long)&site->key) & STATIC_CALL_SITE_TAIL; 56 + return __static_call_key(site) & STATIC_CALL_SITE_TAIL; 54 57 } 55 58 56 59 static inline void static_call_set_init(struct static_call_site *site) 57 60 { 58 - site->key = ((long)static_call_key(site) | STATIC_CALL_SITE_INIT) - 61 + site->key = (__static_call_key(site) | STATIC_CALL_SITE_INIT) - 59 62 (long)&site->key; 60 63 } 61 64 ··· 149 146 }; 150 147 151 148 for (site_mod = &first; site_mod; site_mod = site_mod->next) { 149 + bool init = system_state < SYSTEM_RUNNING; 152 150 struct module *mod = site_mod->mod; 153 151 154 152 if (!site_mod->sites) { ··· 169 165 if (mod) { 170 166 stop = mod->static_call_sites + 171 167 mod->num_static_call_sites; 168 + init = mod->state == MODULE_STATE_COMING; 172 169 } 173 170 #endif 174 171 ··· 177 172 site < stop && static_call_key(site) == key; site++) { 178 173 void *site_addr = static_call_addr(site); 179 174 180 - if (static_call_is_init(site)) { 181 - /* 182 - * Don't write to call sites which were in 183 - * initmem and have since been freed. 184 - */ 185 - if (!mod && system_state >= SYSTEM_RUNNING) 186 - continue; 187 - if (mod && !within_module_init((unsigned long)site_addr, mod)) 188 - continue; 189 - } 175 + if (!init && static_call_is_init(site)) 176 + continue; 190 177 191 178 if (!kernel_text_address((unsigned long)site_addr)) { 192 - WARN_ONCE(1, "can't patch static call site at %pS", 179 + /* 180 + * This skips patching built-in __exit, which 181 + * is part of init_section_contains() but is 182 + * not part of kernel_text_address(). 183 + * 184 + * Skipping built-in __exit is fine since it 185 + * will never be executed. 186 + */ 187 + WARN_ONCE(!static_call_is_init(site), 188 + "can't patch static call site at %pS", 193 189 site_addr); 194 190 continue; 195 191 } 196 192 197 193 arch_static_call_transform(site_addr, NULL, func, 198 - static_call_is_tail(site)); 194 + static_call_is_tail(site)); 199 195 } 200 196 } 201 197 ··· 355 349 struct static_call_site *site; 356 350 357 351 for (site = start; site != stop; site++) { 358 - unsigned long s_key = (long)site->key + (long)&site->key; 352 + unsigned long s_key = __static_call_key(site); 359 353 unsigned long addr = s_key & ~STATIC_CALL_SITE_FLAGS; 360 354 unsigned long key; 361 355