Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5351295pxu; Wed, 21 Oct 2020 23:01:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx1nY3QZi1Z+jncM/sWG4HUIUfUIcPBfbGMMDzeA68I+emnx9Qonf17dx7STX03H8Ve51Wb X-Received: by 2002:a50:8fc5:: with SMTP id y63mr835172edy.10.1603346506693; Wed, 21 Oct 2020 23:01:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603346506; cv=none; d=google.com; s=arc-20160816; b=rISCBW6Evvq8fa7GL36jsWSE1HUB7t70KWLJuCc0Q7VDjO+QUkqWmJzHWJe+JXDHCf uU5l2r6V7+tgshbW9Q742K5y/jd25G2SayHYZN7YbxvAMNJFrZcDkR1JfbF1p9qkI/Bi gEp5IZbskBaZ1PfSaUd3g18+V7YhZbQG0d4YOwVybE95Jl2N6GkW6VrqPO0L8A2Q6nZa ix7u1biUOol3lXZ2+t9lCOUYE8PNDW8KtDXBoDT4K5sMigD0fBgNMIUc3dlBiXXRlJ/K L6cbNSGqtF82GvJ9IenH7Ns/T0xLH0XXzZgL6pae58G8TxdmmQn7Jc1pUk6XKVw6flwv MZzA== 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=QIN92XFqBRf5bqFDhb84nMd4M5qEoHnyEPoKTaQjdhw=; b=A/tTzY/nNlNz0IQkK9sgDBsFkfr7GxDj67c93p/DOnbs9hkA3w17Q0xHDswM8xf6/F Pw3MyhR697A5G3FBpJ2R+QhWMEQaNyN5LIl7yKptEwOGfkFByQGEp52D0GcpfevzJyQH p7RIVozH2u3knRs3nNo3cIw8iC/IIpBXWOASgRItntlG4dnfJTyEpIKmi+lapY7MOCJj 4gZ0XNcZO+rEyGJ598zANs4s/7tFS5BD1AQGDyRj8c7TxfZglECibLPaGAJ5/qS28niK Ir7bjx6BcPR76UQaPtJgT9DwPeX5hFB+rhQtMaaEuPQW0G/YQeNTe9NhE+bnI3YwSCUt ZAdg== 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 w14si258955eje.646.2020.10.21.23.01.17; Wed, 21 Oct 2020 23:01:46 -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 S2503229AbgJUQ4J (ORCPT + 99 others); Wed, 21 Oct 2020 12:56:09 -0400 Received: from foss.arm.com ([217.140.110.172]:37780 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2395372AbgJUQ4J (ORCPT ); Wed, 21 Oct 2020 12:56:09 -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 764FF31B; Wed, 21 Oct 2020 09:56:08 -0700 (PDT) Received: from [10.57.50.191] (unknown [10.57.50.191]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id B24073F719; Wed, 21 Oct 2020 09:56:03 -0700 (PDT) Subject: Re: [PATCH 2/4] iommu/mediatek: Add iotlb_sync_range() support To: Chao Hao , Joerg Roedel , Matthias Brugger Cc: Jun Wen , FY Yang , wsd_upstream@mediatek.com, linux-kernel@vger.kernel.org, iommu@lists.linux-foundation.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, Mingyuan Ma References: <20201019113100.23661-1-chao.hao@mediatek.com> <20201019113100.23661-3-chao.hao@mediatek.com> From: Robin Murphy Message-ID: <7fbe0305-91e4-949e-7d84-bf91e81d6b27@arm.com> Date: Wed, 21 Oct 2020 17:55:58 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Thunderbird/78.3.3 MIME-Version: 1.0 In-Reply-To: <20201019113100.23661-3-chao.hao@mediatek.com> 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 2020-10-19 12:30, Chao Hao wrote: > MTK_IOMMU driver writes one page entry and does tlb flush at a time > currently. More optimal would be to aggregate the writes and flush > BUS buffer in the end. That's exactly what iommu_iotlb_gather_add_page() is meant to achieve. Rather than jumping straight into hacking up a new API to go round the back of the existing API design, it would be far better to ask the question of why that's not behaving as expected. > For 50MB buffer mapping, if mtk_iommu driver use iotlb_sync_range() > instead of tlb_add_range() and tlb_flush_walk/leaf(), it can increase > 50% performance or more(depending on size of every page size) in > comparison to flushing after each page entry update. So we prefer to > use iotlb_sync_range() to replace iotlb_sync(), tlb_add_range() and > tlb_flush_walk/leaf() for MTK platforms. In the case of mapping, it sounds like what you actually want to do is hook up .iotlb_sync_map and generally make IO_PGTABLE_QUIRK_TLBI_ON_MAP cleverer, because the current implementation is as dumb as it could possibly be. In fact if we simply passed an address range to .iotlb_sync_map, io-pgtable probably wouldn't need to be involved at all any more. Robin. > Signed-off-by: Chao Hao > --- > drivers/iommu/mtk_iommu.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c > index 785b228d39a6..d3400c15ff7b 100644 > --- a/drivers/iommu/mtk_iommu.c > +++ b/drivers/iommu/mtk_iommu.c > @@ -224,6 +224,11 @@ static void mtk_iommu_tlb_flush_range_sync(unsigned long iova, size_t size, > } > } > > +static void __mtk_iommu_tlb_flush_range_sync(unsigned long iova, size_t size) > +{ > + mtk_iommu_tlb_flush_range_sync(iova, size, 0, NULL) > +} > + > static void mtk_iommu_tlb_flush_page_nosync(struct iommu_iotlb_gather *gather, > unsigned long iova, size_t granule, > void *cookie) > @@ -536,6 +541,7 @@ static const struct iommu_ops mtk_iommu_ops = { > .map = mtk_iommu_map, > .unmap = mtk_iommu_unmap, > .flush_iotlb_all = mtk_iommu_flush_iotlb_all, > + .iotlb_sync_range = __mtk_iommu_tlb_flush_range_sync, > .iotlb_sync = mtk_iommu_iotlb_sync, > .iova_to_phys = mtk_iommu_iova_to_phys, > .probe_device = mtk_iommu_probe_device, >