/*
* A reference is taken on the patch module to prevent it from being
* unloaded.
- *
- * Note: For immediate (no consistency model) patches we don't allow
- * patch modules to unload since there is no safe/sane method to
- * determine if a thread is still running in the patched code contained
- * in the patch module once the ftrace registration is successful.
*/
if (!try_module_get(patch->mod))
return -ENODEV;
int ret;
bool val;
- patch = container_of(kobj, struct klp_patch, kobj);
-
- /*
- * klp_mutex lock is not grabbed here intentionally. It is not really
- * needed. The race window is harmless and grabbing the lock would only
- * hold the action back.
- */
- if (patch != klp_transition_patch)
- return -EINVAL;
-
ret = kstrtobool(buf, &val);
if (ret)
return ret;
- if (val)
- klp_send_signals();
+ if (!val)
+ return count;
+
+ mutex_lock(&klp_mutex);
+
+ patch = container_of(kobj, struct klp_patch, kobj);
+ if (patch != klp_transition_patch) {
+ mutex_unlock(&klp_mutex);
+ return -EINVAL;
+ }
+
+ klp_send_signals();
+
+ mutex_unlock(&klp_mutex);
return count;
}
int ret;
bool val;
- patch = container_of(kobj, struct klp_patch, kobj);
-
- /*
- * klp_mutex lock is not grabbed here intentionally. It is not really
- * needed. The race window is harmless and grabbing the lock would only
- * hold the action back.
- */
- if (patch != klp_transition_patch)
- return -EINVAL;
-
ret = kstrtobool(buf, &val);
if (ret)
return ret;
- if (val)
- klp_force_transition();
+ if (!val)
+ return count;
+
+ mutex_lock(&klp_mutex);
+
+ patch = container_of(kobj, struct klp_patch, kobj);
+ if (patch != klp_transition_patch) {
+ mutex_unlock(&klp_mutex);
+ return -EINVAL;
+ }
+
+ klp_force_transition();
+
+ mutex_unlock(&klp_mutex);
return count;
}
if (!klp_initialized())
return -ENODEV;
- /*
- * Architectures without reliable stack traces have to set
- * patch->immediate because there's currently no way to patch kthreads
- * with the consistency model.
- */
- if (!klp_have_reliable_stack() && !patch->immediate) {
+ if (!klp_have_reliable_stack()) {
pr_err("This architecture doesn't have support for the livepatch consistency model.\n");
return -ENOSYS;
}