From patchwork Mon Mar 3 03:24:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 3750791 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id AB172BF13A for ; Mon, 3 Mar 2014 03:24:28 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ABF962038C for ; Mon, 3 Mar 2014 03:24:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B165220374 for ; Mon, 3 Mar 2014 03:24:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751984AbaCCDYT (ORCPT ); Sun, 2 Mar 2014 22:24:19 -0500 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 d03dlp03.boulder.ibm.com (9.17.202.179) by e37.co.us.ibm.com (192.168.1.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 2 Mar 2014 20:24:17 -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 Received: from shangw ([9.125.31.224]) by d03av01.boulder.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s233OEDQ027496; Sun, 2 Mar 2014 20:24:14 -0700 Received: by shangw (Postfix, from userid 1000) id C1D3730031A; Mon, 3 Mar 2014 11:24:03 +0800 (CST) From: Gavin Shan To: kvm@vger.kernel.org Cc: alex.williamson@redhat.com, benh@kernel.crashing.org, aik@ozlabs.ru, 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> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1393817042-13758-1-git-send-email-shangw@linux.vnet.ibm.com> References: <1393817042-13758-1-git-send-email-shangw@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14030303-7164-0000-0000-0000068C1CA3 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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) {