Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1018736ybz; Thu, 16 Apr 2020 01:00:09 -0700 (PDT) X-Google-Smtp-Source: APiQypLiMVg6phzQKsC+gccQ4Y73MT21o16b1yB6d3p+hep1vLY90aaPv0v2iMLt2beHhgw/DOm3 X-Received: by 2002:a17:906:158c:: with SMTP id k12mr8586277ejd.7.1587024009248; Thu, 16 Apr 2020 01:00:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587024009; cv=none; d=google.com; s=arc-20160816; b=hwoLxS0yGantMqNC5MwcEigcG6Q/VG/xQxQg4eOHuY5RgckqM2kmM2SJV6FRwsuQlO JtSP7K58V6oH3WJimYIv5r3VSTNT4+hHk62+vQA5WooWZEDYM8kVkeV8ZZg6mqQ/Sf4A /M7HOIJcX58QOicELgHa5/Z/ztTBdhU0jIKa0hBAq1R7WIiOtbpq5THqLJy/0vCLMHGI wYNwjjv5L01vZFQpv4qNjwCz1BsQwDDeMtsSrSHZu3avZTRQf/YQditB+aNxrAGXXnEI 5T5zpHNKljsiZZuYMT6a/YW0F4mXlMUGj4ziaKjH/qmOYAS62c1gSxZ3zXMJjDzuLgVy 8x6A== 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=gavfKGuNl7br7RXb7XSyuq0WG8m5khS0l1y8vD9u01c=; b=BMhOMtWI00sdDM62JLxfq9sxmZMyNLjdN8Y3HE5qDlUlvjDf45xCqKIYFAEqna8LaR 0WFYTlEOYkAMi2MBP6pIZwD5b4HMbuu8n/X1VB2o2tuQMZInK3L2A+OkMotfCZt344Qg SiUjOlevJD4VahfcdirF7hHSO+GokAJSsBt2XHJ6+7yQl1f9cYhdE14bAdiPVyXEHnkO neTviclleguPz6wsERyW/OkYTIeXP08+oVz1ecNVXecjyB05oaNOQn/aDdxY0khnbBZQ OCBzhLTHVxxZAUoNLMXjG+M9ZetP5QS5bT6NhXcepHMWw3rk2AHBfCsEC8+Xd4l3+leg awaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GulRuYGB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id x20si12174030ejo.227.2020.04.16.00.59.45; Thu, 16 Apr 2020 01:00:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GulRuYGB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S2441033AbgDPH6O (ORCPT + 99 others); Thu, 16 Apr 2020 03:58:14 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:57628 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S2440855AbgDPH5S (ORCPT ); Thu, 16 Apr 2020 03:57:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587023837; 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=gavfKGuNl7br7RXb7XSyuq0WG8m5khS0l1y8vD9u01c=; b=GulRuYGBPO3GKZZ3vVaKdwTf+2teZmKB10XlvZ3Au4qrdYVh4fIxL5I4bEfRKmeuXrlWpb 5EfU89ehCuO1vBYefLmbIORDDG5w1ZSAFPkJoZIk2hB1Lx8D4JCo0hnBWxZBzTvqaeTQNi 6aKwqtxN3BrV7/nbS3ooVBI+MYR1bqM= 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-500-tkGFXRgxOSOh6b_CqJMs6A-1; Thu, 16 Apr 2020 03:57:13 -0400 X-MC-Unique: tkGFXRgxOSOh6b_CqJMs6A-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C72601005509; Thu, 16 Apr 2020 07:57:11 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-194.ams2.redhat.com [10.36.112.194]) by smtp.corp.redhat.com (Postfix) with ESMTP id 67EA37E7C0; Thu, 16 Apr 2020 07:57:06 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: "Michael S. Tsirkin" Cc: Stephen Rothwell , "virtualization@lists.linux-foundation.org" , Christian Borntraeger , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Linux Next Mailing List , kvm list , Cornelia Huck , Halil Pasic , "linux-kernel@vger.kernel.org" Subject: [PATCH v2 6/8] tools/virtio: Extract virtqueue initialization in vq_reset Date: Thu, 16 Apr 2020 09:56:41 +0200 Message-Id: <20200416075643.27330-7-eperezma@redhat.com> In-Reply-To: <20200416075643.27330-1-eperezma@redhat.com> References: <20200416075643.27330-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.11 Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org So we can reset after that in the main loop. Signed-off-by: Eugenio P=C3=A9rez --- tools/virtio/virtio_test.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/tools/virtio/virtio_test.c b/tools/virtio/virtio_test.c index d9827b640c21..18d5347003eb 100644 --- a/tools/virtio/virtio_test.c +++ b/tools/virtio/virtio_test.c @@ -95,6 +95,19 @@ void vhost_vq_setup(struct vdev_info *dev, struct vq_i= nfo *info) assert(r >=3D 0); } =20 +static void vq_reset(struct vq_info *info, int num, struct virtio_device= *vdev) +{ + if (info->vq) + vring_del_virtqueue(info->vq); + + memset(info->ring, 0, vring_legacy_size(num, 4096)); + vring_legacy_init(&info->vring, num, info->ring, 4096); + info->vq =3D __vring_new_virtqueue(info->idx, info->vring, vdev, true, + false, vq_notify, vq_callback, "test"); + assert(info->vq); + info->vq->priv =3D info; +} + static void vq_info_add(struct vdev_info *dev, int num) { struct vq_info *info =3D &dev->vqs[dev->nvqs]; @@ -104,13 +117,7 @@ static void vq_info_add(struct vdev_info *dev, int n= um) info->call =3D eventfd(0, EFD_NONBLOCK); r =3D posix_memalign(&info->ring, 4096, vring_legacy_size(num, 4096)); assert(r >=3D 0); - memset(info->ring, 0, vring_legacy_size(num, 4096)); - vring_legacy_init(&info->vring, num, info->ring, 4096); - info->vq =3D - __vring_new_virtqueue(info->idx, info->vring, &dev->vdev, true, - false, vq_notify, vq_callback, "test"); - assert(info->vq); - info->vq->priv =3D info; + vq_reset(info, num, &dev->vdev); vhost_vq_setup(dev, info); dev->fds[info->idx].fd =3D info->call; dev->fds[info->idx].events =3D POLLIN; --=20 2.18.1