* If possible, fall back to IBRS and IBPB.
* Failing that, indicate that we have no Spectre v2 mitigation.
*
- * Obtains spec_ctrl_mutex before checking/changing Spectre v2 mitigation
- * state.
+ * Checks that spec_ctrl_mutex is held.
*/
void disable_retpoline(void)
{
- mutex_lock(&spec_ctrl_mutex);
+ BUG_ON(!mutex_is_locked(&spec_ctrl_mutex));
if (retpoline_enabled()) {
pr_err("Disabling Spectre v2 mitigation retpoline.\n");
} else {
/* retpoline is not enabled. Return */
- mutex_unlock(&spec_ctrl_mutex);
return;
}
if (spectre_v2_enabled == SPECTRE_V2_NONE)
pr_err("system may be vulnerable to spectre\n");
-
- mutex_unlock(&spec_ctrl_mutex);
}
bool retpoline_enabled(void)
#include <uapi/linux/module.h>
#include "module-internal.h"
+#ifdef RETPOLINE
+#include <asm/spec_ctrl.h>
+#endif
+
#define CREATE_TRACE_POINTS
#include <trace/events/module.h>
if (!get_modinfo(info, "intree"))
add_taint_module(mod, TAINT_OOT_MODULE, LOCKDEP_STILL_OK);
#ifdef RETPOLINE
+ mutex_lock(&spec_ctrl_mutex);
+
if (retpoline_enabled() && !get_modinfo(info, "retpoline")) {
if (!test_taint(TAINT_NO_RETPOLINE)) {
pr_warn("%s: loading module not compiled with retpoline compiler.\n",
mod->name);
}
- add_taint_module(mod, TAINT_NO_RETPOLINE, LOCKDEP_STILL_OK);
disable_retpoline();
+ mutex_unlock(&spec_ctrl_mutex);
+ add_taint_module(mod, TAINT_NO_RETPOLINE, LOCKDEP_STILL_OK);
+ } else {
+ mutex_unlock(&spec_ctrl_mutex);
}
#endif
if (get_modinfo(info, "staging")) {