From patchwork Thu Nov 16 18:48:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 10061947 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D59EB604D3 for ; Thu, 16 Nov 2017 18:50:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CE7A02A9EC for ; Thu, 16 Nov 2017 18:50:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C0DBD2ABB1; Thu, 16 Nov 2017 18:50:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 583D32A9EC for ; Thu, 16 Nov 2017 18:50:39 +0000 (UTC) Received: from localhost ([::1]:42477 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFPFG-00085a-Jd for patchwork-qemu-devel@patchwork.kernel.org; Thu, 16 Nov 2017 13:50:38 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39173) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eFPE4-00084B-9n for qemu-devel@nongnu.org; Thu, 16 Nov 2017 13:49:25 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eFPE1-0000ig-7k for qemu-devel@nongnu.org; Thu, 16 Nov 2017 13:49:24 -0500 Received: from mx1.redhat.com ([209.132.183.28]:60612) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eFPE1-0000hR-1e for qemu-devel@nongnu.org; Thu, 16 Nov 2017 13:49:21 -0500 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 mx1.redhat.com (Postfix) with ESMTPS id 11C9581127; Thu, 16 Nov 2017 18:49:20 +0000 (UTC) Received: from localhost.localdomain (ovpn-112-48.ams2.redhat.com [10.36.112.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3F3FD6047F; Thu, 16 Nov 2017 18:49:11 +0000 (UTC) From: Maxime Coquelin To: mst@redhat.com, yuri.benditovich@daynix.com, yvugenfi@redhat.com, jasowang@redhat.com, qemu-devel@nongnu.org Date: Thu, 16 Nov 2017 19:48:34 +0100 Message-Id: <20171116184835.28556-2-maxime.coquelin@redhat.com> In-Reply-To: <20171116184835.28556-1-maxime.coquelin@redhat.com> References: <20171116184835.28556-1-maxime.coquelin@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 16 Nov 2017 18:49:20 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 1/2] virtio: Add queue interface to restore avail index from vring used index X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Maxime Coquelin Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP In case of backend crash, it is not possible to restore internal avail index from the backend value as vhost_get_vring_base callback fails. This patch provides a new interface to restore internal avail index from the vring used index, as done by some vhost-user backend on reconnection. Signed-off-by: Maxime Coquelin Reviewed-by: Jens Freimann --- hw/virtio/virtio.c | 10 ++++++++++ include/hw/virtio/virtio.h | 1 + 2 files changed, 11 insertions(+) diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index 5884ce3480..583516c428 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -2310,6 +2310,16 @@ void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t idx) vdev->vq[n].shadow_avail_idx = idx; } +void virtio_queue_restore_last_avail_idx(VirtIODevice *vdev, int n) +{ + rcu_read_lock(); + if (vdev->vq[n].vring.desc) { + vdev->vq[n].last_avail_idx = vring_used_idx(&vdev->vq[n]); + vdev->vq[n].shadow_avail_idx = vdev->vq[n].last_avail_idx; + } + rcu_read_unlock(); +} + void virtio_queue_update_used_idx(VirtIODevice *vdev, int n) { rcu_read_lock(); diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h index 5abada6966..098bdaaea3 100644 --- a/include/hw/virtio/virtio.h +++ b/include/hw/virtio/virtio.h @@ -272,6 +272,7 @@ hwaddr virtio_queue_get_avail_size(VirtIODevice *vdev, int n); hwaddr virtio_queue_get_used_size(VirtIODevice *vdev, int n); uint16_t virtio_queue_get_last_avail_idx(VirtIODevice *vdev, int n); void virtio_queue_set_last_avail_idx(VirtIODevice *vdev, int n, uint16_t idx); +void virtio_queue_restore_last_avail_idx(VirtIODevice *vdev, int n); void virtio_queue_invalidate_signalled_used(VirtIODevice *vdev, int n); void virtio_queue_update_used_idx(VirtIODevice *vdev, int n); VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n);