All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] arm64 related PREEMPT_RT patches.
@ 2022-05-05 16:32 Sebastian Andrzej Siewior
  2022-05-05 16:32 ` [PATCH 1/3] arm64/sve: Delay freeing memory in fpsimd_flush_thread() Sebastian Andrzej Siewior
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2022-05-05 16:32 UTC (permalink / raw)
  To: linux-arm-kernel; +Cc: Catalin Marinas, Will Deacon, Thomas Gleixner

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
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/3] arm64/sve: Delay freeing memory in fpsimd_flush_thread()
  2022-05-05 16:32 [PATCH 0/3] arm64 related PREEMPT_RT patches Sebastian Andrzej Siewior
@ 2022-05-05 16:32 ` Sebastian Andrzej Siewior
  2022-05-10 18:31   ` Mark Brown
  2022-05-05 16:32 ` [PATCH 2/3] arm64/sve: Make kernel FPU protection RT friendly Sebastian Andrzej Siewior
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2022-05-05 16:32 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Catalin Marinas, Will Deacon, Thomas Gleixner, Sebastian Andrzej Siewior

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.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 arch/arm64/kernel/fpsimd.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
index 95a733d3b2538..475939beb0167 100644
--- a/arch/arm64/kernel/fpsimd.c
+++ b/arch/arm64/kernel/fpsimd.c
@@ -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);
 }
 
 /*
-- 
2.36.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/3] arm64/sve: Make kernel FPU protection RT friendly
  2022-05-05 16:32 [PATCH 0/3] arm64 related PREEMPT_RT patches Sebastian Andrzej Siewior
  2022-05-05 16:32 ` [PATCH 1/3] arm64/sve: Delay freeing memory in fpsimd_flush_thread() Sebastian Andrzej Siewior
@ 2022-05-05 16:32 ` Sebastian Andrzej Siewior
  2022-05-10 18:34   ` Mark Brown
  2022-05-05 16:32 ` [PATCH 3/3] arm64: mm: Make arch_faults_on_old_pte() check for migratability Sebastian Andrzej Siewior
  2022-05-16 18:47 ` [PATCH 0/3] arm64 related PREEMPT_RT patches Catalin Marinas
  3 siblings, 1 reply; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2022-05-05 16:32 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Catalin Marinas, Will Deacon, Thomas Gleixner, 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.

Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
---
 arch/arm64/kernel/fpsimd.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/arch/arm64/kernel/fpsimd.c b/arch/arm64/kernel/fpsimd.c
index 475939beb0167..ce4ee36b1da88 100644
--- a/arch/arm64/kernel/fpsimd.c
+++ b/arch/arm64/kernel/fpsimd.c
@@ -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)
-- 
2.36.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/3] arm64: mm: Make arch_faults_on_old_pte() check for migratability
  2022-05-05 16:32 [PATCH 0/3] arm64 related PREEMPT_RT patches Sebastian Andrzej Siewior
  2022-05-05 16:32 ` [PATCH 1/3] arm64/sve: Delay freeing memory in fpsimd_flush_thread() Sebastian Andrzej Siewior
  2022-05-05 16:32 ` [PATCH 2/3] arm64/sve: Make kernel FPU protection RT friendly Sebastian Andrzej Siewior
@ 2022-05-05 16:32 ` Sebastian Andrzej Siewior
  2022-05-16 18:47 ` [PATCH 0/3] arm64 related PREEMPT_RT patches Catalin Marinas
  3 siblings, 0 replies; 7+ messages in thread
From: Sebastian Andrzej Siewior @ 2022-05-05 16:32 UTC (permalink / raw)
  To: linux-arm-kernel
  Cc: Catalin Marinas, Will Deacon, Thomas Gleixner,
	Valentin Schneider, Valentin Schneider,
	Sebastian Andrzej Siewior

From: Valentin Schneider <valentin.schneider@arm.com>

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().

Cc: Valentin Schneider <vschneid@redhat.com>
Suggested-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Valentin Schneider <valentin.schneider@arm.com>
Link: https://lore.kernel.org/r/20220127192437.1192957-1-valentin.schneider@arm.com
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
---
 arch/arm64/include/asm/pgtable.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h
index 8ebf1cec5d901..5a53558578ab3 100644
--- a/arch/arm64/include/asm/pgtable.h
+++ b/arch/arm64/include/asm/pgtable.h
@@ -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();
 }
-- 
2.36.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/3] arm64/sve: Delay freeing memory in fpsimd_flush_thread()
  2022-05-05 16:32 ` [PATCH 1/3] arm64/sve: Delay freeing memory in fpsimd_flush_thread() Sebastian Andrzej Siewior
@ 2022-05-10 18:31   ` Mark Brown
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2022-05-10 18:31 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-arm-kernel, Catalin Marinas, Will Deacon, Thomas Gleixner


[-- Attachment #1.1: Type: text/plain, Size: 418 bytes --]

On Thu, May 05, 2022 at 06:32:05PM +0200, Sebastian Andrzej Siewior wrote:
> fpsimd_flush_thread() invokes kfree() via sve_free()+sme_free() within a
> preempt disabled section which is not working on -RT.

Reviewed-by: Mark Brown <broonie@kernel.org>

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.

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 2/3] arm64/sve: Make kernel FPU protection RT friendly
  2022-05-05 16:32 ` [PATCH 2/3] arm64/sve: Make kernel FPU protection RT friendly Sebastian Andrzej Siewior
@ 2022-05-10 18:34   ` Mark Brown
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2022-05-10 18:34 UTC (permalink / raw)
  To: Sebastian Andrzej Siewior
  Cc: linux-arm-kernel, Catalin Marinas, Will Deacon, Thomas Gleixner


[-- Attachment #1.1: Type: text/plain, Size: 310 bytes --]

On Thu, May 05, 2022 at 06:32:06PM +0200, Sebastian Andrzej Siewior wrote:
> 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.

Acked-by: Mark Brown <broonie@kernel.org>

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 0/3] arm64 related PREEMPT_RT patches.
  2022-05-05 16:32 [PATCH 0/3] arm64 related PREEMPT_RT patches Sebastian Andrzej Siewior
                   ` (2 preceding siblings ...)
  2022-05-05 16:32 ` [PATCH 3/3] arm64: mm: Make arch_faults_on_old_pte() check for migratability Sebastian Andrzej Siewior
@ 2022-05-16 18:47 ` Catalin Marinas
  3 siblings, 0 replies; 7+ messages in thread
From: Catalin Marinas @ 2022-05-16 18:47 UTC (permalink / raw)
  To: linux-arm-kernel, Sebastian Andrzej Siewior; +Cc: Will Deacon, Thomas Gleixner

On Thu, 5 May 2022 18:32:04 +0200, Sebastian Andrzej Siewior wrote:
> 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.

-- 
Catalin


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-05-16 18:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-05 16:32 [PATCH 0/3] arm64 related PREEMPT_RT patches Sebastian Andrzej Siewior
2022-05-05 16:32 ` [PATCH 1/3] arm64/sve: Delay freeing memory in fpsimd_flush_thread() Sebastian Andrzej Siewior
2022-05-10 18:31   ` Mark Brown
2022-05-05 16:32 ` [PATCH 2/3] arm64/sve: Make kernel FPU protection RT friendly Sebastian Andrzej Siewior
2022-05-10 18:34   ` Mark Brown
2022-05-05 16:32 ` [PATCH 3/3] arm64: mm: Make arch_faults_on_old_pte() check for migratability Sebastian Andrzej Siewior
2022-05-16 18:47 ` [PATCH 0/3] arm64 related PREEMPT_RT patches Catalin Marinas

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.