Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2264818ybi; Sun, 9 Jun 2019 07:36:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqxhWvnoYBIvNDnYAwrX4L+ttHZe1aCV39MNtEdmNqM/EbCt4tgWw0ZJR9nb59iypCPb26bY X-Received: by 2002:a17:902:2ae8:: with SMTP id j95mr29792736plb.276.1560090967151; Sun, 09 Jun 2019 07:36:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560090967; cv=none; d=google.com; s=arc-20160816; b=JOCq2jLtqZVecd7Ac970D984VEN+lTQUsaDuoPbC+XkNdsxSr/A4d0Om0z5IcAPEYD A4nbZCEc40eqU42rwoo5dPqmvs+68WIHV1C79hW+zt0JDsLW6NdBAwRLRW3EcLJVRzb/ YcMl93GULwYE6IyVM+DIhOLnY8X64LerNOdOIoMklNgANoESmpAFvzdySfRQk70mSxV4 DsAlCV+35bKxSVdPlivmtSeZtJQJx9vQzTbLRfBinr6RczXJNnfVSwJKiAX6xmmghF7a 5LNr7957kqaZOF6MkCw0qt8eyLfrVIJrG5G35VnqyJkS6tZanoxFDOpdUiX67WjPkAfu zUKA== 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=yT2xQCF0w3xdYfmuJOSaEhjDKMviI8h52aj6e+9XZdU=; b=Acgef3lKoS5p5eQKyZBGEaoE5w8qNCwcOBid0XeZcu+bI/0B6xwfwn5vsqScpFPuaS RYaAVXu6P68KxXlqldIpBRLp7n7p9urRZNW4AHpjhC6jPyvRDZPToTSgNfIYSFdCsOfq fpZOrkRhYoctQ4jMWV/3OAaEs4Y0BWsnThvz0KDhgc9Ii8/v97OLaDMHZoLWusXNoaIq jOc2h9+e4LSYHXz/ud0jNN9jx3YX7VxHq7Nx2lv0T0C7Xs4/5oY8iuoxGA1l5rlWTzg7 5IhWwXN4i0/tUWQo8KzAL0QVeoGRG9AhM66h4GMpUbSY9iEODTzVD5W9iCTrK1BCAYkf AXQQ== 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 65si7866709ple.240.2019.06.09.07.35.22; Sun, 09 Jun 2019 07:36:07 -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 S1729111AbfFINlk (ORCPT + 99 others); Sun, 9 Jun 2019 09:41:40 -0400 Received: from mga11.intel.com ([192.55.52.93]:32101 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728970AbfFINlV (ORCPT ); Sun, 9 Jun 2019 09:41:21 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 09 Jun 2019 06:41:18 -0700 X-ExtLoop1: 1 Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga003.jf.intel.com with ESMTP; 09 Jun 2019 06:41:18 -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 v4 17/22] iommu/vt-d: Avoid duplicated code for PASID setup Date: Sun, 9 Jun 2019 06:44:17 -0700 Message-Id: <1560087862-57608-18-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1560087862-57608-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1560087862-57608-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 1e25539..1ff2ecc 100644 --- a/drivers/iommu/intel-pasid.c +++ b/drivers/iommu/intel-pasid.c @@ -522,6 +522,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. @@ -567,16 +582,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; } @@ -640,16 +646,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; } @@ -683,16 +680,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