Skip to contentSkip to conversation

x86/asm: Merge KSTK_ESP() implementations

PATCH Applied Brian Gerst 3 participants 5 messages Mar 3, 2025 – Mar 4, 2025 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86/asm: Merge KSTK_ESP() implementations

Commit 263042e4630a ("Save user RSP in pt_regs->sp on SYSCALL64 fastpath") simplified the 64-bit implementation of KSTK_ESP() which is now identical to 32-bit. Merge them into a common definition.

No functional change.

---
 arch/x86/include/asm/processor.h | 5 +----
 arch/x86/kernel/process_64.c     | 5 -----
 2 files changed, 1 insertion(+), 9 deletions(-)
arch/x86/include/asm/processor.h +1 -4
index a969bea1ed07..55f0e48413b0 100644
@@ -652,8 +652,6 @@ static __always_inline void prefetchw(const void *x)
 	.sysenter_cs		= __KERNEL_CS,				  \
 }
 
-#define KSTK_ESP(task)		(task_pt_regs(task)->sp)
-
 #else
 extern unsigned long __top_init_kernel_stack[];
 
@@ -661,8 +659,6 @@ extern unsigned long __top_init_kernel_stack[];
 	.sp	= (unsigned long)&__top_init_kernel_stack,		\
 }
 
-extern unsigned long KSTK_ESP(struct task_struct *task);
-
 #endif /* CONFIG_X86_64 */
 
 extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
@@ -676,6 +672,7 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
 #define TASK_UNMAPPED_BASE		__TASK_UNMAPPED_BASE(TASK_SIZE_LOW)
 
 #define KSTK_EIP(task)		(task_pt_regs(task)->ip)
+#define KSTK_ESP(task)		(task_pt_regs(task)->sp)
 
 /* Get/set a process' ability to use the timestamp counter instruction */
 #define GET_TSC_CTL(adr)	get_tsc_mode((adr))
arch/x86/kernel/process_64.c +0 -5
index 4ca73ddfb30b..f983d2a57ac3 100644
@@ -979,8 +979,3 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2)
 
 	return ret;
 }
-
-unsigned long KSTK_ESP(struct task_struct *task)
-{
-	return task_pt_regs(task)->sp;
-}

base-commit: 693c8502970a533363e9ece482c80bb6db0c12a5

Signature · 1 line
2.48.1
merge bot Applied
#1 lore raw
The following commit has been merged into the x86/core branch of tip:

The following commit has been merged into the x86/core branch of tip:

Commit-ID:     399fd7a26441586021ca3722f6a98ff33ed32caf
Gitweb:        https://git.kernel.org/tip/399fd7a26441586021ca3722f6a98ff33ed32caf
Author:        Brian Gerst <[email protected]>
AuthorDate:    Mon, 03 Mar 2025 13:31:11 -05:00
Committer:     Ingo Molnar <[email protected]>
CommitterDate: Mon, 03 Mar 2025 20:28:33 +01:00

x86/asm: Merge KSTK_ESP() implementations

Commit:

263042e4630a ("Save user RSP in pt_regs->sp on SYSCALL64 fastpath")

simplified the 64-bit implementation of KSTK_ESP() which is now identical to 32-bit. Merge them into a common definition.

No functional change.

---
 arch/x86/include/asm/processor.h | 5 +----
 arch/x86/kernel/process_64.c     | 5 -----
 2 files changed, 1 insertion(+), 9 deletions(-)
arch/x86/include/asm/processor.h +1 -4
index c0cd101..0c91108 100644
@@ -668,8 +668,6 @@ static __always_inline void prefetchw(const void *x)
 	.sysenter_cs		= __KERNEL_CS,				  \
 }
 
-#define KSTK_ESP(task)		(task_pt_regs(task)->sp)
-
 #else
 extern unsigned long __top_init_kernel_stack[];
 
@@ -677,8 +675,6 @@ extern unsigned long __top_init_kernel_stack[];
 	.sp	= (unsigned long)&__top_init_kernel_stack,		\
 }
 
