* [PATCH] vhost: remove a hack on queue allocation @ 2017-03-02 5:59 Yuanhan Liu 2017-03-02 6:16 ` Yuanhan Liu 0 siblings, 1 reply; 6+ messages in thread From: Yuanhan Liu @ 2017-03-02 5:59 UTC (permalink / raw) To: dev; +Cc: Maxime Coquelin, Yuanhan Liu We used to allocate queues based on the index from SET_VRING_CALL request: if corresponding queue hasn't been allocated, allocate it. Though it's pratically right (it's the first per-vring request we will get from QEMU for vhost-user negotiation), but it's not technically right: it's not documented in the vhost-user spec that it will always be the first per-vring request. For example, SET_VRING_ADDR could also be the first per-vring request. Thus, we should not depend the SET_VRING_CALL on queue allocation. Instead, we could catch all the per-vring messages at the entrance of request handler, and allocate one if it hasn't been allocated before. By that, we could remove a hack. Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com> --- lib/librte_vhost/vhost_user.c | 58 +++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index cb2156a..8135fef 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -635,7 +635,6 @@ { struct vhost_vring_file file; struct vhost_virtqueue *vq; - uint32_t cur_qp_idx; file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK) @@ -645,19 +644,7 @@ RTE_LOG(INFO, VHOST_CONFIG, "vring call idx:%d file:%d\n", file.index, file.fd); - /* - * FIXME: VHOST_SET_VRING_CALL is the first per-vring message - * we get, so we do vring queue pair allocation here. - */ - cur_qp_idx = file.index / VIRTIO_QNUM; - if (cur_qp_idx + 1 > dev->virt_qp_nb) { - if (alloc_vring_queue_pair(dev, cur_qp_idx) < 0) - return; - } - vq = dev->virtqueue[file.index]; - assert(vq != NULL); - if (vq->callfd >= 0) close(vq->callfd); @@ -914,6 +901,43 @@ return ret; } +/* + * Allocate a queue pair if it hasn't been allocated yet + */ +static int +vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev, VhostUserMsg *msg) +{ + uint16_t vring_idx; + uint16_t qp_idx; + + switch (msg->request) { + case VHOST_USER_SET_VRING_KICK: + case VHOST_USER_SET_VRING_CALL: + case VHOST_USER_SET_VRING_ERR: + vring_idx = msg->payload.u64 & VHOST_USER_VRING_IDX_MASK; + case VHOST_USER_SET_VRING_NUM: + case VHOST_USER_SET_VRING_BASE: + case VHOST_USER_SET_VRING_ENABLE: + vring_idx = msg->payload.state.index; + case VHOST_USER_SET_VRING_ADDR: + vring_idx = msg->payload.addr.index; + default: + return 0; + } + + qp_idx = vring_idx / VIRTIO_QNUM; + if (qp_idx >= VHOST_MAX_QUEUE_PAIRS) { + RTE_LOG(ERR, VHOST_CONFIG, + "invalid vring index: %u\n", vring_idx); + return -1; + } + + if (dev->virtqueue[qp_idx]) + return 0; + + return alloc_vring_queue_pair(dev, qp_idx); +} + int vhost_user_msg_handler(int vid, int fd) { @@ -943,6 +967,14 @@ ret = 0; RTE_LOG(INFO, VHOST_CONFIG, "read message %s\n", vhost_message_str[msg.request]); + + ret = vhost_user_check_and_alloc_queue_pair(dev, &msg); + if (ret < 0) { + RTE_LOG(ERR, VHOST_CONFIG, + "failed to alloc queue\n"); + return -1; + } + switch (msg.request) { case VHOST_USER_GET_FEATURES: msg.payload.u64 = vhost_user_get_features(); -- 1.9.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH] vhost: remove a hack on queue allocation 2017-03-02 5:59 [PATCH] vhost: remove a hack on queue allocation Yuanhan Liu @ 2017-03-02 6:16 ` Yuanhan Liu 2017-03-22 8:41 ` Maxime Coquelin 0 siblings, 1 reply; 6+ messages in thread From: Yuanhan Liu @ 2017-03-02 6:16 UTC (permalink / raw) To: dev; +Cc: Maxime Coquelin, Yuanhan Liu We used to allocate queues based on the index from SET_VRING_CALL request: if corresponding queue hasn't been allocated, allocate it. Though it's pratically right (it's the first per-vring request we will get from QEMU for vhost-user negotiation), but it's not technically right: it's not documented in the vhost-user spec that it will always be the first per-vring request. For example, SET_VRING_ADDR could also be the first per-vring request. Thus, we should not depend the SET_VRING_CALL on queue allocation. Instead, we could catch all the per-vring messages at the entrance of request handler, and allocate one if it hasn't been allocated before. By that, we could remove a hack. Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com> --- v2: add missing break --- lib/librte_vhost/vhost_user.c | 61 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index cb2156a..8433a54 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -635,7 +635,6 @@ vhost_user_set_vring_call(struct virtio_net *dev, struct VhostUserMsg *pmsg) { struct vhost_vring_file file; struct vhost_virtqueue *vq; - uint32_t cur_qp_idx; file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK) @@ -645,19 +644,7 @@ vhost_user_set_vring_call(struct virtio_net *dev, struct VhostUserMsg *pmsg) RTE_LOG(INFO, VHOST_CONFIG, "vring call idx:%d file:%d\n", file.index, file.fd); - /* - * FIXME: VHOST_SET_VRING_CALL is the first per-vring message - * we get, so we do vring queue pair allocation here. - */ - cur_qp_idx = file.index / VIRTIO_QNUM; - if (cur_qp_idx + 1 > dev->virt_qp_nb) { - if (alloc_vring_queue_pair(dev, cur_qp_idx) < 0) - return; - } - vq = dev->virtqueue[file.index]; - assert(vq != NULL); - if (vq->callfd >= 0) close(vq->callfd); @@ -914,6 +901,46 @@ send_vhost_message(int sockfd, struct VhostUserMsg *msg) return ret; } +/* + * Allocate a queue pair if it hasn't been allocated yet + */ +static int +vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev, VhostUserMsg *msg) +{ + uint16_t vring_idx; + uint16_t qp_idx; + + switch (msg->request) { + case VHOST_USER_SET_VRING_KICK: + case VHOST_USER_SET_VRING_CALL: + case VHOST_USER_SET_VRING_ERR: + vring_idx = msg->payload.u64 & VHOST_USER_VRING_IDX_MASK; + break; + case VHOST_USER_SET_VRING_NUM: + case VHOST_USER_SET_VRING_BASE: + case VHOST_USER_SET_VRING_ENABLE: + vring_idx = msg->payload.state.index; + break; + case VHOST_USER_SET_VRING_ADDR: + vring_idx = msg->payload.addr.index; + break; + default: + return 0; + } + + qp_idx = vring_idx / VIRTIO_QNUM; + if (qp_idx >= VHOST_MAX_QUEUE_PAIRS) { + RTE_LOG(ERR, VHOST_CONFIG, + "invalid vring index: %u\n", vring_idx); + return -1; + } + + if (dev->virtqueue[qp_idx]) + return 0; + + return alloc_vring_queue_pair(dev, qp_idx); +} + int vhost_user_msg_handler(int vid, int fd) { @@ -943,6 +970,14 @@ vhost_user_msg_handler(int vid, int fd) ret = 0; RTE_LOG(INFO, VHOST_CONFIG, "read message %s\n", vhost_message_str[msg.request]); + + ret = vhost_user_check_and_alloc_queue_pair(dev, &msg); + if (ret < 0) { + RTE_LOG(ERR, VHOST_CONFIG, + "failed to alloc queue\n"); + return -1; + } + switch (msg.request) { case VHOST_USER_GET_FEATURES: msg.payload.u64 = vhost_user_get_features(); -- 2.8.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] vhost: remove a hack on queue allocation 2017-03-02 6:16 ` Yuanhan Liu @ 2017-03-22 8:41 ` Maxime Coquelin 2017-03-22 8:56 ` Yuanhan Liu 0 siblings, 1 reply; 6+ messages in thread From: Maxime Coquelin @ 2017-03-22 8:41 UTC (permalink / raw) To: Yuanhan Liu, dev On 03/02/2017 07:16 AM, Yuanhan Liu wrote: > We used to allocate queues based on the index from SET_VRING_CALL > request: if corresponding queue hasn't been allocated, allocate it. > > Though it's pratically right (it's the first per-vring request we > will get from QEMU for vhost-user negotiation), but it's not technically > right: it's not documented in the vhost-user spec that it will always > be the first per-vring request. For example, SET_VRING_ADDR could also > be the first per-vring request. > > Thus, we should not depend the SET_VRING_CALL on queue allocation. > Instead, we could catch all the per-vring messages at the entrance of > request handler, and allocate one if it hasn't been allocated before. > > By that, we could remove a hack. > > Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com> > --- > > v2: add missing break > --- > lib/librte_vhost/vhost_user.c | 61 ++++++++++++++++++++++++++++++++++--------- > 1 file changed, 48 insertions(+), 13 deletions(-) Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com> Thanks, Maxime ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] vhost: remove a hack on queue allocation 2017-03-22 8:41 ` Maxime Coquelin @ 2017-03-22 8:56 ` Yuanhan Liu 2017-04-01 8:32 ` Yuanhan Liu 0 siblings, 1 reply; 6+ messages in thread From: Yuanhan Liu @ 2017-03-22 8:56 UTC (permalink / raw) To: Maxime Coquelin; +Cc: dev On Wed, Mar 22, 2017 at 09:41:07AM +0100, Maxime Coquelin wrote: > > > On 03/02/2017 07:16 AM, Yuanhan Liu wrote: > >We used to allocate queues based on the index from SET_VRING_CALL > >request: if corresponding queue hasn't been allocated, allocate it. > > > >Though it's pratically right (it's the first per-vring request we > >will get from QEMU for vhost-user negotiation), but it's not technically > >right: it's not documented in the vhost-user spec that it will always > >be the first per-vring request. For example, SET_VRING_ADDR could also > >be the first per-vring request. > > > >Thus, we should not depend the SET_VRING_CALL on queue allocation. > >Instead, we could catch all the per-vring messages at the entrance of > >request handler, and allocate one if it hasn't been allocated before. > > > >By that, we could remove a hack. > > > >Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com> > >--- > > > >v2: add missing break > >--- > > lib/librte_vhost/vhost_user.c | 61 ++++++++++++++++++++++++++++++++++--------- > > 1 file changed, 48 insertions(+), 13 deletions(-) > > > Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com> Thanks. Applied to dpdk-next-virtio. --yliu ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] vhost: remove a hack on queue allocation 2017-03-22 8:56 ` Yuanhan Liu @ 2017-04-01 8:32 ` Yuanhan Liu 2017-04-01 8:35 ` Yuanhan Liu 0 siblings, 1 reply; 6+ messages in thread From: Yuanhan Liu @ 2017-04-01 8:32 UTC (permalink / raw) To: dev; +Cc: Maxime Coquelin, Yuanhan Liu On Wed, Mar 22, 2017 at 04:56:12PM +0800, Yuanhan Liu wrote: > On Wed, Mar 22, 2017 at 09:41:07AM +0100, Maxime Coquelin wrote: > > > > > > On 03/02/2017 07:16 AM, Yuanhan Liu wrote: > > >We used to allocate queues based on the index from SET_VRING_CALL > > >request: if corresponding queue hasn't been allocated, allocate it. > > > > > >Though it's pratically right (it's the first per-vring request we > > >will get from QEMU for vhost-user negotiation), but it's not technically > > >right: it's not documented in the vhost-user spec that it will always > > >be the first per-vring request. For example, SET_VRING_ADDR could also > > >be the first per-vring request. > > > > > >Thus, we should not depend the SET_VRING_CALL on queue allocation. > > >Instead, we could catch all the per-vring messages at the entrance of > > >request handler, and allocate one if it hasn't been allocated before. > > > > > >By that, we could remove a hack. > > > > > >Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com> > > >--- > > > > > >v2: add missing break > > >--- > > > lib/librte_vhost/vhost_user.c | 61 ++++++++++++++++++++++++++++++++++--------- > > > 1 file changed, 48 insertions(+), 13 deletions(-) > > > > > > Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com> > > Thanks. > > Applied to dpdk-next-virtio. Reworked, as there is a silly error that cause crash. --yliu -- >8 -- >From 269ba9b3a6a1671f463b9f9d4cc0d51954f7a2f5 Mon Sep 17 00:00:00 2001 From: Yuanhan Liu <yuanhan.liu@linux.intel.com> Date: Thu, 2 Mar 2017 14:16:07 +0800 Subject: [PATCH v3] vhost: remove a hack on queue allocation We used to allocate queues based on the index from SET_VRING_CALL request: if corresponding queue hasn't been allocated, allocate it. Though it's pratically right (it's the first per-vring request we will get from QEMU for vhost-user negotiation), but it's not technically right: it's not documented in the vhost-user spec that it will always be the first per-vring request. For example, SET_VRING_ADDR could also be the first per-vring request. Thus, we should not depend the SET_VRING_CALL on queue allocation. Instead, we could catch all the per-vring messages at the entrance of request handler, and allocate one if it hasn't been allocated before. By that, we could remove a hack. Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com> --- v3: fix the virtuqueue check that introduces crash in MQ --- lib/librte_vhost/vhost_user.c | 61 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index cb2156a..2767cca 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -635,7 +635,6 @@ { struct vhost_vring_file file; struct vhost_virtqueue *vq; - uint32_t cur_qp_idx; file.index = pmsg->payload.u64 & VHOST_USER_VRING_IDX_MASK; if (pmsg->payload.u64 & VHOST_USER_VRING_NOFD_MASK) @@ -645,19 +644,7 @@ RTE_LOG(INFO, VHOST_CONFIG, "vring call idx:%d file:%d\n", file.index, file.fd); - /* - * FIXME: VHOST_SET_VRING_CALL is the first per-vring message - * we get, so we do vring queue pair allocation here. - */ - cur_qp_idx = file.index / VIRTIO_QNUM; - if (cur_qp_idx + 1 > dev->virt_qp_nb) { - if (alloc_vring_queue_pair(dev, cur_qp_idx) < 0) - return; - } - vq = dev->virtqueue[file.index]; - assert(vq != NULL); - if (vq->callfd >= 0) close(vq->callfd); @@ -914,6 +901,46 @@ return ret; } +/* + * Allocate a queue pair if it hasn't been allocated yet + */ +static int +vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev, VhostUserMsg *msg) +{ + uint16_t vring_idx; + uint16_t qp_idx; + + switch (msg->request) { + case VHOST_USER_SET_VRING_KICK: + case VHOST_USER_SET_VRING_CALL: + case VHOST_USER_SET_VRING_ERR: + vring_idx = msg->payload.u64 & VHOST_USER_VRING_IDX_MASK; + break; + case VHOST_USER_SET_VRING_NUM: + case VHOST_USER_SET_VRING_BASE: + case VHOST_USER_SET_VRING_ENABLE: + vring_idx = msg->payload.state.index; + break; + case VHOST_USER_SET_VRING_ADDR: + vring_idx = msg->payload.addr.index; + break; + default: + return 0; + } + + qp_idx = vring_idx / VIRTIO_QNUM; + if (qp_idx >= VHOST_MAX_QUEUE_PAIRS) { + RTE_LOG(ERR, VHOST_CONFIG, + "invalid vring index: %u\n", vring_idx); + return -1; + } + + if (dev->virtqueue[qp_idx * VIRTIO_QNUM]) + return 0; + + return alloc_vring_queue_pair(dev, qp_idx); +} + int vhost_user_msg_handler(int vid, int fd) { @@ -943,6 +970,14 @@ ret = 0; RTE_LOG(INFO, VHOST_CONFIG, "read message %s\n", vhost_message_str[msg.request]); + + ret = vhost_user_check_and_alloc_queue_pair(dev, &msg); + if (ret < 0) { + RTE_LOG(ERR, VHOST_CONFIG, + "failed to alloc queue\n"); + return -1; + } + switch (msg.request) { case VHOST_USER_GET_FEATURES: msg.payload.u64 = vhost_user_get_features(); -- 1.9.0 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] vhost: remove a hack on queue allocation 2017-04-01 8:32 ` Yuanhan Liu @ 2017-04-01 8:35 ` Yuanhan Liu 0 siblings, 0 replies; 6+ messages in thread From: Yuanhan Liu @ 2017-04-01 8:35 UTC (permalink / raw) To: dev; +Cc: Maxime Coquelin On Sat, Apr 01, 2017 at 04:32:58PM +0800, Yuanhan Liu wrote: > On Wed, Mar 22, 2017 at 04:56:12PM +0800, Yuanhan Liu wrote: > > On Wed, Mar 22, 2017 at 09:41:07AM +0100, Maxime Coquelin wrote: > > > > > > > > > On 03/02/2017 07:16 AM, Yuanhan Liu wrote: > > > >We used to allocate queues based on the index from SET_VRING_CALL > > > >request: if corresponding queue hasn't been allocated, allocate it. > > > > > > > >Though it's pratically right (it's the first per-vring request we > > > >will get from QEMU for vhost-user negotiation), but it's not technically > > > >right: it's not documented in the vhost-user spec that it will always > > > >be the first per-vring request. For example, SET_VRING_ADDR could also > > > >be the first per-vring request. > > > > > > > >Thus, we should not depend the SET_VRING_CALL on queue allocation. > > > >Instead, we could catch all the per-vring messages at the entrance of > > > >request handler, and allocate one if it hasn't been allocated before. > > > > > > > >By that, we could remove a hack. > > > > > > > >Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com> > > > >--- > > > > > > > >v2: add missing break > > > >--- > > > > lib/librte_vhost/vhost_user.c | 61 ++++++++++++++++++++++++++++++++++--------- > > > > 1 file changed, 48 insertions(+), 13 deletions(-) > > > > > > > > > Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com> > > > > Thanks. > > > > Applied to dpdk-next-virtio. > > Reworked, as there is a silly error that cause crash. Re-applied. --yliu > -- >8 -- > >From 269ba9b3a6a1671f463b9f9d4cc0d51954f7a2f5 Mon Sep 17 00:00:00 2001 > From: Yuanhan Liu <yuanhan.liu@linux.intel.com> > Date: Thu, 2 Mar 2017 14:16:07 +0800 > Subject: [PATCH v3] vhost: remove a hack on queue allocation ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-04-01 8:37 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2017-03-02 5:59 [PATCH] vhost: remove a hack on queue allocation Yuanhan Liu 2017-03-02 6:16 ` Yuanhan Liu 2017-03-22 8:41 ` Maxime Coquelin 2017-03-22 8:56 ` Yuanhan Liu 2017-04-01 8:32 ` Yuanhan Liu 2017-04-01 8:35 ` Yuanhan Liu
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.