All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] powerpc/64: Bump SIGSTKSZ and MINSIGSTKSZ
@ 2022-03-07 18:27 Nicholas Piggin
  2022-03-07 18:27 ` [PATCH 2/2] powerpc/signal: Report minimum signal frame size to userspace via AT_MINSIGSTKSZ Nicholas Piggin
  2022-05-24 11:08 ` [PATCH 1/2] powerpc/64: Bump SIGSTKSZ and MINSIGSTKSZ Michael Ellerman
  0 siblings, 2 replies; 4+ messages in thread
From: Nicholas Piggin @ 2022-03-07 18:27 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Tulio Magno Quites Machado Filho, Nicholas Piggin, Alan Modra

The sad tale of SIGSTKSZ and MINSIGSTKSZ is documented in glibc.git
commit f7c399cff5bd ("PowerPC SIGSTKSZ"), which explains why glibc
does not use the kernel defines for these constants. Since then in
fact there has been a further expansion of the signal stack frame size
on little-endian with linux commit 573ebfa6601f ("powerpc: Increase
stack redzone for 64-bit userspace to 512 bytes"), which has caused
it to exceed even the glibc defines.

Increase MINSIGSTKSZ to 8192 which is double the current glibc value
and fits the current stack frame with room to grow. SIGSTKSZ is set
to 4x the minimum as convention.

glibc will have to be updated as well.

Cc: Alan Modra <amodra@gmail.com>
Cc: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/include/uapi/asm/signal.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/arch/powerpc/include/uapi/asm/signal.h b/arch/powerpc/include/uapi/asm/signal.h
index 04873dd311c2..81fa9d90be80 100644
--- a/arch/powerpc/include/uapi/asm/signal.h
+++ b/arch/powerpc/include/uapi/asm/signal.h
@@ -62,8 +62,13 @@ typedef struct {
 
 #define SA_RESTORER	0x04000000U
 
+#ifdef __powerpc64__
+#define MINSIGSTKSZ	8192
+#define SIGSTKSZ	32768
+#else
 #define MINSIGSTKSZ	2048
 #define SIGSTKSZ	8192
+#endif
 
 #include <asm-generic/signal-defs.h>
 
-- 
2.23.0


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

* [PATCH 2/2] powerpc/signal: Report minimum signal frame size to userspace via AT_MINSIGSTKSZ
  2022-03-07 18:27 [PATCH 1/2] powerpc/64: Bump SIGSTKSZ and MINSIGSTKSZ Nicholas Piggin
@ 2022-03-07 18:27 ` Nicholas Piggin
  2022-05-18 12:24   ` Tulio Magno Quites Machado Filho
  2022-05-24 11:08 ` [PATCH 1/2] powerpc/64: Bump SIGSTKSZ and MINSIGSTKSZ Michael Ellerman
  1 sibling, 1 reply; 4+ messages in thread
From: Nicholas Piggin @ 2022-03-07 18:27 UTC (permalink / raw)
  To: linuxppc-dev
  Cc: Tulio Magno Quites Machado Filho, Nicholas Piggin, Alan Modra

Implement the AT_MINSIGSTKSZ AUXV entry, allowing userspace to
dynamically size stack allocations in a manner forward-compatible with
new processor state saved in the signal frame

For now these statically find the maximum signal frame size rather than
doing any runtime testing of features to minimise the size.

glibc 2.34 will take advantage of this, as will applications that use
use _SC_MINSIGSTKSZ and _SC_SIGSTKSZ.

Cc: Alan Modra <amodra@gmail.com>
Cc: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
References: 94b07c1f8c39 ("arm64: signal: Report signal frame size to userspace via auxv")
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
---
 arch/powerpc/include/asm/elf.h         | 14 +++++++++++++-
 arch/powerpc/include/asm/signal.h      |  5 +++++
 arch/powerpc/include/uapi/asm/auxvec.h |  4 +++-
 arch/powerpc/kernel/signal.c           | 15 +++++++++++++++
 arch/powerpc/kernel/signal_32.c        |  6 ++++++
 arch/powerpc/kernel/signal_64.c        |  5 +++++
 6 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
index b8425e3cfd81..19d5c798c566 100644
--- a/arch/powerpc/include/asm/elf.h
+++ b/arch/powerpc/include/asm/elf.h
@@ -160,7 +160,7 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
  *   even if DLINFO_ARCH_ITEMS goes to zero or is undefined.
  * update AT_VECTOR_SIZE_ARCH if the number of NEW_AUX_ENT entries changes
  */
-#define ARCH_DLINFO							\
+#define COMMON_ARCH_DLINFO						\
 do {									\
 	/* Handle glibc compatibility. */				\
 	NEW_AUX_ENT(AT_IGNOREPPC, AT_IGNOREPPC);			\
@@ -173,6 +173,18 @@ do {									\
 	ARCH_DLINFO_CACHE_GEOMETRY;					\
 } while (0)
 
+#define ARCH_DLINFO							\
+do {									\
+	COMMON_ARCH_DLINFO;						\
+	NEW_AUX_ENT(AT_MINSIGSTKSZ, get_min_sigframe_size());		\
+} while (0)
+
+#define COMPAT_ARCH_DLINFO						\
+do {									\
+	COMMON_ARCH_DLINFO;						\
+	NEW_AUX_ENT(AT_MINSIGSTKSZ, get_min_sigframe_size_compat());	\
+} while (0)
+
 /* Relocate the kernel image to @final_address */
 void relocate(unsigned long final_address);
 
diff --git a/arch/powerpc/include/asm/signal.h b/arch/powerpc/include/asm/signal.h
index 99e1c6de27bc..922d43700fb4 100644
--- a/arch/powerpc/include/asm/signal.h
+++ b/arch/powerpc/include/asm/signal.h
@@ -9,4 +9,9 @@
 struct pt_regs;
 void do_notify_resume(struct pt_regs *regs, unsigned long thread_info_flags);
 
+unsigned long get_min_sigframe_size_32(void);
+unsigned long get_min_sigframe_size_64(void);
+unsigned long get_min_sigframe_size(void);
+unsigned long get_min_sigframe_size_compat(void);
+
 #endif /* _ASM_POWERPC_SIGNAL_H */
diff --git a/arch/powerpc/include/uapi/asm/auxvec.h b/arch/powerpc/include/uapi/asm/auxvec.h
index 7af21dc0e320..aa7c16215453 100644
--- a/arch/powerpc/include/uapi/asm/auxvec.h
+++ b/arch/powerpc/include/uapi/asm/auxvec.h
@@ -48,6 +48,8 @@
 #define AT_L3_CACHESIZE		46
 #define AT_L3_CACHEGEOMETRY	47
 
-#define AT_VECTOR_SIZE_ARCH	14 /* entries in ARCH_DLINFO */
+#define AT_MINSIGSTKSZ		51      /* stack needed for signal delivery */
+
+#define AT_VECTOR_SIZE_ARCH	15 /* entries in ARCH_DLINFO */
 
 #endif
diff --git a/arch/powerpc/kernel/signal.c b/arch/powerpc/kernel/signal.c
index b93b87df499d..b3c458db2b8d 100644
--- a/arch/powerpc/kernel/signal.c
+++ b/arch/powerpc/kernel/signal.c
@@ -141,6 +141,21 @@ unsigned long copy_ckvsx_from_user(struct task_struct *task,
 
 int show_unhandled_signals = 1;
 
+unsigned long get_min_sigframe_size(void)
+{
+	if (IS_ENABLED(CONFIG_PPC64))
+		return get_min_sigframe_size_64();
+	else
+		return get_min_sigframe_size_32();
+}
+
+#ifdef CONFIG_COMPAT
+unsigned long get_min_sigframe_size_compat(void)
+{
+	return get_min_sigframe_size_32();
+}
+#endif
+
 /*
  * Allocate space for the signal frame
  */
diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
index d84c434b2b78..157a7403e3eb 100644
--- a/arch/powerpc/kernel/signal_32.c
+++ b/arch/powerpc/kernel/signal_32.c
@@ -233,6 +233,12 @@ struct rt_sigframe {
 	int			abigap[56];
 };
 
+unsigned long get_min_sigframe_size_32(void)
+{
+	return max(sizeof(struct rt_sigframe) + __SIGNAL_FRAMESIZE + 16,
+		   sizeof(struct sigframe) + __SIGNAL_FRAMESIZE);
+}
+
 /*
  * Save the current user registers on the user stack.
  * We only save the altivec/spe registers if the process has used
diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
index d1e1fc0acbea..7c5317e07169 100644
--- a/arch/powerpc/kernel/signal_64.c
+++ b/arch/powerpc/kernel/signal_64.c
@@ -66,6 +66,11 @@ struct rt_sigframe {
 	char abigap[USER_REDZONE_SIZE];
 } __attribute__ ((aligned (16)));
 
+unsigned long get_min_sigframe_size_64(void)
+{
+	return sizeof(struct rt_sigframe) + __SIGNAL_FRAMESIZE;
+}
+
 /*
  * This computes a quad word aligned pointer inside the vmx_reserve array
  * element. For historical reasons sigcontext might not be quad word aligned,
-- 
2.23.0


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

* Re: [PATCH 2/2] powerpc/signal: Report minimum signal frame size to userspace via AT_MINSIGSTKSZ
  2022-03-07 18:27 ` [PATCH 2/2] powerpc/signal: Report minimum signal frame size to userspace via AT_MINSIGSTKSZ Nicholas Piggin
@ 2022-05-18 12:24   ` Tulio Magno Quites Machado Filho
  0 siblings, 0 replies; 4+ messages in thread
From: Tulio Magno Quites Machado Filho @ 2022-05-18 12:24 UTC (permalink / raw)
  To: Nicholas Piggin, linuxppc-dev; +Cc: Alan Modra

Nicholas Piggin <npiggin@gmail.com> writes:

> Implement the AT_MINSIGSTKSZ AUXV entry, allowing userspace to
> dynamically size stack allocations in a manner forward-compatible with
> new processor state saved in the signal frame
>
> For now these statically find the maximum signal frame size rather than
> doing any runtime testing of features to minimise the size.
>
> glibc 2.34 will take advantage of this, as will applications that use
> use _SC_MINSIGSTKSZ and _SC_SIGSTKSZ.
>
> Cc: Alan Modra <amodra@gmail.com>
> Cc: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
> References: 94b07c1f8c39 ("arm64: signal: Report signal frame size to userspace via auxv")
> Signed-off-by: Nicholas Piggin <npiggin@gmail.com>

Both patches LGTM from a glibc point of view.

Reviewed-by: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>

Thanks!

-- 
Tulio Magno

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

* Re: [PATCH 1/2] powerpc/64: Bump SIGSTKSZ and MINSIGSTKSZ
  2022-03-07 18:27 [PATCH 1/2] powerpc/64: Bump SIGSTKSZ and MINSIGSTKSZ Nicholas Piggin
  2022-03-07 18:27 ` [PATCH 2/2] powerpc/signal: Report minimum signal frame size to userspace via AT_MINSIGSTKSZ Nicholas Piggin
@ 2022-05-24 11:08 ` Michael Ellerman
  1 sibling, 0 replies; 4+ messages in thread
From: Michael Ellerman @ 2022-05-24 11:08 UTC (permalink / raw)
  To: Nicholas Piggin, linuxppc-dev
  Cc: Tulio Magno Quites Machado Filho, Alan Modra

On Tue, 8 Mar 2022 04:27:33 +1000, Nicholas Piggin wrote:
> The sad tale of SIGSTKSZ and MINSIGSTKSZ is documented in glibc.git
> commit f7c399cff5bd ("PowerPC SIGSTKSZ"), which explains why glibc
> does not use the kernel defines for these constants. Since then in
> fact there has been a further expansion of the signal stack frame size
> on little-endian with linux commit 573ebfa6601f ("powerpc: Increase
> stack redzone for 64-bit userspace to 512 bytes"), which has caused
> it to exceed even the glibc defines.
> 
> [...]

Applied to powerpc/next.

[1/2] powerpc/64: Bump SIGSTKSZ and MINSIGSTKSZ
      https://git.kernel.org/powerpc/c/2f82ec19757f58549467db568c56e7dfff8af283
[2/2] powerpc/signal: Report minimum signal frame size to userspace via AT_MINSIGSTKSZ
      https://git.kernel.org/powerpc/c/2896b2dff49d0377e4372f470dcddbcb26f2be59

cheers

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

end of thread, other threads:[~2022-05-24 11:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-07 18:27 [PATCH 1/2] powerpc/64: Bump SIGSTKSZ and MINSIGSTKSZ Nicholas Piggin
2022-03-07 18:27 ` [PATCH 2/2] powerpc/signal: Report minimum signal frame size to userspace via AT_MINSIGSTKSZ Nicholas Piggin
2022-05-18 12:24   ` Tulio Magno Quites Machado Filho
2022-05-24 11:08 ` [PATCH 1/2] powerpc/64: Bump SIGSTKSZ and MINSIGSTKSZ Michael Ellerman

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.