From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f43.google.com (mail-pa0-f43.google.com [209.85.220.43]) by dpdk.org (Postfix) with ESMTP id EA55C11A2 for ; Thu, 19 Nov 2015 10:07:27 +0100 (CET) Received: by pacdm15 with SMTP id dm15so75150347pac.3 for ; Thu, 19 Nov 2015 01:07:27 -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=AFMWDVos5gXY9sOSDPbuVUBT80sXGjMJEbZeBJmMkDw=; b=bU+gnkvfOCw/t0LLISHDVyOzCMSsGCnHHvCAl2PEYaST1prxu15WDNP0q8nj993Rmn 2QrJ+W0tR+ZJwR/TAeOsFF0D3E5bSjItfAyDJgvm8xaeK4B/TiNo2ClqiaaBhPbHG3co Z0gbjZ8SK4McQQ1lASWVroJ743MGDlNx/e9yRXINKRJ4OkiasHUCpkyrw2zXrnKIgLVQ QAQaBq7Os+zQRIVpXqDwZFeAy6CIOVZ2q0GEQ7rWC5SqAKpnRtc/pAqhVsstnX+ZSIAy t6SMrjegyQZI1I479hAqiPf4UpIgKjxpdIPSPq5UPLTraccyI9lKB8/5UAiFicWBgiiu aT9g== 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=AFMWDVos5gXY9sOSDPbuVUBT80sXGjMJEbZeBJmMkDw=; b=AY79PmJbE+kf3wiuSAUbqkyARWWTssyLZi2xRdPwBqPrBt7QSEOkecIO9JKzXv8Pt3 +7yCmrdWrVqrDcWeQ4NM+CCc5iNfSOgphSjNqUonhtg24XPFWurQsP8Jc6hNqkmANcFm 2htjnbvUvLEu2Fn5cMHKNFKI0Jlv9KFxKm6WXPRRLz4NVb8dY3ISngk8D17wj1BztOFz RzJRjPdLwzdFcN9v8hBDCRpQhb2W/0Cp9BtbQwcAMHN2zNWjiwKaQvAJucBOefXy1cEY FnD9omvjkB7sTGVfDAiojsDW0Rh+6wQ3/Pu4IXcGfsa7CBS5zOa1SeygF6xSt+phclpa oeEw== X-Gm-Message-State: ALoCoQnhJO3tyisHwFpSxOFuIiLhoVRQnLAXrdFPgkByN2//kN7HIlUpeA2596Aru4qyLxSqL/wE X-Received: by 10.68.175.193 with SMTP id cc1mr9076969pbc.16.1447924047295; Thu, 19 Nov 2015 01:07:27 -0800 (PST) Received: from eris.hq.igel.co.jp (napt.igel.co.jp. [219.106.231.132]) by smtp.gmail.com with ESMTPSA id rn7sm9234170pab.23.2015.11.19.01.07.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Nov 2015 01:07:26 -0800 (PST) From: Tetsuya Mukawa To: dev@dpdk.org, yuanhan.liu@linux.intel.com Date: Thu, 19 Nov 2015 18:07:00 +0900 Message-Id: <1447924020-26894-1-git-send-email-mukawa@igel.co.jp> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1447914206-18369-1-git-send-email-mukawa@igel.co.jp> References: <1447914206-18369-1-git-send-email-mukawa@igel.co.jp> Cc: ann.zhuangyanying@huawei.com Subject: [dpdk-dev] [PATCH v2] vhost: Fix reset_owner message handling not to clear 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: , X-List-Received-Date: Thu, 19 Nov 2015 09:07:28 -0000 The patch fixes reset_owner message handling not to clear callfd, because callfd will be valid while connection is establihed. Signed-off-by: Tetsuya Mukawa --- lib/librte_vhost/virtio-net.c | 44 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 38 insertions(+), 6 deletions(-) diff --git a/lib/librte_vhost/virtio-net.c b/lib/librte_vhost/virtio-net.c index 886c104..3907fb5 100644 --- a/lib/librte_vhost/virtio-net.c +++ b/lib/librte_vhost/virtio-net.c @@ -223,9 +223,9 @@ add_config_ll_entry(struct virtio_net_config_ll *new_ll_dev) } static void -cleanup_vq(struct vhost_virtqueue *vq) +cleanup_vq(struct vhost_virtqueue *vq, int destroy) { - if (vq->callfd >= 0) + if ((vq->callfd >= 0) && (destroy != 0)) close(vq->callfd); if (vq->kickfd >= 0) close(vq->kickfd); @@ -249,8 +249,8 @@ cleanup_device(struct virtio_net *dev) } for (i = 0; i < dev->virt_qp_nb; i++) { - cleanup_vq(dev->virtqueue[i * VIRTIO_QNUM + VIRTIO_RXQ]); - cleanup_vq(dev->virtqueue[i * VIRTIO_QNUM + VIRTIO_TXQ]); + cleanup_vq(dev->virtqueue[i * VIRTIO_QNUM + VIRTIO_RXQ], 1); + cleanup_vq(dev->virtqueue[i * VIRTIO_QNUM + VIRTIO_TXQ], 1); } } @@ -322,6 +322,25 @@ init_vring_queue_pair(struct virtio_net *dev, uint32_t qp_idx) init_vring_queue(dev->virtqueue[base_idx + VIRTIO_TXQ], qp_idx); } +static void +reset_vring_queue(struct vhost_virtqueue *vq, int qp_idx) +{ + int callfd; + + callfd = vq->callfd; + init_vring_queue(vq, qp_idx); + vq->callfd = callfd; +} + +static void +reset_vring_queue_pair(struct virtio_net *dev, uint32_t qp_idx) +{ + uint32_t base_idx = qp_idx * VIRTIO_QNUM; + + reset_vring_queue(dev->virtqueue[base_idx + VIRTIO_RXQ], qp_idx); + reset_vring_queue(dev->virtqueue[base_idx + VIRTIO_TXQ], qp_idx); +} + static int alloc_vring_queue_pair(struct virtio_net *dev, uint32_t qp_idx) { @@ -362,7 +381,7 @@ reset_device(struct virtio_net *dev) dev->flags = 0; for (i = 0; i < dev->virt_qp_nb; i++) - init_vring_queue_pair(dev, i); + reset_vring_queue_pair(dev, i); } /* @@ -467,6 +486,7 @@ static int reset_owner(struct vhost_device_ctx ctx) { struct virtio_net *dev; + uint32_t i; dev = get_device(ctx); if (dev == NULL) @@ -475,7 +495,19 @@ reset_owner(struct vhost_device_ctx ctx) if (dev->flags & VIRTIO_DEV_RUNNING) notify_destroy_device(dev); - cleanup_device(dev); + /* Unmap QEMU memory file if mapped. */ + if (dev->mem) { + munmap((void *)(uintptr_t)dev->mem->mapped_address, + (size_t)dev->mem->mapped_size); + free(dev->mem); + dev->mem = NULL; + } + + for (i = 0; i < dev->virt_qp_nb; i++) { + cleanup_vq(dev->virtqueue[i * VIRTIO_QNUM + VIRTIO_RXQ], 0); + cleanup_vq(dev->virtqueue[i * VIRTIO_QNUM + VIRTIO_TXQ], 0); + } + reset_device(dev); return 0; } -- 2.1.4