Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp3228937ybc; Mon, 18 Nov 2019 11:39:29 -0800 (PST) X-Google-Smtp-Source: APXvYqw5pEnm5/fA9UZjrrli77jUPsC+xWZRBLTJfHHm3yvswhwvENIcTaZXlv6Nf8MD9WSvubwO X-Received: by 2002:a17:906:4d58:: with SMTP id b24mr28430593ejv.277.1574105969433; Mon, 18 Nov 2019 11:39:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574105969; cv=none; d=google.com; s=arc-20160816; b=StOsr++clm1YTfE5YzSuHmnWokXF4LL6aPCfJ0R/n76Uxt6GdBPKPJ+e11gjBEZcvC cOVWvNa+ZxO4ULctDbJ6Ytu2cdk/WYFSrY9kW9Fs6QN2UrggrmT0XYimq83FicyEAeLd XjDgXJKcG5aNJocllzF8g6PDLPOcM1/lE7c6F+z9VAaaFGRtiQngaAZYKmGdf3X/Sxa9 +s3R8rAe++XjczjxVKqtgdAn4tBmVvwQTl4lfViK2uYfEWYuTJ1ET2I/lwrChBNACzhf yssWpf6zcpRs9HQURD7B4MFvuP+bOL7dCiyqlY596l8z4Ut8FTpXeClqBdaDXe4SIStG R0Uw== 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=qTB2s2HzVCGU3G5TlWupswbBF7vcVCA0V+6i3HxCjZQMj5a6SSx/+QC6/oPeggAJ/y NGHBynjWuUocD7bNgJC2qrOjcIKZSwSsI3yTiTtKNDRCDfiYoULyGGnviZDUJ/qJkYt+ E8I5Oc7EYMWwbTQw/KU/h9eCcFwg3PgSqRY8HZGZdW+ovIWX5Jwaj0LY7IcyltSMve5l WuHcggqjMscCGh+f3FviBebdJ98SUMYqEFxxHXkXn3cmobIL8iwlHNYrH4g99t95SUzL 4YNqPw6eLK0aHkoUornQ/hMQyfyftDO2K3pVdZsC6Tl4mM+PCFPBeo5nixxSMsLKuxFE wdRQ== 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 pv22si12246838ejb.337.2019.11.18.11.39.05; Mon, 18 Nov 2019 11:39:29 -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 S1726937AbfKRTiD (ORCPT + 99 others); Mon, 18 Nov 2019 14:38:03 -0500 Received: from mga02.intel.com ([134.134.136.20]:60276 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726774AbfKRTiA (ORCPT ); Mon, 18 Nov 2019 14:38:00 -0500 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 18 Nov 2019 11:37:59 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.68,321,1569308400"; d="scan'208";a="380760859" Received: from jacob-builder.jf.intel.com ([10.7.199.155]) by orsmga005.jf.intel.com with ESMTP; 18 Nov 2019 11:37:59 -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 , Jacob Pan Subject: [PATCH v2 05/10] iommu/vt-d: Avoid duplicated code for PASID setup Date: Mon, 18 Nov 2019 11:42:28 -0800 Message-Id: <1574106153-45867-6-git-send-email-jacob.jun.pan@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1574106153-45867-1-git-send-email-jacob.jun.pan@linux.intel.com> References: <1574106153-45867-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