Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp578883ybt; Mon, 6 Jul 2020 17:10:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvckZQNBtrqaitHXgFAe3mQk15sBl3l2jT49Li8nQ+NMsiQDQGHpyyjTsh4/AyWwD4Tvax X-Received: by 2002:a17:906:84ef:: with SMTP id zp15mr40326857ejb.3.1594080601546; Mon, 06 Jul 2020 17:10:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1594080601; cv=none; d=google.com; s=arc-20160816; b=D1B6D9dtJ7KHcvb6d2+EqAx3ZQ9WaycV3G3vFydp5rfer2bNtveXod4uQeizvqjXGH ENeTcwe7AqtD1uud/tDppOJ5Lrxs6ry+8Uw/FPDx0m/67Q0KFJ/rWxrIxorBLzoFeays H3uA/AursKAEGw8b0HFTCb20bVWh0y60wky/3ZQEheRGuaxs9PQ8OgUxWxjujZeqWfay oagCJYq3cvinvQRyk0ZafXJSxeKbq9cvcROv3Xs2ex90tN9ZKfQaVMaQbdFFepltph5k pXIXh5SPVjgFPz4vhdVPpFdYlMUjP4C37idEcGyKtGAHZS/uvnIGZs15WcW+s7fqQrKk EGaQ== 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:ironport-sdr:ironport-sdr; bh=CZdXb2f+caeOetWFPX1gsAN3LWd27rD/x9UgnlkA45E=; b=kGxw6XYDeZrByPK4xcMXdVzsKc3DuuSox9VUoTCxIxKr8hJzMUAOjTNNVeQ9CgXGxj zGC/HNvFbg6zRr2MLic84Kx/v1yzThN2Tk7xyJV0UppHT2d039OCruT5ntgE1cUtA3K2 wEOtfUN1AQU43B/vHkvrOu4GIM7gHuRlcpZ1TsATDpOCBcKgz90A5aX0P9JWaOGty1Go m/GfdFjmK0bE1BrMMPRcwjybu2gBFv132Cxq8qdpqYxdQfwm4gnPhMHCSpHsD1iK4Fvh vBKZuTeuU3NfsPJ6SyImSgvsWdsk58XJgJUbBYg20W/hBXGTuWJ7P4XgMRsxJUuqWyAa TsBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id df18si14454728edb.501.2020.07.06.17.09.38; Mon, 06 Jul 2020 17:10:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726681AbgGGAGe (ORCPT + 99 others); Mon, 6 Jul 2020 20:06:34 -0400 Received: from mga07.intel.com ([134.134.136.100]:18975 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726729AbgGGAGV (ORCPT ); Mon, 6 Jul 2020 20:06:21 -0400 IronPort-SDR: wCUIVi4AvVTxK5xFURbWOOxWTeK6YBien92GZR4iK2+AYsRXQbNqFVwzejmHAgz+Iz6qVwOq4u CEVDSb1YqFsg== X-IronPort-AV: E=McAfee;i="6000,8403,9674"; a="212492289" X-IronPort-AV: E=Sophos;i="5.75,321,1589266800"; d="scan'208";a="212492289" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Jul 2020 17:06:17 -0700 IronPort-SDR: Vde5gJKB1M2vQl74Yv5UwhAujmpsR6aVp+INtk3C1PVUFtmyyzZdw9wdRvC+divgkgoFJc0atm lSavRQZjqNtQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,321,1589266800"; d="scan'208";a="456913817" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga005.jf.intel.com with ESMTP; 06 Jul 2020 17:06:17 -0700 From: Jacob Pan To: iommu@lists.linux-foundation.org, LKML , "Lu Baolu" , Joerg Roedel , David Woodhouse Cc: Yi Liu , "Tian, Kevin" , Raj Ashok , Eric Auger , Jacob Pan Subject: [PATCH v4 3/7] iommu/vt-d: Fix PASID devTLB invalidation Date: Mon, 6 Jul 2020 17:12:50 -0700 Message-Id: <1594080774-33413-4-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1594080774-33413-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1594080774-33413-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 DevTLB flush can be used for both DMA request with and without PASIDs. The former uses PASID#0 (RID2PASID), latter uses non-zero PASID for SVA usage. This patch adds a check for PASID value such that devTLB flush with PASID is used for SVA case. This is more efficient in that multiple PASIDs can be used by a single device, when tearing down a PASID entry we shall flush only the devTLB specific to a PASID. Fixes: 6f7db75e1c46 ("iommu/vt-d: Add second level page table") Acked-by: Lu Baolu Signed-off-by: Jacob Pan --- drivers/iommu/intel/pasid.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/iommu/intel/pasid.c b/drivers/iommu/intel/pasid.c index c81f0f17c6ba..fa0154cce537 100644 --- a/drivers/iommu/intel/pasid.c +++ b/drivers/iommu/intel/pasid.c @@ -486,7 +486,16 @@ devtlb_invalidation_with_pasid(struct intel_iommu *iommu, qdep = info->ats_qdep; pfsid = info->pfsid; - qi_flush_dev_iotlb(iommu, sid, pfsid, qdep, 0, 64 - VTD_PAGE_SHIFT); + /* + * When PASID 0 is used, it indicates RID2PASID(DMA request w/o PASID), + * devTLB flush w/o PASID should be used. For non-zero PASID under + * SVA usage, device could do DMA with multiple PASIDs. It is more + * efficient to flush devTLB specific to the PASID. + */ + if (pasid == PASID_RID2PASID) + qi_flush_dev_iotlb(iommu, sid, pfsid, qdep, 0, 64 - VTD_PAGE_SHIFT); + else + qi_flush_dev_iotlb_pasid(iommu, sid, pfsid, pasid, qdep, 0, 64 - VTD_PAGE_SHIFT); } void intel_pasid_tear_down_entry(struct intel_iommu *iommu, struct device *dev, -- 2.7.4