From nobody Sun Apr 12 06:13: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=1771502186; cv=none; d=zohomail.com; s=zohoarc; b=IiAKCqDPfUuqZXVIAMnQ/VW+6zDxqVS1C2YqB/DECHEc5f4MNg8fB+D6U4CSF6sTjZVnKjhhpdzFyODdISD9MVkMliQMrcfj3pQFBeDIMF47hgVgSTzOfAPUgOnpZdvKTGSkfcXWhcpbyBTKhNXRwqAhhlol9kqUBaOT/rtJpN0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1771502186; 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=fF0WU7Y5ApYR2lkAVIV/MqBLwBoq0YXSQE5sJlwnsPM=; b=Cp1qIhEc00TJpCkLmKGJUt7ZoDQxQ4fT+Ctj+uISpGj3f7yuko9gbyaF0zlH3eQHkVxqrlEXSvT3oH8pzMETY1B2jGuJDk/qxLz6JWgP+6jJBWG6zRulybME6YTHGyXAW9Tb9ezWNcoFHxf+SyFAOLiFKKmQqddF19o6D4uu+5Y= 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 1771502185611115.488339416837; Thu, 19 Feb 2026 03:56:25 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vt2dN-0004Pm-2C; Thu, 19 Feb 2026 06:55:53 -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 1vt2dB-0004NN-JQ for qemu-devel@nongnu.org; Thu, 19 Feb 2026 06:55:42 -0500 Received: from forwardcorp1b.mail.yandex.net ([2a02:6b8:c02:900: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 1vt2d8-0006DE-8z for qemu-devel@nongnu.org; Thu, 19 Feb 2026 06:55:40 -0500 Received: from mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net [IPv6:2a02:6b8:c24:fa2:0:640:41ee:0]) by forwardcorp1b.mail.yandex.net (Yandex) with ESMTPS id 92D5080878; Thu, 19 Feb 2026 14:55:36 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:192::1:26]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id VtZwpM4A6uQ0-lpbtJ6aw; Thu, 19 Feb 2026 14:55: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=1771502136; bh=fF0WU7Y5ApYR2lkAVIV/MqBLwBoq0YXSQE5sJlwnsPM=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=uFY82wqLwx2GK6Ar9Pt93oNYlU/mqfxZPsCqOzQSkdtch//Fmxp8H0N61Vk4LIaKJ 6i85djid4dg43ruC7QC2U3SZNAJ0ye4sjyObFRIUCJBtuhHN183Rgj4Ovw9EXumwgc lnyndiddghYqo6875DmxCBIweiUmNaenVAglhypg= Authentication-Results: mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: jasowang@redhat.com, mst@redhat.com Cc: 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 v11 2/8] net/tap: move vhost initialization to tap_setup_vhost() Date: Thu, 19 Feb 2026 14:55:23 +0300 Message-ID: <20260219115530.2019498-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260219115530.2019498-1-vsementsov@yandex-team.ru> References: <20260219115530.2019498-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:c02:900:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.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: 1771502190525158500 Content-Type: text/plain; charset="utf-8" Make a new helper function in a way it can be reused later for TAP fd-migration feature: we'll need to initialize vhost in a later point when we doesn't have access to QAPI parameters. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 62 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 24 deletions(-) diff --git a/net/tap.c b/net/tap.c index 1245b98408..294ca61f8b 100644 --- a/net/tap.c +++ b/net/tap.c @@ -71,6 +71,8 @@ static const int kernel_feature_bits[] =3D { typedef struct TAPState { NetClientState nc; int fd; + int vhostfd; + uint32_t vhost_busyloop_timeout; char down_script[1024]; char down_script_arg[128]; uint8_t buf[NET_BUFSIZE]; @@ -702,6 +704,38 @@ static int net_tap_init(const NetdevTapOptions *tap, i= nt *vnet_hdr, return fd; } =20 +static bool tap_setup_vhost(TAPState *s, Error **errp) +{ + VhostNetOptions options; + + if (s->vhostfd =3D=3D -1) { + return true; + } + + options.backend_type =3D VHOST_BACKEND_TYPE_KERNEL; + options.net_backend =3D &s->nc; + options.busyloop_timeout =3D s->vhost_busyloop_timeout; + options.opaque =3D (void *)(uintptr_t)s->vhostfd; + options.nvqs =3D 2; + options.feature_bits =3D kernel_feature_bits; + options.get_acked_features =3D NULL; + options.save_acked_features =3D NULL; + options.max_tx_queue_size =3D 0; + options.is_vhost_user =3D false; + + s->vhost_net =3D vhost_net_init(&options); + if (!s->vhost_net) { + error_setg(errp, + "vhost-net requested but could not be initialized"); + return false; + } + + /* vhostfd ownership is passed to s->vhost_net */ + s->vhostfd =3D -1; + + return true; +} + static bool net_init_tap_one(const NetdevTapOptions *tap, NetClientState *= peer, const char *name, const char *ifname, const char *script, @@ -736,30 +770,10 @@ static bool net_init_tap_one(const NetdevTapOptions *= tap, NetClientState *peer, } } =20 - if (vhostfd !=3D -1) { - VhostNetOptions options; - - options.backend_type =3D VHOST_BACKEND_TYPE_KERNEL; - options.net_backend =3D &s->nc; - if (tap->has_poll_us) { - options.busyloop_timeout =3D tap->poll_us; - } else { - options.busyloop_timeout =3D 0; - } - options.opaque =3D (void *)(uintptr_t)vhostfd; - options.nvqs =3D 2; - options.feature_bits =3D kernel_feature_bits; - options.get_acked_features =3D NULL; - options.save_acked_features =3D NULL; - options.max_tx_queue_size =3D 0; - options.is_vhost_user =3D false; - - s->vhost_net =3D vhost_net_init(&options); - if (!s->vhost_net) { - error_setg(errp, - "vhost-net requested but could not be initialized"); - goto failed; - } + s->vhostfd =3D vhostfd; + s->vhost_busyloop_timeout =3D tap->has_poll_us ? tap->poll_us : 0; + if (!tap_setup_vhost(s, errp)) { + return false; } =20 return true; --=20 2.52.0