qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Bin Meng <bmeng@tinylab.org>, Jason Wang <jasowang@redhat.com>,
	qemu-devel@nongnu.org
Cc: Zhangjin Wu <falcon@tinylab.org>
Subject: Re: [PATCH] net: tap: Drop the close of fds for child process
Date: Thu, 6 Apr 2023 14:34:05 +0200	[thread overview]
Message-ID: <8e935a0b-583b-ed14-fded-b0af760ae99d@linaro.org> (raw)
In-Reply-To: <20230406112041.798585-1-bmeng@tinylab.org>

On 6/4/23 13:20, Bin Meng wrote:
> Current codes using a brute-force traversal of all file descriptors
> do not scale on a system where the maximum number of file descriptors
> are set to a very large value (e.g.: in a Docker container of Manjaro
> distribution it is set to 1073741816). QEMU just looks freezed during
> start-up.
> 
> The close-on-exec flag was introduced since a faily old Linux kernel
> (2.6.23). With recent newer kernels that QEMU supports, we don't need
> to manually close the fds for child process as the proper O_CLOEXEC
> flag should have been set properly on files that we don't want child
> process to see.

But this file is common to all POSIX implementations, not only Linux.

> Reported-by: Zhangjin Wu <falcon@tinylab.org>
> Signed-off-by: Bin Meng <bmeng@tinylab.org>
> ---
> 
>   net/tap.c | 14 --------------
>   1 file changed, 14 deletions(-)
> 
> diff --git a/net/tap.c b/net/tap.c
> index 1bf085d422..49e1915484 100644
> --- a/net/tap.c
> +++ b/net/tap.c
> @@ -446,13 +446,6 @@ static void launch_script(const char *setup_script, const char *ifname,
>           return;
>       }
>       if (pid == 0) {

Maybe guard with #ifndef O_CLOEXEC

> -        int open_max = sysconf(_SC_OPEN_MAX), i;
> -
> -        for (i = 3; i < open_max; i++) {
> -            if (i != fd) {
> -                close(i);
> -            }
> -        }

or add qemu_close_cloexec() in util/osdep.c similar to qemu_open_cloexec()?

>           parg = args;
>           *parg++ = (char *)setup_script;
>           *parg++ = (char *)ifname;
> @@ -536,17 +529,10 @@ static int net_bridge_run_helper(const char *helper, const char *bridge,
>           return -1;
>       }
>       if (pid == 0) {
> -        int open_max = sysconf(_SC_OPEN_MAX), i;
>           char *fd_buf = NULL;
>           char *br_buf = NULL;
>           char *helper_cmd = NULL;
>   
> -        for (i = 3; i < open_max; i++) {
> -            if (i != sv[1]) {
> -                close(i);
> -            }
> -        }
> -
>           fd_buf = g_strdup_printf("%s%d", "--fd=", sv[1]);
>   
>           if (strrchr(helper, ' ') || strrchr(helper, '\t')) {



  reply	other threads:[~2023-04-06 12:34 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-06 11:20 [PATCH] net: tap: Drop the close of fds for child process Bin Meng
2023-04-06 12:34 ` Philippe Mathieu-Daudé [this message]
2023-04-06 12:44   ` Bin Meng
2023-04-18  8:55 ` Daniel P. Berrangé

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=8e935a0b-583b-ed14-fded-b0af760ae99d@linaro.org \
    --to=philmd@linaro.org \
    --cc=bmeng@tinylab.org \
    --cc=falcon@tinylab.org \
    --cc=jasowang@redhat.com \
    --cc=qemu-devel@nongnu.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 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 NNTP newsgroup(s).