Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp599910pxj; Fri, 11 Jun 2021 06:59:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLEi0FgZH0hdRK8yBvHNC/SG8TuaoNDQMeRT/JUEmUIYtAjE1Tf7FwQd67CglAFNfDQ/p3 X-Received: by 2002:a17:906:81da:: with SMTP id e26mr3744456ejx.370.1623419951545; Fri, 11 Jun 2021 06:59:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623419951; cv=none; d=google.com; s=arc-20160816; b=CMvGL+7btqNUl/Cxz9nWCJWHYopfMNKS3CkZ0vcnRTKa4y7W+WmucdG3xcShvWXVBy 6rnfhD6lKuwLD0doBrhCOoh72NSjxHje3o7ru64UBj5MttnIRuxBr/mtDPDV6VdRrB+E X7dBvbaz1VswOcwvjcKExkSPeCDzzSlvEJMpLoUIlCax7uC7NdU8C/UQhq9xtlDN1z5G q+8cViEknLtmnfN+thEXnDEr+dgjKUB5/Oi8i3dNbWnwMriJ9NZ0h+oQbBVdfkhHhksv 4c1sSE43HKySLn40FTzsTtklacAoupmv+XZFrtj/5my+BIhmgU126tNa5YbuQsgXE09G LXtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=k2v6wELmfBq9pDTo0yDU140n58gKUvnPHf6FvLT8yVU=; b=TfejNX/AI86N63kCd9G/lfiNDid2Pk/TwdoX9I8SLMphc8r79X57q/3T/yqGB5M9HH 3P3RB+mwUoP3d1MzM3TCO0ztnbC/LuC5pcoPgIKuDIJU2XMWExIdomyHHk1TbKeME4m5 yrk9PFruXKbAo5ulIEU8zo2sMeosznzGkeP8q0ZWfKgYYJjKiqPwf4bDxQ3so4TBsVxU JxO3lfHwIGKv8T8WI8rdvm/lxAvSx6uJyAnfv9V9tGkqTUNgfPpgcQtNqPjZJtcPlReU g+zdfELvANrg4r/kr0ckDlZQV5eSwbSa4+S5gjBdRdlMBYndSCdL9vUn2yJKd2h+b0Mg kvhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ftgXHKBP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y18si5061550edr.488.2021.06.11.06.58.47; Fri, 11 Jun 2021 06:59:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ftgXHKBP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231391AbhFKN7u (ORCPT + 99 others); Fri, 11 Jun 2021 09:59:50 -0400 Received: from mail.kernel.org ([198.145.29.99]:43250 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231355AbhFKN7t (ORCPT ); Fri, 11 Jun 2021 09:59:49 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7AE0D6136D; Fri, 11 Jun 2021 13:57:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1623419871; bh=AWgV4bmc3bhqQ3YMzaNffyJ3Z0ebJe9ErfEnzD8ZC4k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=ftgXHKBP57eTVl2kXNV5HOJw8snhE5MH/1WJh/0rLs0dfdeUBjDBQmSfjOJ/j3bCW fFenox6M2hbp34GAEAGU6KJNuYnhp5+4s2EJeoCCDcVbi/i1OroqYVGsPpVg6pyGMS BE+vKIKp9s06CVOp944zx+GQmoauzg9vDpVE0zoynExgfn1uO0l4puYhrAexm2UHeE 40BUL8C3dPCFJL2YeZajxim0GeYcyVShC77WLyHZaCZXM2YaD1uzpQes7Oy5nWiZUf LTdjFuhoyvsPUlyADkjSKFrzH/aSj6HG/RnS9+MJtJE/yWMzkUl1WXxJfSo5wMit3H Yr8DD9hvvAqRQ== Date: Fri, 11 Jun 2021 14:57:47 +0100 From: Will Deacon To: Nadav Amit Cc: Joerg Roedel , Nadav Amit , Jiajun Cao , Robin Murphy , Lu Baolu , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 4/6] iommu: Factor iommu_iotlb_gather_is_disjoint() out Message-ID: <20210611135746.GC15776@willie-the-truck> References: <20210607182541.119756-1-namit@vmware.com> <20210607182541.119756-5-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210607182541.119756-5-namit@vmware.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 07, 2021 at 11:25:39AM -0700, Nadav Amit wrote: > From: Nadav Amit > > Refactor iommu_iotlb_gather_add_page() and factor out the logic that > detects whether IOTLB gather range and a new range are disjoint. To be > used by the next patch that implements different gathering logic for > AMD. > > Cc: Joerg Roedel > Cc: Will Deacon > Cc: Jiajun Cao > Cc: Robin Murphy > Cc: Lu Baolu > Cc: iommu@lists.linux-foundation.org > Cc: linux-kernel@vger.kernel.org> > Signed-off-by: Nadav Amit > --- > include/linux/iommu.h | 41 +++++++++++++++++++++++++++++++++-------- > 1 file changed, 33 insertions(+), 8 deletions(-) [...] > diff --git a/include/linux/iommu.h b/include/linux/iommu.h > index f254c62f3720..b5a2bfc68fb0 100644 > --- a/include/linux/iommu.h > +++ b/include/linux/iommu.h > @@ -497,6 +497,28 @@ static inline void iommu_iotlb_sync(struct iommu_domain *domain, > iommu_iotlb_gather_init(iotlb_gather); > } > > +/** > + * iommu_iotlb_gather_is_disjoint - Checks whether a new range is disjoint > + * > + * @gather: TLB gather data > + * @iova: start of page to invalidate > + * @size: size of page to invalidate > + * > + * Helper for IOMMU drivers to check whether a new range is and the gathered > + * range are disjoint. I can't quite parse this. Delete the "is"? > For many IOMMUs, flushing the IOMMU in this case is > + * better than merging the two, which might lead to unnecessary invalidations. > + */ > +static inline > +bool iommu_iotlb_gather_is_disjoint(struct iommu_iotlb_gather *gather, > + unsigned long iova, size_t size) > +{ > + unsigned long start = iova, end = start + size - 1; > + > + return gather->end != 0 && > + (end + 1 < gather->start || start > gather->end + 1); > +} > + > + > /** > * iommu_iotlb_gather_add_range - Gather for address-based TLB invalidation > * @gather: TLB gather data > @@ -533,20 +555,16 @@ static inline void iommu_iotlb_gather_add_page(struct iommu_domain *domain, > struct iommu_iotlb_gather *gather, > unsigned long iova, size_t size) > { > - unsigned long start = iova, end = start + size - 1; > - > /* > * If the new page is disjoint from the current range or is mapped at > * a different granularity, then sync the TLB so that the gather > * structure can be rewritten. > */ > - if (gather->pgsize != size || > - end + 1 < gather->start || start > gather->end + 1) { > - if (gather->pgsize) > - iommu_iotlb_sync(domain, gather); > - gather->pgsize = size; > - } > + if ((gather->pgsize && gather->pgsize != size) || > + iommu_iotlb_gather_is_disjoint(gather, iova, size)) > + iommu_iotlb_sync(domain, gather); > > + gather->pgsize = size; Why have you made this unconditional? I think it's ok, but just not sure if it's necessary or not. Will