Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1550880ybz; Sat, 18 Apr 2020 03:25:55 -0700 (PDT) X-Google-Smtp-Source: APiQypJpLINCniv1yjlQ70OBCznEnlxjVo73irx64KlRragEyfhmHzV22QIDHnECPoe2bPZeSqSd X-Received: by 2002:a17:906:bce4:: with SMTP id op4mr2724966ejb.174.1587205554817; Sat, 18 Apr 2020 03:25:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1587205554; cv=none; d=google.com; s=arc-20160816; b=P/t4NcB4T2YtRKlnzBJ68Osv7gUZxhdGHRrZXJcKcr8vq9Or2ZGORu9B80j+V509DT JIcuZzzhImetVUSVb8nfUsDtBxrB7U2jB4Xm36RMIKH5e9HQEo+/Q0o7N9SysrglhJQs Wbez0Scp95sJt7ea+57QgoocNwZH4aRoXzvaomEwNEiqToANf9hyfJoMtDnj5aihUC3K BityGO7xeySzXHYtMkiDVi3b+65A5X+SSwZJ2VErAOzApWoRoFKBcHEYVczN5+eW9ZfO VexfVJfwI3uUjxah0BBuwHKKhUpE5KaEfzTRG/SqBeKFD+NTrkTnn8rpc51XieLw7dKt sDqw== 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=NTpuDlc6qvgZkv1wgOF0V1ahvk1X+aQkxyfimEc4tRM=; b=HtS1lqcT7q225eIXihsnNx3Qi4C1Aeo7ruoYPL21+RdI9s8tFVlu+w0zaB7DkcUdnw JmMi+/LndGnBX3/F56+UQGZ45o9ccne8BSOTiGpLmMYK+Qn+sPuGT6qAcEguT+0SQSIS tP6jtNzhdUmlnVDQJyxYqS+KtThGTIQvTftecxluf1oappG3waAPTCN2NaRWx7EhBXef y504DHrVuj88kuIu77DxQBFcvpbVeLxHfAEfE65BGKB3gXaBLvmdouAX/93s0hS4Q7ph dNkQT83C4r8EKZw+BnnFawpTbCowBvp39umrU0cYDu6IDiT2e5sLiet4nh0FZApgKqe6 UeUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=RRgtBKWD; 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 d9si5020665ejj.290.2020.04.18.03.25.32; Sat, 18 Apr 2020 03:25:54 -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=RRgtBKWD; 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 S1726319AbgDRKYE (ORCPT + 99 others); Sat, 18 Apr 2020 06:24:04 -0400 Received: from us-smtp-1.mimecast.com ([205.139.110.61]:59704 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726050AbgDRKWx (ORCPT ); Sat, 18 Apr 2020 06:22:53 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1587205372; 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=NTpuDlc6qvgZkv1wgOF0V1ahvk1X+aQkxyfimEc4tRM=; b=RRgtBKWDGdRfZky9Ur74wo9nbNASLZYwdi/Vg5lSDy8Q6lj/WWf4Ij3x/l2MIH5KeWAIOj sFz8rmdr2Ar+/ZdIoQT2HbvtEo1pDnHzqUeTFai3ALRlQYaEOTzJDYn4PwH3XwZbu9gU/7 JLRZvNudS2vMhvbCVX3+PGuvWCy7Cj8= 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-30-2j2JnosrPRypXaWZa6e8Ag-1; Sat, 18 Apr 2020 06:22:48 -0400 X-MC-Unique: 2j2JnosrPRypXaWZa6e8Ag-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 938378017F5; Sat, 18 Apr 2020 10:22:47 +0000 (UTC) Received: from eperezma.remote.csb (ovpn-112-94.ams2.redhat.com [10.36.112.94]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3E6641001DC2; Sat, 18 Apr 2020 10:22:42 +0000 (UTC) From: =?UTF-8?q?Eugenio=20P=C3=A9rez?= To: "Michael S. Tsirkin" Cc: "virtualization@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" , Halil Pasic , Cornelia Huck , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Christian Borntraeger , kvm list , Stephen Rothwell , Linux Next Mailing List Subject: [PATCH v3 6/8] tools/virtio: Extract virtqueue initialization in vq_reset Date: Sat, 18 Apr 2020 12:22:15 +0200 Message-Id: <20200418102217.32327-7-eperezma@redhat.com> In-Reply-To: <20200418102217.32327-1-eperezma@redhat.com> References: <20200418102217.32327-1-eperezma@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 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 0a247ba3b899..bc16c818bda3 100644 --- a/tools/virtio/virtio_test.c +++ b/tools/virtio/virtio_test.c @@ -94,6 +94,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_size(num, 4096)); + vring_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]; @@ -103,13 +116,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_size(num, 4096)); assert(r >=3D 0); - memset(info->ring, 0, vring_size(num, 4096)); - vring_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