All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Richard Henderson <richard.henderson@linaro.org>
Cc: qemu-devel@nongnu.org, "Clément Léger" <cleger@rivosinc.com>
Subject: Re: [PULL 3/6] qemu/osdep: Split qemu_close_all_open_fd() and add fallback
Date: Thu, 29 Aug 2024 08:14:56 +0100	[thread overview]
Message-ID: <ZtAf3kZkKXrCFpIk@redhat.com> (raw)
In-Reply-To: <bea888ca-9221-4c51-bcd1-c869d73094ae@linaro.org>

On Thu, Aug 29, 2024 at 08:47:27AM +1000, Richard Henderson wrote:
> On 8/28/24 22:48, Daniel P. Berrangé wrote:
> > >       dir = opendir("/proc/self/fd");
> > 
> > IIUC from previous threads this is valid on Linux and on Solaris.
> > 
> > On FreeBSD & macOS, you need /dev/fd though.
> 
> Fair, but importantly, it doesn't do anything *incorrect* those systems: it
> merely skips this method with ENOENT.
> 
> > > +    int open_max = sysconf(_SC_OPEN_MAX), i;
> > > +
> > > +    /* Fallback */
> > > +    for (i = 0; i < open_max; i++) {
> > > +        close(i);
> > > +    }
> > 
> > I'm told that sysconf(_SC_OPEN_MAX) returns -1 on some versions of
> > macOS. "Luckily" since we assigned to 'int' rather than 'unsigned int'
> > this will result in us not closing any FDs in this fallback path,
> > rather than trying to close several billion FDs (an effective hang).
> 
> Ouch.
> 
> > 
> > If _SC_OPEN_MAX returns -1, we should fallback to the OPEN_MAX
> > constant on macOS (see commit de448e0f26e710e9d2b7fc91393c40ac24b75847
> > which tackled a similar issue wrt getrlimit), and fallback to perhaps
> > a hardcoded 1024 on non-macOS.
> 
> I wish the timing on this had been better -- 25 minutes earlier and I would have delayed rc4.
> 
> Since macOS simply doesn't close fds, I'm of a mind to release 9.1.0 without
> this, and fix it for 9.1.1.  Thoughts?

The original net/tap.c code for closing FDs has the same bug, so in that
area we do NOT have a regression.

The original async teardown code would fail to close FDs as it is looking
for close_range or /proc/$PID/fd, and has no sysconf fallback, so again
no regression there.

IOW, I think this is acceptable to fix in 9.1 stable.

With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|



  reply	other threads:[~2024-08-29  7:16 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-05  0:31 [PULL 0/6] misc patch queue Richard Henderson
2024-08-05  0:31 ` [PULL 1/6] linux-user/elfload: Fix pr_pid values in core files Richard Henderson
2024-08-05  0:31 ` [PATCH for-9.1] target/i386: Fix VSIB decode Richard Henderson
2024-08-05 12:10   ` Paolo Bonzini
2024-08-05  0:31 ` [PULL 2/6] qemu/osdep: Move close_all_open_fds() to oslib-posix Richard Henderson
2024-08-05  0:31 ` [PULL 3/6] qemu/osdep: Split qemu_close_all_open_fd() and add fallback Richard Henderson
2024-08-28 12:48   ` Daniel P. Berrangé
2024-08-28 13:09     ` Clément Léger
2024-08-28 22:47     ` Richard Henderson
2024-08-29  7:14       ` Daniel P. Berrangé [this message]
2024-08-05  0:31 ` [PULL 4/6] net/tap: Factorize fd closing after forking Richard Henderson
2024-08-05  0:31 ` [PULL 5/6] qemu/osdep: Add excluded fd parameter to qemu_close_all_open_fd() Richard Henderson
2024-08-05  0:31 ` [PULL 6/6] net/tap: Use qemu_close_all_open_fd() Richard Henderson
2024-08-05 21:59 ` [PULL 0/6] misc patch queue Richard Henderson

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=ZtAf3kZkKXrCFpIk@redhat.com \
    --to=berrange@redhat.com \
    --cc=cleger@rivosinc.com \
    --cc=qemu-devel@nongnu.org \
    --cc=richard.henderson@linaro.org \
    /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 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.