Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3947932ybi; Tue, 18 Jun 2019 09:04:23 -0700 (PDT) X-Google-Smtp-Source: APXvYqyyp3trWj+QogG5mxdL+ZkIRRNGSfavpAdniMGtjjcZWxRGwZsuXq4j8hv7+1FnyiJkSX5e X-Received: by 2002:a17:902:9a49:: with SMTP id x9mr94637935plv.282.1560873863459; Tue, 18 Jun 2019 09:04:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560873863; cv=none; d=google.com; s=arc-20160816; b=pF2zDmTjnVDC+q7JMVHQs5X2CTB2/iOmlaUtCdvhvMCH/W5+9sXCF55H6NTZISNSrl EGKWhUXnxea5r296C7lyKRr9NTu7BhEZcYqXKQxVPna/AK0V+o5Q1dUQQEaBkPy2fyy7 t4W+UOmbahd8w5Md2OWfzrV25KNtpeB5S2iMfF4K+xJFY72CXR4FOACoyRp9iKy0QiUB /zDHlGWO7at6Hz6Wo+9H+nXwUdtLSNdmbPHOwRxxfswZxhpY+XB+S6nSwDto5tzCNe0Q Xf1x2FY8+WCNoJZMEPHTZ0XbT18gexMyCQA6SGlF+g/zdx7EdB9E/lw0oHBZ9PZNeT2M vEmQ== 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=UnSJBDdAwrvoZYMLWkRvfG/BIXOiafN3SN1Yjwzvf0E=; b=x1vUU0kVOozoOCU7TOCF7O5G3G+hiaim26rvHzYqW5SZWmW9+oqyf4eCuVavUcK0x8 C0hXqVp6pYNlgKiKHz2MyaM+suy+CkWWVzWgFtqyBqciS+VViALboGOGL76Xd2bl1pWg 0fTbw35VRlyHolT4DXahnKELCkO2Nsl4rL9gwfPCMaAPz4zizGgy6iWIsBSxT+0ipxWr Wd+4cuxbvOQ1QsvOeKn9G4E/HLN4cewL3DfmypzapOLFvGV2nWTSHssmBtSE4hQigvqB 25oH3Ga8Hzj6Pu/buhQvTxprKdpJtFc6PianO8SD6cq+WJst1un1EynYX74Ab95QfZqD Eqsw== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f7si505551pgd.155.2019.06.18.09.04.07; Tue, 18 Jun 2019 09:04:23 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729706AbfFRQDw (ORCPT + 99 others); Tue, 18 Jun 2019 12:03:52 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:19039 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729209AbfFRQDw (ORCPT ); Tue, 18 Jun 2019 12:03:52 -0400 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id E4C1B12414D8A08DBFF9; Wed, 19 Jun 2019 00:03:48 +0800 (CST) Received: from localhost (10.202.226.61) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.439.0; Wed, 19 Jun 2019 00:03:46 +0800 Date: Tue, 18 Jun 2019 17:03:35 +0100 From: Jonathan Cameron To: Jacob Pan CC: , LKML , Joerg Roedel , David Woodhouse , "Eric Auger" , Alex Williamson , Jean-Philippe Brucker , "Tian, Kevin" , Raj Ashok , Andriy Shevchenko Subject: Re: [PATCH v4 17/22] iommu/vt-d: Avoid duplicated code for PASID setup Message-ID: <20190618170335.000078db@huawei.com> In-Reply-To: <1560087862-57608-18-git-send-email-jacob.jun.pan@linux.intel.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> Organization: Huawei X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.202.226.61] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 ;) > +} > + > /* > * 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; > }