Received: by 2002:a17:90a:88:0:0:0:0 with SMTP id a8csp4427282pja; Thu, 21 Nov 2019 19:10:49 -0800 (PST) X-Google-Smtp-Source: APXvYqxAVFC2/Jt2jSFTYShAdF/6nZTRC4bRlzaiXrDHXzqIaZuFbtMO8EpzOtQzTNRtkLP7pjK9 X-Received: by 2002:a17:907:1102:: with SMTP id qu2mr18669090ejb.300.1574392249181; Thu, 21 Nov 2019 19:10:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574392249; cv=none; d=google.com; s=arc-20160816; b=F2dlGjU+8luBbLtigY6FHO2o4+TjfvvSixFfcMXeD7QUqhp2MDAIH1G7t3A9T+4fPr hqAdMYlqxqdgeW72tJB6jrdp5btbiyWBpJb519ZukbtYis6hmBEdzRS7Pg8aVKYQYLLZ MGCxqcSiL+FB6q2Ne6mfYQ18klQZlbdCE9C7gWJE7DUTXUzIKcG6nn/jMN59fpsrxVZ1 Un+mutHQ6Nxj1rb7axEfAItok1xqwYWxwiMmbhNEXdYb2G/3GZ3nvYytR1BEbfPScA7t PPQcoRgpZ67X2nE7HLcPBCwS5pzTd9vzTjCzrttg8cTNPeAj1L1jgft7QkEovPjuWfQx 42yg== 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; bh=Ux/8dzbMHVUzhsftqz2qmXEPP/8xuGLlVapPbJBdRaU=; b=lqPRlm0W8ABChJ2rTIAJu7j6J5gYzCYk+VLVOwKkLUqqiNl0w/nTWjlg3N43C8iahm PuRXox6aHQiUXdYnTxDW12AcXBR0fG4cOK8XIZTn6rKVQkR8flMmMHCcgmv0AjBXvvAu dpW5h+ph2rVM2nPc5uK1TS3ilMh/MHTQ95dtIwDXTu/97twB2wEm4nd+HsCSusJ1gLFB MkxsgC9qcZ7zSmTGzLHDgn8Y0kV5f/KkscqK69bkqviIQI+N+74Vtgz6kVWZcPRfR+BJ zGBayeUvjHJIYtD7Tyy/Uog0bf/CjaDp8WzobAavl+ItPZcFpkG+ubMkj6ks4Qoqf1N8 Pyyg== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d23si1581102ejd.165.2019.11.21.19.10.21; Thu, 21 Nov 2019 19:10:49 -0800 (PST) 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726757AbfKVDI2 (ORCPT + 99 others); Thu, 21 Nov 2019 22:08:28 -0500 Received: from mga14.intel.com ([192.55.52.115]:53712 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726704AbfKVDIZ (ORCPT ); Thu, 21 Nov 2019 22:08:25 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Nov 2019 19:08:24 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,228,1571727600"; d="scan'208";a="232540444" Received: from allen-box.sh.intel.com ([10.239.159.136]) by fmsmga004.fm.intel.com with ESMTP; 21 Nov 2019 19:08:23 -0800 From: Lu Baolu To: Joerg Roedel Cc: David Woodhouse , ashok.raj@intel.com, jacob.jun.pan@linux.intel.com, kevin.tian@intel.com, Eric Auger , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org, Lu Baolu Subject: [PATCH 2/5] iommu/vt-d: Consolidate pasid cache invalidation Date: Fri, 22 Nov 2019 11:04:46 +0800 Message-Id: <20191122030449.28892-3-baolu.lu@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191122030449.28892-1-baolu.lu@linux.intel.com> References: <20191122030449.28892-1-baolu.lu@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Merge pasid cache invalidation into iommu->flush.pc_inv. Signed-off-by: Lu Baolu --- drivers/iommu/intel-iommu.c | 13 +++++++++++++ drivers/iommu/intel-pasid.c | 18 ++---------------- include/linux/intel-iommu.h | 3 +++ 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/drivers/iommu/intel-iommu.c b/drivers/iommu/intel-iommu.c index 59e4130161eb..283382584453 100644 --- a/drivers/iommu/intel-iommu.c +++ b/drivers/iommu/intel-iommu.c @@ -2994,6 +2994,18 @@ qi_flush_iotlb(struct intel_iommu *iommu, u16 did, u64 addr, qi_submit_sync(&desc, iommu); } +/* PASID cache invalidation */ +static void +qi_flush_pasid(struct intel_iommu *iommu, u16 did, u32 pasid, u64 granu) +{ + struct qi_desc desc = {.qw1 = 0, .qw2 = 0, .qw3 = 0}; + + desc.qw0 = QI_PC_PASID(pasid) | QI_PC_DID(did) | + QI_PC_GRAN(granu) | QI_PC_TYPE; + + qi_submit_sync(&desc, iommu); +} + static void intel_iommu_init_qi(struct intel_iommu *iommu) { /* @@ -3025,6 +3037,7 @@ static void intel_iommu_init_qi(struct intel_iommu *iommu) } else { iommu->flush.cc_inv = qi_flush_context; iommu->flush.iotlb_inv = qi_flush_iotlb; + iommu->flush.pc_inv = qi_flush_pasid; pr_info("%s: Using Queued invalidation\n", iommu->name); } } diff --git a/drivers/iommu/intel-pasid.c b/drivers/iommu/intel-pasid.c index 3cb569e76642..dd736f673603 100644 --- a/drivers/iommu/intel-pasid.c +++ b/drivers/iommu/intel-pasid.c @@ -359,20 +359,6 @@ pasid_set_flpm(struct pasid_entry *pe, u64 value) pasid_set_bits(&pe->val[2], GENMASK_ULL(3, 2), value << 2); } -static void -pasid_cache_invalidation_with_pasid(struct intel_iommu *iommu, - u16 did, int pasid) -{ - struct qi_desc desc; - - desc.qw0 = QI_PC_DID(did) | QI_PC_PASID_SEL | QI_PC_PASID(pasid); - desc.qw1 = 0; - desc.qw2 = 0; - desc.qw3 = 0; - - qi_submit_sync(&desc, iommu); -} - static void iotlb_invalidation_with_pasid(struct intel_iommu *iommu, u16 did, u32 pasid) { @@ -421,7 +407,7 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu, if (!ecap_coherent(iommu->ecap)) clflush_cache_range(pte, sizeof(*pte)); - pasid_cache_invalidation_with_pasid(iommu, did, pasid); + iommu->flush.pc_inv(iommu, did, pasid, QI_PC_GRAN_PSWD); iotlb_invalidation_with_pasid(iommu, did, pasid); /* Device IOTLB doesn't need to be flushed in caching mode. */ @@ -437,7 +423,7 @@ static void pasid_flush_caches(struct intel_iommu *iommu, clflush_cache_range(pte, sizeof(*pte)); if (cap_caching_mode(iommu->cap)) { - pasid_cache_invalidation_with_pasid(iommu, did, pasid); + iommu->flush.pc_inv(iommu, did, pasid, QI_PC_GRAN_PSWD); iotlb_invalidation_with_pasid(iommu, did, pasid); } else { iommu_flush_write_buffer(iommu); diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h index ac725a4ce1c1..c32ff2a7d958 100644 --- a/include/linux/intel-iommu.h +++ b/include/linux/intel-iommu.h @@ -344,6 +344,9 @@ enum { #define QI_PC_PASID(pasid) (((u64)pasid) << 32) #define QI_PC_DID(did) (((u64)did) << 16) #define QI_PC_GRAN(gran) (((u64)gran) << 4) +#define QI_PC_GRAN_DS 0 +#define QI_PC_GRAN_PSWD 1 +#define QI_PC_GRAN_GLOBAL 3 #define QI_PC_ALL_PASIDS (QI_PC_TYPE | QI_PC_GRAN(0)) #define QI_PC_PASID_SEL (QI_PC_TYPE | QI_PC_GRAN(1)) -- 2.17.1