Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1078464yba; Fri, 3 May 2019 15:45:01 -0700 (PDT) X-Google-Smtp-Source: APXvYqy4eNvILmemTYuxIDypJ5zsvo1QIvbrcP3AEz8Odz4LI7wjm56qV5mZ/Ho7on66F6BKkkfo X-Received: by 2002:a63:dd10:: with SMTP id t16mr14066606pgg.446.1556923501575; Fri, 03 May 2019 15:45:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1556923501; cv=none; d=google.com; s=arc-20160816; b=0L84/hxtagnRwNfyIMTfpP0rG6gQLUJrXvNJ3FnDDNOVoHkgIZh3fEEltYNjr6JP5j CLP1NVJ5wdbzAyx0hqRuZzhdFIYoaNonuJQsqT0JXMcCLwNAzk3OKQynHYyJcBO/b7KF eePr5f5SKbtQCRmpvh8EFOx6UDUbbqK1NftxqQAekVAm6FHAED46uTfRijAPLK52LwRe Vh4gm4L49wBvMDCEJUYnCrTa51otP7mOEWlBV9PCi+yN7fdk8p+rXWaIJT7eHypV62i5 cgXPsBtbQ0+jpSeYoRy+UdUvmqO+gtyVeBbxtNNFnzSXoZ+iE6QS4eNpbpDh6yZpk6Nf fSOA== 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=fHwD9o7bEdQrW7RZzno8wz1Eb2QT9LN01vJxoRDI3Dg=; b=sNVThu+s8KhOGvdoBZsDBkefVfroIZKKvEfnej4d/ywy20bDDISyghWmu0aC0qC9pU saL1T24TDBXRVG9PRtM30yTtqQpHxuSLb2NDVRiRNDHpUXp4LRt828zZfcxp6do7k20e CkdRVn+G+ON3UcQQ2rVUsZEOdde1EEZNCKemWl02nocqIYKZLLoFb+YNJUBOKaHtjnIo spUeHXFkd1vaWQEJ+kpLwlGGuJ3B1bvitvokNhCrotY0by0foOUJDAVSEaKsxIzcRS5D tRuQPyk0X2BCe5ky53cFwApW52ifyZ9iOfqzAk/Sa7NuODYOugjh9kRDIXIaPeUiBwrm 4QgA== 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 w1si3650099pgh.109.2019.05.03.15.44.46; Fri, 03 May 2019 15:45:01 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727079AbfECW3q (ORCPT + 99 others); Fri, 3 May 2019 18:29:46 -0400 Received: from mga02.intel.com ([134.134.136.20]:7005 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726791AbfECW3f (ORCPT ); Fri, 3 May 2019 18:29:35 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 03 May 2019 15:29:33 -0700 X-ExtLoop1: 1 Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga002.jf.intel.com with ESMTP; 03 May 2019 15:29:33 -0700 From: Jacob Pan To: iommu@lists.linux-foundation.org, LKML , Joerg Roedel , David Woodhouse , Eric Auger , Alex Williamson , Jean-Philippe Brucker Cc: "Yi Liu" , "Tian, Kevin" , Raj Ashok , "Christoph Hellwig" , "Lu Baolu" , Andriy Shevchenko , Jacob Pan Subject: [PATCH v3 11/16] iommu/vt-d: Avoid duplicated code for PASID setup Date: Fri, 3 May 2019 15:32:12 -0700 Message-Id: <1556922737-76313-12-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1556922737-76313-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1556922737-76313-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 After each setup for PASID entry, related translation caches must be flushed. We can combine duplicated code into one function which is less error prone. Signed-off-by: Jacob Pan --- drivers/iommu/intel-pasid.c | 48 +++++++++++++++++---------------------------- 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/drivers/iommu/intel-pasid.c b/drivers/iommu/intel-pasid.c index 2ce6ac2..dde05b5 100644 --- a/drivers/iommu/intel-pasid.c +++ b/drivers/iommu/intel-pasid.c @@ -520,6 +520,21 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu, devtlb_invalidation_with_pasid(iommu, dev, pasid); } +static inline void pasid_flush_caches(struct intel_iommu *iommu, + struct pasid_entry *pte, + int pasid, u16 did) +{ + if (!ecap_coherent(iommu->ecap)) + clflush_cache_range(pte, sizeof(*pte)); + + if (cap_caching_mode(iommu->cap)) { + pasid_cache_invalidation_with_pasid(iommu, did, pasid); + iotlb_invalidation_with_pasid(iommu, did, pasid); + } else + iommu_flush_write_buffer(iommu); + +} + /* * Set up the scalable mode pasid table entry for first only * translation type. @@ -565,16 +580,7 @@ int intel_pasid_setup_first_level(struct intel_iommu *iommu, /* Setup Present and PASID Granular Transfer Type: */ pasid_set_translation_type(pte, 1); pasid_set_present(pte); - - if (!ecap_coherent(iommu->ecap)) - clflush_cache_range(pte, sizeof(*pte)); - - if (cap_caching_mode(iommu->cap)) { - pasid_cache_invalidation_with_pasid(iommu, did, pasid); - iotlb_invalidation_with_pasid(iommu, did, pasid); - } else { - iommu_flush_write_buffer(iommu); - } + pasid_flush_caches(iommu, pte, pasid, did); return 0; } @@ -638,16 +644,7 @@ int intel_pasid_setup_second_level(struct intel_iommu *iommu, */ pasid_set_sre(pte); pasid_set_present(pte); - - if (!ecap_coherent(iommu->ecap)) - clflush_cache_range(pte, sizeof(*pte)); - - if (cap_caching_mode(iommu->cap)) { - pasid_cache_invalidation_with_pasid(iommu, did, pasid); - iotlb_invalidation_with_pasid(iommu, did, pasid); - } else { - iommu_flush_write_buffer(iommu); - } + pasid_flush_caches(iommu, pte, pasid, did); return 0; } @@ -681,16 +678,7 @@ int intel_pasid_setup_pass_through(struct intel_iommu *iommu, */ pasid_set_sre(pte); pasid_set_present(pte); - - if (!ecap_coherent(iommu->ecap)) - clflush_cache_range(pte, sizeof(*pte)); - - if (cap_caching_mode(iommu->cap)) { - pasid_cache_invalidation_with_pasid(iommu, did, pasid); - iotlb_invalidation_with_pasid(iommu, did, pasid); - } else { - iommu_flush_write_buffer(iommu); - } + pasid_flush_caches(iommu, pte, pasid, did); return 0; } -- 2.7.4