From patchwork Thu Mar 10 07:06:05 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuya Mukawa X-Patchwork-Id: 11381 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: 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 4412F2BA2; Thu, 10 Mar 2016 08:06:16 +0100 (CET) Received: from mail-pa0-f52.google.com (mail-pa0-f52.google.com [209.85.220.52]) by dpdk.org (Postfix) with ESMTP id 270962B9F for ; Thu, 10 Mar 2016 08:06:14 +0100 (CET) Received: by mail-pa0-f52.google.com with SMTP id td3so33576983pab.2 for ; Wed, 09 Mar 2016 23:06:14 -0800 (PST) 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=M+LS7h4RmWkk8hUVU7y1Sc503NCNdlGh+5cRqypYPak=; b=WcQQytiVzmVn9ba3NNb33ESwL88tJSXNzdSuaLJhuBAxTwNf+bc3YOvLIT6vSgm3F5 kM9+01SwvszRGl/yiU2hFW/Rg7v89Je85KEtXtOcwhaHp7YJcR12W7Qranq3/ZqG131k RHIcdOlrYbqn/s1I80nw7BxZv6TuPogcQeyyWYEBV3CkMaTD374c676d2WZ1tf9Y45xT nOTz9tCF3/PsoVIEsQuALpIFOYm0SECac40bKmxhMZJ/nergtOBpYIIsCzLjOe4N6CLh 5r3Bjkf2J5jyw1u0HeRf5dPmyDYeFHRR/xKLuo8Ec++Tx1lsOUN35DrzFJz7bZ9NFYKh a6KA== 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=M+LS7h4RmWkk8hUVU7y1Sc503NCNdlGh+5cRqypYPak=; b=TUcDmae3I4luoCvveKNJ6N7tisaoWdrbboCCIeiMyy7XFEW5JItM/aSmiCZfbhrsu1 R27X6xSnce7+6HiBdIu4ATb0uYomvoR3/NH5spqBA8f1gUmRdphII3+yr8YUt/G0KlbR RSjU9TCHGVC+ei/80PTFDhqqUMpkUfQV3DhIclxpILGtxcAlhx14Pz0qV7oTdCgSQDEA vg07WEr/grD4QRkZK4yxUxGWmlccZqCVln/LcDfEBzylvkUOKzPATmjWPVpwMAgr2WwV COrGI7jVP7ZV2WRppu6PChNk4bYOpL0sIDlTOoRceCQwtoAf0MRqtZArlJi3zPcSXSoM A5vw== X-Gm-Message-State: AD7BkJJeslgTI8yfuNbhUeoXNXWTIX4pOQmxuuiseDFdUuSWwdzITGQVVVK0VmcX4m6+SA== X-Received: by 10.66.141.76 with SMTP id rm12mr2856562pab.30.1457593573443; Wed, 09 Mar 2016 23:06:13 -0800 (PST) Received: from localhost.localdomain (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id tp9sm2853466pab.14.2016.03.09.23.06.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 09 Mar 2016 23:06:12 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org, jianfeng.tan@intel.com Date: Thu, 10 Mar 2016 16:06:05 +0900 Message-Id: <1457593565-16240-1-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1457590462-3680-1-git-send-email-mukawa@igel.co.jp> References: <1457590462-3680-1-git-send-email-mukawa@igel.co.jp> Subject: [dpdk-dev] [PATCH v2] vhost: Fix default value of kickfd and callfd 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Currently, default values of kickfd and callfd are -1. If the values are -1, current code guesses kickfd and callfd haven't been initialized yet. And vhost library will guess the virtqueue isn't ready for processing. But callfd and kickfd will be set as -1 when "--enable-kvm" isn't specified in QEMU command line. It means we cannot treat -1 as uninitialized state. The patch changes default values to -2. And the patch defines -2 as VIRTIO_UNINITIALIZED_EVENTFD. Signed-off-by: Tetsuya Mukawa --- lib/librte_vhost/rte_virtio_net.h | 1 + lib/librte_vhost/vhost_user/virtio-net-user.c | 10 +++++----- lib/librte_vhost/virtio-net.c | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/librte_vhost/rte_virtio_net.h b/lib/librte_vhost/rte_virtio_net.h index 7d1fde2..d745707 100644 --- a/lib/librte_vhost/rte_virtio_net.h +++ b/lib/librte_vhost/rte_virtio_net.h @@ -89,6 +89,7 @@ struct vhost_virtqueue { uint16_t vhost_hlen; /**< Vhost header length (varies depending on RX merge buffers. */ volatile uint16_t last_used_idx; /**< Last index used on the available ring */ volatile uint16_t last_used_idx_res; /**< Used for multiple devices reserving buffers. */ +#define VIRTIO_UNINITIALIZED_EVENTFD (-2) int callfd; /**< Used to notify the guest (trigger interrupt). */ int kickfd; /**< Currently unused as polling mode is enabled. */ int enabled; diff --git a/lib/librte_vhost/vhost_user/virtio-net-user.c b/lib/librte_vhost/vhost_user/virtio-net-user.c index 65b5652..4c156a6 100644 --- a/lib/librte_vhost/vhost_user/virtio-net-user.c +++ b/lib/librte_vhost/vhost_user/virtio-net-user.c @@ -225,8 +225,8 @@ static int vq_is_ready(struct vhost_virtqueue *vq) { return vq && vq->desc && - vq->kickfd != -1 && - vq->callfd != -1; + vq->kickfd != VIRTIO_UNINITIALIZED_EVENTFD && + vq->callfd != VIRTIO_UNINITIALIZED_EVENTFD; } static int @@ -316,10 +316,10 @@ 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]->kickfd >= 0) { + if (dev->virtqueue[state->index]->kickfd >= 0) close(dev->virtqueue[state->index]->kickfd); - dev->virtqueue[state->index]->kickfd = -1; - } + + dev->virtqueue[state->index]->kickfd = VIRTIO_UNINITIALIZED_EVENTFD; return 0; } diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index fe1a77e..3498e9d 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -263,8 +263,8 @@ init_vring_queue(struct vhost_virtqueue *vq, int qp_idx) { memset(vq, 0, sizeof(struct vhost_virtqueue)); - vq->kickfd = -1; - vq->callfd = -1; + vq->kickfd = VIRTIO_UNINITIALIZED_EVENTFD; + vq->callfd = VIRTIO_UNINITIALIZED_EVENTFD; /* Backends are set to -1 indicating an inactive device. */ vq->backend = -1;