{"id":817376,"url":"http://patchwork.ozlabs.org/api/patches/817376/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/patch/1506067355-5771-2-git-send-email-jasowang@redhat.com/","project":{"id":7,"url":"http://patchwork.ozlabs.org/api/projects/7/?format=json","name":"Linux network development","link_name":"netdev","list_id":"netdev.vger.kernel.org","list_email":"netdev@vger.kernel.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1506067355-5771-2-git-send-email-jasowang@redhat.com>","list_archive_url":null,"date":"2017-09-22T08:02:31","name":"[net-next,RFC,1/5] vhost: split out ring head fetching logic","commit_ref":null,"pull_url":null,"state":"rfc","archived":true,"hash":"34a7f42b9f594c227d7cf17c1ddb8a3777a74a92","submitter":{"id":5225,"url":"http://patchwork.ozlabs.org/api/people/5225/?format=json","name":"Jason Wang","email":"jasowang@redhat.com"},"delegate":{"id":34,"url":"http://patchwork.ozlabs.org/api/users/34/?format=json","username":"davem","first_name":"David","last_name":"Miller","email":"davem@davemloft.net"},"mbox":"http://patchwork.ozlabs.org/project/netdev/patch/1506067355-5771-2-git-send-email-jasowang@redhat.com/mbox/","series":[{"id":4565,"url":"http://patchwork.ozlabs.org/api/series/4565/?format=json","web_url":"http://patchwork.ozlabs.org/project/netdev/list/?series=4565","date":"2017-09-22T08:02:35","name":"batched tx processing in vhost_net","version":1,"mbox":"http://patchwork.ozlabs.org/series/4565/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/817376/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/817376/checks/","tags":{},"related":[],"headers":{"Return-Path":"<netdev-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=netdev-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","ext-mx10.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx10.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=jasowang@redhat.com"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xz5bs0XBcz9s7C\n\tfor <patchwork-incoming@ozlabs.org>;\n\tFri, 22 Sep 2017 18:04:25 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751979AbdIVICv (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tFri, 22 Sep 2017 04:02:51 -0400","from mx1.redhat.com ([209.132.183.28]:36254 \"EHLO mx1.redhat.com\"\n\trhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP\n\tid S1751704AbdIVICr (ORCPT <rfc822;netdev@vger.kernel.org>);\n\tFri, 22 Sep 2017 04:02:47 -0400","from smtp.corp.redhat.com\n\t(int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 48ACD25B9A;\n\tFri, 22 Sep 2017 08:02:47 +0000 (UTC)","from jason-ThinkPad-T450s.redhat.com (ovpn-12-19.pek2.redhat.com\n\t[10.72.12.19])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id C615763621;\n\tFri, 22 Sep 2017 08:02:44 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 48ACD25B9A","From":"Jason Wang <jasowang@redhat.com>","To":"mst@redhat.com, jasowang@redhat.com,\n\tvirtualization@lists.linux-foundation.org, netdev@vger.kernel.org,\n\tlinux-kernel@vger.kernel.org","Cc":"kvm@vger.kernel.org","Subject":"[PATCH net-next RFC 1/5] vhost: split out ring head fetching logic","Date":"Fri, 22 Sep 2017 16:02:31 +0800","Message-Id":"<1506067355-5771-2-git-send-email-jasowang@redhat.com>","In-Reply-To":"<1506067355-5771-1-git-send-email-jasowang@redhat.com>","References":"<1506067355-5771-1-git-send-email-jasowang@redhat.com>","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.15","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.39]);\n\tFri, 22 Sep 2017 08:02:47 +0000 (UTC)","Sender":"netdev-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<netdev.vger.kernel.org>","X-Mailing-List":"netdev@vger.kernel.org"},"content":"This patch splits out ring head fetching logic and leave the\ndescriptor fetching and translation logic. This makes it is possible\nto batch fetching the descriptor indices.\n\nSigned-off-by: Jason Wang <jasowang@redhat.com>\n---\n drivers/vhost/vhost.c | 75 +++++++++++++++++++++++++++++++++------------------\n drivers/vhost/vhost.h |  5 ++++\n 2 files changed, 54 insertions(+), 26 deletions(-)","diff":"diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c\nindex d6dbb28..f87ec75 100644\n--- a/drivers/vhost/vhost.c\n+++ b/drivers/vhost/vhost.c\n@@ -1984,41 +1984,23 @@ static int get_indirect(struct vhost_virtqueue *vq,\n \treturn 0;\n }\n \n-/* This looks in the virtqueue and for the first available buffer, and converts\n- * it to an iovec for convenient access.  Since descriptors consist of some\n- * number of output then some number of input descriptors, it's actually two\n- * iovecs, but we pack them into one and note how many of each there were.\n- *\n- * This function returns the descriptor number found, or vq->num (which is\n- * never a valid descriptor number) if none was found.  A negative code is\n- * returned on error. */\n-int vhost_get_vq_desc(struct vhost_virtqueue *vq,\n-\t\t      struct iovec iov[], unsigned int iov_size,\n-\t\t      unsigned int *out_num, unsigned int *in_num,\n-\t\t      struct vhost_log *log, unsigned int *log_num)\n+static unsigned int vhost_get_vq_head(struct vhost_virtqueue *vq, int *err)\n {\n-\tstruct vring_desc desc;\n-\tunsigned int i, head, found = 0;\n-\tu16 last_avail_idx;\n-\t__virtio16 avail_idx;\n-\t__virtio16 ring_head;\n-\tint ret, access;\n-\n-\t/* Check it isn't doing very strange things with descriptor numbers. */\n-\tlast_avail_idx = vq->last_avail_idx;\n+\tu16 last_avail_idx = vq->last_avail_idx;\n+\t__virtio16 avail_idx, ring_head;\n \n \tif (vq->avail_idx == vq->last_avail_idx) {\n \t\tif (unlikely(vhost_get_avail(vq, avail_idx, &vq->avail->idx))) {\n \t\t\tvq_err(vq, \"Failed to access avail idx at %p\\n\",\n \t\t\t\t&vq->avail->idx);\n-\t\t\treturn -EFAULT;\n+\t\t\tgoto err;\n \t\t}\n \t\tvq->avail_idx = vhost16_to_cpu(vq, avail_idx);\n \n \t\tif (unlikely((u16)(vq->avail_idx - last_avail_idx) > vq->num)) {\n \t\t\tvq_err(vq, \"Guest moved used index from %u to %u\",\n \t\t\t\tlast_avail_idx, vq->avail_idx);\n-\t\t\treturn -EFAULT;\n+\t\t\tgoto err;\n \t\t}\n \n \t\t/* If there's nothing new since last we looked, return\n@@ -2040,13 +2022,35 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,\n \t\tvq_err(vq, \"Failed to read head: idx %d address %p\\n\",\n \t\t       last_avail_idx,\n \t\t       &vq->avail->ring[last_avail_idx % vq->num]);\n-\t\treturn -EFAULT;\n+\t\tgoto err;\n \t}\n \n-\thead = vhost16_to_cpu(vq, ring_head);\n+\treturn vhost16_to_cpu(vq, ring_head);\n+err:\n+\t*err = -EFAULT;\n+\treturn 0;\n+}\n+\n+/* This looks in the virtqueue and for the first available buffer, and converts\n+ * it to an iovec for convenient access.  Since descriptors consist of some\n+ * number of output then some number of input descriptors, it's actually two\n+ * iovecs, but we pack them into one and note how many of each there were.\n+ *\n+ * This function returns the descriptor number found, or vq->num (which is\n+ * never a valid descriptor number) if none was found.  A negative code is\n+ * returned on error. */\n+int __vhost_get_vq_desc(struct vhost_virtqueue *vq,\n+\t\t\tstruct iovec iov[], unsigned int iov_size,\n+\t\t\tunsigned int *out_num, unsigned int *in_num,\n+\t\t\tstruct vhost_log *log, unsigned int *log_num,\n+\t\t\t__virtio16 head)\n+{\n+\tstruct vring_desc desc;\n+\tunsigned int i, found = 0;\n+\tint ret = 0, access;\n \n \t/* If their number is silly, that's an error. */\n-\tif (unlikely(head >= vq->num)) {\n+\tif (unlikely(head > vq->num)) {\n \t\tvq_err(vq, \"Guest says index %u > %u is available\",\n \t\t       head, vq->num);\n \t\treturn -EINVAL;\n@@ -2133,6 +2137,25 @@ int vhost_get_vq_desc(struct vhost_virtqueue *vq,\n \tBUG_ON(!(vq->used_flags & VRING_USED_F_NO_NOTIFY));\n \treturn head;\n }\n+EXPORT_SYMBOL_GPL(__vhost_get_vq_desc);\n+\n+int vhost_get_vq_desc(struct vhost_virtqueue *vq,\n+\t\t      struct iovec iov[], unsigned int iov_size,\n+\t\t      unsigned int *out_num, unsigned int *in_num,\n+\t\t      struct vhost_log *log, unsigned int *log_num)\n+{\n+\tint ret = 0;\n+\tunsigned int head = vhost_get_vq_head(vq, &ret);\n+\n+\tif (ret)\n+\t\treturn ret;\n+\n+\tif (head == vq->num)\n+\t\treturn head;\n+\n+\treturn __vhost_get_vq_desc(vq, iov, iov_size, out_num, in_num,\n+\t\t\t\t   log, log_num, head);\n+}\n EXPORT_SYMBOL_GPL(vhost_get_vq_desc);\n \n /* Reverse the effect of vhost_get_vq_desc. Useful for error handling. */\ndiff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h\nindex d59a9cc..39ff897 100644\n--- a/drivers/vhost/vhost.h\n+++ b/drivers/vhost/vhost.h\n@@ -191,6 +191,11 @@ int vhost_get_vq_desc(struct vhost_virtqueue *,\n \t\t      struct iovec iov[], unsigned int iov_count,\n \t\t      unsigned int *out_num, unsigned int *in_num,\n \t\t      struct vhost_log *log, unsigned int *log_num);\n+int __vhost_get_vq_desc(struct vhost_virtqueue *vq,\n+\t\t\tstruct iovec iov[], unsigned int iov_count,\n+\t\t\tunsigned int *out_num, unsigned int *in_num,\n+\t\t\tstruct vhost_log *log, unsigned int *log_num,\n+\t\t\t__virtio16 ring_head);\n void vhost_discard_vq_desc(struct vhost_virtqueue *, int n);\n \n int vhost_vq_init_access(struct vhost_virtqueue *);\n","prefixes":["net-next","RFC","1/5"]}