Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cc26f146 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "arm64: alternative: Support memory protection"

parents cb00cc9b 2ab541e9
Loading
Loading
Loading
Loading
+8 −7
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@
#include <asm/cacheflush.h>
#include <asm/alternative.h>
#include <asm/cpufeature.h>
#include <asm/insn.h>
#include <linux/stop_machine.h>

extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
@@ -31,21 +32,21 @@ extern struct alt_instr __alt_instructions[], __alt_instructions_end[];
static int __apply_alternatives(void *dummy)
{
	struct alt_instr *alt;
	u8 *origptr, *replptr;
	u32 *origptr, *replptr, *endptr;

	for (alt = __alt_instructions; alt < __alt_instructions_end; alt++) {
		if (!cpus_have_cap(alt->cpufeature))
			continue;

		BUG_ON(alt->alt_len > alt->orig_len);
		BUG_ON(alt->alt_len != alt->orig_len);

		pr_info_once("patching kernel code\n");

		origptr = (u8 *)&alt->orig_offset + alt->orig_offset;
		replptr = (u8 *)&alt->alt_offset + alt->alt_offset;
		memcpy(origptr, replptr, alt->alt_len);
		flush_icache_range((uintptr_t)origptr,
				   (uintptr_t)(origptr + alt->alt_len));
		origptr = (void *)&alt->orig_offset + alt->orig_offset;
		endptr = (void *)origptr + alt->orig_len;
		replptr = (void *)&alt->alt_offset + alt->alt_offset;
		for (; origptr < endptr; origptr++, replptr++)
			BUG_ON(aarch64_insn_patch_text_nosync(origptr, *replptr));
	}

	return 0;