On Tue, Oct 27, 2015 at 02:29:25PM +0800, Yuanhan Liu wrote:
> On Tue, Oct 27, 2015 at 03:12:53PM +0900, Tetsuya Mukawa wrote:
> > The patch fixes wrong handling of virtqueue array index.
> > 
> > GET_VRING_BASE:
> > The vhost backend will receive the message per virtqueue.
> 
> No, that's not right, we will get GET_VRING_BASE for each queue pair,
> including RX and TX virt queue, but not each virt queue.

Oops, you are right, and I was right in the first time till
Huawei pointted out that I made some unexpected change, and
I then checked the code, I then made a wrong decison (a
bit too tired recently :(

So, I will look at this patch, again.

Sorry for that.

        --yliu
> 
> > Also we should call a destroy callback when both RXQ and TXQ receives
> > the message.
> > 
> > SET_BACKEND:
> > Because vhost library supports multiple queue, the index may be over 2.
> > Also a vhost frontend(QEMU) may send such a index.
> > 
> > Signed-off-by: Tetsuya Mukawa <mukawa at igel.co.jp>
> > ---
> >  lib/librte_vhost/vhost_user/virtio-net-user.c | 22 +++++++++++-----------
> >  lib/librte_vhost/virtio-net.c                 |  5 +++--
> >  2 files changed, 14 insertions(+), 13 deletions(-)
> > 
> > diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c 
> > b/lib/librte_vhost/vhost_user/virtio-net-user.c
> > index a998ad8..3e8dfea 100644
> > --- a/lib/librte_vhost/vhost_user/virtio-net-user.c
> > +++ b/lib/librte_vhost/vhost_user/virtio-net-user.c
> > @@ -283,12 +283,10 @@ user_get_vring_base(struct vhost_device_ctx ctx,
> >     struct vhost_vring_state *state)
> >  {
> >     struct virtio_net *dev = get_device(ctx);
> > +   uint16_t base_idx = state->index / VIRTIO_QNUM;
> 
> For the Nth queue (pair), the "state->index" equals to  N * 2.
> So, dividing it by VIRTIO_QNUM (2) is wrong here.
> 
>       --yliu
> 
> >  
> >     if (dev == NULL)
> >             return -1;
> > -   /* We have to stop the queue (virtio) if it is running. */
> > -   if (dev->flags & VIRTIO_DEV_RUNNING)
> > -           notify_ops->destroy_device(dev);
> >  
> >     /* Here we are safe to get the last used index */
> >     ops->get_vring_base(ctx, state->index, state);
> > @@ -300,15 +298,17 @@ user_get_vring_base(struct vhost_device_ctx ctx,
> >      * sent and only sent in vhost_vring_stop.
> >      * TODO: cleanup the vring, it isn't usable since here.
> >      */
> > -   if (dev->virtqueue[state->index + VIRTIO_RXQ]->kickfd >= 0) {
> > -           close(dev->virtqueue[state->index + VIRTIO_RXQ]->kickfd);
> > -           dev->virtqueue[state->index + VIRTIO_RXQ]->kickfd = -1;
> > -   }
> > -   if (dev->virtqueue[state->index + VIRTIO_TXQ]->kickfd >= 0) {
> > -           close(dev->virtqueue[state->index + VIRTIO_TXQ]->kickfd);
> > -           dev->virtqueue[state->index + VIRTIO_TXQ]->kickfd = -1;
> > +   if (dev->virtqueue[state->index]->kickfd >= 0) {
> > +           close(dev->virtqueue[state->index]->kickfd);
> > +           dev->virtqueue[state->index]->kickfd = -1;
> >     }
> >  
> > +   /* We have to stop the queue (virtio) if it is running. */
> > +   if ((dev->flags & VIRTIO_DEV_RUNNING) &&
> > +                   (dev->virtqueue[base_idx + VIRTIO_RXQ]->kickfd == -1) &&
> > +                   (dev->virtqueue[base_idx + VIRTIO_TXQ]->kickfd == -1))
> > +           notify_ops->destroy_device(dev);
> > +
> >     return 0;
> >  }
> >  
> > @@ -321,7 +321,7 @@ user_set_vring_enable(struct vhost_device_ctx ctx,
> >                   struct vhost_vring_state *state)
> >  {
> >     struct virtio_net *dev = get_device(ctx);
> > -   uint16_t base_idx = state->index;
> > +   uint16_t base_idx = state->index / VIRTIO_QNUM;
> >     int enable = (int)state->num;
> >  
> >     RTE_LOG(INFO, VHOST_CONFIG,
> > diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c
> > index 97213c5..ee2e84d 100644
> > --- a/lib/librte_vhost/virtio-net.c
> > +++ b/lib/librte_vhost/virtio-net.c
> > @@ -778,6 +778,7 @@ static int
> >  set_backend(struct vhost_device_ctx ctx, struct vhost_vring_file *file)
> >  {
> >     struct virtio_net *dev;
> > +   uint32_t base_idx = file->index / VIRTIO_QNUM;
> >  
> >     dev = get_device(ctx);
> >     if (dev == NULL)
> > @@ -791,8 +792,8 @@ set_backend(struct vhost_device_ctx ctx, struct 
> > vhost_vring_file *file)
> >      * we add the device.
> >      */
> >     if (!(dev->flags & VIRTIO_DEV_RUNNING)) {
> > -           if (((int)dev->virtqueue[VIRTIO_TXQ]->backend != 
> > VIRTIO_DEV_STOPPED) &&
> > -                   ((int)dev->virtqueue[VIRTIO_RXQ]->backend != 
> > VIRTIO_DEV_STOPPED)) {
> > +           if (((int)dev->virtqueue[base_idx + VIRTIO_RXQ]->backend != 
> > VIRTIO_DEV_STOPPED) &&
> > +                   ((int)dev->virtqueue[base_idx + VIRTIO_TXQ]->backend != 
> > VIRTIO_DEV_STOPPED)) {
> >                     return notify_ops->new_device(dev);
> >             }
> >     /* Otherwise we remove it. */
> > -- 
> > 2.1.4

Reply via email to