Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp1480585ybb; Sun, 29 Mar 2020 05:55:00 -0700 (PDT) X-Google-Smtp-Source: ADFU+vuPV3wx4UqtttZVqRYtKBUO6A5p56E0GG8x8rhkJsnQ/Vukfrri4GS57GQLUSjLAOoSqBq3 X-Received: by 2002:aca:4d86:: with SMTP id a128mr4820806oib.96.1585486500206; Sun, 29 Mar 2020 05:55:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585486500; cv=none; d=google.com; s=arc-20160816; b=m2A2vCPLbI4nkZM5bGY10+phAVWghEtk1RGowHzIUaugO2zUOttcVt6fE+jfQmZlmv pHozOzNp6YVd5IUcYuTcylMnX6Qo0/M6oGfbrXtjcs40goghg+ZB3R2h3FsylALHKFty DjF34iQQkXIoUcSlaf5sKBcEYgOu7aQv4CgzWhUpYM2bMmMtgeDks5weWPoLXg5W7ZJx vOh2c+toffmJEcoCQjuGCB4U3D8Hndsn0Q5SI8OHKcT+hrqyfbv0QGCb3+R4ZAh7GHDz /oNjqTzyQ2XxcqAE4fsSrSy3/Csb0ISIHeWStFyI9g8QO2l++JlQoksmAW8cxbRxVYya EDLQ== 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=hwBJNIszh6TC6VU12FXZ4Vd7wn8RSesK/NNxIOU/Few=; b=n4P2adxG2eHjsaZBi2YAg2ebQdPvZ0hHttW2Ju/snjpGFIsDV3YTM9nhXCu2cexUJ8 wm9wm79hMuDAjwC0/cYd0OCoOGN9CYHAFtfFrYETxPwCMLM900KJPhamJfWG8N3NQlRN jOnJM6LAPua+0d6IlkWPAEkcJftKquig/dkpflB+YNskWb59lHKcKyOK+dxsS2vPJB4Z /xkiDeemrFqpASgQPsPV/wWZq/q1v07K6y4TL4/gBZDdxIOFYTJzV/9KuSSgjpOrf5Zz pkBmLqRlK4UqYQbge05T5aWsj0h9LQQ2AY+JXpG2K3CKXqD4/6vbkpdGmFbd4CuKPTbD JSzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JizUFo5c; 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 k20si4716564otb.168.2020.03.29.05.54.46; Sun, 29 Mar 2020 05:55:00 -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=JizUFo5c; 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 S1728110AbgC2MgU (ORCPT + 99 others); Sun, 29 Mar 2020 08:36:20 -0400 Received: from us-smtp-delivery-74.mimecast.com ([216.205.24.74]:26709 "EHLO us-smtp-delivery-74.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727985AbgC2MgU (ORCPT ); Sun, 29 Mar 2020 08:36:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585485378; 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=hwBJNIszh6TC6VU12FXZ4Vd7wn8RSesK/NNxIOU/Few=; b=JizUFo5cFKkxzL4LRZrTJcKZhdhom9B/wprXZek6ztCFTHLJBLf3oiAVqYApwdTXvr3XMR pCQErbFBu9G295U3KXPz016IbylfFJanPWcEp+JGcBV4bIauOJ7WcI1iF88KBqHSUB6bVS Gv5+hxsNRXGtxYnMLdIXdhQ4vD+5SKM= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-309-MZ2_qOXaNPGOa1LwY9B53Q-1; Sun, 29 Mar 2020 08:36:16 -0400 X-MC-Unique: MZ2_qOXaNPGOa1LwY9B53Q-1 Received: by mail-wr1-f71.google.com with SMTP id f15so8461918wrt.4 for ; Sun, 29 Mar 2020 05:36:16 -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=hwBJNIszh6TC6VU12FXZ4Vd7wn8RSesK/NNxIOU/Few=; b=ohLxCFgz7Ook8G6OTWrj61gLp6qilHPz5vYpCjhM+P0P8qujTOsR48f5eHVAJ8118y zaBSEf65axj/z6Kgedb9gYBauqIS2UY15mUQJc1Fy9NvnPia0cHVSb3rKZvotY6U0goN qV9IlBCMxjrgPuknRmF45tjmSKyF+3a9qjbleC9Tggk43DSYdYnB+8qcbVXPbjyiBB6t 1BoCU2i1qn+2ggq06eHoeoiz82137Y6NNZRPrH14LFn8l5sgPcxshB0rDd6sOucxUrKQ rA62/X1auNb+8IIVwWFt3oYg1p5xr1aiarxVVZHrLFDHpYa93CCLn5M8cv29K/iOEOb2 ejBw== X-Gm-Message-State: ANhLgQ39olCXmVfvmZAVVc3UyqMOW40N7mQMXlpSWIprGUdoIHw8c6an F1qeLr2ByV5/32Wy4bfVe9L4VnBlaNhVQa+S3RklSodf6Cco6x7qLz2dnxgr+pYMPsbl1X3q1Xg 96QrId9wrqfRe3bkw4/UmVaL0 X-Received: by 2002:a1c:f70a:: with SMTP id v10mr8143939wmh.72.1585485375627; Sun, 29 Mar 2020 05:36:15 -0700 (PDT) X-Received: by 2002:a1c:f70a:: with SMTP id v10mr8143921wmh.72.1585485375355; Sun, 29 Mar 2020 05:36:15 -0700 (PDT) Received: from redhat.com (bzq-79-183-139-129.red.bezeqint.net. [79.183.139.129]) by smtp.gmail.com with ESMTPSA id b187sm17230248wmc.14.2020.03.29.05.36.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Mar 2020 05:36:14 -0700 (PDT) Date: Sun, 29 Mar 2020 08:36:12 -0400 From: "Michael S. Tsirkin" To: Eugenio =?iso-8859-1?Q?P=E9rez?= Cc: "virtualization@lists.linux-foundation.org" , Halil Pasic , Stephen Rothwell , Linux Next Mailing List , kvm list , Cornelia Huck , Christian Borntraeger , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 4/6] tools/virtio: Make --reset reset ring idx Message-ID: <20200329083047-mutt-send-email-mst@kernel.org> References: <20200329113359.30960-1-eperezma@redhat.com> <20200329113359.30960-5-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: <20200329113359.30960-5-eperezma@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Mar 29, 2020 at 01:33:57PM +0200, Eugenio P?rez wrote: > Signed-off-by: Eugenio P?rez > --- > drivers/virtio/virtio_ring.c | 18 ++++++++++++++++++ > include/linux/virtio.h | 2 ++ > tools/virtio/linux/virtio.h | 2 ++ > tools/virtio/virtio_test.c | 28 +++++++++++++++++++++++++++- > 4 files changed, 49 insertions(+), 1 deletion(-) > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > index 867c7ebd3f10..aba44ac3f0d6 100644 > --- a/drivers/virtio/virtio_ring.c > +++ b/drivers/virtio/virtio_ring.c > @@ -1810,6 +1810,24 @@ int virtqueue_add_inbuf_ctx(struct virtqueue *vq, > } > EXPORT_SYMBOL_GPL(virtqueue_add_inbuf_ctx); > > +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); > + > /** > * virtqueue_kick_prepare - first half of split virtqueue_kick call. > * @_vq: the struct virtqueue Add documentation please. When should this be called? If it's just for testing, we can put this within some ifdef that only triggers when building the test ... > diff --git a/include/linux/virtio.h b/include/linux/virtio.h > index 15f906e4a748..286a0048fbeb 100644 > --- a/include/linux/virtio.h > +++ b/include/linux/virtio.h > @@ -58,6 +58,8 @@ int virtqueue_add_sgs(struct virtqueue *vq, > void *data, > gfp_t gfp); > > +void virtqueue_reset_free_head(struct virtqueue *vq); > + > bool virtqueue_kick(struct virtqueue *vq); > > bool virtqueue_kick_prepare(struct virtqueue *vq); > diff --git a/tools/virtio/linux/virtio.h b/tools/virtio/linux/virtio.h > index b751350d4ce8..cf2e9ccf4de2 100644 > --- a/tools/virtio/linux/virtio.h > +++ b/tools/virtio/linux/virtio.h > @@ -43,6 +43,8 @@ int virtqueue_add_inbuf(struct virtqueue *vq, > void *data, > gfp_t gfp); > > +void virtqueue_reset_free_head(struct virtqueue *vq); > + > bool virtqueue_kick(struct virtqueue *vq); > > void *virtqueue_get_buf(struct virtqueue *vq, unsigned int *len); > 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; > + virtqueue_reset_free_head(vq->vq); > + Hmm this is poking at internal vq format ... > + 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