On 6/16/23 17:27, Bin Meng wrote:
From: Zhangjin Wu<[email protected]>

Current codes using a brute-force traversal of all file descriptors
do not scale on a system where the maximum number of file descriptors
is set to a very large value (e.g.: in a Docker container of Manjaro
distribution it is set to 1073741816). QEMU just looks frozen during
start-up.

The close-on-exec flag (O_CLOEXEC) was introduced since Linux kernel
2.6.23, FreeBSD 8.3, OpenBSD 5.0, Solaris 11. While it's true QEMU
doesn't need to manually close the fds for child process as the proper
O_CLOEXEC flag should have been set properly on files with its own
codes, QEMU uses a huge number of 3rd party libraries and we don't
trust them to reliably be using O_CLOEXEC on everything they open.

Modern Linux and BSDs have the close_range() call we can use to do the
job, and on Linux we have one more way to walk through /proc/self/fd
to complete the task efficiently, which is what qemu_close_range() does.

Reported-by: Zhangjin Wu<[email protected]>
Signed-off-by: Zhangjin Wu<[email protected]>
Signed-off-by: Bin Meng<[email protected]>

---

Changes in v2:
- Change to use qemu_close_range() to close fds for child process efficiently
- v1 
link:https://lore.kernel.org/qemu-devel/[email protected]/

  net/tap.c | 23 +++++++++++------------
  1 file changed, 11 insertions(+), 12 deletions(-)

Reviewed-by: Richard Henderson <[email protected]>

r~

Reply via email to