From patchwork Thu May 25 21:32:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Piotr Gregor X-Patchwork-Id: 9749197 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 97F3660209 for ; Thu, 25 May 2017 21:35:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 89487283BD for ; Thu, 25 May 2017 21:35:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7DDE2283CE; Thu, 25 May 2017 21:35:34 +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.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=unavailable 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 04B56283BD for ; Thu, 25 May 2017 21:35:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S966238AbdEYVfV (ORCPT ); Thu, 25 May 2017 17:35:21 -0400 Received: from mail-wm0-f46.google.com ([74.125.82.46]:35551 "EHLO mail-wm0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760518AbdEYVfS (ORCPT ); Thu, 25 May 2017 17:35:18 -0400 Received: by mail-wm0-f46.google.com with SMTP id b84so108027505wmh.0 for ; Thu, 25 May 2017 14:35:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rsyncme-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=/6fFgLZkts9m6mHoeuXS09kqSSVHRI75K/IuxmQ5Sb4=; b=aPh6Bp2e+G8nRdX9izPpkVH+V+FXOPnPtOYx3Ijqaj88rMaPgQ1rzdGii8yNUpzb8D WdZfis6uQi79HNiRYBLHBdEU+HAMQZ+yt1uuTDx1YLPwX6GsojYp1Hc4DGgGmeUkW9Yj swZR4VA11kO1vB0os0k3+MHiq3RJm38ZTjn8gq7OrRnS9l6OC72Y/NLQni6mGVfxB4FE DkxT3I0YQGfxZbpn1wOtn+TKCtJME0iNAdk9NTYLeC//fqHkVMqtj99AslweRogV7nnr 3ELys05PKN4cHODOFhSrQcecuLTbxwaWS+Uk73N9ULq9wscyPXtHIKoEO3lX2gTYAQFc Vf0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=/6fFgLZkts9m6mHoeuXS09kqSSVHRI75K/IuxmQ5Sb4=; b=Zltddjy//dv5H4TLyC4xuM/xk4Nfu8mJdkKwvJZAIVAQjI7z5ifbn2C7fRJPHB/fGZ Fgpo01/CMMuqbMNxrHkIhnA5ZwVyjfptL+jqMCF1WyLM45tX8Jqv9rmsVnLjalUZbWay AKtGrwpyXOJUc5gGtmIrYqqP1oILMN0V6kuQUrg+RCz0/ftA+o3LxkL5wMFPyeNuGs1+ NfWj2/9BB12+QUbqeA2kqIpz9LhbRmKRiscmRdT18MFT0QKcYsDaOaU8TeePIDi75Pax v8L5GOhQBE2OY2H6padvFv+w2kAu4MGac6l8iaZ74g6gLqdWu4lZlr1xH51Dt4fUKy/I rcqw== X-Gm-Message-State: AODbwcDLEfFZQDray9MgB/MzcH+7N5n58KRSAs65AlAZWYuM7yj51K87 9cl5AySYwPP0rRIw X-Received: by 10.223.136.165 with SMTP id f34mr9371369wrf.134.1495748116927; Thu, 25 May 2017 14:35:16 -0700 (PDT) Received: from westernst (host86-153-196-174.range86-153.btcentralplus.com. [86.153.196.174]) by smtp.gmail.com with ESMTPSA id v52sm10346683wrc.53.2017.05.25.14.35.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 25 May 2017 14:35:16 -0700 (PDT) Date: Thu, 25 May 2017 22:32:25 +0100 From: Piotr Gregor To: Bjorn Helgaas Cc: "Michael S. Tsirkin" , GregKroah-Hartman , Alex Williamson , Neo Jia , Kirti Wankhede , Vlad Tsyrklevich , Arvind Yadav , Yongji Xie , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, kvm@vger.kernel.org Subject: [PATCH] PCI: Move test of INTx masking to pci_setup_device Message-ID: <20170525213222.GA27295@westernst> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) 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 The test for INTx masking via config space command performed in pci_intx_mask_supported should be performed before PCI device can be used. This is to avoid reading/writing of PCI_COMMAND_INTX_DISABLE register which may collide with MSI/MSI-X interrupts. This patch moves test performed in pci_intx_mask_supported to __pci_intx_mask_supported and unexports the former. The result of INTx masking test is saved in broken_intx_masking field of struct pci_dev (which now has extended meaning: if true then the test has failed or the feature is not supported). The __pci_intx_mask_supported test is moved to pci_setup_device. The result can be queried at any time later from the pci_dev using same interface as before (though whith changed implementation) static inline bool pci_intx_mask_supported(struct pci_dev *pdev) { /* * INTx masking is supported if device passed INTx test * and it's INTx masking feature works properly. */ return !pdev->broken_intx_masking; } so current users of pci_intx_mask_supported: uio and vfio, keep their code unchanged. Signed-off-by: Piotr Gregor --- drivers/pci/pci.c | 45 ++++++++++++++++++++++++--------------------- drivers/pci/probe.c | 3 +++ include/linux/pci.h | 13 +++++++++++-- 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index b01bd5b..8d5628e 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -3709,44 +3709,47 @@ void pci_intx(struct pci_dev *pdev, int enable) EXPORT_SYMBOL_GPL(pci_intx); /** - * pci_intx_mask_supported - probe for INTx masking support + * pci_intx_mask_supported - probe for INTx masking support in pci_setup_device * @dev: the PCI device to operate on * - * Check if the device dev support INTx masking via the config space - * command word. + * Check if the device dev supports INTx masking via the config space + * command word. Executed when PCI device is setup. Result is saved + * in broken_intx_masking field of pci_dev and can be checked + * with pci_intx_mask_supported after PCI device has been setup + * (avoids testing of PCI_COMMAND_INTX_DISABLE register at runtime). */ -bool pci_intx_mask_supported(struct pci_dev *dev) +bool __pci_intx_mask_supported(struct pci_dev *dev) { - bool mask_supported = false; - u16 orig, new; + u16 orig, toggle, new; + /* + * If device doesn't support this feature though it could pass the test. + */ if (dev->broken_intx_masking) return false; pci_cfg_access_lock(dev); + /* + * Perform the test. + */ pci_read_config_word(dev, PCI_COMMAND, &orig); - pci_write_config_word(dev, PCI_COMMAND, - orig ^ PCI_COMMAND_INTX_DISABLE); + toggle = orig ^ PCI_COMMAND_INTX_DISABLE; + pci_write_config_word(dev, PCI_COMMAND, toggle); pci_read_config_word(dev, PCI_COMMAND, &new); /* - * There's no way to protect against hardware bugs or detect them - * reliably, but as long as we know what the value should be, let's - * go ahead and check it. + * Restore initial state. */ - if ((new ^ orig) & ~PCI_COMMAND_INTX_DISABLE) { - dev_err(&dev->dev, "Command register changed from 0x%x to 0x%x: driver or hardware bug?\n", - orig, new); - } else if ((new ^ orig) & PCI_COMMAND_INTX_DISABLE) { - mask_supported = true; - pci_write_config_word(dev, PCI_COMMAND, orig); - } + pci_write_config_word(dev, PCI_COMMAND, orig); pci_cfg_access_unlock(dev); - return mask_supported; + + if (new == toggle) + return true; + + return false; } -EXPORT_SYMBOL_GPL(pci_intx_mask_supported); static bool pci_check_and_set_intx_mask(struct pci_dev *dev, bool mask) { @@ -3798,7 +3801,7 @@ static bool pci_check_and_set_intx_mask(struct pci_dev *dev, bool mask) * @dev: the PCI device to operate on * * Check if the device dev has its INTx line asserted, mask it and - * return true in that case. False is returned if not interrupt was + * return true in that case. False is returned if no interrupt was * pending. */ bool pci_check_and_mask_intx(struct pci_dev *dev) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 19c8950..b343b14 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1399,6 +1399,9 @@ int pci_setup_device(struct pci_dev *dev) } } + if (!dev->broken_intx_masking && !__pci_intx_mask_supported(dev)) + dev->broken_intx_masking = 1; + switch (dev->hdr_type) { /* header type */ case PCI_HEADER_TYPE_NORMAL: /* standard header */ if (class == PCI_CLASS_BRIDGE_PCI) diff --git a/include/linux/pci.h b/include/linux/pci.h index 33c2b0b..58c6fe3 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -366,7 +366,7 @@ struct pci_dev { unsigned int is_thunderbolt:1; /* Thunderbolt controller */ unsigned int __aer_firmware_first_valid:1; unsigned int __aer_firmware_first:1; - unsigned int broken_intx_masking:1; + unsigned int broken_intx_masking:1; /* INTx masking can't be used */ unsigned int io_window_1k:1; /* Intel P2P bridge 1K I/O windows */ unsigned int irq_managed:1; unsigned int has_secondary_link:1; @@ -1003,6 +1003,15 @@ int __must_check pci_reenable_device(struct pci_dev *); int __must_check pcim_enable_device(struct pci_dev *pdev); void pcim_pin_device(struct pci_dev *pdev); +static inline bool pci_intx_mask_supported(struct pci_dev *pdev) +{ + /* + * INTx masking is supported if device passed INTx test and it's INTx + * masking feature works properly. + */ + return !pdev->broken_intx_masking; +} + static inline int pci_is_enabled(struct pci_dev *pdev) { return (atomic_read(&pdev->enable_cnt) > 0); @@ -1026,7 +1035,7 @@ int __must_check pci_set_mwi(struct pci_dev *dev); int pci_try_set_mwi(struct pci_dev *dev); void pci_clear_mwi(struct pci_dev *dev); void pci_intx(struct pci_dev *dev, int enable); -bool pci_intx_mask_supported(struct pci_dev *dev); +bool __pci_intx_mask_supported(struct pci_dev *dev); bool pci_check_and_mask_intx(struct pci_dev *dev); bool pci_check_and_unmask_intx(struct pci_dev *dev); int pci_wait_for_pending(struct pci_dev *dev, int pos, u16 mask);