From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 3F9208DAA for ; Wed, 12 Aug 2015 10:03:23 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP; 12 Aug 2015 01:03:23 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,659,1432623600"; d="scan'208";a="623933677" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga003.jf.intel.com with ESMTP; 12 Aug 2015 01:03:18 -0700 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shvmail01.sh.intel.com with ESMTP id t7C838qh027080; Wed, 12 Aug 2015 16:03:08 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id t7C835mU003661; Wed, 12 Aug 2015 16:03:08 +0800 Received: (from couyang@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id t7C835kN003657; Wed, 12 Aug 2015 16:03:05 +0800 From: Ouyang Changchun To: dev@dpdk.org Date: Wed, 12 Aug 2015 16:02:40 +0800 Message-Id: <1439366567-3402-6-git-send-email-changchun.ouyang@intel.com> X-Mailer: git-send-email 1.7.12.2 In-Reply-To: <1439366567-3402-1-git-send-email-changchun.ouyang@intel.com> References: <1434355006-30583-1-git-send-email-changchun.ouyang@intel.com> <1439366567-3402-1-git-send-email-changchun.ouyang@intel.com> Subject: [dpdk-dev] [PATCH v4 05/12] vhost: check the virtqueue address's validity 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: Wed, 12 Aug 2015 08:03:23 -0000 This is added since v3. Check the virtqueue address's validity. Signed-off-by: Changchun Ouyang --- Changes in v4: - remove unnecessary code lib/librte_vhost/vhost_user/vhost-net-user.c | 4 +++- lib/librte_vhost/virtio-net.c | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/librte_vhost/vhost_user/vhost-net-user.c b/lib/librte_vhost/vhost_user/vhost-net-user.c index 3d7c373..e926ed7 100644 --- a/lib/librte_vhost/vhost_user/vhost-net-user.c +++ b/lib/librte_vhost/vhost_user/vhost-net-user.c @@ -403,7 +403,9 @@ vserver_message_handler(int connfd, void *dat, int *remove) ops->set_vring_num(ctx, &msg.payload.state); break; case VHOST_USER_SET_VRING_ADDR: - ops->set_vring_addr(ctx, &msg.payload.addr); + if (ops->set_vring_addr(ctx, &msg.payload.addr) != 0) + RTE_LOG(INFO, VHOST_CONFIG, + "vring address incorrect.\n"); break; case VHOST_USER_SET_VRING_BASE: ops->set_vring_base(ctx, &msg.payload.state); diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index fd66a06..8901aa5 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -643,6 +643,7 @@ set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) { struct virtio_net *dev; struct vhost_virtqueue *vq; + uint32_t i; dev = get_device(ctx); if (dev == NULL) @@ -673,6 +674,15 @@ set_vring_addr(struct vhost_device_ctx ctx, struct vhost_vring_addr *addr) return -1; } + for (i = vq->last_used_idx; i < vq->avail->idx; i++) + if (vq->avail->ring[i] >= vq->size) { + RTE_LOG(ERR, VHOST_CONFIG, "%s (%"PRIu64"):" + "Please check virt queue pair idx:%d is " + "enalbed correctly on guest.\n", __func__, + dev->device_fh, addr->index / VIRTIO_QNUM); + return -1; + } + vq->used = (struct vring_used *)(uintptr_t)qva_to_vva(dev, addr->index / VIRTIO_QNUM, addr->used_user_addr); if (vq->used == 0) { -- 1.8.4.2