From nobody Mon Feb 9 20:34:21 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (208.118.235.17 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1517860555571665.5037091849316; Mon, 5 Feb 2018 11:55:55 -0800 (PST) Received: from localhost ([::1]:54946 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eimrg-0003bJ-7s for importer@patchew.org; Mon, 05 Feb 2018 14:55:44 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44889) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eimSS-0004eE-OR for qemu-devel@nongnu.org; Mon, 05 Feb 2018 14:29:42 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eimSR-000553-FH for qemu-devel@nongnu.org; Mon, 05 Feb 2018 14:29:40 -0500 Received: from mail-wm0-x244.google.com ([2a00:1450:400c:c09::244]:55659) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1eimSR-00054g-7n for qemu-devel@nongnu.org; Mon, 05 Feb 2018 14:29:39 -0500 Received: by mail-wm0-x244.google.com with SMTP id 143so28225646wma.5 for ; Mon, 05 Feb 2018 11:29:39 -0800 (PST) Received: from 640k.lan ([82.84.122.246]) by smtp.gmail.com with ESMTPSA id g8sm20029891wra.18.2018.02.05.11.29.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Feb 2018 11:29:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=62JDn1g3Yq8CJid9S66wLSXdmUGYN1Se6/uUtICu6gU=; b=MaPA6zwqZxCpqPN33s0MvRe5HGwN7c35uEo1HfvznlC1qHQ/KHc6V1fQoIDveiB5lH PZzS9tLHkCjVhY+opOc3IYdoIYT/o4VweJP59mu9tXUDqJ/BzP0GVzYd3ktRBORQrdxl GIrjCn/r5Vs5ziwzm9mMW60ATB3RKAiMdC4KAEOcf2+F2k1VYGrInxMkM4YADdlSrIDQ hmsN/bsKkI6zkJwr4onoJmKaKjf/GGvF9OMkzKHLgHZLneNvWRi5YypP1Fk9QZpNYqoO wyANSwNC122ax55uZ6HzkHGat7vpwPdW++lB/hAXSIacNUSwYdf4BSW/q1XhvoL6nKiK np2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=62JDn1g3Yq8CJid9S66wLSXdmUGYN1Se6/uUtICu6gU=; b=MB9OVBGESjisvA6vPmzNVTBy9CAUYhk5MFsqAScnlL7zEyhLYvQ0HFt6UzqN6UOPJu ByHxQxFfrxkG91XyZnq08243Lc12+6VBIIqvDjBDQ0udnKwfDqeL7wz/CZacadW0crlk lVgo+zy08v9em5h34k2+1EMq61Aw24QB7ryvxEz3na7bkE9kLxRUrw6P9zRuwiwlqRP6 AJNjTYIm88PSikpYOlModItHUE9LChJOcY805PQh3WGT9SgXS8L62SBu+u80TC8yNMQF QruDHnq2lP49nFdcDtQmLY33PNO9CZSy9dCOGbtzwW8SN403785s/Q8j+3Qz7K369o5L 8fww== X-Gm-Message-State: APf1xPAwnDRIwLTLLnbkZb+yPQ/MpWInLB8oDvQ9kOEXulil9hbC5+My pOdL1uJObHLuwSdS5nKGGzAOSCUj X-Google-Smtp-Source: AH8x226lLsUaR1c0QNwh8yhFWJlItfRZOoVjzZhn1XmW29MBbkeLF2VHFFzunz2P83sD7gljPM1eyA== X-Received: by 10.28.20.206 with SMTP id 197mr282508wmu.19.1517858977795; Mon, 05 Feb 2018 11:29:37 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 5 Feb 2018 20:28:42 +0100 Message-Id: <1517858941-5538-29-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1517858941-5538-1-git-send-email-pbonzini@redhat.com> References: <1517858941-5538-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::244 Subject: [Qemu-devel] [PULL 28/47] ivshmem: Improve MSI irqfd error handling 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: Ladi Prosek Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Ladi Prosek Adds a rollback path to ivshmem_enable_irqfd() and fixes ivshmem_disable_irqfd() to bail if irqfd has not been enabled. To reproduce, run: ivshmem-server -n 0 and QEMU with: -device ivshmem-doorbell,chardev=3Div -chardev socket,path=3D/tmp/ivshmem_socket,id=3Div then load, unload, and load again the Windows driver, at the time of writing available at: https://github.com/virtio-win/kvm-guest-drivers-windows/tree/master/ivshmem The issue is believed to have been masked by other guest drivers, notably Linux ones, not enabling MSI-X on the device. Signed-off-by: Ladi Prosek Reviewed-by: Markus Armbruster Message-Id: <20171211072110.9058-4-lprosek@redhat.com> Signed-off-by: Paolo Bonzini --- hw/misc/ivshmem.c | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/hw/misc/ivshmem.c b/hw/misc/ivshmem.c index 95e85e4..fe1d8d1 100644 --- a/hw/misc/ivshmem.c +++ b/hw/misc/ivshmem.c @@ -785,6 +785,20 @@ static int ivshmem_setup_interrupts(IVShmemState *s, E= rror **errp) return 0; } =20 +static void ivshmem_remove_kvm_msi_virq(IVShmemState *s, int vector) +{ + IVSHMEM_DPRINTF("ivshmem_remove_kvm_msi_virq vector:%d\n", vector); + + if (s->msi_vectors[vector].pdev =3D=3D NULL) { + return; + } + + /* it was cleaned when masked in the frontend. */ + kvm_irqchip_release_virq(kvm_state, s->msi_vectors[vector].virq); + + s->msi_vectors[vector].pdev =3D NULL; +} + static void ivshmem_enable_irqfd(IVShmemState *s) { PCIDevice *pdev =3D PCI_DEVICE(s); @@ -796,7 +810,7 @@ static void ivshmem_enable_irqfd(IVShmemState *s) ivshmem_add_kvm_msi_virq(s, i, &err); if (err) { error_report_err(err); - /* TODO do we need to handle the error? */ + goto undo; } } =20 @@ -805,21 +819,14 @@ static void ivshmem_enable_irqfd(IVShmemState *s) ivshmem_vector_mask, ivshmem_vector_poll)) { error_report("ivshmem: msix_set_vector_notifiers failed"); + goto undo; } -} + return; =20 -static void ivshmem_remove_kvm_msi_virq(IVShmemState *s, int vector) -{ - IVSHMEM_DPRINTF("ivshmem_remove_kvm_msi_virq vector:%d\n", vector); - - if (s->msi_vectors[vector].pdev =3D=3D NULL) { - return; +undo: + while (--i >=3D 0) { + ivshmem_remove_kvm_msi_virq(s, i); } - - /* it was cleaned when masked in the frontend. */ - kvm_irqchip_release_virq(kvm_state, s->msi_vectors[vector].virq); - - s->msi_vectors[vector].pdev =3D NULL; } =20 static void ivshmem_disable_irqfd(IVShmemState *s) @@ -827,6 +834,10 @@ static void ivshmem_disable_irqfd(IVShmemState *s) PCIDevice *pdev =3D PCI_DEVICE(s); int i; =20 + if (!pdev->msix_vector_use_notifier) { + return; + } + msix_unset_vector_notifiers(pdev); =20 for (i =3D 0; i < s->peers[s->vm_id].nb_eventfds; i++) { --=20 1.8.3.1