Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1736671ybb; Thu, 2 Apr 2020 06:29:39 -0700 (PDT) X-Google-Smtp-Source: APiQypKBQftP0jld2qaN5QFlgcyXuRCpCge3dXEdM4hfPASIcAJcVPQD4PKFrn1xLTzCMGHzmO2n X-Received: by 2002:a05:6830:1313:: with SMTP id p19mr2439596otq.179.1585834179756; Thu, 02 Apr 2020 06:29:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585834179; cv=none; d=google.com; s=arc-20160816; b=bY7BBYvrziXk2xhGFhnnnacd3+3qVOdKKivOfWJR9BdTg0Gv4TIvH8A7rQQKPpLUT/ CNPBDASKMeEK9N5k5+PHxBRXdNcnp7YRf4U10C9lhsdrfGFfHe8tclRYhBCy4zFqdMK0 rKS6O812dm70/BMu1hvG3yLOxPzctth6i+G0il5HURtDOEvD3a3RYv54s2lngJ2ay1Ql m1BOs8GQGwVuaRy6KbbS5+ORBsvG/7x9rC+Aqiw8V+98icbPYyZnzQQtqaFLqXH7HyUZ g9SSwSZJbrq/z58F9uD2EazUXYQLuyPKBwtmOcewtlzVm9b20dsd+/dBb1ZscJ6vMsIN +ggg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=/1eX8MBJ9dVspbC5Z01wrbH0AdjiWCbWXslfX6OZ6hs=; b=QsZJpQfXIkOMi+SBGWyk+KLq5bXx7ILKJ5hkblxtSdjYtSIra6AyTS48JcZp0b94KH OeQm/S2bXZHq4E+guByh4PHiq80/vT3uhdBX2mpDnlyRPpi1T5rBToO8eUh+aVKW3oqd 7R65iRH6uNHuQBfhCXmnZYX2eXMskAt+XWLSs34q7pTjsYE5wlFszaoQQIEBa8vkVvuQ o6Sx4KVNVEzNV3wWXrPNiZW392rlgBsOCbqlbnMQ/6rShEMx7aryDXwbZp///gMqCpc3 TqZPu+wwnI+Iu/3NT71dWSM42lmMPTpY577SoMBkxto0FIy17KY1JfuKyT3vA/N0HB0I ARgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=X073aoju; 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 s5si2198980oie.153.2020.04.02.06.29.26; Thu, 02 Apr 2020 06:29:39 -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=X073aoju; 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 S2388620AbgDBN1s (ORCPT + 99 others); Thu, 2 Apr 2020 09:27:48 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:52762 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2388274AbgDBN1r (ORCPT ); Thu, 2 Apr 2020 09:27:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585834065; 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=/1eX8MBJ9dVspbC5Z01wrbH0AdjiWCbWXslfX6OZ6hs=; b=X073aojub94Upl6/d54MHh8luUumvIlR/kYvIKhaMCFefMv4Ej7X3AE+d5G4N8qLiaafyC ObLJF31EBKDIt6JewWNXz4BPsdtIBqpT4osFwJMNIU0pcsqTn2uA43aL7lg8i0nPfYApvG 5tZRraKkQpJ0l5gA9dBlLf+YFsSa61Y= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-334-u5p39jVzNbiUkMR3J-pKGA-1; Thu, 02 Apr 2020 09:27:44 -0400 X-MC-Unique: u5p39jVzNbiUkMR3J-pKGA-1 Received: by mail-qt1-f197.google.com with SMTP id f7so3152015qtq.3 for ; Thu, 02 Apr 2020 06:27:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=/1eX8MBJ9dVspbC5Z01wrbH0AdjiWCbWXslfX6OZ6hs=; b=AibEGPQ1JR2Ehw+atyggrxNyrzMtjk9oQNBGZJ1x2PCfcWZwtu0DQsqkGOTW8nW3mQ fSIYWF8Y1gMrw9/7sNGSVQ6hQhEVCvkSnElPQuObRtd6yt4B+WHMBOYnbNjskYiYi7u0 WlSPf3xzq/3zCRjaUd9uZOScelmB97gAjSon7gwHorgXtU5XN49XM83Yjqr7KxqRWMKM XD7gXTRIAWWCM2Y/IdOh3KyR6HwZviMpo3Se8HfF0dS0PUEIOO2WrGV0q1ZYbH/+a5jE 2P/wrUQd85PJV8TH+nO394Rww3dJ5X2VRJqawR1lZFM1+GPBncOe4wnZloL4sFQC8ztV O/YQ== X-Gm-Message-State: AGi0PuZGsZ38izOVb7k6NvpZiuRlURDaJrfy+cx/PQ0HEd1qXRm/75a2 8XA7LM9QMXE9dFo5TMZP5a2Q+u2cpLlSnfqGc6/SREgvGc2OlIre8Ya9l7EaH8gB0ifvPudG6qB K6B/pYVT9xZvGl3cHzBtK9P4S X-Received: by 2002:a37:7a84:: with SMTP id v126mr3349826qkc.423.1585834063875; Thu, 02 Apr 2020 06:27:43 -0700 (PDT) X-Received: by 2002:a37:7a84:: with SMTP id v126mr3349804qkc.423.1585834063566; Thu, 02 Apr 2020 06:27:43 -0700 (PDT) Received: from redhat.com (bzq-79-176-51-222.red.bezeqint.net. [79.176.51.222]) by smtp.gmail.com with ESMTPSA id 31sm3619643qta.56.2020.04.02.06.27.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Apr 2020 06:27:42 -0700 (PDT) Date: Thu, 2 Apr 2020 09:27:37 -0400 From: "Michael S. Tsirkin" To: Eugenio =?iso-8859-1?Q?P=E9rez?= Cc: "virtualization@lists.linux-foundation.org" , Linux Next Mailing List , Stephen Rothwell , kvm list , Halil Pasic , "linux-kernel@vger.kernel.org" , Cornelia Huck , Christian Borntraeger Subject: Re: [PATCH v4 7/7] tools/virtio: Make --reset reset ring idx Message-ID: <20200402092529-mutt-send-email-mst@kernel.org> References: <20200401183118.8334-1-eperezma@redhat.com> <20200401183118.8334-8-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200401183118.8334-8-eperezma@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 01, 2020 at 08:31:18PM +0200, Eugenio P?rez wrote: > Signed-off-by: Eugenio P?rez I'm still a bit puzzled by this one - could you explain what the rationale here is? > --- > drivers/virtio/virtio_ring.c | 29 +++++++++++++++++++++++++++++ > tools/virtio/linux/virtio.h | 2 ++ > tools/virtio/virtio_test.c | 28 +++++++++++++++++++++++++++- > 3 files changed, 58 insertions(+), 1 deletion(-) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index 58b96baa8d48..f9153a381f72 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -1810,6 +1810,35 @@ int virtqueue_add_inbuf_ctx(struct virtqueue *vq, > } > EXPORT_SYMBOL_GPL(virtqueue_add_inbuf_ctx); > > +#ifndef __KERNEL__ > + > +/** > + * virtqueue_reset_free_head - Reset to 0 the members of split ring. > + * @vq: Virtqueue to reset. > + * > + * At this moment, is only meant for debug the ring index change, do not use > + * in production. > + */ > +void virtqueue_reset_free_head(struct virtqueue *_vq) > +{ > + struct vring_virtqueue *vq = to_vvq(_vq); > + > + // vq->last_used_idx = 0; > + vq->num_added = 0; > + > + vq->split.queue_size_in_bytes = 0; > + vq->split.avail_flags_shadow = 0; > + vq->split.avail_idx_shadow = 0; > + > + memset(vq->split.desc_state, 0, vq->split.vring.num * > + sizeof(struct vring_desc_state_split)); > + > + vq->free_head = 0; > +} > +EXPORT_SYMBOL_GPL(virtqueue_reset_free_head); > + > +#endif > + > /** > * virtqueue_kick_prepare - first half of split virtqueue_kick call. > * @_vq: the struct virtqueue > diff --git a/tools/virtio/linux/virtio.h b/tools/virtio/linux/virtio.h > index b751350d4ce8..5d33eab6b814 100644 > --- a/tools/virtio/linux/virtio.h > +++ b/tools/virtio/linux/virtio.h > @@ -65,4 +65,6 @@ struct virtqueue *vring_new_virtqueue(unsigned int index, > const char *name); > void vring_del_virtqueue(struct virtqueue *vq); > > +void virtqueue_reset_free_head(struct virtqueue *vq); > + > #endif > diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c > index 93d81cd64ba0..bf21ece30594 100644 > --- a/tools/virtio/virtio_test.c > +++ b/tools/virtio/virtio_test.c > @@ -49,6 +49,7 @@ struct vdev_info { > > static const struct vhost_vring_file no_backend = { .fd = -1 }, > backend = { .fd = 1 }; > +static const struct vhost_vring_state null_state = {}; > > bool vq_notify(struct virtqueue *vq) > { > @@ -218,10 +219,33 @@ static void run_test(struct vdev_info *dev, struct vq_info *vq, > } > > if (reset) { > + struct vhost_vring_state s = { .index = 0 }; > + int i; > + vq->vring.avail->idx = 0; > + vq->vq->num_free = vq->vring.num; > + > + // Put everything in free lists. > + for (i = 0; i < vq->vring.num-1; i++) > + vq->vring.desc[i].next = > + cpu_to_virtio16(&dev->vdev, > + i + 1); > + vq->vring.desc[vq->vring.num-1].next = 0; Poking at vq descriptors like this seems fragile. I think this calls for a better API that handles everything internally. > + virtqueue_reset_free_head(vq->vq); > + > + r = ioctl(dev->control, VHOST_GET_VRING_BASE, > + &s); > + assert(!r); > + > + s.num = 0; > + r = ioctl(dev->control, VHOST_SET_VRING_BASE, > + &null_state); > + assert(!r); > + > r = ioctl(dev->control, VHOST_TEST_SET_BACKEND, > &backend); > assert(!r); > > + started = completed; > while (completed > next_reset) > next_reset += completed; > } > @@ -243,7 +267,9 @@ static void run_test(struct vdev_info *dev, struct vq_info *vq, > test = 0; > r = ioctl(dev->control, VHOST_TEST_RUN, &test); > assert(r >= 0); > - fprintf(stderr, "spurious wakeups: 0x%llx\n", spurious); > + fprintf(stderr, > + "spurious wakeups: 0x%llx started=0x%lx completed=0x%lx\n", > + spurious, started, completed); > } > > const char optstring[] = "h"; > -- > 2.18.1