@@ -1225,6 +1225,12 @@ static const struct kernel_symbol *resolve_symbol(struct module *mod,
12251225 const unsigned long * crc ;
12261226 int err ;
12271227
1228+ /*
1229+ * The module_mutex should not be a heavily contended lock;
1230+ * if we get the occasional sleep here, we'll go an extra iteration
1231+ * in the wait_event_interruptible(), which is harmless.
1232+ */
1233+ sched_annotate_sleep ();
12281234 mutex_lock (& module_mutex );
12291235 sym = find_symbol (name , & owner , & crc ,
12301236 !(mod -> taints & (1 << TAINT_PROPRIETARY_MODULE )), true);
@@ -2978,6 +2984,12 @@ static bool finished_loading(const char *name)
29782984 struct module * mod ;
29792985 bool ret ;
29802986
2987+ /*
2988+ * The module_mutex should not be a heavily contended lock;
2989+ * if we get the occasional sleep here, we'll go an extra iteration
2990+ * in the wait_event_interruptible(), which is harmless.
2991+ */
2992+ sched_annotate_sleep ();
29812993 mutex_lock (& module_mutex );
29822994 mod = find_module_all (name , strlen (name ), true);
29832995 ret = !mod || mod -> state == MODULE_STATE_LIVE
@@ -3119,32 +3131,6 @@ static int may_init_module(void)
31193131 return 0 ;
31203132}
31213133
3122- /*
3123- * Can't use wait_event_interruptible() because our condition
3124- * 'finished_loading()' contains a blocking primitive itself (mutex_lock).
3125- */
3126- static int wait_finished_loading (struct module * mod )
3127- {
3128- DEFINE_WAIT_FUNC (wait , woken_wake_function );
3129- int ret = 0 ;
3130-
3131- add_wait_queue (& module_wq , & wait );
3132- for (;;) {
3133- if (finished_loading (mod -> name ))
3134- break ;
3135-
3136- if (signal_pending (current )) {
3137- ret = - ERESTARTSYS ;
3138- break ;
3139- }
3140-
3141- wait_woken (& wait , TASK_INTERRUPTIBLE , MAX_SCHEDULE_TIMEOUT );
3142- }
3143- remove_wait_queue (& module_wq , & wait );
3144-
3145- return ret ;
3146- }
3147-
31483134/*
31493135 * We try to place it in the list now to make sure it's unique before
31503136 * we dedicate too many resources. In particular, temporary percpu
@@ -3165,8 +3151,8 @@ static int add_unformed_module(struct module *mod)
31653151 || old -> state == MODULE_STATE_UNFORMED ) {
31663152 /* Wait in case it fails to load. */
31673153 mutex_unlock (& module_mutex );
3168-
3169- err = wait_finished_loading (mod );
3154+ err = wait_event_interruptible ( module_wq ,
3155+ finished_loading (mod -> name ) );
31703156 if (err )
31713157 goto out_unlocked ;
31723158 goto again ;
@@ -3265,7 +3251,7 @@ static int load_module(struct load_info *info, const char __user *uargs,
32653251 mod -> sig_ok = info -> sig_ok ;
32663252 if (!mod -> sig_ok ) {
32673253 pr_notice_once ("%s: module verification failed: signature "
3268- "and/or required key missing - tainting "
3254+ "and/or required key missing - tainting "
32693255 "kernel\n" , mod -> name );
32703256 add_taint_module (mod , TAINT_UNSIGNED_MODULE , LOCKDEP_STILL_OK );
32713257 }
@@ -3356,6 +3342,9 @@ static int load_module(struct load_info *info, const char __user *uargs,
33563342 module_bug_cleanup (mod );
33573343 mutex_unlock (& module_mutex );
33583344
3345+ /* Free lock-classes: */
3346+ lockdep_free_key_range (mod -> module_core , mod -> core_size );
3347+
33593348 /* we can't deallocate the module until we clear memory protection */
33603349 unset_module_init_ro_nx (mod );
33613350 unset_module_core_ro_nx (mod );
0 commit comments