-extern unsigned long KSTK_ESP(struct task_struct *task);
-
 #endif /* CONFIG_X86_64 */
 
 extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
@@ -692,6 +688,7 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
 #define TASK_UNMAPPED_BASE		__TASK_UNMAPPED_BASE(TASK_SIZE_LOW)
 
 #define KSTK_EIP(task)		(task_pt_regs(task)->ip)
+#define KSTK_ESP(task)		(task_pt_regs(task)->sp)
 
 /* Get/set a process' ability to use the timestamp counter instruction */
 #define GET_TSC_CTL(adr)	get_tsc_mode((adr))
arch/x86/kernel/process_64.c +0 -5
index 4ca73dd..f983d2a 100644
@@ -979,8 +979,3 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2)
 
 	return ret;
 }
-
-unsigned long KSTK_ESP(struct task_struct *task)
-{
-	return task_pt_regs(task)->sp;
-}
#2 lore raw
In reply to Brian Gerst
Quoted 56 lines · Brian Gerst

Commit 263042e4630a ("Save user RSP in pt_regs->sp on SYSCALL64 fastpath") simplified the 64-bit implementation of KSTK_ESP() which is now identical to 32-bit. Merge them into a common definition.

No functional change.

---
arch/x86/include/asm/processor.h | 5 +----
arch/x86/kernel/process_64.c | 5 -----

2 files changed, 1 insertion(+), 9 deletions(-)
arch/x86/include/asm/processor.h +1 -4
index a969bea1ed07..55f0e48413b0 100644
@@ -652,8 +652,6 @@ static __always_inline void prefetchw(const void *x)
 	.sysenter_cs		= __KERNEL_CS,				  \
 }
 
-#define KSTK_ESP(task)		(task_pt_regs(task)->sp)
-
 #else
 extern unsigned long __top_init_kernel_stack[];
 
@@ -661,8 +659,6 @@ extern unsigned long __top_init_kernel_stack[];
 	.sp	= (unsigned long)&__top_init_kernel_stack,		\
 }
 
-extern unsigned long KSTK_ESP(struct task_struct *task);
-
 #endif /* CONFIG_X86_64 */
 
 extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
@@ -676,6 +672,7 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
 #define TASK_UNMAPPED_BASE		__TASK_UNMAPPED_BASE(TASK_SIZE_LOW)
 
 #define KSTK_EIP(task)		(task_pt_regs(task)->ip)
+#define KSTK_ESP(task)		(task_pt_regs(task)->sp)
 
 /* Get/set a process' ability to use the timestamp counter instruction */
 #define GET_TSC_CTL(adr)	get_tsc_mode((adr))
arch/x86/kernel/process_64.c +0 -5
index 4ca73ddfb30b..f983d2a57ac3 100644
@@ -979,8 +979,3 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2)
 
 	return ret;
 }
-
-unsigned long KSTK_ESP(struct task_struct *task)
-{
-	return task_pt_regs(task)->sp;
-}
Quoted 1 line

base-commit: 693c8502970a533363e9ece482c80bb6db0c12a5

Why using the macro version?

#3 lore raw
Quoted 58 lines · H. Peter Anvin
Quoted 56 lines · Brian Gerst

Commit 263042e4630a ("Save user RSP in pt_regs->sp on SYSCALL64 fastpath") simplified the 64-bit implementation of KSTK_ESP() which is now identical to 32-bit. Merge them into a common definition.

No functional change.

---
arch/x86/include/asm/processor.h | 5 +----
arch/x86/kernel/process_64.c | 5 -----

2 files changed, 1 insertion(+), 9 deletions(-)
arch/x86/include/asm/processor.h +1 -4
index a969bea1ed07..55f0e48413b0 100644
@@ -652,8 +652,6 @@ static __always_inline void prefetchw(const void *x)
      .sysenter_cs            = __KERNEL_CS,                            \
 }
 
