From nobody Tue Feb 10 00:59:13 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=1769962862; cv=none; d=zohomail.com; s=zohoarc; b=LVgEQrQMFzsL17yz57v5/6LTz8MAIpjLkiVbMJp883rtMnKJNw/KZ25hsjzG9jGXPZ6uABqz+QCGZbw/2ZeI+vntNTZCejMTzPNml+P0jKZni+gvrOROxXUgWQGbEvyxwv8UA4DhUD1PMx0zsdY86SUmLrtA+ON7Ho0VnMImAj8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769962862; 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=eke6p0O5s5amIMdSZpuJ4Ezrfqr3WEqzpErFVjEXg1Y=; b=WDCThNAYzuE4kb2YGLzpk3nhltJHiMV5W8+qyCQZKwGdeYI1YHMLiQAcJjZ8NC6I0O4ErdLxIFIZR36FfSgfbfd1VDEwX2ev3b35ZrxA7UNZfNf22UCWwUv8qHO1762UyQIOhvoCYUl58uqkwYlhwMwJD6X0rNc3lY0I8Hv/6A4= 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 1769962862690235.69527883763305; Sun, 1 Feb 2026 08:21:02 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vmaBR-0001Bj-9F; Sun, 01 Feb 2026 11:20:21 -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 1vmaBM-00019l-Og for qemu-devel@nongnu.org; Sun, 01 Feb 2026 11:20:16 -0500 Received: from forwardcorp1d.mail.yandex.net ([2a02:6b8:c41:1300: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 1vmaBI-0005Xg-Io for qemu-devel@nongnu.org; Sun, 01 Feb 2026 11:20:16 -0500 Received: from mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net [IPv6:2a02:6b8:c42:65a0:0:640:e1de:0]) by forwardcorp1d.mail.yandex.net (Yandex) with ESMTPS id B7E81807BD; Sun, 01 Feb 2026 19:20:08 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:765::1:3b]) by mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id 4Kp2C46Aq8c0-qqHgTxWH; Sun, 01 Feb 2026 19:20:08 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1769962808; bh=eke6p0O5s5amIMdSZpuJ4Ezrfqr3WEqzpErFVjEXg1Y=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=emlGa0mmY+8Ym6es7hCdOzWMegH891jbN8QNbxFTjCkVOCR/hTg8MWdrAtYoILbmy SXQTSWiWsv9eYtlKHbeS1haZxSq0LK+bONbTAEIQz/tjtRvi6OR3zCIznoAgDY2RbJ WRWDseuIurwJ3lthrtCRoZnf/QyDwgpyTPl19iXk= Authentication-Results: mail-nwsmtp-smtp-corp-main-56.klg.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: pbonzini@redhat.com, berrange@redhat.com, thuth@redhat.com, armbru@redhat.com, eblake@redhat.com, farosas@suse.de, peterx@redhat.com, zhao1.liu@intel.com, wangyanan55@huawei.com, philmd@linaro.org, marcel.apfelbaum@gmail.com, eduardo@habkost.net, davydov-max@yandex-team.ru, qemu-devel@nongnu.org, vsementsov@yandex-team.ru, yc-core@yandex-team.ru, leiyang@redhat.com, raphael.s.norwitz@gmail.com, bchaney@akamai.com Subject: [PATCH v10 1/8] net/tap: move vhost-net open() calls to tap_parse_vhost_fds() Date: Sun, 1 Feb 2026 19:19:53 +0300 Message-ID: <20260201162001.296328-2-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260201162001.296328-1-vsementsov@yandex-team.ru> References: <20260201162001.296328-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:c41:1300:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1d.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, 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: 1769962864826158500 Content-Type: text/plain; charset="utf-8" 1. Simplify code path: get vhostfds for all cases in one function. 2. Prepare for further tap-fd-migraton feature, when we'll need to postpone vhost initialization up to post-load stage. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/net/tap.c b/net/tap.c index 288cfedd81..d003b82142 100644 --- a/net/tap.c +++ b/net/tap.c @@ -738,8 +738,7 @@ static bool net_init_tap_one(const NetdevTapOptions *ta= p, NetClientState *peer, } } =20 - if (tap->has_vhost ? tap->vhost : - (vhostfd !=3D -1) || (tap->has_vhostforce && tap->vhostforce)) { + if (vhostfd !=3D -1) { VhostNetOptions options; =20 options.backend_type =3D VHOST_BACKEND_TYPE_KERNEL; @@ -749,17 +748,6 @@ static bool net_init_tap_one(const NetdevTapOptions *t= ap, NetClientState *peer, } else { options.busyloop_timeout =3D 0; } - - 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"); - goto failed; - } - if (!qemu_set_blocking(vhostfd, false, errp)) { - goto failed; - } - } options.opaque =3D (void *)(uintptr_t)vhostfd; options.nvqs =3D 2; options.feature_bits =3D kernel_feature_bits; @@ -841,13 +829,30 @@ static int tap_parse_fds_and_queues(const NetdevTapOp= tions *tap, int **fds, static bool tap_parse_vhost_fds(const NetdevTapOptions *tap, int **vhost_f= ds, unsigned queues, Error **errp) { - if (!(tap->vhostfd || tap->vhostfds)) { + bool need_vhost =3D tap->has_vhost ? tap->vhost : + ((tap->vhostfd || tap->vhostfds) || + (tap->has_vhostforce && tap->vhostforce)); + + if (!need_vhost) { *vhost_fds =3D NULL; return true; } =20 - if (net_parse_fds(tap->fd ?: tap->fds, vhost_fds, queues, errp) < 0) { - return false; + if (tap->vhostfd || tap->vhostfds) { + if (net_parse_fds(tap->fd ?: tap->fds, vhost_fds, queues, errp) < = 0) { + return false; + } + } else if (!(tap->vhostfd || tap->vhostfds)) { + *vhost_fds =3D g_new(int, queues); + for (int i =3D 0; i < queues; i++) { + int vhostfd =3D open("/dev/vhost-net", O_RDWR); + if (vhostfd < 0) { + error_setg_file_open(errp, errno, "/dev/vhost-net"); + net_free_fds(*vhost_fds, i); + return false; + } + (*vhost_fds)[i] =3D vhostfd; + } } =20 if (!unblock_fds(*vhost_fds, queues, errp)) { --=20 2.52.0