Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp829139ybc; Tue, 19 Nov 2019 09:55:43 -0800 (PST) X-Google-Smtp-Source: APXvYqzH8k69wvSgmQUYfRO3V9VePVEiDJgf3glrdIR+ZB2KL5/9jVZrSVMF80FXEsHcQYW3WS/a X-Received: by 2002:a17:906:d9c4:: with SMTP id qk4mr35436757ejb.214.1574186143252; Tue, 19 Nov 2019 09:55:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574186143; cv=none; d=google.com; s=arc-20160816; b=w4wEhIJ94Yw2vS10EYh3tRsHPPy4Dbx7DU/Yx2djYpP5MYar+OIJV0GAOfutipxy4J 1NKeO8Z7AkQ6lm4r7Y6sxHt43PhAe5bNvYdrzV27anpKFO/AmEb5XUl6bYx7Ysm2JpIF C7+tbSB/Ml39HWE0FBP45ATaBOW6CC4OV90OSe4Hs6ptuwqap9ihwqV+qyycm/K9WJwr kaVOs3W72AtbGgLNenwgbcLyInQt+s0ZUcvCwK0p1kwyVmKjj7riqiIMYAimxG8R8mXx 1Lv+OYu4eCZ9lPMkLL/lOmKGvBhBZlOWlc8BTIhmx5fltTHdk+pQWQHOrQ0wsBHvF8A8 8PpA== 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=GTf95+oIcDsJ8HE8GIUqF1Zup01DWQMImoQUxzYs9m4=; b=VViq/BFB4kJ7Gl/1pXejaCx9f3ZXK2WRuhkwZiq+3AF5Kb1Prz2l1LjZbCMpylIA/v SdL4oMkVJE0W3qxbPtfzEpAw4htgbNA3XBdHhyt2nPmRVEu2yLs5jVCpYVIJr7Fo3coX DGjdPpBmktTLaVZ5g/22HZ8dHWX1GFv3Cq1INSIPmN1Ai/uksWhmejvcMXsmbWq7E9uy WryUiojMITc3lnaE1iijqXQ6eak+xraSd4gSbp9CVXNvG4mEhXtRs4R7dTIClB5zJE05 0UuvWpL3cObJnX33bfUYpQYonZQNtkQG3ppdil5jK+cJlS2feBfx4AFwI3QioJZXnJTX TyKA== 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 t22si14107598ejx.194.2019.11.19.09.55.17; Tue, 19 Nov 2019 09:55:43 -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 S1727487AbfKSRwT (ORCPT + 99 others); Tue, 19 Nov 2019 12:52:19 -0500 Received: from mga07.intel.com ([134.134.136.100]:14025 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726510AbfKSRwB (ORCPT ); Tue, 19 Nov 2019 12:52:01 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Nov 2019 09:52:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.69,218,1571727600"; d="scan'208";a="209488278" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga006.jf.intel.com with ESMTP; 19 Nov 2019 09:51:58 -0800 From: Jacob Pan To: iommu@lists.linux-foundation.org, LKML , Joerg Roedel , "Lu Baolu" , David Woodhouse Cc: "Tian, Kevin" , Raj Ashok , "Yi Liu" , Eric Auger , "Mehta, Sohil" , Jacob Pan Subject: [PATCH v3 4/8] iommu/vt-d: Avoid duplicated code for PASID setup Date: Tue, 19 Nov 2019 09:56:28 -0800 Message-Id: <1574186193-30457-5-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1574186193-30457-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1574186193-30457-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 Reviewed-by: Lu Baolu Acked-by: Lu Baolu --- 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 e7cb0b8a7332..732bfee228df 100644 --- a/drivers/iommu/intel-pasid.c +++ b/drivers/iommu/intel-pasid.c @@ -465,6 +465,21 @@ void intel_pasid_tear_down_entry(struct intel_iommu *iommu, devtlb_invalidation_with_pasid(iommu, dev, pasid); } +static 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. @@ -518,16 +533,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; } @@ -591,16 +597,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; } @@ -634,16 +631,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