Message ID | 1445926375-18986-2-git-send-email-mukawa@igel.co.jp (mailing list archive) |
---|---|
State | Changes Requested, archived |
Headers |
Return-Path: <dev-bounces@dpdk.org> X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 255278DA4; Tue, 27 Oct 2015 07:13:15 +0100 (CET) Received: from mail-pa0-f44.google.com (mail-pa0-f44.google.com [209.85.220.44]) by dpdk.org (Postfix) with ESMTP id 021628DA1 for <dev@dpdk.org>; Tue, 27 Oct 2015 07:13:12 +0100 (CET) Received: by padhk11 with SMTP id hk11so212324725pad.1 for <dev@dpdk.org>; Mon, 26 Oct 2015 23:13:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=igel_co_jp.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NuX5WkSHL1yeU9u1H+b2UipVZQFhnBdpDR5FSClnBAc=; b=x1RoOp30IMCyifEOSWo3ZOxDa3qx7u2MAjA08dOr/5o/Q860nWSqZb6Z7TyOvuMOcz ynY7pNtcv40pGI5utMfreU0bfr6fX3x1Xzsa5uS8LkttjS5ZR6WRKTMg2LLpSwca4wCQ gTY+5yqIuDj5bb5P9LkB2bkkU03kyNMdc7/ID5b3yWJUg0deVEKNrKUQ12I7O9y1GaZP 1pqKd6IMRJl+MhotnrlshE5yA+HdtjMt0QFZ51uDzLWswm3Pz4LrStuCX1B2jlI2hfJt tz+URASEguKoVbzFXYJ7i47AEtR9dE3L4vK7OVu61BTLDUJhl1R0Kt3wfMk+HdEUNbjl bQjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NuX5WkSHL1yeU9u1H+b2UipVZQFhnBdpDR5FSClnBAc=; b=DriVQec5z/iUqZipWrX93Z2y+/GNNpJnH1zaVdTuADFMC1EZc3l873QTyHYIin5RwU Npb2zr4Oi8SO8EOv9azc8fYPEUuSmlV7PstPGkTlEm3Q4q0A79s7ikO9knJjz6qIaFF3 jKJpoayXCTC1mct9UliX0bIUX8/PBzM4PsAAIUDOxx+rJYC/F1My2T3Cts9yRhKrgb56 XDyv+/1x+QsGjiFrpG2dGEUWzAHqSuiM5E2rA1704oviXPjuoaI7h1LICEp6zyC6YfKP eFTzsmBZEiHie8xdjpwJuzmjbM1QIThloocqGhW2uVnnwn1ezyGYW6aNnsVseM8+jPvY GBaQ== X-Gm-Message-State: ALoCoQkfDg7+LCrXjTnx1VotkoFiFWzG8cK0FZCZo2lOIFBOzA5sAbeTLNL6r5Gw2GoanieojHBf X-Received: by 10.66.250.202 with SMTP id ze10mr1924125pac.132.1445926392280; Mon, 26 Oct 2015 23:13:12 -0700 (PDT) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id cn4sm37312954pbc.94.2015.10.26.23.13.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 26 Oct 2015 23:13:11 -0700 (PDT) From: Tetsuya Mukawa <mukawa@igel.co.jp> To: dev@dpdk.org Date: Tue, 27 Oct 2015 15:12:53 +0900 Message-Id: <1445926375-18986-2-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1445926375-18986-1-git-send-email-mukawa@igel.co.jp> References: <1445507150-1481-2-git-send-email-mukawa@igel.co.jp> <1445926375-18986-1-git-send-email-mukawa@igel.co.jp> Cc: ann.zhuangyanying@huawei.com Subject: [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 <dev.dpdk.org> List-Unsubscribe: <http://dpdk.org/ml/options/dev>, <mailto:dev-request@dpdk.org?subject=unsubscribe> List-Archive: <http://dpdk.org/ml/archives/dev/> List-Post: <mailto:dev@dpdk.org> List-Help: <mailto:dev-request@dpdk.org?subject=help> List-Subscribe: <http://dpdk.org/ml/listinfo/dev>, <mailto:dev-request@dpdk.org?subject=subscribe> Errors-To: dev-bounces@dpdk.org Sender: "dev" <dev-bounces@dpdk.org> |
Commit Message
Tetsuya Mukawa
Oct. 27, 2015, 6:12 a.m. UTC
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.
Signed-off-by: Tetsuya Mukawa <mukawa@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(-)
Comments
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. > 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@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
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@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
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 <mukawa@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; 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
Hi Yuanhan, I appreciate your checking. 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 <mukawa@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; > 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
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 <mukawa@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; > > 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
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; 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. */