-#define KSTK_ESP(task)                (task_pt_regs(task)->sp)
-
 #else
 extern unsigned long __top_init_kernel_stack[];
 
@@ -661,8 +659,6 @@ extern unsigned long __top_init_kernel_stack[];
      .sp     = (unsigned long)&__top_init_kernel_stack,              \
 }
 
-extern unsigned long KSTK_ESP(struct task_struct *task);
-
 #endif /* CONFIG_X86_64 */
 
 extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
@@ -676,6 +672,7 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
 #define TASK_UNMAPPED_BASE            __TASK_UNMAPPED_BASE(TASK_SIZE_LOW)
 
 #define KSTK_EIP(task)                (task_pt_regs(task)->ip)
+#define KSTK_ESP(task)                (task_pt_regs(task)->sp)
 
 /* Get/set a process' ability to use the timestamp counter instruction */
 #define GET_TSC_CTL(adr)      get_tsc_mode((adr))
arch/x86/kernel/process_64.c +0 -5
index 4ca73ddfb30b..f983d2a57ac3 100644
@@ -979,8 +979,3 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2)
 
      return ret;
 }
-
-unsigned long KSTK_ESP(struct task_struct *task)
-{
-      return task_pt_regs(task)->sp;
-}
Quoted 3 lines
Quoted 1 line

base-commit: 693c8502970a533363e9ece482c80bb6db0c12a5

Why using the macro version?

Why call an out-of-line function? I guess it could be an inline function (along with KSK_EIP()).

Brian Gerst

#4 lore raw
Quoted 63 lines · Brian Gerst
Quoted 58 lines · H. Peter Anvin
Quoted 56 lines · Brian Gerst

Commit 263042e4630a ("Save user RSP in pt_regs->sp on SYSCALL64 fastpath") simplified the 64-bit implementation of KSTK_ESP() which is now identical to 32-bit. Merge them into a common definition.

No functional change.

---
arch/x86/include/asm/processor.h | 5 +----
arch/x86/kernel/process_64.c | 5 -----

2 files changed, 1 insertion(+), 9 deletions(-)
arch/x86/include/asm/processor.h +1 -4
index a969bea1ed07..55f0e48413b0 100644
@@ -652,8 +652,6 @@ static __always_inline void prefetchw(const void *x)
      .sysenter_cs            = __KERNEL_CS,                            \
 }
 
-#define KSTK_ESP(task)                (task_pt_regs(task)->sp)
-
 #else
 extern unsigned long __top_init_kernel_stack[];
 
@@ -661,8 +659,6 @@ extern unsigned long __top_init_kernel_stack[];
      .sp     = (unsigned long)&__top_init_kernel_stack,              \
 }
 
-extern unsigned long KSTK_ESP(struct task_struct *task);
-
 #endif /* CONFIG_X86_64 */
 
 extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
@@ -676,6 +672,7 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
 #define TASK_UNMAPPED_BASE            __TASK_UNMAPPED_BASE(TASK_SIZE_LOW)
 
 #define KSTK_EIP(task)                (task_pt_regs(task)->ip)
+#define KSTK_ESP(task)                (task_pt_regs(task)->sp)
 
 /* Get/set a process' ability to use the timestamp counter instruction */
 #define GET_TSC_CTL(adr)      get_tsc_mode((adr))
arch/x86/kernel/process_64.c +0 -5
index 4ca73ddfb30b..f983d2a57ac3 100644
@@ -979,8 +979,3 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2)
 
      return ret;
 }
-
-unsigned long KSTK_ESP(struct task_struct *task)
-{
-      return task_pt_regs(task)->sp;
-}
Quoted 3 lines
Quoted 1 line

base-commit: 693c8502970a533363e9ece482c80bb6db0c12a5

Why using the macro version?

Quoted 6 lines

Why call an out-of-line function? I guess it could be an inline function (along with KSK_EIP()).

Brian Gerst

Ah yes, not out of line obviously.