Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5211685pxj; Wed, 9 Jun 2021 11:49:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxch8vpIXoJ8pFP3i8K1Xc/ZU7pJFcEl1PXfD6YHqoPbgOFtRRgWq1QM7WOWSEJi5XONvLQ X-Received: by 2002:a17:907:7713:: with SMTP id kw19mr1115583ejc.249.1623264549407; Wed, 09 Jun 2021 11:49:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623264549; cv=none; d=google.com; s=arc-20160816; b=bkjg3X0jtDoAeuCON6GNAwRyI74EME8v+d7aKrEyI9LjGDUO1rFAMSefKKwIHooExn TEPTvMk4qOugMERHejM8NJGGcmawiKXuwC6QOWVvnlm6Z0PvBPMsxejFwN6p00q55ExO DnaGckfItoIVtxmlZJC1hjZLnOsGHkID+ypscV8BEdRcfg6gtbcNEDCOJC0ufOq7Ppp3 pMBRz4t1DR60X6WUvItj4uM4VbmaZY74vrdaAnPH5SySQZbKPDzdYaxrnvskAURLGXoq D3sym/N9lOBm/RtR4IRTCkjrUi9MM4sKL1vcGG3NAVaMvCnbVAUiA8vsM02LYsLqR8h9 jCPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=ZCfCHqTh6dRobSDLAxAnpSePByaspCZCfIBOsr9OPgQ=; b=TNXheq19oIS8uJpezluQQZpc3SHISnk8Uyf7AwQWAMqDqpGHM5FrPsDbtnyfXFLu8h XxuB/TYaRLhaOJtAyer0+U+BZY8OxvXTQx49n4u9SDrW/DYdpKzHWqtY3epc148IRzV9 BH7RgfVyd/64M+E5hx/zxtYamhUKh6pyt50uxUnHT1/lTwzyO9sHs1DgtZLQ7ydhB/LC lqY+dMl9uj5ymLct54hDlyIqHleYNksptbKvdxKnMy7g/CirzXlXyTjdMSGNXLuUHkbo dCTsoJ3R7WBOxEFGFWHpHguSGW47yAddS0moYWjVV33nu2AH+629Jt+ly6vov9xFSxbJ DwlA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v16si426248ejg.147.2021.06.09.11.48.42; Wed, 09 Jun 2021 11:49:09 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230209AbhFISq0 (ORCPT + 99 others); Wed, 9 Jun 2021 14:46:26 -0400 Received: from foss.arm.com ([217.140.110.172]:40034 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229941AbhFISq0 (ORCPT ); Wed, 9 Jun 2021 14:46:26 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id EF378D6E; Wed, 9 Jun 2021 11:44:30 -0700 (PDT) Received: from [10.57.6.115] (unknown [10.57.6.115]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id D466C3F719; Wed, 9 Jun 2021 11:44:29 -0700 (PDT) Subject: Re: [PATCH] iommu/io-pgtable-arm: Optimize partial walk flush for large scatter-gather list To: Sai Prakash Ranjan , Will Deacon , Joerg Roedel Cc: iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org References: <20210609145315.25750-1-saiprakash.ranjan@codeaurora.org> From: Robin Murphy Message-ID: Date: Wed, 9 Jun 2021 19:44:24 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <20210609145315.25750-1-saiprakash.ranjan@codeaurora.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2021-06-09 15:53, Sai Prakash Ranjan wrote: > Currently for iommu_unmap() of large scatter-gather list with page size > elements, the majority of time is spent in flushing of partial walks in > __arm_lpae_unmap() which is a VA based TLB invalidation (TLBIVA for > arm-smmu). > > For example: to unmap a 32MB scatter-gather list with page size elements > (8192 entries), there are 16->2MB buffer unmaps based on the pgsize (2MB > for 4K granule) and each of 2MB will further result in 512 TLBIVAs (2MB/4K) > resulting in a total of 8192 TLBIVAs (512*16) for 16->2MB causing a huge > overhead. > > So instead use io_pgtable_tlb_flush_all() to invalidate the entire context > if size (pgsize) is greater than the granule size (4K, 16K, 64K). For this > example of 32MB scatter-gather list unmap, this results in just 16 ASID > based TLB invalidations or tlb_flush_all() callback (TLBIASID in case of > arm-smmu) as opposed to 8192 TLBIVAs thereby increasing the performance of > unmaps drastically. > > Condition (size > granule size) is chosen for io_pgtable_tlb_flush_all() > because for any granule with supported pgsizes, we will have at least 512 > TLB invalidations for which tlb_flush_all() is already recommended. For > example, take 4K granule with 2MB pgsize, this will result in 512 TLBIVA > in partial walk flush. > > Test on QTI SM8150 SoC for 10 iterations of iommu_{map_sg}/unmap: > (average over 10 iterations) > > Before this optimization: > > size iommu_map_sg iommu_unmap > 4K 2.067 us 1.854 us > 64K 9.598 us 8.802 us > 1M 148.890 us 130.718 us > 2M 305.864 us 67.291 us > 12M 1793.604 us 390.838 us > 16M 2386.848 us 518.187 us > 24M 3563.296 us 775.989 us > 32M 4747.171 us 1033.364 us > > After this optimization: > > size iommu_map_sg iommu_unmap > 4K 1.723 us 1.765 us > 64K 9.880 us 8.869 us > 1M 155.364 us 135.223 us > 2M 303.906 us 5.385 us > 12M 1786.557 us 21.250 us > 16M 2391.890 us 27.437 us > 24M 3570.895 us 39.937 us > 32M 4755.234 us 51.797 us > > This is further reduced once the map/unmap_pages() support gets in which > will result in just 1 tlb_flush_all() as opposed to 16 tlb_flush_all(). > > Signed-off-by: Sai Prakash Ranjan > --- > drivers/iommu/io-pgtable-arm.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c > index 87def58e79b5..c3cb9add3179 100644 > --- a/drivers/iommu/io-pgtable-arm.c > +++ b/drivers/iommu/io-pgtable-arm.c > @@ -589,8 +589,11 @@ static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, > > if (!iopte_leaf(pte, lvl, iop->fmt)) { > /* Also flush any partial walks */ > - io_pgtable_tlb_flush_walk(iop, iova, size, > - ARM_LPAE_GRANULE(data)); > + if (size > ARM_LPAE_GRANULE(data)) > + io_pgtable_tlb_flush_all(iop); > + else Erm, when will the above condition ever not be true? ;) Taking a step back, though, what about the impact to drivers other than SMMUv2? In particular I'm thinking of SMMUv3.2 where the whole range can be invalidated by VA in a single command anyway, so the additional penalties of TLBIALL are undesirable. Robin. > + io_pgtable_tlb_flush_walk(iop, iova, size, > + ARM_LPAE_GRANULE(data)); > ptep = iopte_deref(pte, data); > __arm_lpae_free_pgtable(data, lvl + 1, ptep); > } else if (iop->cfg.quirks & IO_PGTABLE_QUIRK_NON_STRICT) { >