From nobody Sun Apr 6 20:41:56 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1736964762; cv=none; d=zohomail.com; s=zohoarc; b=LSQ6OvEN7e+VMGQdsgj1UKashW5tM/Hm8lcL/KDZSKXQYl+UThp1rYnvnEiVi1yRQFyqxZbhBIHg8RkPrt1nnLVhL9PcKfnpbTJPrGYQkS/7zceyD1XVnDtSMy3LNXjHOpV7xVt7V1PciSY9lAZes+gd0dIlarm8ybVKu+2nr74= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1736964762; h=Content-Type: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=BEGdjo90qqstcjYDzVJsyocDHaSy9bqqB/C1TwUZ5n8=; b=jA5j3FXofiD+KbzXsHZJJxpqhKSIj1/i4c9hgCLZFDfHjamz85NXplxTvl83bhErCdLbd0qzSUbNF8o4r4lXOIhpo9j+L4OrhXwYVHaARu+wdIQD0Pp7LAkV5sm43v50pEc6PNxSUAVsU/TM9spngdw8oP4kNK+2uim3eLZzfos= 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 1736964762917943.7572305950503; Wed, 15 Jan 2025 10:12:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tY7sL-0007H2-Ts; Wed, 15 Jan 2025 13:12: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 1tY7rB-00018L-OX for qemu-devel@nongnu.org; Wed, 15 Jan 2025 13:11:10 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tY7r9-00078p-SW for qemu-devel@nongnu.org; Wed, 15 Jan 2025 13:11:09 -0500 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-427-lXlZ7V0zPDmaN1bTpWk4gA-1; Wed, 15 Jan 2025 13:11:05 -0500 Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-4361ecebc5bso36870885e9.1 for ; Wed, 15 Jan 2025 10:11:05 -0800 (PST) Received: from redhat.com ([2a0d:6fc7:342:db8c:4ec4:322b:a6a8:f411]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-437c74e5e69sm31081175e9.37.2025.01.15.10.11.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Jan 2025 10:11:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736964667; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=BEGdjo90qqstcjYDzVJsyocDHaSy9bqqB/C1TwUZ5n8=; b=VWgSJnGcpdytGHcWBgh9IesEXsGZDhTfr+VtMU9Yj43k97FltUI3wpCvXbl228VTcEx2RE gSlCdl2ZPjtoSzmZ0el5WhuyeCpTLmJ/nDt9GVgmM5NnK6+BJ9FCtUzafQh/YDcU6hCGv1 0xyAvGJ2ONjhqjuL7ZKL/iHNn6jL6Mc= X-MC-Unique: lXlZ7V0zPDmaN1bTpWk4gA-1 X-Mimecast-MFC-AGG-ID: lXlZ7V0zPDmaN1bTpWk4gA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736964664; x=1737569464; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=BEGdjo90qqstcjYDzVJsyocDHaSy9bqqB/C1TwUZ5n8=; b=JnIzb87/z0J2Qpuln8NtOInGf8OTJTT3Mg1Z3/1b+2J2+YwW40t3/VQQRAFp7KL+Kr EM7YAS3JYVSCW6f144nfQiuFSxZ0LsOD2Sz5u0YD5Vz9tXeOvoDdKvNS7yOY8Cj7kD/s mc9AkZ36Fsvx6j6XBcCq00TDC/fyC9UsMxQe1wkTb/5sjwKBV9LjQcT8zUrtrwF+cWhw jVYzRaqxhJbdQ0rw7UZyRRP1Xq2ONpDjISfujU9zyrBaO8xQsH9b9cIR7DmxTjE4m0LJ 8UDl1muXPtW3D3YMroeMAbkUMyXkYfdfru7EcS/A2bzFSoyhV3lSVgj5SdyPUxH2XJhi f6Wg== X-Gm-Message-State: AOJu0YxPFZjytznZ/biLfC5wKFesxnsrd/jQw9BxQXOrmDbJaXYcwq1a HRnrM/AY1Ggo6nts3TETR3b1M542eRifie0lLuo5RuQaKb+/yWGaWet8KEF0pN9TEj0kACs7Fs4 HwjcRoiGrB2au1wT8TBEE7smFfxfv/XEswGql2HNEhiPHCd+4cJn4XVhOBqbL1upt1+YDsRRXCZ zDt7vv94yIktFJL4vfpKE4lcUCnHc5ug== X-Gm-Gg: ASbGncv+SpyZt5gXJb6fASGvdYKdG2GwqOtu+9jRn4wKdP1pokMbeJgR5s3dn7D9ysj sXXjGkA+lSdxBzOzjb6LYIjcpRgLbOhSI6YHzKhPpwroyi60CE3I+pveoY8JAQzz9s4E+oYEWj8 S0WPBs0OfomG4CTOOt0Vfa+9VGfh3CBOv4adsYzz1im36TmnW78oh/jbdTutymqlw3wC24Tnkdj m1d/oUR3i3tVxgFR8FDAPFdC+iV7yMEoFPv9VvNADk4ybXWKQGQ X-Received: by 2002:a05:600c:4586:b0:431:44fe:fd9f with SMTP id 5b1f17b1804b1-436e26f041bmr246316635e9.23.1736964664352; Wed, 15 Jan 2025 10:11:04 -0800 (PST) X-Google-Smtp-Source: AGHT+IE+V2hQZZ9f5rOnSH6Sk4dEveyDzjCfNx8NCFMjPNHi2wdKyOzMNhGHuNbivQsZb3eiaxAPNg== X-Received: by 2002:a05:600c:4586:b0:431:44fe:fd9f with SMTP id 5b1f17b1804b1-436e26f041bmr246316375e9.23.1736964663942; Wed, 15 Jan 2025 10:11:03 -0800 (PST) Date: Wed, 15 Jan 2025 13:11:01 -0500 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Cc: Peter Maydell , Laurent Vivier , Hanna Czenczek , Jason Wang Subject: [PULL 48/48] virtio-net: vhost-user: Implement internal migration Message-ID: <60f543ad917fad731e39ff8ce2ca83b9a9cc9d90.1736964488.git.mst@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent 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=170.10.129.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -21 X-Spam_score: -2.2 X-Spam_bar: -- X-Spam_report: (-2.2 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.141, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, 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 Precedence: list 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 @redhat.com) X-ZM-MESSAGEID: 1736964764667019000 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Laurent Vivier Add support of VHOST_USER_PROTOCOL_F_DEVICE_STATE in virtio-net with vhost-user backend. Cc: Hanna Czenczek Signed-off-by: Laurent Vivier Message-Id: <20250115135044.799698-3-lvivier@redhat.com> Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/net/virtio-net.c | 135 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 112 insertions(+), 23 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index 06f096abf6..85e14b788c 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3337,6 +3337,117 @@ static const VMStateDescription vmstate_virtio_net_= rss =3D { }, }; =20 +static struct vhost_dev *virtio_net_get_vhost(VirtIODevice *vdev) +{ + VirtIONet *n =3D VIRTIO_NET(vdev); + NetClientState *nc; + struct vhost_net *net; + + if (!n->nic) { + return NULL; + } + + nc =3D qemu_get_queue(n->nic); + if (!nc) { + return NULL; + } + + net =3D get_vhost_net(nc->peer); + if (!net) { + return NULL; + } + + return &net->dev; +} + +static int vhost_user_net_save_state(QEMUFile *f, void *pv, size_t size, + const VMStateField *field, + JSONWriter *vmdesc) +{ + VirtIONet *n =3D pv; + VirtIODevice *vdev =3D VIRTIO_DEVICE(n); + struct vhost_dev *vhdev; + Error *local_error =3D NULL; + int ret; + + vhdev =3D virtio_net_get_vhost(vdev); + if (vhdev =3D=3D NULL) { + error_reportf_err(local_error, + "Error getting vhost back-end of %s device %s: ", + vdev->name, vdev->parent_obj.canonical_path); + return -1; + } + + ret =3D vhost_save_backend_state(vhdev, f, &local_error); + if (ret < 0) { + error_reportf_err(local_error, + "Error saving back-end state of %s device %s: ", + vdev->name, vdev->parent_obj.canonical_path); + return ret; + } + + return 0; +} + +static int vhost_user_net_load_state(QEMUFile *f, void *pv, size_t size, + const VMStateField *field) +{ + VirtIONet *n =3D pv; + VirtIODevice *vdev =3D VIRTIO_DEVICE(n); + struct vhost_dev *vhdev; + Error *local_error =3D NULL; + int ret; + + vhdev =3D virtio_net_get_vhost(vdev); + if (vhdev =3D=3D NULL) { + error_reportf_err(local_error, + "Error getting vhost back-end of %s device %s: ", + vdev->name, vdev->parent_obj.canonical_path); + return -1; + } + + ret =3D vhost_load_backend_state(vhdev, f, &local_error); + if (ret < 0) { + error_reportf_err(local_error, + "Error loading back-end state of %s device %s: = ", + vdev->name, vdev->parent_obj.canonical_path); + return ret; + } + + return 0; +} + +static bool vhost_user_net_is_internal_migration(void *opaque) +{ + VirtIONet *n =3D opaque; + VirtIODevice *vdev =3D VIRTIO_DEVICE(n); + struct vhost_dev *vhdev; + + vhdev =3D virtio_net_get_vhost(vdev); + if (vhdev =3D=3D NULL) { + return false; + } + + return vhost_supports_device_state(vhdev); +} + +static const VMStateDescription vhost_user_net_backend_state =3D { + .name =3D "virtio-net-device/backend", + .version_id =3D 0, + .needed =3D vhost_user_net_is_internal_migration, + .fields =3D (const VMStateField[]) { + { + .name =3D "backend", + .info =3D &(const VMStateInfo) { + .name =3D "virtio-net vhost-user backend state", + .get =3D vhost_user_net_load_state, + .put =3D vhost_user_net_save_state, + }, + }, + VMSTATE_END_OF_LIST() + } +}; + static const VMStateDescription vmstate_virtio_net_device =3D { .name =3D "virtio-net-device", .version_id =3D VIRTIO_NET_VM_VERSION, @@ -3389,6 +3500,7 @@ static const VMStateDescription vmstate_virtio_net_de= vice =3D { }, .subsections =3D (const VMStateDescription * const []) { &vmstate_virtio_net_rss, + &vhost_user_net_backend_state, NULL } }; @@ -3950,29 +4062,6 @@ static bool dev_unplug_pending(void *opaque) return vdc->primary_unplug_pending(dev); } =20 -static struct vhost_dev *virtio_net_get_vhost(VirtIODevice *vdev) -{ - VirtIONet *n =3D VIRTIO_NET(vdev); - NetClientState *nc; - struct vhost_net *net; - - if (!n->nic) { - return NULL; - } - - nc =3D qemu_get_queue(n->nic); - if (!nc) { - return NULL; - } - - net =3D get_vhost_net(nc->peer); - if (!net) { - return NULL; - } - - return &net->dev; -} - static const VMStateDescription vmstate_virtio_net =3D { .name =3D "virtio-net", .minimum_version_id =3D VIRTIO_NET_VM_VERSION, --=20 MST