Skip to contentSkip to conversation

arm64 related PREEMPT_RT patches.

PATCH Applied Sebastian Andrzej Siewior 3 participants 7 messages May 5, 2022 – May 16, 2022 arm64

lore
Share & tools
lore
#0 lore raw

cover arm64 related PREEMPT_RT patches.

This is what I have for ARM64 in my PREEMPT_RT queue of what I believe won't change.

#1 + #2 Were posted before and I don't remember the outcome other than
to opencode the kfree() in #1.

#3 Replaces a warning and Will said that there is a patch in
"multi-generational LRU series" which gets rid of it. I'm posting it again since it isn't -next.

Sebastian

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#1 lore raw

PATCH 1/3 arm64/sve: Delay freeing memory in fpsimd_flush_thread()

fpsimd_flush_thread() invokes kfree() via sve_free()+sme_free() within a preempt disabled section which is not working on -RT.

Delay freeing of memory until preemption is enabled again.

---
 arch/arm64/kernel/fpsimd.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
arch/arm64/kernel/fpsimd.c +15 -2
index 95a733d3b2538..475939beb0167 100644
@@ -1562,6 +1562,9 @@ static void fpsimd_flush_thread_vl(enum vec_type type)
 
 void fpsimd_flush_thread(void)
 {
+	void *sve_state = NULL;
+	void *za_state = NULL;
+
 	if (!system_supports_fpsimd())
 		return;
 
@@ -1573,18 +1576,28 @@ void fpsimd_flush_thread(void)
 
 	if (system_supports_sve()) {
 		clear_thread_flag(TIF_SVE);
-		sve_free(current);
+
+		/* Defer kfree() while in atomic context */
+		sve_state = current->thread.sve_state;
+		current->thread.sve_state = NULL;
+
 		fpsimd_flush_thread_vl(ARM64_VEC_SVE);
 	}
 
 	if (system_supports_sme()) {
 		clear_thread_flag(TIF_SME);
-		sme_free(current);
+
+		/* Defer kfree() while in atomic context */
+		za_state = current->thread.za_state;
+		current->thread.za_state = NULL;
+
 		fpsimd_flush_thread_vl(ARM64_VEC_SME);
 		current->thread.svcr = 0;
 	}
 
 	put_cpu_fpsimd_context();
+	kfree(sve_state);
+	kfree(za_state);
 }
 
 /*
Signature · 7 lines
2.36.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] arm64/sve: Delay freeing memory in fpsimd_flush_thread()

Quoted 2 lines · Sebastian Andrzej Siewior

fpsimd_flush_thread() invokes kfree() via sve_free()+sme_free() within a preempt disabled section which is not working on -RT.

It'd be better to copy people actively working on the specific code you're patching as well as the architecture maintainers, it helps things get noticed for review.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#3 lore raw

PATCH 2/3 arm64/sve: Make kernel FPU protection RT friendly

In reply to Sebastian Andrzej Siewior

Non RT kernels need to protect FPU against preemption and bottom half processing. This is achieved by disabling bottom halves via local_bh_disable() which implictly disables preemption.

On RT kernels this protection mechanism is not sufficient because local_bh_disable() does not disable preemption. It serializes bottom half related processing via a CPU local lock.

As bottom halves are running always in thread context on RT kernels disabling preemption is the proper choice as it implicitly prevents bottom half processing.

---
 arch/arm64/kernel/fpsimd.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
arch/arm64/kernel/fpsimd.c +14 -2
index 475939beb0167..ce4ee36b1da88 100644
@@ -237,10 +237,19 @@ static void __get_cpu_fpsimd_context(void)
  *
  * The double-underscore version must only be called if you know the task
  * can't be preempted.
+ *
+ * On RT kernels local_bh_disable() is not sufficient because it only
+ * serializes soft interrupt related sections via a local lock, but stays
+ * preemptible. Disabling preemption is the right choice here as bottom
+ * half processing is always in thread context on RT kernels so it
+ * implicitly prevents bottom half processing as well.
  */
 static void get_cpu_fpsimd_context(void)
 {
-	local_bh_disable();
+	if (!IS_ENABLED(CONFIG_PREEMPT_RT))
+		local_bh_disable();
+	else
+		preempt_disable();
 	__get_cpu_fpsimd_context();
 }
 
@@ -261,7 +270,10 @@ static void __put_cpu_fpsimd_context(void)
 static void put_cpu_fpsimd_context(void)
 {
 	__put_cpu_fpsimd_context();
-	local_bh_enable();
+	if (!IS_ENABLED(CONFIG_PREEMPT_RT))
+		local_bh_enable();
+	else
+		preempt_enable();
 }
 
 static bool have_cpu_fpsimd_context(void)
Signature · 7 lines
2.36.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Acked-by on v1 2/3
#4 lore raw

Re: [PATCH 2/3] arm64/sve: Make kernel FPU protection RT friendly

Quoted 3 lines · Sebastian Andrzej Siewior

Non RT kernels need to protect FPU against preemption and bottom half processing. This is achieved by disabling bottom halves via local_bh_disable() which implictly disables preemption.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#5 lore raw

PATCH 3/3 arm64: mm: Make arch_faults_on_old_pte() check for migratability

In reply to Sebastian Andrzej Siewior

From: Valentin Schneider <[email protected]>

arch_faults_on_old_pte() relies on the calling context being non-preemptible. CONFIG_PREEMPT_RT turns the PTE lock into a sleepable spinlock, which doesn't disable preemption once acquired, triggering the warning in arch_faults_on_old_pte().

It does however disable migration, ensuring the task remains on the same CPU during the entirety of the critical section, making the read of cpu_has_hw_af() safe and stable.

Make arch_faults_on_old_pte() check cant_migrate() instead of preemptible().

---
 arch/arm64/include/asm/pgtable.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arch/arm64/include/asm/pgtable.h +2 -1
index 8ebf1cec5d901..5a53558578ab3 100644
@@ -1018,7 +1018,8 @@ static inline void update_mmu_cache(struct vm_area_struct *vma,
  */
 static inline bool arch_faults_on_old_pte(void)
 {
-	WARN_ON(preemptible());
+	/* The register read below requires a stable CPU to make any sense */
+	cant_migrate();
 
 	return !cpu_has_hw_af();
 }
Signature · 7 lines
2.36.0


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
maintainer Applied
#6 lore raw
In reply to Sebastian Andrzej Siewior
Quoted 11 lines · Sebastian Andrzej Siewior

This is what I have for ARM64 in my PREEMPT_RT queue of what I believe won't change.

#1 + #2 Were posted before and I don't remember the outcome other than
to opencode the kfree() in #1.

#3 Replaces a warning and Will said that there is a patch in
"multi-generational LRU series" which gets rid of it. I'm posting it again since it isn't -next.

[...]

Applied to arm64 (for-next/sme), thanks!

[1/3] arm64/sve: Delay freeing memory in fpsimd_flush_thread()

      https://git.kernel.org/arm64/c/a1259dd80719
[2/3] arm64/sve: Make kernel FPU protection RT friendly
      https://git.kernel.org/arm64/c/696207d4258b

I appled patch 3 as well to for-next/misc but b4 cannot cope with applying two subsets of a series.

Signature · 7 lines
Catalin


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel