From patchwork Wed Nov 9 12:44:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Franciosi X-Patchwork-Id: 9419167 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 1ADF460512 for ; Wed, 9 Nov 2016 12:49:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A44D29210 for ; Wed, 9 Nov 2016 12:49:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1A0A29226; Wed, 9 Nov 2016 12:49:03 +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 8282129210 for ; Wed, 9 Nov 2016 12:49:03 +0000 (UTC) Received: from localhost ([::1]:39268 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4SJK-0007FI-RV for patchwork-qemu-devel@patchwork.kernel.org; Wed, 09 Nov 2016 07:49:02 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35699) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4SFF-00043u-7I for qemu-devel@nongnu.org; Wed, 09 Nov 2016 07:44:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1c4SFA-0003xo-SV for qemu-devel@nongnu.org; Wed, 09 Nov 2016 07:44:49 -0500 Received: from 206-15-90-246.static.twtelecom.net ([206.15.90.246]:35784 helo=felipe-franciosi.localdomain) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1c4SFA-0003xT-M9 for qemu-devel@nongnu.org; Wed, 09 Nov 2016 07:44:44 -0500 Received: by felipe-franciosi.localdomain (Postfix, from userid 500) id 927C11001A9; Wed, 9 Nov 2016 04:44:43 -0800 (PST) From: Felipe Franciosi To: Paolo Bonzini , Stefan Hajnoczi , "Michael S. Tsirkin" Date: Wed, 9 Nov 2016 04:44:36 -0800 Message-Id: <1478695476-19272-1-git-send-email-felipe@nutanix.com> X-Mailer: git-send-email 1.9.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 206.15.90.246 Subject: [Qemu-devel] [PATCH v2] vhost: Update 'ioeventfd_started' with host notifiers 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: "qemu-devel@nongnu.org" , Felipe Franciosi Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Following the recent refactor of virtio notfiers [1], more specifically the patch that uses virtio_bus_set_host_notifier [2] by default, core virtio code requires 'ioeventfd_started' to be set to true/false when the host notifiers are configured. Because not all vhost devices were update (eg. vhost-scsi) to use the new interface, this value is always set to false. When booting a guest with a vhost-scsi backend controller, SeaBIOS will initially configure the device which sets all notifiers. The guest will continue to boot fine until the kernel virtio-scsi driver reinitialises the device causing a stop followed by another start. Since ioeventfd_started was never set to true, the 'stop' operation triggered by virtio_bus_set_host_notifier() will not result in a call to virtio_pci_ioeventfd_assign(assign=false). This leaves the memory regions with stale notifiers and results on the next start triggering the following assertion: kvm_mem_ioeventfd_add: error adding ioeventfd: File exists Aborted This patch updates ioeventfd_started whenever the notifiers are set or cleared, fixing this issue. Signed-off-by: Felipe Franciosi [1] http://lists.nongnu.org/archive/html/qemu-devel/2016-10/msg07748.html [2] http://lists.nongnu.org/archive/html/qemu-devel/2016-10/msg07760.html Tested-by: Christian Borntraeger --- v1->v2: - Update ioeventfd_started in vhost_dev_enable/disable_notifiers() instead of vhost_scsi_start/stop(). - Reword the commit message accordingly. --- hw/virtio/vhost.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 131f164..1290963 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1205,6 +1205,7 @@ int vhost_dev_enable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev) goto fail_vq; } } + VIRTIO_BUS(qbus)->ioeventfd_started = true; return 0; fail_vq: @@ -1239,6 +1240,7 @@ void vhost_dev_disable_notifiers(struct vhost_dev *hdev, VirtIODevice *vdev) } assert (r >= 0); } + VIRTIO_BUS(qbus)->ioeventfd_started = false; virtio_device_start_ioeventfd(vdev); }