From nobody Sat Sep 6 17:22:35 2025 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=1756906709; cv=none; d=zohomail.com; s=zohoarc; b=eDyyYqCe8n90wnFfjb+HNeCs5y2nY4dAXCks6wjzj2/bkcztFpCF9H5kwvhJXaG3jXdVTVl6u2Nl9X/4w1W6DmYemNRcWYiAvnak4qQVyPl4FjLDAdarshrQC+5n7S5TGSE/C/58Ph3NJ7TCrtBQgwADtz/YMTCiChAnUejPvX8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1756906709; 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=GftTvKuCJ/20RJKBye2/TezLhjc0gyXvfMSFYxlvOO8=; b=K4cL0Gbu5co5cnCxt+dfepXAKc5vBj1LlnLz4qJJRc1ijI/C6S7c9tldDc8K0X1az+gN6IAl7EU0BNFDiiW719zBmviGWEiBy6llBS0z3aeEQDBaZJl7mRrm+T84eB/n0PTjTxhQNY2gIYLv183V9b+y5JFj2hosI9xeiIk/5EU= 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 1756906709097890.829689796582; Wed, 3 Sep 2025 06:38:29 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1utngC-0005Hd-0u; Wed, 03 Sep 2025 09:37:41 -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 1utnfu-00059V-Qi for qemu-devel@nongnu.org; Wed, 03 Sep 2025 09:37:23 -0400 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 1utnfq-0004wY-PL for qemu-devel@nongnu.org; Wed, 03 Sep 2025 09:37:22 -0400 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:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 71616C01A8; Wed, 03 Sep 2025 16:37:17 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:b8f::1:11]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id BbgRSa3GomI0-J7CkUe3K; Wed, 03 Sep 2025 16:37:16 +0300 Precedence: bulk X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1756906636; bh=GftTvKuCJ/20RJKBye2/TezLhjc0gyXvfMSFYxlvOO8=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=y2zSpmtroCmqBEGOq0B5Fqc9nSNMvW+h/AkFw4Ry1kvlo4wrOul9+cpZxLT2KVY7z yBxJxHBX2vStSHYOgUMBhuv51u1Wm+3R1oTo6iFLWyGlF/KnDI5WAC2rRu9HH+Aqzq q0iHM3+i5a+PPChe15hNsT2WnYk1nwLblTCT6uTY= 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, vsementsov@yandex-team.ru, leiyang@redhat.com, steven.sistare@oracle.com, yc-core@yandex-team.ru, peterx@redhat.com, mst@redhat.com, farosas@suse.de, eblake@redhat.com, armbru@redhat.com, thuth@redhat.com, philmd@linaro.org, berrange@redhat.com Subject: [PATCH v2 6/8] virtio-net: support local tap migration Date: Wed, 3 Sep 2025 16:37:03 +0300 Message-ID: <20250903133706.1177633-7-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250903133706.1177633-1-vsementsov@yandex-team.ru> References: <20250903133706.1177633-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: -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_DNSWL_NONE=-0.0001, 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: 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: 1756906711350116600 Content-Type: text/plain; charset="utf-8" Signed-off-by: Vladimir Sementsov-Ogievskiy --- hw/net/virtio-net.c | 100 ++++++++++++++++++++++++++++++++- include/hw/virtio/virtio-net.h | 2 + 2 files changed, 101 insertions(+), 1 deletion(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 6b5b5dace3..874e349fee 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -38,6 +38,8 @@ #include "qapi/qapi-events-migration.h" #include "hw/virtio/virtio-access.h" #include "migration/misc.h" +#include "migration/migration.h" +#include "migration/options.h" #include "standard-headers/linux/ethtool.h" #include "system/system.h" #include "system/replay.h" @@ -2999,7 +3001,13 @@ static void virtio_net_set_multiqueue(VirtIONet *n, = int multiqueue) n->multiqueue =3D multiqueue; virtio_net_change_num_queues(n, max * 2 + 1); =20 - virtio_net_set_queue_pairs(n); + /* + * Called from set_features(0) on reset, when on target we + * doesn't have fds yet + */ + if (!n->tap_wait_incoming) { + virtio_net_set_queue_pairs(n); + } } =20 static int virtio_net_pre_load_queues(VirtIODevice *vdev, uint32_t n) @@ -3009,6 +3017,19 @@ static int virtio_net_pre_load_queues(VirtIODevice *= vdev, uint32_t n) return 0; } =20 +static int virtio_net_pre_save_device(void *opaque) +{ + VirtIONet *n =3D opaque; + int i, r; + + for (i =3D 0; i < n->curr_queue_pairs; i++) { + r =3D peer_detach(n, i); + assert(!r); + } + + return 0; +} + static uint64_t virtio_net_get_features(VirtIODevice *vdev, uint64_t featu= res, Error **errp) { @@ -3028,6 +3049,11 @@ static uint64_t virtio_net_get_features(VirtIODevice= *vdev, uint64_t features, =20 virtio_add_feature(&features, VIRTIO_NET_F_MAC); =20 + if (n->tap_wait_incoming) { + /* Excessive feature set is OK for early initialization */ + return features; + } + if (!peer_has_vnet_hdr(n)) { virtio_clear_feature(&features, VIRTIO_NET_F_CSUM); virtio_clear_feature(&features, VIRTIO_NET_F_HOST_TSO4); @@ -3494,11 +3520,69 @@ static const VMStateDescription vhost_user_net_back= end_state =3D { } }; =20 +static int virtio_net_tap_save(QEMUFile *f, void *pv, size_t size, + const VMStateField *field, + JSONWriter *vmdesc) +{ + VirtIONet *n =3D pv; + int i; + + for (i =3D 0; i < n->max_queue_pairs; i++) { + NetClientState *nc =3D qemu_get_subqueue(n->nic, i); + assert(nc->peer->info->type =3D=3D NET_CLIENT_DRIVER_TAP); + + tap_save(nc->peer, f); + } + + return 0; +} + +static int virtio_net_tap_load(QEMUFile *f, void *pv, size_t size, + const VMStateField *field) +{ + VirtIONet *n =3D pv; + VirtIODevice *vdev =3D VIRTIO_DEVICE(n); + VirtioDeviceClass *vdc =3D VIRTIO_DEVICE_GET_CLASS(vdev); + Error *local_err =3D NULL; + int i; + + for (i =3D 0; i < n->max_queue_pairs; i++) { + NetClientState *nc =3D qemu_get_subqueue(n->nic, i); + assert(nc->peer->info->type =3D=3D NET_CLIENT_DRIVER_TAP); + + tap_load(nc->peer, f); + } + + peer_test_vnet_hdr(n); + n->tap_wait_incoming =3D false; + + vdev->host_features =3D vdc->get_features(vdev, vdev->host_features, + &local_err); + if (local_err) { + error_report_err(local_err); + return -EINVAL; + } + + return 0; +} + +static bool virtio_net_is_tap_local(void *opaque, int version_id) +{ + VirtIONet *n =3D opaque; + NetClientState *nc; + + nc =3D qemu_get_queue(n->nic); + + return migrate_local_tap() && nc->peer && + nc->peer->info->type =3D=3D NET_CLIENT_DRIVER_TAP; +} + static const VMStateDescription vmstate_virtio_net_device =3D { .name =3D "virtio-net-device", .version_id =3D VIRTIO_NET_VM_VERSION, .minimum_version_id =3D VIRTIO_NET_VM_VERSION, .post_load =3D virtio_net_post_load_device, + .pre_save =3D virtio_net_pre_save_device, .fields =3D (const VMStateField[]) { VMSTATE_UINT8_ARRAY(mac, VirtIONet, ETH_ALEN), VMSTATE_STRUCT_POINTER(vqs, VirtIONet, @@ -3525,6 +3609,15 @@ static const VMStateDescription vmstate_virtio_net_d= evice =3D { * but based on the uint. */ VMSTATE_BUFFER_POINTER_UNSAFE(vlans, VirtIONet, 0, MAX_VLAN >> 3), + { + .name =3D "tap", + .info =3D &(const VMStateInfo) { + .name =3D "virtio-net vhost-user backend state", + .get =3D virtio_net_tap_load, + .put =3D virtio_net_tap_save, + }, + .field_exists =3D virtio_net_is_tap_local, + }, VMSTATE_WITH_TMP(VirtIONet, struct VirtIONetMigTmp, vmstate_virtio_net_has_vnet), VMSTATE_UINT8(mac_table.multi_overflow, VirtIONet), @@ -3954,6 +4047,11 @@ static void virtio_net_device_realize(DeviceState *d= ev, Error **errp) vhost_net_set_config(get_vhost_net(nc->peer), (uint8_t *)&netcfg, 0, ETH_ALEN, VHOST_SET_CONFIG_TYPE_FRONTEN= D); } + + if (nc->peer && nc->peer->info->type =3D=3D NET_CLIENT_DRIVER_TAP) { + n->tap_wait_incoming =3D tap_local_incoming(nc->peer); + } + QTAILQ_INIT(&n->rsc_chains); n->qdev =3D dev; =20 diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 73fdefc0dc..04ae0e4c06 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -231,6 +231,8 @@ struct VirtIONet { struct EBPFRSSContext ebpf_rss; uint32_t nr_ebpf_rss_fds; char **ebpf_rss_fds; + + bool tap_wait_incoming; }; =20 size_t virtio_net_handle_ctrl_iov(VirtIODevice *vdev, --=20 2.48.1