Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp5175792pxj; Wed, 9 Jun 2021 10:52:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOSfKubPzqzCEI6GSubxST/iPVgSr0hsYhwwUSPZIYYm7KVikFjuoUHg+OupiyFYC+obHv X-Received: by 2002:a05:6402:10cc:: with SMTP id p12mr622591edu.328.1623261177962; Wed, 09 Jun 2021 10:52:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623261177; cv=none; d=google.com; s=arc-20160816; b=ZAWBn+YKEK9YLUH7yzRnN1lrh6dJ5DoVyp8DgTJtmCXovR0GXN0x+XcaCjkNNA2pi/ Xf28JTqvepqbd90fQsjkIsb8dOhqVTRTpR3W8Gkt+rl1CgX/iRIVlXoZJqMvBsBvV7FR XtfA7EYvXwYbb9hF6G7E2mgxI9IvtdQtmthBtGdHhMmNMiVp/H5Uqtp4yFXqbTthBy7j uZH+UY8cPWBP6NOKojDxgF0GDDsngFPoIHqfGhYV0x0thkJGRL/mrIkJVkPd7StR3/MR YjpaOveYJQTdeKqgt3WXlV0u0R5SURFkoVXcWdQi9ONacmd+8vqzYS6MJWVK9czOEzdW wpHw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dmarc-filter:sender :dkim-signature; bh=VGxI7DNKJ4SftViaONqW/6OR8ZWMMCYv9JR2M0yYWr4=; b=MsXFxwl6twkoXUsNn5WaKZcVXqP1s82oKceAnJu7JvhkUSq/4bNaapc7yFeRztAwRq pRubpUTGKoLjEbBBjOni6eXA3OVueRXr20CpnCXwdH18Dbv6UN6xMyhU0YR9l/PQczSS hv4nENoYJwf0qmEP5PaCuDHY0kOj7Y2Nj+WS/Won8u/M74B7ajox6dNL4/mnxhfZtuYE VBCYW4Ty4wPv00V/pMDiTKasr1L3IxvT17aCJG3hAuoX0PSJSmzE8o+BMsjWLMxqmuzq x0OozjiIXB0GgFoL/6jWva6J4l5bzX2rCBcfPP0DO6vnZ/FgOZyEYLcg59WXgrxYO52g poWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=ka7hZtez; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd1si311598edb.49.2021.06.09.10.52.33; Wed, 09 Jun 2021 10:52:57 -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; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b=ka7hZtez; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238369AbhFIOzm (ORCPT + 99 others); Wed, 9 Jun 2021 10:55:42 -0400 Received: from m43-7.mailgun.net ([69.72.43.7]:29898 "EHLO m43-7.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230239AbhFIOzm (ORCPT ); Wed, 9 Jun 2021 10:55:42 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1623250427; h=Content-Transfer-Encoding: MIME-Version: Message-Id: Date: Subject: Cc: To: From: Sender; bh=VGxI7DNKJ4SftViaONqW/6OR8ZWMMCYv9JR2M0yYWr4=; b=ka7hZtez0/LtIunrb2xZtQGNEtTUqXcJ8JaKu8EYZxSmG6cedO3luvBPBVRL0njleKdWT6PS S87bE8Ykwlt/3WKXN+0jx/wt/x/jvqh2fC6YdIUDsewBj0NmkWiXjoXz68sFMle5hh+mliz0 bdWOrsBho2rEDWHGj2wJBL1O9r0= X-Mailgun-Sending-Ip: 69.72.43.7 X-Mailgun-Sid: WyI0MWYwYSIsICJsaW51eC1rZXJuZWxAdmdlci5rZXJuZWwub3JnIiwgImJlOWU0YSJd Received: from smtp.codeaurora.org (ec2-35-166-182-171.us-west-2.compute.amazonaws.com [35.166.182.171]) by smtp-out-n07.prod.us-west-2.postgun.com with SMTP id 60c0d5e5b6ccaab7531d7238 (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Wed, 09 Jun 2021 14:53:25 GMT Sender: saiprakash.ranjan=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id 3FCC5C43145; Wed, 9 Jun 2021 14:53:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-caf-mail-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=ALL_TRUSTED,BAYES_00,SPF_FAIL autolearn=no autolearn_force=no version=3.4.0 Received: from blr-ubuntu-253.qualcomm.com (blr-bdr-fw-01_GlobalNAT_AllZones-Outside.qualcomm.com [103.229.18.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: saiprakash.ranjan) by smtp.codeaurora.org (Postfix) with ESMTPSA id D312DC433F1; Wed, 9 Jun 2021 14:53:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org D312DC433F1 Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: aws-us-west-2-caf-mail-1.web.codeaurora.org; spf=fail smtp.mailfrom=saiprakash.ranjan@codeaurora.org From: Sai Prakash Ranjan To: Will Deacon , Robin Murphy , 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, Sai Prakash Ranjan Subject: [PATCH] iommu/io-pgtable-arm: Optimize partial walk flush for large scatter-gather list Date: Wed, 9 Jun 2021 20:23:14 +0530 Message-Id: <20210609145315.25750-1-saiprakash.ranjan@codeaurora.org> X-Mailer: git-send-email 2.29.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 + 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) { -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation