From nobody Fri Mar 27 04:52:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1771446602; cv=none; d=zohomail.com; s=zohoarc; b=dtYcrBJkDXeEpTin2u3xqd9NJrrHv3BHdyZ8NTZXAzeke+37LnePFzZtngyH6n9do9+H/Vh5kuapDhPencD78YOUaFZnXTH6Z7alYjd90L9IClwyupyjeQLTT6rZ2pbtmaz2G/cfj2bDJFFrBZJn4yotdFYg0lh5HKh+JSn4rZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771446602; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=QLIq9qTK9Px46zQ/r9TYIEuLmijBWLAAX7/DLfF+Jdw=; b=faA3mjw6C9E6rf/OHjijc6FETSel/6cHAHFQFpdLtEo5XeTt+fWdvCEd0ppeDiktwVibtvQdjzoBUVuWHbZDw5/61QGKEgGlOR2ig3M0VkgCxUOuVtL3corKJfk4y2WAlJfUOGHucqGAp3TIKbszvIKB4PzYZHncJ4afmAFA/0U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1771446602973794.753796231955; Wed, 18 Feb 2026 12:30:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vsoAV-0007HH-Jm; Wed, 18 Feb 2026 15:29:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA3-00074X-Ui for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:40 -0500 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA0-0007rg-KK for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:38 -0500 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 9D28CC038A; Wed, 18 Feb 2026 23:28:33 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:53d::1:1b]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VShB144A8iE0-fCZ88J6v; Wed, 18 Feb 2026 23:28:33 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1771446513; bh=QLIq9qTK9Px46zQ/r9TYIEuLmijBWLAAX7/DLfF+Jdw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=GRkQdGs82gbuWUzk+LWaoqTP/Kx7DlRkW9AyS6Y+jjEO3E4JjxhQZNGD0PVNnOKes 7+eDEdzKQ25UOaac88AcEl0dN5wRcbAdyZ3iW/2N72dVraJUAOpkKbirTRbkcbabqF 3gR9qCy0TbQoPwJHHl0cxAVAc+X1zRWCpMlYbFvo= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, bchaney@akamai.com, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, davydov-max@yandex-team.ru, vsementsov@yandex-team.ru, Ilya Maximets Subject: [PATCH v3 01/12] net/af-xdp: fix type overflow Date: Wed, 18 Feb 2026 23:28:17 +0300 Message-ID: <20260218202829.1322088-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260218202829.1322088-1-vsementsov@yandex-team.ru> References: <20260218202829.1322088-1-vsementsov@yandex-team.ru> 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=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1771446605741154100 Content-Type: text/plain; charset="utf-8" In for-loop in net_init_af_xdp, we do nc->queue_index =3D i, where is is int64_t for 0 to queues-1, and nc->queue_index is unsigned int. Also in parse_socket_fds, g_strv_length() returns guint which is equivalent to unsigned int. Let's simply use int type for queues, and update the check appropriately. It could be unsigned int, but in future commits we'll share with net/tap.c the common function which will return number of queues or negative error. So, let's simply use int for queues-related variables, that simplifies things. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/af-xdp.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/net/af-xdp.c b/net/af-xdp.c index 14f302ea21..ff1cb30a98 100644 --- a/net/af-xdp.c +++ b/net/af-xdp.c @@ -442,14 +442,14 @@ static NetClientInfo net_af_xdp_info =3D { }; =20 static int *parse_socket_fds(const char *sock_fds_str, - int64_t n_expected, Error **errp) + int n_expected, Error **errp) { gchar **substrings =3D g_strsplit(sock_fds_str, ":", -1); - int64_t i, n_sock_fds =3D g_strv_length(substrings); + int i, n_sock_fds =3D g_strv_length(substrings); int *sock_fds =3D NULL; =20 if (n_sock_fds !=3D n_expected) { - error_setg(errp, "expected %"PRIi64" socket fds, got %"PRIi64, + error_setg(errp, "expected %d socket fds, got %d", n_expected, n_sock_fds); goto exit; } @@ -484,7 +484,7 @@ int net_init_af_xdp(const Netdev *netdev, unsigned int ifindex; uint32_t prog_id =3D 0; g_autofree int *sock_fds =3D NULL; - int64_t i, queues; + int i, queues; Error *err =3D NULL; AFXDPState *s; bool inhibit; @@ -496,13 +496,14 @@ int net_init_af_xdp(const Netdev *netdev, return -1; } =20 - queues =3D opts->has_queues ? opts->queues : 1; - if (queues < 1) { + if (opts->has_queues && (opts->queues < 1 || opts->queues > INT_MAX)) { error_setg(errp, "invalid number of queues (%" PRIi64 ") for '%s'", - queues, opts->ifname); + opts->queues, opts->ifname); return -1; } =20 + queues =3D opts->has_queues ? opts->queues : 1; + inhibit =3D opts->has_inhibit && opts->inhibit; if (inhibit && !opts->sock_fds && !opts->map_path) { error_setg(errp, "'inhibit=3Don' requires 'sock-fds' or 'map-path'= "); @@ -537,7 +538,7 @@ int net_init_af_xdp(const Netdev *netdev, =20 for (i =3D 0; i < queues; i++) { nc =3D qemu_new_net_client(&net_af_xdp_info, peer, "af-xdp", name); - qemu_set_info_str(nc, "af-xdp%"PRIi64" to %s", i, opts->ifname); + qemu_set_info_str(nc, "af-xdp%d to %s", i, opts->ifname); nc->queue_index =3D i; =20 if (!nc0) { --=20 2.52.0 From nobody Fri Mar 27 04:52:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1771446544; cv=none; d=zohomail.com; s=zohoarc; b=FVUaSzOFADW8ue0ijjk8mBsskZ75aAUDGlsB3M8DppjAXY/DYyzE3UuYmscFb3M15VIpg8JTUUy8cV8tyWgOYePYHavW+udKHNoVIs4agLneEHhLJK5bKUDDmWlJ2iNvDywTSPLTykhShrk3QHPEeq/nAF2K3JJalMV6sDv1AFc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771446544; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1Q5dYllhtrYtedtJ6lbMYb+MJcVRhmL3kiAJkKDdW/4=; b=ZGW45YVz42Tnly5HZ0+H2M2N2woryNwTUackzvit6tSJALlySYaU05runqWuFKomR+zBmvFMwaiY5OCyx3/1M30BGPhi4Y+J+XiOQ/Fntfi61iVmRxM4KgAz96qE+knledgQmy/Am3YDPSCBx88bqgRVQeAzaDEW85ZT0ICXsdU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 177144654473687.13356821075763; Wed, 18 Feb 2026 12:29:04 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vsoAF-00076o-FZ; Wed, 18 Feb 2026 15:28:51 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA3-00074U-Ve for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:40 -0500 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA0-0007ri-Jw for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:38 -0500 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 60B1FC038B; Wed, 18 Feb 2026 23:28:34 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:53d::1:1b]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VShB144A8iE0-cEPxyj21; Wed, 18 Feb 2026 23:28:33 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1771446513; bh=1Q5dYllhtrYtedtJ6lbMYb+MJcVRhmL3kiAJkKDdW/4=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=QwDWfgfHi4FfPEBi6YW0SDScWrROP76adv5GObA8yiPs2yZiGdH2KxL5bOOqjmeV6 Dp4aO2hfN+HqM7KDIY4vsZSXhJE2H1TvG7GMBdi+hpfK3lbJ4guRdaFAgWAVb/EeVX a4YOEVqk5X2odFzE/Pe2HP3tc5YYt4Kgj/1GGf5s= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, bchaney@akamai.com, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, davydov-max@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v3 02/12] net/tap: net_init_tap_one(): add return value Date: Wed, 18 Feb 2026 23:28:18 +0300 Message-ID: <20260218202829.1322088-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260218202829.1322088-1-vsementsov@yandex-team.ru> References: <20260218202829.1322088-1-vsementsov@yandex-team.ru> 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=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1771446546589154100 Content-Type: text/plain; charset="utf-8" Follow common recommendations in include/qapi/error.h of having a return value together with errp. This allows to avoid error propagation. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/tap.c | 42 +++++++++++++++++------------------------- 1 file changed, 17 insertions(+), 25 deletions(-) diff --git a/net/tap.c b/net/tap.c index 8d7ab6ba6f..a389aec218 100644 --- a/net/tap.c +++ b/net/tap.c @@ -703,7 +703,7 @@ static int net_tap_init(const NetdevTapOptions *tap, in= t *vnet_hdr, =20 #define MAX_TAP_QUEUES 1024 =20 -static void net_init_tap_one(const NetdevTapOptions *tap, NetClientState *= peer, +static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *= peer, const char *model, const char *name, const char *ifname, const char *script, const char *downscript, const char *vhostfdna= me, @@ -783,10 +783,11 @@ static void net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, } } =20 - return; + return true; =20 failed: qemu_del_net_client(&s->nc); + return false; } =20 static int get_fds(char *str, char *fds[], int max) @@ -821,7 +822,6 @@ int net_init_tap(const Netdev *netdev, const char *name, const NetdevTapOptions *tap; int fd, vnet_hdr =3D 0, i =3D 0, queues; /* for the no-fd, no-helper case */ - Error *err =3D NULL; const char *vhostfdname; char ifname[128]; int ret =3D 0; @@ -869,11 +869,9 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, return -1; } =20 - net_init_tap_one(tap, peer, "tap", name, NULL, - NULL, NULL, - vhostfdname, vnet_hdr, fd, &err); - if (err) { - error_propagate(errp, err); + if (!net_init_tap_one(tap, peer, "tap", name, NULL, + NULL, NULL, + vhostfdname, vnet_hdr, fd, errp)) { close(fd); return -1; } @@ -930,12 +928,10 @@ int net_init_tap(const Netdev *netdev, const char *na= me, goto free_fail; } =20 - net_init_tap_one(tap, peer, "tap", name, ifname, - NULL, NULL, - tap->vhostfds ? vhost_fds[i] : NULL, - vnet_hdr, fd, &err); - if (err) { - error_propagate(errp, err); + if (!net_init_tap_one(tap, peer, "tap", name, ifname, + NULL, NULL, + tap->vhostfds ? vhost_fds[i] : NULL, + vnet_hdr, fd, errp)) { ret =3D -1; goto free_fail; } @@ -975,11 +971,9 @@ free_fail: return -1; } =20 - net_init_tap_one(tap, peer, "bridge", name, ifname, - NULL, NULL, vhostfdname, - vnet_hdr, fd, &err); - if (err) { - error_propagate(errp, err); + if (!net_init_tap_one(tap, peer, "bridge", name, ifname, + NULL, NULL, vhostfdname, + vnet_hdr, fd, errp)) { close(fd); return -1; } @@ -1015,12 +1009,10 @@ free_fail: } } =20 - net_init_tap_one(tap, peer, "tap", name, ifname, - i >=3D 1 ? NULL : script, - i >=3D 1 ? NULL : downscript, - vhostfdname, vnet_hdr, fd, &err); - if (err) { - error_propagate(errp, err); + if (!net_init_tap_one(tap, peer, "tap", name, ifname, + i >=3D 1 ? NULL : script, + i >=3D 1 ? NULL : downscript, + vhostfdname, vnet_hdr, fd, errp)) { close(fd); return -1; } --=20 2.52.0 From nobody Fri Mar 27 04:52:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1771446542; cv=none; d=zohomail.com; s=zohoarc; b=SL9XxkFEQjEbpoQSAzcwBoIyk5LwoIzwcuq1/oWSuPb9O4ymRdzmgziEMEkXXDAdPB0AxxoGOLgQ/9PUBOqk3bLtmUbh2HRJ98p21Vx/MlDvXAGDCe1ba8uZHNfLLcdjVImzlYRWbylpZTPhkdQ11SoUINkFVne9rJs8R6SAqfE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771446542; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=5mIy1CyhCgoPLn4Qcg9Hf6mr1MP5XtgStzgPYFDTSFk=; b=DU6w1K2zTYEa79fEFUI/N+MWu+Y0G4nOGCLP8M/E46x57EdAUsw0aIVw6QSm36N5MjA8+LYoKqgVd5hDEqZO4GbDztT0yE44YR+5ucYdX56+mFXMJY+MbjAVO0EzX+M8IdBAkhTHSeIRpxIm1/pWrwb7NdlzYw9xauwjJ7xZw8o= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1771446541527108.14790576603878; Wed, 18 Feb 2026 12:29:01 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vsoAJ-00077A-CQ; Wed, 18 Feb 2026 15:28:56 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA3-00074V-Ui for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:40 -0500 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA1-0007rl-2m for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:39 -0500 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 19593C038C; Wed, 18 Feb 2026 23:28:35 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:53d::1:1b]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VShB144A8iE0-wOJUq9xJ; Wed, 18 Feb 2026 23:28:34 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1771446514; bh=5mIy1CyhCgoPLn4Qcg9Hf6mr1MP5XtgStzgPYFDTSFk=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=QOOPDrDWbW2jxcx8KlUdYXo0cUTuGvMsEecMxXYpx6n26niKdkc7//pjrM47kLozI LGuvXok7goCR7A4y5FDvmFB+lSwPzjuCK4WAhTLgQDAjQ9MloVMeY1305HzDE62RFY x8vOuMf3374ZNFtvnAl5fUJ7VRjczpw8BZ358e6U= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, bchaney@akamai.com, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, davydov-max@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v3 03/12] net/tap: net_init_tap(): drop extra vhostfdname variable Date: Wed, 18 Feb 2026 23:28:19 +0300 Message-ID: <20260218202829.1322088-4-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260218202829.1322088-1-vsementsov@yandex-team.ru> References: <20260218202829.1322088-1-vsementsov@yandex-team.ru> 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=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1771446545291154100 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/tap.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/net/tap.c b/net/tap.c index a389aec218..55b8b33ea8 100644 --- a/net/tap.c +++ b/net/tap.c @@ -822,14 +822,12 @@ int net_init_tap(const Netdev *netdev, const char *na= me, const NetdevTapOptions *tap; int fd, vnet_hdr =3D 0, i =3D 0, queues; /* for the no-fd, no-helper case */ - const char *vhostfdname; char ifname[128]; int ret =3D 0; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); tap =3D &netdev->u.tap; queues =3D tap->has_queues ? tap->queues : 1; - vhostfdname =3D tap->vhostfd; =20 /* QEMU hubs do not support multiqueue tap, in this case peer is set. * For -netdev, peer is always NULL. */ @@ -871,7 +869,7 @@ int net_init_tap(const Netdev *netdev, const char *name, =20 if (!net_init_tap_one(tap, peer, "tap", name, NULL, NULL, NULL, - vhostfdname, vnet_hdr, fd, errp)) { + tap->vhostfd, vnet_hdr, fd, errp)) { close(fd); return -1; } @@ -972,7 +970,7 @@ free_fail: } =20 if (!net_init_tap_one(tap, peer, "bridge", name, ifname, - NULL, NULL, vhostfdname, + NULL, NULL, tap->vhostfd, vnet_hdr, fd, errp)) { close(fd); return -1; @@ -1012,7 +1010,7 @@ free_fail: if (!net_init_tap_one(tap, peer, "tap", name, ifname, i >=3D 1 ? NULL : script, i >=3D 1 ? NULL : downscript, - vhostfdname, vnet_hdr, fd, errp)) { + tap->vhostfd, vnet_hdr, fd, errp)) { close(fd); return -1; } --=20 2.52.0 From nobody Fri Mar 27 04:52:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1771446537; cv=none; d=zohomail.com; s=zohoarc; b=lS71h2Fvb/xzUUvrnPbzliVLA1ErJzxV73xb1S8RKjU1xq1ej+/DvHV9I1JxFkVnsftuwBx8AgouiHE/Bt5hruPFUyH9GhqBNxIWW7/VN7YWCiRbA7dqdLi/w73D07Dn2/gC39fZ58IByS5axuAebYAYyaa5v+XSx39r+dfnLsE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771446537; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=i5eFvQ0MxbzUcT/0vb8vt3GzyP2XMPog1nxdutvP964=; b=KbyuxWSl7eCbjNxsQZEFyDSKTX0FQNvgWHQgF9j3L4bCKJRFljHSFD3CrFt2EB3Mi61Q/0Wc9f2GvYC6jjVc+zztYEN3OWOn9JFrweY2NrLHkhd71wB8lQbPVs60YKhdOKtDx/La0G2s8c9z6a9HBoCLISozg230+qtHt1xF66A= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1771446535463996.0281988403341; Wed, 18 Feb 2026 12:28:55 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vsoA9-00075b-V1; Wed, 18 Feb 2026 15:28:45 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA4-00074Y-1F for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:40 -0500 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA2-0007ru-5O for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:39 -0500 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id DE0DDC038D; Wed, 18 Feb 2026 23:28:35 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:53d::1:1b]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VShB144A8iE0-dQpdG0mh; Wed, 18 Feb 2026 23:28:35 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1771446515; bh=i5eFvQ0MxbzUcT/0vb8vt3GzyP2XMPog1nxdutvP964=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=pMT0aW3m4MiDt16RdeD9uy72johFrFdw48vcOd6WzpxJiLTcbc9b2on8CcCBkqasN 1ChO3SMcrqM9eCB9Ml0lbO+WQDMsOsJsVAz4MGhRql+WLVb12b61XolmP5Ntx1xXVt Muwsmy3wjOUuludWzd23jQ6M17JFXJOGVf87cH+c= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, bchaney@akamai.com, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, davydov-max@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v3 04/12] net/tap: net_init_tap(): refactor parameter checking Date: Wed, 18 Feb 2026 23:28:20 +0300 Message-ID: <20260218202829.1322088-5-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260218202829.1322088-1-vsementsov@yandex-team.ru> References: <20260218202829.1322088-1-vsementsov@yandex-team.ru> 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=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1771446542241154100 Content-Type: text/plain; charset="utf-8" Move checks to the top of the function to simplify further refactoring. Merge duplicated checks. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/tap.c | 53 +++++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 30 deletions(-) diff --git a/net/tap.c b/net/tap.c index 55b8b33ea8..331a779585 100644 --- a/net/tap.c +++ b/net/tap.c @@ -841,16 +841,30 @@ int net_init_tap(const Netdev *netdev, const char *na= me, return -1; } =20 - if (tap->fd) { - if (tap->ifname || tap->script || tap->downscript || - tap->has_vnet_hdr || tap->helper || tap->has_queues || - tap->fds || tap->vhostfds) { - error_setg(errp, "ifname=3D, script=3D, downscript=3D, vnet_hd= r=3D, " - "helper=3D, queues=3D, fds=3D, and vhostfds=3D " - "are invalid with fd=3D"); - return -1; - } + if (tap->has_queues + !!tap->helper + !!tap->fds + !!tap->fd > 1) { + error_setg(errp, "queues=3D, helper=3D, fds=3D and fd=3D are mutua= l exclusive"); + return -1; + } =20 + if ((tap->fd || tap->fds || tap->helper) && + (tap->ifname || tap->script || tap->downscript || + tap->has_vnet_hdr)) { + error_setg(errp, "ifname=3D, script=3D, downscript=3D, vnet_hdr=3D= " + "are invalid with fd=3D/fds=3D/helper=3D"); + return -1; + } + + if (tap->vhostfds && !tap->fds) { + error_setg(errp, "vhostfds=3D is invalid if fds=3D wasn't specifie= d"); + return -1; + } + + if (tap->vhostfd && tap->fds) { + error_setg(errp, "vhostfd=3D is invalid with fds=3D"); + return -1; + } + + if (tap->fd) { fd =3D monitor_fd_param(monitor_cur(), tap->fd, errp); if (fd =3D=3D -1) { return -1; @@ -878,15 +892,6 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, char **vhost_fds; int nfds =3D 0, nvhosts =3D 0; =20 - if (tap->ifname || tap->script || tap->downscript || - tap->has_vnet_hdr || tap->helper || tap->has_queues || - tap->vhostfd) { - error_setg(errp, "ifname=3D, script=3D, downscript=3D, vnet_hd= r=3D, " - "helper=3D, queues=3D, and vhostfd=3D " - "are invalid with fds=3D"); - return -1; - } - fds =3D g_new0(char *, MAX_TAP_QUEUES); vhost_fds =3D g_new0(char *, MAX_TAP_QUEUES); =20 @@ -946,13 +951,6 @@ free_fail: g_free(vhost_fds); return ret; } else if (tap->helper) { - if (tap->ifname || tap->script || tap->downscript || - tap->has_vnet_hdr || tap->has_queues || tap->vhostfds) { - error_setg(errp, "ifname=3D, script=3D, downscript=3D, vnet_hd= r=3D, " - "queues=3D, and vhostfds=3D are invalid with helper= =3D"); - return -1; - } - fd =3D net_bridge_run_helper(tap->helper, tap->br ?: DEFAULT_BRIDGE_INTERFACE, errp); @@ -981,11 +979,6 @@ free_fail: g_autofree char *downscript =3D tap_parse_script(tap->downscript, DEFAULT_NETWORK_DOWN_SCRIPT); =20 - if (tap->vhostfds) { - error_setg(errp, "vhostfds=3D is invalid if fds=3D wasn't spec= ified"); - return -1; - } - if (tap->ifname) { pstrcpy(ifname, sizeof ifname, tap->ifname); } else { --=20 2.52.0 From nobody Fri Mar 27 04:52:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1771446588; cv=none; d=zohomail.com; s=zohoarc; b=YIc29T985GougHV1B6vPVBIgizOCLIBVuYWH84lel/wn0gZoy6Zwo3L7QKbJQGjNKKQBC+G5Yy3AmYh9QvzAG1iyCdbIbIL781O/XElktU9Xdok7eA5Qw3w7w2FsL1UoCH1hGKLq4WaopKT1bIQPtepx6kND3Uzk61cJFoBKVhM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771446588; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zkwUUASolEhVxvg1YgpDo8GiYqPwUnrSrAAlmje9B6M=; b=ZBuf8pKGRzoKSMSwY1832v/5PAt3RRBShCjoqNVJ2gqT6EzNGBdD9l+NA7xi5JsI2pTkHyGvOfXxVqW6jzfq2u313s/6sVQ0/UMPqH8ubEvaPdGoNI3LnXpTASW4/VEOH5VJiDIn7cXjEGZP7+EkJm2vt2ZZtk0Mlw6OECdvUWE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1771446588829387.07040280242325; Wed, 18 Feb 2026 12:29:48 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vsoAU-0007E2-0J; Wed, 18 Feb 2026 15:29:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA4-00074Z-3B for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:40 -0500 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA1-0007s2-Ub for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:39 -0500 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id AFAD3C038E; Wed, 18 Feb 2026 23:28:36 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:53d::1:1b]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VShB144A8iE0-sDDid53j; Wed, 18 Feb 2026 23:28:36 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1771446516; bh=zkwUUASolEhVxvg1YgpDo8GiYqPwUnrSrAAlmje9B6M=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=dhPzQxh1YHd2OTyXJMr0kVnQgP9EDal5IpmpkymFU+7SwSiZVomwDmMU0SRi9EiVy PHYwmJFWbarXK3o0rY9nfFZzj/GcT2pcn5QfbGdyHYelSYxFl7mjALn6jiyMWrLnJ2 YeBqhReJO3+CG0f9Mt9bCEYWIeZWTNEpgY+tgM3w= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, bchaney@akamai.com, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, davydov-max@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v3 05/12] net/tap: net_init_tap(): common fail label Date: Wed, 18 Feb 2026 23:28:21 +0300 Message-ID: <20260218202829.1322088-6-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260218202829.1322088-1-vsementsov@yandex-team.ru> References: <20260218202829.1322088-1-vsementsov@yandex-team.ru> 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=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1771446591513154100 Content-Type: text/plain; charset="utf-8" Add common failure label. This: - simplifies failure paths in the function - get rid of unusual free_fail: in the middle of the function - simplify further refactoring Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/tap.c | 84 ++++++++++++++++++++++++------------------------------- 1 file changed, 37 insertions(+), 47 deletions(-) diff --git a/net/tap.c b/net/tap.c index 331a779585..2eb8a2caeb 100644 --- a/net/tap.c +++ b/net/tap.c @@ -820,10 +820,12 @@ int net_init_tap(const Netdev *netdev, const char *na= me, NetClientState *peer, Error **errp) { const NetdevTapOptions *tap; - int fd, vnet_hdr =3D 0, i =3D 0, queues; + int fd =3D -1, vnet_hdr =3D 0, i =3D 0, queues; /* for the no-fd, no-helper case */ char ifname[128]; - int ret =3D 0; + char **fds =3D NULL, **vhost_fds =3D NULL; + int nfds =3D 0, nvhosts =3D 0; + =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); tap =3D &netdev->u.tap; @@ -867,31 +869,24 @@ int net_init_tap(const Netdev *netdev, const char *na= me, if (tap->fd) { fd =3D monitor_fd_param(monitor_cur(), tap->fd, errp); if (fd =3D=3D -1) { - return -1; + goto fail; } =20 if (!qemu_set_blocking(fd, false, errp)) { - close(fd); - return -1; + goto fail; } =20 vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); if (vnet_hdr < 0) { - close(fd); - return -1; + goto fail; } =20 if (!net_init_tap_one(tap, peer, "tap", name, NULL, NULL, NULL, tap->vhostfd, vnet_hdr, fd, errp)) { - close(fd); - return -1; + goto fail; } } else if (tap->fds) { - char **fds; - char **vhost_fds; - int nfds =3D 0, nvhosts =3D 0; - fds =3D g_new0(char *, MAX_TAP_QUEUES); vhost_fds =3D g_new0(char *, MAX_TAP_QUEUES); =20 @@ -901,77 +896,58 @@ int net_init_tap(const Netdev *netdev, const char *na= me, if (nfds !=3D nvhosts) { error_setg(errp, "The number of fds passed does not match " "the number of vhostfds passed"); - ret =3D -1; - goto free_fail; + goto fail; } } =20 for (i =3D 0; i < nfds; i++) { fd =3D monitor_fd_param(monitor_cur(), fds[i], errp); if (fd =3D=3D -1) { - ret =3D -1; - goto free_fail; + goto fail; } =20 if (!qemu_set_blocking(fd, false, errp)) { - ret =3D -1; - goto free_fail; + goto fail; } =20 if (i =3D=3D 0) { vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); if (vnet_hdr < 0) { - ret =3D -1; - goto free_fail; + goto fail; } } else if (vnet_hdr !=3D tap_probe_vnet_hdr(fd, NULL)) { error_setg(errp, "vnet_hdr not consistent across given tap fds"); - ret =3D -1; - goto free_fail; + goto fail; } =20 if (!net_init_tap_one(tap, peer, "tap", name, ifname, NULL, NULL, tap->vhostfds ? vhost_fds[i] : NULL, vnet_hdr, fd, errp)) { - ret =3D -1; - goto free_fail; + goto fail; } } - -free_fail: - for (i =3D 0; i < nvhosts; i++) { - g_free(vhost_fds[i]); - } - for (i =3D 0; i < nfds; i++) { - g_free(fds[i]); - } - g_free(fds); - g_free(vhost_fds); - return ret; } else if (tap->helper) { fd =3D net_bridge_run_helper(tap->helper, tap->br ?: DEFAULT_BRIDGE_INTERFACE, errp); if (fd =3D=3D -1) { - return -1; + goto fail; } =20 if (!qemu_set_blocking(fd, false, errp)) { - return -1; + goto fail; } vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); if (vnet_hdr < 0) { - close(fd); - return -1; + goto fail; } =20 if (!net_init_tap_one(tap, peer, "bridge", name, ifname, NULL, NULL, tap->vhostfd, vnet_hdr, fd, errp)) { - close(fd); - return -1; + goto fail; } } else { g_autofree char *script =3D @@ -989,14 +965,13 @@ free_fail: fd =3D net_tap_init(tap, &vnet_hdr, i >=3D 1 ? NULL : script, ifname, sizeof ifname, queues > 1, errp); if (fd =3D=3D -1) { - return -1; + goto fail; } =20 if (queues > 1 && i =3D=3D 0 && !tap->ifname) { if (tap_fd_get_ifname(fd, ifname)) { error_setg(errp, "Fail to get ifname"); - close(fd); - return -1; + goto fail; } } =20 @@ -1004,13 +979,28 @@ free_fail: i >=3D 1 ? NULL : script, i >=3D 1 ? NULL : downscript, tap->vhostfd, vnet_hdr, fd, errp)) { - close(fd); - return -1; + goto fail; } } } =20 return 0; + +fail: + close(fd); + if (vhost_fds) { + for (i =3D 0; i < nvhosts; i++) { + g_free(vhost_fds[i]); + } + g_free(vhost_fds); + } + if (fds) { + for (i =3D 0; i < nfds; i++) { + g_free(fds[i]); + } + g_free(fds); + } + return -1; } =20 int tap_enable(NetClientState *nc) --=20 2.52.0 From nobody Fri Mar 27 04:52:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1771446584; cv=none; d=zohomail.com; s=zohoarc; b=nskkegTfTCTgbYFTsMoHIgmeL4TrtW5oij97iwPbtWMRACgqaBuoc9TYB0BIEVDgUTawDuo3H9ZtyeeIgxfvQy3EDBV2i0n06E0BDYkuWYRlti72pkI03VZtLSkGYPIozrAMqyFKwfi4C+I+IeRsWiFnckiSuZ3KQVO32wn4VDM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771446584; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1LHoJ5DJvDzwJvSX0/dnBSGc1kLmBrli5OwBikWNfk8=; b=WpCVht++yaUvGp9B2mh2zbrgiwttlexn/YaBKyeDO0jVoTiISFSkWEUwCMe83YjKPaAsgfeYGZ7KJP5hKoARX0LufGE74rzeKN9uwWqzeTt5rzNtjflhMSQekoj30QoyZabk4kNmrp2tVCg7BE1+FY5efpugN8rT2yXgHCFVB4Q= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1771446584153487.57453716022405; Wed, 18 Feb 2026 12:29:44 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vsoAU-0007GS-N7; Wed, 18 Feb 2026 15:29:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA5-00075B-Ch for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:42 -0500 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA3-0007s9-MZ for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:41 -0500 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 7D5ACC038F; Wed, 18 Feb 2026 23:28:37 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:53d::1:1b]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VShB144A8iE0-yHpr2ejx; Wed, 18 Feb 2026 23:28:37 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1771446517; bh=1LHoJ5DJvDzwJvSX0/dnBSGc1kLmBrli5OwBikWNfk8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=0Rx+iNiDtE6zyzQv0zegr0aBak4NmcTLbXA1qHkntheGhI8WtLXvRBNeWuVQnZPbi sVQcktJmCZUdpA35FZzfXKGyOuRi/hDwf8i419mkPuKEYa3Uq/dRAsRX/hKq9kB+bE jcll/DDLFvWUCT1QshLnSyRtjbSCsyxF3eQX3wu8= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, bchaney@akamai.com, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, davydov-max@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v3 06/12] net/tap: net_init_tap_one() refactor to get vhostfd param Date: Wed, 18 Feb 2026 23:28:22 +0300 Message-ID: <20260218202829.1322088-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260218202829.1322088-1-vsementsov@yandex-team.ru> References: <20260218202829.1322088-1-vsementsov@yandex-team.ru> 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=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1771446586642158500 Content-Type: text/plain; charset="utf-8" Get vhostfd instead of vhostfdname: - more symmetry with fd param - prepare to further changes Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/tap.c | 48 +++++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 17 deletions(-) diff --git a/net/tap.c b/net/tap.c index 2eb8a2caeb..2c5f8e73fe 100644 --- a/net/tap.c +++ b/net/tap.c @@ -706,11 +706,10 @@ static int net_tap_init(const NetdevTapOptions *tap, = int *vnet_hdr, static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *= peer, const char *model, const char *name, const char *ifname, const char *script, - const char *downscript, const char *vhostfdna= me, + const char *downscript, int vhostfd, int vnet_hdr, int fd, Error **errp) { TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); - int vhostfd; bool sndbuf_required =3D tap->has_sndbuf; int sndbuf =3D (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; @@ -738,7 +737,7 @@ static bool net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, } =20 if (tap->has_vhost ? tap->vhost : - vhostfdname || (tap->has_vhostforce && tap->vhostforce)) { + (vhostfd !=3D -1) || (tap->has_vhostforce && tap->vhostforce)) { VhostNetOptions options; =20 options.backend_type =3D VHOST_BACKEND_TYPE_KERNEL; @@ -749,15 +748,7 @@ static bool net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, options.busyloop_timeout =3D 0; } =20 - if (vhostfdname) { - vhostfd =3D monitor_fd_param(monitor_cur(), vhostfdname, errp); - if (vhostfd =3D=3D -1) { - goto failed; - } - if (!qemu_set_blocking(vhostfd, false, errp)) { - goto failed; - } - } else { + if (vhostfd =3D=3D -1) { vhostfd =3D open("/dev/vhost-net", O_RDWR); if (vhostfd < 0) { error_setg_file_open(errp, errno, "/dev/vhost-net"); @@ -820,7 +811,7 @@ int net_init_tap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { const NetdevTapOptions *tap; - int fd =3D -1, vnet_hdr =3D 0, i =3D 0, queues; + int fd =3D -1, vhostfd =3D -1, vnet_hdr =3D 0, i =3D 0, queues; /* for the no-fd, no-helper case */ char ifname[128]; char **fds =3D NULL, **vhost_fds =3D NULL; @@ -866,6 +857,17 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, return -1; } =20 + if (tap->vhostfd) { + vhostfd =3D monitor_fd_param(monitor_cur(), tap->vhostfd, errp); + if (vhostfd =3D=3D -1) { + return -1; + } + + if (!qemu_set_blocking(vhostfd, false, errp)) { + goto fail; + } + } + if (tap->fd) { fd =3D monitor_fd_param(monitor_cur(), tap->fd, errp); if (fd =3D=3D -1) { @@ -883,7 +885,7 @@ int net_init_tap(const Netdev *netdev, const char *name, =20 if (!net_init_tap_one(tap, peer, "tap", name, NULL, NULL, NULL, - tap->vhostfd, vnet_hdr, fd, errp)) { + vhostfd, vnet_hdr, fd, errp)) { goto fail; } } else if (tap->fds) { @@ -910,6 +912,17 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, goto fail; } =20 + if (tap->vhostfds) { + vhostfd =3D monitor_fd_param(monitor_cur(), vhost_fds[i], = errp); + if (vhostfd =3D=3D -1) { + goto fail; + } + + if (!qemu_set_blocking(vhostfd, false, errp)) { + goto fail; + } + } + if (i =3D=3D 0) { vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); if (vnet_hdr < 0) { @@ -923,7 +936,7 @@ int net_init_tap(const Netdev *netdev, const char *name, =20 if (!net_init_tap_one(tap, peer, "tap", name, ifname, NULL, NULL, - tap->vhostfds ? vhost_fds[i] : NULL, + vhostfd, vnet_hdr, fd, errp)) { goto fail; } @@ -945,7 +958,7 @@ int net_init_tap(const Netdev *netdev, const char *name, } =20 if (!net_init_tap_one(tap, peer, "bridge", name, ifname, - NULL, NULL, tap->vhostfd, + NULL, NULL, vhostfd, vnet_hdr, fd, errp)) { goto fail; } @@ -978,7 +991,7 @@ int net_init_tap(const Netdev *netdev, const char *name, if (!net_init_tap_one(tap, peer, "tap", name, ifname, i >=3D 1 ? NULL : script, i >=3D 1 ? NULL : downscript, - tap->vhostfd, vnet_hdr, fd, errp)) { + vhostfd, vnet_hdr, fd, errp)) { goto fail; } } @@ -988,6 +1001,7 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, =20 fail: close(fd); + close(vhostfd); if (vhost_fds) { for (i =3D 0; i < nvhosts; i++) { g_free(vhost_fds[i]); --=20 2.52.0 From nobody Fri Mar 27 04:52:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1771446584; cv=none; d=zohomail.com; s=zohoarc; b=VccmeqJdY+SX1dqHH+2h5M/Cmmhs8GSEDkv+y0138DjNNgYPe3BO5U22OcCr3zLgKH1LAA/a/ccaves4mvaRUwbxhSuvKCPf1IYkPay34XuDARy+giJf4WMoWhkfiTcYGI5CSc+AJlzgUfoVCj6rbZQhai4ouj6tNG1dJSeZR10= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771446584; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=BDiEM5hFQxkhlp+sUNQkEBGuisXIqaX1d5OB08sKy8A=; b=gXoDVRQCLHbB23CKGCGbHD0UjEqQvHw5c4bZHJP2Yq69QONo2KFft1iX3BJy976PIw3cxkBn4OT8419qJsP5B1ymV8QKhRCDkabFa144iSgB+PFN1ljpnBt1eY2YVowcSGfy93XV2wOaL+G0lb8oVTUx8MH0mdXPn04Cwul3C7k= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1771446583090187.79395893358685; Wed, 18 Feb 2026 12:29:43 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vsoAL-00077C-4V; Wed, 18 Feb 2026 15:29:00 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA5-00075A-5v for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:42 -0500 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA3-0007sK-Mt for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:40 -0500 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 3A22EC0390; Wed, 18 Feb 2026 23:28:38 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:53d::1:1b]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VShB144A8iE0-BTqabyzq; Wed, 18 Feb 2026 23:28:37 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1771446517; bh=BDiEM5hFQxkhlp+sUNQkEBGuisXIqaX1d5OB08sKy8A=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=OeGzIX65okFHOG82icbCPBwoLhXTPft/ODqmFKVSiQP/vMdc6qigxu4CW1xyJV6vR b+na6eRXldrDyQlF4mHvI0P9OHJlrGSRXy1Bn3we6qlB4OGPooIgbFxsYlJji5wYhu /xcs5RLpQJjmHCwTdaIjnOuhsekgMe+jMgUQJ9pE= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, bchaney@akamai.com, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, davydov-max@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v3 07/12] net/tap: net_init_tap_one(): drop model parameter Date: Wed, 18 Feb 2026 23:28:23 +0300 Message-ID: <20260218202829.1322088-8-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260218202829.1322088-1-vsementsov@yandex-team.ru> References: <20260218202829.1322088-1-vsementsov@yandex-team.ru> 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=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1771446586951158500 Content-Type: text/plain; charset="utf-8" It could be simply derived from tap parameter. And this change simplifies further refactoring. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/tap.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/net/tap.c b/net/tap.c index 2c5f8e73fe..db3fe380a4 100644 --- a/net/tap.c +++ b/net/tap.c @@ -704,12 +704,13 @@ static int net_tap_init(const NetdevTapOptions *tap, = int *vnet_hdr, #define MAX_TAP_QUEUES 1024 =20 static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *= peer, - const char *model, const char *name, + const char *name, const char *ifname, const char *script, const char *downscript, int vhostfd, int vnet_hdr, int fd, Error **errp) { - TAPState *s =3D net_tap_fd_init(peer, model, name, fd, vnet_hdr); + TAPState *s =3D net_tap_fd_init(peer, tap->helper ? "bridge" : "tap", + name, fd, vnet_hdr); bool sndbuf_required =3D tap->has_sndbuf; int sndbuf =3D (tap->has_sndbuf && tap->sndbuf) ? MIN(tap->sndbuf, INT_MAX) : INT= _MAX; @@ -883,7 +884,7 @@ int net_init_tap(const Netdev *netdev, const char *name, goto fail; } =20 - if (!net_init_tap_one(tap, peer, "tap", name, NULL, + if (!net_init_tap_one(tap, peer, name, NULL, NULL, NULL, vhostfd, vnet_hdr, fd, errp)) { goto fail; @@ -934,7 +935,7 @@ int net_init_tap(const Netdev *netdev, const char *name, goto fail; } =20 - if (!net_init_tap_one(tap, peer, "tap", name, ifname, + if (!net_init_tap_one(tap, peer, name, ifname, NULL, NULL, vhostfd, vnet_hdr, fd, errp)) { @@ -957,7 +958,7 @@ int net_init_tap(const Netdev *netdev, const char *name, goto fail; } =20 - if (!net_init_tap_one(tap, peer, "bridge", name, ifname, + if (!net_init_tap_one(tap, peer, name, ifname, NULL, NULL, vhostfd, vnet_hdr, fd, errp)) { goto fail; @@ -988,7 +989,7 @@ int net_init_tap(const Netdev *netdev, const char *name, } } =20 - if (!net_init_tap_one(tap, peer, "tap", name, ifname, + if (!net_init_tap_one(tap, peer, name, ifname, i >=3D 1 ? NULL : script, i >=3D 1 ? NULL : downscript, vhostfd, vnet_hdr, fd, errp)) { --=20 2.52.0 From nobody Fri Mar 27 04:52:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1771446609; cv=none; d=zohomail.com; s=zohoarc; b=OR6HaApi+PGpxFTKZU0lydarrbcA6aZXrhxd/uoiPEqrM7pNSYuXbzvcRdlUsKd7+b9s6wu3ifx3GPkULfM4waCPo4g6q1QNeI8PPDfqj/EucfLd7epNci+g4xfae6GwbIhPGGCdOsMg4A4gQjN1AEiU4Blvxi0JBW/3DYm3b8s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771446609; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=dhvf7c3k/uO9jHIwPOa/zbw14qpoj7QwL07+jRiyYfw=; b=hnlUzleMGqn2Ue5PfzIuQTkqFlHmOVx+8l3v6GkvModcQXbK9vLunqDe1/0j0gv5Zr1ZQGnQ8NH/G2JFnDGJFkuN8YW44QMEcNSyoHaJvbZCQJ+HdKDbZo5dp76CKYfoM+FhP5XV5lwEQev15tPVkH5KeNpawRhR9kT3MBNxb5E= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1771446609849449.94928212706657; Wed, 18 Feb 2026 12:30:09 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vsoAT-0007Ce-Lc; Wed, 18 Feb 2026 15:29:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA6-00075a-GX for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:42 -0500 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA4-0007sW-Dm for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:42 -0500 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 34C00C0392; Wed, 18 Feb 2026 23:28:39 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:53d::1:1b]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VShB144A8iE0-DH4i0Afb; Wed, 18 Feb 2026 23:28:38 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1771446518; bh=dhvf7c3k/uO9jHIwPOa/zbw14qpoj7QwL07+jRiyYfw=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=A/S2jqPrfAI1xZjnTaiQEAdpO/I/JdmXKWZ5ewbnbHJQEgu5bclzoghkNyJiPuELQ tzWM+DNhmhCTBnKcDiEYtbw72mQVSxkVD4PQrOk8sCG9eNV5/rUwROtX79UCURxfQg vlxIGkWW0BzIl/HTgn951+xKECtxPvxIcU8XRIuE= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, bchaney@akamai.com, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, davydov-max@yandex-team.ru, vsementsov@yandex-team.ru, Ilya Maximets Subject: [PATCH v3 08/12] net: introduce net_parse_fds() Date: Wed, 18 Feb 2026 23:28:24 +0300 Message-ID: <20260218202829.1322088-9-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260218202829.1322088-1-vsementsov@yandex-team.ru> References: <20260218202829.1322088-1-vsementsov@yandex-team.ru> 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=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1771446611702154100 Content-Type: text/plain; charset="utf-8" Add common net_parse_fds() and net_free_fds() helpers and use them in tap.c and af-xdp.c. Choose returning queues instead of fds, because we'll have derived helper in net/tap, which will be able to return fds=3DNULL and non-zero queues on success. That's also why we move to INT_MAX for queues, to support negative return value for net_parse_fds() (for failure paths). Note that redundant restriction of MAX_TAP_QUEUES is dropped for tap.c Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/af-xdp.c | 33 ++----------------- net/tap.c | 92 +++++++++++----------------------------------------- net/util.c | 50 ++++++++++++++++++++++++++++ net/util.h | 14 ++++++++ 4 files changed, 85 insertions(+), 104 deletions(-) diff --git a/net/af-xdp.c b/net/af-xdp.c index ff1cb30a98..1ffd6363a8 100644 --- a/net/af-xdp.c +++ b/net/af-xdp.c @@ -21,6 +21,7 @@ #include "clients.h" #include "monitor/monitor.h" #include "net/net.h" +#include "net/util.h" #include "qapi/error.h" #include "qemu/cutils.h" #include "qemu/error-report.h" @@ -441,35 +442,6 @@ static NetClientInfo net_af_xdp_info =3D { .cleanup =3D af_xdp_cleanup, }; =20 -static int *parse_socket_fds(const char *sock_fds_str, - int n_expected, Error **errp) -{ - gchar **substrings =3D g_strsplit(sock_fds_str, ":", -1); - int i, n_sock_fds =3D g_strv_length(substrings); - int *sock_fds =3D NULL; - - if (n_sock_fds !=3D n_expected) { - error_setg(errp, "expected %d socket fds, got %d", - n_expected, n_sock_fds); - goto exit; - } - - sock_fds =3D g_new(int, n_sock_fds); - - for (i =3D 0; i < n_sock_fds; i++) { - sock_fds[i] =3D monitor_fd_param(monitor_cur(), substrings[i], err= p); - if (sock_fds[i] < 0) { - g_free(sock_fds); - sock_fds =3D NULL; - goto exit; - } - } - -exit: - g_strfreev(substrings); - return sock_fds; -} - /* * The exported init function. * @@ -530,8 +502,7 @@ int net_init_af_xdp(const Netdev *netdev, } =20 if (opts->sock_fds) { - sock_fds =3D parse_socket_fds(opts->sock_fds, queues, errp); - if (!sock_fds) { + if (net_parse_fds(opts->sock_fds, &sock_fds, queues, errp) < 0) { return -1; } } diff --git a/net/tap.c b/net/tap.c index db3fe380a4..2d4630c350 100644 --- a/net/tap.c +++ b/net/tap.c @@ -45,6 +45,7 @@ #include "hw/virtio/vhost.h" =20 #include "net/tap.h" +#include "net/util.h" =20 #include "net/vhost_net.h" =20 @@ -701,8 +702,6 @@ static int net_tap_init(const NetdevTapOptions *tap, in= t *vnet_hdr, return fd; } =20 -#define MAX_TAP_QUEUES 1024 - static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *= peer, const char *name, const char *ifname, const char *script, @@ -782,32 +781,6 @@ failed: return false; } =20 -static int get_fds(char *str, char *fds[], int max) -{ - char *ptr =3D str, *this; - size_t len =3D strlen(str); - int i =3D 0; - - while (i < max && ptr < str + len) { - this =3D strchr(ptr, ':'); - - if (this =3D=3D NULL) { - fds[i] =3D g_strdup(ptr); - } else { - fds[i] =3D g_strndup(ptr, this - ptr); - } - - i++; - if (this =3D=3D NULL) { - break; - } else { - ptr =3D this + 1; - } - } - - return i; -} - int net_init_tap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { @@ -815,9 +788,7 @@ int net_init_tap(const Netdev *netdev, const char *name, int fd =3D -1, vhostfd =3D -1, vnet_hdr =3D 0, i =3D 0, queues; /* for the no-fd, no-helper case */ char ifname[128]; - char **fds =3D NULL, **vhost_fds =3D NULL; - int nfds =3D 0, nvhosts =3D 0; - + int *fds =3D NULL, *vhost_fds =3D NULL; =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); tap =3D &netdev->u.tap; @@ -890,46 +861,31 @@ int net_init_tap(const Netdev *netdev, const char *na= me, goto fail; } } else if (tap->fds) { - fds =3D g_new0(char *, MAX_TAP_QUEUES); - vhost_fds =3D g_new0(char *, MAX_TAP_QUEUES); - - nfds =3D get_fds(tap->fds, fds, MAX_TAP_QUEUES); - if (tap->vhostfds) { - nvhosts =3D get_fds(tap->vhostfds, vhost_fds, MAX_TAP_QUEUES); - if (nfds !=3D nvhosts) { - error_setg(errp, "The number of fds passed does not match " - "the number of vhostfds passed"); - goto fail; - } + queues =3D net_parse_fds(tap->fds, &fds, 0, errp); + if (queues < 0) { + goto fail; } =20 - for (i =3D 0; i < nfds; i++) { - fd =3D monitor_fd_param(monitor_cur(), fds[i], errp); - if (fd =3D=3D -1) { - goto fail; - } + if (tap->vhostfds && net_parse_fds(tap->vhostfds, &vhost_fds, + queues, errp) < 0) { + goto fail; + } =20 - if (!qemu_set_blocking(fd, false, errp)) { + for (i =3D 0; i < queues; i++) { + if (!qemu_set_blocking(fds[i], false, errp)) { goto fail; } =20 - if (tap->vhostfds) { - vhostfd =3D monitor_fd_param(monitor_cur(), vhost_fds[i], = errp); - if (vhostfd =3D=3D -1) { - goto fail; - } - - if (!qemu_set_blocking(vhostfd, false, errp)) { - goto fail; - } + if (vhost_fds && !qemu_set_blocking(vhost_fds[i], false, errp)= ) { + goto fail; } =20 if (i =3D=3D 0) { - vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); + vnet_hdr =3D tap_probe_vnet_hdr(fds[i], errp); if (vnet_hdr < 0) { goto fail; } - } else if (vnet_hdr !=3D tap_probe_vnet_hdr(fd, NULL)) { + } else if (vnet_hdr !=3D tap_probe_vnet_hdr(fds[i], NULL)) { error_setg(errp, "vnet_hdr not consistent across given tap fds"); goto fail; @@ -937,8 +893,8 @@ int net_init_tap(const Netdev *netdev, const char *name, =20 if (!net_init_tap_one(tap, peer, name, ifname, NULL, NULL, - vhostfd, - vnet_hdr, fd, errp)) { + vhost_fds ? vhost_fds[i] : -1, + vnet_hdr, fds[i], errp)) { goto fail; } } @@ -1003,18 +959,8 @@ int net_init_tap(const Netdev *netdev, const char *na= me, fail: close(fd); close(vhostfd); - if (vhost_fds) { - for (i =3D 0; i < nvhosts; i++) { - g_free(vhost_fds[i]); - } - g_free(vhost_fds); - } - if (fds) { - for (i =3D 0; i < nfds; i++) { - g_free(fds[i]); - } - g_free(fds); - } + net_free_fds(fds, queues); + net_free_fds(vhost_fds, queues); return -1; } =20 diff --git a/net/util.c b/net/util.c index 0b3dbfe5d3..1998a6554e 100644 --- a/net/util.c +++ b/net/util.c @@ -23,6 +23,8 @@ */ =20 #include "qemu/osdep.h" +#include "monitor/monitor.h" +#include "qapi/error.h" #include "util.h" =20 int net_parse_macaddr(uint8_t *macaddr, const char *p) @@ -57,3 +59,51 @@ int net_parse_macaddr(uint8_t *macaddr, const char *p) =20 return 0; } + +void net_free_fds(int *fds, int nfds) +{ + int i; + + if (!fds || nfds <=3D 0) { + return; + } + + for (i =3D 0; i < nfds; i++) { + if (fds[i] !=3D -1) { + close(fds[i]); + } + } + + g_free(fds); +} + +int net_parse_fds(const char *fds_param, int **fds, int expected_nfds, + Error **errp) +{ + g_auto(GStrv) fdnames =3D g_strsplit(fds_param, ":", -1); + unsigned nfds =3D g_strv_length(fdnames); + int i; + + if (nfds > INT_MAX) { + error_setg(errp, "fds parameter exceeds maximum of %d", INT_MAX); + return -1; + } + + if (expected_nfds && nfds !=3D expected_nfds) { + error_setg(errp, "expected %u socket fds, got %u", expected_nfds, = nfds); + return -1; + } + + *fds =3D g_new(int, nfds); + + for (i =3D 0; i < nfds; i++) { + (*fds)[i] =3D monitor_fd_param(monitor_cur(), fdnames[i], errp); + if ((*fds)[i] =3D=3D -1) { + net_free_fds(*fds, i); + *fds =3D NULL; + return -1; + } + } + + return nfds; +} diff --git a/net/util.h b/net/util.h index 288312979f..4dbc5d416d 100644 --- a/net/util.h +++ b/net/util.h @@ -83,4 +83,18 @@ static inline bool in6_equal_net(const struct in6_addr *= a, =20 int net_parse_macaddr(uint8_t *macaddr, const char *p); =20 +/* + * Close all @fds and free @fds itself + */ +void net_free_fds(int *fds, int nfds); + +/* + * Parse @fds_param, where monitor fds are separated by a colon. + * @nfds must be non-NULL. If *@nfds is zero - set it accordingly. + * If *@nfds is non-zero - check that we have exactly *@nfds fds + * and fail otherwise. + */ +int net_parse_fds(const char *fds_param, int **fds, int expected_nfds, + Error **errp); + #endif /* QEMU_NET_UTIL_H */ --=20 2.52.0 From nobody Fri Mar 27 04:52:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1771446576; cv=none; d=zohomail.com; s=zohoarc; b=AeT+vadjznFT5JgRAfE1j6YNbGpZOmPmVWGMlNfdTlbeAnKpYDqM5e4u5zsH7cZ2ve+7NMk58PytZyxVejOuGcETghWWgb6WSXDiEhYoNo2K8W4Ntg1Tad7V71/W1SUWX9OSOTppRwBsi4TTWug4xzFbmfq79wTHEtD2QzxDdTs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771446576; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=o/aFvBrBgV0clNaGOdZOhE5r1XfxDS8kc1noxuRnRqQ=; b=AHg3ScOtGN0eZnzSO5RSuja8U8ECCv2kFZmFHZbYkYtUzFU3fa+pon88ap0NI+P5jRfhN1eDkH6Vf72pE2YyQ6cOUHY3gcyvDHivdBp7WYfQUtcJa5fjFJ+6wP9MPlupS8OPBqQkBisuUAdFV8ucRoEpDaJUr+eHCXEBGU0UrTo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 17714465769231015.0921014410472; Wed, 18 Feb 2026 12:29:36 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vsoAT-0007DW-Qs; Wed, 18 Feb 2026 15:29:05 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA6-00075c-SY for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:44 -0500 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA5-0007sy-7j for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:42 -0500 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id EF678C0389; Wed, 18 Feb 2026 23:28:39 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:53d::1:1b]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VShB144A8iE0-8ezo4kjE; Wed, 18 Feb 2026 23:28:39 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1771446519; bh=o/aFvBrBgV0clNaGOdZOhE5r1XfxDS8kc1noxuRnRqQ=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Q/QWShrU+OnS2MOmvw6gaSiEZoCsuuYh9TA8QYRaC/Q4a4q74RexKxcOdhF1pyWsO j+8g3FzLx2M2YjJW7x0I6UDTqiv/S+USdmWSRnskVCBKQLthJ1KMJU4I6GHTpL6DAk tvDaBNIZW2U6BQXIejFMVo2KRx0kKRaoZdYcffx4= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, bchaney@akamai.com, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, davydov-max@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v3 09/12] net/tap: move fds parameters handling to separate functions Date: Wed, 18 Feb 2026 23:28:25 +0300 Message-ID: <20260218202829.1322088-10-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260218202829.1322088-1-vsementsov@yandex-team.ru> References: <20260218202829.1322088-1-vsementsov@yandex-team.ru> 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=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1771446579267154100 Content-Type: text/plain; charset="utf-8" This significantly simplify the code in net_init_tap(). Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/tap.c | 99 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 65 insertions(+), 34 deletions(-) diff --git a/net/tap.c b/net/tap.c index 2d4630c350..b794f80e34 100644 --- a/net/tap.c +++ b/net/tap.c @@ -781,6 +781,61 @@ failed: return false; } =20 +static bool unblock_fds(int *fds, int nfds, Error **errp) +{ + for (int i =3D 0; i < nfds; i++) { + if (!qemu_set_blocking(fds[i], false, errp)) { + return false; + } + } + + return true; +} + +static int tap_parse_fds_and_queues(const NetdevTapOptions *tap, int **fds, + Error **errp) +{ + int queues =3D 1; + + if (tap->has_queues + !!tap->helper + !!tap->fds + !!tap->fd > 1) { + error_setg(errp, "queues=3D, helper=3D, fds=3D and fd=3D are mutua= l exclusive"); + return -1; + } + + if (tap->has_queues) { + if (tap->queues > INT_MAX) { + error_setg(errp, "queues exceeds maximum %d", INT_MAX); + return -1; + } + queues =3D tap->queues; + *fds =3D NULL; + } else if (tap->fd || tap->fds) { + queues =3D net_parse_fds(tap->fd ?: tap->fds, fds, + tap->fd ? 1 : 0, errp); + if (!*fds) { + return -1; + } + } else if (tap->helper) { + int fd =3D net_bridge_run_helper(tap->helper, + tap->br ?: DEFAULT_BRIDGE_INTERFACE, + errp); + if (fd < 0) { + return -1; + } + + queues =3D 1; + *fds =3D g_new(int, 1); + **fds =3D fd; + } + + if (*fds && !unblock_fds(*fds, queues, errp)) { + net_free_fds(*fds, queues); + return -1; + } + + return queues; +} + int net_init_tap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { @@ -792,7 +847,6 @@ int net_init_tap(const Netdev *netdev, const char *name, =20 assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); tap =3D &netdev->u.tap; - queues =3D tap->has_queues ? tap->queues : 1; =20 /* QEMU hubs do not support multiqueue tap, in this case peer is set. * For -netdev, peer is always NULL. */ @@ -829,10 +883,15 @@ int net_init_tap(const Netdev *netdev, const char *na= me, return -1; } =20 + queues =3D tap_parse_fds_and_queues(tap, &fds, errp); + if (queues < 0) { + return -1; + } + if (tap->vhostfd) { vhostfd =3D monitor_fd_param(monitor_cur(), tap->vhostfd, errp); if (vhostfd =3D=3D -1) { - return -1; + goto fail; } =20 if (!qemu_set_blocking(vhostfd, false, errp)) { @@ -841,41 +900,23 @@ int net_init_tap(const Netdev *netdev, const char *na= me, } =20 if (tap->fd) { - fd =3D monitor_fd_param(monitor_cur(), tap->fd, errp); - if (fd =3D=3D -1) { - goto fail; - } - - if (!qemu_set_blocking(fd, false, errp)) { - goto fail; - } - - vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); + vnet_hdr =3D tap_probe_vnet_hdr(fds[0], errp); if (vnet_hdr < 0) { goto fail; } =20 if (!net_init_tap_one(tap, peer, name, NULL, NULL, NULL, - vhostfd, vnet_hdr, fd, errp)) { + vhostfd, vnet_hdr, fds[0], errp)) { goto fail; } } else if (tap->fds) { - queues =3D net_parse_fds(tap->fds, &fds, 0, errp); - if (queues < 0) { - goto fail; - } - if (tap->vhostfds && net_parse_fds(tap->vhostfds, &vhost_fds, queues, errp) < 0) { goto fail; } =20 for (i =3D 0; i < queues; i++) { - if (!qemu_set_blocking(fds[i], false, errp)) { - goto fail; - } - if (vhost_fds && !qemu_set_blocking(vhost_fds[i], false, errp)= ) { goto fail; } @@ -899,24 +940,14 @@ int net_init_tap(const Netdev *netdev, const char *na= me, } } } else if (tap->helper) { - fd =3D net_bridge_run_helper(tap->helper, - tap->br ?: DEFAULT_BRIDGE_INTERFACE, - errp); - if (fd =3D=3D -1) { - goto fail; - } - - if (!qemu_set_blocking(fd, false, errp)) { - goto fail; - } - vnet_hdr =3D tap_probe_vnet_hdr(fd, errp); + vnet_hdr =3D tap_probe_vnet_hdr(fds[0], errp); if (vnet_hdr < 0) { goto fail; } =20 if (!net_init_tap_one(tap, peer, name, ifname, NULL, NULL, vhostfd, - vnet_hdr, fd, errp)) { + vnet_hdr, fds[0], errp)) { goto fail; } } else { --=20 2.52.0 From nobody Fri Mar 27 04:52:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1771446617; cv=none; d=zohomail.com; s=zohoarc; b=D6DRJymCdPTwS7UBs74P7VkZomwKHjAaEdHrAFYLgm0hz2zZyVCcqyJS63qsQfQ/Eo5ymx0RZqaR08sYFM1tyyQsZSVjxasY26Wfl1aFdf6GJkv+KVUpDOahfqUeLQGIASvncAFS0VW47DGYSSUqrHjQtRtJPujBlLvu6MmokyY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771446617; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=Z3LRTynch+4myJVp1TEpXR+21m9Xv+l3cSzmxxYwtEs=; b=iJESsftMn9nb4hg0uTHZUk669aVmwkV+bhaOTGwvAqw/3D7UNWIPyu5B3O5vHt2OmssCkGeMflV/yyVyBIYKpxj6+X6YEaIZGFtINfviH3867+Z+ilFnQ3wceSO8TRga5t68LerHjsxrLtp+o8P27KE7FNrtuYZIntWMX0O0BXE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1771446617845423.1465624776795; Wed, 18 Feb 2026 12:30:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vsoAV-0007Ge-6t; Wed, 18 Feb 2026 15:29:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA7-00075f-NG for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:44 -0500 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA5-0007tA-V8 for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:43 -0500 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id B688AC038B; Wed, 18 Feb 2026 23:28:40 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:53d::1:1b]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VShB144A8iE0-NatTMEsU; Wed, 18 Feb 2026 23:28:40 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1771446520; bh=Z3LRTynch+4myJVp1TEpXR+21m9Xv+l3cSzmxxYwtEs=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=oiDrRvgvyEK8sUK+nrjzt1jtjkflwvTjj3JN/iYy8Z4Btk2pg65YODbaM44BXwcLV 0mYwMLeIai8k2ujSg71LJXnY4RhvAXPrwUkw+3tPZjVUrXAgl/U+QtIJKjDetejaeG 8ds1fZsunwvj1GFyLOs9gPIyeu4KW35IoQ899AAQ= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, bchaney@akamai.com, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, davydov-max@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v3 10/12] net/tap: fix vhostfds/vhostfd parameters API Date: Wed, 18 Feb 2026 23:28:26 +0300 Message-ID: <20260218202829.1322088-11-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260218202829.1322088-1-vsementsov@yandex-team.ru> References: <20260218202829.1322088-1-vsementsov@yandex-team.ru> 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=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1771446618755158500 Content-Type: text/plain; charset="utf-8" There is a bug in the interface: we don't allow vhostfds argument together with queues. But we allow vhostfd, and try use it for all queues of multiqueue TAP. Let's relax the restriction. We already check that number of vhost fds match queues (or number of fds). So, no matter do vhost fds come from vhostfds or vhostfd argument. Let's use correct vhost fds for multiqueue TAP. To achieve this we move vhost fds parsing to separate function and call it earlier in net_init_tap(). Then we have vhost fds available (and already checked) for all further cases. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/tap.c | 62 ++++++++++++++++++++++++++----------------------------- 1 file changed, 29 insertions(+), 33 deletions(-) diff --git a/net/tap.c b/net/tap.c index b794f80e34..64164643d2 100644 --- a/net/tap.c +++ b/net/tap.c @@ -836,11 +836,31 @@ static int tap_parse_fds_and_queues(const NetdevTapOp= tions *tap, int **fds, return queues; } =20 +static bool tap_parse_vhost_fds(const NetdevTapOptions *tap, int **vhost_f= ds, + int queues, Error **errp) +{ + if (!(tap->vhostfd || tap->vhostfds)) { + *vhost_fds =3D NULL; + return true; + } + + if (net_parse_fds(tap->fd ?: tap->fds, vhost_fds, queues, errp) < 0) { + return false; + } + + if (!unblock_fds(*vhost_fds, queues, errp)) { + net_free_fds(*vhost_fds, queues); + return false; + } + + return true; +} + int net_init_tap(const Netdev *netdev, const char *name, NetClientState *peer, Error **errp) { const NetdevTapOptions *tap; - int fd =3D -1, vhostfd =3D -1, vnet_hdr =3D 0, i =3D 0, queues; + int fd =3D -1, vnet_hdr =3D 0, i =3D 0, queues; /* for the no-fd, no-helper case */ char ifname[128]; int *fds =3D NULL, *vhost_fds =3D NULL; @@ -873,30 +893,13 @@ int net_init_tap(const Netdev *netdev, const char *na= me, return -1; } =20 - if (tap->vhostfds && !tap->fds) { - error_setg(errp, "vhostfds=3D is invalid if fds=3D wasn't specifie= d"); - return -1; - } - - if (tap->vhostfd && tap->fds) { - error_setg(errp, "vhostfd=3D is invalid with fds=3D"); - return -1; - } - queues =3D tap_parse_fds_and_queues(tap, &fds, errp); if (queues < 0) { return -1; } =20 - if (tap->vhostfd) { - vhostfd =3D monitor_fd_param(monitor_cur(), tap->vhostfd, errp); - if (vhostfd =3D=3D -1) { - goto fail; - } - - if (!qemu_set_blocking(vhostfd, false, errp)) { - goto fail; - } + if (!tap_parse_vhost_fds(tap, &vhost_fds, queues, errp)) { + goto fail; } =20 if (tap->fd) { @@ -907,20 +910,12 @@ int net_init_tap(const Netdev *netdev, const char *na= me, =20 if (!net_init_tap_one(tap, peer, name, NULL, NULL, NULL, - vhostfd, vnet_hdr, fds[0], errp)) { + vhost_fds ? vhost_fds[0] : -1, + vnet_hdr, fds[0], errp)) { goto fail; } } else if (tap->fds) { - if (tap->vhostfds && net_parse_fds(tap->vhostfds, &vhost_fds, - queues, errp) < 0) { - goto fail; - } - for (i =3D 0; i < queues; i++) { - if (vhost_fds && !qemu_set_blocking(vhost_fds[i], false, errp)= ) { - goto fail; - } - if (i =3D=3D 0) { vnet_hdr =3D tap_probe_vnet_hdr(fds[i], errp); if (vnet_hdr < 0) { @@ -946,7 +941,8 @@ int net_init_tap(const Netdev *netdev, const char *name, } =20 if (!net_init_tap_one(tap, peer, name, ifname, - NULL, NULL, vhostfd, + NULL, NULL, + vhost_fds ? vhost_fds[0] : -1, vnet_hdr, fds[0], errp)) { goto fail; } @@ -979,7 +975,8 @@ int net_init_tap(const Netdev *netdev, const char *name, if (!net_init_tap_one(tap, peer, name, ifname, i >=3D 1 ? NULL : script, i >=3D 1 ? NULL : downscript, - vhostfd, vnet_hdr, fd, errp)) { + vhost_fds ? vhost_fds[i] : -1, + vnet_hdr, fd, errp)) { goto fail; } } @@ -989,7 +986,6 @@ int net_init_tap(const Netdev *netdev, const char *name, =20 fail: close(fd); - close(vhostfd); net_free_fds(fds, queues); net_free_fds(vhost_fds, queues); return -1; --=20 2.52.0 From nobody Fri Mar 27 04:52:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1771446563; cv=none; d=zohomail.com; s=zohoarc; b=XEqObl6HU5Z2WdBiNUp0kozDUyZpHRAtuynY7eeGDOyY1VEEhsTgJf/6RqbDLHINdv7nw3RGgeSJdhc0uVKe3yKrJmqhqd3oCNkvTGAdNeDSO/OuLelnKidZDlVHhycNMtORSB88diUYyb5yHoH0td1qYW651lImtlFbahEw5+w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771446563; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=tdVLrrht22AdazOVmFV4FQPo+VPPK0JuvaulnDvvKJQ=; b=Il/dEF4uQX+YLMTBSPb05FEb0ZttytgYTK6SpiKXycH9/qdrKigL/7TKs1Wi3rSGo4WiTxLTRX7fLV6ZRpo36r/XTRm5V3Qc+My7Kxv27mChFRUgGdTiRzCsbUi3p+c2H9aXzhJXByt3qngO6dU1BWdh0sHETpHheILiqGFpgaw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1771446562772538.4290537626734; Wed, 18 Feb 2026 12:29:22 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vsoAU-0007GP-EU; Wed, 18 Feb 2026 15:29:06 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA8-00075g-5d for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:45 -0500 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA6-0007tY-MR for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:43 -0500 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 6C8E9C038C; Wed, 18 Feb 2026 23:28:41 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:53d::1:1b]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VShB144A8iE0-4IIiAMgl; Wed, 18 Feb 2026 23:28:41 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1771446521; bh=tdVLrrht22AdazOVmFV4FQPo+VPPK0JuvaulnDvvKJQ=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=MZ3L/2GeHBxmyGcUBxwxqMLfAj9D4dfSYr55jCEKdXgOhPLc8cE6Go17Bs+75DXnF Lfa42Wz/7Q3J6ZcU/Y/xivneVsVXzJtKJrFd3brx72CV6yYh4k9ZgrdjfvMia26CEn ENJX5pDqyf374TUb9hC0K+UNZAwiIN2Et+yxmSBI= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, bchaney@akamai.com, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, davydov-max@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v3 11/12] net/tap: net_init_tap(): merge fd=, fds= and helper= cases into one Date: Wed, 18 Feb 2026 23:28:27 +0300 Message-ID: <20260218202829.1322088-12-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260218202829.1322088-1-vsementsov@yandex-team.ru> References: <20260218202829.1322088-1-vsementsov@yandex-team.ru> 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=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1771446565195154100 Content-Type: text/plain; charset="utf-8" Now fd=3D and helper=3D cases are just a duplication of fds=3D case with queues=3D1. Let's merge them all. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/tap.c | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/net/tap.c b/net/tap.c index 64164643d2..2318158adc 100644 --- a/net/tap.c +++ b/net/tap.c @@ -902,19 +902,7 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, goto fail; } =20 - if (tap->fd) { - vnet_hdr =3D tap_probe_vnet_hdr(fds[0], errp); - if (vnet_hdr < 0) { - goto fail; - } - - if (!net_init_tap_one(tap, peer, name, NULL, - NULL, NULL, - vhost_fds ? vhost_fds[0] : -1, - vnet_hdr, fds[0], errp)) { - goto fail; - } - } else if (tap->fds) { + if (fds) { for (i =3D 0; i < queues; i++) { if (i =3D=3D 0) { vnet_hdr =3D tap_probe_vnet_hdr(fds[i], errp); @@ -934,18 +922,6 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, goto fail; } } - } else if (tap->helper) { - vnet_hdr =3D tap_probe_vnet_hdr(fds[0], errp); - if (vnet_hdr < 0) { - goto fail; - } - - if (!net_init_tap_one(tap, peer, name, ifname, - NULL, NULL, - vhost_fds ? vhost_fds[0] : -1, - vnet_hdr, fds[0], errp)) { - goto fail; - } } else { g_autofree char *script =3D tap_parse_script(tap->script, DEFAULT_NETWORK_SCRIPT); --=20 2.52.0 From nobody Fri Mar 27 04:52:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1771446612; cv=none; d=zohomail.com; s=zohoarc; b=EVaq96EDKZ74eTTMo+b198t2NxQrh1KRegCCk+7ZzVeG5qph9wnQYQjDHWS1e+G3Ea9477JxFcTwoG1UrJ8smo5TIoOGHyJB52Y3qnOEcaGi0ROot7/AzuatINxAYp5fcwB156rYO+vr/7l4hIL1hTFqi0yUfiyML57iQdhfl5Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771446612; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=1uN4WvXdRNNARpB5HjLnfN38lT4cspiFjdLpr7Detyk=; b=UxT6gEKJSn2BYYTY/uzEAFWEaPjuCwgKv9K9dWMkU9rVsNDJMzrPVdX7IrhwohkZX7B9/75S09hnhKdo78SARJV74iTh77REXJfa/msZyVXyT/kmYzkbJWSzQXD03EaRjrNkiJ/1jm+9ObYT29ooEi8AQLphPK+7QbCvaTNwISA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1771446611680580.5712000055078; Wed, 18 Feb 2026 12:30:11 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vsoAV-0007Ga-3k; Wed, 18 Feb 2026 15:29:07 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA8-00075p-Vu for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:45 -0500 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vsoA7-0007tj-Bl for qemu-devel@nongnu.org; Wed, 18 Feb 2026 15:28:44 -0500 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:3530:0:640:eca4:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 2292BC038D; Wed, 18 Feb 2026 23:28:42 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:53d::1:1b]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VShB144A8iE0-NPmEUsve; Wed, 18 Feb 2026 23:28:41 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1771446521; bh=1uN4WvXdRNNARpB5HjLnfN38lT4cspiFjdLpr7Detyk=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=m4aUnT4fF6x8KBJBFEJBfsIm8ag45cX0CvMHgP6dNMawhMnCJF4sbJqmhS+PwXB7/ V5Ok09yGN+/aqRgMxEXiFJoimX3qbzhy2zmK4Kvn442sv/U4ag6TXyprvS1G7kjVxk 6K0kdFuHf0JFHdZj5XmgLwbGK0qdqs8ZylGw378w= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, bchaney@akamai.com, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, davydov-max@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH v3 12/12] net/tap: net_init_tap(): relax QEMU hubs check Date: Wed, 18 Feb 2026 23:28:28 +0300 Message-ID: <20260218202829.1322088-13-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260218202829.1322088-1-vsementsov@yandex-team.ru> References: <20260218202829.1322088-1-vsementsov@yandex-team.ru> 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=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1771446614755158500 Content-Type: text/plain; charset="utf-8" queues may be set to 1, as well as fds may contain only one fd. No reason to block such cases. Let's check exactly number of queues. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/tap.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/net/tap.c b/net/tap.c index 2318158adc..1623ddff5f 100644 --- a/net/tap.c +++ b/net/tap.c @@ -868,13 +868,6 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, assert(netdev->type =3D=3D NET_CLIENT_DRIVER_TAP); tap =3D &netdev->u.tap; =20 - /* QEMU hubs do not support multiqueue tap, in this case peer is set. - * For -netdev, peer is always NULL. */ - if (peer && (tap->has_queues || tap->fds || tap->vhostfds)) { - error_setg(errp, "Multiqueue tap cannot be used with hubs"); - return -1; - } - if (tap->has_vhost && !tap->vhost && (tap->vhostfds || tap->vhostfd)) { error_setg(errp, "vhostfd(s)=3D is not valid without vhost"); return -1; @@ -898,6 +891,15 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, return -1; } =20 + /* + * QEMU hubs do not support multiqueue tap, in this case peer is set. + * For -netdev, peer is always NULL. + */ + if (peer && queues > 1) { + error_setg(errp, "Multiqueue tap cannot be used with hubs"); + goto fail; + } + if (!tap_parse_vhost_fds(tap, &vhost_fds, queues, errp)) { goto fail; } --=20 2.52.0 From nobody Fri Mar 27 04:52:33 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1772739860; cv=none; d=zohomail.com; s=zohoarc; b=mhrGuWpRKhYgb/Sq7QKFkNZfwhk20GvKcZmoHlZw7kvK1o3eUk6iboDKrDjXbha3FBRvm577BEB9/lBguREhnhm36+uUqYMCAPAPYuDTBvb+CgVv6r0mguFSRKRcxDCpEAnB1vuYbBBoNNCx1PrWdBO7i29mruUNSEWCX+XnlsM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1772739860; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=87dUWNkHcTPzQRSbWhPCiEzsPvmojygUsu9xACani3Q=; b=aKvvq3ZuY03XAaCzgz0qTKZ1uuIeanL1xJAFjFAscJJINivHHGLiY0qlg+vimJ9ykrI9BXKV/GHhzlN4QWvxvpqZ0EBYX56vp0f9sn9Xk5XbGBdEIg3Vmui31vGzHqDshv/5tFfFAZChYqK8Qu/xBsW12IXIMWIItRz4CjdpObA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1772739859143919.5453750011686; Thu, 5 Mar 2026 11:44:19 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vyEbl-0004zU-JI; Thu, 05 Mar 2026 14:43:41 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyEbj-0004z8-FT for qemu-devel@nongnu.org; Thu, 05 Mar 2026 14:43:39 -0500 Received: from forwardcorp1a.mail.yandex.net ([178.154.239.72]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vyEbh-0001yd-LW for qemu-devel@nongnu.org; Thu, 05 Mar 2026 14:43:39 -0500 Received: from mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:a189:0:640:4da6:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 69346C01EF; Thu, 05 Mar 2026 22:43:33 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:b93::1:1]) by mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VhvFMN0A1Cg0-a7Ib3pOl; Thu, 05 Mar 2026 22:43:32 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1772739812; bh=87dUWNkHcTPzQRSbWhPCiEzsPvmojygUsu9xACani3Q=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=EQR8fDptTWODqUoVP4iTOX1IHkV7dbdA34I0Yl1g/HoR/50XGoZ2g+rNcfD1qKZ3Y 6tJ7652EqySusz90HLEEt9njuZNRCHnJTdkUojDe7OVhzk3fBBL94u2mI45so2rFrp 0PjDpFm7J9UUYiv9E93aHPRVG3HqoTcOkVoNyPt0= Authentication-Results: mail-nwsmtp-smtp-corp-main-80.iva.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com Cc: qemu-devel@nongnu.org, bchaney@akamai.com, yc-core@yandex-team.ru, d-tatianin@yandex-team.ru, davydov-max@yandex-team.ru, vsementsov@yandex-team.ru Subject: [PATCH 13/12 v3] net/tap: check that user tries to define zero queues Date: Thu, 5 Mar 2026 22:43:29 +0300 Message-ID: <20260305194329.1470084-1-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260218202829.1322088-1-vsementsov@yandex-team.ru> References: <20260218202829.1322088-1-vsementsov@yandex-team.ru> 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=178.154.239.72; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.892, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.622, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 List-Id: qemu development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1772739862246158500 Content-Type: text/plain; charset="utf-8" Add check for queues parameter to be non-zero, and for fd/fds parameters to be non-empty. Signed-off-by: Vladimir Sementsov-Ogievskiy Reviewed-by: Ben Chaney --- net/tap.c | 4 ++++ net/util.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/net/tap.c b/net/tap.c index 1623ddff5fb..383e158d5e2 100644 --- a/net/tap.c +++ b/net/tap.c @@ -807,6 +807,10 @@ static int tap_parse_fds_and_queues(const NetdevTapOpt= ions *tap, int **fds, error_setg(errp, "queues exceeds maximum %d", INT_MAX); return -1; } + if (tap->queues =3D=3D 0) { + error_setg(errp, "queues must be greater than zero"); + return -1; + } queues =3D tap->queues; *fds =3D NULL; } else if (tap->fd || tap->fds) { diff --git a/net/util.c b/net/util.c index 1998a6554e0..8265f155484 100644 --- a/net/util.c +++ b/net/util.c @@ -94,6 +94,11 @@ int net_parse_fds(const char *fds_param, int **fds, int = expected_nfds, return -1; } =20 + if (nfds =3D=3D 0) { + error_setg(errp, "no fds passed"); + return -1; + } + *fds =3D g_new(int, nfds); =20 for (i =3D 0; i < nfds; i++) { --=20 2.52.0