vDPA shadow virtqueue
Subsystems (3)
Eugenio Pérez
maintainerPATCH 1/1 util: Add iova_tree_alloc
In reply to Jason WangThis iova tree function allows it to look for a hole in allocated regions and return a totally new translation for a given translated address.
It's usage is mainly to allow devices to access qemu address space, remapping guest's one into a new iova space where qemu can add chunks of addresses.
--- include/qemu/iova-tree.h | 17 +++++ util/iova-tree.c | 132 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 149 insertions(+)
include/qemu/iova-tree.h +17 -0
@@ -29,6 +29,7 @@#define IOVA_OK (0)#define IOVA_ERR_INVALID (-1)/* Invalid parameters */ #define IOVA_ERR_OVERLAP (-2)/* IOVA range overlapped */ +#define IOVA_ERR_NOMEM (-3)/* Cannot allocate */ typedef struct IOVATree IOVATree ; typedef struct DMAMap {
@@ -119,6 +120,22 @@ const DMAMap *iova_tree_find_address(const IOVATree *tree, hwaddr iova);*/ void iova_tree_foreach (IOVATree *tree,iova_tree_iterator iterator); +/** +* iova_tree_alloc: +* +* @tree: the iova tree to allocate from +* @map: the new map (as translated addr & size) to allocate in iova region +* @iova_begin: the minimum address of the allocation +* @iova_end: the maximum addressable direction of the allocation +* +* Allocates a new region of a given size, between iova_min and iova_max. +* +* Return: Same as iova_tree_insert, but cannot overlap and can be out of +* free contiguous range. Caller can get the assigned iova in map->iova. +*/ +int iova_tree_alloc_map (IOVATree *tree,DMAMap *map,hwaddr iova_begin, +hwaddr iova_end); +/** * iova_tree_destroy: *
util/iova-tree.c +132 -0
144 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [PATCH] util: Add iova_tree_alloc
Quoted 9 lines · Eugenio Pérez
This iova tree function allows it to look for a hole in allocated regions and return a totally new translation for a given translated address.
It's usage is mainly to allow devices to access qemu address space, remapping guest's one into a new iova space where qemu can add chunks of addresses.
Signed-off-by Eugenio Pérez <[email protected]>
Signature · 1 line
Peter Xu
Re: [PATCH 21/31] util: Add iova_tree_alloc
In reply to Eugenio Perez MartinQuoted 64 lines · Eugenio Perez Martin
Quoted 2 lines · Peter Xu
Quoted 1 line · Eugenio Pérez
+int iova_tree_alloc(IOVATree *tree, DMAMap *map, hwaddr
iova_begin,I forgot to s/iova_tree_alloc/iova_tree_alloc_map/ here.
Quoted 42 lines
Quoted 26 lines
util/iova-tree.c +26
-0+ hwaddr iova_last) +{ +const DMAMapInternal *last, *i; + +assert (iova_begin < iova_last); + +/* +* Find a valid hole for the mapping +* +* TODO: Replace all this with g_tree_node_first/next/last when available +* (from glib since 2.68). Using a sepparated QTAILQ complicates code. +* +* Try to allocate first at the end of the list. +*/ + last =QTAILQ_LAST (&tree->list); +if (iova_tree_alloc_map_in_hole (last,NULL , iova_begin, iova_last, + map->size)) { + goto alloc; + } + +/* Look for inner hole */ + last =NULL ; +for (i =QTAILQ_FIRST (&tree->list); i; + last = i, i =QTAILQ_NEXT (i, entry)) { +if (iova_tree_alloc_map_in_hole (last, i, iova_begin, iova_last, + map->size)) {util/iova-tree.c int iova_tree_remove(IOVATree *tree, const DMAMap *map) · line 247
Quoted 10 lines
util/iova-tree.c +10
-0+ goto alloc; + } + } + +return IOVA_ERR_NOMEM ; + +alloc: + map->iova = last ? last->map.iova + last->map.size +1 : iova_begin; +return iova_tree_insert (tree, map); +}Hi, Eugenio,
Have you tried with what Jason suggested previously?
https://lore.kernel.org/qemu-devel/CACGkMEtZAPd9xQTP_R4w296N_Qz7VuV1FLnb544fEVoYO0of+g@mail.gmail.com/Quoted 9 lines
That solution still sounds very sensible to me even without the newly introduced list in previous two patches.
IMHO we could move "DMAMap *previous, *this" into the IOVATreeAllocArgs* stucture that was passed into the traverse func though, so it'll naturally work with threading.
Or is there any blocker for it?
Hi Peter,
I can try that solution again, but the main problem was the special cases of the beginning and ending.
For the function to locate a hole, DMAMap first = {.iova = 0, .size = 0} means that it cannot account 0 for the hole.
Quoted 7 lines
In other words, with that algorithm, if the only valid hole is [0, N) and we try to allocate a block of size N, it would fail.
Same happens with
iova_end, although in practice it seems that IOMMU hardware iova upper limit is neverUINT64_MAX.Maybe we could treat .size = 0 as a special case?
Yes, the pseudo-code I past is just to show the idea of using g_tree_foreach() instead of introducing new auxiliary data structures. That will simplify both the codes and the reviewers.
Down the road, we may start from an iova range specified during the creation of the iova tree. E.g for vtd, it's the GAW, for vhost-vdpa, it's the one that we get from VHOST_VDPA_GET_IOVA_RANGE.
Thanks
Quoted 13 lines
I see cleaner either
to build the list (but insert needs to take the list into account) or to explicitly tell that prev == NULL means to useiova_first.Another solution that comes to my mind: to add both exceptions outside of transverse function, and skip the first iteration with something like:
if (prev == NULL) {
prev = this;
return false /* continue */
}
Quoted 9 lines
So the transverse callback has way less code paths. Would it work for you if I send a separate RFC from SVQ only to validate this?
Thanks!
Quoted 4 lines
Thanks,
--
Peter Xu
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Eugenio Pérez
maintainerPATCH 22/31 vhost: Add VhostIOVATree
In reply to Eugenio PérezThis tree is able to look for a translated address from an IOVA address.
At first glance it is similar to util/iova-tree. However, SVQ working on devices with limited IOVA space need more capabilities, like allocating IOVA chunks or performing reverse translations (qemu addresses to iova).
The allocation capability, as "assign a free IOVA address to this chunk of memory in qemu's address space" allows shadow virtqueue to create a new address space that is not restricted by guest's addressable one, so we can allocate shadow vqs vrings outside of it.
It duplicates the tree so it can search efficiently both directions, and it will signal overlap if iova or the translated address is present in any tree.
--- hw/virtio/vhost-iova-tree.h | 27 +++++++ hw/virtio/vhost-iova-tree.c | 157 ++++++++++++++++++++++++++++++++++++ hw/virtio/meson.build | 2 +- 3 files changed, 185 insertions(+), 1 deletion(-) create mode 100644 hw/virtio/vhost-iova-tree.h create mode 100644 hw/virtio/vhost-iova-tree.c
hw/virtio/vhost-iova-tree.h new file +27 -0
@@ -0,0 +1,27 @@ +/* +* vhost software live migration ring +* +* SPDX-FileCopyrightText: Red Hat, Inc. 2021 +* SPDX-FileContributor: Author: Eugenio Pérez <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_VIRTIO_VHOST_IOVA_TREE_H +#define HW_VIRTIO_VHOST_IOVA_TREE_H + +#include "qemu/iova-tree.h" +#include "exec/memory.h" + +typedef struct VhostIOVATree VhostIOVATree ; + +VhostIOVATree *vhost_iova_tree_new (uint64_t iova_first,uint64_t iova_last); +void vhost_iova_tree_delete (VhostIOVATree *iova_tree); +G_DEFINE_AUTOPTR_CLEANUP_FUNC (VhostIOVATree, vhost_iova_tree_delete); + +const DMAMap *vhost_iova_tree_find_iova (const VhostIOVATree *iova_tree, +const DMAMap *map); +int vhost_iova_tree_map_alloc (VhostIOVATree *iova_tree,DMAMap *map); +void vhost_iova_tree_remove (VhostIOVATree *iova_tree,const DMAMap *map); + +#endif
hw/virtio/vhost-iova-tree.c new file +157 -0
157 lines not on this page · raw message
hw/virtio/meson.build +1 -1
@@ -11,7 +11,7 @@ softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-stub.c')) virtio_ss = ss.source_set() virtio_ss.add(files('virtio.c')) -virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c', 'vhost-shadow-virtqueue.c')) +virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c', 'vhost-shadow-virtqueue.c', 'vhost-iova-tree.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user.c')) virtio_ss.add(when: 'CONFIG_VHOST_VDPA', if_true: files('vhost-vdpa.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virtio-balloon.c'))
Signature · 1 line
2.27.0
Re: [PATCH 22/31] vhost: Add VhostIOVATree
Quoted 4 lines · Eugenio Pérez
This tree is able to look for a translated address from an IOVA address.
At first glance it is similar to util/iova-tree. However, SVQ working on devices with limited IOVA space need more capabilities,
So did the IOVA tree (e.g l2 vtd can only work in the range of GAW and without RMRRs).
Quoted 2 lines
like allocating
IOVA chunks or performing reverse translations (qemu addresses to iova).
This looks like a general request as well. So I wonder if we can simply extend iova tree instead.
Thanks
Quoted 220 lines
The allocation capability, as "assign a free IOVA address to this chunk of memory in qemu's address space" allows shadow virtqueue to create a new address space that is not restricted by guest's addressable one, so we can allocate shadow vqs vrings outside of it.
It duplicates the tree so it can search efficiently both directions, and it will signal overlap if iova or the translated address is present in any tree.
Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-iova-tree.h | 27 +++++++ hw/virtio/vhost-iova-tree.c | 157 ++++++++++++++++++++++++++++++++++++ hw/virtio/meson.build | 2 +- 3 files changed, 185 insertions(+), 1 deletion(-)create mode 100644
hw/virtio/vhost-iova-tree.h
create mode 100644hw/virtio/vhost-iova-tree.chw/virtio/vhost-iova-tree.h new file +27
-0@@ -0,0 +1,27 @@ +/* +* vhost software live migration ring +* +* SPDX-FileCopyrightText: Red Hat, Inc. 2021 +* SPDX-FileContributor: Author: Eugenio Pérez <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_VIRTIO_VHOST_IOVA_TREE_H +#define HW_VIRTIO_VHOST_IOVA_TREE_H + +#include "qemu/iova-tree.h" +#include "exec/memory.h" + +typedef struct VhostIOVATree VhostIOVATree ; + +VhostIOVATree *vhost_iova_tree_new (uint64_t iova_first,uint64_t iova_last); +void vhost_iova_tree_delete (VhostIOVATree *iova_tree); +G_DEFINE_AUTOPTR_CLEANUP_FUNC (VhostIOVATree, vhost_iova_tree_delete); + +const DMAMap *vhost_iova_tree_find_iova (const VhostIOVATree *iova_tree, +const DMAMap *map); +int vhost_iova_tree_map_alloc (VhostIOVATree *iova_tree,DMAMap *map); +void vhost_iova_tree_remove (VhostIOVATree *iova_tree,const DMAMap *map); + +#endif hw/virtio/vhost-iova-tree.c new file +157
-0@@ -0,0 +1,157 @@ +/* +* vhost software live migration ring +* +* SPDX-FileCopyrightText: Red Hat, Inc. 2021 +* SPDX-FileContributor: Author: Eugenio Pérez <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qemu/iova-tree.h" +#include "vhost-iova-tree.h" + +#define iova_min_addr qemu_real_host_page_size + +/** +* VhostIOVATree, able to: +* - Translate iova address +* - Reverse translate iova address (from translated to iova) +* - Allocate IOVA regions for translated range (potentially slow operation) +* +* Note that it cannot remove nodes. +*/ +struct VhostIOVATree { +/* First addresable iova address in the device */ +uint64_t iova_first; + +/* Last addressable iova address in the device */ +uint64_t iova_last; + +/* IOVA address to qemu memory maps. */ +IOVATree *iova_taddr_map; + +/* QEMU virtual memory address to iova maps */ +GTree *taddr_iova_map; +}; + +static gint vhost_iova_tree_cmp_taddr (gconstpointer a,gconstpointer b, +gpointer data) +{ +const DMAMap *m1 = a, *m2 = b; + +if (m1->translated_addr > m2->translated_addr + m2->size) { +return 1 ; + } + +if (m1->translated_addr + m1->size < m2->translated_addr) { +return -1 ; + } + +/* Overlapped */ +return 0 ; +} + +/** +* Create a new IOVA tree +* +* Returns the new IOVA tree +*/ +VhostIOVATree *vhost_iova_tree_new (hwaddr iova_first,hwaddr iova_last) +{ +VhostIOVATree *tree =g_new (VhostIOVATree,1 ); + +/* Some devices does not like 0 addresses */ + tree->iova_first =MAX (iova_first, iova_min_addr); + tree->iova_last = iova_last; + + tree->iova_taddr_map =iova_tree_new (); + tree->taddr_iova_map =g_tree_new_full (vhost_iova_tree_cmp_taddr,NULL , +NULL , g_free); +return tree; +} + +/** +* Delete an iova tree +*/ +void vhost_iova_tree_delete (VhostIOVATree *iova_tree) +{ +iova_tree_destroy (iova_tree->iova_taddr_map); +g_tree_unref (iova_tree->taddr_iova_map); +g_free (iova_tree); +} + +/** +* Find the IOVA address stored from a memory address +* +* @tree The iova tree +* @map The map with the memory address +* +* Return the stored mapping, or NULL if not found. +*/ +const DMAMap *vhost_iova_tree_find_iova (const VhostIOVATree *tree, +const DMAMap *map) +{ +return g_tree_lookup (tree->taddr_iova_map, map); +} + +/** +* Allocate a new mapping +* +* @tree The iova tree +* @map The iova map +* +* Returns: +* - IOVA_OK if the map fits in the container +* - IOVA_ERR_INVALID if the map does not make sense (like size overflow) +* - IOVA_ERR_OVERLAP if the tree already contains that map +* - IOVA_ERR_NOMEM if tree cannot allocate more space. +* +* It returns assignated iova in map->iova if return value is VHOST_DMA_MAP_OK. +*/ +int vhost_iova_tree_map_alloc (VhostIOVATree *tree,DMAMap *map) +{ +/* Some vhost devices does not like addr 0. Skip first page */ +hwaddr iova_first = tree->iova_first ?: qemu_real_host_page_size; +DMAMap *new; +int r; + +if (map->translated_addr + map->size < map->translated_addr || + map->perm ==IOMMU_NONE ) { +return IOVA_ERR_INVALID ; + } + +/* Check for collisions in translated addresses */ +if (vhost_iova_tree_find_iova (tree, map)) { +return IOVA_ERR_OVERLAP ; + } + +/* Allocate a node in IOVA address */ + r =iova_tree_alloc (tree->iova_taddr_map, map, iova_first, + tree->iova_last); +if (r !=IOVA_OK ) { +return r; + } + +/* Allocate node in qemu -> iova translations */ + new =g_malloc (sizeof (*new)); +memcpy (new, map,sizeof (*new)); +g_tree_insert (tree->taddr_iova_map, new, new); +return IOVA_OK ; +} + +/** +* Remove existing mappings from iova tree +* +* @param iova_tree The vhost iova tree +* @param map The map to remove +*/ +void vhost_iova_tree_remove (VhostIOVATree *iova_tree,const DMAMap *map) +{ +const DMAMap *overlap; + +iova_tree_remove (iova_tree->iova_taddr_map, map); +while ((overlap =vhost_iova_tree_find_iova (iova_tree, map))) { +g_tree_remove (iova_tree->taddr_iova_map, overlap); + } +}hw/virtio/meson.build +0
-0
hw/virtio/meson.build softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-stub.c')) · line 17
Quoted 8 lines
hw/virtio/meson.build +1
-1@@ -11,7 +11,7 @@ softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-stub.c')) virtio_ss = ss.source_set() virtio_ss.add(files('virtio.c')) -virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c', 'vhost-shadow-virtqueue.c')) +virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c', 'vhost-shadow-virtqueue.c', 'vhost-iova-tree.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user.c')) virtio_ss.add(when: 'CONFIG_VHOST_VDPA', if_true: files('vhost-vdpa.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virtio-balloon.c'))
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Eugenio Perez Martin
maintainerRe: [PATCH 22/31] vhost: Add VhostIOVATree
Quoted 13 lines · Jason Wang
Quoted 4 lines · Eugenio Pérez
This tree is able to look for a translated address from an IOVA address.
At first glance it is similar to util/iova-tree. However, SVQ working on devices with limited IOVA space need more capabilities,
So did the IOVA tree (e.g l2 vtd can only work in the range of GAW and without RMRRs).
Quoted 7 lines
Quoted 2 lines
like allocating
IOVA chunks or performing reverse translations (qemu addresses to iova).This looks like a general request as well. So I wonder if we can simply extend iova tree instead.
While both are true, I don't see code that performs allocations or qemu vaddr to iova translations. But if the changes can be integrated into iova-tree that would be great for sure.
The main drawback I see is the need to maintain two trees instead of one for users of iova-tree. While complexity does not grow, it needs to double the amount of work needed.
Thanks!
Quoted 232 lines
Thanks
Quoted 228 lines
The allocation capability, as "assign a free IOVA address to this chunk of memory in qemu's address space" allows shadow virtqueue to create a new address space that is not restricted by guest's addressable one, so we can allocate shadow vqs vrings outside of it.
It duplicates the tree so it can search efficiently both directions, and it will signal overlap if iova or the translated address is present in any tree.
Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-iova-tree.h | 27 +++++++ hw/virtio/vhost-iova-tree.c | 157 ++++++++++++++++++++++++++++++++++++ hw/virtio/meson.build | 2 +- 3 files changed, 185 insertions(+), 1 deletion(-)create mode 100644
hw/virtio/vhost-iova-tree.h
create mode 100644hw/virtio/vhost-iova-tree.chw/virtio/vhost-iova-tree.h new file +27
-0@@ -0,0 +1,27 @@ +/* +* vhost software live migration ring +* +* SPDX-FileCopyrightText: Red Hat, Inc. 2021 +* SPDX-FileContributor: Author: Eugenio Pérez <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_VIRTIO_VHOST_IOVA_TREE_H +#define HW_VIRTIO_VHOST_IOVA_TREE_H + +#include "qemu/iova-tree.h" +#include "exec/memory.h" + +typedef struct VhostIOVATree VhostIOVATree ; + +VhostIOVATree *vhost_iova_tree_new (uint64_t iova_first,uint64_t iova_last); +void vhost_iova_tree_delete (VhostIOVATree *iova_tree); +G_DEFINE_AUTOPTR_CLEANUP_FUNC (VhostIOVATree, vhost_iova_tree_delete); + +const DMAMap *vhost_iova_tree_find_iova (const VhostIOVATree *iova_tree, +const DMAMap *map); +int vhost_iova_tree_map_alloc (VhostIOVATree *iova_tree,DMAMap *map); +void vhost_iova_tree_remove (VhostIOVATree *iova_tree,const DMAMap *map); + +#endif hw/virtio/vhost-iova-tree.c new file +157
-0@@ -0,0 +1,157 @@ +/* +* vhost software live migration ring +* +* SPDX-FileCopyrightText: Red Hat, Inc. 2021 +* SPDX-FileContributor: Author: Eugenio Pérez <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qemu/iova-tree.h" +#include "vhost-iova-tree.h" + +#define iova_min_addr qemu_real_host_page_size + +/** +* VhostIOVATree, able to: +* - Translate iova address +* - Reverse translate iova address (from translated to iova) +* - Allocate IOVA regions for translated range (potentially slow operation) +* +* Note that it cannot remove nodes. +*/ +struct VhostIOVATree { +/* First addresable iova address in the device */ +uint64_t iova_first; + +/* Last addressable iova address in the device */ +uint64_t iova_last; + +/* IOVA address to qemu memory maps. */ +IOVATree *iova_taddr_map; + +/* QEMU virtual memory address to iova maps */ +GTree *taddr_iova_map; +}; + +static gint vhost_iova_tree_cmp_taddr (gconstpointer a,gconstpointer b, +gpointer data) +{ +const DMAMap *m1 = a, *m2 = b; + +if (m1->translated_addr > m2->translated_addr + m2->size) { +return 1 ; + } + +if (m1->translated_addr + m1->size < m2->translated_addr) { +return -1 ; + } + +/* Overlapped */ +return 0 ; +} + +/** +* Create a new IOVA tree +* +* Returns the new IOVA tree +*/ +VhostIOVATree *vhost_iova_tree_new (hwaddr iova_first,hwaddr iova_last) +{ +VhostIOVATree *tree =g_new (VhostIOVATree,1 ); + +/* Some devices does not like 0 addresses */ + tree->iova_first =MAX (iova_first, iova_min_addr); + tree->iova_last = iova_last; + + tree->iova_taddr_map =iova_tree_new (); + tree->taddr_iova_map =g_tree_new_full (vhost_iova_tree_cmp_taddr,NULL , +NULL , g_free); +return tree; +} + +/** +* Delete an iova tree +*/ +void vhost_iova_tree_delete (VhostIOVATree *iova_tree) +{ +iova_tree_destroy (iova_tree->iova_taddr_map); +g_tree_unref (iova_tree->taddr_iova_map); +g_free (iova_tree); +} + +/** +* Find the IOVA address stored from a memory address +* +* @tree The iova tree +* @map The map with the memory address +* +* Return the stored mapping, or NULL if not found. +*/ +const DMAMap *vhost_iova_tree_find_iova (const VhostIOVATree *tree, +const DMAMap *map) +{ +return g_tree_lookup (tree->taddr_iova_map, map); +} + +/** +* Allocate a new mapping +* +* @tree The iova tree +* @map The iova map +* +* Returns: +* - IOVA_OK if the map fits in the container +* - IOVA_ERR_INVALID if the map does not make sense (like size overflow) +* - IOVA_ERR_OVERLAP if the tree already contains that map +* - IOVA_ERR_NOMEM if tree cannot allocate more space. +* +* It returns assignated iova in map->iova if return value is VHOST_DMA_MAP_OK. +*/ +int vhost_iova_tree_map_alloc (VhostIOVATree *tree,DMAMap *map) +{ +/* Some vhost devices does not like addr 0. Skip first page */ +hwaddr iova_first = tree->iova_first ?: qemu_real_host_page_size; +DMAMap *new; +int r; + +if (map->translated_addr + map->size < map->translated_addr || + map->perm ==IOMMU_NONE ) { +return IOVA_ERR_INVALID ; + } + +/* Check for collisions in translated addresses */ +if (vhost_iova_tree_find_iova (tree, map)) { +return IOVA_ERR_OVERLAP ; + } + +/* Allocate a node in IOVA address */ + r =iova_tree_alloc (tree->iova_taddr_map, map, iova_first, + tree->iova_last); +if (r !=IOVA_OK ) { +return r; + } + +/* Allocate node in qemu -> iova translations */ + new =g_malloc (sizeof (*new)); +memcpy (new, map,sizeof (*new)); +g_tree_insert (tree->taddr_iova_map, new, new); +return IOVA_OK ; +} + +/** +* Remove existing mappings from iova tree +* +* @param iova_tree The vhost iova tree +* @param map The map to remove +*/ +void vhost_iova_tree_remove (VhostIOVATree *iova_tree,const DMAMap *map) +{ +const DMAMap *overlap; + +iova_tree_remove (iova_tree->iova_taddr_map, map); +while ((overlap =vhost_iova_tree_find_iova (iova_tree, map))) { +g_tree_remove (iova_tree->taddr_iova_map, overlap); + } +}hw/virtio/meson.build +1
-1@@ -11,7 +11,7 @@ softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-stub.c')) virtio_ss = ss.source_set() virtio_ss.add(files('virtio.c')) -virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c', 'vhost-shadow-virtqueue.c')) +virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c', 'vhost-shadow-virtqueue.c', 'vhost-iova-tree.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user.c')) virtio_ss.add(when: 'CONFIG_VHOST_VDPA', if_true: files('vhost-vdpa.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virtio-balloon.c'))
Re: [PATCH 22/31] vhost: Add VhostIOVATree
Quoted 18 lines · Eugenio Perez Martin
Quoted 11 lines · Jason Wang
Quoted 4 lines · Eugenio Pérez
This tree is able to look for a translated address from an IOVA address.
At first glance it is similar to util/iova-tree. However, SVQ working on devices with limited IOVA space need more capabilities,
So did the IOVA tree (e.g l2 vtd can only work in the range of GAW and without RMRRs).
Quoted 6 lines
Quoted 2 lines
like allocating
IOVA chunks or performing reverse translations (qemu addresses to iova).This looks like a general request as well. So I wonder if we can simply extend iova tree instead.
Quoted 7 lines
While both are true, I don't see code that performs allocations or qemu vaddr to iova translations. But if the changes can be integrated into iova-tree that would be great for sure.
The main drawback I see is the need to maintain two trees instead of one for users of iova-tree. While complexity does not grow, it needs to double the amount of work needed.
If you care about the performance, we can disable the reverse mapping during the allocation. For vIOMMU users it won't notice any performance penalty.
Thanks
Quoted 226 lines
Thanks!
Quoted 223 lines
Thanks
Quoted 220 lines
The allocation capability, as "assign a free IOVA address to this chunk of memory in qemu's address space" allows shadow virtqueue to create a new address space that is not restricted by guest's addressable one, so we can allocate shadow vqs vrings outside of it.
It duplicates the tree so it can search efficiently both directions, and it will signal overlap if iova or the translated address is present in any tree.
Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-iova-tree.h | 27 +++++++ hw/virtio/vhost-iova-tree.c | 157 ++++++++++++++++++++++++++++++++++++ hw/virtio/meson.build | 2 +- 3 files changed, 185 insertions(+), 1 deletion(-)create mode 100644
hw/virtio/vhost-iova-tree.h
create mode 100644hw/virtio/vhost-iova-tree.chw/virtio/vhost-iova-tree.h new file +27
-0@@ -0,0 +1,27 @@ +/* +* vhost software live migration ring +* +* SPDX-FileCopyrightText: Red Hat, Inc. 2021 +* SPDX-FileContributor: Author: Eugenio Pérez <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#ifndef HW_VIRTIO_VHOST_IOVA_TREE_H +#define HW_VIRTIO_VHOST_IOVA_TREE_H + +#include "qemu/iova-tree.h" +#include "exec/memory.h" + +typedef struct VhostIOVATree VhostIOVATree ; + +VhostIOVATree *vhost_iova_tree_new (uint64_t iova_first,uint64_t iova_last); +void vhost_iova_tree_delete (VhostIOVATree *iova_tree); +G_DEFINE_AUTOPTR_CLEANUP_FUNC (VhostIOVATree, vhost_iova_tree_delete); + +const DMAMap *vhost_iova_tree_find_iova (const VhostIOVATree *iova_tree, +const DMAMap *map); +int vhost_iova_tree_map_alloc (VhostIOVATree *iova_tree,DMAMap *map); +void vhost_iova_tree_remove (VhostIOVATree *iova_tree,const DMAMap *map); + +#endif hw/virtio/vhost-iova-tree.c new file +157
-0@@ -0,0 +1,157 @@ +/* +* vhost software live migration ring +* +* SPDX-FileCopyrightText: Red Hat, Inc. 2021 +* SPDX-FileContributor: Author: Eugenio Pérez <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qemu/iova-tree.h" +#include "vhost-iova-tree.h" + +#define iova_min_addr qemu_real_host_page_size + +/** +* VhostIOVATree, able to: +* - Translate iova address +* - Reverse translate iova address (from translated to iova) +* - Allocate IOVA regions for translated range (potentially slow operation) +* +* Note that it cannot remove nodes. +*/ +struct VhostIOVATree { +/* First addresable iova address in the device */ +uint64_t iova_first; + +/* Last addressable iova address in the device */ +uint64_t iova_last; + +/* IOVA address to qemu memory maps. */ +IOVATree *iova_taddr_map; + +/* QEMU virtual memory address to iova maps */ +GTree *taddr_iova_map; +}; + +static gint vhost_iova_tree_cmp_taddr (gconstpointer a,gconstpointer b, +gpointer data) +{ +const DMAMap *m1 = a, *m2 = b; + +if (m1->translated_addr > m2->translated_addr + m2->size) { +return 1 ; + } + +if (m1->translated_addr + m1->size < m2->translated_addr) { +return -1 ; + } + +/* Overlapped */ +return 0 ; +} + +/** +* Create a new IOVA tree +* +* Returns the new IOVA tree +*/ +VhostIOVATree *vhost_iova_tree_new (hwaddr iova_first,hwaddr iova_last) +{ +VhostIOVATree *tree =g_new (VhostIOVATree,1 ); + +/* Some devices does not like 0 addresses */ + tree->iova_first =MAX (iova_first, iova_min_addr); + tree->iova_last = iova_last; + + tree->iova_taddr_map =iova_tree_new (); + tree->taddr_iova_map =g_tree_new_full (vhost_iova_tree_cmp_taddr,NULL , +NULL , g_free); +return tree; +} + +/** +* Delete an iova tree +*/ +void vhost_iova_tree_delete (VhostIOVATree *iova_tree) +{ +iova_tree_destroy (iova_tree->iova_taddr_map); +g_tree_unref (iova_tree->taddr_iova_map); +g_free (iova_tree); +} + +/** +* Find the IOVA address stored from a memory address +* +* @tree The iova tree +* @map The map with the memory address +* +* Return the stored mapping, or NULL if not found. +*/ +const DMAMap *vhost_iova_tree_find_iova (const VhostIOVATree *tree, +const DMAMap *map) +{ +return g_tree_lookup (tree->taddr_iova_map, map); +} + +/** +* Allocate a new mapping +* +* @tree The iova tree +* @map The iova map +* +* Returns: +* - IOVA_OK if the map fits in the container +* - IOVA_ERR_INVALID if the map does not make sense (like size overflow) +* - IOVA_ERR_OVERLAP if the tree already contains that map +* - IOVA_ERR_NOMEM if tree cannot allocate more space. +* +* It returns assignated iova in map->iova if return value is VHOST_DMA_MAP_OK. +*/ +int vhost_iova_tree_map_alloc (VhostIOVATree *tree,DMAMap *map) +{ +/* Some vhost devices does not like addr 0. Skip first page */ +hwaddr iova_first = tree->iova_first ?: qemu_real_host_page_size; +DMAMap *new; +int r; + +if (map->translated_addr + map->size < map->translated_addr || + map->perm ==IOMMU_NONE ) { +return IOVA_ERR_INVALID ; + } + +/* Check for collisions in translated addresses */ +if (vhost_iova_tree_find_iova (tree, map)) { +return IOVA_ERR_OVERLAP ; + } + +/* Allocate a node in IOVA address */ + r =iova_tree_alloc (tree->iova_taddr_map, map, iova_first, + tree->iova_last); +if (r !=IOVA_OK ) { +return r; + } + +/* Allocate node in qemu -> iova translations */ + new =g_malloc (sizeof (*new)); +memcpy (new, map,sizeof (*new)); +g_tree_insert (tree->taddr_iova_map, new, new); +return IOVA_OK ; +} + +/** +* Remove existing mappings from iova tree +* +* @param iova_tree The vhost iova tree +* @param map The map to remove +*/ +void vhost_iova_tree_remove (VhostIOVATree *iova_tree,const DMAMap *map) +{ +const DMAMap *overlap; + +iova_tree_remove (iova_tree->iova_taddr_map, map); +while ((overlap =vhost_iova_tree_find_iova (iova_tree, map))) { +g_tree_remove (iova_tree->taddr_iova_map, overlap); + } +}hw/virtio/meson.build +0
-0@@ -11,7 +11,7 @@ softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-stub.c'))
Quoted 7 lines
Quoted 7 lines
hw/virtio/meson.build softmmu_ss.add(when: 'CONFIG_ALL', if_true: files('vhost-stub.c')) · line 17
Quoted 7 lines
hw/virtio/meson.build +1
-1virtio_ss = ss.source_set() virtio_ss.add(files('virtio.c')) -virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c', 'vhost-shadow-virtqueue.c')) +virtio_ss.add(when: 'CONFIG_VHOST', if_true: files('vhost.c', 'vhost-backend.c', 'vhost-shadow-virtqueue.c', 'vhost-iova-tree.c')) virtio_ss.add(when: 'CONFIG_VHOST_USER', if_true: files('vhost-user.c')) virtio_ss.add(when: 'CONFIG_VHOST_VDPA', if_true: files('vhost-vdpa.c')) virtio_ss.add(when: 'CONFIG_VIRTIO_BALLOON', if_true: files('virtio-balloon.c'))
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Eugenio Pérez
maintainerPATCH 23/31 vdpa: Add custom IOTLB translations to SVQ
In reply to Eugenio PérezUse translations added in VhostIOVATree in SVQ.
Only introduce usage here, not allocation and deallocation. As with previous patches, we use the dead code paths of shadow_vqs_enabled to avoid commiting too many changes at once. These are impossible to take at the moment.
--- hw/virtio/vhost-shadow-virtqueue.h | 3 +- include/hw/virtio/vhost-vdpa.h | 3 + hw/virtio/vhost-shadow-virtqueue.c | 111 ++++++++++++++++---- hw/virtio/vhost-vdpa.c | 161 +++++++++++++++++++++++++---- 4 files changed, 238 insertions(+), 40 deletions(-)
hw/virtio/vhost-shadow-virtqueue.h +2 -1
@@ -12,6 +12,7 @@#include "hw/virtio/vhost.h" #include "qemu/event_notifier.h" +#include "hw/virtio/vhost-iova-tree.h" typedef struct VhostShadowVirtqueue VhostShadowVirtqueue ;
@@ -37,7 +38,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, VirtQueue *vq);void vhost_svq_stop (VhostShadowVirtqueue *svq); -VhostShadowVirtqueue *vhost_svq_new (uint16_t qsize); +VhostShadowVirtqueue *vhost_svq_new (uint16_t qsize,VhostIOVATree *iova_map);void vhost_svq_free (VhostShadowVirtqueue *vq);
include/hw/virtio/vhost-vdpa.h +3 -0
@@ -14,6 +14,7 @@#include <gmodule.h> +#include "hw/virtio/vhost-iova-tree.h" #include "hw/virtio/virtio.h" #include "standard-headers/linux/vhost_types.h"
@@ -30,6 +31,8 @@ typedef struct vhost_vdpa {MemoryListener listener;struct vhost_vdpa_iova_range iova_range;bool shadow_vqs_enabled; +/* IOVA mapping used by Shadow Virtqueue */ +VhostIOVATree *iova_tree;GPtrArray *shadow_vqs;struct vhost_dev *dev;VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX ];
hw/virtio/vhost-shadow-virtqueue.c +91 -20
203 lines not on this page · raw message
hw/virtio/vhost-vdpa.c +142 -19
239 lines not on this page · raw message
Signature · 1 line
2.27.0
Re: [PATCH 23/31] vdpa: Add custom IOTLB translations to SVQ
Quoted 121 lines · Eugenio Pérez
Use translations added in VhostIOVATree in SVQ.
Only introduce usage here, not allocation and deallocation. As with previous patches, we use the dead code paths of
shadow_vqs_enabledto avoid commiting too many changes at once. These are impossible to take at the moment.Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-shadow-virtqueue.h | 3 +- include/hw/virtio/vhost-vdpa.h | 3 + hw/virtio/vhost-shadow-virtqueue.c | 111 ++++++++++++++++---- hw/virtio/vhost-vdpa.c | 161 +++++++++++++++++++++++++---- 4 files changed, 238 insertions(+), 40 deletions(-)hw/virtio/vhost-shadow-virtqueue.h +2
-1@@ -12,6 +12,7 @@#include "hw/virtio/vhost.h" #include "qemu/event_notifier.h" +#include "hw/virtio/vhost-iova-tree.h" typedef struct VhostShadowVirtqueue VhostShadowVirtqueue ;@@ -37,7 +38,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, VirtQueue *vq);void vhost_svq_stop (VhostShadowVirtqueue *svq); -VhostShadowVirtqueue *vhost_svq_new (uint16_t qsize); +VhostShadowVirtqueue *vhost_svq_new (uint16_t qsize,VhostIOVATree *iova_map);void vhost_svq_free (VhostShadowVirtqueue *vq);include/hw/virtio/vhost-vdpa.h +3
-0@@ -14,6 +14,7 @@#include <gmodule.h> +#include "hw/virtio/vhost-iova-tree.h" #include "hw/virtio/virtio.h" #include "standard-headers/linux/vhost_types.h" @@ -30,6 +31,8 @@ typedef struct vhost_vdpa {MemoryListener listener;struct vhost_vdpa_iova_range iova_range;bool shadow_vqs_enabled; +/* IOVA mapping used by Shadow Virtqueue */ +VhostIOVATree *iova_tree;GPtrArray *shadow_vqs;struct vhost_dev *dev;VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX ];hw/virtio/vhost-shadow-virtqueue.c +28
-7@@ -11,6 +11,7 @@#include "hw/virtio/vhost-shadow-virtqueue.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-access.h" +#include "hw/virtio/vhost-iova-tree.h" #include "standard-headers/linux/vhost_types.h" #include "qemu/error-report.h" @@ -45,6 +46,9 @@ typedef struct VhostShadowVirtqueue {/* Virtio device */ VirtIODevice *vdev; +/* IOVA mapping */ +VhostIOVATree *iova_tree; +/* Map for returning guest's descriptors */ VirtQueueElement **ring_id_maps;@@ -97,13 +101,7 @@ bool vhost_svq_valid_device_features(uint64_t *dev_features)continue ;case VIRTIO_F_ACCESS_PLATFORM : -/* SVQ does not know how to translate addresses */ -if (*dev_features &BIT_ULL (b)) { -clear_bit (b, dev_features); - r = false; - } -break ; - +/* SVQ trust in host's IOMMU to translate addresses */ case VIRTIO_F_VERSION_1 :/* SVQ trust that guest vring is little endian */ if (!(*dev_features &BIT_ULL (b))) {@@ -205,7 +203,55 @@ static void vhost_svq_set_notification(VhostShadowVirtqueue *svq, bool enable) } } +/** +* Translate addresses between qemu's virtual address and SVQ IOVA +* +* @svq Shadow VirtQueue +* @vaddr Translated IOVA addresses +* @iovec Source qemu's VA addresses +* @num Length of iovec and minimum length of vaddr +*/ +static bool vhost_svq_translate_addr (const VhostShadowVirtqueue *svq, +void **addrs,const struct iovec *iovec, +size_t num) +{ +size_t i; + +if (num ==0 ) { +return true; + } + +for (i =0 ; i < num; ++i) { +DMAMap needle = { + .translated_addr = (hwaddr )iovec[i].iov_base, + .size = iovec[i].iov_len, + };
hw/virtio/vhost-shadow-virtqueue.c static void vhost_svq_set_notification(VhostShadowVirtqueue *svq, bool enable) · line 238
Quoted 10 lines
hw/virtio/vhost-shadow-virtqueue.c +10
-0+size_t off; + +const DMAMap *map =vhost_iova_tree_find_iova (svq->iova_tree, &needle); +/* +* Map cannot be NULL since iova map contains all guest space and +* qemu already has a physical address mapped +*/ +if (unlikely (!map)) { +error_report ("Invalid address 0x%" HWADDR_PRIx" given by guest" , + needle.translated_addr);
This can be triggered by guest, we need use once or log_guest_error() etc.
hw/virtio/vhost-shadow-virtqueue.c static void vhost_svq_set_notification(VhostShadowVirtqueue *svq, bool enable) · line 245
Quoted 7 lines
hw/virtio/vhost-shadow-virtqueue.c +7
-0+return false; + } + +/* +* Map->iova chunk size is ignored. What to do if descriptor +* (addr, size) does not fit is delegated to the device. +*/
I think we need at least check the size and fail if the size doesn't match here. Or is it possible that we have a buffer that may cross two memory regions?
Quoted 22 lines
hw/virtio/vhost-shadow-virtqueue.c +9
-1+ off = needle.translated_addr - map->translated_addr; + addrs[i] = (void *)(map->iova + off); + } + +return true; +} +static void vhost_vring_write_descs (VhostShadowVirtqueue *svq, +void *const *vaddr_sg,const struct iovec *iovec,size_t num,bool more_descs,bool write) {@@ -224,7 +270,7 @@ static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, }else { descs[i].flags = flags; } - descs[i].addr =cpu_to_le64 ((hwaddr )iovec[n].iov_base); + descs[i].addr =cpu_to_le64 ((hwaddr )vaddr_sg[n]); descs[i].len =cpu_to_le32 (iovec[n].iov_len); last = i;
hw/virtio/vhost-shadow-virtqueue.c static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, · line 285
Quoted 8 lines
hw/virtio/vhost-shadow-virtqueue.c +3
-2@@ -234,42 +280,60 @@ static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, svq->free_head =le16_to_cpu (descs[last].next); } -static unsigned vhost_svq_add_split (VhostShadowVirtqueue *svq, -VirtQueueElement *elem) +static bool vhost_svq_add_split (VhostShadowVirtqueue *svq, +VirtQueueElement *elem, +unsigned *head)
I'd suggest to make it returns bool since the patch that introduces this function.
Quoted 113 lines
hw/virtio/vhost-shadow-virtqueue.c +34
-10{ -int head;unsigned avail_idx;vring_avail_t *avail = svq->vring.avail; +bool ok; + g_autofree void **sgs = g_new(void *, MAX(elem->out_num, elem->in_num)); - head = svq->free_head; + *head = svq->free_head;/* We need some descriptors here */ assert (elem->out_num || elem->in_num); -vhost_vring_write_descs (svq, elem->out_sg, elem->out_num, + ok =vhost_svq_translate_addr (svq, sgs, elem->out_sg, elem->out_num); +if (unlikely (!ok)) { +return false; + } +vhost_vring_write_descs (svq, sgs, elem->out_sg, elem->out_num, elem->in_num >0 , false); -vhost_vring_write_descs (svq, elem->in_sg, elem->in_num, false, true); + + + ok =vhost_svq_translate_addr (svq, sgs, elem->in_sg, elem->in_num); +if (unlikely (!ok)) { +return false; + } + +vhost_vring_write_descs (svq, sgs, elem->in_sg, elem->in_num, false, true);/* * Put entry in available array (but don't update avail->idx until they * do sync). */ avail_idx = svq->avail_idx_shadow & (svq->vring.num -1 ); - avail->ring[avail_idx] =cpu_to_le16 (head); + avail->ring[avail_idx] =cpu_to_le16 (*head); svq->avail_idx_shadow++;/* Update avail index after the descriptor is wrote */ smp_wmb (); avail->idx =cpu_to_le16 (svq->avail_idx_shadow); -return head; +return true; } -static void vhost_svq_add (VhostShadowVirtqueue *svq,VirtQueueElement *elem) +static bool vhost_svq_add (VhostShadowVirtqueue *svq,VirtQueueElement *elem) { -unsigned qemu_head =vhost_svq_add_split (svq, elem); +unsigned qemu_head; +bool ok =vhost_svq_add_split (svq, elem, &qemu_head); +if (unlikely (!ok)) { +return false; + } svq->ring_id_maps[qemu_head] = elem; +return true; }static void vhost_svq_kick (VhostShadowVirtqueue *svq)@@ -309,6 +373,7 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueue *svq)while (true) {VirtQueueElement *elem; +bool ok;if (svq->next_guest_avail_elem) { elem =g_steal_pointer (&svq->next_guest_avail_elem);@@ -337,7 +402,11 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueue *svq)return ; } -vhost_svq_add (svq, elem); + ok =vhost_svq_add (svq, elem); +if (unlikely (!ok)) { +/* VQ is broken, just return and ignore any other kicks */ +return ; + }vhost_svq_kick (svq); }@@ -619,12 +688,13 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq)* methods and file descriptors. * * @qsize Shadow VirtQueue size +* @iova_tree Tree to perform descriptors translations * * Returns the new virtqueue or NULL. * * In case of error, reason is reported through error_report. */ -VhostShadowVirtqueue *vhost_svq_new (uint16_t qsize) +VhostShadowVirtqueue *vhost_svq_new (uint16_t qsize,VhostIOVATree *iova_tree) {size_t desc_size =sizeof (vring_desc_t) * qsize;size_t device_size, driver_size;@@ -656,6 +726,7 @@ VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize)memset (svq->vring.desc,0 , driver_size); svq->vring.used =qemu_memalign (qemu_real_host_page_size, device_size);memset (svq->vring.used,0 , device_size); + svq->iova_tree = iova_tree; svq->ring_id_maps = g_new0(VirtQueueElement *, qsize);event_notifier_set_handler (&svq->hdev_call, vhost_svq_handle_call);return g_steal_pointer (&svq);hw/virtio/vhost-vdpa.c +0
-0@@ -209,6 +209,18 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, vaddr, section->readonly);
hw/virtio/vhost-vdpa.c static void vhost_vdpa_listener_region_add(MemoryListener *listener, · line 220
Quoted 10 lines
hw/virtio/vhost-vdpa.c +9
-0llsize =int128_sub (llend,int128_make64 (iova)); +if (v->shadow_vqs_enabled) { +DMAMap mem_region = { + .translated_addr = (hwaddr )vaddr, + .size =int128_get64 (llsize) -1 , + .perm =IOMMU_ACCESS_FLAG (true, section->readonly), + }; + +int r =vhost_iova_tree_map_alloc (v->iova_tree, &mem_region); +assert (r ==IOVA_OK );
It's better to fail or warn here.
Quoted 216 lines
hw/virtio/vhost-vdpa.c +119
-19+ + iova = mem_region.iova; + }vhost_vdpa_iotlb_batch_begin_once (v); ret = vhost_vdpa_dma_map(v, iova, int128_get64(llsize),@@ -261,6 +273,20 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener, llsize =int128_sub (llend,int128_make64 (iova)); +if (v->shadow_vqs_enabled) { +const DMAMap *result; +const void *vaddr =memory_region_get_ram_ptr (section->mr) + + section->offset_within_region + + (iova - section->offset_within_address_space); +DMAMap mem_region = { + .translated_addr = (hwaddr )vaddr, + .size =int128_get64 (llsize) -1 , + }; + + result =vhost_iova_tree_find_iova (v->iova_tree, &mem_region); + iova = result->iova; +vhost_iova_tree_remove (v->iova_tree, &mem_region); + }vhost_vdpa_iotlb_batch_begin_once (v); ret =vhost_vdpa_dma_unmap (v, iova,int128_get64 (llsize));if (ret) {@@ -783,33 +809,70 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev,/** * Unmap SVQ area in the device */ -static bool vhost_vdpa_svq_unmap_ring (struct vhost_vdpa *v,hwaddr iova, -hwaddr size) +static bool vhost_vdpa_svq_unmap_ring (struct vhost_vdpa *v, +const DMAMap *needle) { +const DMAMap *result =vhost_iova_tree_find_iova (v->iova_tree, needle); +hwaddr size;int r; - size =ROUND_UP (size, qemu_real_host_page_size); - r =vhost_vdpa_dma_unmap (v, iova, size); +if (unlikely (!result)) { +error_report ("Unable to find SVQ address to unmap" ); +return false; + } + + size =ROUND_UP (result->size, qemu_real_host_page_size); + r =vhost_vdpa_dma_unmap (v, result->iova, size);return r ==0 ; }static bool vhost_vdpa_svq_unmap_rings (struct vhost_dev *dev,const VhostShadowVirtqueue *svq) { +DMAMap needle;struct vhost_vdpa *v = dev->opaque;struct vhost_vring_addr svq_addr; -size_t device_size =vhost_svq_device_area_size (svq); -size_t driver_size =vhost_svq_driver_area_size (svq);bool ok;vhost_svq_get_vring_addr (svq, &svq_addr); - ok =vhost_vdpa_svq_unmap_ring (v, svq_addr.desc_user_addr, driver_size); + needle = (DMAMap ) { + .translated_addr = svq_addr.desc_user_addr, + }; + ok =vhost_vdpa_svq_unmap_ring (v, &needle);if (unlikely (!ok)) {return false; } -return vhost_vdpa_svq_unmap_ring (v, svq_addr.used_user_addr, device_size); + needle = (DMAMap ) { + .translated_addr = svq_addr.used_user_addr, + }; +return vhost_vdpa_svq_unmap_ring (v, &needle); +} + +/** +* Map SVQ area in the device +* +* @v Vhost-vdpa device +* @needle The area to search iova +* @readonly Permissions of the area +*/ +static bool vhost_vdpa_svq_map_ring (struct vhost_vdpa *v,const DMAMap *needle, +bool readonly) +{ +hwaddr off; +const DMAMap *result =vhost_iova_tree_find_iova (v->iova_tree, needle); +int r; + +if (unlikely (!result)) { +error_report ("Can't locate SVQ ring" ); +return false; + } + + off = needle->translated_addr - result->translated_addr; + r =vhost_vdpa_dma_map (v, result->iova + off, needle->size, + (void *)needle->translated_addr, readonly); +return r ==0 ; }/** @@ -821,23 +884,29 @@ static bool vhost_vdpa_svq_unmap_rings(struct vhost_dev *dev,static bool vhost_vdpa_svq_map_rings (struct vhost_dev *dev,const VhostShadowVirtqueue *svq) { +DMAMap needle;struct vhost_vdpa *v = dev->opaque;struct vhost_vring_addr svq_addr;size_t device_size =vhost_svq_device_area_size (svq);size_t driver_size =vhost_svq_driver_area_size (svq); -int r; +bool ok;vhost_svq_get_vring_addr (svq, &svq_addr); - r =vhost_vdpa_dma_map (v, svq_addr.desc_user_addr, driver_size, - (void *)svq_addr.desc_user_addr, true); -if (unlikely (r !=0 )) { + needle = (DMAMap ) { + .translated_addr = svq_addr.desc_user_addr, + .size = driver_size, + }; + ok =vhost_vdpa_svq_map_ring (v, &needle, true); +if (unlikely (!ok)) {return false; } - r =vhost_vdpa_dma_map (v, svq_addr.used_user_addr, device_size, - (void *)svq_addr.used_user_addr, false); -return r ==0 ; + needle = (DMAMap ) { + .translated_addr = svq_addr.used_user_addr, + .size = device_size, + }; +return vhost_vdpa_svq_map_ring (v, &needle, false); } static bool vhost_vdpa_svq_setup(struct vhost_dev *dev,@@ -1006,6 +1075,23 @@ static int vhost_vdpa_set_owner(struct vhost_dev *dev)return vhost_vdpa_call (dev,VHOST_SET_OWNER ,NULL ); } +static bool vhost_vdpa_svq_get_vq_region (struct vhost_vdpa *v, +unsigned long long addr, +uint64_t *iova_addr) +{ +const DMAMap needle = { + .translated_addr = addr, + }; +const DMAMap *translation =vhost_iova_tree_find_iova (v->iova_tree, + &needle); +if (!translation) { +return false; + } + + *iova_addr = translation->iova + (addr - translation->translated_addr); +return true; +} +static void vhost_vdpa_vq_get_guest_addr (struct vhost_vring_addr *addr,struct vhost_virtqueue *vq) {@@ -1023,10 +1109,23 @@ static int vhost_vdpa_vq_get_addr(struct vhost_dev *dev,assert (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_VDPA );if (v->shadow_vqs_enabled) { +struct vhost_vring_addr svq_addr;int idx =vhost_vdpa_get_vq_index (dev, addr->index);VhostShadowVirtqueue *svq =g_ptr_array_index (v->shadow_vqs, idx); -vhost_svq_get_vring_addr (svq, addr); +vhost_svq_get_vring_addr (svq, &svq_addr); +if (!vhost_vdpa_svq_get_vq_region (v, svq_addr.desc_user_addr, + &addr->desc_user_addr)) { +return -1 ; + } +if (!vhost_vdpa_svq_get_vq_region (v, svq_addr.avail_user_addr, + &addr->avail_user_addr)) { +return -1 ; + } +if (!vhost_vdpa_svq_get_vq_region (v, svq_addr.used_user_addr, + &addr->used_user_addr)) { +return -1 ; + } }else {vhost_vdpa_vq_get_guest_addr (addr, vq); }@@ -1095,13 +1194,37 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v, shadow_vqs =g_ptr_array_new_full (hdev->nvqs, vhost_psvq_free);for (unsigned n =0 ; n < hdev->nvqs; ++n) { -VhostShadowVirtqueue *svq =vhost_svq_new (qsize); - +DMAMap device_region, driver_region; +struct vhost_vring_addr addr; +VhostShadowVirtqueue *svq =vhost_svq_new (qsize, v->iova_tree);if (unlikely (!svq)) {error_setg (errp,"Cannot create svq %u" , n);return -1 ; } -g_ptr_array_add (v->shadow_vqs, svq); + +vhost_svq_get_vring_addr (svq, &addr); + driver_region = (DMAMap ) { + .translated_addr = (hwaddr )addr.desc_user_addr, + +/* +* DMAMAp.size include the last byte included in the range, while +* sizeof marks one past it. Substract one byte to make them match. +*/ + .size =vhost_svq_driver_area_size (svq) -1 ,
hw/virtio/vhost-vdpa.c static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v, · line 1223
Quoted 10 lines
hw/virtio/vhost-vdpa.c +10
-0+ .perm = VHOST_ACCESS_RO, + }; + device_region = (DMAMap ) { + .translated_addr = (hwaddr )addr.used_user_addr, + .size =vhost_svq_device_area_size (svq) -1 , + .perm =VHOST_ACCESS_RW , + }; + + r =vhost_iova_tree_map_alloc (v->iova_tree, &driver_region); +assert (r ==IOVA_OK );
Let's fail instead of assert here.
Thanks
hw/virtio/vhost-vdpa.c static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v, · line 1230
Quoted 7 lines
hw/virtio/vhost-vdpa.c +4
-0+ r =vhost_iova_tree_map_alloc (v->iova_tree, &device_region); +assert (r ==IOVA_OK ); + +g_ptr_array_add (shadow_vqs, svq); } out:
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Eugenio Perez Martin
maintainerRe: [PATCH 23/31] vdpa: Add custom IOTLB translations to SVQ
Quoted 129 lines · Jason Wang
Quoted 126 lines · Eugenio Pérez
Use translations added in VhostIOVATree in SVQ.
Only introduce usage here, not allocation and deallocation. As with previous patches, we use the dead code paths of
shadow_vqs_enabledto avoid commiting too many changes at once. These are impossible to take at the moment.Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-shadow-virtqueue.h | 3 +- include/hw/virtio/vhost-vdpa.h | 3 + hw/virtio/vhost-shadow-virtqueue.c | 111 ++++++++++++++++---- hw/virtio/vhost-vdpa.c | 161 +++++++++++++++++++++++++---- 4 files changed, 238 insertions(+), 40 deletions(-)hw/virtio/vhost-shadow-virtqueue.h +2
-1@@ -12,6 +12,7 @@#include "hw/virtio/vhost.h" #include "qemu/event_notifier.h" +#include "hw/virtio/vhost-iova-tree.h" typedef struct VhostShadowVirtqueue VhostShadowVirtqueue ;@@ -37,7 +38,7 @@ void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, VirtQueue *vq);void vhost_svq_stop (VhostShadowVirtqueue *svq); -VhostShadowVirtqueue *vhost_svq_new (uint16_t qsize); +VhostShadowVirtqueue *vhost_svq_new (uint16_t qsize,VhostIOVATree *iova_map);void vhost_svq_free (VhostShadowVirtqueue *vq);include/hw/virtio/vhost-vdpa.h +3
-0@@ -14,6 +14,7 @@#include <gmodule.h> +#include "hw/virtio/vhost-iova-tree.h" #include "hw/virtio/virtio.h" #include "standard-headers/linux/vhost_types.h" @@ -30,6 +31,8 @@ typedef struct vhost_vdpa {MemoryListener listener;struct vhost_vdpa_iova_range iova_range;bool shadow_vqs_enabled; +/* IOVA mapping used by Shadow Virtqueue */ +VhostIOVATree *iova_tree;GPtrArray *shadow_vqs;struct vhost_dev *dev;VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX ];hw/virtio/vhost-shadow-virtqueue.c +33
-7@@ -11,6 +11,7 @@#include "hw/virtio/vhost-shadow-virtqueue.h" #include "hw/virtio/vhost.h" #include "hw/virtio/virtio-access.h" +#include "hw/virtio/vhost-iova-tree.h" #include "standard-headers/linux/vhost_types.h" #include "qemu/error-report.h" @@ -45,6 +46,9 @@ typedef struct VhostShadowVirtqueue {/* Virtio device */ VirtIODevice *vdev; +/* IOVA mapping */ +VhostIOVATree *iova_tree; +/* Map for returning guest's descriptors */ VirtQueueElement **ring_id_maps;@@ -97,13 +101,7 @@ bool vhost_svq_valid_device_features(uint64_t *dev_features)continue ;case VIRTIO_F_ACCESS_PLATFORM : -/* SVQ does not know how to translate addresses */ -if (*dev_features &BIT_ULL (b)) { -clear_bit (b, dev_features); - r = false; - } -break ; - +/* SVQ trust in host's IOMMU to translate addresses */ case VIRTIO_F_VERSION_1 :/* SVQ trust that guest vring is little endian */ if (!(*dev_features &BIT_ULL (b))) {@@ -205,7 +203,55 @@ static void vhost_svq_set_notification(VhostShadowVirtqueue *svq, bool enable) } } +/** +* Translate addresses between qemu's virtual address and SVQ IOVA +* +* @svq Shadow VirtQueue +* @vaddr Translated IOVA addresses +* @iovec Source qemu's VA addresses +* @num Length of iovec and minimum length of vaddr +*/ +static bool vhost_svq_translate_addr (const VhostShadowVirtqueue *svq, +void **addrs,const struct iovec *iovec, +size_t num) +{ +size_t i; + +if (num ==0 ) { +return true; + } + +for (i =0 ; i < num; ++i) { +DMAMap needle = { + .translated_addr = (hwaddr )iovec[i].iov_base, + .size = iovec[i].iov_len, + }; +size_t off; + +const DMAMap *map =vhost_iova_tree_find_iova (svq->iova_tree, &needle); +/* +* Map cannot be NULL since iova map contains all guest space and
Quoted 9 lines
hw/virtio/vhost-shadow-virtqueue.c static void vhost_svq_set_notification(VhostShadowVirtqueue *svq, bool enable) · line 238
Quoted 5 lines
hw/virtio/vhost-shadow-virtqueue.c +5
-0+* qemu already has a physical address mapped +*/ +if (unlikely (!map)) { +error_report ("Invalid address 0x%" HWADDR_PRIx" given by guest" , + needle.translated_addr);This can be triggered by guest, we need use once or
log_guest_error()etc.
Ok I see the issue, I will change.
Quoted 10 lines
hw/virtio/vhost-shadow-virtqueue.c static void vhost_svq_set_notification(VhostShadowVirtqueue *svq, bool enable) · line 245
Quoted 8 lines
hw/virtio/vhost-shadow-virtqueue.c +7
-0+return false; + } + +/* +* Map->iova chunk size is ignored. What to do if descriptor +* (addr, size) does not fit is delegated to the device. +*/
Quoted 4 lines
I think we need at least check the size and fail if the size doesn't match here. Or is it possible that we have a buffer that may cross two memory regions?
It should be impossible, since both iova_tree and VirtQueue should be in sync regarding the memory regions updates. If a VirtQueue buffer crosses many memory regions, iovec has more entries.
I can add a return false, but I'm not able to trigger that situation even with a malformed driver.
Quoted 26 lines
Quoted 26 lines
hw/virtio/vhost-shadow-virtqueue.c +9
-1+ off = needle.translated_addr - map->translated_addr; + addrs[i] = (void *)(map->iova + off); + } + +return true; +} +static void vhost_vring_write_descs (VhostShadowVirtqueue *svq, +void *const *vaddr_sg,const struct iovec *iovec,size_t num,bool more_descs,bool write) {@@ -224,7 +270,7 @@ static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, }else { descs[i].flags = flags; } - descs[i].addr =cpu_to_le64 ((hwaddr )iovec[n].iov_base); + descs[i].addr =cpu_to_le64 ((hwaddr )vaddr_sg[n]); descs[i].len =cpu_to_le32 (iovec[n].iov_len); last = i;@@ -234,42 +280,60 @@ static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, svq->free_head =le16_to_cpu (descs[last].next); }
Quoted 10 lines
hw/virtio/vhost-shadow-virtqueue.c static void vhost_vring_write_descs(VhostShadowVirtqueue *svq, · line 285
Quoted 5 lines
hw/virtio/vhost-shadow-virtqueue.c +3
-2-static unsigned vhost_svq_add_split (VhostShadowVirtqueue *svq, -VirtQueueElement *elem) +static bool vhost_svq_add_split (VhostShadowVirtqueue *svq, +VirtQueueElement *elem, +unsigned *head)I'd suggest to make it returns bool since the patch that introduces this function.
Ok I will do it from the start.
Quoted 114 lines
Quoted 114 lines
hw/virtio/vhost-shadow-virtqueue.c +34
-10{ -int head;unsigned avail_idx;vring_avail_t *avail = svq->vring.avail; +bool ok; + g_autofree void **sgs = g_new(void *, MAX(elem->out_num, elem->in_num)); - head = svq->free_head; + *head = svq->free_head;/* We need some descriptors here */ assert (elem->out_num || elem->in_num); -vhost_vring_write_descs (svq, elem->out_sg, elem->out_num, + ok =vhost_svq_translate_addr (svq, sgs, elem->out_sg, elem->out_num); +if (unlikely (!ok)) { +return false; + } +vhost_vring_write_descs (svq, sgs, elem->out_sg, elem->out_num, elem->in_num >0 , false); -vhost_vring_write_descs (svq, elem->in_sg, elem->in_num, false, true); + + + ok =vhost_svq_translate_addr (svq, sgs, elem->in_sg, elem->in_num); +if (unlikely (!ok)) { +return false; + } + +vhost_vring_write_descs (svq, sgs, elem->in_sg, elem->in_num, false, true);/* * Put entry in available array (but don't update avail->idx until they * do sync). */ avail_idx = svq->avail_idx_shadow & (svq->vring.num -1 ); - avail->ring[avail_idx] =cpu_to_le16 (head); + avail->ring[avail_idx] =cpu_to_le16 (*head); svq->avail_idx_shadow++;/* Update avail index after the descriptor is wrote */ smp_wmb (); avail->idx =cpu_to_le16 (svq->avail_idx_shadow); -return head; +return true; } -static void vhost_svq_add (VhostShadowVirtqueue *svq,VirtQueueElement *elem) +static bool vhost_svq_add (VhostShadowVirtqueue *svq,VirtQueueElement *elem) { -unsigned qemu_head =vhost_svq_add_split (svq, elem); +unsigned qemu_head; +bool ok =vhost_svq_add_split (svq, elem, &qemu_head); +if (unlikely (!ok)) { +return false; + } svq->ring_id_maps[qemu_head] = elem; +return true; }static void vhost_svq_kick (VhostShadowVirtqueue *svq)@@ -309,6 +373,7 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueue *svq)while (true) {VirtQueueElement *elem; +bool ok;if (svq->next_guest_avail_elem) { elem =g_steal_pointer (&svq->next_guest_avail_elem);@@ -337,7 +402,11 @@ static void vhost_handle_guest_kick(VhostShadowVirtqueue *svq)return ; } -vhost_svq_add (svq, elem); + ok =vhost_svq_add (svq, elem); +if (unlikely (!ok)) { +/* VQ is broken, just return and ignore any other kicks */ +return ; + }vhost_svq_kick (svq); }@@ -619,12 +688,13 @@ void vhost_svq_stop(VhostShadowVirtqueue *svq)* methods and file descriptors. * * @qsize Shadow VirtQueue size +* @iova_tree Tree to perform descriptors translations * * Returns the new virtqueue or NULL. * * In case of error, reason is reported through error_report. */ -VhostShadowVirtqueue *vhost_svq_new (uint16_t qsize) +VhostShadowVirtqueue *vhost_svq_new (uint16_t qsize,VhostIOVATree *iova_tree) {size_t desc_size =sizeof (vring_desc_t) * qsize;size_t device_size, driver_size;@@ -656,6 +726,7 @@ VhostShadowVirtqueue *vhost_svq_new(uint16_t qsize)memset (svq->vring.desc,0 , driver_size); svq->vring.used =qemu_memalign (qemu_real_host_page_size, device_size);memset (svq->vring.used,0 , device_size); + svq->iova_tree = iova_tree; svq->ring_id_maps = g_new0(VirtQueueElement *, qsize);event_notifier_set_handler (&svq->hdev_call, vhost_svq_handle_call);return g_steal_pointer (&svq);hw/virtio/vhost-vdpa.c +0
-0@@ -209,6 +209,18 @@ static void vhost_vdpa_listener_region_add(MemoryListener *listener, vaddr, section->readonly);
Quoted 14 lines
hw/virtio/vhost-vdpa.c static void vhost_vdpa_listener_region_add(MemoryListener *listener, · line 220
Quoted 10 lines
hw/virtio/vhost-vdpa.c +9
-0llsize =int128_sub (llend,int128_make64 (iova)); +if (v->shadow_vqs_enabled) { +DMAMap mem_region = { + .translated_addr = (hwaddr )vaddr, + .size =int128_get64 (llsize) -1 , + .perm =IOMMU_ACCESS_FLAG (true, section->readonly), + }; + +int r =vhost_iova_tree_map_alloc (v->iova_tree, &mem_region); +assert (r ==IOVA_OK );It's better to fail or warn here.
Sure, a warning is possible.
Quoted 222 lines
Quoted 222 lines
hw/virtio/vhost-vdpa.c +124
-19+ + iova = mem_region.iova; + }vhost_vdpa_iotlb_batch_begin_once (v); ret = vhost_vdpa_dma_map(v, iova, int128_get64(llsize),@@ -261,6 +273,20 @@ static void vhost_vdpa_listener_region_del(MemoryListener *listener, llsize =int128_sub (llend,int128_make64 (iova)); +if (v->shadow_vqs_enabled) { +const DMAMap *result; +const void *vaddr =memory_region_get_ram_ptr (section->mr) + + section->offset_within_region + + (iova - section->offset_within_address_space); +DMAMap mem_region = { + .translated_addr = (hwaddr )vaddr, + .size =int128_get64 (llsize) -1 , + }; + + result =vhost_iova_tree_find_iova (v->iova_tree, &mem_region); + iova = result->iova; +vhost_iova_tree_remove (v->iova_tree, &mem_region); + }vhost_vdpa_iotlb_batch_begin_once (v); ret =vhost_vdpa_dma_unmap (v, iova,int128_get64 (llsize));if (ret) {@@ -783,33 +809,70 @@ static int vhost_vdpa_svq_set_fds(struct vhost_dev *dev,/** * Unmap SVQ area in the device */ -static bool vhost_vdpa_svq_unmap_ring (struct vhost_vdpa *v,hwaddr iova, -hwaddr size) +static bool vhost_vdpa_svq_unmap_ring (struct vhost_vdpa *v, +const DMAMap *needle) { +const DMAMap *result =vhost_iova_tree_find_iova (v->iova_tree, needle); +hwaddr size;int r; - size =ROUND_UP (size, qemu_real_host_page_size); - r =vhost_vdpa_dma_unmap (v, iova, size); +if (unlikely (!result)) { +error_report ("Unable to find SVQ address to unmap" ); +return false; + } + + size =ROUND_UP (result->size, qemu_real_host_page_size); + r =vhost_vdpa_dma_unmap (v, result->iova, size);return r ==0 ; }static bool vhost_vdpa_svq_unmap_rings (struct vhost_dev *dev,const VhostShadowVirtqueue *svq) { +DMAMap needle;struct vhost_vdpa *v = dev->opaque;struct vhost_vring_addr svq_addr; -size_t device_size =vhost_svq_device_area_size (svq); -size_t driver_size =vhost_svq_driver_area_size (svq);bool ok;vhost_svq_get_vring_addr (svq, &svq_addr); - ok =vhost_vdpa_svq_unmap_ring (v, svq_addr.desc_user_addr, driver_size); + needle = (DMAMap ) { + .translated_addr = svq_addr.desc_user_addr, + }; + ok =vhost_vdpa_svq_unmap_ring (v, &needle);if (unlikely (!ok)) {return false; } -return vhost_vdpa_svq_unmap_ring (v, svq_addr.used_user_addr, device_size); + needle = (DMAMap ) { + .translated_addr = svq_addr.used_user_addr, + }; +return vhost_vdpa_svq_unmap_ring (v, &needle); +} + +/** +* Map SVQ area in the device +* +* @v Vhost-vdpa device +* @needle The area to search iova +* @readonly Permissions of the area +*/ +static bool vhost_vdpa_svq_map_ring (struct vhost_vdpa *v,const DMAMap *needle, +bool readonly) +{ +hwaddr off; +const DMAMap *result =vhost_iova_tree_find_iova (v->iova_tree, needle); +int r; + +if (unlikely (!result)) { +error_report ("Can't locate SVQ ring" ); +return false; + } + + off = needle->translated_addr - result->translated_addr; + r =vhost_vdpa_dma_map (v, result->iova + off, needle->size, + (void *)needle->translated_addr, readonly); +return r ==0 ; }/** @@ -821,23 +884,29 @@ static bool vhost_vdpa_svq_unmap_rings(struct vhost_dev *dev,static bool vhost_vdpa_svq_map_rings (struct vhost_dev *dev,const VhostShadowVirtqueue *svq) { +DMAMap needle;struct vhost_vdpa *v = dev->opaque;struct vhost_vring_addr svq_addr;size_t device_size =vhost_svq_device_area_size (svq);size_t driver_size =vhost_svq_driver_area_size (svq); -int r; +bool ok;vhost_svq_get_vring_addr (svq, &svq_addr); - r =vhost_vdpa_dma_map (v, svq_addr.desc_user_addr, driver_size, - (void *)svq_addr.desc_user_addr, true); -if (unlikely (r !=0 )) { + needle = (DMAMap ) { + .translated_addr = svq_addr.desc_user_addr, + .size = driver_size, + }; + ok =vhost_vdpa_svq_map_ring (v, &needle, true); +if (unlikely (!ok)) {return false; } - r =vhost_vdpa_dma_map (v, svq_addr.used_user_addr, device_size, - (void *)svq_addr.used_user_addr, false); -return r ==0 ; + needle = (DMAMap ) { + .translated_addr = svq_addr.used_user_addr, + .size = device_size, + }; +return vhost_vdpa_svq_map_ring (v, &needle, false); } static bool vhost_vdpa_svq_setup(struct vhost_dev *dev,@@ -1006,6 +1075,23 @@ static int vhost_vdpa_set_owner(struct vhost_dev *dev)return vhost_vdpa_call (dev,VHOST_SET_OWNER ,NULL ); } +static bool vhost_vdpa_svq_get_vq_region (struct vhost_vdpa *v, +unsigned long long addr, +uint64_t *iova_addr) +{ +const DMAMap needle = { + .translated_addr = addr, + }; +const DMAMap *translation =vhost_iova_tree_find_iova (v->iova_tree, + &needle); +if (!translation) { +return false; + } + + *iova_addr = translation->iova + (addr - translation->translated_addr); +return true; +} +static void vhost_vdpa_vq_get_guest_addr (struct vhost_vring_addr *addr,struct vhost_virtqueue *vq) {@@ -1023,10 +1109,23 @@ static int vhost_vdpa_vq_get_addr(struct vhost_dev *dev,assert (dev->vhost_ops->backend_type ==VHOST_BACKEND_TYPE_VDPA );if (v->shadow_vqs_enabled) { +struct vhost_vring_addr svq_addr;int idx =vhost_vdpa_get_vq_index (dev, addr->index);VhostShadowVirtqueue *svq =g_ptr_array_index (v->shadow_vqs, idx); -vhost_svq_get_vring_addr (svq, addr); +vhost_svq_get_vring_addr (svq, &svq_addr); +if (!vhost_vdpa_svq_get_vq_region (v, svq_addr.desc_user_addr, + &addr->desc_user_addr)) { +return -1 ; + } +if (!vhost_vdpa_svq_get_vq_region (v, svq_addr.avail_user_addr, + &addr->avail_user_addr)) { +return -1 ; + } +if (!vhost_vdpa_svq_get_vq_region (v, svq_addr.used_user_addr, + &addr->used_user_addr)) { +return -1 ; + } }else {vhost_vdpa_vq_get_guest_addr (addr, vq); }@@ -1095,13 +1194,37 @@ static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v, shadow_vqs =g_ptr_array_new_full (hdev->nvqs, vhost_psvq_free);for (unsigned n =0 ; n < hdev->nvqs; ++n) { -VhostShadowVirtqueue *svq =vhost_svq_new (qsize); - +DMAMap device_region, driver_region; +struct vhost_vring_addr addr; +VhostShadowVirtqueue *svq =vhost_svq_new (qsize, v->iova_tree);if (unlikely (!svq)) {error_setg (errp,"Cannot create svq %u" , n);return -1 ; } -g_ptr_array_add (v->shadow_vqs, svq); + +vhost_svq_get_vring_addr (svq, &addr); + driver_region = (DMAMap ) { + .translated_addr = (hwaddr )addr.desc_user_addr, + +/* +* DMAMAp.size include the last byte included in the range, while +* sizeof marks one past it. Substract one byte to make them match. +*/ + .size =vhost_svq_driver_area_size (svq) -1 , + .perm =VHOST_ACCESS_RO , + }; + device_region = (DMAMap ) { + .translated_addr = (hwaddr )addr.used_user_addr, + .size =vhost_svq_device_area_size (svq) -1 ,
Quoted 9 lines
hw/virtio/vhost-vdpa.c static int vhost_vdpa_init_svq(struct vhost_dev *hdev, struct vhost_vdpa *v, · line 1223
Quoted 5 lines
hw/virtio/vhost-vdpa.c +5
-0+ .perm = VHOST_ACCESS_RW, + }; + + r =vhost_iova_tree_map_alloc (v->iova_tree, &driver_region); +assert (r ==IOVA_OK );Let's fail instead of assert here.
Sure, I see how we must not assert here too.
Thanks!
Quoted 11 lines
Thanks
Quoted 7 lines
hw/virtio/vhost-vdpa.c +4
-0+ r =vhost_iova_tree_map_alloc (v->iova_tree, &device_region); +assert (r ==IOVA_OK ); + +g_ptr_array_add (shadow_vqs, svq); } out:
Re: [PATCH 23/31] vdpa: Add custom IOTLB translations to SVQ
Quoted 11 lines · Eugenio Perez Martin
Quoted 11 lines
hw/virtio/vhost-shadow-virtqueue.c static void vhost_svq_set_notification(VhostShadowVirtqueue *svq, bool enable) · line 245
Quoted 7 lines
hw/virtio/vhost-shadow-virtqueue.c +7
-0+return false; + } + +/* +* Map->iova chunk size is ignored. What to do if descriptor +* (addr, size) does not fit is delegated to the device. +*/ I think we need at least check the size and fail if the size doesn't match here. Or is it possible that we have a buffer that may cross two memory regions?
Quoted 7 lines
It should be impossible, since both
iova_treeand VirtQueue should be in sync regarding the memory regions updates. If a VirtQueue buffer crosses many memory regions, iovec has more entries.I can add a return false, but I'm not able to trigger that situation even with a malformed driver.
Ok, but it won't harm to add a warn here.
Thanks
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Eugenio Pérez
maintainerPATCH 24/31 vhost: Add vhost_svq_get_last_used_idx
In reply to Eugenio PérezThis way SVQ queues can be migrated.
--- hw/virtio/vhost-shadow-virtqueue.h | 1 + hw/virtio/vhost-shadow-virtqueue.c | 8 ++++++++ 2 files changed, 9 insertions(+)
hw/virtio/vhost-shadow-virtqueue.h +1 -0
@@ -30,6 +30,7 @@ const EventNotifier *vhost_svq_get_svq_call_notifier( const VhostShadowVirtqueue *svq);void vhost_svq_get_vring_addr (const VhostShadowVirtqueue *svq,struct vhost_vring_addr *addr); +uint16_t vhost_svq_get_last_used_idx (const VhostShadowVirtqueue *svq);uint16_t vhost_svq_get_num (const VhostShadowVirtqueue *svq);size_t vhost_svq_driver_area_size (const VhostShadowVirtqueue *svq);size_t vhost_svq_device_area_size (const VhostShadowVirtqueue *svq);
hw/virtio/vhost-shadow-virtqueue.c +8 -0
@@ -574,6 +574,14 @@ void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, addr->used_user_addr = (uint64_t )svq->vring.used; } +/** +* Get the next index that SVQ is going to consume from SVQ used ring. +*/ +uint16_t vhost_svq_get_last_used_idx (const VhostShadowVirtqueue *svq) +{ +return svq->last_used_idx; +} +uint16_t vhost_svq_get_num (const VhostShadowVirtqueue *svq) {return svq->vring.num;
Signature · 1 line
2.27.0
Eugenio Pérez
maintainerPATCH 25/31 vdpa: Adapt vhost_vdpa_get_vring_base to SVQ
In reply to Eugenio PérezThis is needed to achieve migration, so destination can restore its index.
--- hw/virtio/vhost-vdpa.c | 9 +++++++++ 1 file changed, 9 insertions(+)
hw/virtio/vhost-vdpa.c +9 -0
@@ -716,8 +716,17 @@ static int vhost_vdpa_set_vring_base(struct vhost_dev *dev,static int vhost_vdpa_get_vring_base (struct vhost_dev *dev,struct vhost_vring_state *ring) { +struct vhost_vdpa *v = dev->opaque;int ret; +if (v->shadow_vqs_enabled) { +VhostShadowVirtqueue *svq =g_ptr_array_index (v->shadow_vqs, + ring->index); + + ring->num =vhost_svq_get_last_used_idx (svq); +return 0 ; + } + ret =vhost_vdpa_call (dev,VHOST_GET_VRING_BASE , ring);trace_vhost_vdpa_get_vring_base (dev, ring->index, ring->num);return ret;
Signature · 1 line
2.27.0
Eugenio Pérez
maintainerPATCH 26/31 vdpa: Clear VHOST_VRING_F_LOG at vhost_vdpa_set_vring_addr in SVQ
In reply to Eugenio PérezDoing so would cause the device to export writes to SVQ addresses, which are not part of the guest's IOVA.
Like the previous patch, this is currently not possible since SVQ does not run if the device exports VHOST_VRING_F_LOG. But it's needed to enable migration with SVQ.
--- hw/virtio/vhost-vdpa.c | 6 ++++++ 1 file changed, 6 insertions(+)
hw/virtio/vhost-vdpa.c +6 -0
@@ -660,10 +660,16 @@ static int vhost_vdpa_set_log_base(struct vhost_dev *dev, uint64_t base,static int vhost_vdpa_set_vring_addr (struct vhost_dev *dev,struct vhost_vring_addr *addr) { +struct vhost_vdpa *v = dev->opaque; +trace_vhost_vdpa_set_vring_addr (dev, addr->index, addr->flags, addr->desc_user_addr, addr->used_user_addr, addr->avail_user_addr, addr->log_guest_addr); + +if (v->shadow_vqs_enabled) { + addr->flags &= ~BIT_ULL (VHOST_VRING_F_LOG ); + }return vhost_vdpa_call (dev,VHOST_SET_VRING_ADDR , addr); }
Signature · 1 line
2.27.0
Eugenio Pérez
maintainerPATCH 27/31 vdpa: Never set log_base addr if SVQ is enabled
In reply to Eugenio PérezSetting the log address would make the device start reporting invalid dirty memory because the SVQ vrings are located in qemu's memory.
--- hw/virtio/vhost-vdpa.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
hw/virtio/vhost-vdpa.c +2 -1
@@ -648,7 +648,8 @@ static int vhost_vdpa_get_config(struct vhost_dev *dev, uint8_t *config,static int vhost_vdpa_set_log_base (struct vhost_dev *dev,uint64_t base,struct vhost_log *log) { -if (vhost_vdpa_one_time_request (dev)) { +struct vhost_vdpa *v = dev->opaque; +if (v->shadow_vqs_enabled ||vhost_vdpa_one_time_request (dev)) {return 0 ; }
Signature · 1 line
2.27.0
Eugenio Pérez
maintainerPATCH 28/31 vdpa: Expose VHOST_F_LOG_ALL on SVQ
In reply to Eugenio PérezSVQ is able to log the dirty bits by itself, so let's use it to not block migration.
Also, ignore set and clear of VHOST_F_LOG_ALL on set_features if SVQ is enabled. Even if the device supports it, the reports would be nonsense because SVQ memory is in the qemu region.
The log region is still allocated. Future changes might skip that, but this series is already long enough.
--- hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
hw/virtio/vhost-vdpa.c +20 -0
@@ -1022,6 +1022,9 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev, uint64_t *features)if (ret ==0 && v->shadow_vqs_enabled) {/* Filter only features that SVQ can offer to guest */ vhost_svq_valid_guest_features (features); + +/* Add SVQ logging capabilities */ + *features |=BIT_ULL (VHOST_F_LOG_ALL ); }return ret;
@@ -1039,8 +1042,25 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,if (v->shadow_vqs_enabled) {uint64_t dev_features, svq_features, acked_features; +uint8_t status =0 ;bool ok; + ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &status); +if (unlikely (ret)) { +return ret; + } + +if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { +/* +* vhost is trying to enable or disable _F_LOG, and the device +* would report wrong dirty pages. SVQ handles it. +*/ +return 0 ; + } + +/* We must not ack _F_LOG if SVQ is enabled */ + features &= ~BIT_ULL (VHOST_F_LOG_ALL ); + ret =vhost_vdpa_get_dev_features (dev, &dev_features);if (ret !=0 ) {error_report ("Can't get vdpa device features, got (%d)" , ret);
Signature · 1 line
2.27.0
Re: [PATCH 28/31] vdpa: Expose VHOST_F_LOG_ALL on SVQ
Quoted 36 lines · Eugenio Pérez
SVQ is able to log the dirty bits by itself, so let's use it to not block migration.
Also, ignore set and clear of
VHOST_F_LOG_ALLonset_featuresif SVQ is enabled. Even if the device supports it, the reports would be nonsense because SVQ memory is in the qemu region.The log region is still allocated. Future changes might skip that, but this series is already long enough.
Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)hw/virtio/vhost-vdpa.c +4
-0@@ -1022,6 +1022,9 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev, uint64_t *features)if (ret ==0 && v->shadow_vqs_enabled) {/* Filter only features that SVQ can offer to guest */ vhost_svq_valid_guest_features (features); + +/* Add SVQ logging capabilities */ + *features |=BIT_ULL (VHOST_F_LOG_ALL ); }return ret;@@ -1039,8 +1042,25 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,if (v->shadow_vqs_enabled) {uint64_t dev_features, svq_features, acked_features; +uint8_t status =0 ;bool ok;
hw/virtio/vhost-vdpa.c static int vhost_vdpa_set_features(struct vhost_dev *dev, · line 1057
Quoted 10 lines
hw/virtio/vhost-vdpa.c +10
-0+ ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &status); +if (unlikely (ret)) { +return ret; + } + +if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { +/* +* vhost is trying to enable or disable _F_LOG, and the device +* would report wrong dirty pages. SVQ handles it. +*/
I fail to understand this comment, I'd think there's no way to disable dirty page tracking for SVQ.
Thanks
hw/virtio/vhost-vdpa.c static int vhost_vdpa_set_features(struct vhost_dev *dev, · line 1066
Quoted 9 lines
hw/virtio/vhost-vdpa.c +6
-0+return 0 ; + } + +/* We must not ack _F_LOG if SVQ is enabled */ + features &= ~BIT_ULL (VHOST_F_LOG_ALL ); + ret =vhost_vdpa_get_dev_features (dev, &dev_features);if (ret !=0 ) {error_report ("Can't get vdpa device features, got (%d)" , ret);
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Eugenio Perez Martin
maintainerRe: [PATCH 28/31] vdpa: Expose VHOST_F_LOG_ALL on SVQ
Quoted 39 lines · Jason Wang
Quoted 36 lines · Eugenio Pérez
SVQ is able to log the dirty bits by itself, so let's use it to not block migration.
Also, ignore set and clear of
VHOST_F_LOG_ALLonset_featuresif SVQ is enabled. Even if the device supports it, the reports would be nonsense because SVQ memory is in the qemu region.The log region is still allocated. Future changes might skip that, but this series is already long enough.
Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)hw/virtio/vhost-vdpa.c +4
-0@@ -1022,6 +1022,9 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev, uint64_t *features)if (ret ==0 && v->shadow_vqs_enabled) {/* Filter only features that SVQ can offer to guest */ vhost_svq_valid_guest_features (features); + +/* Add SVQ logging capabilities */ + *features |=BIT_ULL (VHOST_F_LOG_ALL ); }return ret;@@ -1039,8 +1042,25 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,if (v->shadow_vqs_enabled) {uint64_t dev_features, svq_features, acked_features; +uint8_t status =0 ;bool ok;
Quoted 15 lines
hw/virtio/vhost-vdpa.c static int vhost_vdpa_set_features(struct vhost_dev *dev, · line 1057
Quoted 10 lines
hw/virtio/vhost-vdpa.c +10
-0+ ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &status); +if (unlikely (ret)) { +return ret; + } + +if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { +/* +* vhost is trying to enable or disable _F_LOG, and the device +* would report wrong dirty pages. SVQ handles it. +*/ I fail to understand this comment, I'd think there's no way to disable dirty page tracking for SVQ.
vhost_log_global_{start,stop} are called at the beginning and end of migration. To inform the device that it should start logging, they set or clean VHOST_F_LOG_ALL at vhost_dev_set_log.
While SVQ does not use VHOST_F_LOG_ALL, it exports the feature bit so vhost does not block migration. Maybe we need to look for another way to do this?
Thanks!
Quoted 13 lines
Thanks
Quoted 9 lines
hw/virtio/vhost-vdpa.c +6
-0+return 0 ; + } + +/* We must not ack _F_LOG if SVQ is enabled */ + features &= ~BIT_ULL (VHOST_F_LOG_ALL ); + ret =vhost_vdpa_get_dev_features (dev, &dev_features);if (ret !=0 ) {error_report ("Can't get vdpa device features, got (%d)" , ret);
Re: [PATCH 28/31] vdpa: Expose VHOST_F_LOG_ALL on SVQ
Quoted 53 lines · Eugenio Perez Martin
Quoted 38 lines · Jason Wang
Quoted 36 lines · Eugenio Pérez
SVQ is able to log the dirty bits by itself, so let's use it to not block migration.
Also, ignore set and clear of
VHOST_F_LOG_ALLonset_featuresif SVQ is enabled. Even if the device supports it, the reports would be nonsense because SVQ memory is in the qemu region.The log region is still allocated. Future changes might skip that, but this series is already long enough.
Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)hw/virtio/vhost-vdpa.c +4
-0@@ -1022,6 +1022,9 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev, uint64_t *features)if (ret ==0 && v->shadow_vqs_enabled) {/* Filter only features that SVQ can offer to guest */ vhost_svq_valid_guest_features (features); + +/* Add SVQ logging capabilities */ + *features |=BIT_ULL (VHOST_F_LOG_ALL ); }return ret;@@ -1039,8 +1042,25 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,if (v->shadow_vqs_enabled) {uint64_t dev_features, svq_features, acked_features; +uint8_t status =0 ;bool ok;Quoted 14 lines
hw/virtio/vhost-vdpa.c static int vhost_vdpa_set_features(struct vhost_dev *dev, · line 1057
Quoted 10 lines
hw/virtio/vhost-vdpa.c +10
-0+ ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &status); +if (unlikely (ret)) { +return ret; + } + +if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { +/* +* vhost is trying to enable or disable _F_LOG, and the device +* would report wrong dirty pages. SVQ handles it. +*/ I fail to understand this comment, I'd think there's no way to disable dirty page tracking for SVQ.
Quoted 3 lines
vhost_log_global_{start,stop} are called at the beginning and end of migration. To inform the device that it should start logging, they set or clean
VHOST_F_LOG_ALLatvhost_dev_set_log.
Yes, but for SVQ, we can't disable dirty page tracking, isn't it? The only thing is to ignore or filter out the F_LOG_ALL and pretend to be enabled and disabled.
Quoted 4 lines
While SVQ does not use
VHOST_F_LOG_ALL, it exports the feature bit so vhost does not block migration. Maybe we need to look for another way to do this?
I'm fine with filtering since it's much more simpler, but I fail to understand why we need to check DRIVER_OK.
Thanks
Quoted 6 lines
Thanks!
Quoted 3 lines
Thanks
Quoted 9 lines
Quoted 9 lines
hw/virtio/vhost-vdpa.c static int vhost_vdpa_set_features(struct vhost_dev *dev, · line 1066
Quoted 9 lines
hw/virtio/vhost-vdpa.c +6
-0+return 0 ; + } + +/* We must not ack _F_LOG if SVQ is enabled */ + features &= ~BIT_ULL (VHOST_F_LOG_ALL ); + ret =vhost_vdpa_get_dev_features (dev, &dev_features);if (ret !=0 ) {error_report ("Can't get vdpa device features, got (%d)" , ret);
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Eugenio Perez Martin
maintainerRe: [PATCH 28/31] vdpa: Expose VHOST_F_LOG_ALL on SVQ
Quoted 56 lines · Jason Wang
Quoted 53 lines · Eugenio Perez Martin
Quoted 52 lines · Jason Wang
Quoted 36 lines · Eugenio Pérez
SVQ is able to log the dirty bits by itself, so let's use it to not block migration.
Also, ignore set and clear of
VHOST_F_LOG_ALLonset_featuresif SVQ is enabled. Even if the device supports it, the reports would be nonsense because SVQ memory is in the qemu region.The log region is still allocated. Future changes might skip that, but this series is already long enough.
Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)hw/virtio/vhost-vdpa.c +4
-0@@ -1022,6 +1022,9 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev, uint64_t *features)if (ret ==0 && v->shadow_vqs_enabled) {/* Filter only features that SVQ can offer to guest */ vhost_svq_valid_guest_features (features); + +/* Add SVQ logging capabilities */ + *features |=BIT_ULL (VHOST_F_LOG_ALL ); }return ret;@@ -1039,8 +1042,25 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,if (v->shadow_vqs_enabled) {uint64_t dev_features, svq_features, acked_features; +uint8_t status =0 ;bool ok;hw/virtio/vhost-vdpa.c static int vhost_vdpa_set_features(struct vhost_dev *dev, · line 1057
Quoted 10 lines
hw/virtio/vhost-vdpa.c +10
-0+ ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &status); +if (unlikely (ret)) { +return ret; + } + +if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { +/* +* vhost is trying to enable or disable _F_LOG, and the device +* would report wrong dirty pages. SVQ handles it. +*/ I fail to understand this comment, I'd think there's no way to disable dirty page tracking for SVQ.
Quoted 9 lines
Quoted 3 lines
vhost_log_global_{start,stop} are called at the beginning and end of migration. To inform the device that it should start logging, they set or clean
VHOST_F_LOG_ALLatvhost_dev_set_log.Yes, but for SVQ, we can't disable dirty page tracking, isn't it? The only thing is to ignore or filter out the
F_LOG_ALLand pretend to be enabled and disabled.
Yes, that's what this patch does.
Quoted 10 lines
Quoted 5 lines
While SVQ does not use
VHOST_F_LOG_ALL, it exports the feature bit so vhost does not block migration. Maybe we need to look for another way to do this?I'm fine with filtering since it's much more simpler, but I fail to understand why we need to check
DRIVER_OK.
Ok maybe I can make that part more clear,
Since both operations use vhost_vdpa_set_features we must just filter the one that actually sets or removes VHOST_F_LOG_ALL, without affecting other features.
In practice, that means to not forward the set features after DRIVER_OK. The device is not expecting them anymore.
Does that make more sense?
Thanks!
Quoted 19 lines
Thanks
Quoted 15 lines
Thanks!
Quoted 12 lines
Thanks
Quoted 9 lines
hw/virtio/vhost-vdpa.c +6
-0+return 0 ; + } + +/* We must not ack _F_LOG if SVQ is enabled */ + features &= ~BIT_ULL (VHOST_F_LOG_ALL ); + ret =vhost_vdpa_get_dev_features (dev, &dev_features);if (ret !=0 ) {error_report ("Can't get vdpa device features, got (%d)" , ret);
Re: [PATCH 28/31] vdpa: Expose VHOST_F_LOG_ALL on SVQ
Quoted 81 lines · Eugenio Perez Martin
Quoted 56 lines · Jason Wang
Quoted 53 lines · Eugenio Perez Martin
Quoted 52 lines · Jason Wang
Quoted 36 lines · Eugenio Pérez
SVQ is able to log the dirty bits by itself, so let's use it to not block migration.
Also, ignore set and clear of
VHOST_F_LOG_ALLonset_featuresif SVQ is enabled. Even if the device supports it, the reports would be nonsense because SVQ memory is in the qemu region.The log region is still allocated. Future changes might skip that, but this series is already long enough.
Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)hw/virtio/vhost-vdpa.c +4
-0@@ -1022,6 +1022,9 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev, uint64_t *features)if (ret ==0 && v->shadow_vqs_enabled) {/* Filter only features that SVQ can offer to guest */ vhost_svq_valid_guest_features (features); + +/* Add SVQ logging capabilities */ + *features |=BIT_ULL (VHOST_F_LOG_ALL ); }return ret;@@ -1039,8 +1042,25 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,if (v->shadow_vqs_enabled) {uint64_t dev_features, svq_features, acked_features; +uint8_t status =0 ;bool ok;hw/virtio/vhost-vdpa.c static int vhost_vdpa_set_features(struct vhost_dev *dev, · line 1057
Quoted 10 lines
hw/virtio/vhost-vdpa.c +10
-0+ ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &status); +if (unlikely (ret)) { +return ret; + } + +if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { +/* +* vhost is trying to enable or disable _F_LOG, and the device +* would report wrong dirty pages. SVQ handles it. +*/ I fail to understand this comment, I'd think there's no way to disable dirty page tracking for SVQ.
Quoted 9 lines
Quoted 3 lines
vhost_log_global_{start,stop} are called at the beginning and end of migration. To inform the device that it should start logging, they set or clean
VHOST_F_LOG_ALLatvhost_dev_set_log.Yes, but for SVQ, we can't disable dirty page tracking, isn't it? The only thing is to ignore or filter out the
F_LOG_ALLand pretend to be enabled and disabled.Yes, that's what this patch does.
Quoted 10 lines
Quoted 5 lines
While SVQ does not use
VHOST_F_LOG_ALL, it exports the feature bit so vhost does not block migration. Maybe we need to look for another way to do this?I'm fine with filtering since it's much more simpler, but I fail to understand why we need to check
DRIVER_OK.
Quoted 8 lines
Ok maybe I can make that part more clear,
Since both operations use
vhost_vdpa_set_featureswe must just filter the one that actually sets or removesVHOST_F_LOG_ALL, without affecting other features.In practice, that means to not forward the set features after
DRIVER_OK. The device is not expecting them anymore.
I wonder what happens if we don't do this.
So kernel had this check:
/*
* It's not allowed to change the features after they have
* been negotiated.
*/
if (ops->get_status(vdpa) & VIRTIO_CONFIG_S_FEATURES_OK)
return -EBUSY;
So is it FEATURES_OK actually?
For this patch, I wonder if the thing we need to do is to see whether it is a enable/disable F_LOG_ALL and simply return.
Thanks
Quoted 25 lines
Does that make more sense?
Thanks!
Quoted 19 lines
Thanks
Quoted 15 lines
Thanks!
Quoted 12 lines
Thanks
Quoted 9 lines
hw/virtio/vhost-vdpa.c +6
-0+return 0 ; + } + +/* We must not ack _F_LOG if SVQ is enabled */ + features &= ~BIT_ULL (VHOST_F_LOG_ALL ); + ret =vhost_vdpa_get_dev_features (dev, &dev_features);if (ret !=0 ) {error_report ("Can't get vdpa device features, got (%d)" , ret);
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Eugenio Perez Martin
maintainerRe: [PATCH 28/31] vdpa: Expose VHOST_F_LOG_ALL on SVQ
Quoted 86 lines · Jason Wang
Quoted 83 lines · Eugenio Perez Martin
Quoted 56 lines · Jason Wang
Quoted 53 lines · Eugenio Perez Martin
Quoted 52 lines · Jason Wang
Quoted 36 lines · Eugenio Pérez
SVQ is able to log the dirty bits by itself, so let's use it to not block migration.
Also, ignore set and clear of
VHOST_F_LOG_ALLonset_featuresif SVQ is enabled. Even if the device supports it, the reports would be nonsense because SVQ memory is in the qemu region.The log region is still allocated. Future changes might skip that, but this series is already long enough.
Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)hw/virtio/vhost-vdpa.c +4
-0@@ -1022,6 +1022,9 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev, uint64_t *features)if (ret ==0 && v->shadow_vqs_enabled) {/* Filter only features that SVQ can offer to guest */ vhost_svq_valid_guest_features (features); + +/* Add SVQ logging capabilities */ + *features |=BIT_ULL (VHOST_F_LOG_ALL ); }return ret;@@ -1039,8 +1042,25 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,if (v->shadow_vqs_enabled) {uint64_t dev_features, svq_features, acked_features; +uint8_t status =0 ;bool ok;hw/virtio/vhost-vdpa.c static int vhost_vdpa_set_features(struct vhost_dev *dev, · line 1057
Quoted 10 lines
hw/virtio/vhost-vdpa.c +10
-0+ ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &status); +if (unlikely (ret)) { +return ret; + } + +if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { +/* +* vhost is trying to enable or disable _F_LOG, and the device +* would report wrong dirty pages. SVQ handles it. +*/ I fail to understand this comment, I'd think there's no way to disable dirty page tracking for SVQ.
Quoted 9 lines
Quoted 3 lines
vhost_log_global_{start,stop} are called at the beginning and end of migration. To inform the device that it should start logging, they set or clean
VHOST_F_LOG_ALLatvhost_dev_set_log.Yes, but for SVQ, we can't disable dirty page tracking, isn't it? The only thing is to ignore or filter out the
F_LOG_ALLand pretend to be enabled and disabled.Yes, that's what this patch does.
Quoted 10 lines
Quoted 5 lines
While SVQ does not use
VHOST_F_LOG_ALL, it exports the feature bit so vhost does not block migration. Maybe we need to look for another way to do this?I'm fine with filtering since it's much more simpler, but I fail to understand why we need to check
DRIVER_OK.Ok maybe I can make that part more clear,
Quoted 9 lines
Quoted 6 lines
Since both operations use
vhost_vdpa_set_featureswe must just filter the one that actually sets or removesVHOST_F_LOG_ALL, without affecting other features.In practice, that means to not forward the set features after
DRIVER_OK. The device is not expecting them anymore.I wonder what happens if we don't do this.
If we simply delete the check vhost_dev_set_features will return an error, failing the start of the migration. More on this below.
Quoted 11 lines
So kernel had this check:
/*
* It's not allowed to change the features after they have
* been negotiated.
*/
if (ops->get_status(vdpa)&VIRTIO_CONFIG_S_FEATURES_OK)return -EBUSY;So is it
FEATURES_OKactually?
Yes, FEATURES_OK seems more appropriate actually so I will switch to it for the next version.
But it should be functionally equivalent, since vhost.c:vhost_dev_start sets both and the setting of _F_LOG_ALL cannot be concurrent with it.
Quoted 3 lines
For this patch, I wonder if the thing we need to do is to see whether it is a enable/disable
F_LOG_ALLand simply return.
Yes, that's the intention of the patch.
We have 4 cases here:
a) We're being called from vhost_dev_start, with enable_log = false
b) We're being called from vhost_dev_start, with enable_log = true
c) We're being called from vhost_dev_set_log, with enable_log = false
d) We're being called from vhost_dev_set_log, with enable_log = true
The way to tell the difference between a/b and c/d is to check if {FEATURES,DRIVER}_OK is set. And, as you point out in previous mails, F_LOG_ALL must be filtered unconditionally since SVQ tracks dirty memory through the memory unmapping, so we clear the bit unconditionally if we detect that VHOST_SET_FEATURES will be called (cases a and b).
Another possibility is to track if features have been set with a bool in vhost_vdpa or something like that. But it seems cleaner to me to only store that in the actual device.
Quoted 28 lines
Thanks
Quoted 25 lines
Does that make more sense?
Thanks!
Quoted 19 lines
Thanks
Quoted 15 lines
Thanks!
Quoted 12 lines
Thanks
Quoted 9 lines
hw/virtio/vhost-vdpa.c +6
-0+return 0 ; + } + +/* We must not ack _F_LOG if SVQ is enabled */ + features &= ~BIT_ULL (VHOST_F_LOG_ALL ); + ret =vhost_vdpa_get_dev_features (dev, &dev_features);if (ret !=0 ) {error_report ("Can't get vdpa device features, got (%d)" , ret);
Re: [PATCH 28/31] vdpa: Expose VHOST_F_LOG_ALL on SVQ
Quoted 80 lines · Eugenio Perez Martin
Quoted 79 lines · Jason Wang
Quoted 77 lines · Eugenio Perez Martin
Quoted 53 lines · Jason Wang
Quoted 51 lines · Eugenio Perez Martin
Quoted 50 lines · Jason Wang
Quoted 36 lines · Eugenio Pérez
SVQ is able to log the dirty bits by itself, so let's use it to not block migration.
Also, ignore set and clear of
VHOST_F_LOG_ALLonset_featuresif SVQ is enabled. Even if the device supports it, the reports would be nonsense because SVQ memory is in the qemu region.The log region is still allocated. Future changes might skip that, but this series is already long enough.
Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)hw/virtio/vhost-vdpa.c +4
-0@@ -1022,6 +1022,9 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev, uint64_t *features)if (ret ==0 && v->shadow_vqs_enabled) {/* Filter only features that SVQ can offer to guest */ vhost_svq_valid_guest_features (features); + +/* Add SVQ logging capabilities */ + *features |=BIT_ULL (VHOST_F_LOG_ALL ); }return ret;@@ -1039,8 +1042,25 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,if (v->shadow_vqs_enabled) {uint64_t dev_features, svq_features, acked_features; +uint8_t status =0 ;bool ok;hw/virtio/vhost-vdpa.c static int vhost_vdpa_set_features(struct vhost_dev *dev, · line 1057
Quoted 10 lines
hw/virtio/vhost-vdpa.c +10
-0+ ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &status); +if (unlikely (ret)) { +return ret; + } + +if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { +/* +* vhost is trying to enable or disable _F_LOG, and the device +* would report wrong dirty pages. SVQ handles it. +*/ I fail to understand this comment, I'd think there's no way to disable dirty page tracking for SVQ.
Quoted 8 lines
Quoted 3 lines
vhost_log_global_{start,stop} are called at the beginning and end of migration. To inform the device that it should start logging, they set or clean
VHOST_F_LOG_ALLatvhost_dev_set_log.Yes, but for SVQ, we can't disable dirty page tracking, isn't it? The only thing is to ignore or filter out the
F_LOG_ALLand pretend to be enabled and disabled.Yes, that's what this patch does.
Quoted 7 lines
Quoted 3 lines
While SVQ does not use
VHOST_F_LOG_ALL, it exports the feature bit so vhost does not block migration. Maybe we need to look for another way to do this?I'm fine with filtering since it's much more simpler, but I fail to understand why we need to check
DRIVER_OK.Ok maybe I can make that part more clear,
Since both operations use
vhost_vdpa_set_featureswe must just filter the one that actually sets or removesVHOST_F_LOG_ALL, without affecting other features.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
In practice, that means to not forward the set features after
DRIVER_OK. The device is not expecting them anymore.I wonder what happens if we don't do this.
If we simply delete the check
vhost_dev_set_featureswill return an error, failing the start of the migration. More on this below.
Ok.
Quoted 10 lines
Quoted 10 lines
So kernel had this check:
/*
* It's not allowed to change the features after they have
* been negotiated.
*/
if (ops->get_status(vdpa)&VIRTIO_CONFIG_S_FEATURES_OK)return -EBUSY;
Quoted 8 lines
Quoted 2 lines
So is it
FEATURES_OKactually?Yes,
FEATURES_OKseems more appropriate actually so I will switch to it for the next version.But it should be functionally equivalent, since vhost.c:vhost_dev_start sets both and the setting of
_F_LOG_ALLcannot be concurrent with it.
Right.
Quoted 9 lines
Quoted 4 lines
For this patch, I wonder if the thing we need to do is to see whether it is a enable/disable
F_LOG_ALLand simply return.Yes, that's the intention of the patch.
We have 4 cases here:
a) We're being called fromvhost_dev_start, withenable_log= false
b) We're being called fromvhost_dev_start, withenable_log= true
And this case makes us can't simply return without calling vhost-vdpa.
Quoted 10 lines
c) We're being called from
vhost_dev_set_log, withenable_log= false
d) We're being called fromvhost_dev_set_log, withenable_log= trueThe way to tell the difference between a/b and c/d is to check if {FEATURES,DRIVER}_OK is set. And, as you point out in previous mails,
F_LOG_ALLmust be filtered unconditionally since SVQ tracks dirty memory through the memory unmapping, so we clear the bit unconditionally if we detect thatVHOST_SET_FEATURESwill be called (cases a and b).
Quoted 3 lines
Another possibility is to track if features have been set with a bool in
vhost_vdpaor something like that. But it seems cleaner to me to only store that in the actual device.
So I suggest to make sure codes match the comment:
if (status & VIRTIO_CONFIG_S_DRIVER_OK) {
/*
* vhost is trying to enable or disable _F_LOG, and the device
* would report wrong dirty pages. SVQ handles it. */
return 0;
}
It would be better to check whether the caller is toggling _F_LOG_ALL in this case.
Thanks
Quoted 15 lines
Quoted 15 lines
Thanks
Quoted 12 lines
Does that make more sense?
Thanks!
Quoted 8 lines
Thanks
Quoted 5 lines
Thanks!
Quoted 3 lines
Thanks
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
hw/virtio/vhost-vdpa.c static int vhost_vdpa_set_features(struct vhost_dev *dev, · line 1066
Quoted 9 lines
hw/virtio/vhost-vdpa.c +6
-0+return 0 ; + } + +/* We must not ack _F_LOG if SVQ is enabled */ + features &= ~BIT_ULL (VHOST_F_LOG_ALL ); + ret =vhost_vdpa_get_dev_features (dev, &dev_features);if (ret !=0 ) {error_report ("Can't get vdpa device features, got (%d)" , ret);
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Eugenio Perez Martin
maintainerRe: [PATCH 28/31] vdpa: Expose VHOST_F_LOG_ALL on SVQ
Quoted 121 lines · Jason Wang
Quoted 80 lines · Eugenio Perez Martin
Quoted 79 lines · Jason Wang
Quoted 77 lines · Eugenio Perez Martin
Quoted 53 lines · Jason Wang
Quoted 51 lines · Eugenio Perez Martin
Quoted 50 lines · Jason Wang
Quoted 36 lines · Eugenio Pérez
SVQ is able to log the dirty bits by itself, so let's use it to not block migration.
Also, ignore set and clear of
VHOST_F_LOG_ALLonset_featuresif SVQ is enabled. Even if the device supports it, the reports would be nonsense because SVQ memory is in the qemu region.The log region is still allocated. Future changes might skip that, but this series is already long enough.
Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)hw/virtio/vhost-vdpa.c +4
-0@@ -1022,6 +1022,9 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev, uint64_t *features)if (ret ==0 && v->shadow_vqs_enabled) {/* Filter only features that SVQ can offer to guest */ vhost_svq_valid_guest_features (features); + +/* Add SVQ logging capabilities */ + *features |=BIT_ULL (VHOST_F_LOG_ALL ); }return ret;@@ -1039,8 +1042,25 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,if (v->shadow_vqs_enabled) {uint64_t dev_features, svq_features, acked_features; +uint8_t status =0 ;bool ok;hw/virtio/vhost-vdpa.c static int vhost_vdpa_set_features(struct vhost_dev *dev, · line 1057
Quoted 10 lines
hw/virtio/vhost-vdpa.c +10
-0+ ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &status); +if (unlikely (ret)) { +return ret; + } + +if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { +/* +* vhost is trying to enable or disable _F_LOG, and the device +* would report wrong dirty pages. SVQ handles it. +*/ I fail to understand this comment, I'd think there's no way to disable dirty page tracking for SVQ.
Quoted 8 lines
Quoted 3 lines
vhost_log_global_{start,stop} are called at the beginning and end of migration. To inform the device that it should start logging, they set or clean
VHOST_F_LOG_ALLatvhost_dev_set_log.Yes, but for SVQ, we can't disable dirty page tracking, isn't it? The only thing is to ignore or filter out the
F_LOG_ALLand pretend to be enabled and disabled.Yes, that's what this patch does.
Quoted 7 lines
Quoted 3 lines
While SVQ does not use
VHOST_F_LOG_ALL, it exports the feature bit so vhost does not block migration. Maybe we need to look for another way to do this?I'm fine with filtering since it's much more simpler, but I fail to understand why we need to check
DRIVER_OK.Ok maybe I can make that part more clear,
Since both operations use
vhost_vdpa_set_featureswe must just filter the one that actually sets or removesVHOST_F_LOG_ALL, without affecting other features.Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
In practice, that means to not forward the set features after
DRIVER_OK. The device is not expecting them anymore.I wonder what happens if we don't do this.
If we simply delete the check
vhost_dev_set_featureswill return an error, failing the start of the migration. More on this below.Ok.
Quoted 10 lines
Quoted 10 lines
So kernel had this check:
/*
* It's not allowed to change the features after they have
* been negotiated.
*/
if (ops->get_status(vdpa)&VIRTIO_CONFIG_S_FEATURES_OK)return -EBUSY;Quoted 8 lines
Quoted 2 lines
So is it
FEATURES_OKactually?Yes,
FEATURES_OKseems more appropriate actually so I will switch to it for the next version.But it should be functionally equivalent, since vhost.c:vhost_dev_start sets both and the setting of
_F_LOG_ALLcannot be concurrent with it.Right.
Quoted 4 lines
Quoted 4 lines
For this patch, I wonder if the thing we need to do is to see whether it is a enable/disable
F_LOG_ALLand simply return.
Quoted 9 lines
Quoted 5 lines
Yes, that's the intention of the patch.
We have 4 cases here:
a) We're being called fromvhost_dev_start, withenable_log= false
b) We're being called fromvhost_dev_start, withenable_log= trueAnd this case makes us can't simply return without calling vhost-vdpa.
It calls because {FEATURES,DRIVER}_OK is still not set at that point.
Quoted 26 lines
Quoted 11 lines
c) We're being called from
vhost_dev_set_log, withenable_log= false
d) We're being called fromvhost_dev_set_log, withenable_log= trueThe way to tell the difference between a/b and c/d is to check if {FEATURES,DRIVER}_OK is set. And, as you point out in previous mails,
F_LOG_ALLmust be filtered unconditionally since SVQ tracks dirty memory through the memory unmapping, so we clear the bit unconditionally if we detect thatVHOST_SET_FEATURESwill be called (cases a and b).Quoted 3 lines
Another possibility is to track if features have been set with a bool in
vhost_vdpaor something like that. But it seems cleaner to me to only store that in the actual device.So I suggest to make sure codes match the comment:
if (status & VIRTIO_CONFIG_S_DRIVER_OK) { /* * vhost is trying to enable or disable _F_LOG, and the device * would report wrong dirty pages. SVQ handles it. */ return 0; }
Quoted 3 lines
It would be better to check whether the caller is toggling
_F_LOG_ALLin this case.
How to detect? We can save feature flags and compare, but ignoring all set_features after FEATURES_OK seems simpler to me.
Would changing the comment work? Something like "set_features after _S_FEATURES_OK means vhost is trying to enable or disable _F_LOG, and the device would report wrong dirty pages. SVQ handles it."
Thanks!
Quoted 28 lines
Thanks
Quoted 24 lines
Quoted 24 lines
Thanks
Quoted 21 lines
Does that make more sense?
Thanks!
Quoted 17 lines
Thanks
Quoted 14 lines
Thanks!
Quoted 12 lines
Thanks
Quoted 9 lines
hw/virtio/vhost-vdpa.c +6
-0+return 0 ; + } + +/* We must not ack _F_LOG if SVQ is enabled */ + features &= ~BIT_ULL (VHOST_F_LOG_ALL ); + ret =vhost_vdpa_get_dev_features (dev, &dev_features);if (ret !=0 ) {error_report ("Can't get vdpa device features, got (%d)" , ret);
Re: [PATCH 28/31] vdpa: Expose VHOST_F_LOG_ALL on SVQ
Quoted 161 lines · Eugenio Perez Martin
Quoted 121 lines · Jason Wang
Quoted 80 lines · Eugenio Perez Martin
Quoted 79 lines · Jason Wang
Quoted 77 lines · Eugenio Perez Martin
Quoted 53 lines · Jason Wang
Quoted 51 lines · Eugenio Perez Martin
Quoted 50 lines · Jason Wang
Quoted 36 lines · Eugenio Pérez
SVQ is able to log the dirty bits by itself, so let's use it to not block migration.
Also, ignore set and clear of
VHOST_F_LOG_ALLonset_featuresif SVQ is enabled. Even if the device supports it, the reports would be nonsense because SVQ memory is in the qemu region.The log region is still allocated. Future changes might skip that, but this series is already long enough.
Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)hw/virtio/vhost-vdpa.c +4
-0@@ -1022,6 +1022,9 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev, uint64_t *features)if (ret ==0 && v->shadow_vqs_enabled) {/* Filter only features that SVQ can offer to guest */ vhost_svq_valid_guest_features (features); + +/* Add SVQ logging capabilities */ + *features |=BIT_ULL (VHOST_F_LOG_ALL ); }return ret;@@ -1039,8 +1042,25 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,if (v->shadow_vqs_enabled) {uint64_t dev_features, svq_features, acked_features; +uint8_t status =0 ;bool ok;hw/virtio/vhost-vdpa.c static int vhost_vdpa_set_features(struct vhost_dev *dev, · line 1057
Quoted 10 lines
hw/virtio/vhost-vdpa.c +10
-0+ ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &status); +if (unlikely (ret)) { +return ret; + } + +if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { +/* +* vhost is trying to enable or disable _F_LOG, and the device +* would report wrong dirty pages. SVQ handles it. +*/ I fail to understand this comment, I'd think there's no way to disable dirty page tracking for SVQ.
Quoted 8 lines
Quoted 3 lines
vhost_log_global_{start,stop} are called at the beginning and end of migration. To inform the device that it should start logging, they set or clean
VHOST_F_LOG_ALLatvhost_dev_set_log.Yes, but for SVQ, we can't disable dirty page tracking, isn't it? The only thing is to ignore or filter out the
F_LOG_ALLand pretend to be enabled and disabled.Yes, that's what this patch does.
Quoted 7 lines
Quoted 3 lines
While SVQ does not use
VHOST_F_LOG_ALL, it exports the feature bit so vhost does not block migration. Maybe we need to look for another way to do this?I'm fine with filtering since it's much more simpler, but I fail to understand why we need to check
DRIVER_OK.Ok maybe I can make that part more clear,
Since both operations use
vhost_vdpa_set_featureswe must just filter the one that actually sets or removesVHOST_F_LOG_ALL, without affecting other features.Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
In practice, that means to not forward the set features after
DRIVER_OK. The device is not expecting them anymore.I wonder what happens if we don't do this.
If we simply delete the check
vhost_dev_set_featureswill return an error, failing the start of the migration. More on this below.Ok.
Quoted 10 lines
Quoted 10 lines
So kernel had this check:
/*
* It's not allowed to change the features after they have
* been negotiated.
*/
if (ops->get_status(vdpa)&VIRTIO_CONFIG_S_FEATURES_OK)return -EBUSY;Quoted 8 lines
Quoted 2 lines
So is it
FEATURES_OKactually?Yes,
FEATURES_OKseems more appropriate actually so I will switch to it for the next version.But it should be functionally equivalent, since vhost.c:vhost_dev_start sets both and the setting of
_F_LOG_ALLcannot be concurrent with it.Right.
Quoted 4 lines
Quoted 4 lines
For this patch, I wonder if the thing we need to do is to see whether it is a enable/disable
F_LOG_ALLand simply return.Quoted 9 lines
Quoted 5 lines
Yes, that's the intention of the patch.
We have 4 cases here:
a) We're being called fromvhost_dev_start, withenable_log= false
b) We're being called fromvhost_dev_start, withenable_log= trueAnd this case makes us can't simply return without calling vhost-vdpa.
It calls because {FEATURES,DRIVER}_OK is still not set at that point.
Quoted 26 lines
Quoted 11 lines
c) We're being called from
vhost_dev_set_log, withenable_log= false
d) We're being called fromvhost_dev_set_log, withenable_log= trueThe way to tell the difference between a/b and c/d is to check if {FEATURES,DRIVER}_OK is set. And, as you point out in previous mails,
F_LOG_ALLmust be filtered unconditionally since SVQ tracks dirty memory through the memory unmapping, so we clear the bit unconditionally if we detect thatVHOST_SET_FEATURESwill be called (cases a and b).Quoted 3 lines
Another possibility is to track if features have been set with a bool in
vhost_vdpaor something like that. But it seems cleaner to me to only store that in the actual device.So I suggest to make sure codes match the comment:
if (status & VIRTIO_CONFIG_S_DRIVER_OK) { /* * vhost is trying to enable or disable _F_LOG, and the device * would report wrong dirty pages. SVQ handles it. */ return 0; }
Quoted 6 lines
Quoted 3 lines
It would be better to check whether the caller is toggling
_F_LOG_ALLin this case.How to detect? We can save feature flags and compare, but ignoring all
set_featuresafterFEATURES_OKseems simpler to me.
Something like:
(status ^ status_old == _F_LOG_ALL) ?
It helps us to return errors on wrong features set during DRIVER_OK.
Thanks
Quoted 36 lines
Would changing the comment work? Something like "
set_featuresafter_S_FEATURES_OKmeans vhost is trying to enable or disable_F_LOG, and the device would report wrong dirty pages. SVQ handles it."Thanks!
Quoted 28 lines
Thanks
Quoted 24 lines
Quoted 24 lines
Thanks
Quoted 21 lines
Does that make more sense?
Thanks!
Quoted 17 lines
Thanks
Quoted 14 lines
Thanks!
Quoted 12 lines
Thanks
Quoted 9 lines
hw/virtio/vhost-vdpa.c +6
-0+return 0 ; + } + +/* We must not ack _F_LOG if SVQ is enabled */ + features &= ~BIT_ULL (VHOST_F_LOG_ALL ); + ret =vhost_vdpa_get_dev_features (dev, &dev_features);if (ret !=0 ) {error_report ("Can't get vdpa device features, got (%d)" , ret);
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Eugenio Perez Martin
maintainerRe: [PATCH 28/31] vdpa: Expose VHOST_F_LOG_ALL on SVQ
Quoted 168 lines · Jason Wang
Quoted 165 lines · Eugenio Perez Martin
Quoted 121 lines · Jason Wang
Quoted 80 lines · Eugenio Perez Martin
Quoted 79 lines · Jason Wang
Quoted 77 lines · Eugenio Perez Martin
Quoted 53 lines · Jason Wang
Quoted 51 lines · Eugenio Perez Martin
Quoted 50 lines · Jason Wang
Quoted 36 lines · Eugenio Pérez
SVQ is able to log the dirty bits by itself, so let's use it to not block migration.
Also, ignore set and clear of
VHOST_F_LOG_ALLonset_featuresif SVQ is enabled. Even if the device supports it, the reports would be nonsense because SVQ memory is in the qemu region.The log region is still allocated. Future changes might skip that, but this series is already long enough.
Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)hw/virtio/vhost-vdpa.c +4
-0@@ -1022,6 +1022,9 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev, uint64_t *features)if (ret ==0 && v->shadow_vqs_enabled) {/* Filter only features that SVQ can offer to guest */ vhost_svq_valid_guest_features (features); + +/* Add SVQ logging capabilities */ + *features |=BIT_ULL (VHOST_F_LOG_ALL ); }return ret;@@ -1039,8 +1042,25 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,if (v->shadow_vqs_enabled) {uint64_t dev_features, svq_features, acked_features; +uint8_t status =0 ;bool ok;hw/virtio/vhost-vdpa.c static int vhost_vdpa_set_features(struct vhost_dev *dev, · line 1057
Quoted 10 lines
hw/virtio/vhost-vdpa.c +10
-0+ ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &status); +if (unlikely (ret)) { +return ret; + } + +if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { +/* +* vhost is trying to enable or disable _F_LOG, and the device +* would report wrong dirty pages. SVQ handles it. +*/ I fail to understand this comment, I'd think there's no way to disable dirty page tracking for SVQ.
Quoted 8 lines
Quoted 3 lines
vhost_log_global_{start,stop} are called at the beginning and end of migration. To inform the device that it should start logging, they set or clean
VHOST_F_LOG_ALLatvhost_dev_set_log.Yes, but for SVQ, we can't disable dirty page tracking, isn't it? The only thing is to ignore or filter out the
F_LOG_ALLand pretend to be enabled and disabled.Yes, that's what this patch does.
Quoted 7 lines
Quoted 3 lines
While SVQ does not use
VHOST_F_LOG_ALL, it exports the feature bit so vhost does not block migration. Maybe we need to look for another way to do this?I'm fine with filtering since it's much more simpler, but I fail to understand why we need to check
DRIVER_OK.Ok maybe I can make that part more clear,
Since both operations use
vhost_vdpa_set_featureswe must just filter the one that actually sets or removesVHOST_F_LOG_ALL, without affecting other features.Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
In practice, that means to not forward the set features after
DRIVER_OK. The device is not expecting them anymore.I wonder what happens if we don't do this.
If we simply delete the check
vhost_dev_set_featureswill return an error, failing the start of the migration. More on this below.Ok.
Quoted 10 lines
Quoted 10 lines
So kernel had this check:
/*
* It's not allowed to change the features after they have
* been negotiated.
*/
if (ops->get_status(vdpa)&VIRTIO_CONFIG_S_FEATURES_OK)return -EBUSY;Quoted 8 lines
Quoted 2 lines
So is it
FEATURES_OKactually?Yes,
FEATURES_OKseems more appropriate actually so I will switch to it for the next version.But it should be functionally equivalent, since vhost.c:vhost_dev_start sets both and the setting of
_F_LOG_ALLcannot be concurrent with it.Right.
Quoted 4 lines
Quoted 4 lines
For this patch, I wonder if the thing we need to do is to see whether it is a enable/disable
F_LOG_ALLand simply return.Quoted 9 lines
Quoted 5 lines
Yes, that's the intention of the patch.
We have 4 cases here:
a) We're being called fromvhost_dev_start, withenable_log= false
b) We're being called fromvhost_dev_start, withenable_log= trueAnd this case makes us can't simply return without calling vhost-vdpa.
It calls because {FEATURES,DRIVER}_OK is still not set at that point.
Quoted 29 lines
Quoted 11 lines
c) We're being called from
vhost_dev_set_log, withenable_log= false
d) We're being called fromvhost_dev_set_log, withenable_log= trueThe way to tell the difference between a/b and c/d is to check if {FEATURES,DRIVER}_OK is set. And, as you point out in previous mails,
F_LOG_ALLmust be filtered unconditionally since SVQ tracks dirty memory through the memory unmapping, so we clear the bit unconditionally if we detect thatVHOST_SET_FEATURESwill be called (cases a and b).Quoted 3 lines
Another possibility is to track if features have been set with a bool in
vhost_vdpaor something like that. But it seems cleaner to me to only store that in the actual device.So I suggest to make sure codes match the comment:
if (status & VIRTIO_CONFIG_S_DRIVER_OK) { /* * vhost is trying to enable or disable _F_LOG, and the device * would report wrong dirty pages. SVQ handles it. */ return 0; }It would be better to check whether the caller is toggling
_F_LOG_ALLin this case.
Quoted 7 lines
Quoted 2 lines
How to detect? We can save feature flags and compare, but ignoring all
set_featuresafterFEATURES_OKseems simpler to me.Something like:
(status ^
status_old==_F_LOG_ALL) ?
s/status/features/ ?
Quoted 2 lines
It helps us to return errors on wrong features set during
DRIVER_OK.
Do you mean to return errors in case of toggling other features than _F_LOG_ALL, isn't it? That's interesting actually, but it seems it forces vhost_vdpa to track acked_features too.
Actually, it seems to me vhost_dev->acked_features will retain the bad features even on error. I'll investigate it.
Thanks!
Quoted 7 lines
Thanks
Quoted 5 lines
Would changing the comment work? Something like "
set_featuresafter_S_FEATURES_OKmeans vhost is trying to enable or disable_F_LOG, and the device would report wrong dirty pages. SVQ handles it."
Re: [PATCH 28/31] vdpa: Expose VHOST_F_LOG_ALL on SVQ
Quoted 173 lines · Eugenio Perez Martin
Quoted 171 lines · Jason Wang
Quoted 167 lines · Eugenio Perez Martin
Quoted 121 lines · Jason Wang
Quoted 80 lines · Eugenio Perez Martin
Quoted 79 lines · Jason Wang
Quoted 77 lines · Eugenio Perez Martin
Quoted 53 lines · Jason Wang
Quoted 51 lines · Eugenio Perez Martin
Quoted 50 lines · Jason Wang
Quoted 36 lines · Eugenio Pérez
SVQ is able to log the dirty bits by itself, so let's use it to not block migration.
Also, ignore set and clear of
VHOST_F_LOG_ALLonset_featuresif SVQ is enabled. Even if the device supports it, the reports would be nonsense because SVQ memory is in the qemu region.The log region is still allocated. Future changes might skip that, but this series is already long enough.
Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-vdpa.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)hw/virtio/vhost-vdpa.c +4
-0@@ -1022,6 +1022,9 @@ static int vhost_vdpa_get_features(struct vhost_dev *dev, uint64_t *features)if (ret ==0 && v->shadow_vqs_enabled) {/* Filter only features that SVQ can offer to guest */ vhost_svq_valid_guest_features (features); + +/* Add SVQ logging capabilities */ + *features |=BIT_ULL (VHOST_F_LOG_ALL ); }return ret;@@ -1039,8 +1042,25 @@ static int vhost_vdpa_set_features(struct vhost_dev *dev,if (v->shadow_vqs_enabled) {uint64_t dev_features, svq_features, acked_features; +uint8_t status =0 ;bool ok;hw/virtio/vhost-vdpa.c static int vhost_vdpa_set_features(struct vhost_dev *dev, · line 1057
Quoted 10 lines
hw/virtio/vhost-vdpa.c +10
-0+ ret =vhost_vdpa_call (dev,VHOST_VDPA_GET_STATUS , &status); +if (unlikely (ret)) { +return ret; + } + +if (status &VIRTIO_CONFIG_S_DRIVER_OK ) { +/* +* vhost is trying to enable or disable _F_LOG, and the device +* would report wrong dirty pages. SVQ handles it. +*/ I fail to understand this comment, I'd think there's no way to disable dirty page tracking for SVQ.
Quoted 8 lines
Quoted 3 lines
vhost_log_global_{start,stop} are called at the beginning and end of migration. To inform the device that it should start logging, they set or clean
VHOST_F_LOG_ALLatvhost_dev_set_log.Yes, but for SVQ, we can't disable dirty page tracking, isn't it? The only thing is to ignore or filter out the
F_LOG_ALLand pretend to be enabled and disabled.Yes, that's what this patch does.
Quoted 7 lines
Quoted 3 lines
While SVQ does not use
VHOST_F_LOG_ALL, it exports the feature bit so vhost does not block migration. Maybe we need to look for another way to do this?I'm fine with filtering since it's much more simpler, but I fail to understand why we need to check
DRIVER_OK.Ok maybe I can make that part more clear,
Since both operations use
vhost_vdpa_set_featureswe must just filter the one that actually sets or removesVHOST_F_LOG_ALL, without affecting other features.Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
In practice, that means to not forward the set features after
DRIVER_OK. The device is not expecting them anymore.I wonder what happens if we don't do this.
If we simply delete the check
vhost_dev_set_featureswill return an error, failing the start of the migration. More on this below.Ok.
Quoted 10 lines
Quoted 10 lines
So kernel had this check:
/*
* It's not allowed to change the features after they have
* been negotiated.
*/
if (ops->get_status(vdpa)&VIRTIO_CONFIG_S_FEATURES_OK)return -EBUSY;Quoted 8 lines
Quoted 2 lines
So is it
FEATURES_OKactually?Yes,
FEATURES_OKseems more appropriate actually so I will switch to it for the next version.But it should be functionally equivalent, since vhost.c:vhost_dev_start sets both and the setting of
_F_LOG_ALLcannot be concurrent with it.Right.
Quoted 4 lines
Quoted 4 lines
For this patch, I wonder if the thing we need to do is to see whether it is a enable/disable
F_LOG_ALLand simply return.Quoted 9 lines
Quoted 5 lines
Yes, that's the intention of the patch.
We have 4 cases here:
a) We're being called fromvhost_dev_start, withenable_log= false
b) We're being called fromvhost_dev_start, withenable_log= trueAnd this case makes us can't simply return without calling vhost-vdpa.
It calls because {FEATURES,DRIVER}_OK is still not set at that point.
Quoted 26 lines
Quoted 11 lines
c) We're being called from
vhost_dev_set_log, withenable_log= false
d) We're being called fromvhost_dev_set_log, withenable_log= trueThe way to tell the difference between a/b and c/d is to check if {FEATURES,DRIVER}_OK is set. And, as you point out in previous mails,
F_LOG_ALLmust be filtered unconditionally since SVQ tracks dirty memory through the memory unmapping, so we clear the bit unconditionally if we detect thatVHOST_SET_FEATURESwill be called (cases a and b).Quoted 3 lines
Another possibility is to track if features have been set with a bool in
vhost_vdpaor something like that. But it seems cleaner to me to only store that in the actual device.So I suggest to make sure codes match the comment:
if (status & VIRTIO_CONFIG_S_DRIVER_OK) { /* * vhost is trying to enable or disable _F_LOG, and the device * would report wrong dirty pages. SVQ handles it. */ return 0; }Quoted 3 lines
It would be better to check whether the caller is toggling
_F_LOG_ALLin this case.How to detect? We can save feature flags and compare, but ignoring all
set_featuresafterFEATURES_OKseems simpler to me.
Quoted 6 lines
Quoted 4 lines
Something like:
(status ^
status_old==_F_LOG_ALL) ?s/status/features/ ?
Right.
Quoted 7 lines
Quoted 3 lines
It helps us to return errors on wrong features set during
DRIVER_OK.Do you mean to return errors in case of toggling other features than
_F_LOG_ALL, isn't it? That's interesting actually, but it seems it forcesvhost_vdpato trackacked_featurestoo.
I meant we can change the check a little bit like:
if (featurs ^ features_old == _F_LOG_ALL && status &
VIRTIO_CONFIG_S_DRIVER_OK) {
return 0;
}For other features changing we and let it go down the logic as you proposed in this patch.
Thanks
Quoted 15 lines
Actually, it seems to me
vhost_dev->acked_featureswill retain the bad features even on error. I'll investigate it.Thanks!
Quoted 7 lines
Thanks
Quoted 5 lines
Would changing the comment work? Something like "
set_featuresafter_S_FEATURES_OKmeans vhost is trying to enable or disable_F_LOG, and the device would report wrong dirty pages. SVQ handles it."
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Eugenio Pérez
maintainerPATCH 29/31 vdpa: Make ncs autofree
In reply to Eugenio PérezSimplifying memory management.
--- net/vhost-vdpa.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
net/vhost-vdpa.c +2 -3
@@ -264,7 +264,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, {const NetdevVhostVDPAOptions *opts;int vdpa_device_fd; -NetClientState **ncs, *nc; + g_autofree NetClientState **ncs = NULL; +NetClientState *nc;int queue_pairs, i, has_cvq =0 ;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_VDPA );
@@ -302,7 +303,6 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, goto err; } -g_free (ncs);return 0 ; err:
@@ -310,7 +310,6 @@ err:qemu_del_net_client (ncs[0 ]); }qemu_close (vdpa_device_fd); -g_free (ncs);return -1 ; }
Signature · 1 line
2.27.0
Re: [PATCH 29/31] vdpa: Make ncs autofree
Quoted 3 lines · Eugenio Pérez
Simplifying memory management.
Signed-off-by Eugenio Pérez <[email protected]>
To reduce the size of this series. This can be sent as an separate patch if I was not wrong.
Thanks
Quoted 27 lines
--- net/vhost-vdpa.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)net/vhost-vdpa.c +2
-2@@ -264,7 +264,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, {const NetdevVhostVDPAOptions *opts;int vdpa_device_fd; -NetClientState **ncs, *nc; + g_autofree NetClientState **ncs = NULL; +NetClientState *nc;int queue_pairs, i, has_cvq =0 ;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_VDPA );@@ -302,7 +303,6 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, goto err; } -g_free (ncs);return 0 ; err:
net/vhost-vdpa.c err: · line 315
Quoted 7 lines
net/vhost-vdpa.c +0
-1@@ -310,7 +310,6 @@ err:qemu_del_net_client (ncs[0 ]); }qemu_close (vdpa_device_fd); -g_free (ncs);return -1 ; }
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Eugenio Perez Martin
maintainerRe: [PATCH 29/31] vdpa: Make ncs autofree
Quoted 11 lines · Jason Wang
Quoted 3 lines · Eugenio Pérez
Simplifying memory management.
Signed-off-by Eugenio Pérez <[email protected]>To reduce the size of this series. This can be sent as an separate patch if I was not wrong.
Sure, I'll send separately to trivial maillist.
Thanks!
Quoted 38 lines
Thanks
Quoted 34 lines
--- net/vhost-vdpa.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)net/vhost-vdpa.c +2
-3@@ -264,7 +264,8 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, {const NetdevVhostVDPAOptions *opts;int vdpa_device_fd; -NetClientState **ncs, *nc; + g_autofree NetClientState **ncs = NULL; +NetClientState *nc;int queue_pairs, i, has_cvq =0 ;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_VDPA );@@ -302,7 +303,6 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, goto err; } -g_free (ncs);return 0 ; err:@@ -310,7 +310,6 @@ err:qemu_del_net_client (ncs[0 ]); }qemu_close (vdpa_device_fd); -g_free (ncs);return -1 ; }
Eugenio Pérez
maintainerPATCH 30/31 vdpa: Move vhost_vdpa_get_iova_range to net/vhost-vdpa.c
In reply to Eugenio PérezSince it's a device property, it can be done in net/. This helps SVQ to allocate the rings in vdpa device initialization, rather than delay that.
--- hw/virtio/vhost-vdpa.c | 15 --------------- net/vhost-vdpa.c | 32 ++++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 23 deletions(-)
hw/virtio/vhost-vdpa.c +0 -15
@@ -350,19 +350,6 @@ static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)return 0 ; } -static void vhost_vdpa_get_iova_range (struct vhost_vdpa *v) -{ -int ret =vhost_vdpa_call (v->dev,VHOST_VDPA_GET_IOVA_RANGE , - &v->iova_range); -if (ret !=0 ) { - v->iova_range.first =0 ; - v->iova_range.last =UINT64_MAX ; - } - -trace_vhost_vdpa_get_iova_range (v->dev, v->iova_range.first, - v->iova_range.last); -} -static bool vhost_vdpa_one_time_request (struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque;
@@ -1295,8 +1282,6 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp) goto err; } -vhost_vdpa_get_iova_range (v); -if (vhost_vdpa_one_time_request (dev)) {return 0 ; }
net/vhost-vdpa.c +24 -8
@@ -22,6 +22,7 @@#include <sys/ioctl.h> #include <err.h> #include "standard-headers/linux/virtio_net.h" +#include "standard-headers/linux/vhost_types.h" #include "monitor/monitor.h" #include "hw/virtio/vhost.h"
@@ -187,13 +188,25 @@ static NetClientInfo net_vhost_vdpa_info = { .check_peer_type = vhost_vdpa_check_peer_type, }; +static void vhost_vdpa_get_iova_range (int fd, +struct vhost_vdpa_iova_range *iova_range) +{ +int ret =ioctl (fd,VHOST_VDPA_GET_IOVA_RANGE , iova_range); + +if (ret <0 ) { + iova_range->first =0 ; + iova_range->last =UINT64_MAX ; + } +} +static NetClientState *net_vhost_vdpa_init (NetClientState *peer, -const char *device, -const char *name, -int vdpa_device_fd, -int queue_pair_index, -int nvqs, -bool is_datapath) +const char *device, +const char *name, +int vdpa_device_fd, +int queue_pair_index, +int nvqs, +bool is_datapath, +struct vhost_vdpa_iova_range iova_range) {NetClientState *nc =NULL ;VhostVDPAState *s;
@@ -211,6 +224,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.device_fd = vdpa_device_fd; s->vhost_vdpa.index = queue_pair_index; + s->vhost_vdpa.iova_range = iova_range; ret =vhost_vdpa_add (nc, (void *)&s->vhost_vdpa, queue_pair_index, nvqs);if (ret) {qemu_del_net_client (nc);
@@ -267,6 +281,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, g_autofree NetClientState **ncs = NULL;NetClientState *nc;int queue_pairs, i, has_cvq =0 ; +struct vhost_vdpa_iova_range iova_range;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); opts = &netdev->u.vhost_vdpa;
@@ -286,19 +301,20 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,qemu_close (vdpa_device_fd);return queue_pairs; } +vhost_vdpa_get_iova_range (vdpa_device_fd, &iova_range); ncs =g_malloc0 (sizeof (*ncs) * queue_pairs);for (i =0 ; i < queue_pairs; i++) { ncs[i] =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, - vdpa_device_fd, i,2 , true); + vdpa_device_fd, i,2 , true, iova_range);if (!ncs[i]) goto err; }if (has_cvq) { nc =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, - vdpa_device_fd, i,1 , false); + vdpa_device_fd, i,1 , false, iova_range);if (!nc) goto err; }
Signature · 1 line
2.27.0
Re: [PATCH 30/31] vdpa: Move vhost_vdpa_get_iova_range to net/vhost-vdpa.c
Quoted 8 lines · Eugenio Pérez
Since it's a device property, it can be done in
net/. This helps SVQ to allocate the rings in vdpa device initialization, rather than delay that.Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-vdpa.c | 15 --------------- net/vhost-vdpa.c | 32 ++++++++++++++++++++++++--------
I don't understand here, since we will support device other than net?
Quoted 12 lines
2 files changed, 24 insertions(+), 23 deletions(-)hw/virtio/vhost-vdpa.c +0
-2@@ -350,19 +350,6 @@ static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)return 0 ; } -static void vhost_vdpa_get_iova_range (struct vhost_vdpa *v) -{
hw/virtio/vhost-vdpa.c static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status) · line 364
Quoted 10 lines
hw/virtio/vhost-vdpa.c +0
-10-int ret =vhost_vdpa_call (v->dev,VHOST_VDPA_GET_IOVA_RANGE , - &v->iova_range); -if (ret !=0 ) { - v->iova_range.first =0 ; - v->iova_range.last =UINT64_MAX ; - } - -trace_vhost_vdpa_get_iova_range (v->dev, v->iova_range.first, - v->iova_range.last); -}
Let's just export this instead?
Thanks
Quoted 86 lines
hw/virtio/vhost-vdpa.c +0
-3-static bool vhost_vdpa_one_time_request (struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque;@@ -1295,8 +1282,6 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp) goto err; } -vhost_vdpa_get_iova_range (v); -if (vhost_vdpa_one_time_request (dev)) {return 0 ; }net/vhost-vdpa.c +23
-7@@ -22,6 +22,7 @@#include <sys/ioctl.h> #include <err.h> #include "standard-headers/linux/virtio_net.h" +#include "standard-headers/linux/vhost_types.h" #include "monitor/monitor.h" #include "hw/virtio/vhost.h" @@ -187,13 +188,25 @@ static NetClientInfo net_vhost_vdpa_info = { .check_peer_type = vhost_vdpa_check_peer_type, }; +static void vhost_vdpa_get_iova_range (int fd, +struct vhost_vdpa_iova_range *iova_range) +{ +int ret =ioctl (fd,VHOST_VDPA_GET_IOVA_RANGE , iova_range); + +if (ret <0 ) { + iova_range->first =0 ; + iova_range->last =UINT64_MAX ; + } +} +static NetClientState *net_vhost_vdpa_init (NetClientState *peer, -const char *device, -const char *name, -int vdpa_device_fd, -int queue_pair_index, -int nvqs, -bool is_datapath) +const char *device, +const char *name, +int vdpa_device_fd, +int queue_pair_index, +int nvqs, +bool is_datapath, +struct vhost_vdpa_iova_range iova_range) {NetClientState *nc =NULL ;VhostVDPAState *s;@@ -211,6 +224,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.device_fd = vdpa_device_fd; s->vhost_vdpa.index = queue_pair_index; + s->vhost_vdpa.iova_range = iova_range; ret =vhost_vdpa_add (nc, (void *)&s->vhost_vdpa, queue_pair_index, nvqs);if (ret) {qemu_del_net_client (nc);@@ -267,6 +281,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, g_autofree NetClientState **ncs = NULL;NetClientState *nc;int queue_pairs, i, has_cvq =0 ; +struct vhost_vdpa_iova_range iova_range;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); opts = &netdev->u.vhost_vdpa;@@ -286,19 +301,20 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,qemu_close (vdpa_device_fd);return queue_pairs; } +vhost_vdpa_get_iova_range (vdpa_device_fd, &iova_range); ncs =g_malloc0 (sizeof (*ncs) * queue_pairs);for (i =0 ; i < queue_pairs; i++) { ncs[i] =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, - vdpa_device_fd, i,2 , true); + vdpa_device_fd, i,2 , true, iova_range);if (!ncs[i])
net/vhost-vdpa.c int net_init_vhost_vdpa(const Netdev *netdev, const char *name, · line 320
Quoted 10 lines
net/vhost-vdpa.c +1
-1goto err; }if (has_cvq) { nc =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, - vdpa_device_fd, i,1 , false); + vdpa_device_fd, i,1 , false, iova_range);if (!nc) goto err; }
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Eugenio Perez Martin
maintainerRe: [PATCH 30/31] vdpa: Move vhost_vdpa_get_iova_range to net/vhost-vdpa.c
Quoted 26 lines · Jason Wang
Quoted 8 lines · Eugenio Pérez
Since it's a device property, it can be done in
net/. This helps SVQ to allocate the rings in vdpa device initialization, rather than delay that.Signed-off-by Eugenio Pérez <[email protected]>--- hw/virtio/vhost-vdpa.c | 15 --------------- net/vhost-vdpa.c | 32 ++++++++++++++++++++++++--------I don't understand here, since we will support device other than net?
Quoted 10 lines
2 files changed, 24 insertions(+), 23 deletions(-)hw/virtio/vhost-vdpa.c +0
-0@@ -350,19 +350,6 @@ static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status)return 0 ; }
Quoted 16 lines
hw/virtio/vhost-vdpa.c static int vhost_vdpa_add_status(struct vhost_dev *dev, uint8_t status) · line 364
Quoted 12 lines
hw/virtio/vhost-vdpa.c +0
-12-static void vhost_vdpa_get_iova_range (struct vhost_vdpa *v) -{ -int ret =vhost_vdpa_call (v->dev,VHOST_VDPA_GET_IOVA_RANGE , - &v->iova_range); -if (ret !=0 ) { - v->iova_range.first =0 ; - v->iova_range.last =UINT64_MAX ; - } - -trace_vhost_vdpa_get_iova_range (v->dev, v->iova_range.first, - v->iova_range.last); -}Let's just export this instead?
Yes, I see now that export is a better solution than moving.
Thanks!
Quoted 100 lines
Thanks
Quoted 96 lines
hw/virtio/vhost-vdpa.c +0
-3-static bool vhost_vdpa_one_time_request (struct vhost_dev *dev) {struct vhost_vdpa *v = dev->opaque;@@ -1295,8 +1282,6 @@ static int vhost_vdpa_init(struct vhost_dev *dev, void *opaque, Error **errp) goto err; } -vhost_vdpa_get_iova_range (v); -if (vhost_vdpa_one_time_request (dev)) {return 0 ; }net/vhost-vdpa.c +24
-8@@ -22,6 +22,7 @@#include <sys/ioctl.h> #include <err.h> #include "standard-headers/linux/virtio_net.h" +#include "standard-headers/linux/vhost_types.h" #include "monitor/monitor.h" #include "hw/virtio/vhost.h" @@ -187,13 +188,25 @@ static NetClientInfo net_vhost_vdpa_info = { .check_peer_type = vhost_vdpa_check_peer_type, }; +static void vhost_vdpa_get_iova_range (int fd, +struct vhost_vdpa_iova_range *iova_range) +{ +int ret =ioctl (fd,VHOST_VDPA_GET_IOVA_RANGE , iova_range); + +if (ret <0 ) { + iova_range->first =0 ; + iova_range->last =UINT64_MAX ; + } +} +static NetClientState *net_vhost_vdpa_init (NetClientState *peer, -const char *device, -const char *name, -int vdpa_device_fd, -int queue_pair_index, -int nvqs, -bool is_datapath) +const char *device, +const char *name, +int vdpa_device_fd, +int queue_pair_index, +int nvqs, +bool is_datapath, +struct vhost_vdpa_iova_range iova_range) {NetClientState *nc =NULL ;VhostVDPAState *s;@@ -211,6 +224,7 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.device_fd = vdpa_device_fd; s->vhost_vdpa.index = queue_pair_index; + s->vhost_vdpa.iova_range = iova_range; ret =vhost_vdpa_add (nc, (void *)&s->vhost_vdpa, queue_pair_index, nvqs);if (ret) {qemu_del_net_client (nc);@@ -267,6 +281,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, g_autofree NetClientState **ncs = NULL;NetClientState *nc;int queue_pairs, i, has_cvq =0 ; +struct vhost_vdpa_iova_range iova_range;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_VDPA ); opts = &netdev->u.vhost_vdpa;@@ -286,19 +301,20 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,qemu_close (vdpa_device_fd);return queue_pairs; } +vhost_vdpa_get_iova_range (vdpa_device_fd, &iova_range); ncs =g_malloc0 (sizeof (*ncs) * queue_pairs);for (i =0 ; i < queue_pairs; i++) { ncs[i] =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, - vdpa_device_fd, i,2 , true); + vdpa_device_fd, i,2 , true, iova_range);if (!ncs[i]) goto err; }if (has_cvq) { nc =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, - vdpa_device_fd, i,1 , false); + vdpa_device_fd, i,1 , false, iova_range);if (!nc) goto err; }
Eugenio Pérez
maintainerPATCH 31/31 vdpa: Add x-svq to NetdevVhostVDPAOptions
In reply to Eugenio PérezFinally offering the possibility to enable SVQ from the command line.
--- qapi/net.json | 5 ++++- net/vhost-vdpa.c | 27 ++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 4 deletions(-)
qapi/net.json +4 -1
@@ -445,12 +445,15 @@ # @queues: number of queues to be created for multiqueue vhost-vdpa # (default: 1) # +# @x-svq: Start device with (experimental) shadow virtqueue. (Since 7.0) +# # Since: 5.1 ## { 'struct': 'NetdevVhostVDPAOptions', 'data': { '*vhostdev': 'str', - '*queues': 'int' } } + '*queues': 'int', + '*x-svq': 'bool' } } ## # @NetClientDriver:
net/vhost-vdpa.c +24 -3
@@ -128,7 +128,11 @@ err_init:static void vhost_vdpa_cleanup (NetClientState *nc) {VhostVDPAState *s =DO_UPCAST (VhostVDPAState, nc, nc); +struct vhost_dev *dev = s->vhost_vdpa.dev; +if (dev && dev->vq_index + dev->nvqs == dev->vq_index_end) { +g_clear_pointer (&s->vhost_vdpa.iova_tree, vhost_iova_tree_delete); + }if (s->vhost_net) {vhost_net_cleanup (s->vhost_net);g_free (s->vhost_net);
@@ -206,7 +210,9 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer,int queue_pair_index, int nvqs, bool is_datapath, - struct vhost_vdpa_iova_range iova_range) + bool svq, + struct vhost_vdpa_iova_range iova_range, + VhostIOVATree *iova_tree) { NetClientState *nc = NULL;VhostVDPAState *s;
@@ -225,6 +231,8 @@ static NetClientState *net_vhost_vdpa_init(NetClientState *peer, s->vhost_vdpa.device_fd = vdpa_device_fd; s->vhost_vdpa.index = queue_pair_index; s->vhost_vdpa.iova_range = iova_range; + s->vhost_vdpa.shadow_vqs_enabled = svq; + s->vhost_vdpa.iova_tree = iova_tree; ret =vhost_vdpa_add (nc, (void *)&s->vhost_vdpa, queue_pair_index, nvqs);if (ret) {qemu_del_net_client (nc);
@@ -281,6 +289,7 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name, g_autofree NetClientState **ncs = NULL;NetClientState *nc;int queue_pairs, i, has_cvq =0 ; +g_autoptr (VhostIOVATree) iova_tree =NULL ;struct vhost_vdpa_iova_range iova_range;assert (netdev->type ==NET_CLIENT_DRIVER_VHOST_VDPA );
@@ -302,29 +311,41 @@ int net_init_vhost_vdpa(const Netdev *netdev, const char *name,return queue_pairs; }vhost_vdpa_get_iova_range (vdpa_device_fd, &iova_range); +if (opts->x_svq) { +if (has_cvq) { +error_setg (errp,"vdpa svq does not work with cvq" ); + goto err_svq; + } + iova_tree =vhost_iova_tree_new (iova_range.first, iova_range.last); + } ncs =g_malloc0 (sizeof (*ncs) * queue_pairs);for (i =0 ; i < queue_pairs; i++) { ncs[i] =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, - vdpa_device_fd, i,2 , true, iova_range); + vdpa_device_fd, i,2 , true, opts->x_svq, + iova_range, iova_tree);if (!ncs[i]) goto err; }if (has_cvq) { nc =net_vhost_vdpa_init (peer,TYPE_VHOST_VDPA , name, - vdpa_device_fd, i,1 , false, iova_range); + vdpa_device_fd, i,1 , false, opts->x_svq, + iova_range, iova_tree);if (!nc) goto err; } + iova_tree =NULL ;return 0 ; err:if (i) {qemu_del_net_client (ncs[0 ]); } + +err_svq:qemu_close (vdpa_device_fd);return -1 ;
Signature · 1 line
2.27.0
Quoted 46 lines · Eugenio Pérez
This series enables shadow virtqueue (SVQ) for vhost-vdpa devices. This is intended as a new method of tracking the memory the devices touch during a migration process: Instead of relay on vhost device's dirty logging capability, SVQ intercepts the VQ dataplane forwarding the descriptors between VM and device. This way qemu is the effective writer of guests memory, like in qemu's emulated virtio device operation.
When SVQ is enabled qemu offers a new virtual address space to the device to read and write into, and it maps new vrings and the guest memory in it. SVQ also intercepts kicks and calls between the device and the guest. Used buffers relay would cause dirty memory being tracked, but at this RFC SVQ is not enabled on migration automatically.
Thanks of being a buffers relay system, SVQ can be used also to communicate devices and drivers with different capabilities, like devices that only support packed vring and not split and old guests with no driver packed support.
It is based on the ideas of DPDK SW assisted LM, in the series of DPDK's https://patchwork.dpdk.org/cover/48370/ . However, these does not map the shadow vq in guest's VA, but in qemu's.
This version of SVQ is limited in the amount of features it can use with guest and device, because this series is already very big otherwise. Features like indirect or
event_idxwill be addressed in future series.SVQ needs to be enabled with cmdline parameter x-svq, like:
-netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-0,id=vhost-vdpa0,x-svq=true
In this version it cannot be enabled or disabled in runtime. Further series will remove this limitation and will enable it only for migration time.
Some patches are intentionally very small to ease review, but they can be squashed if preferred.
Patches 1-10 prepares the SVQ and QEMU to support both guest to device and device to guest notifications forwarding, with the extra qemu hop. That part can be tested in isolation if cmdline change is reproduced.
Patches from 11 to 18 implement the actual buffer forwarding, but with no IOMMU support. It requires a vdpa device capable of addressing all qemu vaddr.
Quoted 7 lines
Patches 19 to 23 adds the iommu support, so the device with address range limitations can access SVQ through this new virtual address space created.
The rest of the series add the last pieces needed for migration.
Comments are welcome.
I wonder the performance impact. So performance numbers are more than welcomed.
Thanks
Quoted 133 lines
TODO:
* Event, indirect, packed, and other features of virtio.
* To separate buffers forwarding in its own AIO context, so we can throw more threads to that task and we don't need to stop the main event loop.
* Support virtio-net control vq.
* Proper documentation.Changes from v5 RFC:
* Remove dynamic enablement of SVQ, making less dependent of the device.
* Enable live migration if SVQ is enabled.
* Fix SVQ when driver reset.
* Comments addressed, specially in the iova area.
* Rebase on latest master, adding multiqueue support (but no networking control vq processing).
v5 link:
https://lists.gnu.org/archive/html/qemu-devel/2021-10/msg07250.htmlChanges from v4 RFC:
* Support of allocating / freeing iova ranges in IOVA tree. Extending already present iova-tree for that.
* Proper validation of guest features. Now SVQ can negotiate a different set of features with the device when enabled.
* Support of host notifiers memory regions
* Handling of SVQ full queue in case guest's descriptors span to different memory regions (qemu's VA chunks).
* Flush pending used buffers at end of SVQ operation.
* QMP command now looks by NetClientState name. Other devices will need to implement it's way to enable vdpa.
* Rename QMP command to set, so it looks more like a way of working
* Better use of qemu error system
* Make a few assertions proper error-handling paths.
* Add more documentation
* Less coupling of virtio / vhost, that could cause friction on changes
* Addressed many other small comments and small fixes.Changes from v3 RFC:
* Move everything to vhost-vdpa backend. A big change, this allowed some cleanup but more code has been added in other places.
* More use of glib utilities, especially to manage memory.
v3 link:
https://lists.nongnu.org/archive/html/qemu-devel/2021-05/msg06032.htmlChanges from v2 RFC:
* Adding vhost-vdpa devices support
* Fixed some memory leaks pointed by different comments
v2 link:
https://lists.nongnu.org/archive/html/qemu-devel/2021-03/msg05600.htmlChanges from v1 RFC:
* Use QMP instead of migration to start SVQ mode.
* Only accepting IOMMU devices, closer behavior with target devices(vDPA)* Fix invalid masking/unmasking of vhost call fd.
* Use of proper methods for synchronization.
* No need to modify VirtIO device code, all of the changes are contained in vhost code.
* Delete superfluous code.
* An intermediate RFC was sent with only the notifications forwarding changes. It can be seen in
https://patchew.org/QEMU/[email protected]/
v1 link:
https://lists.gnu.org/archive/html/qemu-devel/2020-11/msg05372.htmlEugenio Pérez (20):
virtio: AddVIRTIO_F_QUEUE_STATE
virtio-net: HonorVIRTIO_CONFIG_S_DEVICE_STOPPED
virtio: Addvirtio_queue_is_host_notifier_enabled
vhost: Make vhost_virtqueue_{start,stop} public
vhost: Add x-vhost-enable-shadow-vq qmp
vhost: Add VhostShadowVirtqueue
vdpa: Register vdpa devices in a list
vhost: Routeguest->hostnotification through shadow virtqueue Addvhost_svq_get_svq_call_notifier
Addvhost_svq_set_guest_call_notifier
vdpa: Savecall_fdin vhost-vdpa
vhost-vdpa: Take into account SVQ invhost_vdpa_set_vring_call
vhost: Routehost->guestnotification through shadow virtqueue
virtio: Addvhost_shadow_vq_get_vring_addr
vdpa: Save host and guest features
vhost: Addvhost_svq_valid_device_featuresto shadow vq
vhost: Shadow virtqueue buffers forwarding
vhost: Add VhostIOVATree
vhost: Use a tree to store memory mappings
vdpa: Add custom IOTLB translations to SVQEugenio Pérez (31):
vdpa: Reordervirtio/vhost-vdpa.cfunctions
vhost: Add VhostShadowVirtqueue
vdpa: Addvhost_svq_get_dev_kick_notifier
vdpa: Addvhost_svq_set_svq_kick_fd
vhost: Add Shadow VirtQueue kick forwarding capabilities
vhost: Routeguest->hostnotification through shadow virtqueue
vhost: ddvhost_svq_get_svq_call_notifier
vhost: Addvhost_svq_set_guest_call_notifier
vhost-vdpa: Take into account SVQ invhost_vdpa_set_vring_call
vhost: Routehost->guestnotification through shadow virtqueue
vhost: Addvhost_svq_valid_device_featuresto shadow vq
vhost: Addvhost_svq_valid_guest_featuresto shadow vq
vhost: Addvhost_svq_ack_guest_featuresto shadow vq
virtio: Addvhost_shadow_vq_get_vring_addr
vdpa: Addvhost_svq_get_num
vhost: pass queue index tovhost_vq_get_addr
vdpa: adaptvhost_opscallbacks to svq
vhost: Shadow virtqueue buffers forwarding
utils: Add internal DMAMap to iova-tree
util: Store DMA entries in a list
util: Addiova_tree_alloc
vhost: Add VhostIOVATree
vdpa: Add custom IOTLB translations to SVQ
vhost: Addvhost_svq_get_last_used_idx
vdpa: Adaptvhost_vdpa_get_vring_baseto SVQ
vdpa: ClearVHOST_VRING_F_LOGatvhost_vdpa_set_vring_addrin SVQ
vdpa: Never setlog_baseaddr if SVQ is enabled
vdpa: ExposeVHOST_F_LOG_ALLon SVQ
vdpa: Make ncs autofree
vdpa: Movevhost_vdpa_get_iova_rangetonet/vhost-vdpa.c
vdpa: Add x-svq to NetdevVhostVDPAOptionsqapi/net.json | 5 +- hw/virtio/vhost-iova-tree.h | 27 + hw/virtio/vhost-shadow-virtqueue.h | 46 ++ include/hw/virtio/vhost-vdpa.h | 7 + include/qemu/iova-tree.h | 17 + hw/virtio/vhost-iova-tree.c | 157 ++++++ hw/virtio/vhost-shadow-virtqueue.c | 761 +++++++++++++++++++++++++++++ hw/virtio/vhost-vdpa.c | 740 ++++++++++++++++++++++++---- hw/virtio/vhost.c | 6 +- net/vhost-vdpa.c | 58 ++- util/iova-tree.c | 161 +++++- hw/virtio/meson.build | 2 +- 12 files changed, 1852 insertions(+), 135 deletions(-)
Quoted 5 lines
create mode 100644
hw/virtio/vhost-iova-tree.hcreate mode 100644hw/virtio/vhost-shadow-virtqueue.hcreate mode 100644hw/virtio/vhost-iova-tree.ccreate mode 100644hw/virtio/vhost-shadow-virtqueue.c
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Eugenio Perez Martin
maintainerQuoted 53 lines · Jason Wang
Quoted 50 lines · Eugenio Pérez
This series enables shadow virtqueue (SVQ) for vhost-vdpa devices. This is intended as a new method of tracking the memory the devices touch during a migration process: Instead of relay on vhost device's dirty logging capability, SVQ intercepts the VQ dataplane forwarding the descriptors between VM and device. This way qemu is the effective writer of guests memory, like in qemu's emulated virtio device operation.
When SVQ is enabled qemu offers a new virtual address space to the device to read and write into, and it maps new vrings and the guest memory in it. SVQ also intercepts kicks and calls between the device and the guest. Used buffers relay would cause dirty memory being tracked, but at this RFC SVQ is not enabled on migration automatically.
Thanks of being a buffers relay system, SVQ can be used also to communicate devices and drivers with different capabilities, like devices that only support packed vring and not split and old guests with no driver packed support.
It is based on the ideas of DPDK SW assisted LM, in the series of DPDK's https://patchwork.dpdk.org/cover/48370/ . However, these does not map the shadow vq in guest's VA, but in qemu's.
This version of SVQ is limited in the amount of features it can use with guest and device, because this series is already very big otherwise. Features like indirect or
event_idxwill be addressed in future series.SVQ needs to be enabled with cmdline parameter x-svq, like:
-netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-0,id=vhost-vdpa0,x-svq=true
In this version it cannot be enabled or disabled in runtime. Further series will remove this limitation and will enable it only for migration time.
Some patches are intentionally very small to ease review, but they can be squashed if preferred.
Patches 1-10 prepares the SVQ and QEMU to support both guest to device and device to guest notifications forwarding, with the extra qemu hop. That part can be tested in isolation if cmdline change is reproduced.
Patches from 11 to 18 implement the actual buffer forwarding, but with no IOMMU support. It requires a vdpa device capable of addressing all qemu vaddr.
Patches 19 to 23 adds the iommu support, so the device with address range limitations can access SVQ through this new virtual address space created.
Quoted 8 lines
Quoted 3 lines
The rest of the series add the last pieces needed for migration.
Comments are welcome.
I wonder the performance impact. So performance numbers are more than welcomed.
Sure, I'll do it for the next revision. Since this one brings a decent amount of changes, I chose to collect the feedback first.
Thanks!
Quoted 142 lines
Thanks
Quoted 138 lines
TODO:
* Event, indirect, packed, and other features of virtio.
* To separate buffers forwarding in its own AIO context, so we can throw more threads to that task and we don't need to stop the main event loop.
* Support virtio-net control vq.
* Proper documentation.Changes from v5 RFC:
* Remove dynamic enablement of SVQ, making less dependent of the device.
* Enable live migration if SVQ is enabled.
* Fix SVQ when driver reset.
* Comments addressed, specially in the iova area.
* Rebase on latest master, adding multiqueue support (but no networking control vq processing).
v5 link:
https://lists.gnu.org/archive/html/qemu-devel/2021-10/msg07250.htmlChanges from v4 RFC:
* Support of allocating / freeing iova ranges in IOVA tree. Extending already present iova-tree for that.
* Proper validation of guest features. Now SVQ can negotiate a different set of features with the device when enabled.
* Support of host notifiers memory regions
* Handling of SVQ full queue in case guest's descriptors span to different memory regions (qemu's VA chunks).
* Flush pending used buffers at end of SVQ operation.
* QMP command now looks by NetClientState name. Other devices will need to implement it's way to enable vdpa.
* Rename QMP command to set, so it looks more like a way of working
* Better use of qemu error system
* Make a few assertions proper error-handling paths.
* Add more documentation
* Less coupling of virtio / vhost, that could cause friction on changes
* Addressed many other small comments and small fixes.Changes from v3 RFC:
* Move everything to vhost-vdpa backend. A big change, this allowed some cleanup but more code has been added in other places.
* More use of glib utilities, especially to manage memory.
v3 link:
https://lists.nongnu.org/archive/html/qemu-devel/2021-05/msg06032.htmlChanges from v2 RFC:
* Adding vhost-vdpa devices support
* Fixed some memory leaks pointed by different comments
v2 link:
https://lists.nongnu.org/archive/html/qemu-devel/2021-03/msg05600.htmlChanges from v1 RFC:
* Use QMP instead of migration to start SVQ mode.
* Only accepting IOMMU devices, closer behavior with target devices(vDPA)* Fix invalid masking/unmasking of vhost call fd.
* Use of proper methods for synchronization.
* No need to modify VirtIO device code, all of the changes are contained in vhost code.
* Delete superfluous code.
* An intermediate RFC was sent with only the notifications forwarding changes. It can be seen in
https://patchew.org/QEMU/[email protected]/
v1 link:
https://lists.gnu.org/archive/html/qemu-devel/2020-11/msg05372.htmlEugenio Pérez (20):
virtio: AddVIRTIO_F_QUEUE_STATE
virtio-net: HonorVIRTIO_CONFIG_S_DEVICE_STOPPED
virtio: Addvirtio_queue_is_host_notifier_enabled
vhost: Make vhost_virtqueue_{start,stop} public
vhost: Add x-vhost-enable-shadow-vq qmp
vhost: Add VhostShadowVirtqueue
vdpa: Register vdpa devices in a list
vhost: Routeguest->hostnotification through shadow virtqueue Addvhost_svq_get_svq_call_notifier
Addvhost_svq_set_guest_call_notifier
vdpa: Savecall_fdin vhost-vdpa
vhost-vdpa: Take into account SVQ invhost_vdpa_set_vring_call
vhost: Routehost->guestnotification through shadow virtqueue
virtio: Addvhost_shadow_vq_get_vring_addr
vdpa: Save host and guest features
vhost: Addvhost_svq_valid_device_featuresto shadow vq
vhost: Shadow virtqueue buffers forwarding
vhost: Add VhostIOVATree
vhost: Use a tree to store memory mappings
vdpa: Add custom IOTLB translations to SVQEugenio Pérez (31):
vdpa: Reordervirtio/vhost-vdpa.cfunctions
vhost: Add VhostShadowVirtqueue
vdpa: Addvhost_svq_get_dev_kick_notifier
vdpa: Addvhost_svq_set_svq_kick_fd
vhost: Add Shadow VirtQueue kick forwarding capabilities
vhost: Routeguest->hostnotification through shadow virtqueue
vhost: ddvhost_svq_get_svq_call_notifier
vhost: Addvhost_svq_set_guest_call_notifier
vhost-vdpa: Take into account SVQ invhost_vdpa_set_vring_call
vhost: Routehost->guestnotification through shadow virtqueue
vhost: Addvhost_svq_valid_device_featuresto shadow vq
vhost: Addvhost_svq_valid_guest_featuresto shadow vq
vhost: Addvhost_svq_ack_guest_featuresto shadow vq
virtio: Addvhost_shadow_vq_get_vring_addr
vdpa: Addvhost_svq_get_num
vhost: pass queue index tovhost_vq_get_addr
vdpa: adaptvhost_opscallbacks to svq
vhost: Shadow virtqueue buffers forwarding
utils: Add internal DMAMap to iova-tree
util: Store DMA entries in a list
util: Addiova_tree_alloc
vhost: Add VhostIOVATree
vdpa: Add custom IOTLB translations to SVQ
vhost: Addvhost_svq_get_last_used_idx
vdpa: Adaptvhost_vdpa_get_vring_baseto SVQ
vdpa: ClearVHOST_VRING_F_LOGatvhost_vdpa_set_vring_addrin SVQ
vdpa: Never setlog_baseaddr if SVQ is enabled
vdpa: ExposeVHOST_F_LOG_ALLon SVQ
vdpa: Make ncs autofree
vdpa: Movevhost_vdpa_get_iova_rangetonet/vhost-vdpa.c
vdpa: Add x-svq to NetdevVhostVDPAOptionsqapi/net.json | 5 +- hw/virtio/vhost-iova-tree.h | 27 + hw/virtio/vhost-shadow-virtqueue.h | 46 ++ include/hw/virtio/vhost-vdpa.h | 7 + include/qemu/iova-tree.h | 17 + hw/virtio/vhost-iova-tree.c | 157 ++++++ hw/virtio/vhost-shadow-virtqueue.c | 761 +++++++++++++++++++++++++++++ hw/virtio/vhost-vdpa.c | 740 ++++++++++++++++++++++++---- hw/virtio/vhost.c | 6 +- net/vhost-vdpa.c | 58 ++- util/iova-tree.c | 161 +++++- hw/virtio/meson.build | 2 +- 12 files changed, 1852 insertions(+), 135 deletions(-)create mode 100644
hw/virtio/vhost-iova-tree.hcreate mode 100644hw/virtio/vhost-shadow-virtqueue.hcreate mode 100644hw/virtio/vhost-iova-tree.ccreate mode 100644hw/virtio/vhost-shadow-virtqueue.c
Quoted 55 lines · Eugenio Perez Martin
Quoted 54 lines · Jason Wang
Quoted 52 lines · Eugenio Pérez
This series enables shadow virtqueue (SVQ) for vhost-vdpa devices. This is intended as a new method of tracking the memory the devices touch during a migration process: Instead of relay on vhost device's dirty logging capability, SVQ intercepts the VQ dataplane forwarding the descriptors between VM and device. This way qemu is the effective writer of guests memory, like in qemu's emulated virtio device operation.
When SVQ is enabled qemu offers a new virtual address space to the device to read and write into, and it maps new vrings and the guest memory in it. SVQ also intercepts kicks and calls between the device and the guest. Used buffers relay would cause dirty memory being tracked, but at this RFC SVQ is not enabled on migration automatically.
Thanks of being a buffers relay system, SVQ can be used also to communicate devices and drivers with different capabilities, like devices that only support packed vring and not split and old guests with no driver packed support.
It is based on the ideas of DPDK SW assisted LM, in the series of DPDK's https://patchwork.dpdk.org/cover/48370/ . However, these does not map the shadow vq in guest's VA, but in qemu's.
This version of SVQ is limited in the amount of features it can use with guest and device, because this series is already very big otherwise. Features like indirect or
event_idxwill be addressed in future series.SVQ needs to be enabled with cmdline parameter x-svq, like:
-netdev type=vhost-vdpa,vhostdev=/dev/vhost-vdpa-0,id=vhost-vdpa0,x-svq=true
In this version it cannot be enabled or disabled in runtime. Further series will remove this limitation and will enable it only for migration time.
Some patches are intentionally very small to ease review, but they can be squashed if preferred.
Patches 1-10 prepares the SVQ and QEMU to support both guest to device and device to guest notifications forwarding, with the extra qemu hop. That part can be tested in isolation if cmdline change is reproduced.
Patches from 11 to 18 implement the actual buffer forwarding, but with no IOMMU support. It requires a vdpa device capable of addressing all qemu vaddr.
Patches 19 to 23 adds the iommu support, so the device with address range limitations can access SVQ through this new virtual address space created.
The rest of the series add the last pieces needed for migration.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Comments are welcome.
I wonder the performance impact. So performance numbers are more than welcomed.
Sure, I'll do it for the next revision. Since this one brings a decent amount of changes, I chose to collect the feedback first.
A simple single TCP_STREAM netperf test should be sufficient to give some basic understanding about the performance impact.
Thanks
Quoted 143 lines
Thanks!
Quoted 140 lines
Thanks
Quoted 137 lines
TODO:
* Event, indirect, packed, and other features of virtio.
* To separate buffers forwarding in its own AIO context, so we can throw more threads to that task and we don't need to stop the main event loop.
* Support virtio-net control vq.
* Proper documentation.Changes from v5 RFC:
* Remove dynamic enablement of SVQ, making less dependent of the device.
* Enable live migration if SVQ is enabled.
* Fix SVQ when driver reset.
* Comments addressed, specially in the iova area.
* Rebase on latest master, adding multiqueue support (but no networking control vq processing).
v5 link:
https://lists.gnu.org/archive/html/qemu-devel/2021-10/msg07250.htmlChanges from v4 RFC:
* Support of allocating / freeing iova ranges in IOVA tree. Extending already present iova-tree for that.
* Proper validation of guest features. Now SVQ can negotiate a different set of features with the device when enabled.
* Support of host notifiers memory regions
* Handling of SVQ full queue in case guest's descriptors span to different memory regions (qemu's VA chunks).
* Flush pending used buffers at end of SVQ operation.
* QMP command now looks by NetClientState name. Other devices will need to implement it's way to enable vdpa.
* Rename QMP command to set, so it looks more like a way of working
* Better use of qemu error system
* Make a few assertions proper error-handling paths.
* Add more documentation
* Less coupling of virtio / vhost, that could cause friction on changes
* Addressed many other small comments and small fixes.Changes from v3 RFC:
* Move everything to vhost-vdpa backend. A big change, this allowed some cleanup but more code has been added in other places.
* More use of glib utilities, especially to manage memory.
v3 link:
https://lists.nongnu.org/archive/html/qemu-devel/2021-05/msg06032.htmlChanges from v2 RFC:
* Adding vhost-vdpa devices support
* Fixed some memory leaks pointed by different comments
v2 link:
https://lists.nongnu.org/archive/html/qemu-devel/2021-03/msg05600.htmlChanges from v1 RFC:
* Use QMP instead of migration to start SVQ mode.
* Only accepting IOMMU devices, closer behavior with target devices (vDPA)
* Fix invalid masking/unmasking of vhost call fd.
* Use of proper methods for synchronization.
* No need to modify VirtIO device code, all of the changes are contained in vhost code.
* Delete superfluous code.
* An intermediate RFC was sent with only the notifications forwarding changes. It can be seen in
https://patchew.org/QEMU/[email protected]/
v1 link:
https://lists.gnu.org/archive/html/qemu-devel/2020-11/msg05372.htmlEugenio Pérez (20):
virtio: AddVIRTIO_F_QUEUE_STATE
virtio-net: HonorVIRTIO_CONFIG_S_DEVICE_STOPPED
virtio: Addvirtio_queue_is_host_notifier_enabled
vhost: Make vhost_virtqueue_{start,stop} public
vhost: Add x-vhost-enable-shadow-vq qmp
vhost: Add VhostShadowVirtqueue
vdpa: Register vdpa devices in a list
vhost: Routeguest->hostnotification through shadow virtqueue Addvhost_svq_get_svq_call_notifier
Addvhost_svq_set_guest_call_notifier
vdpa: Savecall_fdin vhost-vdpa
vhost-vdpa: Take into account SVQ invhost_vdpa_set_vring_call
vhost: Routehost->guestnotification through shadow virtqueue
virtio: Addvhost_shadow_vq_get_vring_addr
vdpa: Save host and guest features
vhost: Addvhost_svq_valid_device_featuresto shadow vq
vhost: Shadow virtqueue buffers forwarding
vhost: Add VhostIOVATree
vhost: Use a tree to store memory mappings
vdpa: Add custom IOTLB translations to SVQEugenio Pérez (31):
vdpa: Reordervirtio/vhost-vdpa.cfunctions
vhost: Add VhostShadowVirtqueue
vdpa: Addvhost_svq_get_dev_kick_notifier
vdpa: Addvhost_svq_set_svq_kick_fd
vhost: Add Shadow VirtQueue kick forwarding capabilities
vhost: Routeguest->hostnotification through shadow virtqueue
vhost: ddvhost_svq_get_svq_call_notifier
vhost: Addvhost_svq_set_guest_call_notifier
vhost-vdpa: Take into account SVQ invhost_vdpa_set_vring_call
vhost: Routehost->guestnotification through shadow virtqueue
vhost: Addvhost_svq_valid_device_featuresto shadow vq
vhost: Addvhost_svq_valid_guest_featuresto shadow vq
vhost: Addvhost_svq_ack_guest_featuresto shadow vq
virtio: Addvhost_shadow_vq_get_vring_addr
vdpa: Addvhost_svq_get_num
vhost: pass queue index tovhost_vq_get_addr
vdpa: adaptvhost_opscallbacks to svq
vhost: Shadow virtqueue buffers forwarding
utils: Add internal DMAMap to iova-tree
util: Store DMA entries in a list
util: Addiova_tree_alloc
vhost: Add VhostIOVATree
vdpa: Add custom IOTLB translations to SVQ
vhost: Addvhost_svq_get_last_used_idx
vdpa: Adaptvhost_vdpa_get_vring_baseto SVQ
vdpa: ClearVHOST_VRING_F_LOGatvhost_vdpa_set_vring_addrin SVQ
vdpa: Never setlog_baseaddr if SVQ is enabled
vdpa: ExposeVHOST_F_LOG_ALLon SVQ
vdpa: Make ncs autofree
vdpa: Movevhost_vdpa_get_iova_rangetonet/vhost-vdpa.c
vdpa: Add x-svq to NetdevVhostVDPAOptionsqapi/net.json | 5 +- hw/virtio/vhost-iova-tree.h | 27 + hw/virtio/vhost-shadow-virtqueue.h | 46 ++ include/hw/virtio/vhost-vdpa.h | 7 + include/qemu/iova-tree.h | 17 + hw/virtio/vhost-iova-tree.c | 157 ++++++ hw/virtio/vhost-shadow-virtqueue.c | 761 +++++++++++++++++++++++++++++ hw/virtio/vhost-vdpa.c | 740 ++++++++++++++++++++++++---- hw/virtio/vhost.c | 6 +- net/vhost-vdpa.c | 58 ++- util/iova-tree.c | 161 +++++- hw/virtio/meson.build | 2 +- 12 files changed, 1852 insertions(+), 135 deletions(-)create mode 100644
hw/virtio/vhost-iova-tree.hcreate mode 100644hw/virtio/vhost-shadow-virtqueue.hcreate mode 100644hw/virtio/vhost-iova-tree.ccreate mode 100644hw/virtio/vhost-shadow-virtqueue.c
_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization