From mboxrd@z Thu Jan 1 00:00:00 1970 From: Gavin Shan Subject: [PATCH 3/3] drivers/vfio/pci: Fix MSIx message lost Date: Mon, 3 Mar 2014 11:24:02 +0800 Message-ID: <1393817042-13758-3-git-send-email-shangw@linux.vnet.ibm.com> References: <1393817042-13758-1-git-send-email-shangw@linux.vnet.ibm.com> Cc: alex.williamson@redhat.com, benh@kernel.crashing.org, aik@ozlabs.ru, Gavin Shan To: kvm@vger.kernel.org Return-path: Received: from e37.co.us.ibm.com ([32.97.110.158]:55140 "EHLO e37.co.us.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751452AbaCCDYS (ORCPT ); Sun, 2 Mar 2014 22:24:18 -0500 Received: from /spool/local by e37.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 2 Mar 2014 20:24:18 -0700 Received: from b03cxnp08026.gho.boulder.ibm.com (b03cxnp08026.gho.boulder.ibm.com [9.17.130.18]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id 0C75E19D8036 for ; Sun, 2 Mar 2014 20:24:14 -0700 (MST) Received: from d03av01.boulder.ibm.com (d03av01.boulder.ibm.com [9.17.195.167]) by b03cxnp08026.gho.boulder.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s233Nmt756885418 for ; Mon, 3 Mar 2014 04:23:48 +0100 Received: from d03av01.boulder.ibm.com (localhost [127.0.0.1]) by d03av01.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s233OFCc027550 for ; Sun, 2 Mar 2014 20:24:15 -0700 In-Reply-To: <1393817042-13758-1-git-send-email-shangw@linux.vnet.ibm.com> Sender: kvm-owner@vger.kernel.org List-ID: The problem is specific to the case of BIST issued applied to IPR adapter on the guest side. After BIST reset, we lose everything in MSIx table and we never have chance update MSIx messages for those enabled interrupts to MSIx table. The patch fixes it by writing MSIx message to MSIx table before reenabling them. Reported-by: Wen Xiong Signed-off-by: Gavin Shan --- drivers/vfio/pci/vfio_pci_intrs.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c index 2103576..279ebd0 100644 --- a/drivers/vfio/pci/vfio_pci_intrs.c +++ b/drivers/vfio/pci/vfio_pci_intrs.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -517,6 +518,7 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev, struct pci_dev *pdev = vdev->pdev; int irq = msix ? vdev->msix[vector].vector : pdev->irq + vector; char *name = msix ? "vfio-msix" : "vfio-msi"; + struct msi_msg msg; struct eventfd_ctx *trigger; int ret; @@ -544,6 +546,23 @@ static int vfio_msi_set_vector_signal(struct vfio_pci_device *vdev, return PTR_ERR(trigger); } + /* We possiblly lose the MSI/MSIx message in some cases. + * For example, BIST reset on IPR adapter. The MSIx table + * is cleaned out. However, we never get chance to put + * MSIx messages to MSIx table because all MSIx stuff is + * being cached in QEMU. Here, we had the trick to put the + * MSI/MSIx message back. + * + * Basically, we needn't worry about MSI messages. However, + * it's not harmful and there might be cases of PCI config data + * lost because of cached PCI config data in QEMU again. + * + * Note that we should flash the message prior to enabling + * the corresponding interrupt by request_irq(). + */ + get_cached_msi_msg(irq, &msg); + write_msi_msg(irq, &msg); + ret = request_irq(irq, vfio_msihandler, 0, vdev->ctx[vector].name, trigger); if (ret) { -- 1.7.10.4