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.5 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 6AFF5C433B4 for ; Tue, 6 Apr 2021 12:18:07 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 1661E6139E for ; Tue, 6 Apr 2021 12:18:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1661E6139E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.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=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc: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=jsByGiqKJ3WEjoaT6jc3ARm/otSV0ysKGAwrwWRmQSA=; b=ZrGxAIMevU0mbeccQV9NM1zqK IyYhwbstSzlPtOXVzbk7xLC9OvTOnGnyaBAKfretaWNtO+XdXQONdYbX9nYlZMNd7WbOviJnX4wyf QYlPw6VnvzCnRfZt3srwJDHiCu/KgRpNceupj+TgI//dadVR9aV8nNEXqUJnEekYZkrGQXd637Kfh b04R3SkyHn/M0pzMa/S5a1pXXBvul58HdFteh7cMY7NQHutQ1fwqU8Q4MBQGwPr3v1z3Ppgz36u/g vxgr7mu9Y0cGIx+2xh8/ZRSGBLIlI6ZlRdr4hQFc8jKXlXTsY/e/RB7CxzAL8byjdYznAUSBRroQv oerkeQeaQ==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lTkcm-002Y2V-Nt; Tue, 06 Apr 2021 12:16:04 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lTkcg-002Y0k-UP for linux-arm-kernel@lists.infradead.org; Tue, 06 Apr 2021 12:16:01 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 51DE3613BD; Tue, 6 Apr 2021 12:15:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617711357; bh=bA/5RMPS+MqCFEq4ueYRVrnW78xgwbC/GxYc9ETEp5w=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=t8PA10JOPbGpErhN9KYxRfyRA5RxhZebXDKVG1cSnArPl4XiDEpL1bdC1iWkI5W8U HmJ+dVDKxIzaWEQE8AgrMvLktpF4cTERyUDy7HPgqwF2hZvnnXAHwB+PGkDEf3Ceun Bu10Zl9uBqfPngYliBe2hLiu8IFiOhkIvpI4owaaAIfysJtKGPnc+6OcPaar+Yip20 F8N/011c+zFO8N5UUWmndnEKE/t3R4DPUjPrqNbsDW0PO7LCwIaJbA7W1dX0ieqFG+ q0kZSOXnnCqYB//oBM/Y85ftsREPwx3VLMNFPhAioO8OJ5WFk5Mqt0FvZkDOLi++Jn F/xOXoTkoZ+2A== Date: Tue, 6 Apr 2021 13:15:53 +0100 From: Will Deacon To: "Isaac J. Manjarres" Cc: iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, robin.murphy@arm.com, pratikp@codeaurora.org, baolu.lu@linux.intel.com Subject: Re: [RFC PATCH v3 09/12] iommu/io-pgtable-arm: Implement arm_lpae_unmap_pages() Message-ID: <20210406121552.GF13747@willie-the-truck> References: <20210405191112.28192-1-isaacm@codeaurora.org> <20210405191112.28192-10-isaacm@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210405191112.28192-10-isaacm@codeaurora.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210406_131559_661051_54068E1F X-CRM114-Status: GOOD ( 19.97 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , 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 Mon, Apr 05, 2021 at 12:11:09PM -0700, Isaac J. Manjarres wrote: > Implement the unmap_pages() callback for the ARM LPAE io-pgtable > format. > > Signed-off-by: Isaac J. Manjarres > Suggested-by: Will Deacon > --- > drivers/iommu/io-pgtable-arm.c | 124 +++++++++++++++++++++++++++------ > 1 file changed, 104 insertions(+), 20 deletions(-) [...] > +static size_t arm_lpae_unmap_pages(struct io_pgtable_ops *ops, unsigned long iova, > + size_t pgsize, size_t pgcount, > + struct iommu_iotlb_gather *gather) > +{ > + struct arm_lpae_io_pgtable *data = io_pgtable_ops_to_data(ops); > + struct io_pgtable_cfg *cfg = &data->iop.cfg; > + arm_lpae_iopte *ptep = data->pgd; > + long iaext = (s64)iova >> cfg->ias; > + size_t unmapped = 0, unmapped_page; > + int last_lvl; > + size_t table_size, pages, tbl_offset, max_entries; > + > + if (WARN_ON(!pgsize || (pgsize & cfg->pgsize_bitmap) != pgsize || !pgcount)) > + return 0; > + > + if (cfg->quirks & IO_PGTABLE_QUIRK_ARM_TTBR1) > + iaext = ~iaext; > + if (WARN_ON(iaext)) > + return 0; > + > + /* > + * Calculating the page table size here helps avoid situations where > + * a page range that is being unmapped may be mapped at the same level > + * but not mapped by the same tables. Allowing such a scenario to > + * occur can complicate the logic in arm_lpae_split_blk_unmap(). > + */ > + last_lvl = ARM_LPAE_BLOCK_SIZE_LVL(pgsize, data); > + > + if (last_lvl == data->start_level) > + table_size = ARM_LPAE_PGD_SIZE(data); > + else > + table_size = ARM_LPAE_GRANULE(data); > + > + max_entries = table_size / sizeof(*ptep); > + > + while (pgcount) { > + tbl_offset = ARM_LPAE_LVL_IDX(iova, last_lvl, data); > + pages = min_t(size_t, pgcount, max_entries - tbl_offset); > + unmapped_page = __arm_lpae_unmap(data, gather, iova, pgsize, > + pages, data->start_level, > + ptep); > + if (!unmapped_page) > + break; > + > + unmapped += unmapped_page; > + iova += unmapped_page; > + pgcount -= pages; > + } Robin has some comments on the first version of this patch, and I don't think you addressed them: https://lore.kernel.org/r/b93fa0b1-e2a4-1aad-8b88-4d0dfecdfef7@arm.com I'm inclined to agree that iterating here doesn't make a lot of sense -- we've already come back out of the page-table walk, so I think we should just return to the caller (who is well prepared to handle a partial unmap). Same for the map side of things. If we get numbers showing that this is causing a performance issue, then we should rework the page-table code to handle this at the lower level (because I doubt the loop that you have is really worse than returning to the caller anyway). Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel