Received: by 2002:a25:f815:0:0:0:0:0 with SMTP id u21csp3172888ybd; Mon, 24 Jun 2019 20:57:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmujT+5egJ7bgQJIVLNr2j+HC+jnOCjf3wUdH6Ri9V1NcQw4i3GtCbr5xro7Mo2+RYR6w5 X-Received: by 2002:a63:f346:: with SMTP id t6mr25886842pgj.203.1561435044580; Mon, 24 Jun 2019 20:57:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561435044; cv=none; d=google.com; s=arc-20160816; b=pRc6nj8W9aF7lblVCpE54n7rk7MYrFDlGwGzJZLcLs36SUOwoq3f4aFUgHYz66AxAH MUcFZwTLcgoBZjV8fK3PkIXoOEQeMyKIq0540rqpV0l6UVhfDVc3OPcS5d6TeBh+GGa5 aY9o/6KzzmInbanMQaxjEwakzlp44KHXFBPnMDL0TyNmifjBnQK3q8nFUCr3TQ37KBLL AfjClVTT/t1bffcEh4X1uttYNM5JsHBXpRZYEuDOBRRMXbygdu+11y9kOV2fa+4aH2zm pORhPmFcjAmsHKsHSdIehdPnmVN++3zGQl+nk+Aun/0zzYR9zsr9EZ/BNZWJJgELGIYG K1Qg== 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:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date; bh=fECcqg8XX15NZBCEuWM4ctjXU7naxE9SHX04hXDj4k0=; b=uhbf7VSMW/dzADiHq9LMpMCPUq77pSngmE3Nh8cbsfCgNaOLw7JnBCcq6PeuYZ5pCq z4XH8PWifd0ba+Tbn5PwIJS3OJV2MOrEG64IRmO4tlkjlIzTjxZynIJ+I/gokFDamRdY Bt8OvlF5r+W9/jFVi33xt0sJTgcbdNePWaHIwc5ygPzhk7tHZaFz5tCfQW308K698oou aQk6Jh02b7TQsKyCkeIJHbcGKK6yTUTmU51XL51JeUH21oSZggbITehfBbxox56ZpMz1 hqAkQHZk2OsiODMmb3Rtrw+OIJo5oq17F2Aijw63TiExX/Bxfr3RPUUhS4w0ccoQxa04 qUow== 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 o8si11640336pll.64.2019.06.24.20.57.08; Mon, 24 Jun 2019 20:57:24 -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 S1728539AbfFXXlh (ORCPT + 99 others); Mon, 24 Jun 2019 19:41:37 -0400 Received: from mga07.intel.com ([134.134.136.100]:29338 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728499AbfFXXlh (ORCPT ); Mon, 24 Jun 2019 19:41:37 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga105.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 24 Jun 2019 16:41:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.63,413,1557212400"; d="scan'208";a="244876675" Received: from jacob-builder.jf.intel.com (HELO jacob-builder) ([10.7.199.155]) by orsmga001.jf.intel.com with ESMTP; 24 Jun 2019 16:41:35 -0700 Date: Mon, 24 Jun 2019 16:44:50 -0700 From: Jacob Pan To: Jonathan Cameron Cc: , LKML , Joerg Roedel , David Woodhouse , "Eric Auger" , Alex Williamson , Jean-Philippe Brucker , "Tian, Kevin" , Raj Ashok , Andriy Shevchenko , jacob.jun.pan@linux.intel.com Subject: Re: [PATCH v4 17/22] iommu/vt-d: Avoid duplicated code for PASID setup Message-ID: <20190624164450.732e5539@jacob-builder> In-Reply-To: <20190618170335.000078db@huawei.com> 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> <20190618170335.000078db@huawei.com> Organization: OTC X-Mailer: Claws Mail 3.13.2 (GTK+ 2.24.30; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 18 Jun 2019 17:03:35 +0100 Jonathan Cameron wrote: > On Sun, 9 Jun 2019 06:44:17 -0700 > 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 > Formatting nitpick below ;) > > Otherwise it's cut and paste > > --- > > 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); > > I have some vague recollection kernel style says use brackets around > single lines if other blocks in an if / else stack have multiple > lines.. > > I checked, this case is specifically called out > > https://www.kernel.org/doc/html/v5.1/process/coding-style.html > > + > This blank line doesn't add anything either ;) indeed. i will add the braces and remove the blank line. Thanks for looking it up. > > +} > > + > > /* > > * 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; > > } > > [Jacob Pan]