From nobody Sun Mar 22 15:41:49 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=1773935704; cv=none; d=zohomail.com; s=zohoarc; b=dIgOWjIuF4xnRMJIkz1P6eHwzTJv4g4+vFNw+aKG2bY4uUCW25B4lq/TG3R+a+slxLiReoakQ4nERc7Hao32VzKUYX7FKAp4pgwREvhWYhmCe4YaeBznqHw2WMGiRwBttSq7/4gNwV+TQhky/6qLWJAJpnhr3GlvqD9JeEpmY+Q= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1773935704; 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=uM4ZSd5P6FlqCb5Aknd1WBF30LZiWvbe5vaL6RixKhA=; b=Fn3PhiCi4MFweT2vl/L3j/xY+wX+MpnxHG/FmUfINmI9M4A5vgAsmc4ncR6TvAELgPgSrkQVfULohbWOGgVf8s32HDfHQp1OFeEZJ7vRArS8t9FMPMEG9iLji6Qmej/gMcpCzaRUfbUB9wsHWiqO5xQN4sJv8ZP3auh4fG5m41Q= 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 177393570336262.34692366872275; Thu, 19 Mar 2026 08:55:03 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1w3Fh0-0003Y6-H4; Thu, 19 Mar 2026 11:53:50 -0400 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 1w3Fgy-0003Xg-O2 for qemu-devel@nongnu.org; Thu, 19 Mar 2026 11:53:48 -0400 Received: from forwardcorp1b.mail.yandex.net ([178.154.239.136]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1w3Fgv-0007fn-UF for qemu-devel@nongnu.org; Thu, 19 Mar 2026 11:53:48 -0400 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 19AC88080A; Thu, 19 Mar 2026 18:53:42 +0300 (MSK) Received: from vsementsov-lin (unknown [2a02:6bf:8080:d57::1:20]) by mail-nwsmtp-smtp-corp-main-34.sas.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id arQgWZ2AA0U0-uAwN6QWP; Thu, 19 Mar 2026 18:53: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=1773935621; bh=uM4ZSd5P6FlqCb5Aknd1WBF30LZiWvbe5vaL6RixKhA=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Tw6EQStmRNuXVsvOYYmV+F3NQvzBD97es//5TGfHTVhVYWyiBTjn9fDzCzCdJjI2R atpIHJ55thyGDQWIqYf58t1lcK4zU9xv4hYdJ4DwTpqFVV8XcSyUmUy5jAcViHr3YF /OpAc6BA/q90S9p31RC3tbbFqi2KNV2dTFsLcu1g= 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: 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, th.huth+qemu@posteo.eu, berrange@redhat.com, pbonzini@redhat.com Subject: [PATCH v13 2/8] net/tap: move vhost initialization to tap_setup_vhost() Date: Thu, 19 Mar 2026 18:53:26 +0300 Message-ID: <20260319155333.260341-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260319155333.260341-1-vsementsov@yandex-team.ru> References: <20260319155333.260341-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.136; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1b.mail.yandex.net X-Spam_score_int: -3 X-Spam_score: -0.4 X-Spam_bar: / X-Spam_report: (-0.4 / 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.819, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.903, 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: 1773935705232158501 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 d941c67895e..9d6213fc3e5 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