From patchwork Thu Dec 14 02:21:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: cao.zou@windriver.com X-Patchwork-Id: 10111351 X-Patchwork-Delegate: bhelgaas@google.com 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 BF57D60352 for ; Thu, 14 Dec 2017 02:22:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B10A929A79 for ; Thu, 14 Dec 2017 02:22:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A581729A8E; Thu, 14 Dec 2017 02:22:27 +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 vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B85E29A79 for ; Thu, 14 Dec 2017 02:22:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751952AbdLNCWY (ORCPT ); Wed, 13 Dec 2017 21:22:24 -0500 Received: from mail1.windriver.com ([147.11.146.13]:50282 "EHLO mail1.windriver.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751101AbdLNCWW (ORCPT ); Wed, 13 Dec 2017 21:22:22 -0500 Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail1.windriver.com (8.15.2/8.15.1) with ESMTPS id vBE2MHiw001525 (version=TLSv1 cipher=AES128-SHA bits=128 verify=FAIL); Wed, 13 Dec 2017 18:22:17 -0800 (PST) Received: from pek-czou-u14.wrs.com (128.224.162.234) by ALA-HCA.corp.ad.wrs.com (147.11.189.40) with Microsoft SMTP Server id 14.3.361.1; Wed, 13 Dec 2017 18:22:17 -0800 From: To: CC: , , , Subject: [PATCH] PCI: designware: add a check of msi_desc in irqchip Date: Thu, 14 Dec 2017 10:21:23 +0800 Message-ID: <1513218083-5461-2-git-send-email-cao.zou@windriver.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1513218083-5461-1-git-send-email-cao.zou@windriver.com> References: <1513218083-5461-1-git-send-email-cao.zou@windriver.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Zou Cao When PCIE host setup, 32 MSI irq descriptions are created, but its msi_desc is NULL, msi_desc is bound in MSI irq requested by PCI device, normally just part of MSI are used, for others not used MSI irqs, its msi_desc is NULL, it is dangerous for MSI irq mask when MSI irq mask use the msi_desc to mask irq without checking, normally not used MSI irqs are never masked, it looks fine, but in some specified case, such as kdump, machine_kexec_mask_interrupts will force to mask these not used MSI irqs, than a crash will happen with NULL msi_desc. it is necessary to add check of msi_desc in irqchip, if we still bind the msi_desc only in irqs request and mask MSI irq by msi_desc. Add dwc_pci_msi_mask/unmask_irq, so we can get a chance to check the msi_desc. here is reproduced crash log in IMX7-SABER board with Intel 1030 PCI, when running kdump by "echo c > /proc/sysrq-trigger": sysrq: SysRq : Trigger a crash Unable to handle kernel NULL pointer dereference at virtual address 00000000 pgd = 98ee1839 [00000000] *pgd=00000000 Internal error: Oops: 805 [#1] SMP ARM Modules linked in: CPU: 0 PID: 1370 Comm: sh Not tainted 4.15.0-rc3-00033-ga638349 #1 Hardware name: Freescale i.MX7 Dual (Device Tree) PC is at sysrq_handle_crash+0x50/0x98 LR is at sysrq_handle_crash+0x50/0x98 Backtrace: [] (msi_set_mask_bit) from [] (pci_msi_mask_irq+0x14/0x18) [] (pci_msi_mask_irq) from [] (machine_crash_shutdown+0xd8/0x190) [] (machine_crash_shutdown) from [] (__crash_kexec+0x5c/0xa0) [] (__crash_kexec) from [] (crash_kexec+0x74/0x80) [] (crash_kexec) from [] (die+0x220/0x358) [] (die) from [] (__do_kernel_fault.part.0+0x5c/0x7c) [] (__do_kernel_fault.part.0) from [] (do_page_fault+0x2cc/0x37c) [] (do_page_fault) from [] (do_translation_fault+0xb0/0xbc) [] (do_translation_fault) from [] (do_DataAbort+0x3c/0xbc) [] (do_DataAbort) from [] (__dabt_svc+0x64/0xa0) Exception stack(0xec08bdf8 to 0xec08be40) bde0: 00000000 ec08be10 be00: 00000000 00000000 00000000 00000001 00000063 00000000 00000007 ec08a000 be20: 00000000 ec08be5c ec08be48 ec08be48 c04c46b8 c04c46b8 60060013 ffffffff [] (sysrq_handle_crash) from [] (__handle_sysrq+0xe0/0x254) [] (__handle_sysrq) from [] (write_sysrq_trigger+0x78/0x90) [] (write_sysrq_trigger) from [] (proc_reg_write+0x68/0x90) [] (proc_reg_write) from [] (__vfs_write+0x34/0x12c) [] (__vfs_write) from [] (vfs_write+0xa8/0x16c) [] (vfs_write) from [] (SyS_write+0x44/0x90) [] (SyS_write) from [] (ret_fast_syscall+0x0/0x28) Signed-off-by: Zou Cao --- drivers/pci/dwc/pcie-designware-host.c | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/drivers/pci/dwc/pcie-designware-host.c b/drivers/pci/dwc/pcie-designware-host.c index 81e2157..485c4df 100644 --- a/drivers/pci/dwc/pcie-designware-host.c +++ b/drivers/pci/dwc/pcie-designware-host.c @@ -45,12 +45,28 @@ static int dw_pcie_wr_own_conf(struct pcie_port *pp, int where, int size, return dw_pcie_write(pci->dbi_base + where, size, val); } +static void dwc_pci_msi_mask_irq(struct irq_data *data) +{ + struct msi_desc *desc = irq_data_get_msi_desc(data); + + if (desc) + pci_msi_mask_irq(data); +} + +static void dwc_pci_msi_unmask_irq(struct irq_data *data) +{ + struct msi_desc *desc = irq_data_get_msi_desc(data); + + if (desc) + pci_msi_unmask_irq(data); +} + static struct irq_chip dw_msi_irq_chip = { .name = "PCI-MSI", - .irq_enable = pci_msi_unmask_irq, - .irq_disable = pci_msi_mask_irq, - .irq_mask = pci_msi_mask_irq, - .irq_unmask = pci_msi_unmask_irq, + .irq_enable = dwc_pci_msi_unmask_irq, + .irq_disable = dwc_pci_msi_mask_irq, + .irq_mask = dwc_pci_msi_mask_irq, + .irq_unmask = dwc_pci_msi_unmask_irq, }; /* MSI int handler */