From patchwork Tue Jul 21 19:44:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ashok Raj X-Patchwork-Id: 11676557 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4CE3C13B1 for ; Tue, 21 Jul 2020 19:44:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3C653207BB for ; Tue, 21 Jul 2020 19:44:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730929AbgGUTo0 (ORCPT ); Tue, 21 Jul 2020 15:44:26 -0400 Received: from mga05.intel.com ([192.55.52.43]:59805 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730250AbgGUTo0 (ORCPT ); Tue, 21 Jul 2020 15:44:26 -0400 IronPort-SDR: Et36MVXSNo2Pe1PHqxR9folC2OW/3NbidXbOwz4MjQHIIz35t98+C67eSbAvmPDJSDacy/cdh8 JjZGsB50KdtA== X-IronPort-AV: E=McAfee;i="6000,8403,9689"; a="235084359" X-IronPort-AV: E=Sophos;i="5.75,379,1589266800"; d="scan'208";a="235084359" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 21 Jul 2020 12:44:25 -0700 IronPort-SDR: LjU3Q2bNdiXBdGUjRgtcumpVhVHG2+Pn7mZ69Avb09AwR1PnNjOrmsKAOqmHOHlZ1Mqyk+jSut x0SwjbM3tfCQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,379,1589266800"; d="scan'208";a="327980667" Received: from otc-nc-03.jf.intel.com ([10.54.39.25]) by orsmga007.jf.intel.com with ESMTP; 21 Jul 2020 12:44:24 -0700 From: Ashok Raj To: linux-pci@vger.kernel.org, Bjorn Helgaas , Joerg Roedel Cc: Ashok Raj , stable@vger.kernel.org, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org Subject: [PATCH] PCI/ATS: PASID and PRI are only enumerated in PF devices. Date: Tue, 21 Jul 2020 12:44:20 -0700 Message-Id: <1595360660-213129-1-git-send-email-ashok.raj@intel.com> X-Mailer: git-send-email 2.7.4 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org PASID and PRI capabilities are only enumerated in PF devices. VF devices do not enumerate these capabilites. IOMMU drivers also need to enumerate them before enabling features in the IOMMU. Extending the same support as PASID feature discovery (pci_pasid_features) for PRI. Signed-off-by: Ashok Raj v2: Fixed build failure from lkp when CONFIG_PRI=n Almost all the PRI functions were called only when CONFIG_PASID is set. Except the new pci_pri_supported(). To: Bjorn Helgaas To: Joerg Roedel To: Lu Baolu Cc: stable@vger.kernel.org Cc: linux-pci@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Ashok Raj Cc: iommu@lists.linux-foundation.org --- drivers/iommu/intel/iommu.c | 2 +- drivers/pci/ats.c | 14 ++++++++++++++ include/linux/pci-ats.h | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/iommu.c b/drivers/iommu/intel/iommu.c index d759e7234e98..276452f5e6a7 100644 --- a/drivers/iommu/intel/iommu.c +++ b/drivers/iommu/intel/iommu.c @@ -2560,7 +2560,7 @@ static struct dmar_domain *dmar_insert_one_dev_info(struct intel_iommu *iommu, } if (info->ats_supported && ecap_prs(iommu->ecap) && - pci_find_ext_capability(pdev, PCI_EXT_CAP_ID_PRI)) + pci_pri_supported(pdev)) info->pri_supported = 1; } } diff --git a/drivers/pci/ats.c b/drivers/pci/ats.c index b761c1f72f67..ffb4de8c5a77 100644 --- a/drivers/pci/ats.c +++ b/drivers/pci/ats.c @@ -461,6 +461,20 @@ int pci_pasid_features(struct pci_dev *pdev) } EXPORT_SYMBOL_GPL(pci_pasid_features); +/** + * pci_pri_supported - Check if PRI is supported. + * @pdev: PCI device structure + * + * Returns false when no PRI capability is present. + * Returns true if PRI feature is supported and enabled + */ +bool pci_pri_supported(struct pci_dev *pdev) +{ + /* VFs share the PF PRI configuration */ + return !!(pci_physfn(pdev)->pri_cap); +} +EXPORT_SYMBOL_GPL(pci_pri_supported); + #define PASID_NUMBER_SHIFT 8 #define PASID_NUMBER_MASK (0x1f << PASID_NUMBER_SHIFT) /** diff --git a/include/linux/pci-ats.h b/include/linux/pci-ats.h index f75c307f346d..fc989295daf3 100644 --- a/include/linux/pci-ats.h +++ b/include/linux/pci-ats.h @@ -28,6 +28,10 @@ int pci_enable_pri(struct pci_dev *pdev, u32 reqs); void pci_disable_pri(struct pci_dev *pdev); int pci_reset_pri(struct pci_dev *pdev); int pci_prg_resp_pasid_required(struct pci_dev *pdev); +bool pci_pri_supported(struct pci_dev *pdev); +#else +bool pci_pri_supported(struct pci_dev *pdev) +{ return false; } #endif /* CONFIG_PCI_PRI */ #ifdef CONFIG_PCI_PASID