Unverified Commit e77c0a41 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!585 x86/speculation: Allow enabling STIBP with legacy IBRS

parents 693a53a5 811a507c
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -1051,14 +1051,18 @@ spectre_v2_parse_user_cmdline(void)
	return SPECTRE_V2_USER_CMD_AUTO;
}

static inline bool spectre_v2_in_ibrs_mode(enum spectre_v2_mitigation mode)
static inline bool spectre_v2_in_eibrs_mode(enum spectre_v2_mitigation mode)
{
	return mode == SPECTRE_V2_IBRS ||
	       mode == SPECTRE_V2_EIBRS ||
	return mode == SPECTRE_V2_EIBRS ||
	       mode == SPECTRE_V2_EIBRS_RETPOLINE ||
	       mode == SPECTRE_V2_EIBRS_LFENCE;
}

static inline bool spectre_v2_in_ibrs_mode(enum spectre_v2_mitigation mode)
{
	return spectre_v2_in_eibrs_mode(mode) || mode == SPECTRE_V2_IBRS;
}

static void __init
spectre_v2_user_select_mitigation(void)
{
@@ -1121,12 +1125,19 @@ spectre_v2_user_select_mitigation(void)
	}

	/*
	 * If no STIBP, IBRS or enhanced IBRS is enabled, or SMT impossible,
	 * STIBP is not required.
	 * If no STIBP, enhanced IBRS is enabled, or SMT impossible, STIBP
	 * is not required.
	 *
	 * Enhanced IBRS also protects against cross-thread branch target
	 * injection in user-mode as the IBRS bit remains always set which
	 * implicitly enables cross-thread protections.  However, in legacy IBRS
	 * mode, the IBRS bit is set only on kernel entry and cleared on return
	 * to userspace. This disables the implicit cross-thread protection,
	 * so allow for STIBP to be selected in that case.
	 */
	if (!boot_cpu_has(X86_FEATURE_STIBP) ||
	    !smt_possible ||
	    spectre_v2_in_ibrs_mode(spectre_v2_enabled))
	    spectre_v2_in_eibrs_mode(spectre_v2_enabled))
		return;

	/*
@@ -2220,7 +2231,7 @@ static ssize_t mmio_stale_data_show_state(char *buf)

static char *stibp_state(void)
{
	if (spectre_v2_in_ibrs_mode(spectre_v2_enabled))
	if (spectre_v2_in_eibrs_mode(spectre_v2_enabled))
		return "";

	switch (spectre_v2_user_stibp) {