Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp891341ybb; Wed, 1 Apr 2020 11:32:36 -0700 (PDT) X-Google-Smtp-Source: APiQypKQP5JfN2F8jj3T+18Tuq9BWKnjGGCS3JAW7qlCrzhnu5Q1aiVpUH0BG3vb72hkDLShI+0N X-Received: by 2002:aca:4a08:: with SMTP id x8mr3961478oia.158.1585765956105; Wed, 01 Apr 2020 11:32:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585765956; cv=none; d=google.com; s=arc-20160816; b=dRmAW8t7C1rst2HYCiUtQYxzz7i5ufekG6AO8v/N6GfR0zjT4gjYHkuoLMh2ny+oKn RrttfNL6cZWZTUsSmQPygCE9LG3qlezLlWGyMwQSk4ZoKcp3ECTmJDb6dLfpY1N8AjF+ PwStSc2DSZ57VmW1O7/DSqFUD+C6tOaqSPcfTRaw3GwafskrJoBHO2IucxkvDchNOPFV Kg1EFjZcVLooNdViUulfz77w8c4gDvJ4Y/f4a57dS8JJRDWrxoGSqiu0BuMU9AOzi97Z mA9XA28UufBO2fEDJFzHPh4wtTJlEijyrmXdoO4qFeS7pdxoP5najwTasB8NJynDSU2F Xbmw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5cd/tAAKc92RQcsvHpnGKQyliE7tkeu/uRWIaIVI0J4=; b=DrS/65y/DjEIV8U2iXtbKt9to1IzW/HVV2OJrhMHYICbI5h/ekt+wkW/KvHImYKG1y 9RnC0zfnVPYhOtYN9y9quzb8WshnH+F4wWEppNE4HIGo03TAUOr1bRBKDbsKreBIzpFR uguKmH5NhQmdDHYRLybVtLi+FCuUKB3305hymY6PgODQ2Z+pWxHQbgvunMIPNqcVq0xi zsqT0n75KbgJ9xzlX4InYejDfmzFQeesz+hsv6ugCkbnVqTljJp4oeM28ImKN8fqokGN amidfr+JmrwPr2Pnk8+Vil9S0tg3HI1xISLwoJAvgt0pMwhBSel6cwmPBJtQPlo3m/yl QLIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TrEZMj60; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w15si1101525oth.84.2020.04.01.11.32.19; Wed, 01 Apr 2020 11:32:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TrEZMj60; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733072AbgDASbk (ORCPT + 99 others); Wed, 1 Apr 2020 14:31:40 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:58051 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1732979AbgDASbi (ORCPT ); Wed, 1 Apr 2020 14:31:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585765896; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5cd/tAAKc92RQcsvHpnGKQyliE7tkeu/uRWIaIVI0J4=; b=TrEZMj6035OnEC87FYVBdAnd54npBdb6uLaWBHH863sPnyX8snu7r+5UqX6E+o505++Z/6 WjMC0MM1+YQfkqXcQ4+Cc2XlYIYILVY9pABzG1VvVPUoOEcIMKF8LzCffL9+uKTiyewsJq UmH1Rq9x7uYhzbVm8Ns/h5IpXYMtzjA= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-103-hd9xlhQUPuW7Dr_84iWPUA-1; Wed, 01 Apr 2020 14:31:34 -0400 X-MC-Unique: hd9xlhQUPuW7Dr_84iWPUA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 1F3D818C8C00; Wed, 1 Apr 2020 18:31:33 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-113-73.ams2.redhat.com [10.36.113.73]) by smtp.corp.redhat.com (Postfix) with ESMTP id B6E6E9A240; Wed, 1 Apr 2020 18:31:30 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: "Michael S. Tsirkin" Cc: "virtualization@lists.linux-foundation.org" , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Linux Next Mailing List , Stephen Rothwell , kvm list , Halil Pasic , "linux-kernel@vger.kernel.org" , Cornelia Huck , Christian Borntraeger Subject: [PATCH v4 2/7] vhost: use batched version by default Date: Wed, 1 Apr 2020 20:31:13 +0200 Message-Id: <20200401183118.8334-3-eperezma@redhat.com> In-Reply-To: <20200401183118.8334-1-eperezma@redhat.com> References: <20200401183118.8334-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Michael S. Tsirkin" As testing shows no performance change, switch to that now. Signed-off-by: Michael S. Tsirkin Signed-off-by: Eugenio P=C3=A9rez --- drivers/vhost/vhost.c | 251 +----------------------------------------- drivers/vhost/vhost.h | 4 - 2 files changed, 2 insertions(+), 253 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index 56593ba6decc..6ca658c21e15 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2038,253 +2038,6 @@ static unsigned next_desc(struct vhost_virtqueue = *vq, struct vring_desc *desc) return next; } =20 -static int get_indirect(struct vhost_virtqueue *vq, - struct iovec iov[], unsigned int iov_size, - unsigned int *out_num, unsigned int *in_num, - struct vhost_log *log, unsigned int *log_num, - struct vring_desc *indirect) -{ - struct vring_desc desc; - unsigned int i =3D 0, count, found =3D 0; - u32 len =3D vhost32_to_cpu(vq, indirect->len); - struct iov_iter from; - int ret, access; - - /* Sanity check */ - if (unlikely(len % sizeof desc)) { - vq_err(vq, "Invalid length in indirect descriptor: " - "len 0x%llx not multiple of 0x%zx\n", - (unsigned long long)len, - sizeof desc); - return -EINVAL; - } - - ret =3D translate_desc(vq, vhost64_to_cpu(vq, indirect->addr), len, vq-= >indirect, - UIO_MAXIOV, VHOST_ACCESS_RO); - if (unlikely(ret < 0)) { - if (ret !=3D -EAGAIN) - vq_err(vq, "Translation failure %d in indirect.\n", ret); - return ret; - } - iov_iter_init(&from, READ, vq->indirect, ret, len); - - /* We will use the result as an address to read from, so most - * architectures only need a compiler barrier here. */ - read_barrier_depends(); - - count =3D len / sizeof desc; - /* Buffers are chained via a 16 bit next field, so - * we can have at most 2^16 of these. */ - if (unlikely(count > USHRT_MAX + 1)) { - vq_err(vq, "Indirect buffer length too big: %d\n", - indirect->len); - return -E2BIG; - } - - do { - unsigned iov_count =3D *in_num + *out_num; - if (unlikely(++found > count)) { - vq_err(vq, "Loop detected: last one at %u " - "indirect size %u\n", - i, count); - return -EINVAL; - } - if (unlikely(!copy_from_iter_full(&desc, sizeof(desc), &from))) { - vq_err(vq, "Failed indirect descriptor: idx %d, %zx\n", - i, (size_t)vhost64_to_cpu(vq, indirect->addr) + i * sizeof des= c); - return -EINVAL; - } - if (unlikely(desc.flags & cpu_to_vhost16(vq, VRING_DESC_F_INDIRECT))) = { - vq_err(vq, "Nested indirect descriptor: idx %d, %zx\n", - i, (size_t)vhost64_to_cpu(vq, indirect->addr) + i * sizeof des= c); - return -EINVAL; - } - - if (desc.flags & cpu_to_vhost16(vq, VRING_DESC_F_WRITE)) - access =3D VHOST_ACCESS_WO; - else - access =3D VHOST_ACCESS_RO; - - ret =3D translate_desc(vq, vhost64_to_cpu(vq, desc.addr), - vhost32_to_cpu(vq, desc.len), iov + iov_count, - iov_size - iov_count, access); - if (unlikely(ret < 0)) { - if (ret !=3D -EAGAIN) - vq_err(vq, "Translation failure %d indirect idx %d\n", - ret, i); - return ret; - } - /* If this is an input descriptor, increment that count. */ - if (access =3D=3D VHOST_ACCESS_WO) { - *in_num +=3D ret; - if (unlikely(log && ret)) { - log[*log_num].addr =3D vhost64_to_cpu(vq, desc.addr); - log[*log_num].len =3D vhost32_to_cpu(vq, desc.len); - ++*log_num; - } - } else { - /* If it's an output descriptor, they're all supposed - * to come before any input descriptors. */ - if (unlikely(*in_num)) { - vq_err(vq, "Indirect descriptor " - "has out after in: idx %d\n", i); - return -EINVAL; - } - *out_num +=3D ret; - } - } while ((i =3D next_desc(vq, &desc)) !=3D -1); - return 0; -} - -/* This looks in the virtqueue and for the first available buffer, and c= onverts - * it to an iovec for convenient access. Since descriptors consist of s= ome - * number of output then some number of input descriptors, it's actually= two - * iovecs, but we pack them into one and note how many of each there wer= e. - * - * This function returns the descriptor number found, or vq->num (which = is - * never a valid descriptor number) if none was found. A negative code = is - * returned on error. */ -int vhost_get_vq_desc(struct vhost_virtqueue *vq, - struct iovec iov[], unsigned int iov_size, - unsigned int *out_num, unsigned int *in_num, - struct vhost_log *log, unsigned int *log_num) -{ - struct vring_desc desc; - unsigned int i, head, found =3D 0; - u16 last_avail_idx; - __virtio16 avail_idx; - __virtio16 ring_head; - int ret, access; - - /* Check it isn't doing very strange things with descriptor numbers. */ - last_avail_idx =3D vq->last_avail_idx; - - if (vq->avail_idx =3D=3D vq->last_avail_idx) { - if (unlikely(vhost_get_avail_idx(vq, &avail_idx))) { - vq_err(vq, "Failed to access avail idx at %p\n", - &vq->avail->idx); - return -EFAULT; - } - vq->avail_idx =3D vhost16_to_cpu(vq, avail_idx); - - if (unlikely((u16)(vq->avail_idx - last_avail_idx) > vq->num)) { - vq_err(vq, "Guest moved used index from %u to %u", - last_avail_idx, vq->avail_idx); - return -EFAULT; - } - - /* If there's nothing new since last we looked, return - * invalid. - */ - if (vq->avail_idx =3D=3D last_avail_idx) - return vq->num; - - /* Only get avail ring entries after they have been - * exposed by guest. - */ - smp_rmb(); - } - - /* Grab the next descriptor number they're advertising, and increment - * the index we've seen. */ - if (unlikely(vhost_get_avail_head(vq, &ring_head, last_avail_idx))) { - vq_err(vq, "Failed to read head: idx %d address %p\n", - last_avail_idx, - &vq->avail->ring[last_avail_idx % vq->num]); - return -EFAULT; - } - - head =3D vhost16_to_cpu(vq, ring_head); - - /* If their number is silly, that's an error. */ - if (unlikely(head >=3D vq->num)) { - vq_err(vq, "Guest says index %u > %u is available", - head, vq->num); - return -EINVAL; - } - - /* When we start there are none of either input nor output. */ - *out_num =3D *in_num =3D 0; - if (unlikely(log)) - *log_num =3D 0; - - i =3D head; - do { - unsigned iov_count =3D *in_num + *out_num; - if (unlikely(i >=3D vq->num)) { - vq_err(vq, "Desc index is %u > %u, head =3D %u", - i, vq->num, head); - return -EINVAL; - } - if (unlikely(++found > vq->num)) { - vq_err(vq, "Loop detected: last one at %u " - "vq size %u head %u\n", - i, vq->num, head); - return -EINVAL; - } - ret =3D vhost_get_desc(vq, &desc, i); - if (unlikely(ret)) { - vq_err(vq, "Failed to get descriptor: idx %d addr %p\n", - i, vq->desc + i); - return -EFAULT; - } - if (desc.flags & cpu_to_vhost16(vq, VRING_DESC_F_INDIRECT)) { - ret =3D get_indirect(vq, iov, iov_size, - out_num, in_num, - log, log_num, &desc); - if (unlikely(ret < 0)) { - if (ret !=3D -EAGAIN) - vq_err(vq, "Failure detected " - "in indirect descriptor at idx %d\n", i); - return ret; - } - continue; - } - - if (desc.flags & cpu_to_vhost16(vq, VRING_DESC_F_WRITE)) - access =3D VHOST_ACCESS_WO; - else - access =3D VHOST_ACCESS_RO; - ret =3D translate_desc(vq, vhost64_to_cpu(vq, desc.addr), - vhost32_to_cpu(vq, desc.len), iov + iov_count, - iov_size - iov_count, access); - if (unlikely(ret < 0)) { - if (ret !=3D -EAGAIN) - vq_err(vq, "Translation failure %d descriptor idx %d\n", - ret, i); - return ret; - } - if (access =3D=3D VHOST_ACCESS_WO) { - /* If this is an input descriptor, - * increment that count. */ - *in_num +=3D ret; - if (unlikely(log && ret)) { - log[*log_num].addr =3D vhost64_to_cpu(vq, desc.addr); - log[*log_num].len =3D vhost32_to_cpu(vq, desc.len); - ++*log_num; - } - } else { - /* If it's an output descriptor, they're all supposed - * to come before any input descriptors. */ - if (unlikely(*in_num)) { - vq_err(vq, "Descriptor has out after in: " - "idx %d\n", i); - return -EINVAL; - } - *out_num +=3D ret; - } - } while ((i =3D next_desc(vq, &desc)) !=3D -1); - - /* On success, increment avail index. */ - vq->last_avail_idx++; - - /* Assume notifications from guest are disabled at this point, - * if they aren't we would need to update avail_event index. */ - BUG_ON(!(vq->used_flags & VRING_USED_F_NO_NOTIFY)); - return head; -} -EXPORT_SYMBOL_GPL(vhost_get_vq_desc); - static struct vhost_desc *peek_split_desc(struct vhost_virtqueue *vq) { BUG_ON(!vq->ndescs); @@ -2495,7 +2248,7 @@ static int fetch_descs(struct vhost_virtqueue *vq) * This function returns the descriptor number found, or vq->num (which = is * never a valid descriptor number) if none was found. A negative code = is * returned on error. */ -int vhost_get_vq_desc_batch(struct vhost_virtqueue *vq, +int vhost_get_vq_desc(struct vhost_virtqueue *vq, struct iovec iov[], unsigned int iov_size, unsigned int *out_num, unsigned int *in_num, struct vhost_log *log, unsigned int *log_num) @@ -2570,7 +2323,7 @@ int vhost_get_vq_desc_batch(struct vhost_virtqueue = *vq, =20 return ret; } -EXPORT_SYMBOL_GPL(vhost_get_vq_desc_batch); +EXPORT_SYMBOL_GPL(vhost_get_vq_desc); =20 /* Reverse the effect of vhost_get_vq_desc. Useful for error handling. *= / void vhost_discard_vq_desc(struct vhost_virtqueue *vq, int n) diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h index 20bb95661f94..e5f295e5ffcc 100644 --- a/drivers/vhost/vhost.h +++ b/drivers/vhost/vhost.h @@ -187,10 +187,6 @@ long vhost_vring_ioctl(struct vhost_dev *d, unsigned= int ioctl, void __user *arg bool vhost_vq_access_ok(struct vhost_virtqueue *vq); bool vhost_log_access_ok(struct vhost_dev *); =20 -int vhost_get_vq_desc_batch(struct vhost_virtqueue *, - struct iovec iov[], unsigned int iov_count, - unsigned int *out_num, unsigned int *in_num, - struct vhost_log *log, unsigned int *log_num); int vhost_get_vq_desc(struct vhost_virtqueue *, struct iovec iov[], unsigned int iov_count, unsigned int *out_num, unsigned int *in_num, --=20 2.18.1