Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp628816ybi; Tue, 16 Jul 2019 02:53:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqz5j7/4CKr3ld/nG6McVZwadplkrjT66U+aA0nm8mnb6w8Dj0WZ8SekExOdk4rob1GmyaOY X-Received: by 2002:a63:5402:: with SMTP id i2mr5477746pgb.414.1563270821493; Tue, 16 Jul 2019 02:53:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563270821; cv=none; d=google.com; s=arc-20160816; b=y0F2J0oW89y2N5eQagqnLeFDKeuvtTLweDmE146dQhM+65OQMA4WcuqZscC7MmXpXI boXYoqHWFkzSwE9AxL0nSNmtlBfFAtjLb4V1sQFPHr+GeRk8RyE7p3yxmEJ+I0twF2Oz 4y/EdjMTkj4XI2HImIyA06MWvg9mFK9MAKDVYKS4P/Kh+i0Zea87e6G1aBeB5ikkTAeo HehQDYLNm10wawOseQNbzdGbFXM/E7YFfYkW3iNsp124cCS3iLM+Y5bkH28yhaUb+Rg/ CJJtSFNNigN30+YOHNL/Y0pYW5x1YLlSKu9tVai+Q1bRaIHyErebyCsFuUnhkCta778f Hrzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=aDYpXbbWbjPrey037P2QMg7CD5jVm1ddGDJgvlUkfOU=; b=BzcEExFZVYBeKjlKgLjTrBJsmWACOz4hwtyYZZy4h6bSjgFwH1nvn1jnAiGK4AzqM0 IScHkwIeWgb/g5L9FCSqYmOIJ9MBEBNexXrEEnmq7M4tUz79wZSO6owdoddGN57qBjOH mumXFMrEbdCMaRvj9+4rwsCMENK2hh1ExTbHVwYt2qjtcKtjgvTYQ/+F+W58zSIXrgos 2QdITzLU2wlYIuQcK4aFMfaeTUh9nARXFCJ36l4Kc4G4OnRnhDVFRXvIbn6NmsNZFv98 aXNta7LBVpxD2lp63UXIE2o2dHMK6FbXAskjsZWRYIg+aZUY6v+lBSSEewbM75Kb244a rB0w== 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o127si19448648pga.593.2019.07.16.02.53.25; Tue, 16 Jul 2019 02:53:41 -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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732151AbfGPJwe (ORCPT + 99 others); Tue, 16 Jul 2019 05:52:34 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35950 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726536AbfGPJwe (ORCPT ); Tue, 16 Jul 2019 05:52:34 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9201D3081244; Tue, 16 Jul 2019 09:52:33 +0000 (UTC) Received: from [10.36.116.32] (ovpn-116-32.ams2.redhat.com [10.36.116.32]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3EB0F611DE; Tue, 16 Jul 2019 09:52:28 +0000 (UTC) Subject: Re: [PATCH v4 17/22] iommu/vt-d: Avoid duplicated code for PASID setup To: Jacob Pan , iommu@lists.linux-foundation.org, LKML , Joerg Roedel , David Woodhouse , Alex Williamson , Jean-Philippe Brucker Cc: Yi Liu , "Tian, Kevin" , Raj Ashok , Christoph Hellwig , Lu Baolu , Andriy Shevchenko References: <1560087862-57608-1-git-send-email-jacob.jun.pan@linux.intel.com> <1560087862-57608-18-git-send-email-jacob.jun.pan@linux.intel.com> From: Auger Eric Message-ID: <798650b7-4187-4a44-152a-b0d99be55c6c@redhat.com> Date: Tue, 16 Jul 2019 11:52:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <1560087862-57608-18-git-send-email-jacob.jun.pan@linux.intel.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Tue, 16 Jul 2019 09:52:33 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jacob, On 6/9/19 3:44 PM, Jacob Pan wrote: > 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); Besides the style issue reported by Jonathan and the fact this function may not deserve the inline (chapt 15 of https://www.kernel.org/doc/html/v5.1/process/coding-style.html), Reviewed-by: Eric Auger Thanks Eric > + > +} > + > /* > * 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; > } >