From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by dpdk.org (Postfix) with ESMTP id 4540F5A76 for ; Tue, 27 Oct 2015 08:32:55 +0100 (CET) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga103.fm.intel.com with ESMTP; 27 Oct 2015 00:32:54 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,203,1444719600"; d="scan'208";a="835889151" Received: from yliu-dev.sh.intel.com (HELO yliu-dev) ([10.239.66.49]) by orsmga002.jf.intel.com with ESMTP; 27 Oct 2015 00:32:52 -0700 Date: Tue, 27 Oct 2015 15:34:10 +0800 From: Yuanhan Liu To: Tetsuya Mukawa Message-ID: <20151027073410.GE3115@yliu-dev.sh.intel.com> References: <1445507150-1481-2-git-send-email-mukawa@igel.co.jp> <1445926375-18986-1-git-send-email-mukawa@igel.co.jp> <1445926375-18986-2-git-send-email-mukawa@igel.co.jp> <20151027064720.GD3115@yliu-dev.sh.intel.com> <562F27BA.5060501@igel.co.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <562F27BA.5060501@igel.co.jp> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: dev@dpdk.org, ann.zhuangyanying@huawei.com Subject: Re: [dpdk-dev] [PATCH 1/3] vhost: Fix wrong handling of virtqueue array index X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Oct 2015 07:32:56 -0000 On Tue, Oct 27, 2015 at 04:28:58PM +0900, Tetsuya Mukawa wrote: > Hi Yuanhan, > > I appreciate your checking. Welcome! And thank you for catching out my faults. --yliu > I haven't noticed SET_BACKEND is only supported by vhost-cuse. :-( > I will follow your comments, then submit again. > > Thanks, > Tetsuya > > On 2015/10/27 15:47, 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. > >> 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. > > Note that only vhost-user supports MQ. vhost-cuse does not. > > > >> Signed-off-by: Tetsuya Mukawa > >> --- > >> 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; > > So, fixing what my 1st reply said, for Nth queue pair, state->index > > is "N * 2 + is_tx". So, the base should be "state->index / 2 * 2". > > > >> > >> 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); > > This is a proper fix then. (You just need fix base_idx). > > > >> 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; > > user_set_vring_enable is sent per queue pair (I'm sure this time), so > > base_idx equals to state->index. No need fix here. > > > >> 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; > > As stated, vhost-cuse doesn't not support MQ. > > > > --yliu > >> > >> 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