spectre_v2_enabled = mode;
pr_info("%s\n", spectre_v2_strings[mode]);
- /*
- * If we have a full retpoline mode and then disable IBPB in kernel mode
- * we do not require both.
- */
- if (mode == SPECTRE_V2_RETPOLINE_AMD ||
- mode == SPECTRE_V2_RETPOLINE_GENERIC)
- {
- pr_info("Retpoline compiled kernel disabling IBPB in kernel");
- set_ibpb_retpoline_enabled();
- }
-
/*
* If neither SMEP or KPTI are available, there is a risk of
* hitting userspace addresses in the RSB after a context switch
if (!boot_cpu_has_bug(X86_BUG_SPECTRE_V2))
return sprintf(buf, "Not affected\n");
- return sprintf(buf, "%s%s\n", spectre_v2_strings[spectre_v2_enabled],
- ibpb_enabled_user ? ", IBPB (Intel v4)" : "");
+ return sprintf(buf, "%s\n", spectre_v2_strings[spectre_v2_enabled]);
}
#endif
/* indicate usage of IBPB to control execution speculation */
extern int use_ibpb;
extern u32 sysctl_ibpb_enabled;
-/* ibpb_enabled_kernel (use_ibpb & 0x1) */
#define ibpb_supported (use_ibpb & 0x2)
#define ibpb_disabled (use_ibpb & 0x4)
-#define ibpb_retpoline_enabled (use_ibpb & 0x8)
-#define ibpb_enabled_user (use_ibpb & 0x10)
-static inline void sync_ibpb_inuse(void)
+static inline void set_ibpb_inuse(void)
{
- if (ibpb_supported && !ibpb_disabled) {
- use_ibpb |= 0x10; /* Enable flushing on context/VM switch. */
- if (!ibpb_retpoline_enabled)
- use_ibpb |= 0x1; /* Enable for kernel proper (entry). */
- else
- use_ibpb &= ~0x1;
- } else {
- use_ibpb &= ~(0x10|0x1);
- }
+ if (ibpb_supported)
+ use_ibpb |= 0x1;
+}
+static inline void clear_ibpb_inuse(void)
+{
+ use_ibpb &= ~0x1;
}
static inline int check_ibpb_inuse(void)
{
- if (use_ibpb & 0x10)
+ if (use_ibpb & 0x1)
return 1;
else
/* rmb to prevent wrong speculation for security */
static inline void set_ibpb_supported(void)
{
use_ibpb |= 0x2;
- sync_ibpb_inuse();
+ if (!ibpb_disabled)
+ set_ibpb_inuse();
}
static inline void set_ibpb_disabled(void)
{
use_ibpb |= 0x4;
- sync_ibpb_inuse();
+ if (check_ibpb_inuse())
+ clear_ibpb_inuse();
}
static inline void clear_ibpb_disabled(void)
{
use_ibpb &= ~0x4;
- sync_ibpb_inuse();
-}
-static inline void set_ibpb_retpoline_enabled(void)
-{
- use_ibpb |= 0x8;
- sync_ibpb_inuse();
+ set_ibpb_inuse();
}
#define ibpb_inuse (check_ibpb_inuse())
#endif