Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp288972pxu; Wed, 25 Nov 2020 03:17:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJyYRY2nvY8+eVAlzaOILpa/c91SI5KJBz3pFGOLpZG8jx07nLNQXTB9n6VmM+iHFdCruxCG X-Received: by 2002:a17:906:1b09:: with SMTP id o9mr2835724ejg.79.1606303026315; Wed, 25 Nov 2020 03:17:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606303026; cv=none; d=google.com; s=arc-20160816; b=PgyppS5lGMcd9hfbUAMz1liNmorBXaS/r6BGM3keY1cJBuGuS1bXgOvk7Edi1PFOGZ OInKsjlBtiH5n8+wIcy8dSwHzZLzU2P651AuN0+6LJilEt7kGNLKEXGzp1U1/jvEKV/s C8ASZq6w4cmMymQdkFLh93XmJEleGIvpP83WeNavTYQhOiSgDa2EjJqc8M5u4L+MbgVp TRY7BQlIws6oekl+Gwxzvp08b9uXqxyVzvhijFCYJ30ce9UHETPsf1h7dvK+Ziu0PP4P XDsCC0+HwZ/+weqryZPUwPin4nT1/vKN0G7JczHuuRI7ADU2RsWMeW2NMCbIhzKO7I+c kocw== 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=9tGqEwAyxdZCSWlLmTggj7Y57UkAU1kCZZJEyVvjNAk=; b=fj5pH2gCBxEzCKIzYKr15yOJkKYdSfMs+6rcljrXcCxwHvyt56cO/4l3qtJYgBI0T9 cvY7/9CODM5jPxYdjp3YG8kEgmDaIgZfUTUclg/qg7pwLxqewSlOqRpJp/92ImbI1jmk JSUc8a0/W3kC7pYZ1opXOEkbuqgKPwNP/5qiZrTZw+0mzIQAHw/rOVXmr9uOT5mmRN5A hvRM+muDDTYVb2ZeNQvMR3NkJOViNeAnaPUMzBfnzFdYppKo6lI4pHlOgl4RS2AaQ2e5 Clo2AArMstbEjk0VNeY03PUKbrnPEMAAMxCZu/JRbTTQm6+8dt2A1lafJoKCiXNDYwJw MlFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uahWelgQ; 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 i7si1415930ejo.726.2020.11.25.03.16.43; Wed, 25 Nov 2020 03:17:06 -0800 (PST) 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=default header.b=uahWelgQ; 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 S1728193AbgKYLNJ (ORCPT + 99 others); Wed, 25 Nov 2020 06:13:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:35492 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726411AbgKYLNI (ORCPT ); Wed, 25 Nov 2020 06:13:08 -0500 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5FECF206B7; Wed, 25 Nov 2020 11:13:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606302788; bh=rbevIJAsSB/iRPD2vJR1nkW2xROzISyxEwaJMCSnkso=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=uahWelgQafXjRsuI496JVdUNxkEZm3JksQ9wJ1cwLh6puVI2ye4SNLrtruQL4fU4V UwWTo+hCjkW7fqNmMG4Qi6yOj6GcqoKnuediWkLgQ0DfOEXU/BVkN87icfKT45+m8X l9QM/ksIyV6ERAwsQpKuBYGIddyhVWQ4oOhKWgaA= Date: Wed, 25 Nov 2020 11:13:02 +0000 From: Will Deacon To: Yong Wu Cc: youlin.pei@mediatek.com, anan.sun@mediatek.com, Nicolas Boichat , srv_heupstream@mediatek.com, chao.hao@mediatek.com, Joerg Roedel , linux-kernel@vger.kernel.org, Krzysztof Kozlowski , Tomasz Figa , iommu@lists.linux-foundation.org, linux-mediatek@lists.infradead.org, Matthias Brugger , Robin Murphy , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH] iommu: Improve the performance for direct_mapping Message-ID: <20201125111301.GB15239@willie-the-truck> References: <20201120090628.6566-1-yong.wu@mediatek.com> <20201123123258.GC10233@willie-the-truck> <1606209884.26323.132.camel@mhfsdcap03> <20201124110520.GA12980@willie-the-truck> <1606302214.26323.141.camel@mhfsdcap03> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1606302214.26323.141.camel@mhfsdcap03> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 25, 2020 at 07:03:34PM +0800, Yong Wu wrote: > On Tue, 2020-11-24 at 11:05 +0000, Will Deacon wrote: > > On Tue, Nov 24, 2020 at 05:24:44PM +0800, Yong Wu wrote: > > > On Mon, 2020-11-23 at 12:32 +0000, Will Deacon wrote: > > That said, maybe we could simplify this further by changing the loop bounds > > to be: > > > > for (addr = start; addr <= end; addr += pg_size) > > > > and checking: > > > > if (!phys_addr && addr != end) { > > map_size += pg_size; > > continue; > > } > > > > does that work? > > It works but I think we can not check iommu_iova_to_phys(domain, end). > We should add a "if", like: > > for (addr = start; addr <= end; addr += pg_size) { > ... > if (addr < end) { > phys_addr = iommu_iova_to_phys(domain, addr); > if (!phys_addr) { > map_size += pg_size; > continue; > } > } > ... > Oh yes, you're right. > If you don't like this "if (addr < end)", then we have to add a "goto". > like this: > > > for (addr = start; addr <= end; addr += pg_size) { > phys_addr_t phys_addr; > > if (addr == end) > goto map_last; > > phys_addr = iommu_iova_to_phys(domain, addr); > if (!phys_addr) { > map_size += pg_size; > continue; > } > > map_last: > if (!map_size) > continue; > ret = iommu_map(domain, addr - map_size, > addr - map_size, map_size, entry->prot); I think it's cleared to invert this as you had before: if (map_size) ret = iommu_map(...); > Which one is better? The second one is easier to read. I'll stop making suggestions now, thanks. Will