Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3484336pxj; Sun, 20 Jun 2021 22:49:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyTXOIViInODmrInhFProcYAYL6AiuyxnOoRWoJHgw6nFIDaY3vZm6HptT3qtusKZ2fPFfY X-Received: by 2002:a17:906:b55:: with SMTP id v21mr22925815ejg.88.1624254593905; Sun, 20 Jun 2021 22:49:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1624254593; cv=none; d=google.com; s=arc-20160816; b=Nlrb402/fJ7qyJJpEE5gEx4HgvPnRbSFxDKu0UM3LxqZB4ZV5p8vUqmzXCrdpe3TXu SCKrfuVmKDaWc0hlYXJjKn+biRIlvzv1dp+kDWvEP42EFAYkr0c9pR2O7kXHZxB2dafB q2RFemMRUatK8titrhStg8dTPmKnOYII2MFWXqb/r0jr6BFK85/fXKK58z2TGdICPHMA 2XoDe7WQEL//rtCXhKYhSCcVYgmHC7b+hjlxZmeqfT5PTAYuOzzoMEfOA9fEfV5zQImH ZiLx2rxxps847VkWrHj8qq295w//12ie00ss5UOLd7n/DuHvXguTxwocVUKF0htOJ5QQ 0Egg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:message-id:references:in-reply-to :subject:cc:to:from:date:content-transfer-encoding:mime-version :sender:dkim-signature; bh=dd/c0WzWEfKMbrpV11k4uuAZn72RvTRCSkxT5YGla6U=; b=BSrDt47ixmDA/RIzBV0xdNOGOS6vpjFaA8Fk091zF2/JdSweYAc8oVnowvQ1XcgHpB NcyEuAVf72n78Twn8QMeNqU1WL+vC89lGDVXnteO/6Q07BXXySR7M5N0gpOXjX0r8c2g ZChMAPtvKUPmKt3xwJgYNy972sfL7I10VATUSuzrmyj+JqZM/NdUBCjTMmepa0vzk6dD zYgVMBqZrh5aHFwj20i8Ww6prbQieGZmBs0HwhT3ePxK172iw6h/dJjfFWtOjbrTBuEc N2lFy7TGYNlyNa4PV4dYqylYtQPUoNivEHI/UscOIOR2rqUwZySILeRCADJdUtWq5OeC Pg/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mg.codeaurora.org header.s=smtp header.b="h/tCvTqE"; 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 g7si9229005ejh.141.2021.06.20.22.49.28; Sun, 20 Jun 2021 22:49:53 -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="h/tCvTqE"; 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 S229479AbhFUFtx (ORCPT + 99 others); Mon, 21 Jun 2021 01:49:53 -0400 Received: from so254-9.mailgun.net ([198.61.254.9]:48879 "EHLO so254-9.mailgun.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbhFUFtw (ORCPT ); Mon, 21 Jun 2021 01:49:52 -0400 DKIM-Signature: a=rsa-sha256; v=1; c=relaxed/relaxed; d=mg.codeaurora.org; q=dns/txt; s=smtp; t=1624254458; h=Message-ID: References: In-Reply-To: Subject: Cc: To: From: Date: Content-Transfer-Encoding: Content-Type: MIME-Version: Sender; bh=dd/c0WzWEfKMbrpV11k4uuAZn72RvTRCSkxT5YGla6U=; b=h/tCvTqElJdF9kMly4CB1B1ce5AMjVXVub6EeDvjQJkiHh/iYTRegbjPW22AIkgoMFDSADXH Twx05c8YXWLo8A7/RlgEUC6cH3dPDmsBRLpw2n3JIHpe4sQBRPk5/Uua6Oq78AagYDHHfjpY Rhcn++optMqlIM9WKglKvgs5Gbk= X-Mailgun-Sending-Ip: 198.61.254.9 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-n06.prod.us-west-2.postgun.com with SMTP id 60d027fa8491191eb3ea9f4f (version=TLS1.2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256); Mon, 21 Jun 2021 05:47:38 GMT Sender: saiprakash.ranjan=codeaurora.org@mg.codeaurora.org Received: by smtp.codeaurora.org (Postfix, from userid 1001) id B895FC43143; Mon, 21 Jun 2021 05:47:37 +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 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.codeaurora.org (localhost.localdomain [127.0.0.1]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: saiprakash.ranjan) by smtp.codeaurora.org (Postfix) with ESMTPSA id 84534C433F1; Mon, 21 Jun 2021 05:47:36 +0000 (UTC) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 21 Jun 2021 11:17:36 +0530 From: Sai Prakash Ranjan To: Doug Anderson Cc: Robin Murphy , Will Deacon , Joerg Roedel , "list@263.net:IOMMU DRIVERS , Joerg Roedel ," , Linux ARM , LKML , linux-arm-msm , Bjorn Andersson , Krishna Reddy , Thierry Reding , Tomasz Figa Subject: Re: [PATCHv2 2/3] iommu/io-pgtable: Optimize partial walk flush for large scatter-gather list In-Reply-To: References: <150fc7ab1c7f9b70a95dae1f4bc3b9018c0f9e04.1623981933.git.saiprakash.ranjan@codeaurora.org> Message-ID: <716fbc51ec73434e325d84752a471e89@codeaurora.org> X-Sender: saiprakash.ranjan@codeaurora.org User-Agent: Roundcube Webmail/1.3.9 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On 2021-06-19 03:39, Doug Anderson wrote: > Hi, > > On Thu, Jun 17, 2021 at 7:51 PM 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 invalidating >> page-by-page on iommus like arm-smmu-v2 (TLBIVA) which do not support >> range based invalidations like on arm-smmu-v3.2. >> >> 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 tlb_flush_all() callback (TLBIALL/TLBIASID) to >> invalidate >> the entire context for partial walk flush on select few platforms >> where >> cost of over-invalidation is less than unmap latency > > It would probably be worth punching this description up a little bit. > Elsewhere you said in more detail why this over-invalidation is less > of a big deal for the Qualcomm SMMU. It's probably worth saying > something like that here, too. Like this bit paraphrased from your > other email: > > On qcom impl, we have several performance improvements for TLB cache > invalidations in HW like wait-for-safe (for realtime clients such as > camera and display) and few others to allow for cache lookups/updates > when TLBI is in progress for the same context bank. > Sure will add this info as well in the next version. > >> using the newly >> introduced quirk IO_PGTABLE_QUIRK_TLB_INV_ALL. We also do this for >> non-strict mode given its all about over-invalidation saving time on >> individual unmaps and non-deterministic generally. > > As per usual I'm mostly clueless, but I don't quite understand why you > want this new behavior for non-strict mode. To me it almost seems like > the opposite? Specifically, non-strict mode is already outside the > critical path today and so there's no need to optimize it. I'm > probably not explaining myself clearly, but I guess i'm thinking: > > a) today for strict, unmap is in the critical path and it's important > to get it out of there. Getting it out of the critical path is so > important that we're willing to over-invalidate to speed up the > critical path. > > b) today for non-strict, unmap is not in the critical path. > > So I would almost expect your patch to _disable_ your new feature for > non-strict mappings, not auto-enable your new feature for non-strict > mappings. > > If I'm babbling, feel free to ignore. ;-) Looking back, I guess Robin > was the one that suggested the behavior you're implementing, so it's > more likely he's right than I am. ;-) > Thanks for taking a look. Non-strict mode is only for leaf entries and dma domains and this optimization is for non-leaf entries and is applicable for both, see __arm_lpae_unmap(). In other words, if you have iommu.strict=0 (non-strict mode) and try unmapping a large sg buffer as the problem described in the commit text, you would still go via this path in unmap and see the delay without this patch. So what Robin suggested is that, let's do this unconditionally for all users with non-strict mode as opposed to only restricting it to implementation specific in case of strict mode. Thanks, Sai -- QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation