From nobody Tue Nov 26 22:42:28 2024 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=1703159637; cv=none; d=zohomail.com; s=zohoarc; b=enSAUruYlS3FMfDlvW7yIL+c9qX9j6XWK5kaxJfRvi4PSJoKEb4ynzvfeKPEfx+baAt3UtbCyoelLe7143G0NEFQWJt/qLqiYuSbAQk63MKa9b+0qlWHqvutA6ndbk5fJ5dwEnAwxVhBIs+kflQpXPhYDS/TcbimvlbnbpA8Z1I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703159637; h=Content-Type: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=WZy41tfjoU8aHftvwSt3RzK3QFCxnhNMHWVDMCQrRsY=; b=GxF91FNAd5YLI4uabsdB0Z70k+oVVNYeacu7JzaCJbtCUaqAON1WP1iYKTrzneM3SgFj0f861TpILt0zsqKQwfHKeL3DL4mYNOtVLMVmMdCOjqdkYKiDFrfv5q25CFk6RR93gvFdOobrbhxDtCt7ky/ONUv560KscpFDPPS8AZw= 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 1703159637606745.9699214077282; Thu, 21 Dec 2023 03:53:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGHcM-00086f-An; Thu, 21 Dec 2023 06:53:34 -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 1rGHcI-00086O-Lz for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:30 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rGHcG-0007ts-VX for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:30 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-690-nC0GqH1DPNepzZwHkvmQYg-1; Thu, 21 Dec 2023 06:53:26 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CF9DA185A780; Thu, 21 Dec 2023 11:53:25 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0D98B40C6E2B; Thu, 21 Dec 2023 11:53:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703159607; 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=WZy41tfjoU8aHftvwSt3RzK3QFCxnhNMHWVDMCQrRsY=; b=L3SaJjudr4nmyDdq79xCcRkP6yOfmRx+dr2akIHRTZAxJmuniYrpRk7TTTsEtJbC8U8Boo yMQoc9ULozG5X67fdXCfT6p66NK4tNmnIW60CIh40uZD8a/rMWXw4SGSsG9FCDiqI75c3r j7RkW/OJa2KMVUmzEFomfbxOHJH6oxY= X-MC-Unique: nC0GqH1DPNepzZwHkvmQYg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Parav Pandit , Dragos Tatulea , Lei Yang , Jason Wang , si-wei.liu@oracle.com, Zhu Lingshan , Stefano Garzarella , "Michael S. Tsirkin" , Laurent Vivier Subject: [PATCH v3 01/14] vdpa: add VhostVDPAShared Date: Thu, 21 Dec 2023 12:53:06 +0100 Message-Id: <20231221115319.3067586-2-eperezma@redhat.com> In-Reply-To: <20231221115319.3067586-1-eperezma@redhat.com> References: <20231221115319.3067586-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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.133.124; envelope-from=eperezma@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.063, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1703159639742100003 It will hold properties shared among all vhost_vdpa instances associated with of the same device. For example, we just need one iova_tree or one memory listener for the entire device. Next patches will register the vhost_vdpa memory listener at the beginning of the VM migration at the destination. This enables QEMU to map the memory to the device before stopping the VM at the source, instead of doing while both source and destination are stopped, thus minimizing the downtime. However, the destination QEMU is unaware of which vhost_vdpa struct will register its memory_listener. If the source guest has CVQ enabled, it will be the one associated with the CVQ. Otherwise, it will be the first one. Save the memory operations related members in a common place rather than always in the first / last vhost_vdpa. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- include/hw/virtio/vhost-vdpa.h | 5 +++++ net/vhost-vdpa.c | 24 ++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 5407d54fd7..eb1a56d75a 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -30,6 +30,10 @@ typedef struct VhostVDPAHostNotifier { void *addr; } VhostVDPAHostNotifier; =20 +/* Info shared by all vhost_vdpa device models */ +typedef struct vhost_vdpa_shared { +} VhostVDPAShared; + typedef struct vhost_vdpa { int device_fd; int index; @@ -46,6 +50,7 @@ typedef struct vhost_vdpa { bool suspended; /* IOVA mapping used by the Shadow Virtqueue */ VhostIOVATree *iova_tree; + VhostVDPAShared *shared; GPtrArray *shadow_vqs; const VhostShadowVirtqueueOps *shadow_vq_ops; void *shadow_vq_ops_opaque; diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index d0614d7954..8b661b9e6d 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -240,6 +240,10 @@ static void vhost_vdpa_cleanup(NetClientState *nc) qemu_close(s->vhost_vdpa.device_fd); s->vhost_vdpa.device_fd =3D -1; } + if (s->vhost_vdpa.index !=3D 0) { + return; + } + g_free(s->vhost_vdpa.shared); } =20 /** Dummy SetSteeringEBPF to support RSS for vhost-vdpa backend */ @@ -1661,6 +1665,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientS= tate *peer, bool svq, struct vhost_vdpa_iova_range iova_r= ange, uint64_t features, + VhostVDPAShared *shared, Error **errp) { NetClientState *nc =3D NULL; @@ -1696,6 +1701,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientS= tate *peer, if (queue_pair_index =3D=3D 0) { vhost_vdpa_net_valid_svq_features(features, &s->vhost_vdpa.migration_blocker= ); + s->vhost_vdpa.shared =3D g_new0(VhostVDPAShared, 1); } else if (!is_datapath) { s->cvq_cmd_out_buffer =3D mmap(NULL, vhost_vdpa_net_cvq_cmd_page_l= en(), PROT_READ | PROT_WRITE, @@ -1708,11 +1714,16 @@ static NetClientState *net_vhost_vdpa_init(NetClien= tState *peer, s->vhost_vdpa.shadow_vq_ops_opaque =3D s; s->cvq_isolated =3D cvq_isolated; } + if (queue_pair_index !=3D 0) { + s->vhost_vdpa.shared =3D shared; + } + ret =3D vhost_vdpa_add(nc, (void *)&s->vhost_vdpa, queue_pair_index, n= vqs); if (ret) { qemu_del_net_client(nc); return NULL; } + return nc; } =20 @@ -1824,17 +1835,26 @@ int net_init_vhost_vdpa(const Netdev *netdev, const= char *name, ncs =3D g_malloc0(sizeof(*ncs) * queue_pairs); =20 for (i =3D 0; i < queue_pairs; i++) { + VhostVDPAShared *shared =3D NULL; + + if (i) { + shared =3D DO_UPCAST(VhostVDPAState, nc, ncs[0])->vhost_vdpa.s= hared; + } ncs[i] =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, vdpa_device_fd, i, 2, true, opts->x_s= vq, - iova_range, features, errp); + iova_range, features, shared, errp); if (!ncs[i]) goto err; } =20 if (has_cvq) { + VhostVDPAState *s0 =3D DO_UPCAST(VhostVDPAState, nc, ncs[0]); + VhostVDPAShared *shared =3D s0->vhost_vdpa.shared; + nc =3D net_vhost_vdpa_init(peer, TYPE_VHOST_VDPA, name, vdpa_device_fd, i, 1, false, - opts->x_svq, iova_range, features, errp); + opts->x_svq, iova_range, features, shared, + errp); if (!nc) goto err; } --=20 2.39.3 From nobody Tue Nov 26 22:42:28 2024 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=1703159716; cv=none; d=zohomail.com; s=zohoarc; b=KJWYLW6u2L4575fzwBrBFek0Vehs+hTlkTsN+N1jfXt2IShvwK+OA9H7Fm35pgDLO9W1scYRiNOWaL3N+84oLef5HsjIMQJAvpGHvG2myT1r812HUk4joW5OQYjk/0M+UvKx2HhiP7qJQBDn/hleKX6YnNxMXJXOv0AQEi3nZ84= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703159716; h=Content-Type: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=YvA8DRQtDSqR0QnTAPfKnn8uM+q3xCroDQsExpaGUPw=; b=c5oMRqKIhBpd+23JD5TxFUPJw8gmYvkjrFam1OdxmdXEziyA21hwPcd79Tqv/fi+OZ9Gagv+crlHsMyLoyk8qpzlaIl/FQoFAn4oL3gHKT5OV9B2neZJMBKJom0zsFqjx8R9+Fprl8jCW7l+YdoIYp35TxNQp8H7Gtzt0AzwlwY= 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 1703159716916279.8787778907259; Thu, 21 Dec 2023 03:55:16 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGHcR-00088S-Iu; Thu, 21 Dec 2023 06:53:39 -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 1rGHcO-00087T-SS for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rGHcK-0007uc-9R for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:36 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-530-bWmldburNhGHac68UvAkhQ-1; Thu, 21 Dec 2023 06:53:28 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DBA2085A589; Thu, 21 Dec 2023 11:53:27 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1BF0640C6EB9; Thu, 21 Dec 2023 11:53:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703159611; 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=YvA8DRQtDSqR0QnTAPfKnn8uM+q3xCroDQsExpaGUPw=; b=JnbbQTJMWA4DR2JwDg6sLqcqpdujYIEBhnZq2MPwiDkweEx/aYpkpkyYnmbNvu+Fqe9rci XK6aZCeEJLc6BR7/ANXk923JwHH6W9Mpfw+6Uvpb3E03yIRtIzTQ4doWwVE+VTiA94Ufc3 RwcxD6jAmXAId/UbSZ63SF4Ht+EE56o= X-MC-Unique: bWmldburNhGHac68UvAkhQ-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Parav Pandit , Dragos Tatulea , Lei Yang , Jason Wang , si-wei.liu@oracle.com, Zhu Lingshan , Stefano Garzarella , "Michael S. Tsirkin" , Laurent Vivier Subject: [PATCH v3 02/14] vdpa: move iova tree to the shared struct Date: Thu, 21 Dec 2023 12:53:07 +0100 Message-Id: <20231221115319.3067586-3-eperezma@redhat.com> In-Reply-To: <20231221115319.3067586-1-eperezma@redhat.com> References: <20231221115319.3067586-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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.133.124; envelope-from=eperezma@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.063, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1703159718124100001 Next patches will register the vhost_vdpa memory listener while the VM is migrating at the destination, so we can map the memory to the device before stopping the VM at the source. The main goal is to reduce the downtime. However, the destination QEMU is unaware of which vhost_vdpa device will register its memory_listener. If the source guest has CVQ enabled, it will be the CVQ device. Otherwise, it will be the first one. Move the iova tree to VhostVDPAShared so all vhost_vdpa can use it, rather than always in the first or last vhost_vdpa. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- include/hw/virtio/vhost-vdpa.h | 4 +-- hw/virtio/vhost-vdpa.c | 19 ++++++------ net/vhost-vdpa.c | 54 +++++++++++++++------------------- 3 files changed, 35 insertions(+), 42 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index eb1a56d75a..ac036055d3 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -32,6 +32,8 @@ typedef struct VhostVDPAHostNotifier { =20 /* Info shared by all vhost_vdpa device models */ typedef struct vhost_vdpa_shared { + /* IOVA mapping used by the Shadow Virtqueue */ + VhostIOVATree *iova_tree; } VhostVDPAShared; =20 typedef struct vhost_vdpa { @@ -48,8 +50,6 @@ typedef struct vhost_vdpa { bool shadow_data; /* Device suspended successfully */ bool suspended; - /* IOVA mapping used by the Shadow Virtqueue */ - VhostIOVATree *iova_tree; VhostVDPAShared *shared; GPtrArray *shadow_vqs; const VhostShadowVirtqueueOps *shadow_vq_ops; diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 819b2d811a..9cee38cb6d 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -358,7 +358,7 @@ static void vhost_vdpa_listener_region_add(MemoryListen= er *listener, mem_region.size =3D int128_get64(llsize) - 1, mem_region.perm =3D IOMMU_ACCESS_FLAG(true, section->readonly), =20 - r =3D vhost_iova_tree_map_alloc(v->iova_tree, &mem_region); + r =3D vhost_iova_tree_map_alloc(v->shared->iova_tree, &mem_region); if (unlikely(r !=3D IOVA_OK)) { error_report("Can't allocate a mapping (%d)", r); goto fail; @@ -379,7 +379,7 @@ static void vhost_vdpa_listener_region_add(MemoryListen= er *listener, =20 fail_map: if (v->shadow_data) { - vhost_iova_tree_remove(v->iova_tree, mem_region); + vhost_iova_tree_remove(v->shared->iova_tree, mem_region); } =20 fail: @@ -441,13 +441,13 @@ static void vhost_vdpa_listener_region_del(MemoryList= ener *listener, .size =3D int128_get64(llsize) - 1, }; =20 - result =3D vhost_iova_tree_find_iova(v->iova_tree, &mem_region); + result =3D vhost_iova_tree_find_iova(v->shared->iova_tree, &mem_re= gion); if (!result) { /* The memory listener map wasn't mapped */ return; } iova =3D result->iova; - vhost_iova_tree_remove(v->iova_tree, *result); + vhost_iova_tree_remove(v->shared->iova_tree, *result); } vhost_vdpa_iotlb_batch_begin_once(v); /* @@ -1059,7 +1059,8 @@ static void vhost_vdpa_svq_unmap_ring(struct vhost_vd= pa *v, hwaddr addr) const DMAMap needle =3D { .translated_addr =3D addr, }; - const DMAMap *result =3D vhost_iova_tree_find_iova(v->iova_tree, &need= le); + const DMAMap *result =3D vhost_iova_tree_find_iova(v->shared->iova_tre= e, + &needle); hwaddr size; int r; =20 @@ -1075,7 +1076,7 @@ static void vhost_vdpa_svq_unmap_ring(struct vhost_vd= pa *v, hwaddr addr) return; } =20 - vhost_iova_tree_remove(v->iova_tree, *result); + vhost_iova_tree_remove(v->shared->iova_tree, *result); } =20 static void vhost_vdpa_svq_unmap_rings(struct vhost_dev *dev, @@ -1103,7 +1104,7 @@ static bool vhost_vdpa_svq_map_ring(struct vhost_vdpa= *v, DMAMap *needle, { int r; =20 - r =3D vhost_iova_tree_map_alloc(v->iova_tree, needle); + r =3D vhost_iova_tree_map_alloc(v->shared->iova_tree, needle); if (unlikely(r !=3D IOVA_OK)) { error_setg(errp, "Cannot allocate iova (%d)", r); return false; @@ -1115,7 +1116,7 @@ static bool vhost_vdpa_svq_map_ring(struct vhost_vdpa= *v, DMAMap *needle, needle->perm =3D=3D IOMMU_RO); if (unlikely(r !=3D 0)) { error_setg_errno(errp, -r, "Cannot map region to device"); - vhost_iova_tree_remove(v->iova_tree, *needle); + vhost_iova_tree_remove(v->shared->iova_tree, *needle); } =20 return r =3D=3D 0; @@ -1216,7 +1217,7 @@ static bool vhost_vdpa_svqs_start(struct vhost_dev *d= ev) goto err; } =20 - vhost_svq_start(svq, dev->vdev, vq, v->iova_tree); + vhost_svq_start(svq, dev->vdev, vq, v->shared->iova_tree); ok =3D vhost_vdpa_svq_map_rings(dev, svq, &addr, &err); if (unlikely(!ok)) { goto err_map; diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 8b661b9e6d..10703e5833 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -354,8 +354,8 @@ static void vhost_vdpa_net_data_start_first(VhostVDPASt= ate *s) migration_add_notifier(&s->migration_state, vdpa_net_migration_state_notifier); if (v->shadow_vqs_enabled) { - v->iova_tree =3D vhost_iova_tree_new(v->iova_range.first, - v->iova_range.last); + v->shared->iova_tree =3D vhost_iova_tree_new(v->iova_range.first, + v->iova_range.last); } } =20 @@ -380,11 +380,6 @@ static int vhost_vdpa_net_data_start(NetClientState *n= c) return 0; } =20 - if (v->shadow_vqs_enabled) { - VhostVDPAState *s0 =3D vhost_vdpa_net_first_nc_vdpa(s); - v->iova_tree =3D s0->vhost_vdpa.iova_tree; - } - return 0; } =20 @@ -417,9 +412,8 @@ static void vhost_vdpa_net_client_stop(NetClientState *= nc) =20 dev =3D s->vhost_vdpa.dev; if (dev->vq_index + dev->nvqs =3D=3D dev->vq_index_end) { - g_clear_pointer(&s->vhost_vdpa.iova_tree, vhost_iova_tree_delete); - } else { - s->vhost_vdpa.iova_tree =3D NULL; + g_clear_pointer(&s->vhost_vdpa.shared->iova_tree, + vhost_iova_tree_delete); } } =20 @@ -474,7 +468,7 @@ static int vhost_vdpa_set_address_space_id(struct vhost= _vdpa *v, =20 static void vhost_vdpa_cvq_unmap_buf(struct vhost_vdpa *v, void *addr) { - VhostIOVATree *tree =3D v->iova_tree; + VhostIOVATree *tree =3D v->shared->iova_tree; DMAMap needle =3D { /* * No need to specify size or to look for more translations since @@ -508,7 +502,7 @@ static int vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v,= void *buf, size_t size, map.translated_addr =3D (hwaddr)(uintptr_t)buf; map.size =3D size - 1; map.perm =3D write ? IOMMU_RW : IOMMU_RO, - r =3D vhost_iova_tree_map_alloc(v->iova_tree, &map); + r =3D vhost_iova_tree_map_alloc(v->shared->iova_tree, &map); if (unlikely(r !=3D IOVA_OK)) { error_report("Cannot map injected element"); return r; @@ -523,7 +517,7 @@ static int vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v,= void *buf, size_t size, return 0; =20 dma_map_err: - vhost_iova_tree_remove(v->iova_tree, map); + vhost_iova_tree_remove(v->shared->iova_tree, map); return r; } =20 @@ -583,24 +577,22 @@ out: return 0; } =20 - if (s0->vhost_vdpa.iova_tree) { - /* - * SVQ is already configured for all virtqueues. Reuse IOVA tree = for - * simplicity, whether CVQ shares ASID with guest or not, because: - * - Memory listener need access to guest's memory addresses alloc= ated - * in the IOVA tree. - * - There should be plenty of IOVA address space for both ASID no= t to - * worry about collisions between them. Guest's translations are - * still validated with virtio virtqueue_pop so there is no risk= for - * the guest to access memory that it shouldn't. - * - * To allocate a iova tree per ASID is doable but it complicates t= he - * code and it is not worth it for the moment. - */ - v->iova_tree =3D s0->vhost_vdpa.iova_tree; - } else { - v->iova_tree =3D vhost_iova_tree_new(v->iova_range.first, - v->iova_range.last); + /* + * If other vhost_vdpa already have an iova_tree, reuse it for simplic= ity, + * whether CVQ shares ASID with guest or not, because: + * - Memory listener need access to guest's memory addresses allocated= in + * the IOVA tree. + * - There should be plenty of IOVA address space for both ASID not to + * worry about collisions between them. Guest's translations are st= ill + * validated with virtio virtqueue_pop so there is no risk for the g= uest + * to access memory that it shouldn't. + * + * To allocate a iova tree per ASID is doable but it complicates the c= ode + * and it is not worth it for the moment. + */ + if (!v->shared->iova_tree) { + v->shared->iova_tree =3D vhost_iova_tree_new(v->iova_range.first, + v->iova_range.last); } =20 r =3D vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, s->cvq_cmd_out_buffer, --=20 2.39.3 From nobody Tue Nov 26 22:42:28 2024 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=1703159657; cv=none; d=zohomail.com; s=zohoarc; b=SIOEZhDi3Cb1j38VmFhBCNqShVnGsyK120AJSlsx4cyDH/RsswpvV3zalUs6CXfPzzcEFZWOX7z3mO+5ZvfzHxj188VR3xqMBPU7emQiYxZjCYBiK6JPPSJZkbXSe1USIuheQj8s7B3SlJ4y5ZWMfkSEMXRmyxqrNiCt4wR7Rvs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703159657; h=Content-Type: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=AJ6EY9+dxb+hUkXtFe3Tj/Ogm+TWyUj2g+fUoYkez98=; b=OEQpNfPuZhtlC56nyhNAP8CSqd2QwzWA3TqgriJy93J2UoC2sOY731aAm/fIYfU2zJtgZ7gbkJWX3Mj8Kxoy+yTvGxLi5cNFh99DFMX4UIPKkvS2Ba+CkD7RkSYEgDvh4EmY3AiA8Ni5GTAldymvze0WUAM79Dx6QiSJZ+EMmHA= 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 170315965749666.01744573198255; Thu, 21 Dec 2023 03:54:17 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGHcQ-00087v-Mf; Thu, 21 Dec 2023 06:53:38 -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 1rGHcO-00087M-JX for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:36 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rGHcM-0007ur-G3 for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:36 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-144-A6RT25RkO1q-HwsNSIpxNg-1; Thu, 21 Dec 2023 06:53:30 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E14E43C000B6; Thu, 21 Dec 2023 11:53:29 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 25C7240C6EB9; Thu, 21 Dec 2023 11:53:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703159613; 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=AJ6EY9+dxb+hUkXtFe3Tj/Ogm+TWyUj2g+fUoYkez98=; b=QvbCe64bZ98jbCUxCIHLLXoNe22zkGc7mhJ41yUI0wyhQ+HT0G78BvPiMo7or6lxa5iDp4 E4/OcMmpIwf0gttmwZ7/eEbMlpXJFirBb6j4IxhyIqfG6vXHfNZDPKgL9h5N2Fxm6bZ7M+ TftD1nxv5xZTScNG3tf5ocsD3VnO1Cc= X-MC-Unique: A6RT25RkO1q-HwsNSIpxNg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Parav Pandit , Dragos Tatulea , Lei Yang , Jason Wang , si-wei.liu@oracle.com, Zhu Lingshan , Stefano Garzarella , "Michael S. Tsirkin" , Laurent Vivier Subject: [PATCH v3 03/14] vdpa: move iova_range to vhost_vdpa_shared Date: Thu, 21 Dec 2023 12:53:08 +0100 Message-Id: <20231221115319.3067586-4-eperezma@redhat.com> In-Reply-To: <20231221115319.3067586-1-eperezma@redhat.com> References: <20231221115319.3067586-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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.133.124; envelope-from=eperezma@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.063, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1703159657694100009 Next patches will register the vhost_vdpa memory listener while the VM is migrating at the destination, so we can map the memory to the device before stopping the VM at the source. The main goal is to reduce the downtime. However, the destination QEMU is unaware of which vhost_vdpa device will register its memory_listener. If the source guest has CVQ enabled, it will be the CVQ device. Otherwise, it will be the first one. Move the iova range to VhostVDPAShared so all vhost_vdpa can use it, rather than always in the first or last vhost_vdpa. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- include/hw/virtio/vhost-vdpa.h | 3 ++- hw/virtio/vdpa-dev.c | 5 ++++- hw/virtio/vhost-vdpa.c | 16 ++++++++++------ net/vhost-vdpa.c | 10 +++++----- 4 files changed, 21 insertions(+), 13 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index ac036055d3..8d52a7e498 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -32,6 +32,8 @@ typedef struct VhostVDPAHostNotifier { =20 /* Info shared by all vhost_vdpa device models */ typedef struct vhost_vdpa_shared { + struct vhost_vdpa_iova_range iova_range; + /* IOVA mapping used by the Shadow Virtqueue */ VhostIOVATree *iova_tree; } VhostVDPAShared; @@ -43,7 +45,6 @@ typedef struct vhost_vdpa { bool iotlb_batch_begin_sent; uint32_t address_space_id; MemoryListener listener; - struct vhost_vdpa_iova_range iova_range; uint64_t acked_features; bool shadow_vqs_enabled; /* Vdpa must send shadow addresses as IOTLB key for data queues, not G= PA */ diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c index f22d5d5bc0..457960d28a 100644 --- a/hw/virtio/vdpa-dev.c +++ b/hw/virtio/vdpa-dev.c @@ -114,7 +114,8 @@ static void vhost_vdpa_device_realize(DeviceState *dev,= Error **errp) strerror(-ret)); goto free_vqs; } - v->vdpa.iova_range =3D iova_range; + v->vdpa.shared =3D g_new0(VhostVDPAShared, 1); + v->vdpa.shared->iova_range =3D iova_range; =20 ret =3D vhost_dev_init(&v->dev, &v->vdpa, VHOST_BACKEND_TYPE_VDPA, 0, = NULL); if (ret < 0) { @@ -162,6 +163,7 @@ vhost_cleanup: vhost_dev_cleanup(&v->dev); free_vqs: g_free(vqs); + g_free(v->vdpa.shared); out: qemu_close(v->vhostfd); v->vhostfd =3D -1; @@ -184,6 +186,7 @@ static void vhost_vdpa_device_unrealize(DeviceState *de= v) g_free(s->config); g_free(s->dev.vqs); vhost_dev_cleanup(&s->dev); + g_free(s->vdpa.shared); qemu_close(s->vhostfd); s->vhostfd =3D -1; } diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 9cee38cb6d..2bceadd118 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -213,10 +213,10 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier= *n, IOMMUTLBEntry *iotlb) RCU_READ_LOCK_GUARD(); /* check if RAM section out of device range */ llend =3D int128_add(int128_makes64(iotlb->addr_mask), int128_makes64(= iova)); - if (int128_gt(llend, int128_make64(v->iova_range.last))) { + if (int128_gt(llend, int128_make64(v->shared->iova_range.last))) { error_report("RAM section out of device range (max=3D0x%" PRIx64 ", end addr=3D0x%" PRIx64 ")", - v->iova_range.last, int128_get64(llend)); + v->shared->iova_range.last, int128_get64(llend)); return; } =20 @@ -316,8 +316,10 @@ static void vhost_vdpa_listener_region_add(MemoryListe= ner *listener, int page_size =3D qemu_target_page_size(); int page_mask =3D -page_size; =20 - if (vhost_vdpa_listener_skipped_section(section, v->iova_range.first, - v->iova_range.last, page_mask)= ) { + if (vhost_vdpa_listener_skipped_section(section, + v->shared->iova_range.first, + v->shared->iova_range.last, + page_mask)) { return; } if (memory_region_is_iommu(section->mr)) { @@ -403,8 +405,10 @@ static void vhost_vdpa_listener_region_del(MemoryListe= ner *listener, int page_size =3D qemu_target_page_size(); int page_mask =3D -page_size; =20 - if (vhost_vdpa_listener_skipped_section(section, v->iova_range.first, - v->iova_range.last, page_mask)= ) { + if (vhost_vdpa_listener_skipped_section(section, + v->shared->iova_range.first, + v->shared->iova_range.last, + page_mask)) { return; } if (memory_region_is_iommu(section->mr)) { diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 10703e5833..7be2c30ad3 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -354,8 +354,8 @@ static void vhost_vdpa_net_data_start_first(VhostVDPASt= ate *s) migration_add_notifier(&s->migration_state, vdpa_net_migration_state_notifier); if (v->shadow_vqs_enabled) { - v->shared->iova_tree =3D vhost_iova_tree_new(v->iova_range.first, - v->iova_range.last); + v->shared->iova_tree =3D vhost_iova_tree_new(v->shared->iova_range= .first, + v->shared->iova_range.l= ast); } } =20 @@ -591,8 +591,8 @@ out: * and it is not worth it for the moment. */ if (!v->shared->iova_tree) { - v->shared->iova_tree =3D vhost_iova_tree_new(v->iova_range.first, - v->iova_range.last); + v->shared->iova_tree =3D vhost_iova_tree_new(v->shared->iova_range= .first, + v->shared->iova_range.l= ast); } =20 r =3D vhost_vdpa_cvq_map_buf(&s->vhost_vdpa, s->cvq_cmd_out_buffer, @@ -1688,12 +1688,12 @@ static NetClientState *net_vhost_vdpa_init(NetClien= tState *peer, s->always_svq =3D svq; s->migration_state.notify =3D NULL; s->vhost_vdpa.shadow_vqs_enabled =3D svq; - s->vhost_vdpa.iova_range =3D iova_range; s->vhost_vdpa.shadow_data =3D svq; if (queue_pair_index =3D=3D 0) { vhost_vdpa_net_valid_svq_features(features, &s->vhost_vdpa.migration_blocker= ); s->vhost_vdpa.shared =3D g_new0(VhostVDPAShared, 1); + s->vhost_vdpa.shared->iova_range =3D iova_range; } else if (!is_datapath) { s->cvq_cmd_out_buffer =3D mmap(NULL, vhost_vdpa_net_cvq_cmd_page_l= en(), PROT_READ | PROT_WRITE, --=20 2.39.3 From nobody Tue Nov 26 22:42:28 2024 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=1703159693; cv=none; d=zohomail.com; s=zohoarc; b=fHcmlgoC7eXsNXdN/o7CB1Zwaen5VHGk4BGYE1BM/OXDOVNcmwT8Q8A5xNUykO7wXgqfcUS6+3ZfakTHe4+LipQxBO6ktDRgTuVpm0mavgEhxKJXx55/y8rry5MsOp6ZvSIhUH9LyTgPWtoeOq6nHt2lCCb4bv2vEMNfTK/Pays= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703159693; h=Content-Type: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=FyxOQUcohfLV3GcvLXt2h1Qk7/Uv5b6Nb+fqdDUkLQ0=; b=PiK4jMQ4DFw7G3djgO+SqMZNZOD7Qg1OGBz1YNF0TZ35OwtVRU4K5NR010qf/DlwLo6BpO4aRQ44oSvmeFHcdZvOYFPc2Gqry/rX0rBZsj/pESyCTKc77EJQYvLypB62gp59yIMKfq/cjGvB0TrdBQJQy+Jrxlw2UhhDYo2QlxA= 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 1703159693265250.04933925071202; Thu, 21 Dec 2023 03:54:53 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGHcf-0008CR-U1; Thu, 21 Dec 2023 06:53:54 -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 1rGHcb-0008BN-Fp for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:50 -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 1rGHcN-0007v5-U1 for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:47 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-eYS7KJ9XOn-h8dolJ9HwlA-1; Thu, 21 Dec 2023 06:53:32 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E305385A58A; Thu, 21 Dec 2023 11:53:31 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2BF3740C6EB9; Thu, 21 Dec 2023 11:53:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703159615; 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=FyxOQUcohfLV3GcvLXt2h1Qk7/Uv5b6Nb+fqdDUkLQ0=; b=Xem10XAiroprNFCqUOMwJ4uZeMD4PTfZQu9TuO6I9m3CRtod3+t2QS6cVYDU4DiOWMHn2t 9IToXODC/iK0AN7JqFo5LvFqCNAm8VYrI3kTFOIoGGUucVA1HKXyF7y497OrbOPvjA6zA+ aUKWu5UKqYn1bVw3td4iNNapN+dlHZg= X-MC-Unique: eYS7KJ9XOn-h8dolJ9HwlA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Parav Pandit , Dragos Tatulea , Lei Yang , Jason Wang , si-wei.liu@oracle.com, Zhu Lingshan , Stefano Garzarella , "Michael S. Tsirkin" , Laurent Vivier Subject: [PATCH v3 04/14] vdpa: move shadow_data to vhost_vdpa_shared Date: Thu, 21 Dec 2023 12:53:09 +0100 Message-Id: <20231221115319.3067586-5-eperezma@redhat.com> In-Reply-To: <20231221115319.3067586-1-eperezma@redhat.com> References: <20231221115319.3067586-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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: -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.063, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1703159693966100005 Next patches will register the vhost_vdpa memory listener while the VM is migrating at the destination, so we can map the memory to the device before stopping the VM at the source. The main goal is to reduce the downtime. However, the destination QEMU is unaware of which vhost_vdpa device will register its memory_listener. If the source guest has CVQ enabled, it will be the CVQ device. Otherwise, it will be the first one. Move the shadow_data member to VhostVDPAShared so all vhost_vdpa can use it, rather than always in the first or last vhost_vdpa. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- v1 from RFC: * Fix vhost_vdpa_net_cvq_start checking for always_svq instead of shadow_data. This could cause CVQ not being shadowed if vhost_vdpa_net_cvq_start was called in the middle of a migration. v2: * Avoid repeated setting shared->shadow_data by squashing Si-Wei's patch [1] [1] https://patchwork.kernel.org/project/qemu-devel/patch/1701970793-6865-1= 0-git-send-email-si-wei.liu@oracle.com/ --- include/hw/virtio/vhost-vdpa.h | 5 +++-- hw/virtio/vhost-vdpa.c | 6 +++--- net/vhost-vdpa.c | 22 +++++----------------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 8d52a7e498..01e0f25e27 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -36,6 +36,9 @@ typedef struct vhost_vdpa_shared { =20 /* IOVA mapping used by the Shadow Virtqueue */ VhostIOVATree *iova_tree; + + /* Vdpa must send shadow addresses as IOTLB key for data queues, not G= PA */ + bool shadow_data; } VhostVDPAShared; =20 typedef struct vhost_vdpa { @@ -47,8 +50,6 @@ typedef struct vhost_vdpa { MemoryListener listener; uint64_t acked_features; bool shadow_vqs_enabled; - /* Vdpa must send shadow addresses as IOTLB key for data queues, not G= PA */ - bool shadow_data; /* Device suspended successfully */ bool suspended; VhostVDPAShared *shared; diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 2bceadd118..ec028e4c56 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -353,7 +353,7 @@ static void vhost_vdpa_listener_region_add(MemoryListen= er *listener, vaddr, section->readonly); =20 llsize =3D int128_sub(llend, int128_make64(iova)); - if (v->shadow_data) { + if (v->shared->shadow_data) { int r; =20 mem_region.translated_addr =3D (hwaddr)(uintptr_t)vaddr, @@ -380,7 +380,7 @@ static void vhost_vdpa_listener_region_add(MemoryListen= er *listener, return; =20 fail_map: - if (v->shadow_data) { + if (v->shared->shadow_data) { vhost_iova_tree_remove(v->shared->iova_tree, mem_region); } =20 @@ -435,7 +435,7 @@ static void vhost_vdpa_listener_region_del(MemoryListen= er *listener, =20 llsize =3D int128_sub(llend, int128_make64(iova)); =20 - if (v->shadow_data) { + if (v->shared->shadow_data) { const DMAMap *result; const void *vaddr =3D memory_region_get_ram_ptr(section->mr) + section->offset_within_region + diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 7be2c30ad3..bf8e8327da 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -290,15 +290,6 @@ static ssize_t vhost_vdpa_receive(NetClientState *nc, = const uint8_t *buf, return size; } =20 -/** From any vdpa net client, get the netclient of the first queue pair */ -static VhostVDPAState *vhost_vdpa_net_first_nc_vdpa(VhostVDPAState *s) -{ - NICState *nic =3D qemu_get_nic(s->nc.peer); - NetClientState *nc0 =3D qemu_get_peer(nic->ncs, 0); - - return DO_UPCAST(VhostVDPAState, nc, nc0); -} - static void vhost_vdpa_net_log_global_enable(VhostVDPAState *s, bool enabl= e) { struct vhost_vdpa *v =3D &s->vhost_vdpa; @@ -369,13 +360,12 @@ static int vhost_vdpa_net_data_start(NetClientState *= nc) if (s->always_svq || migration_is_setup_or_active(migrate_get_current()->state)) { v->shadow_vqs_enabled =3D true; - v->shadow_data =3D true; } else { v->shadow_vqs_enabled =3D false; - v->shadow_data =3D false; } =20 if (v->index =3D=3D 0) { + v->shared->shadow_data =3D v->shadow_vqs_enabled; vhost_vdpa_net_data_start_first(s); return 0; } @@ -523,7 +513,7 @@ dma_map_err: =20 static int vhost_vdpa_net_cvq_start(NetClientState *nc) { - VhostVDPAState *s, *s0; + VhostVDPAState *s; struct vhost_vdpa *v; int64_t cvq_group; int r; @@ -534,12 +524,10 @@ static int vhost_vdpa_net_cvq_start(NetClientState *n= c) s =3D DO_UPCAST(VhostVDPAState, nc, nc); v =3D &s->vhost_vdpa; =20 - s0 =3D vhost_vdpa_net_first_nc_vdpa(s); - v->shadow_data =3D s0->vhost_vdpa.shadow_vqs_enabled; - v->shadow_vqs_enabled =3D s0->vhost_vdpa.shadow_vqs_enabled; + v->shadow_vqs_enabled =3D v->shared->shadow_data; s->vhost_vdpa.address_space_id =3D VHOST_VDPA_GUEST_PA_ASID; =20 - if (s->vhost_vdpa.shadow_data) { + if (v->shared->shadow_data) { /* SVQ is already configured for all virtqueues */ goto out; } @@ -1688,12 +1676,12 @@ static NetClientState *net_vhost_vdpa_init(NetClien= tState *peer, s->always_svq =3D svq; s->migration_state.notify =3D NULL; s->vhost_vdpa.shadow_vqs_enabled =3D svq; - s->vhost_vdpa.shadow_data =3D svq; if (queue_pair_index =3D=3D 0) { vhost_vdpa_net_valid_svq_features(features, &s->vhost_vdpa.migration_blocker= ); s->vhost_vdpa.shared =3D g_new0(VhostVDPAShared, 1); s->vhost_vdpa.shared->iova_range =3D iova_range; + s->vhost_vdpa.shared->shadow_data =3D svq; } else if (!is_datapath) { s->cvq_cmd_out_buffer =3D mmap(NULL, vhost_vdpa_net_cvq_cmd_page_l= en(), PROT_READ | PROT_WRITE, --=20 2.39.3 From nobody Tue Nov 26 22:42:28 2024 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=1703159647; cv=none; d=zohomail.com; s=zohoarc; b=iqKaefYhkM1wlxQEpS8Q68FO5BUYeW/EvD2qxLDKdpMuymS9a/+Dz0oobIZgSsc7dRL7aP2ihfarO2GDB7oeebKWCen8lGeW6lyqc5y68ytdWh+2jEYqTxACb4tl7o+pqu+DoX4KWuAGXhDJNT2JdV2Towmt3qVuLZxkjei35Eo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703159647; h=Content-Type: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=6+QK/N2PZdG4lv35CVCveKrlfGmbDCglKspi37Q1jgc=; b=KUPce5E3keFtG6555TwVQmwgPMQtTI3gkFM4K0aXhZ6siZKb6jaRsdexh/31yk9W8QTMVj6KLnOsJ93NdGs418fF93N3WWzhxjrqMN7br93nA7s8cnRSLPlorLkWojOve2q8hJeUpBEJ3OxX6lF4wx6/OLyhOXjoT/RWEDA/bPI= 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 1703159647093626.4820759829635; Thu, 21 Dec 2023 03:54:07 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGHcT-000895-4X; Thu, 21 Dec 2023 06:53:41 -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 1rGHcS-00088b-8c for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:40 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rGHcQ-0007vp-Ax for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:40 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-166-JTI-fKY0PImyfs2b0IDc0g-1; Thu, 21 Dec 2023 06:53:34 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E990D85A589; Thu, 21 Dec 2023 11:53:33 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2D73440C6E2B; Thu, 21 Dec 2023 11:53:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703159617; 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=6+QK/N2PZdG4lv35CVCveKrlfGmbDCglKspi37Q1jgc=; b=YBXNFpvfV1VsoZn6a+DI978QwTr912m23gNaMe0xrAiAwrCCJIGGqTrjbL+pjQVTP3OLoY RkLgoSVZ1hmLhIVxn7CLyqwUTWOykuel6m40NJbQahk25M0A2luDFQyhqZPN4RXQQZUR4R FTZq3YEQ4bafdcXhBxKG4ucNcFIxmBc= X-MC-Unique: JTI-fKY0PImyfs2b0IDc0g-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Parav Pandit , Dragos Tatulea , Lei Yang , Jason Wang , si-wei.liu@oracle.com, Zhu Lingshan , Stefano Garzarella , "Michael S. Tsirkin" , Laurent Vivier Subject: [PATCH v3 05/14] vdpa: use vdpa shared for tracing Date: Thu, 21 Dec 2023 12:53:10 +0100 Message-Id: <20231221115319.3067586-6-eperezma@redhat.com> In-Reply-To: <20231221115319.3067586-1-eperezma@redhat.com> References: <20231221115319.3067586-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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.133.124; envelope-from=eperezma@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.063, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1703159647661100001 By the end of this series dma_map and dma_unmap functions don't have the vdpa device for tracing. Movinge trace function to shared member one. Print it also in the vdpa initialization so log reader can relate them. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- hw/virtio/vhost-vdpa.c | 26 ++++++++++++++------------ hw/virtio/trace-events | 14 +++++++------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index ec028e4c56..85de60b184 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -101,7 +101,7 @@ int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t a= sid, hwaddr iova, msg.iotlb.perm =3D readonly ? VHOST_ACCESS_RO : VHOST_ACCESS_RW; msg.iotlb.type =3D VHOST_IOTLB_UPDATE; =20 - trace_vhost_vdpa_dma_map(v, fd, msg.type, msg.asid, msg.iotlb.iova, + trace_vhost_vdpa_dma_map(v->shared, fd, msg.type, msg.asid, msg.iotlb.= iova, msg.iotlb.size, msg.iotlb.uaddr, msg.iotlb.pe= rm, msg.iotlb.type); =20 @@ -131,8 +131,8 @@ int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32_t= asid, hwaddr iova, msg.iotlb.size =3D size; msg.iotlb.type =3D VHOST_IOTLB_INVALIDATE; =20 - trace_vhost_vdpa_dma_unmap(v, fd, msg.type, msg.asid, msg.iotlb.iova, - msg.iotlb.size, msg.iotlb.type); + trace_vhost_vdpa_dma_unmap(v->shared, fd, msg.type, msg.asid, + msg.iotlb.iova, msg.iotlb.size, msg.iotlb.t= ype); =20 if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { error_report("failed to write, fd=3D%d, errno=3D%d (%s)", @@ -151,7 +151,8 @@ static void vhost_vdpa_listener_begin_batch(struct vhos= t_vdpa *v) .iotlb.type =3D VHOST_IOTLB_BATCH_BEGIN, }; =20 - trace_vhost_vdpa_listener_begin_batch(v, fd, msg.type, msg.iotlb.type); + trace_vhost_vdpa_listener_begin_batch(v->shared, fd, msg.type, + msg.iotlb.type); if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { error_report("failed to write, fd=3D%d, errno=3D%d (%s)", fd, errno, strerror(errno)); @@ -186,7 +187,7 @@ static void vhost_vdpa_listener_commit(MemoryListener *= listener) msg.type =3D v->msg_type; msg.iotlb.type =3D VHOST_IOTLB_BATCH_END; =20 - trace_vhost_vdpa_listener_commit(v, fd, msg.type, msg.iotlb.type); + trace_vhost_vdpa_listener_commit(v->shared, fd, msg.type, msg.iotlb.ty= pe); if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { error_report("failed to write, fd=3D%d, errno=3D%d (%s)", fd, errno, strerror(errno)); @@ -329,7 +330,8 @@ static void vhost_vdpa_listener_region_add(MemoryListen= er *listener, =20 if (unlikely((section->offset_within_address_space & ~page_mask) !=3D (section->offset_within_region & ~page_mask))) { - trace_vhost_vdpa_listener_region_add_unaligned(v, section->mr->nam= e, + trace_vhost_vdpa_listener_region_add_unaligned(v->shared, + section->mr->name, section->offset_within_address_space & ~page_mask, section->offset_within_region & ~page_mask); return; @@ -349,7 +351,7 @@ static void vhost_vdpa_listener_region_add(MemoryListen= er *listener, section->offset_within_region + (iova - section->offset_within_address_space); =20 - trace_vhost_vdpa_listener_region_add(v, iova, int128_get64(llend), + trace_vhost_vdpa_listener_region_add(v->shared, iova, int128_get64(lle= nd), vaddr, section->readonly); =20 llsize =3D int128_sub(llend, int128_make64(iova)); @@ -417,7 +419,8 @@ static void vhost_vdpa_listener_region_del(MemoryListen= er *listener, =20 if (unlikely((section->offset_within_address_space & ~page_mask) !=3D (section->offset_within_region & ~page_mask))) { - trace_vhost_vdpa_listener_region_del_unaligned(v, section->mr->nam= e, + trace_vhost_vdpa_listener_region_del_unaligned(v->shared, + section->mr->name, section->offset_within_address_space & ~page_mask, section->offset_within_region & ~page_mask); return; @@ -426,7 +429,7 @@ static void vhost_vdpa_listener_region_del(MemoryListen= er *listener, iova =3D ROUND_UP(section->offset_within_address_space, page_size); llend =3D vhost_vdpa_section_end(section, page_mask); =20 - trace_vhost_vdpa_listener_region_del(v, iova, + trace_vhost_vdpa_listener_region_del(v->shared, iova, int128_get64(int128_sub(llend, int128_one()))); =20 if (int128_ge(int128_make64(iova), llend)) { @@ -583,12 +586,11 @@ static void vhost_vdpa_init_svq(struct vhost_dev *hde= v, struct vhost_vdpa *v) =20 static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **er= rp) { - struct vhost_vdpa *v; + struct vhost_vdpa *v =3D opaque; assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); - trace_vhost_vdpa_init(dev, opaque); + trace_vhost_vdpa_init(dev, v->shared, opaque); int ret; =20 - v =3D opaque; v->dev =3D dev; dev->opaque =3D opaque ; v->listener =3D vhost_vdpa_memory_listener; diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 637cac4edf..77905d1994 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -30,16 +30,16 @@ vhost_user_write(uint32_t req, uint32_t flags) "req:%d = flags:0x%"PRIx32"" vhost_user_create_notifier(int idx, void *n) "idx:%d n:%p" =20 # vhost-vdpa.c -vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, u= int64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "v= dpa:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0= x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 -vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid,= uint64_t iova, uint64_t size, uint8_t type) "vdpa:%p fd: %d msg_type: %"PR= Iu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PRIu8 -vhost_vdpa_listener_begin_batch(void *v, int fd, uint32_t msg_type, uint8_= t type) "vdpa:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 -vhost_vdpa_listener_commit(void *v, int fd, uint32_t msg_type, uint8_t typ= e) "vdpa:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 -vhost_vdpa_listener_region_add_unaligned(void *v, const char *name, uint64= _t offset_as, uint64_t offset_page) "vdpa: %p region %s offset_within_addre= ss_space %"PRIu64" offset_within_region %"PRIu64 +vhost_vdpa_dma_map(void *vdpa, int fd, uint32_t msg_type, uint32_t asid, u= int64_t iova, uint64_t size, uint64_t uaddr, uint8_t perm, uint8_t type) "v= dpa_shared:%p fd: %d msg_type: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" = size: 0x%"PRIx64" uaddr: 0x%"PRIx64" perm: 0x%"PRIx8" type: %"PRIu8 +vhost_vdpa_dma_unmap(void *vdpa, int fd, uint32_t msg_type, uint32_t asid,= uint64_t iova, uint64_t size, uint8_t type) "vdpa_shared:%p fd: %d msg_typ= e: %"PRIu32" asid: %"PRIu32" iova: 0x%"PRIx64" size: 0x%"PRIx64" type: %"PR= Iu8 +vhost_vdpa_listener_begin_batch(void *v, int fd, uint32_t msg_type, uint8_= t type) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 +vhost_vdpa_listener_commit(void *v, int fd, uint32_t msg_type, uint8_t typ= e) "vdpa_shared:%p fd: %d msg_type: %"PRIu32" type: %"PRIu8 +vhost_vdpa_listener_region_add_unaligned(void *v, const char *name, uint64= _t offset_as, uint64_t offset_page) "vdpa_shared: %p region %s offset_withi= n_address_space %"PRIu64" offset_within_region %"PRIu64 vhost_vdpa_listener_region_add(void *vdpa, uint64_t iova, uint64_t llend, = void *vaddr, bool readonly) "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64" va= ddr: %p read-only: %d" -vhost_vdpa_listener_region_del_unaligned(void *v, const char *name, uint64= _t offset_as, uint64_t offset_page) "vdpa: %p region %s offset_within_addre= ss_space %"PRIu64" offset_within_region %"PRIu64 +vhost_vdpa_listener_region_del_unaligned(void *v, const char *name, uint64= _t offset_as, uint64_t offset_page) "vdpa_shared: %p region %s offset_withi= n_address_space %"PRIu64" offset_within_region %"PRIu64 vhost_vdpa_listener_region_del(void *vdpa, uint64_t iova, uint64_t llend) = "vdpa: %p iova 0x%"PRIx64" llend 0x%"PRIx64 vhost_vdpa_add_status(void *dev, uint8_t status) "dev: %p status: 0x%"PRIx8 -vhost_vdpa_init(void *dev, void *vdpa) "dev: %p vdpa: %p" +vhost_vdpa_init(void *dev, void *s, void *vdpa) "dev: %p, common dev: %p v= dpa: %p" vhost_vdpa_cleanup(void *dev, void *vdpa) "dev: %p vdpa: %p" vhost_vdpa_memslots_limit(void *dev, int ret) "dev: %p =3D 0x%x" vhost_vdpa_set_mem_table(void *dev, uint32_t nregions, uint32_t padding) "= dev: %p nregions: %"PRIu32" padding: 0x%"PRIx32 --=20 2.39.3 From nobody Tue Nov 26 22:42:28 2024 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=1703159713; cv=none; d=zohomail.com; s=zohoarc; b=Tq2CLUshFgkMud8KNI0lMQ0N5nJWMo4qn8rb5COpaF6lT6H7Rd79PYoduIwetvd4PrzVHUEnIPQcxh8UnKrPiYJi6wteLtttspABww4DZ0SCWaF9+x4YxQqhjV5bJCvjCr+c6uNWT4mH+52mllG271HlfyCjZzzo71g00iaQolM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703159713; h=Content-Type: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=sKw7Lc5dbc3ZhJ80NoSM5i4XA6DsdEMiVfFfx0uDMPU=; b=HC7JFVs9iT+7HkO4V5Grz4LzjzUVezV52RgjMixDykkXDl70YI/SVhTkiJsO9IvlLBdURHNkIpUxDYeXKqubhhLzU1c9oXH7uWRozWr0fJOKiQa0DjCu+WoD1Z/KyG2/6IFoJW7knnTz5BT+wABAwkw1HrMrlabLZVYvbn4vRek= 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 1703159713153151.43239129553785; Thu, 21 Dec 2023 03:55:13 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGHcW-0008AY-GB; Thu, 21 Dec 2023 06:53:44 -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 1rGHcU-0008A3-Sq for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:42 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rGHcS-0007wA-Is for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:42 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-390-qd0qkjR0Ms6OlevgPTL-Xg-1; Thu, 21 Dec 2023 06:53:36 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F0CF61C05EAB; Thu, 21 Dec 2023 11:53:35 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 33DBF40C6EB9; Thu, 21 Dec 2023 11:53:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703159619; 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=sKw7Lc5dbc3ZhJ80NoSM5i4XA6DsdEMiVfFfx0uDMPU=; b=ep1HJzWm7iZrkqAwnphUVcCBGNPiYORZ6C/fD0yFcrIC34Ppi26wxO/8a2QUZ93KxaKHSu Lwz/KId2rmLXYNVCOx74fNOjK1M/HZSaVrHSyBQYeoUDJ+Sor/8DnPALivdV6R2sZpwYDs zxgXfSYfP0eYh2hP3uWY76BLSYxSlGY= X-MC-Unique: qd0qkjR0Ms6OlevgPTL-Xg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Parav Pandit , Dragos Tatulea , Lei Yang , Jason Wang , si-wei.liu@oracle.com, Zhu Lingshan , Stefano Garzarella , "Michael S. Tsirkin" , Laurent Vivier Subject: [PATCH v3 06/14] vdpa: move file descriptor to vhost_vdpa_shared Date: Thu, 21 Dec 2023 12:53:11 +0100 Message-Id: <20231221115319.3067586-7-eperezma@redhat.com> In-Reply-To: <20231221115319.3067586-1-eperezma@redhat.com> References: <20231221115319.3067586-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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.133.124; envelope-from=eperezma@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.063, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1703159714040100001 Next patches will register the vhost_vdpa memory listener while the VM is migrating at the destination, so we can map the memory to the device before stopping the VM at the source. The main goal is to reduce the downtime. However, the destination QEMU is unaware of which vhost_vdpa device will register its memory_listener. If the source guest has CVQ enabled, it will be the CVQ device. Otherwise, it will be the first one. Move the file descriptor to VhostVDPAShared so all vhost_vdpa can use it, rather than always in the first / last vhost_vdpa. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- include/hw/virtio/vhost-vdpa.h | 2 +- hw/virtio/vdpa-dev.c | 2 +- hw/virtio/vhost-vdpa.c | 14 +++++++------- net/vhost-vdpa.c | 11 ++++------- 4 files changed, 13 insertions(+), 16 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 01e0f25e27..796a180afa 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -32,6 +32,7 @@ typedef struct VhostVDPAHostNotifier { =20 /* Info shared by all vhost_vdpa device models */ typedef struct vhost_vdpa_shared { + int device_fd; struct vhost_vdpa_iova_range iova_range; =20 /* IOVA mapping used by the Shadow Virtqueue */ @@ -42,7 +43,6 @@ typedef struct vhost_vdpa_shared { } VhostVDPAShared; =20 typedef struct vhost_vdpa { - int device_fd; int index; uint32_t msg_type; bool iotlb_batch_begin_sent; diff --git a/hw/virtio/vdpa-dev.c b/hw/virtio/vdpa-dev.c index 457960d28a..8774986571 100644 --- a/hw/virtio/vdpa-dev.c +++ b/hw/virtio/vdpa-dev.c @@ -66,7 +66,6 @@ static void vhost_vdpa_device_realize(DeviceState *dev, E= rror **errp) if (*errp) { return; } - v->vdpa.device_fd =3D v->vhostfd; =20 v->vdev_id =3D vhost_vdpa_device_get_u32(v->vhostfd, VHOST_VDPA_GET_DEVICE_ID, errp); @@ -115,6 +114,7 @@ static void vhost_vdpa_device_realize(DeviceState *dev,= Error **errp) goto free_vqs; } v->vdpa.shared =3D g_new0(VhostVDPAShared, 1); + v->vdpa.shared->device_fd =3D v->vhostfd; v->vdpa.shared->iova_range =3D iova_range; =20 ret =3D vhost_dev_init(&v->dev, &v->vdpa, VHOST_BACKEND_TYPE_VDPA, 0, = NULL); diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 85de60b184..095543395b 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -90,7 +90,7 @@ int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asi= d, hwaddr iova, hwaddr size, void *vaddr, bool readonly) { struct vhost_msg_v2 msg =3D {}; - int fd =3D v->device_fd; + int fd =3D v->shared->device_fd; int ret =3D 0; =20 msg.type =3D v->msg_type; @@ -122,7 +122,7 @@ int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32_t= asid, hwaddr iova, hwaddr size) { struct vhost_msg_v2 msg =3D {}; - int fd =3D v->device_fd; + int fd =3D v->shared->device_fd; int ret =3D 0; =20 msg.type =3D v->msg_type; @@ -145,7 +145,7 @@ int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32_t= asid, hwaddr iova, =20 static void vhost_vdpa_listener_begin_batch(struct vhost_vdpa *v) { - int fd =3D v->device_fd; + int fd =3D v->shared->device_fd; struct vhost_msg_v2 msg =3D { .type =3D v->msg_type, .iotlb.type =3D VHOST_IOTLB_BATCH_BEGIN, @@ -174,7 +174,7 @@ static void vhost_vdpa_listener_commit(MemoryListener *= listener) struct vhost_vdpa *v =3D container_of(listener, struct vhost_vdpa, lis= tener); struct vhost_dev *dev =3D v->dev; struct vhost_msg_v2 msg =3D {}; - int fd =3D v->device_fd; + int fd =3D v->shared->device_fd; =20 if (!(dev->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH))) { return; @@ -499,7 +499,7 @@ static int vhost_vdpa_call(struct vhost_dev *dev, unsig= ned long int request, void *arg) { struct vhost_vdpa *v =3D dev->opaque; - int fd =3D v->device_fd; + int fd =3D v->shared->device_fd; int ret; =20 assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); @@ -657,7 +657,7 @@ static int vhost_vdpa_host_notifier_init(struct vhost_d= ev *dev, int queue_index) struct vhost_vdpa *v =3D dev->opaque; VirtIODevice *vdev =3D dev->vdev; VhostVDPAHostNotifier *n; - int fd =3D v->device_fd; + int fd =3D v->shared->device_fd; void *addr; char *name; =20 @@ -1286,7 +1286,7 @@ static void vhost_vdpa_suspend(struct vhost_dev *dev) =20 if (dev->backend_cap & BIT_ULL(VHOST_BACKEND_F_SUSPEND)) { trace_vhost_vdpa_suspend(dev); - r =3D ioctl(v->device_fd, VHOST_VDPA_SUSPEND); + r =3D ioctl(v->shared->device_fd, VHOST_VDPA_SUSPEND); if (unlikely(r)) { error_report("Cannot suspend: %s(%d)", g_strerror(errno), errn= o); } else { diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index bf8e8327da..10cf0027de 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -235,14 +235,11 @@ static void vhost_vdpa_cleanup(NetClientState *nc) vhost_net_cleanup(s->vhost_net); g_free(s->vhost_net); s->vhost_net =3D NULL; - } - if (s->vhost_vdpa.device_fd >=3D 0) { - qemu_close(s->vhost_vdpa.device_fd); - s->vhost_vdpa.device_fd =3D -1; } if (s->vhost_vdpa.index !=3D 0) { return; } + qemu_close(s->vhost_vdpa.shared->device_fd); g_free(s->vhost_vdpa.shared); } =20 @@ -448,7 +445,7 @@ static int vhost_vdpa_set_address_space_id(struct vhost= _vdpa *v, }; int r; =20 - r =3D ioctl(v->device_fd, VHOST_VDPA_SET_GROUP_ASID, &asid); + r =3D ioctl(v->shared->device_fd, VHOST_VDPA_SET_GROUP_ASID, &asid); if (unlikely(r < 0)) { error_report("Can't set vq group %u asid %u, errno=3D%d (%s)", asid.index, asid.num, errno, g_strerror(errno)); @@ -544,7 +541,7 @@ static int vhost_vdpa_net_cvq_start(NetClientState *nc) return 0; } =20 - cvq_group =3D vhost_vdpa_get_vring_group(v->device_fd, + cvq_group =3D vhost_vdpa_get_vring_group(v->shared->device_fd, v->dev->vq_index_end - 1, &err); if (unlikely(cvq_group < 0)) { @@ -1671,7 +1668,6 @@ static NetClientState *net_vhost_vdpa_init(NetClientS= tate *peer, qemu_set_info_str(nc, TYPE_VHOST_VDPA); s =3D DO_UPCAST(VhostVDPAState, nc, nc); =20 - s->vhost_vdpa.device_fd =3D vdpa_device_fd; s->vhost_vdpa.index =3D queue_pair_index; s->always_svq =3D svq; s->migration_state.notify =3D NULL; @@ -1680,6 +1676,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientS= tate *peer, vhost_vdpa_net_valid_svq_features(features, &s->vhost_vdpa.migration_blocker= ); s->vhost_vdpa.shared =3D g_new0(VhostVDPAShared, 1); + s->vhost_vdpa.shared->device_fd =3D vdpa_device_fd; s->vhost_vdpa.shared->iova_range =3D iova_range; s->vhost_vdpa.shared->shadow_data =3D svq; } else if (!is_datapath) { --=20 2.39.3 From nobody Tue Nov 26 22:42:28 2024 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=1703159660; cv=none; d=zohomail.com; s=zohoarc; b=XgX7M7vgkX5pWS4AGtLq20zGE1+xRV8wckJHCawaqUupuAn4sLDRhGnr1qvyRgN9DRIhqh4jSzd/vO4YOgyWTmPGW8YtV3+rGFwJlKH0dFgwCzfQKfdBbZGbEoKvPK5Ve+RcM68xoLzBCOcr4Lv3R3dE5lccSQ9dQdj24szgavs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703159660; h=Content-Type: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=5U4m8fIAMN0n6WTo/QLzpZYbobkarUjTFlCLBwhwyvM=; b=ZiFqXKAe0nrFrX8bxZYW02n2FGzOC2D5Jp1S0JePjpHkNxw4Ttu2x6yTtmN1srP3BEHS6qA7bw39ZdIgPDt8PQc7UvFG9RBkrhbg+2CTGf7RjAfiZWdnLZTEwxgn4GabXnBo/89YKG0B+7S4JvhduBW2inlnpLZlqWu3wOaEHjE= 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 1703159660452978.2611996085451; Thu, 21 Dec 2023 03:54:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGHcZ-0008B3-65; Thu, 21 Dec 2023 06:53:47 -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 1rGHcX-0008Aj-Jz for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:45 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rGHcW-0007wq-2q for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:45 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-450-rxiGqkDwNVWthv_5ukcFSg-1; Thu, 21 Dec 2023 06:53:38 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id F1E833C000AD; Thu, 21 Dec 2023 11:53:37 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3B84A40C6EB9; Thu, 21 Dec 2023 11:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703159623; 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=5U4m8fIAMN0n6WTo/QLzpZYbobkarUjTFlCLBwhwyvM=; b=AU8ePvztTucQPNr7HG42Cnt8AWJTznn74aQf/ce6N9wvikvNkzzRpwWO2b+oDRBjJIUrhc x4GeV6TXgCt5YsGhCEyjxrHUF6ka1UCzX0u+8vPoTdKB/tlcDHDr/En3bEqzbDQGi6dTg0 9jBAHL1hPjAAIPJpAedPW2NF04LJrpg= X-MC-Unique: rxiGqkDwNVWthv_5ukcFSg-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Parav Pandit , Dragos Tatulea , Lei Yang , Jason Wang , si-wei.liu@oracle.com, Zhu Lingshan , Stefano Garzarella , "Michael S. Tsirkin" , Laurent Vivier Subject: [PATCH v3 07/14] vdpa: move iotlb_batch_begin_sent to vhost_vdpa_shared Date: Thu, 21 Dec 2023 12:53:12 +0100 Message-Id: <20231221115319.3067586-8-eperezma@redhat.com> In-Reply-To: <20231221115319.3067586-1-eperezma@redhat.com> References: <20231221115319.3067586-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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.133.124; envelope-from=eperezma@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.063, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1703159661726100003 Next patches will register the vhost_vdpa memory listener while the VM is migrating at the destination, so we can map the memory to the device before stopping the VM at the source. The main goal is to reduce the downtime. However, the destination QEMU is unaware of which vhost_vdpa device will register its memory_listener. If the source guest has CVQ enabled, it will be the CVQ device. Otherwise, it will be the first one. Move the iotlb_batch_begin_sent member to VhostVDPAShared so all vhost_vdpa can use it, rather than always in the first / last vhost_vdpa. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- include/hw/virtio/vhost-vdpa.h | 3 ++- hw/virtio/vhost-vdpa.c | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 796a180afa..05219bbcf7 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -38,6 +38,8 @@ typedef struct vhost_vdpa_shared { /* IOVA mapping used by the Shadow Virtqueue */ VhostIOVATree *iova_tree; =20 + bool iotlb_batch_begin_sent; + /* Vdpa must send shadow addresses as IOTLB key for data queues, not G= PA */ bool shadow_data; } VhostVDPAShared; @@ -45,7 +47,6 @@ typedef struct vhost_vdpa_shared { typedef struct vhost_vdpa { int index; uint32_t msg_type; - bool iotlb_batch_begin_sent; uint32_t address_space_id; MemoryListener listener; uint64_t acked_features; diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 095543395b..85b13e09f4 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -162,11 +162,11 @@ static void vhost_vdpa_listener_begin_batch(struct vh= ost_vdpa *v) static void vhost_vdpa_iotlb_batch_begin_once(struct vhost_vdpa *v) { if (v->dev->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH) && - !v->iotlb_batch_begin_sent) { + !v->shared->iotlb_batch_begin_sent) { vhost_vdpa_listener_begin_batch(v); } =20 - v->iotlb_batch_begin_sent =3D true; + v->shared->iotlb_batch_begin_sent =3D true; } =20 static void vhost_vdpa_listener_commit(MemoryListener *listener) @@ -180,7 +180,7 @@ static void vhost_vdpa_listener_commit(MemoryListener *= listener) return; } =20 - if (!v->iotlb_batch_begin_sent) { + if (!v->shared->iotlb_batch_begin_sent) { return; } =20 @@ -193,7 +193,7 @@ static void vhost_vdpa_listener_commit(MemoryListener *= listener) fd, errno, strerror(errno)); } =20 - v->iotlb_batch_begin_sent =3D false; + v->shared->iotlb_batch_begin_sent =3D false; } =20 static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *i= otlb) --=20 2.39.3 From nobody Tue Nov 26 22:42:28 2024 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=1703159742; cv=none; d=zohomail.com; s=zohoarc; b=MRCHYF5520NucJGauKzPmJkie+VT0oLb5YR9SWBfHj/weeyTXDk+OOAm2BpN1cyZ+U7xEZQJ1APaeYDde9oNDZEoSAfb26pJjOa3vEuCnPKiaXRwagffIpWKJB5q1WMVXqbK4XB05N9fjYlvgx/nKD6+BA3cBgaR3o6jjhobCdc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703159742; h=Content-Type: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=X1DbYgqk7ziG6yx4zIVFuyjJx5NuNdzxtgur0I7rsm0=; b=gpDSggkpc3Tp9YasAsSdPCvGUZuI+rU8fOr1Itbco5yghOTQ566ut5WsHe8LIdSk0lwHO+NKU7dMqzU2xIgFv1M2ZHGbha5DB0pGgHG4/73VSgv58S8/XKmCVqIvkid33ws5EwxeWeelvdQX3GUUFGyB6t5Zmxpbcc2NHsfpAG4= 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 1703159742512659.3807686831061; Thu, 21 Dec 2023 03:55:42 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGHch-0008DI-ES; Thu, 21 Dec 2023 06:53:55 -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 1rGHcb-0008BM-Fu for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:50 -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 1rGHcY-0007x6-B2 for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:47 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-139-thVNTv3-PxKpUxE4zjMSFA-1; Thu, 21 Dec 2023 06:53:40 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 011EA2806041; Thu, 21 Dec 2023 11:53:40 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E20A40C6EB9; Thu, 21 Dec 2023 11:53:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703159625; 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=X1DbYgqk7ziG6yx4zIVFuyjJx5NuNdzxtgur0I7rsm0=; b=GhOib7XYAcSXEUorAV9gvO+skEhvDh9b8f6tuW6OcVMDzvLxd1AHgmkWZnZL8APdYriWza kGSFWwJf85NDV7J/OHB6jfyY8/YM9FAVnjfRvT+nD3SjHUBv54DNeq+eI2c/SHkT2Q6Ui9 fRIEd3flVN3pe/olFWgzDLvqiLhC4PE= X-MC-Unique: thVNTv3-PxKpUxE4zjMSFA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Parav Pandit , Dragos Tatulea , Lei Yang , Jason Wang , si-wei.liu@oracle.com, Zhu Lingshan , Stefano Garzarella , "Michael S. Tsirkin" , Laurent Vivier Subject: [PATCH v3 08/14] vdpa: move backend_cap to vhost_vdpa_shared Date: Thu, 21 Dec 2023 12:53:13 +0100 Message-Id: <20231221115319.3067586-9-eperezma@redhat.com> In-Reply-To: <20231221115319.3067586-1-eperezma@redhat.com> References: <20231221115319.3067586-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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: -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.063, 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_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1703159744150100003 Next patches will register the vhost_vdpa memory listener while the VM is migrating at the destination, so we can map the memory to the device before stopping the VM at the source. The main goal is to reduce the downtime. However, the destination QEMU is unaware of which vhost_vdpa device will register its memory_listener. If the source guest has CVQ enabled, it will be the CVQ device. Otherwise, it will be the first one. Move the backend_cap member to VhostVDPAShared so all vhost_vdpa can use it, rather than always in the first / last vhost_vdpa. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- include/hw/virtio/vhost-vdpa.h | 3 +++ hw/virtio/vhost-vdpa.c | 8 +++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 05219bbcf7..11ac14085a 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -38,6 +38,9 @@ typedef struct vhost_vdpa_shared { /* IOVA mapping used by the Shadow Virtqueue */ VhostIOVATree *iova_tree; =20 + /* Copy of backend features */ + uint64_t backend_cap; + bool iotlb_batch_begin_sent; =20 /* Vdpa must send shadow addresses as IOTLB key for data queues, not G= PA */ diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 85b13e09f4..458e46befd 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -161,7 +161,7 @@ static void vhost_vdpa_listener_begin_batch(struct vhos= t_vdpa *v) =20 static void vhost_vdpa_iotlb_batch_begin_once(struct vhost_vdpa *v) { - if (v->dev->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH) && + if (v->shared->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH) && !v->shared->iotlb_batch_begin_sent) { vhost_vdpa_listener_begin_batch(v); } @@ -172,11 +172,10 @@ static void vhost_vdpa_iotlb_batch_begin_once(struct = vhost_vdpa *v) static void vhost_vdpa_listener_commit(MemoryListener *listener) { struct vhost_vdpa *v =3D container_of(listener, struct vhost_vdpa, lis= tener); - struct vhost_dev *dev =3D v->dev; struct vhost_msg_v2 msg =3D {}; int fd =3D v->shared->device_fd; =20 - if (!(dev->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH))) { + if (!(v->shared->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH)= )) { return; } =20 @@ -834,6 +833,8 @@ static int vhost_vdpa_set_features(struct vhost_dev *de= v, =20 static int vhost_vdpa_set_backend_cap(struct vhost_dev *dev) { + struct vhost_vdpa *v =3D dev->opaque; + uint64_t features; uint64_t f =3D 0x1ULL << VHOST_BACKEND_F_IOTLB_MSG_V2 | 0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH | @@ -855,6 +856,7 @@ static int vhost_vdpa_set_backend_cap(struct vhost_dev = *dev) } =20 dev->backend_cap =3D features; + v->shared->backend_cap =3D features; =20 return 0; } --=20 2.39.3 From nobody Tue Nov 26 22:42:28 2024 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=1703159757; cv=none; d=zohomail.com; s=zohoarc; b=nVOSHfqOutd9MGqZNxCBrpirf6tAapgkWNkCW2C3StUPssnIwNDomK+xm8QhAexuFISe8mtVE9rz3PZhYGOGnGRolkgCGPvkOhLhn6SuUMceKid/lUPsQ4F3By0EUdinl8EszHg3tymTJKjWo8sKyx0oLZTgatD2KIsM9vWejVw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703159757; h=Content-Type: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=wEqxCxIU4wEiF1ZxDcemsg37cDOuCjoWmO0/s/NRmkQ=; b=G7KS3ooGuMQe4/35opHDhO66PVcuw0KzF/wG7VNPoQBZ68+AtW4cb3PUyTEE9xacBbgVHTJLHJKG3kiX0q05wHpKYAB7KDdlmMRnEkvUi0CSlae6MM7gF9JzM3qL8ZoOOzem3KKgSUnvUrG0BaSomV5pTvyFppyIex2lVMIh8H0= 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 1703159757840194.9661695896766; Thu, 21 Dec 2023 03:55:57 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGHch-0008DD-A9; Thu, 21 Dec 2023 06:53:55 -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 1rGHcb-0008BO-HI for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:50 -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 1rGHcY-0007x9-HT for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:47 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-269-3sHyjAZyPUSCOUY97mZLxw-1; Thu, 21 Dec 2023 06:53:42 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 03443185A780; Thu, 21 Dec 2023 11:53:42 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4130E40C6EB9; Thu, 21 Dec 2023 11:53:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703159625; 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=wEqxCxIU4wEiF1ZxDcemsg37cDOuCjoWmO0/s/NRmkQ=; b=XHsovZ73CeagAFAra6X0dUAgjzKP3wKjSjvXptFxS/L2gohY/VlhrT/kvb18WtrUBYeXJX uKrU3Kr654LsKa36/jve7IY6Nw5ac4mOs46YV48JLqm7pcmHyDaOBIAlOGO82f9p+tlcCH 8EeQJN/hNWLGbtqMkVDowMrrigMo9W4= X-MC-Unique: 3sHyjAZyPUSCOUY97mZLxw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Parav Pandit , Dragos Tatulea , Lei Yang , Jason Wang , si-wei.liu@oracle.com, Zhu Lingshan , Stefano Garzarella , "Michael S. Tsirkin" , Laurent Vivier Subject: [PATCH v3 09/14] vdpa: remove msg type of vhost_vdpa Date: Thu, 21 Dec 2023 12:53:14 +0100 Message-Id: <20231221115319.3067586-10-eperezma@redhat.com> In-Reply-To: <20231221115319.3067586-1-eperezma@redhat.com> References: <20231221115319.3067586-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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: -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.063, 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_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1703159758262100001 It is always VHOST_IOTLB_MSG_V2. We can always make it back per vhost_dev if needed. This change makes easier for vhost_vdpa_map and unmap not to depend on vhost_vdpa but only in VhostVDPAShared. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- include/hw/virtio/vhost-vdpa.h | 1 - hw/virtio/vhost-vdpa.c | 9 ++++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 11ac14085a..5bd964dac5 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -49,7 +49,6 @@ typedef struct vhost_vdpa_shared { =20 typedef struct vhost_vdpa { int index; - uint32_t msg_type; uint32_t address_space_id; MemoryListener listener; uint64_t acked_features; diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 458e46befd..38afcbf1c9 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -93,7 +93,7 @@ int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asi= d, hwaddr iova, int fd =3D v->shared->device_fd; int ret =3D 0; =20 - msg.type =3D v->msg_type; + msg.type =3D VHOST_IOTLB_MSG_V2; msg.asid =3D asid; msg.iotlb.iova =3D iova; msg.iotlb.size =3D size; @@ -125,7 +125,7 @@ int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32_t= asid, hwaddr iova, int fd =3D v->shared->device_fd; int ret =3D 0; =20 - msg.type =3D v->msg_type; + msg.type =3D VHOST_IOTLB_MSG_V2; msg.asid =3D asid; msg.iotlb.iova =3D iova; msg.iotlb.size =3D size; @@ -147,7 +147,7 @@ static void vhost_vdpa_listener_begin_batch(struct vhos= t_vdpa *v) { int fd =3D v->shared->device_fd; struct vhost_msg_v2 msg =3D { - .type =3D v->msg_type, + .type =3D VHOST_IOTLB_MSG_V2, .iotlb.type =3D VHOST_IOTLB_BATCH_BEGIN, }; =20 @@ -183,7 +183,7 @@ static void vhost_vdpa_listener_commit(MemoryListener *= listener) return; } =20 - msg.type =3D v->msg_type; + msg.type =3D VHOST_IOTLB_MSG_V2; msg.iotlb.type =3D VHOST_IOTLB_BATCH_END; =20 trace_vhost_vdpa_listener_commit(v->shared, fd, msg.type, msg.iotlb.ty= pe); @@ -593,7 +593,6 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void = *opaque, Error **errp) v->dev =3D dev; dev->opaque =3D opaque ; v->listener =3D vhost_vdpa_memory_listener; - v->msg_type =3D VHOST_IOTLB_MSG_V2; vhost_vdpa_init_svq(dev, v); =20 error_propagate(&dev->migration_blocker, v->migration_blocker); --=20 2.39.3 From nobody Tue Nov 26 22:42:28 2024 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=1703159654; cv=none; d=zohomail.com; s=zohoarc; b=Y/NzknvFkOADs4dbQbkMPXe78ViXCrZbSQUq5ZdDaIJYiu/QRwmw8Yqs/hnG8YosqVCjsd0M3eb2nSu9mTJQ+B8WumPO9EpmSymCHpKPe2zEKrnN36UFKDy3tPmKeRiQSklvob6SoxHVPkb9C/PQF+d/KbWRJTJcixrNZTPwrQY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703159654; h=Content-Type: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=tmPzHpJ7J2BnbFMyirhJkM/dBrBacMx6b4xylXe8QsI=; b=l4R6d/GJ3TmaY67p6/teli7DctxTrQGigrwf4LWeOg8mon2UHbhEgHrT1kf1NeaMnID0bJz0sFP60e2rXc0PmsT6m4eaBFYA30dCudQgWZdE2Jkcof4LFBloZzpOXW3qIWr8TTNLh2Y+L/do5K/ocOj4agorKcz1gUcvxMU3U1g= 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 17031596548091.9164094821298931; Thu, 21 Dec 2023 03:54:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGHcg-0008D7-Oy; Thu, 21 Dec 2023 06:53:54 -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 1rGHcb-0008BS-R5 for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:50 -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 1rGHca-0007xR-8i for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:49 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-363-Ym5jm0Q6PfOikSY0l7-3JA-1; Thu, 21 Dec 2023 06:53:45 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DACD13816B4B; Thu, 21 Dec 2023 11:53:44 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 423C440C6EB9; Thu, 21 Dec 2023 11:53:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703159626; 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=tmPzHpJ7J2BnbFMyirhJkM/dBrBacMx6b4xylXe8QsI=; b=J9CX7u0zYN6hdv1I8ppfmSHfLSG/prWAiArOkEgNteXKttgw6ivXvNl3jbOeUhW+lF7M88 D04Ex1Q2K7l7l77qupAQBjxn7VoN04dct7dv4CTZD3FpkFMjjhAF19VBBqkQ5cBEFkN4di paZGZhYn0zoXh5uXUS/xZ3I1cBRBQOk= X-MC-Unique: Ym5jm0Q6PfOikSY0l7-3JA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Parav Pandit , Dragos Tatulea , Lei Yang , Jason Wang , si-wei.liu@oracle.com, Zhu Lingshan , Stefano Garzarella , "Michael S. Tsirkin" , Laurent Vivier Subject: [PATCH v3 10/14] vdpa: move iommu_list to vhost_vdpa_shared Date: Thu, 21 Dec 2023 12:53:15 +0100 Message-Id: <20231221115319.3067586-11-eperezma@redhat.com> In-Reply-To: <20231221115319.3067586-1-eperezma@redhat.com> References: <20231221115319.3067586-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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: -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.063, 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_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1703159655681100006 Next patches will register the vhost_vdpa memory listener while the VM is migrating at the destination, so we can map the memory to the device before stopping the VM at the source. The main goal is to reduce the downtime. However, the destination QEMU is unaware of which vhost_vdpa device will register its memory_listener. If the source guest has CVQ enabled, it will be the CVQ device. Otherwise, it will be the first one. Move the iommu_list member to VhostVDPAShared so all vhost_vdpa can use it, rather than always in the first / last vhost_vdpa. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- include/hw/virtio/vhost-vdpa.h | 2 +- hw/virtio/vhost-vdpa.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 5bd964dac5..3880b9e7f2 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -34,6 +34,7 @@ typedef struct VhostVDPAHostNotifier { typedef struct vhost_vdpa_shared { int device_fd; struct vhost_vdpa_iova_range iova_range; + QLIST_HEAD(, vdpa_iommu) iommu_list; =20 /* IOVA mapping used by the Shadow Virtqueue */ VhostIOVATree *iova_tree; @@ -62,7 +63,6 @@ typedef struct vhost_vdpa { struct vhost_dev *dev; Error *migration_blocker; VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; - QLIST_HEAD(, vdpa_iommu) iommu_list; IOMMUNotifier n; } VhostVDPA; =20 diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 38afcbf1c9..a07cd85081 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -279,7 +279,7 @@ static void vhost_vdpa_iommu_region_add(MemoryListener = *listener, return; } =20 - QLIST_INSERT_HEAD(&v->iommu_list, iommu, iommu_next); + QLIST_INSERT_HEAD(&v->shared->iommu_list, iommu, iommu_next); memory_region_iommu_replay(iommu->iommu_mr, &iommu->n); =20 return; @@ -292,7 +292,7 @@ static void vhost_vdpa_iommu_region_del(MemoryListener = *listener, =20 struct vdpa_iommu *iommu; =20 - QLIST_FOREACH(iommu, &v->iommu_list, iommu_next) + QLIST_FOREACH(iommu, &v->shared->iommu_list, iommu_next) { if (MEMORY_REGION(iommu->iommu_mr) =3D=3D section->mr && iommu->n.start =3D=3D section->offset_within_region) { --=20 2.39.3 From nobody Tue Nov 26 22:42:28 2024 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=1703159730; cv=none; d=zohomail.com; s=zohoarc; b=bOcNHCy9fmShtJ8vDlccVsOydnNgERU2+i/YVoEs1GpprAqEQUZGCLqESEVOBDHPmQ927+LP1kyBfqh0lTlTJmEEgtDrPgUzcfr2lwtUfPAc1h+Zug494SgyV7krsVmu5dc4y/QzPwCJ4z4x1Fb+ju2TaAdi75BfX+LAlfvgfm4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703159730; h=Content-Type: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=AOJdU7+LTCbcIbFGhWsioiLCcidyY/foJ+x5Lc4jyQ4=; b=bU5ByKHuV2dZ92FTci8KOtrGCLalmMVM++XZjb6Sp+QpeApaYCOPJJIJ9aSICtMOJ7i+lxK0fBj5s+uYwg09c7EUvVGPikaGvYkmibQGc2zlSqU1ftPTKJwWoPCN+lffp7fd6YoMexcQ21q8Tb0tv3OO2lqnewacaZd1UZ/5vjQ= 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 1703159730164925.231533698918; Thu, 21 Dec 2023 03:55:30 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGHch-0008DW-OO; Thu, 21 Dec 2023 06:53:55 -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 1rGHcg-0008CW-3J for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:54 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rGHce-0007zh-7h for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:53 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-368-nY3O--cCMi2pCI2fMe-fSw-1; Thu, 21 Dec 2023 06:53:48 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 30397101A555; Thu, 21 Dec 2023 11:53:48 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6C14440C6EB9; Thu, 21 Dec 2023 11:53:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703159631; 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=AOJdU7+LTCbcIbFGhWsioiLCcidyY/foJ+x5Lc4jyQ4=; b=Ys/6E/uA5R1l9bJR1aEPuxTWxxbTNaUb6BrUi9QS4Aol2yi81jkLbZxi1odeo3n48oeuAr 5edlVZqprc6bjBbOJ4RpNYi6BDv7gLbYSSuGEFbmun5bfNPlHV2AO/r4eOh4UMA4rJG320 VenbSJXylabtQlvneExP4G1SrKuvovo= X-MC-Unique: nY3O--cCMi2pCI2fMe-fSw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Parav Pandit , Dragos Tatulea , Lei Yang , Jason Wang , si-wei.liu@oracle.com, Zhu Lingshan , Stefano Garzarella , "Michael S. Tsirkin" , Laurent Vivier Subject: [PATCH v3 11/14] vdpa: use VhostVDPAShared in vdpa_dma_map and unmap Date: Thu, 21 Dec 2023 12:53:16 +0100 Message-Id: <20231221115319.3067586-12-eperezma@redhat.com> In-Reply-To: <20231221115319.3067586-1-eperezma@redhat.com> References: <20231221115319.3067586-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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.133.124; envelope-from=eperezma@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.063, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1703159732165100003 The callers only have the shared information by the end of this series. Start converting this functions. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- include/hw/virtio/vhost-vdpa.h | 4 +-- hw/virtio/vhost-vdpa.c | 50 +++++++++++++++++----------------- net/vhost-vdpa.c | 5 ++-- 3 files changed, 30 insertions(+), 29 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 3880b9e7f2..705c754776 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -69,9 +69,9 @@ typedef struct vhost_vdpa { int vhost_vdpa_get_iova_range(int fd, struct vhost_vdpa_iova_range *iova_r= ange); int vhost_vdpa_set_vring_ready(struct vhost_vdpa *v, unsigned idx); =20 -int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, +int vhost_vdpa_dma_map(VhostVDPAShared *s, uint32_t asid, hwaddr iova, hwaddr size, void *vaddr, bool readonly); -int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, +int vhost_vdpa_dma_unmap(VhostVDPAShared *s, uint32_t asid, hwaddr iova, hwaddr size); =20 typedef struct vdpa_iommu { diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index a07cd85081..0ed6550aad 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -86,11 +86,11 @@ static bool vhost_vdpa_listener_skipped_section(MemoryR= egionSection *section, * The caller must set asid =3D 0 if the device does not support asid. * This is not an ABI break since it is set to 0 by the initializer anyway. */ -int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, +int vhost_vdpa_dma_map(VhostVDPAShared *s, uint32_t asid, hwaddr iova, hwaddr size, void *vaddr, bool readonly) { struct vhost_msg_v2 msg =3D {}; - int fd =3D v->shared->device_fd; + int fd =3D s->device_fd; int ret =3D 0; =20 msg.type =3D VHOST_IOTLB_MSG_V2; @@ -101,7 +101,7 @@ int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t a= sid, hwaddr iova, msg.iotlb.perm =3D readonly ? VHOST_ACCESS_RO : VHOST_ACCESS_RW; msg.iotlb.type =3D VHOST_IOTLB_UPDATE; =20 - trace_vhost_vdpa_dma_map(v->shared, fd, msg.type, msg.asid, msg.iotlb.= iova, + trace_vhost_vdpa_dma_map(s, fd, msg.type, msg.asid, msg.iotlb.iova, msg.iotlb.size, msg.iotlb.uaddr, msg.iotlb.pe= rm, msg.iotlb.type); =20 @@ -118,11 +118,11 @@ int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t= asid, hwaddr iova, * The caller must set asid =3D 0 if the device does not support asid. * This is not an ABI break since it is set to 0 by the initializer anyway. */ -int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, +int vhost_vdpa_dma_unmap(VhostVDPAShared *s, uint32_t asid, hwaddr iova, hwaddr size) { struct vhost_msg_v2 msg =3D {}; - int fd =3D v->shared->device_fd; + int fd =3D s->device_fd; int ret =3D 0; =20 msg.type =3D VHOST_IOTLB_MSG_V2; @@ -131,8 +131,8 @@ int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32_t= asid, hwaddr iova, msg.iotlb.size =3D size; msg.iotlb.type =3D VHOST_IOTLB_INVALIDATE; =20 - trace_vhost_vdpa_dma_unmap(v->shared, fd, msg.type, msg.asid, - msg.iotlb.iova, msg.iotlb.size, msg.iotlb.t= ype); + trace_vhost_vdpa_dma_unmap(s, fd, msg.type, msg.asid, msg.iotlb.iova, + msg.iotlb.size, msg.iotlb.type); =20 if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { error_report("failed to write, fd=3D%d, errno=3D%d (%s)", @@ -143,30 +143,29 @@ int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32= _t asid, hwaddr iova, return ret; } =20 -static void vhost_vdpa_listener_begin_batch(struct vhost_vdpa *v) +static void vhost_vdpa_listener_begin_batch(VhostVDPAShared *s) { - int fd =3D v->shared->device_fd; + int fd =3D s->device_fd; struct vhost_msg_v2 msg =3D { .type =3D VHOST_IOTLB_MSG_V2, .iotlb.type =3D VHOST_IOTLB_BATCH_BEGIN, }; =20 - trace_vhost_vdpa_listener_begin_batch(v->shared, fd, msg.type, - msg.iotlb.type); + trace_vhost_vdpa_listener_begin_batch(s, fd, msg.type, msg.iotlb.type); if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { error_report("failed to write, fd=3D%d, errno=3D%d (%s)", fd, errno, strerror(errno)); } } =20 -static void vhost_vdpa_iotlb_batch_begin_once(struct vhost_vdpa *v) +static void vhost_vdpa_iotlb_batch_begin_once(VhostVDPAShared *s) { - if (v->shared->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH) && - !v->shared->iotlb_batch_begin_sent) { - vhost_vdpa_listener_begin_batch(v); + if (s->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH) && + !s->iotlb_batch_begin_sent) { + vhost_vdpa_listener_begin_batch(s); } =20 - v->shared->iotlb_batch_begin_sent =3D true; + s->iotlb_batch_begin_sent =3D true; } =20 static void vhost_vdpa_listener_commit(MemoryListener *listener) @@ -226,7 +225,7 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *= n, IOMMUTLBEntry *iotlb) if (!memory_get_xlat_addr(iotlb, &vaddr, NULL, &read_only, NULL)) { return; } - ret =3D vhost_vdpa_dma_map(v, VHOST_VDPA_GUEST_PA_ASID, iova, + ret =3D vhost_vdpa_dma_map(v->shared, VHOST_VDPA_GUEST_PA_ASID, io= va, iotlb->addr_mask + 1, vaddr, read_only); if (ret) { error_report("vhost_vdpa_dma_map(%p, 0x%" HWADDR_PRIx ", " @@ -234,7 +233,7 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *= n, IOMMUTLBEntry *iotlb) v, iova, iotlb->addr_mask + 1, vaddr, ret); } } else { - ret =3D vhost_vdpa_dma_unmap(v, VHOST_VDPA_GUEST_PA_ASID, iova, + ret =3D vhost_vdpa_dma_unmap(v->shared, VHOST_VDPA_GUEST_PA_ASID, = iova, iotlb->addr_mask + 1); if (ret) { error_report("vhost_vdpa_dma_unmap(%p, 0x%" HWADDR_PRIx ", " @@ -370,8 +369,8 @@ static void vhost_vdpa_listener_region_add(MemoryListen= er *listener, iova =3D mem_region.iova; } =20 - vhost_vdpa_iotlb_batch_begin_once(v); - ret =3D vhost_vdpa_dma_map(v, VHOST_VDPA_GUEST_PA_ASID, iova, + vhost_vdpa_iotlb_batch_begin_once(v->shared); + ret =3D vhost_vdpa_dma_map(v->shared, VHOST_VDPA_GUEST_PA_ASID, iova, int128_get64(llsize), vaddr, section->readonl= y); if (ret) { error_report("vhost vdpa map fail!"); @@ -455,13 +454,13 @@ static void vhost_vdpa_listener_region_del(MemoryList= ener *listener, iova =3D result->iova; vhost_iova_tree_remove(v->shared->iova_tree, *result); } - vhost_vdpa_iotlb_batch_begin_once(v); + vhost_vdpa_iotlb_batch_begin_once(v->shared); /* * The unmap ioctl doesn't accept a full 64-bit. need to check it */ if (int128_eq(llsize, int128_2_64())) { llsize =3D int128_rshift(llsize, 1); - ret =3D vhost_vdpa_dma_unmap(v, VHOST_VDPA_GUEST_PA_ASID, iova, + ret =3D vhost_vdpa_dma_unmap(v->shared, VHOST_VDPA_GUEST_PA_ASID, = iova, int128_get64(llsize)); =20 if (ret) { @@ -471,7 +470,7 @@ static void vhost_vdpa_listener_region_del(MemoryListen= er *listener, } iova +=3D int128_get64(llsize); } - ret =3D vhost_vdpa_dma_unmap(v, VHOST_VDPA_GUEST_PA_ASID, iova, + ret =3D vhost_vdpa_dma_unmap(v->shared, VHOST_VDPA_GUEST_PA_ASID, iova, int128_get64(llsize)); =20 if (ret) { @@ -1077,7 +1076,8 @@ static void vhost_vdpa_svq_unmap_ring(struct vhost_vd= pa *v, hwaddr addr) } =20 size =3D ROUND_UP(result->size, qemu_real_host_page_size()); - r =3D vhost_vdpa_dma_unmap(v, v->address_space_id, result->iova, size); + r =3D vhost_vdpa_dma_unmap(v->shared, v->address_space_id, result->iov= a, + size); if (unlikely(r < 0)) { error_report("Unable to unmap SVQ vring: %s (%d)", g_strerror(-r),= -r); return; @@ -1117,7 +1117,7 @@ static bool vhost_vdpa_svq_map_ring(struct vhost_vdpa= *v, DMAMap *needle, return false; } =20 - r =3D vhost_vdpa_dma_map(v, v->address_space_id, needle->iova, + r =3D vhost_vdpa_dma_map(v->shared, v->address_space_id, needle->iova, needle->size + 1, (void *)(uintptr_t)needle->translated_addr, needle->perm =3D=3D IOMMU_RO); diff --git a/net/vhost-vdpa.c b/net/vhost-vdpa.c index 10cf0027de..3726ee5d67 100644 --- a/net/vhost-vdpa.c +++ b/net/vhost-vdpa.c @@ -471,7 +471,8 @@ static void vhost_vdpa_cvq_unmap_buf(struct vhost_vdpa = *v, void *addr) return; } =20 - r =3D vhost_vdpa_dma_unmap(v, v->address_space_id, map->iova, map->siz= e + 1); + r =3D vhost_vdpa_dma_unmap(v->shared, v->address_space_id, map->iova, + map->size + 1); if (unlikely(r !=3D 0)) { error_report("Device cannot unmap: %s(%d)", g_strerror(r), r); } @@ -495,7 +496,7 @@ static int vhost_vdpa_cvq_map_buf(struct vhost_vdpa *v,= void *buf, size_t size, return r; } =20 - r =3D vhost_vdpa_dma_map(v, v->address_space_id, map.iova, + r =3D vhost_vdpa_dma_map(v->shared, v->address_space_id, map.iova, vhost_vdpa_net_cvq_cmd_page_len(), buf, !write); if (unlikely(r < 0)) { goto dma_map_err; --=20 2.39.3 From nobody Tue Nov 26 22:42:28 2024 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=1703159654; cv=none; d=zohomail.com; s=zohoarc; b=k5RWIVKOlfC8QURSgWfNI6ao30DZ5/xX7eDP7MjPjZhWMlLoQVRUt2E4SLh8Mqi5BSWAl4IMJql/v3JvvPfaL1BM05K8zUPl3uKvToI6RRADtlsdlsEp03IgwJDAmCNnnNu8hHDrrklXWIu4PdwgT3AnVqJAl4yB7SOYPcOli0M= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703159654; h=Content-Type: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=cuBFWfNNtw64fAJhsw7LPpnb02Jg4XxtbrnhOX0GkdM=; b=kxke8xO69gSuveFXJpgWSXwwOsFlEgmTZ2gBUZdnFx5Zf7QYeSGaLxUPeaz6QYvNUlJZjkRl/xnWw4NGrEGaaTuxNDyMx9Jb/0yoAKL5vzFCFFxIlATKOL4XY/9TnbTG2CrSNZFqXRhJo4aXZumpyxiuYrtlkZqYmNtTah5uBvQ= 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 1703159654835537.5222930522007; Thu, 21 Dec 2023 03:54:14 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGHcl-0008UF-UA; Thu, 21 Dec 2023 06:54:00 -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 1rGHcj-0008Ka-Ri for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:57 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rGHci-00083j-6c for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:57 -0500 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-384-4dmxgevWP9i2ApDKL-a6fw-1; Thu, 21 Dec 2023 06:53:51 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 421808F5DA1; Thu, 21 Dec 2023 11:53:50 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F60F40C6EB9; Thu, 21 Dec 2023 11:53:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703159635; 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=cuBFWfNNtw64fAJhsw7LPpnb02Jg4XxtbrnhOX0GkdM=; b=XxHhyTdJAvCnevw2bi9QvOcxRfUHeVfo34bhkzLb4QvkG1EOV19PxpoWC/4MsTNJ7kvVgj Wy4JjlBlcTPp+n/ULplfkwsdRA5k6yR6ZXGP0DnnMxLbRmjrpDPcXuVuO/qNlRxf1DnviF 4HQWmbDJbyGa1rp2mU5pDnAvULV4/RQ= X-MC-Unique: 4dmxgevWP9i2ApDKL-a6fw-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Parav Pandit , Dragos Tatulea , Lei Yang , Jason Wang , si-wei.liu@oracle.com, Zhu Lingshan , Stefano Garzarella , "Michael S. Tsirkin" , Laurent Vivier Subject: [PATCH v3 12/14] vdpa: use dev_shared in vdpa_iommu Date: Thu, 21 Dec 2023 12:53:17 +0100 Message-Id: <20231221115319.3067586-13-eperezma@redhat.com> In-Reply-To: <20231221115319.3067586-1-eperezma@redhat.com> References: <20231221115319.3067586-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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.133.124; envelope-from=eperezma@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.063, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1703159655673100005 The memory listener functions can call these too. Make vdpa_iommu work with VhostVDPAShared. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- include/hw/virtio/vhost-vdpa.h | 2 +- hw/virtio/vhost-vdpa.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 705c754776..2abee2164a 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -75,7 +75,7 @@ int vhost_vdpa_dma_unmap(VhostVDPAShared *s, uint32_t asi= d, hwaddr iova, hwaddr size); =20 typedef struct vdpa_iommu { - struct vhost_vdpa *dev; + VhostVDPAShared *dev_shared; IOMMUMemoryRegion *iommu_mr; hwaddr iommu_offset; IOMMUNotifier n; diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 0ed6550aad..61553ad196 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -199,7 +199,7 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *= n, IOMMUTLBEntry *iotlb) struct vdpa_iommu *iommu =3D container_of(n, struct vdpa_iommu, n); =20 hwaddr iova =3D iotlb->iova + iommu->iommu_offset; - struct vhost_vdpa *v =3D iommu->dev; + VhostVDPAShared *s =3D iommu->dev_shared; void *vaddr; int ret; Int128 llend; @@ -212,10 +212,10 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier= *n, IOMMUTLBEntry *iotlb) RCU_READ_LOCK_GUARD(); /* check if RAM section out of device range */ llend =3D int128_add(int128_makes64(iotlb->addr_mask), int128_makes64(= iova)); - if (int128_gt(llend, int128_make64(v->shared->iova_range.last))) { + if (int128_gt(llend, int128_make64(s->iova_range.last))) { error_report("RAM section out of device range (max=3D0x%" PRIx64 ", end addr=3D0x%" PRIx64 ")", - v->shared->iova_range.last, int128_get64(llend)); + s->iova_range.last, int128_get64(llend)); return; } =20 @@ -225,20 +225,20 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier= *n, IOMMUTLBEntry *iotlb) if (!memory_get_xlat_addr(iotlb, &vaddr, NULL, &read_only, NULL)) { return; } - ret =3D vhost_vdpa_dma_map(v->shared, VHOST_VDPA_GUEST_PA_ASID, io= va, + ret =3D vhost_vdpa_dma_map(s, VHOST_VDPA_GUEST_PA_ASID, iova, iotlb->addr_mask + 1, vaddr, read_only); if (ret) { error_report("vhost_vdpa_dma_map(%p, 0x%" HWADDR_PRIx ", " "0x%" HWADDR_PRIx ", %p) =3D %d (%m)", - v, iova, iotlb->addr_mask + 1, vaddr, ret); + s, iova, iotlb->addr_mask + 1, vaddr, ret); } } else { - ret =3D vhost_vdpa_dma_unmap(v->shared, VHOST_VDPA_GUEST_PA_ASID, = iova, + ret =3D vhost_vdpa_dma_unmap(s, VHOST_VDPA_GUEST_PA_ASID, iova, iotlb->addr_mask + 1); if (ret) { error_report("vhost_vdpa_dma_unmap(%p, 0x%" HWADDR_PRIx ", " "0x%" HWADDR_PRIx ") =3D %d (%m)", - v, iova, iotlb->addr_mask + 1, ret); + s, iova, iotlb->addr_mask + 1, ret); } } } @@ -270,7 +270,7 @@ static void vhost_vdpa_iommu_region_add(MemoryListener = *listener, iommu_idx); iommu->iommu_offset =3D section->offset_within_address_space - section->offset_within_region; - iommu->dev =3D v; + iommu->dev_shared =3D v->shared; =20 ret =3D memory_region_register_iommu_notifier(section->mr, &iommu->n, = NULL); if (ret) { --=20 2.39.3 From nobody Tue Nov 26 22:42:28 2024 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=1703159738; cv=none; d=zohomail.com; s=zohoarc; b=YXqQC0uGe2bxkYpqHLIkbQx3iage1INMrNE0c08OcUvimXibmYYxCk0ar1edmJcy0Rw3Bv+Xh4RUxX0Qr7p1IOEEEqs1xtG5uF/GWoaZWpwB8WJH3otNIpp5JhXZzFVf7RPclv/l9UxppFhC5CgQ65uf8DRsQ5lbNDMO0OFSE/o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703159738; h=Content-Type: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=sST+tbW3FDPrDUDc3xV+1NvvJGBb56HBn5rBJaKRGNE=; b=c6udBV6uHS0GOXyfP9NfycEMm9AUxMBnasFGkBj8JuqFBGV/Y7PzewaaeIegw0EBkTT0rkkuzQ3dHeNbv7qkIuIwxxPnUMU1rRRtf1Z4GO9zmLX4g/0RZ9Ir1jPhcAJXuIjdIYXCvkkn4Gyfr8JDFxQWpBCVAR9mePg9STqwOI0= 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 1703159738060747.6989317766014; Thu, 21 Dec 2023 03:55:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGHcn-0008VW-F2; Thu, 21 Dec 2023 06:54:01 -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 1rGHck-0008NE-8N for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:58 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rGHci-00084G-Mc for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:53:57 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-482-oIu6j0OVNsCMaU1igCq2aA-1; Thu, 21 Dec 2023 06:53:52 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 509763C000B4; Thu, 21 Dec 2023 11:53:52 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 809B140C6EB9; Thu, 21 Dec 2023 11:53:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703159636; 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=sST+tbW3FDPrDUDc3xV+1NvvJGBb56HBn5rBJaKRGNE=; b=g9Jzw0zyVj8EMOi2dRmgO6S8I6l2vhtk6RXQ45Kc27dh849+SQCXZL2Oe7hA/MHSQm9T6m X2jK+WR2LrX0SY/sBca/e/l6fAbTYxd4FEMRXBw0cj8O7+AioH6mSQEfoUeWqozucMun/O nlrjFy7w5TSKYGfTnIfX1/Dxkcr9AGw= X-MC-Unique: oIu6j0OVNsCMaU1igCq2aA-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Parav Pandit , Dragos Tatulea , Lei Yang , Jason Wang , si-wei.liu@oracle.com, Zhu Lingshan , Stefano Garzarella , "Michael S. Tsirkin" , Laurent Vivier Subject: [PATCH v3 13/14] vdpa: factor out vhost_vdpa_last_dev Date: Thu, 21 Dec 2023 12:53:18 +0100 Message-Id: <20231221115319.3067586-14-eperezma@redhat.com> In-Reply-To: <20231221115319.3067586-1-eperezma@redhat.com> References: <20231221115319.3067586-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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.133.124; envelope-from=eperezma@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.063, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1703159740211100005 From: Si-Wei Liu Generalize duplicated condition check for the last vq of vdpa device to a common function. This is used in next patches. Signed-off-by: Si-Wei Liu Reviewed-by: Eugenio P=C3=A9rez --- v3: Cherry-picked from Si-Wei's series --- hw/virtio/vhost-vdpa.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index 61553ad196..a846abccb0 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -557,6 +557,11 @@ static bool vhost_vdpa_first_dev(struct vhost_dev *dev) return v->index =3D=3D 0; } =20 +static bool vhost_vdpa_last_dev(struct vhost_dev *dev) +{ + return dev->vq_index + dev->nvqs =3D=3D dev->vq_index_end; +} + static int vhost_vdpa_get_dev_features(struct vhost_dev *dev, uint64_t *features) { @@ -1317,7 +1322,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev= , bool started) vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); } =20 - if (dev->vq_index + dev->nvqs !=3D dev->vq_index_end) { + if (!vhost_vdpa_last_dev(dev)) { return 0; } =20 @@ -1339,7 +1344,7 @@ static void vhost_vdpa_reset_status(struct vhost_dev = *dev) { struct vhost_vdpa *v =3D dev->opaque; =20 - if (dev->vq_index + dev->nvqs !=3D dev->vq_index_end) { + if (!vhost_vdpa_last_dev(dev)) { return; } =20 --=20 2.39.3 From nobody Tue Nov 26 22:42:28 2024 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=1703159738; cv=none; d=zohomail.com; s=zohoarc; b=Ikzod3l0N4h4bKnfLtR0serDeJ/CVZQ6k67P50YIpu3E0bWMWEqQh/F1S7p3YxDtDMlGQde37rdWBGMtVWvnZysnznczEbaILdYc9fpooeljz7tSiKo/CFLiW10fpApwEHinzQvkhXOCmn3d5YG9/gPKeb2SzS6UZj+7IweUedY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1703159738; h=Content-Type: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=ca3/Xt80Qzbjm45ddnOSNgNcXA/xV2xRJsy4vk7sgxY=; b=kQXbBsIRcAMimeYniq2WjO5564te6q/AXXQfcFu4PKh8iK9Tx4Ksxk5QiHkWFbTgoaLdOerPJXx1+qEKltl4aSiOTR8Rn6feWinbC6NnHCLnL3H5mcokX41SKQNqMNp7LiaArBwcu4GKQ6xGiwYlTeV7e1+Yvm8JVZGi22b5uGQ= 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 1703159738127407.4359272798806; Thu, 21 Dec 2023 03:55:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rGHco-0000CK-Ev; Thu, 21 Dec 2023 06:54:02 -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 1rGHcn-00007B-Ew for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:54:01 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rGHck-00084z-PI for qemu-devel@nongnu.org; Thu, 21 Dec 2023 06:54:01 -0500 Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-70-yIM0ycz9NfeJGrM0D1pQ3g-1; Thu, 21 Dec 2023 06:53:54 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 543B73C000B6; Thu, 21 Dec 2023 11:53:54 +0000 (UTC) Received: from eperezma.remote.csb (unknown [10.39.193.3]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9147040C6EB9; Thu, 21 Dec 2023 11:53:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1703159638; 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=ca3/Xt80Qzbjm45ddnOSNgNcXA/xV2xRJsy4vk7sgxY=; b=f0CSCQBzRJ0+3efSZhkFnM1wy8pC0nV+9Cc6qRGox72+bOnifBlR+A7g1RlqxcAhbze3bf 3n9DoiFqbHccylPrywhN1t/aANfZqzQK7PacF6Aa1GfQkT33ngF+nHcXg13uBvZBD9mcL5 Jw1/gVnhdRdl1Gwh/E9H2B7wYchodUo= X-MC-Unique: yIM0ycz9NfeJGrM0D1pQ3g-1 From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: qemu-devel@nongnu.org Cc: Parav Pandit , Dragos Tatulea , Lei Yang , Jason Wang , si-wei.liu@oracle.com, Zhu Lingshan , Stefano Garzarella , "Michael S. Tsirkin" , Laurent Vivier Subject: [PATCH v3 14/14] vdpa: move memory listener to vhost_vdpa_shared Date: Thu, 21 Dec 2023 12:53:19 +0100 Message-Id: <20231221115319.3067586-15-eperezma@redhat.com> In-Reply-To: <20231221115319.3067586-1-eperezma@redhat.com> References: <20231221115319.3067586-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.2 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.133.124; envelope-from=eperezma@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.063, 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_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1703159740279100007 Next patches will register the vhost_vdpa memory listener while the VM is migrating at the destination, so we can map the memory to the device before stopping the VM at the source. The main goal is to reduce the downtime. However, the destination QEMU is unaware of which vhost_vdpa device will register its memory_listener. If the source guest has CVQ enabled, it will be the CVQ device. Otherwise, it will be the first one. Move the memory listener to a common place rather than always in the first / last vhost_vdpa. Signed-off-by: Eugenio P=C3=A9rez Acked-by: Jason Wang --- v3: * Only memory_listener_unregister at vhost_vdpa_cleanup in the last dev. SIGSEGV detected by both Si-Wei and Lei Yang [1]. * Move ram_block_discard_disable at vhost_vdpa_cleanup to the last dev [1] https://patchwork.kernel.org/comment/25614601/ --- include/hw/virtio/vhost-vdpa.h | 2 +- hw/virtio/vhost-vdpa.c | 90 ++++++++++++++++------------------ 2 files changed, 43 insertions(+), 49 deletions(-) diff --git a/include/hw/virtio/vhost-vdpa.h b/include/hw/virtio/vhost-vdpa.h index 2abee2164a..8f54e5edd4 100644 --- a/include/hw/virtio/vhost-vdpa.h +++ b/include/hw/virtio/vhost-vdpa.h @@ -33,6 +33,7 @@ typedef struct VhostVDPAHostNotifier { /* Info shared by all vhost_vdpa device models */ typedef struct vhost_vdpa_shared { int device_fd; + MemoryListener listener; struct vhost_vdpa_iova_range iova_range; QLIST_HEAD(, vdpa_iommu) iommu_list; =20 @@ -51,7 +52,6 @@ typedef struct vhost_vdpa_shared { typedef struct vhost_vdpa { int index; uint32_t address_space_id; - MemoryListener listener; uint64_t acked_features; bool shadow_vqs_enabled; /* Device suspended successfully */ diff --git a/hw/virtio/vhost-vdpa.c b/hw/virtio/vhost-vdpa.c index a846abccb0..a7c63d52d3 100644 --- a/hw/virtio/vhost-vdpa.c +++ b/hw/virtio/vhost-vdpa.c @@ -170,28 +170,28 @@ static void vhost_vdpa_iotlb_batch_begin_once(VhostVD= PAShared *s) =20 static void vhost_vdpa_listener_commit(MemoryListener *listener) { - struct vhost_vdpa *v =3D container_of(listener, struct vhost_vdpa, lis= tener); + VhostVDPAShared *s =3D container_of(listener, VhostVDPAShared, listene= r); struct vhost_msg_v2 msg =3D {}; - int fd =3D v->shared->device_fd; + int fd =3D s->device_fd; =20 - if (!(v->shared->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH)= )) { + if (!(s->backend_cap & (0x1ULL << VHOST_BACKEND_F_IOTLB_BATCH))) { return; } =20 - if (!v->shared->iotlb_batch_begin_sent) { + if (!s->iotlb_batch_begin_sent) { return; } =20 msg.type =3D VHOST_IOTLB_MSG_V2; msg.iotlb.type =3D VHOST_IOTLB_BATCH_END; =20 - trace_vhost_vdpa_listener_commit(v->shared, fd, msg.type, msg.iotlb.ty= pe); + trace_vhost_vdpa_listener_commit(s, fd, msg.type, msg.iotlb.type); if (write(fd, &msg, sizeof(msg)) !=3D sizeof(msg)) { error_report("failed to write, fd=3D%d, errno=3D%d (%s)", fd, errno, strerror(errno)); } =20 - v->shared->iotlb_batch_begin_sent =3D false; + s->iotlb_batch_begin_sent =3D false; } =20 static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *n, IOMMUTLBEntry *i= otlb) @@ -246,7 +246,7 @@ static void vhost_vdpa_iommu_map_notify(IOMMUNotifier *= n, IOMMUTLBEntry *iotlb) static void vhost_vdpa_iommu_region_add(MemoryListener *listener, MemoryRegionSection *section) { - struct vhost_vdpa *v =3D container_of(listener, struct vhost_vdpa, lis= tener); + VhostVDPAShared *s =3D container_of(listener, VhostVDPAShared, listene= r); =20 struct vdpa_iommu *iommu; Int128 end; @@ -270,7 +270,7 @@ static void vhost_vdpa_iommu_region_add(MemoryListener = *listener, iommu_idx); iommu->iommu_offset =3D section->offset_within_address_space - section->offset_within_region; - iommu->dev_shared =3D v->shared; + iommu->dev_shared =3D s; =20 ret =3D memory_region_register_iommu_notifier(section->mr, &iommu->n, = NULL); if (ret) { @@ -278,7 +278,7 @@ static void vhost_vdpa_iommu_region_add(MemoryListener = *listener, return; } =20 - QLIST_INSERT_HEAD(&v->shared->iommu_list, iommu, iommu_next); + QLIST_INSERT_HEAD(&s->iommu_list, iommu, iommu_next); memory_region_iommu_replay(iommu->iommu_mr, &iommu->n); =20 return; @@ -287,11 +287,11 @@ static void vhost_vdpa_iommu_region_add(MemoryListene= r *listener, static void vhost_vdpa_iommu_region_del(MemoryListener *listener, MemoryRegionSection *section) { - struct vhost_vdpa *v =3D container_of(listener, struct vhost_vdpa, lis= tener); + VhostVDPAShared *s =3D container_of(listener, VhostVDPAShared, listene= r); =20 struct vdpa_iommu *iommu; =20 - QLIST_FOREACH(iommu, &v->shared->iommu_list, iommu_next) + QLIST_FOREACH(iommu, &s->iommu_list, iommu_next) { if (MEMORY_REGION(iommu->iommu_mr) =3D=3D section->mr && iommu->n.start =3D=3D section->offset_within_region) { @@ -307,7 +307,7 @@ static void vhost_vdpa_listener_region_add(MemoryListen= er *listener, MemoryRegionSection *section) { DMAMap mem_region =3D {}; - struct vhost_vdpa *v =3D container_of(listener, struct vhost_vdpa, lis= tener); + VhostVDPAShared *s =3D container_of(listener, VhostVDPAShared, listene= r); hwaddr iova; Int128 llend, llsize; void *vaddr; @@ -315,10 +315,8 @@ static void vhost_vdpa_listener_region_add(MemoryListe= ner *listener, int page_size =3D qemu_target_page_size(); int page_mask =3D -page_size; =20 - if (vhost_vdpa_listener_skipped_section(section, - v->shared->iova_range.first, - v->shared->iova_range.last, - page_mask)) { + if (vhost_vdpa_listener_skipped_section(section, s->iova_range.first, + s->iova_range.last, page_mask)= ) { return; } if (memory_region_is_iommu(section->mr)) { @@ -328,8 +326,7 @@ static void vhost_vdpa_listener_region_add(MemoryListen= er *listener, =20 if (unlikely((section->offset_within_address_space & ~page_mask) !=3D (section->offset_within_region & ~page_mask))) { - trace_vhost_vdpa_listener_region_add_unaligned(v->shared, - section->mr->name, + trace_vhost_vdpa_listener_region_add_unaligned(s, section->mr->nam= e, section->offset_within_address_space & ~page_mask, section->offset_within_region & ~page_mask); return; @@ -349,18 +346,18 @@ static void vhost_vdpa_listener_region_add(MemoryList= ener *listener, section->offset_within_region + (iova - section->offset_within_address_space); =20 - trace_vhost_vdpa_listener_region_add(v->shared, iova, int128_get64(lle= nd), + trace_vhost_vdpa_listener_region_add(s, iova, int128_get64(llend), vaddr, section->readonly); =20 llsize =3D int128_sub(llend, int128_make64(iova)); - if (v->shared->shadow_data) { + if (s->shadow_data) { int r; =20 mem_region.translated_addr =3D (hwaddr)(uintptr_t)vaddr, mem_region.size =3D int128_get64(llsize) - 1, mem_region.perm =3D IOMMU_ACCESS_FLAG(true, section->readonly), =20 - r =3D vhost_iova_tree_map_alloc(v->shared->iova_tree, &mem_region); + r =3D vhost_iova_tree_map_alloc(s->iova_tree, &mem_region); if (unlikely(r !=3D IOVA_OK)) { error_report("Can't allocate a mapping (%d)", r); goto fail; @@ -369,8 +366,8 @@ static void vhost_vdpa_listener_region_add(MemoryListen= er *listener, iova =3D mem_region.iova; } =20 - vhost_vdpa_iotlb_batch_begin_once(v->shared); - ret =3D vhost_vdpa_dma_map(v->shared, VHOST_VDPA_GUEST_PA_ASID, iova, + vhost_vdpa_iotlb_batch_begin_once(s); + ret =3D vhost_vdpa_dma_map(s, VHOST_VDPA_GUEST_PA_ASID, iova, int128_get64(llsize), vaddr, section->readonl= y); if (ret) { error_report("vhost vdpa map fail!"); @@ -380,8 +377,8 @@ static void vhost_vdpa_listener_region_add(MemoryListen= er *listener, return; =20 fail_map: - if (v->shared->shadow_data) { - vhost_iova_tree_remove(v->shared->iova_tree, mem_region); + if (s->shadow_data) { + vhost_iova_tree_remove(s->iova_tree, mem_region); } =20 fail: @@ -398,17 +395,15 @@ fail: static void vhost_vdpa_listener_region_del(MemoryListener *listener, MemoryRegionSection *section) { - struct vhost_vdpa *v =3D container_of(listener, struct vhost_vdpa, lis= tener); + VhostVDPAShared *s =3D container_of(listener, VhostVDPAShared, listene= r); hwaddr iova; Int128 llend, llsize; int ret; int page_size =3D qemu_target_page_size(); int page_mask =3D -page_size; =20 - if (vhost_vdpa_listener_skipped_section(section, - v->shared->iova_range.first, - v->shared->iova_range.last, - page_mask)) { + if (vhost_vdpa_listener_skipped_section(section, s->iova_range.first, + s->iova_range.last, page_mask)= ) { return; } if (memory_region_is_iommu(section->mr)) { @@ -417,8 +412,7 @@ static void vhost_vdpa_listener_region_del(MemoryListen= er *listener, =20 if (unlikely((section->offset_within_address_space & ~page_mask) !=3D (section->offset_within_region & ~page_mask))) { - trace_vhost_vdpa_listener_region_del_unaligned(v->shared, - section->mr->name, + trace_vhost_vdpa_listener_region_del_unaligned(s, section->mr->nam= e, section->offset_within_address_space & ~page_mask, section->offset_within_region & ~page_mask); return; @@ -427,7 +421,7 @@ static void vhost_vdpa_listener_region_del(MemoryListen= er *listener, iova =3D ROUND_UP(section->offset_within_address_space, page_size); llend =3D vhost_vdpa_section_end(section, page_mask); =20 - trace_vhost_vdpa_listener_region_del(v->shared, iova, + trace_vhost_vdpa_listener_region_del(s, iova, int128_get64(int128_sub(llend, int128_one()))); =20 if (int128_ge(int128_make64(iova), llend)) { @@ -436,7 +430,7 @@ static void vhost_vdpa_listener_region_del(MemoryListen= er *listener, =20 llsize =3D int128_sub(llend, int128_make64(iova)); =20 - if (v->shared->shadow_data) { + if (s->shadow_data) { const DMAMap *result; const void *vaddr =3D memory_region_get_ram_ptr(section->mr) + section->offset_within_region + @@ -446,37 +440,37 @@ static void vhost_vdpa_listener_region_del(MemoryList= ener *listener, .size =3D int128_get64(llsize) - 1, }; =20 - result =3D vhost_iova_tree_find_iova(v->shared->iova_tree, &mem_re= gion); + result =3D vhost_iova_tree_find_iova(s->iova_tree, &mem_region); if (!result) { /* The memory listener map wasn't mapped */ return; } iova =3D result->iova; - vhost_iova_tree_remove(v->shared->iova_tree, *result); + vhost_iova_tree_remove(s->iova_tree, *result); } - vhost_vdpa_iotlb_batch_begin_once(v->shared); + vhost_vdpa_iotlb_batch_begin_once(s); /* * The unmap ioctl doesn't accept a full 64-bit. need to check it */ if (int128_eq(llsize, int128_2_64())) { llsize =3D int128_rshift(llsize, 1); - ret =3D vhost_vdpa_dma_unmap(v->shared, VHOST_VDPA_GUEST_PA_ASID, = iova, + ret =3D vhost_vdpa_dma_unmap(s, VHOST_VDPA_GUEST_PA_ASID, iova, int128_get64(llsize)); =20 if (ret) { error_report("vhost_vdpa_dma_unmap(%p, 0x%" HWADDR_PRIx ", " "0x%" HWADDR_PRIx ") =3D %d (%m)", - v, iova, int128_get64(llsize), ret); + s, iova, int128_get64(llsize), ret); } iova +=3D int128_get64(llsize); } - ret =3D vhost_vdpa_dma_unmap(v->shared, VHOST_VDPA_GUEST_PA_ASID, iova, + ret =3D vhost_vdpa_dma_unmap(s, VHOST_VDPA_GUEST_PA_ASID, iova, int128_get64(llsize)); =20 if (ret) { error_report("vhost_vdpa_dma_unmap(%p, 0x%" HWADDR_PRIx ", " "0x%" HWADDR_PRIx ") =3D %d (%m)", - v, iova, int128_get64(llsize), ret); + s, iova, int128_get64(llsize), ret); } =20 memory_region_unref(section->mr); @@ -596,7 +590,7 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void = *opaque, Error **errp) =20 v->dev =3D dev; dev->opaque =3D opaque ; - v->listener =3D vhost_vdpa_memory_listener; + v->shared->listener =3D vhost_vdpa_memory_listener; vhost_vdpa_init_svq(dev, v); =20 error_propagate(&dev->migration_blocker, v->migration_blocker); @@ -754,12 +748,12 @@ static int vhost_vdpa_cleanup(struct vhost_dev *dev) assert(dev->vhost_ops->backend_type =3D=3D VHOST_BACKEND_TYPE_VDPA); v =3D dev->opaque; trace_vhost_vdpa_cleanup(dev, v); - if (vhost_vdpa_first_dev(dev)) { - ram_block_discard_disable(false); - } =20 vhost_vdpa_host_notifiers_uninit(dev, dev->nvqs); - memory_listener_unregister(&v->listener); + if (vhost_vdpa_last_dev(dev)) { + ram_block_discard_disable(false); + memory_listener_unregister(&v->shared->listener); + } vhost_vdpa_svq_cleanup(dev); =20 dev->opaque =3D NULL; @@ -1332,7 +1326,7 @@ static int vhost_vdpa_dev_start(struct vhost_dev *dev= , bool started) "IOMMU and try again"); return -1; } - memory_listener_register(&v->listener, dev->vdev->dma_as); + memory_listener_register(&v->shared->listener, dev->vdev->dma_as); =20 return vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_DRIVER_OK); } @@ -1351,7 +1345,7 @@ static void vhost_vdpa_reset_status(struct vhost_dev = *dev) vhost_vdpa_reset_device(dev); vhost_vdpa_add_status(dev, VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER); - memory_listener_unregister(&v->listener); + memory_listener_unregister(&v->shared->listener); } =20 static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base, --=20 2.39.3