unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Dave Martin via Libc-alpha <libc-alpha@sourceware.org>
To: "H.J. Lu" <hjl.tools@gmail.com>
Cc: GNU C Library <libc-alpha@sourceware.org>, libc-coord@lists.openwall.com
Subject: Re: V4 [PATCH] sysconf: Add _SC_MINSIGSTKSZ/_SC_SIGSTKSZ [BZ #20305]
Date: Mon, 12 Oct 2020 14:21:47 +0100	[thread overview]
Message-ID: <20201012132146.GB32292@arm.com> (raw)
In-Reply-To: <CAMe9rOo5bCBdjHHqeVLd7VdDfoC3P=ZRYEFS-LOJyDmsMS_PwA@mail.gmail.com>

On Mon, Oct 12, 2020 at 05:42:06AM -0700, H.J. Lu via Libc-alpha wrote:
> On Mon, Oct 12, 2020 at 4:04 AM Dave Martin <Dave.Martin@arm.com> wrote:
> >
> > On Mon, Oct 12, 2020 at 08:53:32AM +0100, Szabolcs Nagy via Libc-alpha wrote:
> > > The 10/10/2020 05:19, H.J. Lu via Libc-alpha wrote:
> > > > Add _SC_MINSIGSTKSZ for the minimum signal stack size derived from
> > > > AT_MINSIGSTKSZ, which is the minimum number of bytes of free stack
> > > > space required in order to gurantee successful, non-nested handling
> > > > of a single signal whose handler is an empty function, and _SC_SIGSTKSZ
> > > > which is the suggested minimum number of bytes of stack space required
> > > > for a signal stack.
> > > >
> > > > If AT_MINSIGSTKSZ isn't available, sysconf (_SC_MINSIGSTKSZ) returns
> > > > MINSIGSTKSZ.  On Linux/x86 with XSAVE, the signal frame used by kernel
> > > > is composed of the following areas and laid out as:
> > > >
> > > >  ------------------------------
> > > >  | alignment padding          |
> > > >  ------------------------------
> > > >  | xsave buffer               |
> > > >  ------------------------------
> > > >  | fsave header (32-bit only) |
> > > >  ------------------------------
> > > >  | siginfo + ucontext         |
> > > >  ------------------------------
> > > >
> > > > Compute AT_MINSIGSTKSZ value as size of xsave buffer + size of fsave
> > > > header (32-bit only) + size of siginfo and ucontext + alignment padding.
> > > >
> > > > If _SC_SIGSTKSZ_SOURCE is defined, MINSIGSTKSZ and SIGSTKSZ are redefined
> > > > as
> > > >
> > > > /* Default stack size for a signal handler: sysconf (SC_SIGSTKSZ).  */
> > > >  # undef SIGSTKSZ
> > > >  # define SIGSTKSZ sysconf (_SC_SIGSTKSZ)
> > > >
> > > > /* Minimum stack size for a signal handler: SIGSTKSZ.  */
> > > >  # undef MINSIGSTKSZ
> > > >  # define MINSIGSTKSZ SIGSTKSZ
> > > >
> > > > Compilation will fail if the source assumes constant MINSIGSTKSZ or
> > > > SIGSTKSZ.
> > > >
> > > > The reason for not simply increasing the kernel's MINSIGSTKSZ #define
> > > > (apart from the fact that it is rarely used, due to glibc's shadowing
> > > > definitions) was that userspace binaries will have baked in the old
> > > > value of the constant and may be making assumptions about it.
> > > >
> > > > For example, the type (char [MINSIGSTKSZ]) changes if this #define
> > > > changes.  This could be a problem if an newly built library tries to
> > > > memcpy() or dump such an object defined by and old binary.
> > > > Bounds-checking and the stack sizes passed to things like sigaltstack()
> > > > and makecontext() could similarly go wrong.
> > >
> > >
> > > this looks reasonable to me.
> > >
> > > i added libc-coord on cc as it seems to be
> > > a useful generic api across targets.
> > >
> > >
> > > /* Return MAX (MINSIGSTKSZ, sysconf (_SC_MINSIGSTKSZ)) * 4.  */
> > > this can be excessive for sigstksz,
> > > but reasonable on glibc given the
> > > overhead of libc internal signals
> > > and lazy binding.
> >
> > Interesting points.  Can we put actual numbers on those?
> >
> > Code that tries to allocate correctly sized stacks would need this
> > information.
> >
> > In the presence of things like IFUNC, I suppose there might be no hard
> > limit on the amount of stack that might be required to resolve a
> > symbol, but I hope most IFUNC functions are pretty minimal.
> >
> > > does this decrease the size on any
> > > existing target?
> >
> > To avoid unpleasant surprises, I think we should explicitly clamp both
> > parameters to be no less than the value of the legacy #define.  Then
> > the answer becomes "no" by construction.  Allowing them to be smaller
> > will likely save little memory, so it's probably not worth the risk it.
> 
> I added sysconf-sigstksz.h:
> 
> static long int
> sysconf_sigstksz (void)
> {
>   long int minsigstacksize = GLRO(dl_minsigstacksize);
>   assert (minsigstacksize != 0);
>   _Static_assert (__builtin_constant_p (MINSIGSTKSZ),
>   "MINSIGSTKSZ is constant");
>   if (minsigstacksize < MINSIGSTKSZ)
>     minsigstacksize = MINSIGSTKSZ;
>   /* MAX (MINSIGSTKSZ, sysconf (_SC_MINSIGSTKSZ)) * 4.  */
>   long int sigstacksize = minsigstacksize * 4;
>   /* Return MAX (SIGSTKSZ, sigstacksize).  */
>   _Static_assert (__builtin_constant_p (SIGSTKSZ),
>   "SIGSTKSZ is constant");
>   if (sigstacksize < SIGSTKSZ)
>     sigstacksize = SIGSTKSZ;
>   return sigstacksize;
> }
>
> A target can override it.

Something like that seems reasonable.

> > (The same rule doesn't apply to AT_MINSIGSTKSZ though, since that's a
> > new invention, and purely a property of the kernel.  We yield the "true"
> > kernel value there, which can be less then MINSIGSTKSZ.)
> >
> >
> > On ia64, we should probably override the default "* 4" rule and keep the
> > old value.  There seems zero chance that this architecture will be
> > extended with additional register state, and this avoids making the
> > current huge value even larger.
> 
> IA64 has
> 
> /* Minimum stack size for a signal handler.  */
> #define MINSIGSTKSZ 4096
> 
> /* System default stack size.  */
> #define SIGSTKSZ 16384

Really?  I see in sysdeps/unix/sysv/linux/ia64/bits/sigstack.h:

   Yes, this should be 131072 but the constant got defined incorrectly
   in the kernel and we have to live with it.  Users should in any case
   use SIGSTKSZ as the size user-supplied buffers should have.  */
#define MINSIGSTKSZ     131027

/* System default stack size.  */
#define SIGSTKSZ        262144

(which matches the kernel definitions.)

> On ia64,  SIGSTKSZ is unchanged with and without
> -D_SC_SIGSTKSZ_SOURCE.  If needed, ia64 can override
> bits/sigstksz.h to keep MINSIGSTKSZ and SIGSTKSZ as is.

OK, I guess if the effect is just to leave the old values for ia64 then
that should be fine.

Cheers
---Dave

  reply	other threads:[~2020-10-12 13:21 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-10 12:19 [PATCH] sysconf: Add _SC_MINSIGSTKSZ/_SC_SIGSTKSZ [BZ #20305] H.J. Lu via Libc-alpha
2020-10-12  7:53 ` Szabolcs Nagy via Libc-alpha
2020-10-12 11:04   ` Dave Martin via Libc-alpha
2020-10-12 12:42     ` V4 " H.J. Lu via Libc-alpha
2020-10-12 13:21       ` Dave Martin via Libc-alpha [this message]
2020-10-12 14:12     ` Szabolcs Nagy via Libc-alpha
2020-10-12 14:37       ` Dave Martin via Libc-alpha
2020-10-12 15:36         ` [libc-coord] " Rich Felker
2020-10-12 22:03 ` Joseph Myers
2020-10-13 20:32   ` V5 " H.J. Lu via Libc-alpha
2020-10-14 17:47     ` Dave Martin via Libc-alpha
2020-10-14 18:07       ` Florian Weimer via Libc-alpha
2020-10-19 16:30         ` Dave Martin via Libc-alpha
2020-10-15 11:57       ` V6 " H.J. Lu via Libc-alpha
2020-10-19 15:08         ` Dave Martin via Libc-alpha
2020-10-19 21:32           ` H.J. Lu via Libc-alpha
2020-10-20  9:19             ` Dave Martin via Libc-alpha
2020-10-20 14:59               ` H.J. Lu via Libc-alpha
2020-10-20 15:22                 ` Dave Martin via Libc-alpha
2020-10-20 18:19                 ` V7 " H.J. Lu via Libc-alpha
2020-11-03  3:06                   ` PING: " H.J. Lu via Libc-alpha
2020-11-04 16:50                     ` Dave Martin via Libc-alpha
2020-11-04 17:48                       ` H.J. Lu via Libc-alpha
2020-11-18 14:13                         ` H.J. Lu via Libc-alpha
2020-11-18 14:25                           ` Zack Weinberg
2020-11-18 14:40                             ` H.J. Lu via Libc-alpha
2020-11-18 15:12                               ` Zack Weinberg
2020-11-18 15:17                                 ` H.J. Lu via Libc-alpha
2020-11-18 15:20                                   ` Florian Weimer
2020-11-18 17:04                                     ` Dave Martin via Libc-alpha
2020-11-18 17:35                                       ` Florian Weimer
2020-11-18 17:48                                         ` H.J. Lu via Libc-alpha
2020-11-18 18:09                                         ` Dave Martin via Libc-alpha
2020-11-19 14:59                                           ` Szabolcs Nagy via Libc-alpha
2020-11-19 15:10                                             ` H.J. Lu via Libc-alpha
2020-11-19 15:39                                             ` Zack Weinberg
2020-11-19 15:51                                               ` Florian Weimer
2020-11-19 16:16                                               ` Rich Felker
2020-11-19 16:52                                                 ` Dave Martin via Libc-alpha
2020-11-19 16:37                                             ` Dave Martin via Libc-alpha
2020-11-19 17:29                                               ` Rich Felker
2020-11-19 17:33                                               ` Szabolcs Nagy via Libc-alpha
2020-11-19 19:39                                                 ` Dave Martin via Libc-alpha
2020-11-20 14:08                                           ` H.J. Lu via Libc-alpha
2020-11-20 14:11                                             ` Florian Weimer
2020-11-20 23:13                                               ` V8 " H.J. Lu via Libc-alpha
2021-01-20 14:16                                                 ` Carlos O'Donell via Libc-alpha
2021-01-20 15:05                                                   ` V9 " H.J. Lu via Libc-alpha
2021-01-22 19:41                                                     ` V10 " H.J. Lu via Libc-alpha
2021-01-25 13:31                                                       ` Carlos O'Donell via Libc-alpha
2021-01-25 13:57                                                         ` H.J. Lu via Libc-alpha
2021-01-25 13:59                                                           ` Carlos O'Donell via Libc-alpha
2021-01-25 13:58                                                       ` Carlos O'Donell via Libc-alpha
2021-01-25 14:16                                                         ` Florian Weimer via Libc-alpha
2021-02-02 13:08                                                           ` Carlos O'Donell via Libc-alpha
2021-01-25 14:34                                                         ` Carlos O'Donell via Libc-alpha
2021-01-20 15:06                                                   ` V8 " Florian Weimer via Libc-alpha
2021-01-20 15:30                                                     ` Carlos O'Donell via Libc-alpha
2021-01-20 15:33                                                       ` H.J. Lu via Libc-alpha
2021-01-20 15:59                                                         ` Carlos O'Donell via Libc-alpha
2021-01-20 16:04                                                           ` H.J. Lu via Libc-alpha
2021-01-20 15:33                                                       ` Florian Weimer via Libc-alpha
2020-10-15 12:26       ` [PATCH] Deprecate SIGSTKSZ/MINSIGSTKSZ with _SC_SIGSTKSZ_SOURCE H.J. Lu via Libc-alpha
2020-10-15 19:59         ` Joseph Myers
2020-10-15 21:22           ` V2 " H.J. Lu via Libc-alpha
2020-10-16  0:57             ` Joseph Myers
2021-07-09 18:53             ` Carlos O'Donell via Libc-alpha
2021-07-09 19:34               ` H.J. Lu via Libc-alpha
2020-10-12 22:07 ` [PATCH] sysconf: Add _SC_MINSIGSTKSZ/_SC_SIGSTKSZ [BZ #20305] Joseph Myers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/libc/involved.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201012132146.GB32292@arm.com \
    --to=libc-alpha@sourceware.org \
    --cc=Dave.Martin@arm.com \
    --cc=hjl.tools@gmail.com \
    --cc=libc-coord@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).