On 24/06/2024 05:02, David Gibson wrote:
On Fri, Jun 21, 2024 at 04:56:38PM +0200, Laurent Vivier wrote:
Add vhost_user.c and vhost_user.h that define the functions needed to implement vhost-user backend.
Signed-off-by: Laurent Vivier
I'm a little confused by this patch. The commit message seems to suggest that like the previous patch it's basically just a code import from qemu. However...
[snip]
diff --git a/passt.c b/passt.c index a5e2c5a8e151..9d21c545b9cf 100644 --- a/passt.c +++ b/passt.c @@ -73,6 +73,8 @@ char *epoll_type_str[] = { [EPOLL_TYPE_TAP_PASTA] = "/dev/net/tun device", [EPOLL_TYPE_TAP_PASST] = "connected qemu socket", [EPOLL_TYPE_TAP_LISTEN] = "listening qemu socket", + [EPOLL_TYPE_VHOST_CMD] = "vhost-user command socket", + [EPOLL_TYPE_VHOST_KICK] = "vhost-user kick socket",
... we also have real changes to passt specific code. It's not very obvious to me what the boundaries of that are.
I have moved all of this to the last patch. ...
+/* Translate qemu virtual address to our virtual address. */
Now that this code is not in qemu, it's not very clear what either of these "virtual addresses" is.
It's actually QEMU virtual address (QEMU or any other vhost-user client). it's also called userspace address in vhost data structure but I don't like this term as we don't know if it's our userspace or the user space of the vhost-user client. Our userspace address is called mmap address. We have also the guest physical address that is the address from inside the guest. The vring addresses are provided from the QEMU userspace address (information from the vhost-user level): https://qemu-project.gitlab.io/qemu/interop/vhost-user.html#a-vring-address-... The descriptor ring addresses are provided from the guest space so they are physical addresses (information from the virtio level): https://docs.oasis-open.org/virtio/virtio/v1.1/cs01/virtio-v1.1-cs01.html#x1...
+static void *qva_to_va(VuDev *dev, uint64_t qemu_addr) +{ + unsigned int i; + + /* Find matching memory region. */ + for (i = 0; i < dev->nregions; i++) { + const VuDevRegion *r = &dev->regions[i]; + + if ((qemu_addr >= r->qva) && (qemu_addr < (r->qva + r->size))) { + /* NOLINTNEXTLINE(performance-no-int-to-ptr) */ + return (void *)(qemu_addr - r->qva + r->mmap_addr + + r->mmap_offset); + } + } + + return NULL; +}
This function translate the QEMU userspace address to our process userspace address (mmapped memory). I'm updating all the function comment headers to describe this kind of information. Thanks, Laurent