Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp43775pxu; Tue, 24 Nov 2020 18:03:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJxbV9Ttj3YFmdXpLIOZqrI5Q2fLM42fuU9ItP5B2EQHkEp0Q5zziiP5PDFRsyGDAyGv2v2R X-Received: by 2002:a17:906:5a8f:: with SMTP id l15mr1176521ejq.419.1606269837726; Tue, 24 Nov 2020 18:03:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606269837; cv=none; d=google.com; s=arc-20160816; b=qw/F/FE8Foy2Pcds40KeIjiKFoPSXrwxwjZowEDxsbDaEHCZvkYdK73sydQZvXIPqG 76YoiK/aMNdAMg117LYjP55ate9ohxu1cRX4Yt4O2tNv/kdkTmp9Tcivc/68gL8D9S2U RGH4DXpufWixgy6qNpdCNi8cA2aMBlikua1QnY3XhdXH2uRl89Jj/xAB7GFkUeMlYZXM R7aigoU3xoazQ4EevDph/4gtyl4Rjlg7ge/5vaeY4yaoAZGDtJsSrT/AxKK3XqBu0cb2 CTIOp6L0GRZhW3E5YomPdZ29//81jdrFhzOG077X8gWw2nRA0RmhNdhHT6Npv/3/OLDH j5yw== 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=BtFVvBswSOsuAQSKsFSdQX6CRLay6+90LznfwdplR7Q=; b=jmlYQ/88JJT5TlQHzXIJelY35OdSoZlLsV6DHpNx8Ka1ixn8l5NFPawD3MBP5NGjvJ fOA+2zegtwwRTBwPSYTxORJeM6r7WfII4rXlGGNUPeWB9t/GlkmVNkL1N2xl4nIlGOev 8sCASVqOkCqqZVGftKk+4JmRhO79rHRMB0BbVb5g9eC/Oy0PBNT9DB+4Nfpnq6oWcede 1SkjWFSnSU09hAb2IwL/FcjfxI5coJJAmoA+L5SeQt/pvLYUpCLWl+ZIgCcHO5fLwUn0 aJCwD71ZtUoua91F+R1/9fRMHWNbBS4Ibl2auXnSndJpWupTt0AeT+yeIeQdwRJ1yW0X yKhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=F3SBAmZR; 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 k25si184151ejk.415.2020.11.24.18.03.30; Tue, 24 Nov 2020 18:03:57 -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=F3SBAmZR; 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 S1732392AbgKXLF2 (ORCPT + 99 others); Tue, 24 Nov 2020 06:05:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:32884 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731911AbgKXLF1 (ORCPT ); Tue, 24 Nov 2020 06:05:27 -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 9A41B20708; Tue, 24 Nov 2020 11:05:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1606215927; bh=p7cS0enyaISQXUsFbBkJBL1aoa2MlX33h5/J260iXIw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=F3SBAmZRTb54N/YAxmPu1vt5vCXgqcUrDxC/I6tq4FoRWdxlhKAXh24e2A3yq6vzm BgHxbhukrj9r3LrDIPXIc3Mwe2Guh38i3iRJEe4ZQjjNxebY2oBWMFXYq3afwnmKfK THIyImd3gme1xi91jEdzIxGCeTTwpRkoTNsv8iK8= Date: Tue, 24 Nov 2020 11:05:21 +0000 From: Will Deacon To: Yong Wu Cc: Joerg Roedel , Robin Murphy , Matthias Brugger , Krzysztof Kozlowski , Tomasz Figa , linux-mediatek@lists.infradead.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, iommu@lists.linux-foundation.org, youlin.pei@mediatek.com, Nicolas Boichat , anan.sun@mediatek.com, chao.hao@mediatek.com Subject: Re: [PATCH] iommu: Improve the performance for direct_mapping Message-ID: <20201124110520.GA12980@willie-the-truck> References: <20201120090628.6566-1-yong.wu@mediatek.com> <20201123123258.GC10233@willie-the-truck> <1606209884.26323.132.camel@mhfsdcap03> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1606209884.26323.132.camel@mhfsdcap03> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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: > > On Fri, Nov 20, 2020 at 05:06:28PM +0800, Yong Wu wrote: > > > + unmapped_sz = 0; > > > + } > > > + start += pg_size; > > > + } > > > + if (unmapped_sz) { > > > + ret = iommu_map(domain, start, start, unmapped_sz, > > > + entry->prot); > > > > Can you avoid this hunk by changing your loop check to something like: > > > > if (!phys_addr) { > > map_size += pg_size; > > if (addr + pg_size < end) > > continue; > > } > > Thanks for your quick review. I have fixed and tested it. the patch is > simple. I copy it here. Is this readable for you now? > > > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -737,6 +737,7 @@ static int > iommu_create_device_direct_mappings(struct iommu_group *group, > /* We need to consider overlapping regions for different devices */ > list_for_each_entry(entry, &mappings, list) { > dma_addr_t start, end, addr; > + size_t map_size = 0; > > if (domain->ops->apply_resv_region) > domain->ops->apply_resv_region(dev, domain, entry); > @@ -752,12 +753,21 @@ static int > iommu_create_device_direct_mappings(struct iommu_group *group, > phys_addr_t phys_addr; > > phys_addr = iommu_iova_to_phys(domain, addr); > - if (phys_addr) > - continue; > + if (!phys_addr) { > + map_size += pg_size; > + if (addr + pg_size < end) > + continue; > + else You don't need the 'else' here ^^^ > + addr += pg_size; /*Point to End */ addr = end ? 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? Will