From nobody Thu May 2 00:05:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1660305022306515.7896462925377; Fri, 12 Aug 2022 04:50:22 -0700 (PDT) Received: from localhost ([::1]:55376 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oMTBE-0002Ci-7s for importer@patchew.org; Fri, 12 Aug 2022 07:50:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35458) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMT5r-0007wI-R0 for qemu-devel@nongnu.org; Fri, 12 Aug 2022 07:44:47 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.226]:38288 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oMT5o-00029Q-Kj for qemu-devel@nongnu.org; Fri, 12 Aug 2022 07:44:47 -0400 Received: from clientip-36.111.64.85 (unknown [172.18.0.48]) by chinatelecom.cn (HERMES) with SMTP id 0982B2800AB; Fri, 12 Aug 2022 19:44:36 +0800 (CST) Received: from ([172.18.0.48]) by app0024 with ESMTP id 5780c06b26034459af61b9476233f7a0 for peter.maydell@linaro.org; Fri, 12 Aug 2022 19:44:39 CST HMM_SOURCE_IP: 172.18.0.48:45914.1860825121 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +tugy@chinatelecom.cn X-Transaction-ID: 5780c06b26034459af61b9476233f7a0 X-Real-From: tugy@chinatelecom.cn X-Receive-IP: 172.18.0.48 X-MEDUSA-Status: 0 From: tugy@chinatelecom.cn To: peter.maydell@linaro.org, f4bug@amsat.org, marcandre.lureau@redhat.com, qemu_oss@crudebyte.com, richard.henderson@linaro.org, berrange@redhat.com, mst@redhat.com, kraxel@redhat.com, qemu-devel@nongnu.org, tugy@chinatelecom.cn Subject: [PATCH 1/2] osdeps: Introduce qemu_socketpair() Date: Fri, 12 Aug 2022 19:44:29 +0800 Message-Id: <211833676831b86d70af12df9912aa971d46092b.1660303075.git.tugy@chinatelecom.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=42.123.76.226; envelope-from=tugy@chinatelecom.cn; helo=chinatelecom.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1660305024630100002 Content-Type: text/plain; charset="utf-8" From: Guoyi Tu qemu_socketpair() will create a pair of connected sockets with FD_CLOEXEC set Signed-off-by: Guoyi Tu --- include/qemu/sockets.h | 3 +++ util/osdep.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/qemu/sockets.h b/include/qemu/sockets.h index 038faa157f..52cf2855df 100644 --- a/include/qemu/sockets.h +++ b/include/qemu/sockets.h @@ -14,6 +14,9 @@ int inet_aton(const char *cp, struct in_addr *ia); /* misc helpers */ bool fd_is_socket(int fd); int qemu_socket(int domain, int type, int protocol); +#ifndef WIN32 +int qemu_socketpair(int domain, int type, int protocol, int sv[2]); +#endif int qemu_accept(int s, struct sockaddr *addr, socklen_t *addrlen); int socket_set_cork(int fd, int v); int socket_set_nodelay(int fd); diff --git a/util/osdep.c b/util/osdep.c index 60fcbbaebe..4b1ab623c7 100644 --- a/util/osdep.c +++ b/util/osdep.c @@ -481,6 +481,30 @@ int qemu_socket(int domain, int type, int protocol) return ret; } =20 +#ifndef _WIN32 +/* + * Create a pair of connected sockets with FD_CLOEXEC set + */ +int qemu_socketpair(int domain, int type, int protocol, int sv[2]) +{ + int ret; + +#ifdef SOCK_CLOEXEC + ret =3D socketpair(domain, type | SOCK_CLOEXEC, protocol, sv); + if (ret !=3D -1 || errno !=3D EINVAL) { + return ret; + } +#endif + ret =3D socketpair(domain, type, protocol, sv);; + if (ret =3D=3D 0) { + qemu_set_cloexec(sv[0]); + qemu_set_cloexec(sv[1]); + } + + return ret; +} +#endif + /* * Accept a connection and set FD_CLOEXEC */ --=20 2.25.1 From nobody Thu May 2 00:05:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 166030502573698.9195480438051; Fri, 12 Aug 2022 04:50:25 -0700 (PDT) Received: from localhost ([::1]:55442 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oMTBI-0002Fv-Kp for importer@patchew.org; Fri, 12 Aug 2022 07:50:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35460) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oMT5r-0007wJ-R6 for qemu-devel@nongnu.org; Fri, 12 Aug 2022 07:44:47 -0400 Received: from prt-mail.chinatelecom.cn ([42.123.76.226]:38307 helo=chinatelecom.cn) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oMT5o-00029e-V5 for qemu-devel@nongnu.org; Fri, 12 Aug 2022 07:44:47 -0400 Received: from clientip-36.111.64.85 (unknown [172.18.0.48]) by chinatelecom.cn (HERMES) with SMTP id AAFD72800B5; Fri, 12 Aug 2022 19:44:40 +0800 (CST) Received: from ([172.18.0.48]) by app0024 with ESMTP id a814a91a80944a169063d287d92060d2 for peter.maydell@linaro.org; Fri, 12 Aug 2022 19:44:43 CST HMM_SOURCE_IP: 172.18.0.48:45914.1860825121 HMM_ATTACHE_NUM: 0000 HMM_SOURCE_TYPE: SMTP X-189-SAVE-TO-SEND: +tugy@chinatelecom.cn X-Transaction-ID: a814a91a80944a169063d287d92060d2 X-Real-From: tugy@chinatelecom.cn X-Receive-IP: 172.18.0.48 X-MEDUSA-Status: 0 From: tugy@chinatelecom.cn To: peter.maydell@linaro.org, f4bug@amsat.org, marcandre.lureau@redhat.com, qemu_oss@crudebyte.com, richard.henderson@linaro.org, berrange@redhat.com, mst@redhat.com, kraxel@redhat.com, qemu-devel@nongnu.org, tugy@chinatelecom.cn Subject: [PATCH 2/2] vhost-user: Call qemu_socketpair() instead of socketpair() Date: Fri, 12 Aug 2022 19:44:30 +0800 Message-Id: <3e370aa5326809d63f7eef573be558da987d27f5.1660303075.git.tugy@chinatelecom.cn> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=42.123.76.226; envelope-from=tugy@chinatelecom.cn; helo=chinatelecom.cn X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZM-MESSAGEID: 1660305026033100005 Content-Type: text/plain; charset="utf-8" From: Guoyi Tu set close-on-exec flag on the new opened file descriptors at default Signed-off-by: Guoyi Tu --- hw/display/vhost-user-gpu.c | 3 ++- hw/virtio/vhost-user.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c index 3340ef9e5f..19c0e20103 100644 --- a/hw/display/vhost-user-gpu.c +++ b/hw/display/vhost-user-gpu.c @@ -11,6 +11,7 @@ */ =20 #include "qemu/osdep.h" +#include "qemu/sockets.h" #include "hw/qdev-properties.h" #include "hw/virtio/virtio-gpu.h" #include "chardev/char-fe.h" @@ -375,7 +376,7 @@ vhost_user_gpu_do_set_socket(VhostUserGPU *g, Error **e= rrp) Chardev *chr; int sv[2]; =20 - if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) =3D=3D -1) { + if (qemu_socketpair(PF_UNIX, SOCK_STREAM, 0, sv) =3D=3D -1) { error_setg_errno(errp, errno, "socketpair() failed"); return false; } diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 75b8df21a4..4d2b227028 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -1726,7 +1726,7 @@ static int vhost_setup_slave_channel(struct vhost_dev= *dev) return 0; } =20 - if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) =3D=3D -1) { + if (qemu_socketpair(PF_UNIX, SOCK_STREAM, 0, sv) =3D=3D -1) { int saved_errno =3D errno; error_report("socketpair() failed"); return -saved_errno; --=20 2.25.1