Skip to contentSkip to conversation

FAILED: patch "[PATCH] arm64: mte: move register initialization to C" failed to apply to 5.10-stable tree

PATCH [email protected] 1 participant 1 message Oct 16, 2022

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

The patch below does not apply to the 5.10-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.

Possible dependencies:

973b9e373306 ("arm64: mte: move register initialization to C") e921da6bc7ca ("arm64/mm: Consolidate TCR_EL1 fields") 7a062ce31807 ("arm64/cpufeature: Optionally disable MTE via command-line") 82868247897b ("arm64: kasan: mte: use a constant kernel GCR_EL1 value") d914b80a8f56 ("arm64: avoid double ISB on kernel entry") 59f44069e052 ("arm64: mte: fix restoration of GCR_EL1 from suspend") fdceddb06a5f ("Merge branch 'for-next/mte' into for-next/core")

thanks,

greg k-h

------------------ original commit in Linus's tree ------------------

From 973b9e37330656dec719ede508e4dc40e5c2d80c Mon Sep 17 00:00:00 2001
From: Peter Collingbourne <[email protected]>
Date: Thu, 15 Sep 2022 15:20:53 -0700
Subject: [PATCH] arm64: mte: move register initialization to C

If FEAT_MTE2 is disabled via the arm64.nomte command line argument on a CPU that claims to support FEAT_MTE2, the kernel will use Tagged Normal in the MAIR. If we interpret arm64.nomte to mean that the CPU does not in fact implement FEAT_MTE2, setting the system register like this may lead to UNSPECIFIED behavior. Fix it by arranging for MAIR to be set in the C function cpu_enable_mte which is called based on the sanitized version of the system register.

There is no need for the rest of the MTE-related system register initialization to happen from assembly, with the exception of TCR_EL1, which must be set to include at least TBI1 because the secondary CPUs access KASan-allocated data structures early. Therefore, make the TCR_EL1 initialization unconditional and move the rest of the initialization to cpu_enable_mte so that we no longer have a dependency on the unsanitized ID register value.

arch/arm64/include/asm/mte.h +5 -0
index aa523591a44e..760c62f8e22f 100644
@@ -42,7 +42,9 @@ void mte_sync_tags(pte_t old_pte, pte_t pte);
 void mte_copy_page_tags(void *kto, const void *kfrom);
 void mte_thread_init_user(void);
 void mte_thread_switch(struct task_struct *next);
+void mte_cpu_setup(void);
 void mte_suspend_enter(void);
+void mte_suspend_exit(void);
 long set_mte_ctrl(struct task_struct *task, unsigned long arg);
 long get_mte_ctrl(struct task_struct *task);
 int mte_ptrace_copy_tags(struct task_struct *child, long request,
@@ -72,6 +74,9 @@ static inline void mte_thread_switch(struct task_struct *next)
 static inline void mte_suspend_enter(void)
 {
 }
+static inline void mte_suspend_exit(void)
+{
+}
 static inline long set_mte_ctrl(struct task_struct *task, unsigned long arg)
 {
 	return 0;
arch/arm64/kernel/cpufeature.c +2 -1
index af4de817d712..d7a077b5ccd1 100644
@@ -2034,7 +2034,8 @@ static void bti_enable(const struct arm64_cpu_capabilities *__unused)
 static void cpu_enable_mte(struct arm64_cpu_capabilities const *cap)
 {
 	sysreg_clear_set(sctlr_el1, 0, SCTLR_ELx_ATA | SCTLR_EL1_ATA0);
-	isb();
+
+	mte_cpu_setup();
 
 	/*
 	 * Clear the tags in the zero page. This needs to be done via the
arch/arm64/kernel/mte.c +51 -0

63 lines not on this page · raw message

arch/arm64/kernel/suspend.c +2 -0
index 9135fe0f3df5..8b02d310838f 100644
@@ -43,6 +43,8 @@ void notrace __cpu_suspend_exit(void)
 {
 	unsigned int cpu = smp_processor_id();
 
+	mte_suspend_exit();
+
 	/*
 	 * We are resuming from reset with the idmap active in TTBR0_EL1.
 	 * We must uninstall the idmap and restore the expected MMU
arch/arm64/mm/proc.S +5 -41

68 lines not on this page · raw message