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=-12.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,USER_AGENT_SANE_1 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 75015C433B4 for ; Thu, 8 Apr 2021 14:32:21 +0000 (UTC) Received: from smtp3.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (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 1B6E061104 for ; Thu, 8 Apr 2021 14:32:21 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B6E061104 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.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 smtp3.osuosl.org (Postfix) with ESMTP id D9A84606F0; Thu, 8 Apr 2021 14:32:20 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from smtp3.osuosl.org ([127.0.0.1]) by localhost (smtp3.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id X0CC3A6R9ND8; Thu, 8 Apr 2021 14:32:19 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by smtp3.osuosl.org (Postfix) with ESMTP id 82D45606EC; Thu, 8 Apr 2021 14:32:19 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 67CFDC000C; Thu, 8 Apr 2021 14:32:19 +0000 (UTC) Received: from smtp1.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id A35AFC000A for ; Thu, 8 Apr 2021 14:32:18 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by smtp1.osuosl.org (Postfix) with ESMTP id 92B62841AA for ; Thu, 8 Apr 2021 14:32:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Authentication-Results: smtp1.osuosl.org (amavisd-new); dkim=pass (2048-bit key) header.d=kernel.org Received: from smtp1.osuosl.org ([127.0.0.1]) by localhost (smtp1.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ukVOmhMl6nBZ for ; Thu, 8 Apr 2021 14:32:18 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.8.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp1.osuosl.org (Postfix) with ESMTPS id 04B18841A9 for ; Thu, 8 Apr 2021 14:32:17 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 7C4F4610CC; Thu, 8 Apr 2021 14:32:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617892335; bh=dCSZUf5qRFCdJRNa1E7k/U97LHBatePsybZ6J/TrTNI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WZ4+rQV3FbcAYMb5Fm/QEPV+j+Gdzu8vGVFdO8/jXedrtE0tEjQtshrU8YUQdJFEt BXVSY3ETIYaEiHEniXLLgUdUNOW0L4xslVHgxN0jQ7EgSQCfV5/nmso3lKurEGpW9N Xt6X7fH7lH0H9+/au7QIfrT+vrpeNokml5M9kma5SjaOmf6E+pZdJ1njxkEgXf4ZUt +yJ54J51dKuRz0tW7jkAXz+4CzCUAFDeBn8LRABd7EPFxkWsvjesTAVtRgnGhX7LdB REUZXUg8xzxXls9mf0lV10fNZ+hl3DdAePTBxEWzAN/zr6kyNfpRoYqVdub29lfd0h QeT07+3E9iRxA== Date: Thu, 8 Apr 2021 15:32:11 +0100 From: Will Deacon To: "Isaac J. Manjarres" Subject: Re: [RFC PATCH v4 10/15] iommu/io-pgtable-arm: Implement arm_lpae_unmap_pages() Message-ID: <20210408143211.GE17998@willie-the-truck> References: <20210408045241.27316-1-isaacm@codeaurora.org> <20210408045241.27316-11-isaacm@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210408045241.27316-11-isaacm@codeaurora.org> User-Agent: Mutt/1.10.1 (2018-07-13) Cc: pratikp@codeaurora.org, iommu@lists.linux-foundation.org, robin.murphy@arm.com, 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, Apr 07, 2021 at 09:52:36PM -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 | 70 ++++++++++++++++++++++------------ > 1 file changed, 45 insertions(+), 25 deletions(-) > > diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c > index ea66b10c04c4..6700685f81d4 100644 > --- a/drivers/iommu/io-pgtable-arm.c > +++ b/drivers/iommu/io-pgtable-arm.c > @@ -253,8 +253,8 @@ static void __arm_lpae_set_pte(arm_lpae_iopte *ptep, arm_lpae_iopte pte, > > static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, > struct iommu_iotlb_gather *gather, > - unsigned long iova, size_t size, int lvl, > - arm_lpae_iopte *ptep); > + unsigned long iova, size_t size, size_t pgcount, > + int lvl, arm_lpae_iopte *ptep); > > static void __arm_lpae_init_pte(struct arm_lpae_io_pgtable *data, > phys_addr_t paddr, arm_lpae_iopte prot, > @@ -298,7 +298,7 @@ static int arm_lpae_init_pte(struct arm_lpae_io_pgtable *data, > size_t sz = ARM_LPAE_BLOCK_SIZE(lvl, data); > > tblp = ptep - ARM_LPAE_LVL_IDX(iova, lvl, data); > - if (__arm_lpae_unmap(data, NULL, iova + i * sz, sz, > + if (__arm_lpae_unmap(data, NULL, iova + i * sz, sz, 1, > lvl, tblp) != sz) { > WARN_ON(1); > return -EINVAL; > @@ -526,14 +526,14 @@ static size_t arm_lpae_split_blk_unmap(struct arm_lpae_io_pgtable *data, > struct iommu_iotlb_gather *gather, > unsigned long iova, size_t size, > arm_lpae_iopte blk_pte, int lvl, > - arm_lpae_iopte *ptep) > + arm_lpae_iopte *ptep, size_t pgcount) > { > struct io_pgtable_cfg *cfg = &data->iop.cfg; > arm_lpae_iopte pte, *tablep; > phys_addr_t blk_paddr; > size_t tablesz = ARM_LPAE_GRANULE(data); > size_t split_sz = ARM_LPAE_BLOCK_SIZE(lvl, data); > - int i, unmap_idx = -1; > + int i, unmap_idx_start = -1, num_entries = 0, max_entries; > > if (WARN_ON(lvl == ARM_LPAE_MAX_LEVELS)) > return 0; > @@ -542,15 +542,18 @@ static size_t arm_lpae_split_blk_unmap(struct arm_lpae_io_pgtable *data, > if (!tablep) > return 0; /* Bytes unmapped */ > > - if (size == split_sz) > - unmap_idx = ARM_LPAE_LVL_IDX(iova, lvl, data); > + if (size == split_sz) { > + unmap_idx_start = ARM_LPAE_LVL_IDX(iova, lvl, data); > + max_entries = (tablesz >> ilog2(sizeof(pte))) - unmap_idx_start; > + num_entries = min_t(int, pgcount, max_entries); > + } > > blk_paddr = iopte_to_paddr(blk_pte, data); > pte = iopte_prot(blk_pte); > > for (i = 0; i < tablesz / sizeof(pte); i++, blk_paddr += split_sz) { Given that we already have a 'tablesz / sizeof(pte)' expression here, I'd be inclined to have either a local variable or a macro helper to get at the ptes_per_table value that you also need to compute max_entries. > /* Unmap! */ > - if (i == unmap_idx) > + if (i >= unmap_idx_start && i < (unmap_idx_start + num_entries)) > continue; > > __arm_lpae_init_pte(data, blk_paddr, pte, lvl, 1, &tablep[i]); > @@ -568,38 +571,45 @@ static size_t arm_lpae_split_blk_unmap(struct arm_lpae_io_pgtable *data, > return 0; > > tablep = iopte_deref(pte, data); > - } else if (unmap_idx >= 0) { > - io_pgtable_tlb_add_page(&data->iop, gather, iova, size); > - return size; > + } else if (unmap_idx_start >= 0) { > + for (i = 0; i < num_entries; i++) > + io_pgtable_tlb_add_page(&data->iop, gather, iova + i * size, size); I suppose we could add a count paramater to the iotlb gather stuff in future too, but for now this is fine as this series is already pretty big. Will _______________________________________________ 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=-12.7 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,UNWANTED_LANGUAGE_BODY,URIBL_BLOCKED,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 CCC55C433ED for ; Thu, 8 Apr 2021 14:34:22 +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 5E22360FF1 for ; Thu, 8 Apr 2021 14:34:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E22360FF1 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=SjQJCBFloSZVu7YHmCFswqMTVSI6+kpaykipZfQcnAo=; b=k/fG8Bf5/3/x01ZedxdCtA+zM aMnY0of8aDSOXRJdGyq27GaqQNcLfPbo7JuyAdDX8wNa4eEZBpJF0ZLKAX8zeUosL/lkfyg8Hg8g/ Sdhb0DuqSREyi+946cfkR8E2CieK3azaFB6YqPuam7l5US/291V6B2CoVb5HvjNp26lJWcIQCPQ0j hew5eLJmMJ4QkTg1HkE0pbjRjeqcAnUwGESFFeojRXQMjNvdfakdosRDuzz/AgxzwOw3WgCFj76JJ FxOSf2wfzKIW+P6vHGL0ziiBEsz+w9LT+Ot+WlqdKTBxMJgy6OYvnBxQ49IOWgOCQuoYyhg2keCjG g2AI34pPg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lUVhx-008G39-Db; Thu, 08 Apr 2021 14:32:33 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lUVhh-008G1k-6i for linux-arm-kernel@lists.infradead.org; Thu, 08 Apr 2021 14:32:30 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7C4F4610CC; Thu, 8 Apr 2021 14:32:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617892335; bh=dCSZUf5qRFCdJRNa1E7k/U97LHBatePsybZ6J/TrTNI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WZ4+rQV3FbcAYMb5Fm/QEPV+j+Gdzu8vGVFdO8/jXedrtE0tEjQtshrU8YUQdJFEt BXVSY3ETIYaEiHEniXLLgUdUNOW0L4xslVHgxN0jQ7EgSQCfV5/nmso3lKurEGpW9N Xt6X7fH7lH0H9+/au7QIfrT+vrpeNokml5M9kma5SjaOmf6E+pZdJ1njxkEgXf4ZUt +yJ54J51dKuRz0tW7jkAXz+4CzCUAFDeBn8LRABd7EPFxkWsvjesTAVtRgnGhX7LdB REUZXUg8xzxXls9mf0lV10fNZ+hl3DdAePTBxEWzAN/zr6kyNfpRoYqVdub29lfd0h QeT07+3E9iRxA== Date: Thu, 8 Apr 2021 15:32:11 +0100 From: Will Deacon To: "Isaac J. Manjarres" Cc: iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, baolu.lu@linux.intel.com, robin.murphy@arm.com, pratikp@codeaurora.org Subject: Re: [RFC PATCH v4 10/15] iommu/io-pgtable-arm: Implement arm_lpae_unmap_pages() Message-ID: <20210408143211.GE17998@willie-the-truck> References: <20210408045241.27316-1-isaacm@codeaurora.org> <20210408045241.27316-11-isaacm@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210408045241.27316-11-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-20210408_153228_220695_849D451F X-CRM114-Status: GOOD ( 20.79 ) 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 Wed, Apr 07, 2021 at 09:52:36PM -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 | 70 ++++++++++++++++++++++------------ > 1 file changed, 45 insertions(+), 25 deletions(-) > > diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c > index ea66b10c04c4..6700685f81d4 100644 > --- a/drivers/iommu/io-pgtable-arm.c > +++ b/drivers/iommu/io-pgtable-arm.c > @@ -253,8 +253,8 @@ static void __arm_lpae_set_pte(arm_lpae_iopte *ptep, arm_lpae_iopte pte, > > static size_t __arm_lpae_unmap(struct arm_lpae_io_pgtable *data, > struct iommu_iotlb_gather *gather, > - unsigned long iova, size_t size, int lvl, > - arm_lpae_iopte *ptep); > + unsigned long iova, size_t size, size_t pgcount, > + int lvl, arm_lpae_iopte *ptep); > > static void __arm_lpae_init_pte(struct arm_lpae_io_pgtable *data, > phys_addr_t paddr, arm_lpae_iopte prot, > @@ -298,7 +298,7 @@ static int arm_lpae_init_pte(struct arm_lpae_io_pgtable *data, > size_t sz = ARM_LPAE_BLOCK_SIZE(lvl, data); > > tblp = ptep - ARM_LPAE_LVL_IDX(iova, lvl, data); > - if (__arm_lpae_unmap(data, NULL, iova + i * sz, sz, > + if (__arm_lpae_unmap(data, NULL, iova + i * sz, sz, 1, > lvl, tblp) != sz) { > WARN_ON(1); > return -EINVAL; > @@ -526,14 +526,14 @@ static size_t arm_lpae_split_blk_unmap(struct arm_lpae_io_pgtable *data, > struct iommu_iotlb_gather *gather, > unsigned long iova, size_t size, > arm_lpae_iopte blk_pte, int lvl, > - arm_lpae_iopte *ptep) > + arm_lpae_iopte *ptep, size_t pgcount) > { > struct io_pgtable_cfg *cfg = &data->iop.cfg; > arm_lpae_iopte pte, *tablep; > phys_addr_t blk_paddr; > size_t tablesz = ARM_LPAE_GRANULE(data); > size_t split_sz = ARM_LPAE_BLOCK_SIZE(lvl, data); > - int i, unmap_idx = -1; > + int i, unmap_idx_start = -1, num_entries = 0, max_entries; > > if (WARN_ON(lvl == ARM_LPAE_MAX_LEVELS)) > return 0; > @@ -542,15 +542,18 @@ static size_t arm_lpae_split_blk_unmap(struct arm_lpae_io_pgtable *data, > if (!tablep) > return 0; /* Bytes unmapped */ > > - if (size == split_sz) > - unmap_idx = ARM_LPAE_LVL_IDX(iova, lvl, data); > + if (size == split_sz) { > + unmap_idx_start = ARM_LPAE_LVL_IDX(iova, lvl, data); > + max_entries = (tablesz >> ilog2(sizeof(pte))) - unmap_idx_start; > + num_entries = min_t(int, pgcount, max_entries); > + } > > blk_paddr = iopte_to_paddr(blk_pte, data); > pte = iopte_prot(blk_pte); > > for (i = 0; i < tablesz / sizeof(pte); i++, blk_paddr += split_sz) { Given that we already have a 'tablesz / sizeof(pte)' expression here, I'd be inclined to have either a local variable or a macro helper to get at the ptes_per_table value that you also need to compute max_entries. > /* Unmap! */ > - if (i == unmap_idx) > + if (i >= unmap_idx_start && i < (unmap_idx_start + num_entries)) > continue; > > __arm_lpae_init_pte(data, blk_paddr, pte, lvl, 1, &tablep[i]); > @@ -568,38 +571,45 @@ static size_t arm_lpae_split_blk_unmap(struct arm_lpae_io_pgtable *data, > return 0; > > tablep = iopte_deref(pte, data); > - } else if (unmap_idx >= 0) { > - io_pgtable_tlb_add_page(&data->iop, gather, iova, size); > - return size; > + } else if (unmap_idx_start >= 0) { > + for (i = 0; i < num_entries; i++) > + io_pgtable_tlb_add_page(&data->iop, gather, iova + i * size, size); I suppose we could add a count paramater to the iotlb gather stuff in future too, but for now this is fine as this series is already pretty big. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel