From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 47576C43381 for ; Wed, 23 Dec 2020 08:57:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 206072256F for ; Wed, 23 Dec 2020 08:57:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728259AbgLWI4z (ORCPT ); Wed, 23 Dec 2020 03:56:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40410 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727050AbgLWI4y (ORCPT ); Wed, 23 Dec 2020 03:56:54 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF2DCC0613D3 for ; Wed, 23 Dec 2020 00:56:14 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id t22so10009258pfl.3 for ; Wed, 23 Dec 2020 00:56:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6K+sLQbds6lT1EQKsvW+QH4EoaymFe0n2zEViQ0TTtE=; b=cVvERGAR9ZDjsCLfMz6MESVacPIuLG8icEg0rKSPWxT7+6NFoAASq2s3H/KmoVuUl4 9f59HEeGpHfRj9NFe22Y+kqk8O+bpnzFwnzCkvgfvLgrlr6USEUjIHm3Tc8UerarnDSX fp5cTKX4HJLd7AWU7MtYsQS7UU4xel2Z1eh3g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6K+sLQbds6lT1EQKsvW+QH4EoaymFe0n2zEViQ0TTtE=; b=F5ndXTbbuu7oDPlYBkRXeIxN6YKFFCokiquXk2JEWfDLFm/FznTkTElY54MKLtoVHJ 5bU0EKosa5brtCG2wqbcR/rFLlLG34XtX10Cq4Iv1+P+0arG7+rySzpLHVsDX3QjGGmH m71c576APEVLBeDJnFbeeJq/REmDmqJq+wD1ob5+cXtA5JnZkmHpoUbHVn1/XVxvb8du tPEOTwC4iT7UKsCAUT24U6K2jQ3MLJ8npp7O9Qcbeel8drWmdG7HR9ICkrgyZGaawm9t PtoA58bMgO1pf7BH4gjxihBZPSiMBgYIDJ1kYk7Og2fpdR4MTwCeZd21xHMwocj3A1q5 NIqA== X-Gm-Message-State: AOAM530ukyojTzAz4rofBfVigTMar/l+Vq5LPbiGmtS74aQK+clNIT0R 2Bh7Mb9/AkXNsdFMrIv6chn1cQ== X-Google-Smtp-Source: ABdhPJzQmPns0kBAA60ayRdmhDvciIE9lgEoYhfBVgerB6EDy1NMQs0Tx7MT1YRWXh23VK7AIUSXHQ== X-Received: by 2002:a63:4c5d:: with SMTP id m29mr24117617pgl.368.1608713774304; Wed, 23 Dec 2020 00:56:14 -0800 (PST) Received: from chromium.org ([2401:fa00:8f:2:a28c:fdff:fef0:43bf]) by smtp.gmail.com with ESMTPSA id c10sm23942098pfj.54.2020.12.23.00.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 00:56:13 -0800 (PST) Date: Wed, 23 Dec 2020 17:56:08 +0900 From: Tomasz Figa To: Yong Wu Cc: Joerg Roedel , Will Deacon , Robin Murphy , youlin.pei@mediatek.com, anan.sun@mediatek.com, Nicolas Boichat , srv_heupstream@mediatek.com, chao.hao@mediatek.com, linux-kernel@vger.kernel.org, Krzysztof Kozlowski , Tomasz Figa , iommu@lists.linux-foundation.org, linux-mediatek@lists.infradead.org, Matthias Brugger , Greg Kroah-Hartman , kernel-team@android.com, linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH v3 6/7] iommu/mediatek: Gather iova in iommu_unmap to achieve tlb sync once Message-ID: References: <20201216103607.23050-1-yong.wu@mediatek.com> <20201216103607.23050-7-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201216103607.23050-7-yong.wu@mediatek.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Dec 16, 2020 at 06:36:06PM +0800, Yong Wu wrote: > In current iommu_unmap, this code is: > > iommu_iotlb_gather_init(&iotlb_gather); > ret = __iommu_unmap(domain, iova, size, &iotlb_gather); > iommu_iotlb_sync(domain, &iotlb_gather); > > We could gather the whole iova range in __iommu_unmap, and then do tlb > synchronization in the iommu_iotlb_sync. > > This patch implement this, Gather the range in mtk_iommu_unmap. > then iommu_iotlb_sync call tlb synchronization for the gathered iova range. > we don't call iommu_iotlb_gather_add_page since our tlb synchronization > could be regardless of granule size. > > In this way, gather->start is impossible ULONG_MAX, remove the checking. > > This patch aims to do tlb synchronization *once* in the iommu_unmap. > > Signed-off-by: Yong Wu > --- > drivers/iommu/mtk_iommu.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c > index db7d43adb06b..89cec51405cd 100644 > --- a/drivers/iommu/mtk_iommu.c > +++ b/drivers/iommu/mtk_iommu.c > @@ -506,7 +506,12 @@ static size_t mtk_iommu_unmap(struct iommu_domain *domain, > struct iommu_iotlb_gather *gather) > { > struct mtk_iommu_domain *dom = to_mtk_domain(domain); > + unsigned long long end = iova + size; > > + if (gather->start > iova) > + gather->start = iova; > + if (gather->end < end) > + gather->end = end; I don't know how common the case is, but what happens if gather->start...gather->end is a disjoint range from iova...end? E.g. | gather | ..XXX... | iova | | | | | gather->start | iova | gather->end end We would also end up invalidating the TLB for the XXX area, which could affect the performance. Also, why is the existing code in __arm_v7s_unmap() not enough? It seems to call io_pgtable_tlb_add_page() already, so it should be batching the flushes. > return dom->iop->unmap(dom->iop, iova, size, gather); > } > > @@ -523,9 +528,6 @@ static void mtk_iommu_iotlb_sync(struct iommu_domain *domain, > struct mtk_iommu_domain *dom = to_mtk_domain(domain); > size_t length = gather->end - gather->start; > > - if (gather->start == ULONG_MAX) > - return; > - > mtk_iommu_tlb_flush_range_sync(gather->start, length, gather->pgsize, > dom->data); > } > -- > 2.18.0 > > _______________________________________________ > iommu mailing list > iommu@lists.linux-foundation.org > https://lists.linuxfoundation.org/mailman/listinfo/iommu From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FC7FC433DB for ; Wed, 23 Dec 2020 08:56:18 +0000 (UTC) Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9FBF3206D6 for ; Wed, 23 Dec 2020 08:56:17 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9FBF3206D6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=iommu-bounces@lists.linux-foundation.org Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id 56A8185CAA; Wed, 23 Dec 2020 08:56:17 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id fppajUvq4QHQ; Wed, 23 Dec 2020 08:56:16 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by fraxinus.osuosl.org (Postfix) with ESMTP id C736B85485; Wed, 23 Dec 2020 08:56:16 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id AE6DFC1787; Wed, 23 Dec 2020 08:56:16 +0000 (UTC) Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 6C443C0893 for ; Wed, 23 Dec 2020 08:56:15 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 559AD87241 for ; Wed, 23 Dec 2020 08:56:15 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WZBquio04Qx4 for ; Wed, 23 Dec 2020 08:56:14 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) by hemlock.osuosl.org (Postfix) with ESMTPS id A96A38723B for ; Wed, 23 Dec 2020 08:56:14 +0000 (UTC) Received: by mail-pg1-f169.google.com with SMTP id i7so10206963pgc.8 for ; Wed, 23 Dec 2020 00:56:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6K+sLQbds6lT1EQKsvW+QH4EoaymFe0n2zEViQ0TTtE=; b=cVvERGAR9ZDjsCLfMz6MESVacPIuLG8icEg0rKSPWxT7+6NFoAASq2s3H/KmoVuUl4 9f59HEeGpHfRj9NFe22Y+kqk8O+bpnzFwnzCkvgfvLgrlr6USEUjIHm3Tc8UerarnDSX fp5cTKX4HJLd7AWU7MtYsQS7UU4xel2Z1eh3g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6K+sLQbds6lT1EQKsvW+QH4EoaymFe0n2zEViQ0TTtE=; b=CfTM1UYDJNNtDftdAPcEKEUe8kKAMRuwyAZMaqZfdvpx3LNxC7sVbGT0YDYI487WM/ KlUdHVKp3ODHHIWRmH8BUDSr5/4l7D/0T1IVm/sq7XPWq3PFF2qEF5cs8VYyHdXzOvs9 +FAPyMCRB3aszZUmo3LP/woPAexTC5qTRD41AXJEjMwJ8L5gxkd/+9lUxAcPR0j7yt6H dG+nSeKv0Slye41DLOo4VtQRiCkY9/U0EMpmLfxSt+2JASYWxeykzc/CSQZpGyytvlM4 EzQyKd/GsT9m0pNkvAY1NSfw3pdeOEoYexzzvccKBwngbuJnbKSpaQSwl2e1vvKeLbww ar8w== X-Gm-Message-State: AOAM532LiGecoKpQRM6WnyV9unokPdWVeiQH0Y3X/TB3chwj9Gcg7464 R4tsQFqg3aP3CBAV46JcyuAd5w== X-Google-Smtp-Source: ABdhPJzQmPns0kBAA60ayRdmhDvciIE9lgEoYhfBVgerB6EDy1NMQs0Tx7MT1YRWXh23VK7AIUSXHQ== X-Received: by 2002:a63:4c5d:: with SMTP id m29mr24117617pgl.368.1608713774304; Wed, 23 Dec 2020 00:56:14 -0800 (PST) Received: from chromium.org ([2401:fa00:8f:2:a28c:fdff:fef0:43bf]) by smtp.gmail.com with ESMTPSA id c10sm23942098pfj.54.2020.12.23.00.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 00:56:13 -0800 (PST) Date: Wed, 23 Dec 2020 17:56:08 +0900 From: Tomasz Figa To: Yong Wu Subject: Re: [PATCH v3 6/7] iommu/mediatek: Gather iova in iommu_unmap to achieve tlb sync once Message-ID: References: <20201216103607.23050-1-yong.wu@mediatek.com> <20201216103607.23050-7-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201216103607.23050-7-yong.wu@mediatek.com> Cc: youlin.pei@mediatek.com, anan.sun@mediatek.com, Nicolas Boichat , srv_heupstream@mediatek.com, Tomasz Figa , Will Deacon , linux-kernel@vger.kernel.org, Krzysztof Kozlowski , chao.hao@mediatek.com, iommu@lists.linux-foundation.org, linux-mediatek@lists.infradead.org, Matthias Brugger , kernel-team@android.com, Greg Kroah-Hartman , Robin Murphy , linux-arm-kernel@lists.infradead.org X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Development issues for Linux IOMMU support List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: iommu-bounces@lists.linux-foundation.org Sender: "iommu" On Wed, Dec 16, 2020 at 06:36:06PM +0800, Yong Wu wrote: > In current iommu_unmap, this code is: > > iommu_iotlb_gather_init(&iotlb_gather); > ret = __iommu_unmap(domain, iova, size, &iotlb_gather); > iommu_iotlb_sync(domain, &iotlb_gather); > > We could gather the whole iova range in __iommu_unmap, and then do tlb > synchronization in the iommu_iotlb_sync. > > This patch implement this, Gather the range in mtk_iommu_unmap. > then iommu_iotlb_sync call tlb synchronization for the gathered iova range. > we don't call iommu_iotlb_gather_add_page since our tlb synchronization > could be regardless of granule size. > > In this way, gather->start is impossible ULONG_MAX, remove the checking. > > This patch aims to do tlb synchronization *once* in the iommu_unmap. > > Signed-off-by: Yong Wu > --- > drivers/iommu/mtk_iommu.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c > index db7d43adb06b..89cec51405cd 100644 > --- a/drivers/iommu/mtk_iommu.c > +++ b/drivers/iommu/mtk_iommu.c > @@ -506,7 +506,12 @@ static size_t mtk_iommu_unmap(struct iommu_domain *domain, > struct iommu_iotlb_gather *gather) > { > struct mtk_iommu_domain *dom = to_mtk_domain(domain); > + unsigned long long end = iova + size; > > + if (gather->start > iova) > + gather->start = iova; > + if (gather->end < end) > + gather->end = end; I don't know how common the case is, but what happens if gather->start...gather->end is a disjoint range from iova...end? E.g. | gather | ..XXX... | iova | | | | | gather->start | iova | gather->end end We would also end up invalidating the TLB for the XXX area, which could affect the performance. Also, why is the existing code in __arm_v7s_unmap() not enough? It seems to call io_pgtable_tlb_add_page() already, so it should be batching the flushes. > return dom->iop->unmap(dom->iop, iova, size, gather); > } > > @@ -523,9 +528,6 @@ static void mtk_iommu_iotlb_sync(struct iommu_domain *domain, > struct mtk_iommu_domain *dom = to_mtk_domain(domain); > size_t length = gather->end - gather->start; > > - if (gather->start == ULONG_MAX) > - return; > - > mtk_iommu_tlb_flush_range_sync(gather->start, length, gather->pgsize, > dom->data); > } > -- > 2.18.0 > > _______________________________________________ > iommu mailing list > iommu@lists.linux-foundation.org > https://lists.linuxfoundation.org/mailman/listinfo/iommu _______________________________________________ iommu mailing list iommu@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/iommu From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D225C433E0 for ; Wed, 23 Dec 2020 08:56:34 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B070A20684 for ; Wed, 23 Dec 2020 08:56:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B070A20684 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=8LhH1fcLbrusLealGKrNzPe8LrSjkAO4qntt+n2gQZ0=; b=a3jKinQUHLb7ogg0g7g1NTuiN tMlX4ikAAGyw4AKtjb6Bm9oGNzVSOwuddsCD1scKkI8G7di1rEXHLB91muVtv6ZY8Mem5t5c1f9kF rnzxcq/EKIP/3BqXUpti4j+8f3ogIMMJSX+VAOcW8C/GptjxpcHwWUlyF2xgp1LMc75MGXJoTvG8N YElj3GfFLU57GsmfLh1SBtTzFRNCyCHkXrql1uD7yDBhNdY36ne7ufLDK5t6KsyWBBxoyGAn2HuNk 7SS6ufbOT8OjZYzIs2Zz26TNuLWWKaSJKgAXLW9virNAklEAJ4UTIpkyX7oZZVbdV5SptEvWudOD5 TN53QWMAg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1krzwV-0001Qe-4z; Wed, 23 Dec 2020 08:56:23 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1krzwO-0001OQ-JD for linux-mediatek@lists.infradead.org; Wed, 23 Dec 2020 08:56:18 +0000 Received: by mail-pf1-x434.google.com with SMTP id f9so9979148pfc.11 for ; Wed, 23 Dec 2020 00:56:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6K+sLQbds6lT1EQKsvW+QH4EoaymFe0n2zEViQ0TTtE=; b=cVvERGAR9ZDjsCLfMz6MESVacPIuLG8icEg0rKSPWxT7+6NFoAASq2s3H/KmoVuUl4 9f59HEeGpHfRj9NFe22Y+kqk8O+bpnzFwnzCkvgfvLgrlr6USEUjIHm3Tc8UerarnDSX fp5cTKX4HJLd7AWU7MtYsQS7UU4xel2Z1eh3g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6K+sLQbds6lT1EQKsvW+QH4EoaymFe0n2zEViQ0TTtE=; b=hxnI5BvWt1gHUXMN2EUBFil/3FhiZR4zKCuTPRUudCy6fG+iTbQvBIGl7sS27cOExv YGn1Aalkx2HRk6jbxHoR2VkwWKkfFjYQSgS6HzfA45g2SE1EJNOFhvFaDy9lrho25usM u1SaOL40CPvSUpDmGUAwuZZMw9qL05PNjJRpdZmd45rb0ug2AIpCbmxMSfNrbzB3ZCqu 96WInCBYK/HhXeuL8jWHfpeDGocdZ0av4PRxLyf8kkB2dwLx/u6eJYJvzh58zSJmfwyT sFRC0WIOgUs9wC+Qd5u2eEagklZC73cU4+p/zvJiPnlhQdny/QvWBfq+xezALiuvoPXA Uf1g== X-Gm-Message-State: AOAM532/EVj03EHNBZoq3py2rRQcdaK0G57y3gWmmFAFVJxble3Ki8R0 FLu++O1nX5L6QRykiBgLH78NsA== X-Google-Smtp-Source: ABdhPJzQmPns0kBAA60ayRdmhDvciIE9lgEoYhfBVgerB6EDy1NMQs0Tx7MT1YRWXh23VK7AIUSXHQ== X-Received: by 2002:a63:4c5d:: with SMTP id m29mr24117617pgl.368.1608713774304; Wed, 23 Dec 2020 00:56:14 -0800 (PST) Received: from chromium.org ([2401:fa00:8f:2:a28c:fdff:fef0:43bf]) by smtp.gmail.com with ESMTPSA id c10sm23942098pfj.54.2020.12.23.00.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 00:56:13 -0800 (PST) Date: Wed, 23 Dec 2020 17:56:08 +0900 From: Tomasz Figa To: Yong Wu Subject: Re: [PATCH v3 6/7] iommu/mediatek: Gather iova in iommu_unmap to achieve tlb sync once Message-ID: References: <20201216103607.23050-1-yong.wu@mediatek.com> <20201216103607.23050-7-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201216103607.23050-7-yong.wu@mediatek.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201223_035616_769145_110D7A8D X-CRM114-Status: GOOD ( 26.85 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: youlin.pei@mediatek.com, anan.sun@mediatek.com, Nicolas Boichat , srv_heupstream@mediatek.com, Tomasz Figa , Will Deacon , Joerg Roedel , linux-kernel@vger.kernel.org, Krzysztof Kozlowski , chao.hao@mediatek.com, iommu@lists.linux-foundation.org, linux-mediatek@lists.infradead.org, Matthias Brugger , kernel-team@android.com, Greg Kroah-Hartman , Robin Murphy , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org On Wed, Dec 16, 2020 at 06:36:06PM +0800, Yong Wu wrote: > In current iommu_unmap, this code is: > > iommu_iotlb_gather_init(&iotlb_gather); > ret = __iommu_unmap(domain, iova, size, &iotlb_gather); > iommu_iotlb_sync(domain, &iotlb_gather); > > We could gather the whole iova range in __iommu_unmap, and then do tlb > synchronization in the iommu_iotlb_sync. > > This patch implement this, Gather the range in mtk_iommu_unmap. > then iommu_iotlb_sync call tlb synchronization for the gathered iova range. > we don't call iommu_iotlb_gather_add_page since our tlb synchronization > could be regardless of granule size. > > In this way, gather->start is impossible ULONG_MAX, remove the checking. > > This patch aims to do tlb synchronization *once* in the iommu_unmap. > > Signed-off-by: Yong Wu > --- > drivers/iommu/mtk_iommu.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c > index db7d43adb06b..89cec51405cd 100644 > --- a/drivers/iommu/mtk_iommu.c > +++ b/drivers/iommu/mtk_iommu.c > @@ -506,7 +506,12 @@ static size_t mtk_iommu_unmap(struct iommu_domain *domain, > struct iommu_iotlb_gather *gather) > { > struct mtk_iommu_domain *dom = to_mtk_domain(domain); > + unsigned long long end = iova + size; > > + if (gather->start > iova) > + gather->start = iova; > + if (gather->end < end) > + gather->end = end; I don't know how common the case is, but what happens if gather->start...gather->end is a disjoint range from iova...end? E.g. | gather | ..XXX... | iova | | | | | gather->start | iova | gather->end end We would also end up invalidating the TLB for the XXX area, which could affect the performance. Also, why is the existing code in __arm_v7s_unmap() not enough? It seems to call io_pgtable_tlb_add_page() already, so it should be batching the flushes. > return dom->iop->unmap(dom->iop, iova, size, gather); > } > > @@ -523,9 +528,6 @@ static void mtk_iommu_iotlb_sync(struct iommu_domain *domain, > struct mtk_iommu_domain *dom = to_mtk_domain(domain); > size_t length = gather->end - gather->start; > > - if (gather->start == ULONG_MAX) > - return; > - > mtk_iommu_tlb_flush_range_sync(gather->start, length, gather->pgsize, > dom->data); > } > -- > 2.18.0 > > _______________________________________________ > iommu mailing list > iommu@lists.linux-foundation.org > https://lists.linuxfoundation.org/mailman/listinfo/iommu _______________________________________________ Linux-mediatek mailing list Linux-mediatek@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-mediatek From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3FA2DC433E0 for ; Wed, 23 Dec 2020 08:57:39 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D829220684 for ; Wed, 23 Dec 2020 08:57:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D829220684 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=T72P+yhPgcSCUIQKtqzNOoyRNNVlsXunnuX1uIwhyBc=; b=oMeYzCb/ZxKfIBEvZCceAYvkO v7QbWVrr8weI9BVez6q5L0j9zETJjUDpc+fmAbbo8p+C4yDX+1nlZPkNfVlPFqcUCZFLrk8v1i4cp UbOcEjXKgy9PoKxutV5U6rtKQTs1/NPFPHMm2xN0p3lsrjTynWyARdEveyt5O6jk44RwDKnoCiLC2 KUqpfyG2pGh27gILla09snTDmmlAO+cBjXMLuHKJUjRPG7S+H1jMMSnpsrhqjAV3ulngA5Dp49ieS l9jNFjLkbgIWnezyDbzqFm9qKVl3i/3JhIv98j9vHCHXY5l1APYt7B0wZXSMFJUUt+K/ymQYZX3Lt fOF25BCAQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1krzwS-0001QA-Ja; Wed, 23 Dec 2020 08:56:20 +0000 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1krzwO-0001OP-JD for linux-arm-kernel@lists.infradead.org; Wed, 23 Dec 2020 08:56:18 +0000 Received: by mail-pf1-x42c.google.com with SMTP id 11so9995440pfu.4 for ; Wed, 23 Dec 2020 00:56:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=6K+sLQbds6lT1EQKsvW+QH4EoaymFe0n2zEViQ0TTtE=; b=cVvERGAR9ZDjsCLfMz6MESVacPIuLG8icEg0rKSPWxT7+6NFoAASq2s3H/KmoVuUl4 9f59HEeGpHfRj9NFe22Y+kqk8O+bpnzFwnzCkvgfvLgrlr6USEUjIHm3Tc8UerarnDSX fp5cTKX4HJLd7AWU7MtYsQS7UU4xel2Z1eh3g= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=6K+sLQbds6lT1EQKsvW+QH4EoaymFe0n2zEViQ0TTtE=; b=ltR5nE8+xUts4aUaRRfBXWtJcyOuMPMxPalxfJI+BKg4Jo6OJIbZE4Kocq3WeispTt Llrd8d/IHDhT9APIeWMDF/aKN6lWufms8/2gKgkDfISy9NHgSG+u3YObE5n32Fn4Y3Fk RHXHewG8DBHDCCREllPOlRy475IuyxujD1uxm/kbeOQsJ/IIwzfvxdva0YxR8NrFGC1V olwYUMevJi+JZenY+zR3S3cvVEKLlJ776Qmj0s/7HL9J/PJb2dfsT5eyUonVO4MjbVAg T23FI4snC4HBw3Wd/89OL+Odrah6xKLxFKXKCZHJ2azsL7S6Ea+89vhMAN7Ym7Nsq9RN ddRQ== X-Gm-Message-State: AOAM531eAg/GWePTNc6VfzhWKq0D+GDG4y3vuY/v/JkBLYPZdp4BQW6G tccyokaJN3g5Vx/xLFH0sY1DrQ== X-Google-Smtp-Source: ABdhPJzQmPns0kBAA60ayRdmhDvciIE9lgEoYhfBVgerB6EDy1NMQs0Tx7MT1YRWXh23VK7AIUSXHQ== X-Received: by 2002:a63:4c5d:: with SMTP id m29mr24117617pgl.368.1608713774304; Wed, 23 Dec 2020 00:56:14 -0800 (PST) Received: from chromium.org ([2401:fa00:8f:2:a28c:fdff:fef0:43bf]) by smtp.gmail.com with ESMTPSA id c10sm23942098pfj.54.2020.12.23.00.56.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Dec 2020 00:56:13 -0800 (PST) Date: Wed, 23 Dec 2020 17:56:08 +0900 From: Tomasz Figa To: Yong Wu Subject: Re: [PATCH v3 6/7] iommu/mediatek: Gather iova in iommu_unmap to achieve tlb sync once Message-ID: References: <20201216103607.23050-1-yong.wu@mediatek.com> <20201216103607.23050-7-yong.wu@mediatek.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20201216103607.23050-7-yong.wu@mediatek.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201223_035616_773849_5BBDD96C X-CRM114-Status: GOOD ( 28.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: youlin.pei@mediatek.com, anan.sun@mediatek.com, Nicolas Boichat , srv_heupstream@mediatek.com, Tomasz Figa , Will Deacon , Joerg Roedel , linux-kernel@vger.kernel.org, Krzysztof Kozlowski , chao.hao@mediatek.com, iommu@lists.linux-foundation.org, linux-mediatek@lists.infradead.org, Matthias Brugger , kernel-team@android.com, Greg Kroah-Hartman , Robin Murphy , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Dec 16, 2020 at 06:36:06PM +0800, Yong Wu wrote: > In current iommu_unmap, this code is: > > iommu_iotlb_gather_init(&iotlb_gather); > ret = __iommu_unmap(domain, iova, size, &iotlb_gather); > iommu_iotlb_sync(domain, &iotlb_gather); > > We could gather the whole iova range in __iommu_unmap, and then do tlb > synchronization in the iommu_iotlb_sync. > > This patch implement this, Gather the range in mtk_iommu_unmap. > then iommu_iotlb_sync call tlb synchronization for the gathered iova range. > we don't call iommu_iotlb_gather_add_page since our tlb synchronization > could be regardless of granule size. > > In this way, gather->start is impossible ULONG_MAX, remove the checking. > > This patch aims to do tlb synchronization *once* in the iommu_unmap. > > Signed-off-by: Yong Wu > --- > drivers/iommu/mtk_iommu.c | 8 +++++--- > 1 file changed, 5 insertions(+), 3 deletions(-) > > diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c > index db7d43adb06b..89cec51405cd 100644 > --- a/drivers/iommu/mtk_iommu.c > +++ b/drivers/iommu/mtk_iommu.c > @@ -506,7 +506,12 @@ static size_t mtk_iommu_unmap(struct iommu_domain *domain, > struct iommu_iotlb_gather *gather) > { > struct mtk_iommu_domain *dom = to_mtk_domain(domain); > + unsigned long long end = iova + size; > > + if (gather->start > iova) > + gather->start = iova; > + if (gather->end < end) > + gather->end = end; I don't know how common the case is, but what happens if gather->start...gather->end is a disjoint range from iova...end? E.g. | gather | ..XXX... | iova | | | | | gather->start | iova | gather->end end We would also end up invalidating the TLB for the XXX area, which could affect the performance. Also, why is the existing code in __arm_v7s_unmap() not enough? It seems to call io_pgtable_tlb_add_page() already, so it should be batching the flushes. > return dom->iop->unmap(dom->iop, iova, size, gather); > } > > @@ -523,9 +528,6 @@ static void mtk_iommu_iotlb_sync(struct iommu_domain *domain, > struct mtk_iommu_domain *dom = to_mtk_domain(domain); > size_t length = gather->end - gather->start; > > - if (gather->start == ULONG_MAX) > - return; > - > mtk_iommu_tlb_flush_range_sync(gather->start, length, gather->pgsize, > dom->data); > } > -- > 2.18.0 > > _______________________________________________ > iommu mailing list > iommu@lists.linux-foundation.org > https://lists.linuxfoundation.org/mailman/listinfo/iommu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel