From nobody Tue Feb 10 05:42:04 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=1769962851; cv=none; d=zohomail.com; s=zohoarc; b=TMMLmu3U0GjUI3/JTLrtFOKy1ZgrRz2cSoG+aSsvhMrMUIN5liX4MrGugLwJRjEY8mTjLl1tGyqexk1ZGAcSodAXpyQqH4j9QmvX6MO6xsafwSQ73R6ugRGxWMXtPSmIW8MESCnbje3Y430n9Lr7FcGeRPLxkanAhy6DVwsb2H0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1769962851; 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=P1HaemTso6fzJD5byCYPxAqcpX9YE+ug+soY+b3svcs=; b=ezsVE3Kfh4WkvRI8J+gbdVGayEGp2K+BUvX3Jcl3AGSpe/XeeXowhVs2nf0JBONlyN//G6GXNoEUI7D7QdMmgb7am2n2VlX0OvpjFNSvB7DoGDyN8tIJ4CiqS6i3+lG3BBu9Hu6FMwGEjsJit19yEJfp6Nnn5YUdZCIRfB6byVc= 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 1769962851909848.4884161872676; Sun, 1 Feb 2026 08:20:51 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vmaBS-0001Bq-Oy; Sun, 01 Feb 2026 11:20:22 -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 1vmaBO-0001AT-64 for qemu-devel@nongnu.org; Sun, 01 Feb 2026 11:20:18 -0500 Received: from forwardcorp1d.mail.yandex.net ([178.154.239.200]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vmaBK-0005Ye-8V for qemu-devel@nongnu.org; Sun, 01 Feb 2026 11:20:17 -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 E7CA8807F6; Sun, 01 Feb 2026 19:20:12 +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-ufP40ES0; Sun, 01 Feb 2026 19:20:12 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1769962812; bh=P1HaemTso6fzJD5byCYPxAqcpX9YE+ug+soY+b3svcs=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=b3TWEPpZeTlsTYgHvsbKfDPZeiEsb6RrhPwzHmqqD1P5iRy/krROqaOMMSbRJcEmj ww0oE1D2h5wWh/3DkBQFfYwJt2g/OviyLVtNkKiTNazjsDW4BVKIezLzs5dEzs9Rdt pYXeuMAkz7RxAXVNH51C6lSJ3aVYA5m+AvEcffxM= 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 6/8] net/tap: support backend-transfer migration Date: Sun, 1 Feb 2026 19:19:58 +0300 Message-ID: <20260201162001.296328-7-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=178.154.239.200; 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, 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: 1769962854694158500 Content-Type: text/plain; charset="utf-8" Support transferring of TAP state (including open fd) through migration stream. Add new option, incoming-fds, which should be set to true to trigger new logic. Signed-off-by: Vladimir Sementsov-Ogievskiy --- net/tap.c | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++- qapi/net.json | 6 +++- 2 files changed, 92 insertions(+), 2 deletions(-) diff --git a/net/tap.c b/net/tap.c index bd19c71c42..57d4d2d9f8 100644 --- a/net/tap.c +++ b/net/tap.c @@ -393,6 +393,65 @@ static VHostNetState *tap_get_vhost_net(NetClientState= *nc) return s->vhost_net; } =20 +static bool tap_is_wait_incoming(NetClientState *nc) +{ + TAPState *s =3D DO_UPCAST(TAPState, nc, nc); + assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_TAP); + return s->fd =3D=3D -1; +} + +static int tap_pre_load(void *opaque) +{ + TAPState *s =3D opaque; + + if (s->fd !=3D -1) { + error_report( + "TAP is already initialized and cannot receive incoming fd"); + return -EINVAL; + } + + return 0; +} + +static bool tap_setup_vhost(TAPState *s, Error **errp); + +static int tap_post_load(void *opaque, int version_id) +{ + TAPState *s =3D opaque; + Error *local_err =3D NULL; + + tap_read_poll(s, true); + + if (s->fd < 0) { + return -1; + } + + if (!tap_setup_vhost(s, &local_err)) { + error_prepend(&local_err, + "Failed to setup vhost during TAP post-load: "); + error_report_err(local_err); + return -1; + } + + return 0; +} + +static const VMStateDescription vmstate_tap =3D { + .name =3D "net-tap", + .pre_load =3D tap_pre_load, + .post_load =3D tap_post_load, + .fields =3D (const VMStateField[]) { + VMSTATE_FD(fd, TAPState), + VMSTATE_BOOL(using_vnet_hdr, TAPState), + VMSTATE_BOOL(has_ufo, TAPState), + VMSTATE_BOOL(has_uso, TAPState), + VMSTATE_BOOL(has_tunnel, TAPState), + VMSTATE_BOOL(enabled, TAPState), + VMSTATE_UINT32(host_vnet_hdr_len, TAPState), + VMSTATE_END_OF_LIST() + } +}; + /* fd support */ =20 static NetClientInfo net_tap_info =3D { @@ -412,7 +471,9 @@ static NetClientInfo net_tap_info =3D { .set_vnet_le =3D tap_set_vnet_le, .set_vnet_be =3D tap_set_vnet_be, .set_steering_ebpf =3D tap_set_steering_ebpf, + .is_wait_incoming =3D tap_is_wait_incoming, .get_vhost_net =3D tap_get_vhost_net, + .backend_vmsd =3D &vmstate_tap, }; =20 static TAPState *net_tap_fd_init(NetClientState *peer, @@ -907,6 +968,14 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, return -1; } =20 + if (tap->incoming_fds && + (tap->fd || tap->fds || tap->helper || tap->script || + tap->downscript)) { + error_setg(errp, "incoming-fds is incompatible with " + "fd=3D, fds=3D, helper=3D, script=3D, downscript=3D"); + return -1; + } + queues =3D tap_parse_fds_and_queues(tap, &fds, errp); if (queues < 0) { return -1; @@ -925,7 +994,24 @@ int net_init_tap(const Netdev *netdev, const char *nam= e, goto fail; } =20 - if (fds) { + if (tap->incoming_fds) { + for (i =3D 0; i < queues; i++) { + NetClientState *nc; + TAPState *s; + + nc =3D qemu_new_net_client(&net_tap_info, peer, "tap", name); + qemu_set_info_str(nc, "incoming"); + + s =3D DO_UPCAST(TAPState, nc, nc); + s->fd =3D -1; + if (vhost_fds) { + s->vhostfd =3D vhost_fds[i]; + s->vhost_busyloop_timeout =3D tap->has_poll_us ? tap->poll= _us : 0; + } else { + s->vhostfd =3D -1; + } + } + } else if (fds) { for (i =3D 0; i < queues; i++) { if (i =3D=3D 0) { vnet_hdr =3D tap_probe_vnet_hdr(fds[i], errp); diff --git a/qapi/net.json b/qapi/net.json index 118bd34965..79f5ce9f43 100644 --- a/qapi/net.json +++ b/qapi/net.json @@ -355,6 +355,9 @@ # @poll-us: maximum number of microseconds that could be spent on busy # polling for tap (since 2.7) # +# @incoming-fds: do not open/connnect any resources, instead wait for +# TAP state from incoming migration stream. (Since 11.0) +# # Since: 1.2 ## { 'struct': 'NetdevTapOptions', @@ -373,7 +376,8 @@ '*vhostfds': 'str', '*vhostforce': 'bool', '*queues': 'uint32', - '*poll-us': 'uint32'} } + '*poll-us': 'uint32', + '*incoming-fds': 'bool' } } =20 ## # @NetdevSocketOptions: --=20 2.52.0