Received: by 10.192.165.156 with SMTP id m28csp1132665imm; Mon, 16 Apr 2018 14:49:08 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/rxTVmIsG9IU8aCI7nyyI+NgRFOrBnPlTn22XJZtK6r6Ru0Ua4pbxtfY1CHAy469R+XxV4 X-Received: by 2002:a17:902:22a:: with SMTP id 39-v6mr17070099plc.128.1523915348934; Mon, 16 Apr 2018 14:49:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523915348; cv=none; d=google.com; s=arc-20160816; b=lF6EMIvd8exDsydrGAjDJY2TK8xNgaMRAYgQrQmdHGKdqLlwpSJSy47Ktzs0MsNUp2 lGBXCu14KZiDKQnDqp7hlDV3OTpb0YqNdCaKuOXsT7nm7MoXDDgyeY986XMu6YnRYovT PwJxGBSyaYhh4t9CStu4LertQXpgX8IjSRUL0rbg44DgKnkL+qw6KiB/c2w4Etfpv+I9 /nQoUlxorM9/UCIwUR3zkTADzAeHYN1B2zACteiRVoyeLg1iID0UVp3LQUHrX8fCNEcU FYH2XkneVyOOEkgYNlijCu59NWYprN4tMq1rV1ZlZYYOSEQAf9lReiUJwxDqXrgFE9Yf E6rA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=4dnTpTRcY9LnX11gphWi5M6lLS35Ibd6O4cA3fmFPpU=; b=dSLf2H/4Sk5137fXsJrNXDJgBSXiIQMHWyKq/C6F1t17iDHy+MbGUJrD27vD3aZZB3 23/F0hKQxR9MTtZkGEh14meTpuWAJP8GAeJthNZx2JnKTlHFrepgYP/p1SsekheO/DMC p0+yJUorbmo1GXB7zCAW/fNwTJSSG1cEESwPhflHiu3PZ1JJgjOtBydV5HszlKiedzgV oJFpbRVKtOt0sEyJm8Cf9sjDeEi4hjKARIYhLMIfA/lgLCQcBuv/aXbxoHOL5PU3GxcK Cxq2TsK9obSNym8pjbsGlnmG1H7I0l4QK3gmCtrSt2eOsIwyEdFOT9XOBQYDRbtD5S+t VVng== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a15si11128226pff.107.2018.04.16.14.48.54; Mon, 16 Apr 2018 14:49:08 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753071AbeDPVqw (ORCPT + 99 others); Mon, 16 Apr 2018 17:46:52 -0400 Received: from mga09.intel.com ([134.134.136.24]:12291 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751110AbeDPVqp (ORCPT ); Mon, 16 Apr 2018 17:46:45 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Apr 2018 14:46:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.48,460,1517904000"; d="scan'208";a="34740154" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga006.jf.intel.com with ESMTP; 16 Apr 2018 14:46:42 -0700 From: Jacob Pan To: iommu@lists.linux-foundation.org, LKML , Joerg Roedel , David Woodhouse , Greg Kroah-Hartman , Alex Williamson , Jean-Philippe Brucker Cc: Rafael Wysocki , "Liu, Yi L" , "Tian, Kevin" , Raj Ashok , Jean Delvare , "Christoph Hellwig" , "Lu Baolu" , Jacob Pan Subject: [PATCH v4 07/22] iommu/vt-d: fix dev iotlb pfsid use Date: Mon, 16 Apr 2018 14:48:56 -0700 Message-Id: <1523915351-54415-8-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523915351-54415-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1523915351-54415-1-git-send-email-jacob.jun.pan@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org PFSID should be used in the invalidation descriptor for flushing device IOTLBs on SRIOV VFs. Signed-off-by: Jacob Pan --- drivers/iommu/dmar.c | 6 +++--- drivers/iommu/intel-iommu.c | 16 +++++++++++++++- include/linux/intel-iommu.h | 5 ++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c index accf5838..38bb90f 100644 --- a/drivers/iommu/dmar.c +++ b/drivers/iommu/dmar.c @@ -1339,8 +1339,8 @@ void qi_flush_iotlb(struct intel_iommu *iommu, u16 did, u64 addr, qi_submit_sync(&desc, iommu); } -void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 qdep, - u64 addr, unsigned mask) +void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 pfsid, + u16 qdep, u64 addr, unsigned mask) { struct qi_desc desc; @@ -1355,7 +1355,7 @@ void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 qdep, qdep = 0; desc.low = QI_DEV_IOTLB_SID(sid) | QI_DEV_IOTLB_QDEP(qdep) | - QI_DIOTLB_TYPE; + QI_DIOTLB_TYPE | QI_DEV_IOTLB_PFSID(pfsid); qi_submit_sync(&desc, iommu); } diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index d8058be..cae4042 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -1459,6 +1459,19 @@ static void iommu_enable_dev_iotlb(struct device_domain_info *info) return; pdev = to_pci_dev(info->dev); + /* For IOMMU that supports device IOTLB throttling (DIT), we assign + * PFSID to the invalidation desc of a VF such that IOMMU HW can gauge + * queue depth at PF level. If DIT is not set, PFSID will be treated as + * reserved, which should be set to 0. + */ + if (!ecap_dit(info->iommu->ecap)) + info->pfsid = 0; + else if (pdev && pdev->is_virtfn) { + if (ecap_dit(info->iommu->ecap)) + dev_warn(&pdev->dev, "SRIOV VF device IOTLB enabled without flow control\n"); + info->pfsid = PCI_DEVID(pdev->physfn->bus->number, pdev->physfn->devfn); + } else + info->pfsid = PCI_DEVID(info->bus, info->devfn); #ifdef CONFIG_INTEL_IOMMU_SVM /* The PCIe spec, in its wisdom, declares that the behaviour of @@ -1524,7 +1537,8 @@ static void iommu_flush_dev_iotlb(struct dmar_domain *domain, sid = info->bus << 8 | info->devfn; qdep = info->ats_qdep; - qi_flush_dev_iotlb(info->iommu, sid, qdep, addr, mask); + qi_flush_dev_iotlb(info->iommu, sid, info->pfsid, + qdep, addr, mask); } spin_unlock_irqrestore(&device_domain_lock, flags); } diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index dfacd49..678a0f4 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -504,9 +504,8 @@ extern void qi_flush_context(struct intel_iommu *iommu, u16 did, u16 sid, u8 fm, u64 type); extern void qi_flush_iotlb(struct intel_iommu *iommu, u16 did, u64 addr, unsigned int size_order, u64 type); -extern void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 qdep, - u64 addr, unsigned mask); - +extern void qi_flush_dev_iotlb(struct intel_iommu *iommu, u16 sid, u16 pfsid, + u16 qdep, u64 addr, unsigned mask); extern int qi_submit_sync(struct qi_desc *desc, struct intel_iommu *iommu); extern int dmar_ir_support(void); -- 2.7.4