From nobody Mon Feb 9 10:29:31 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=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1660157235; cv=none; d=zohomail.com; s=zohoarc; b=M8qNYtDVIrrNc7JLKyWdVxqQMQDzc6cDOI4IpeaUOKKtp5S9x+irmBlv4x4yfJn8a46ZpF7n3CNMrspjs+zVhWTV3vlymDrefHRnxYGs20zCzNKn4CNmvCj+QQ2YKPxjFvSuX5SMQrIRh5eHAmfAy1bk/I5hPgQoURMAYeRYEzk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1660157235; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sdWfPImGYnxmxXNlua6fqa5IUyRe5dPjNA7afa0LHj0=; b=DFgQFv7S3DSusp4FcljqxJBQToyGgk+57fYdU8zeaPgz0Q0ahiKfpgOSsGlFZ5Q3DucXtv2UfHZRkY29nnEc4NC+dVmpQsCEXE42ADSMA80FvgQdoLXHhC8bUPLru4AlumfgPaw7RrncdtMSa7ChkUq/AqxF4/gRQlm9k0qtuJ4= 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 1660157235702117.95674310076174; Wed, 10 Aug 2022 11:47:15 -0700 (PDT) Received: from localhost ([::1]:49204 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oLqjV-0004or-DI for importer@patchew.org; Wed, 10 Aug 2022 14:47:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oLqfG-00028x-NO for qemu-devel@nongnu.org; Wed, 10 Aug 2022 14:42:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]:44647) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oLqfF-0006kT-6C for qemu-devel@nongnu.org; Wed, 10 Aug 2022 14:42:46 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-401-Rtw7x0VwPtOmWZbn4LnDyA-1; Wed, 10 Aug 2022 14:42:40 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CEFC385A58F; Wed, 10 Aug 2022 18:42:39 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.156]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4021BC15BA3; Wed, 10 Aug 2022 18:42:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1660156964; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sdWfPImGYnxmxXNlua6fqa5IUyRe5dPjNA7afa0LHj0=; b=DWmnwvVKcyp45g8KloH5C7MpZojfWEC7/yHaZe4uVHxw1nj5XRhXO1e6oRSii9821E55YL mxtkGkYNx7FYvbgmETJD7OTx1D0O+xf31XWbFEmG8Oa/04khDcaOgxzjFIoNFbz7NiGQdw ag92OY/XYOb1WkSIDfH5dcHJq1vTU9w= X-MC-Unique: Rtw7x0VwPtOmWZbn4LnDyA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Paolo Bonzini , "Gonglei (Arei)" , Cindy Lu , Laurent Vivier , Stefan Hajnoczi , Parav Pandit , Zhu Lingshan , Gautam Dawar , Liuxiangdong , Jason Wang , Cornelia Huck , Eli Cohen , Stefano Garzarella , "Michael S. Tsirkin" , Harpreet Singh Anand Subject: [RFC 5/8] vdpa: Add vdpa memory listener Date: Wed, 10 Aug 2022 20:42:17 +0200 Message-Id: <20220810184220.2362292-6-eperezma@redhat.com> In-Reply-To: <20220810184220.2362292-1-eperezma@redhat.com> References: <20220810184220.2362292-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 2.85 on 10.11.54.8 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=eperezma@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -28 X-Spam_score: -2.9 X-Spam_bar: -- X-Spam_report: (-2.9 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.082, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1660157236304100001 This enable net/vdpa to restart the full device when a migration is started or stopped. Signed-off-by: Eugenio P=C3=A9rez --- net/vhost-vdpa.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index a035c89c34..4c6947feb8 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -21,6 +21,7 @@ #include "qemu/memalign.h" #include "qemu/option.h" #include "qapi/error.h" +#include "exec/address-spaces.h" #include #include #include @@ -32,6 +33,8 @@ typedef struct VhostVDPAState { NetClientState nc; struct vhost_vdpa vhost_vdpa; + MemoryListener memory_listener; + VHostNetState *vhost_net; =20 /* Control commands shadow buffers */ @@ -110,6 +113,16 @@ static const uint64_t vdpa_svq_device_features =3D #define VHOST_VDPA_NET_CVQ_PASSTHROUGH 0 #define VHOST_VDPA_NET_CVQ_ASID 1 =20 +/* + * Vdpa memory listener must run before vhost one, so vhost_vdpa does not = get + * _F_LOG_ALL without SVQ. + */ +#define VHOST_VDPA_NET_MEMORY_LISTENER_PRIORITY \ + (VHOST_DEV_MEMORY_LISTENER_PRIORITY= - 1) +/* Check for underflow */ +QEMU_BUILD_BUG_ON(VHOST_DEV_MEMORY_LISTENER_PRIORITY < + VHOST_VDPA_NET_MEMORY_LISTENER_PRIORITY); + VHostNetState *vhost_vdpa_get_vhost_net(NetClientState *nc) { VhostVDPAState *s =3D DO_UPCAST(VhostVDPAState, nc, nc); @@ -172,6 +185,9 @@ static void vhost_vdpa_cleanup(NetClientState *nc) =20 qemu_vfree(s->cvq_cmd_out_buffer); qemu_vfree(s->cvq_cmd_in_buffer); + if (dev->vq_index =3D=3D 0) { + memory_listener_unregister(&s->memory_listener); + } if (dev->vq_index + dev->nvqs =3D=3D dev->vq_index_end) { g_clear_pointer(&s->vhost_vdpa.iova_tree, vhost_iova_tree_delete); } @@ -224,6 +240,69 @@ static ssize_t vhost_vdpa_receive(NetClientState *nc, = const uint8_t *buf, return 0; } =20 +static void vhost_vdpa_net_log_global_enable(MemoryListener *listener, + bool enable) +{ + VhostVDPAState *s =3D container_of(listener, VhostVDPAState, + memory_listener); + struct vhost_vdpa *v =3D &s->vhost_vdpa; + VirtIONet *n; + VirtIODevice *vdev; + int data_queue_pairs, cvq, r; + NetClientState *peer; + + if (s->always_svq || s->log_enabled =3D=3D enable) { + return; + } + + s->log_enabled =3D enable; + vdev =3D v->dev->vdev; + n =3D VIRTIO_NET(vdev); + if (!n->vhost_started) { + return; + } + + if (enable) { + ioctl(v->device_fd, VHOST_VDPA_SUSPEND); + } + data_queue_pairs =3D n->multiqueue ? n->max_queue_pairs : 1; + cvq =3D virtio_vdev_has_feature(vdev, VIRTIO_NET_F_CTRL_VQ) ? + n->max_ncs - n->max_queue_pairs : 0; + vhost_net_stop(vdev, n->nic->ncs, data_queue_pairs, cvq); + + peer =3D s->nc.peer; + for (int i =3D 0; i < data_queue_pairs + cvq; i++) { + VhostVDPAState *vdpa_state; + NetClientState *nc; + + if (i < data_queue_pairs) { + nc =3D qemu_get_peer(peer, i); + } else { + nc =3D qemu_get_peer(peer, n->max_queue_pairs); + } + + vdpa_state =3D DO_UPCAST(VhostVDPAState, nc, nc); + vdpa_state->vhost_vdpa.listener_shadow_vq =3D enable; + vdpa_state->vhost_vdpa.shadow_vqs_enabled =3D enable; + vdpa_state->log_enabled =3D enable; + } + + r =3D vhost_net_start(vdev, n->nic->ncs, data_queue_pairs, cvq); + if (unlikely(r < 0)) { + error_report("unable to start vhost net: %s(%d)", g_strerror(-r), = -r); + } +} + +static void vhost_vdpa_net_log_global_start(MemoryListener *listener) +{ + vhost_vdpa_net_log_global_enable(listener, true); +} + +static void vhost_vdpa_net_log_global_stop(MemoryListener *listener) +{ + vhost_vdpa_net_log_global_enable(listener, false); +} + static NetClientInfo net_vhost_vdpa_info =3D { .type =3D NET_CLIENT_DRIVER_VHOST_VDPA, .size =3D sizeof(VhostVDPAState), @@ -413,6 +492,7 @@ static void vhost_vdpa_net_cvq_stop(NetClientState *nc) =20 assert(nc->info->type =3D=3D NET_CLIENT_DRIVER_VHOST_VDPA); =20 + memory_listener_unregister(&s->memory_listener); if (s->vhost_vdpa.shadow_vqs_enabled) { vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_out_buffer); vhost_vdpa_cvq_unmap_buf(&s->vhost_vdpa, s->cvq_cmd_in_buffer); @@ -671,6 +751,13 @@ static NetClientState *net_vhost_vdpa_init(NetClientSt= ate *peer, s->vhost_vdpa.shadow_vqs_enabled =3D svq; s->vhost_vdpa.listener_shadow_vq =3D svq; s->vhost_vdpa.iova_tree =3D iova_tree; + if (queue_pair_index =3D=3D 0) { + s->memory_listener =3D (MemoryListener) { + .log_global_start =3D vhost_vdpa_net_log_global_start, + .log_global_stop =3D vhost_vdpa_net_log_global_stop, + }; + memory_listener_register(&s->memory_listener, &address_space_memor= y); + } if (!is_datapath) { s->cvq_cmd_out_buffer =3D qemu_memalign(qemu_real_host_page_size(), vhost_vdpa_net_cvq_cmd_page_le= n()); --=20 2.31.1