From patchwork Fri Oct 9 10:23:34 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joerg Roedel X-Patchwork-Id: 7360641 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 842469F32B for ; Fri, 9 Oct 2015 10:23:42 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 242222088D for ; Fri, 9 Oct 2015 10:23:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F38A220834 for ; Fri, 9 Oct 2015 10:23:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755944AbbJIKXi (ORCPT ); Fri, 9 Oct 2015 06:23:38 -0400 Received: from 8bytes.org ([81.169.241.247]:35961 "EHLO theia.8bytes.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753524AbbJIKXh (ORCPT ); Fri, 9 Oct 2015 06:23:37 -0400 Received: by theia.8bytes.org (Postfix, from userid 1000) id 3C4BC3C5; Fri, 9 Oct 2015 12:23:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=8bytes.org; s=mail-1; t=1444386216; bh=y/Ty9ILTk6gBgJDx/9YNkheJrZ/+7/9QgYNHPXzPOo0=; h=From:To:Cc:Subject:Date:From; b=orR5CEilBKUyXiKxiuQYCHb5glCAqrnW5zzlcLhqAjL/+1g51W38qHFE7gZfYuJkf IkyFahBNMRiV2k1Sn0y4Zzfl1MzdeSguthWtBINjLPT5qXLP/QRpHz/bGqZVcye/2X UiX1jUnHmyBQJiwK91FAt1/kaeHXo2zfbyAzG4ADQMvV/HY9INHufVG00VwTiTAyW8 N9sVhwWdSeBTUr+98R/+UtQe0Pht2ZIKXuQhYmuRGVk3k8FZ+eej3ZQGI/yPCqQEXm gZeLcG2rwrMLHMeqZO5lMMT9gF6aOm2HHyxYD+66MYcBtd7REo2xYzQvu7aDysK07E PRichwsEls3TQ== From: Joerg Roedel To: Bjorn Helgaas , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" Cc: x86@kernel.org, linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Joerg Roedel , Jiang Liu Subject: [PATCH] x86/PCI: Don't alloc pcibios-irq when MSI is enabled Date: Fri, 9 Oct 2015 12:23:34 +0200 Message-Id: <1444386214-26319-1-git-send-email-joro@8bytes.org> X-Mailer: git-send-email 1.9.1 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID,T_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 From: Joerg Roedel The pcibios-irq and MSI both use dev->irq to store the IRQ number. While the MSI code checks for that and frees the pcibios-irq before overwriting dev->irq, the pcibios_alloc_irq function does not. Usually this is not a problem, as the pcibios-irq is allocated before probe time of the device and the MSI irq is allocted from the drivers probe path. But there are PCI devices handled by the core kernel and not by a standard pci driver, like the AMD IOMMU for example. For the AMD IOMMU a normal pci device driver does not make sense, because a driver can be forcibly unbound from its device, which is not a good idea for an IOMMU. Nevertheless the PCI core code tries to match the PCI device implementing the AMD IOMMU against drivers, and allocates/frees a pcibios IRQ every time it tries out a new driver. This overwrites the dev->irq field set by pci_enable_msi() and sets it to 0 in the end (because the probe fails and the pcibios-irq is freed again). On suspend/resume this breaks the kernel, because the irq descriptor for irq 0 is NULL. Fix this by not allocating a pcibios-irq when MSI is already active. This also has the benefit, that a device claimed by the core kernel can not be probed by a pci driver later. Cc: Jiang Liu Reported-by: Borislav Petkov Signed-off-by: Joerg Roedel Reviewed-by: Thomas Gleixner --- arch/x86/pci/common.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/arch/x86/pci/common.c b/arch/x86/pci/common.c index dc78a4a..6254c06 100644 --- a/arch/x86/pci/common.c +++ b/arch/x86/pci/common.c @@ -675,6 +675,14 @@ int pcibios_add_device(struct pci_dev *dev) int pcibios_alloc_irq(struct pci_dev *dev) { + /* + * If the PCI device was already claimed by core code and has + * MSI enabled, probing of the pcibios irq will overwrite + * dev->irq. So bail out if MSI is already enabled. + */ + if (pci_dev_msi_enabled(dev)) + return -EBUSY; + return pcibios_enable_irq(dev); }