From 22ca1e7738025ae38d07c05bae2af934b1b2c11f Mon Sep 17 00:00:00 2001
From: Heiko Carstens <hca@linux.ibm.com>
Date: Mon, 27 Mar 2023 11:37:27 +0200
Subject: [PATCH] s390: move on_thread_stack() to processor.h

As preparation for the stackleak feature move on_thread_stack() to
processor.h like x86.

Also make it __always_inline, and slightly optimize it by reading
current task's kernel stack pointer from lowcore.

Reviewed-by: Vasily Gorbik <gor@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
---
 arch/s390/include/asm/entry-common.h | 5 -----
 arch/s390/include/asm/processor.h    | 7 +++++++
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/arch/s390/include/asm/entry-common.h b/arch/s390/include/asm/entry-common.h
index 000de2b1e67a2..fdd319a622b06 100644
--- a/arch/s390/include/asm/entry-common.h
+++ b/arch/s390/include/asm/entry-common.h
@@ -60,9 +60,4 @@ static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs,
 
 #define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare
 
-static inline bool on_thread_stack(void)
-{
-	return !(((unsigned long)(current->stack) ^ current_stack_pointer) & ~(THREAD_SIZE - 1));
-}
-
 #endif
diff --git a/arch/s390/include/asm/processor.h b/arch/s390/include/asm/processor.h
index 80ac0c1034dc8..efffc28cbad8d 100644
--- a/arch/s390/include/asm/processor.h
+++ b/arch/s390/include/asm/processor.h
@@ -226,6 +226,13 @@ static __always_inline unsigned long __current_stack_pointer(void)
 	return sp;
 }
 
+static __always_inline bool on_thread_stack(void)
+{
+	unsigned long ksp = S390_lowcore.kernel_stack;
+
+	return !((ksp ^ current_stack_pointer) & ~(THREAD_SIZE - 1));
+}
+
 static __always_inline unsigned short stap(void)
 {
 	unsigned short cpu_address;
-- 
GitLab