Jason Wang
2022-Feb-08 06:58 UTC
[PATCH 16/31] vhost: pass queue index to vhost_vq_get_addr
? 2022/2/1 ??1:44, Eugenio Perez Martin ??:> On Sat, Jan 29, 2022 at 9:20 AM Jason Wang <jasowang at redhat.com> wrote: >> >> ? 2022/1/22 ??4:27, Eugenio P?rez ??: >>> Doing that way allows vhost backend to know what address to return. >>> >>> Signed-off-by: Eugenio P?rez <eperezma at redhat.com> >>> --- >>> hw/virtio/vhost.c | 6 +++--- >>> 1 file changed, 3 insertions(+), 3 deletions(-) >>> >>> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c >>> index 7b03efccec..64b955ba0c 100644 >>> --- a/hw/virtio/vhost.c >>> +++ b/hw/virtio/vhost.c >>> @@ -798,9 +798,10 @@ static int vhost_virtqueue_set_addr(struct vhost_dev *dev, >>> struct vhost_virtqueue *vq, >>> unsigned idx, bool enable_log) >>> { >>> - struct vhost_vring_addr addr; >>> + struct vhost_vring_addr addr = { >>> + .index = idx, >>> + }; >>> int r; >>> - memset(&addr, 0, sizeof(struct vhost_vring_addr)); >>> >>> if (dev->vhost_ops->vhost_vq_get_addr) { >>> r = dev->vhost_ops->vhost_vq_get_addr(dev, &addr, vq); >>> @@ -813,7 +814,6 @@ static int vhost_virtqueue_set_addr(struct vhost_dev *dev, >>> addr.avail_user_addr = (uint64_t)(unsigned long)vq->avail; >>> addr.used_user_addr = (uint64_t)(unsigned long)vq->used; >>> } >> >> I'm a bit lost in the logic above, any reason we need call >> vhost_vq_get_addr() :) ? >> > It's the way vhost_virtqueue_set_addr works if the backend has a > vhost_vq_get_addr operation (currently, only vhost-vdpa). vhost first > ask the address to the back end and then set it.Right it's because vhost-vdpa doesn't use VA but GPA. But I'm not sure it's worth a dedicated vhost_ops. But consider we introduce shadow virtqueue stuffs, it should be ok now. (In the future, we may consider to generalize non vhost-vdpa specific stuffs to VhostShadowVirtqueue, then we can get rid of this vhost_ops.> > Previously, index was not needed because all the information was in > vhost_virtqueue. However to extract queue index from vhost_virtqueue > is tricky, so I think it's easier to simply have that information at > request, something similar to get_base or get_num when asking vdpa > device. We can extract the index from vq - dev->vqs or something > similar if it's prefered.It looks odd for the caller to tell the index consider vhost_virtqueue is already passed. So I think we need deduce it from vhost_virtqueue as you mentioned here. Thanks> > Thanks! > >> Thanks >> >> >>> - addr.index = idx; >>> addr.log_guest_addr = vq->used_phys; >>> addr.flags = enable_log ? (1 << VHOST_VRING_F_LOG) : 0; >>> r = dev->vhost_ops->vhost_set_vring_addr(dev, &addr);