public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top, Andrea Bolognani <abologna@redhat.com>
Subject: Re: [PATCH] util: Set NS_FN_STACK_SIZE to one eighth of ulimit-reported maximum stack size
Date: Mon, 24 Oct 2022 10:36:19 +1100	[thread overview]
Message-ID: <Y1XP82roRw+gkvQM@yekko> (raw)
In-Reply-To: <20221022101535.4ceda8d6@elisabeth>

[-- Attachment #1: Type: text/plain, Size: 2804 bytes --]

On Sat, Oct 22, 2022 at 10:15:35AM +0200, Stefano Brivio wrote:
> On Sat, 22 Oct 2022 08:45:03 +0200
> Stefano Brivio <sbrivio@redhat.com> wrote:
> 
> > ...instead of one fourth. On the main() -> conf() -> nl_sock_init()
> > call path, LTO from gcc 12 on (at least) x86_64 decides to inline...
> > everything: nl_sock_init() is effectively part of main(), after
> > commit 3e2eb4337bc0 ("conf: Bind inbound ports with
> > CAP_NET_BIND_SERVICE before isolate_user()").
> > 
> > This means we exceed the maximum stack size, and we get SIGSEGV,
> > under any condition, at start time, as reported by Andrea on a recent
> > build for CentOS Stream 9.
> > 
> > The calculation of NS_FN_STACK_SIZE, which is the stack size we
> > reserve for clones, was previously obtained by dividing the maximum
> > stack size by two, to avoid an explicit check on architecture (on
> > PA-RISC, also known as hppa, the stack grows up, so we point the
> > clone to the middle of this area), and then further divided by two
> > to allow for any additional usage in the caller.
> > 
> > Well, if there are essentially no function calls anymore, this is
> > not enough. Divide it by eight, which is anyway much more than
> > possibly needed by any clone()d callee.
> > 
> > I think this is robust, so it's a fix in some sense. Strictly
> > speaking, though, we have no formal guarantees that this isn't
> > either too little or too much.
> > 
> > What we should do, eventually: check cloned() callees, there are just
> > thirteen of them at the moment. Note down any stack usage (they are
> > mostly small helpers), bonus points for an automated way at build
> > time, quadruple that or so, to allow for extreme clumsiness, and use
> > as NS_FN_STACK_SIZE. Perhaps introduce a specific condition for hppa.
> > 
> > Reported-by: Andrea Bolognani <abologna@redhat.com>
> > Fixes: 3e2eb4337bc0 ("conf: Bind inbound ports with CAP_NET_BIND_SERVICE before isolate_user()")
> > Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
> > ---
> 
> I posted this in any case for (later) review, but I'm actually applying
> it right away, given that some builds are completely unusable otherwise.

That's sensible, however, this patch confuses me.  I don't really
understand how reducing the stack size is avoiding a SEGV, regardless
of what LTO does.  The fact that we're basing the runtime stack size
on a limit that's from build time also doesn't really make sense to
me.

> I guess it would make sense to extend build ("distro") tests with some
> compiler flags, common and less common.
> 

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

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

  reply	other threads:[~2022-10-23 23:43 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-22  6:45 [PATCH] util: Set NS_FN_STACK_SIZE to one eighth of ulimit-reported maximum stack size Stefano Brivio
2022-10-22  8:15 ` Stefano Brivio
2022-10-23 23:36   ` David Gibson [this message]
2022-10-23 23:52     ` David Gibson
2022-10-24  0:36       ` Stefano Brivio

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

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

  git send-email \
    --in-reply-to=Y1XP82roRw+gkvQM@yekko \
    --to=david@gibson.dropbear.id.au \
    --cc=abologna@redhat.com \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.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.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

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 IMAP folder(s).