arch/arm/mm/proc-v7-bugs.c

Source file repositories/reference/linux-study-clean/arch/arm/mm/proc-v7-bugs.c

File Facts

System
Linux kernel
Corpus path
arch/arm/mm/proc-v7-bugs.c
Extension
.c
Size
6793 bytes
Lines
298
Domain
Architecture Layer
Bucket
arch/arm
Inferred role
Architecture Layer: implementation source
Status
source implementation candidate

Why This File Exists

CPU and platform-specific kernel glue: boot entry, traps, syscall entry, interrupts, page tables, context switch, and low-level barriers.

Dependency Surface

Detected Declarations

Annotated Snippet

if (read_cpuid_implementor() == ARM_CPU_IMP_ARM) {
			state = SPECTRE_UNAFFECTED;
			break;
		}

		fallthrough;

	/* Cortex A57/A72 require firmware workaround */
	case ARM_CPU_PART_CORTEX_A57:
	case ARM_CPU_PART_CORTEX_A72:
		state = spectre_v2_get_cpu_fw_mitigation_state();
		if (state != SPECTRE_MITIGATED)
			break;

		switch (arm_smccc_1_1_get_conduit()) {
		case SMCCC_CONDUIT_HVC:
			method = SPECTRE_V2_METHOD_HVC;
			break;

		case SMCCC_CONDUIT_SMC:
			method = SPECTRE_V2_METHOD_SMC;
			break;

		default:
			state = SPECTRE_VULNERABLE;
			break;
		}
	}

	if (state == SPECTRE_MITIGATED)
		state = spectre_v2_install_workaround(method);

	spectre_v2_update_state(state, method);
}

#ifdef CONFIG_HARDEN_BRANCH_HISTORY
static int spectre_bhb_method;

static const char *spectre_bhb_method_name(int method)
{
	switch (method) {
	case SPECTRE_V2_METHOD_LOOP8:
		return "loop";

	case SPECTRE_V2_METHOD_BPIALL:
		return "BPIALL";

	default:
		return "unknown";
	}
}

static int spectre_bhb_install_workaround(int method)
{
	if (spectre_bhb_method != method) {
		if (spectre_bhb_method) {
			pr_err("CPU%u: Spectre BHB: method disagreement, system vulnerable\n",
			       smp_processor_id());

			return SPECTRE_VULNERABLE;
		}

		if (spectre_bhb_update_vectors(method) == SPECTRE_VULNERABLE)
			return SPECTRE_VULNERABLE;

		spectre_bhb_method = method;

		pr_info("CPU%u: Spectre BHB: enabling %s workaround for all CPUs\n",
			smp_processor_id(), spectre_bhb_method_name(method));
	}

	return SPECTRE_MITIGATED;
}
#else
static int spectre_bhb_install_workaround(int method)
{
	return SPECTRE_VULNERABLE;
}
#endif

static void cpu_v7_spectre_bhb_init(void)
{
	unsigned int state, method = 0;

	switch (read_cpuid_part()) {
	case ARM_CPU_PART_CORTEX_A15:
	case ARM_CPU_PART_BRAHMA_B15:
	case ARM_CPU_PART_CORTEX_A57:
	case ARM_CPU_PART_CORTEX_A72:
		state = SPECTRE_MITIGATED;

Annotation

Implementation Notes