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=-8.3 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, 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 C86ACCA9EB5 for ; Mon, 4 Nov 2019 18:17:30 +0000 (UTC) Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (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 3877C20578 for ; Mon, 4 Nov 2019 18:17:30 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="MregfVcg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3877C20578 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 mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id EBE77CD2; Mon, 4 Nov 2019 18:17:29 +0000 (UTC) Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 1D6BBCAF for ; Mon, 4 Nov 2019 18:17:28 +0000 (UTC) Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id C144DA9 for ; Mon, 4 Nov 2019 18:17:27 +0000 (UTC) Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B025420578; Mon, 4 Nov 2019 18:17:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572891447; bh=I0ClEyfYYg+5vZmQ5JQDLaZ5AFVtu2E4q0e7uMtVpz4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MregfVcg4Le7ebB4b6p6lGzAOFFhK7K25ALaLHWbsDc8WmaRHztAMBvyXPfhH57Zk Ymq4nsLSWJaxb1X/M0ZO4nPFio44FxATL1oAHF4tzCygnuURfV/PK0o/voR6/EdndF D+4XkeyENeKp0wa3XYpIN0XyIod2Um9Mjw6r+M4A= Date: Mon, 4 Nov 2019 18:17:23 +0000 From: Will Deacon To: Robin Murphy Subject: Re: [PATCH v2 06/10] iommu/io-pgtable-arm: Simplify level indexing Message-ID: <20191104181722.GF24909@willie-the-truck> References: <698173b487383735e470a28e5cca4f9db22703de.1572024120.git.robin.murphy@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <698173b487383735e470a28e5cca4f9db22703de.1572024120.git.robin.murphy@arm.com> User-Agent: Mutt/1.10.1 (2018-07-13) Cc: iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org X-BeenThere: iommu@lists.linux-foundation.org X-Mailman-Version: 2.1.12 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 Sender: iommu-bounces@lists.linux-foundation.org Errors-To: iommu-bounces@lists.linux-foundation.org On Fri, Oct 25, 2019 at 07:08:35PM +0100, Robin Murphy wrote: > The nature of the LPAE format means that data->pg_shift is always > redundant with data->bits_per_level, since they represent the size of a > page and the number of PTEs per page respectively, and the size of a PTE > is constant. Thus it works out more efficient to only store the latter, > and derive the former via a trivial addition where necessary. > > Signed-off-by: Robin Murphy > --- > drivers/iommu/io-pgtable-arm.c | 29 +++++++++++++---------------- > 1 file changed, 13 insertions(+), 16 deletions(-) > > diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c > index 4b1483eb0ccf..15b4927ce36b 100644 > --- a/drivers/iommu/io-pgtable-arm.c > +++ b/drivers/iommu/io-pgtable-arm.c > @@ -36,10 +36,11 @@ > * in a virtual address mapped by the pagetable in d. > */ > #define ARM_LPAE_LVL_SHIFT(l,d) \ > - (((ARM_LPAE_MAX_LEVELS - 1 - (l)) * (d)->bits_per_level) + \ > - (d)->pg_shift) > + (((ARM_LPAE_MAX_LEVELS - (l)) * (d)->bits_per_level) + \ > + ilog2(sizeof(arm_lpae_iopte))) > > -#define ARM_LPAE_GRANULE(d) (1UL << (d)->pg_shift) > +#define ARM_LPAE_GRANULE(d) \ > + (sizeof(arm_lpae_iopte) << (d)->bits_per_level) > #define ARM_LPAE_PGD_SIZE(d) \ > (sizeof(arm_lpae_iopte) << (d)->pgd_bits) > > @@ -55,9 +56,7 @@ > ((1 << ((d)->bits_per_level + ARM_LPAE_PGD_IDX(l,d))) - 1)) > > /* Calculate the block/page mapping size at level l for pagetable in d. */ > -#define ARM_LPAE_BLOCK_SIZE(l,d) \ > - (1ULL << (ilog2(sizeof(arm_lpae_iopte)) + \ > - ((ARM_LPAE_MAX_LEVELS - (l)) * (d)->bits_per_level))) > +#define ARM_LPAE_BLOCK_SIZE(l,d) (1ULL << ARM_LPAE_LVL_SHIFT(l,d)) > > /* Page table bits */ > #define ARM_LPAE_PTE_TYPE_SHIFT 0 > @@ -175,8 +174,7 @@ struct arm_lpae_io_pgtable { > > int pgd_bits; > int start_level; > - unsigned long pg_shift; > - unsigned long bits_per_level; > + int bits_per_level; > > void *pgd; > }; > @@ -206,7 +204,7 @@ static phys_addr_t iopte_to_paddr(arm_lpae_iopte pte, > { > u64 paddr = pte & ARM_LPAE_PTE_ADDR_MASK; > > - if (data->pg_shift < 16) > + if (data->bits_per_level < 13) /* i.e. 64K granule */ nit, but: if (ARM_LPAE_GRANULE(data) < SZ_64K) might be clearer and avoid the need for a comment? (I can make the change locally if you agree) 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=-8.5 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,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 1D3AECA9EB5 for ; Mon, 4 Nov 2019 18:17:36 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 EB12620578 for ; Mon, 4 Nov 2019 18:17:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="hs8p/bpw"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="MregfVcg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EB12620578 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+infradead-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=bombadil.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=c8tE9mYlmrxqqHVc+3NrUXUKZOl2777krniHdMV9W6E=; b=hs8p/bpw2/K1D2 VcDUfnKmR52Sueq9u6+fk1ofzVEKWo5nlKSV1ZRDukjYeDmAAnP+WCLDmynlxWxj8f6ZjM6S8eRN2 ThUbraijR/2ajDmxcIaBEyq93GQQejBjmCkC46Kz6ci+S/3zcN/ka4GgIEfvx6I3QyL3FzLiC4xIN O3NAeI4vC7M9/L7sKBJxFKbSp90qmt7tiR25gsv5IciXqIkH7MyHgeKzVJ/vmoL2KnwtcaXI1BcE8 pl/XVowKFYygweROUycqO0ImwkHUVp3JKvGcIIoXqEyJC7IWJ43Tw4ZAnMvYxEToHk20uv7oxY/EV WEqdsnULARC0dHzwE5Ww==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iRgv1-0003za-FU; Mon, 04 Nov 2019 18:17:35 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iRguu-0003vq-2l for linux-arm-kernel@lists.infradead.org; Mon, 04 Nov 2019 18:17:29 +0000 Received: from willie-the-truck (236.31.169.217.in-addr.arpa [217.169.31.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B025420578; Mon, 4 Nov 2019 18:17:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1572891447; bh=I0ClEyfYYg+5vZmQ5JQDLaZ5AFVtu2E4q0e7uMtVpz4=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=MregfVcg4Le7ebB4b6p6lGzAOFFhK7K25ALaLHWbsDc8WmaRHztAMBvyXPfhH57Zk Ymq4nsLSWJaxb1X/M0ZO4nPFio44FxATL1oAHF4tzCygnuURfV/PK0o/voR6/EdndF D+4XkeyENeKp0wa3XYpIN0XyIod2Um9Mjw6r+M4A= Date: Mon, 4 Nov 2019 18:17:23 +0000 From: Will Deacon To: Robin Murphy Subject: Re: [PATCH v2 06/10] iommu/io-pgtable-arm: Simplify level indexing Message-ID: <20191104181722.GF24909@willie-the-truck> References: <698173b487383735e470a28e5cca4f9db22703de.1572024120.git.robin.murphy@arm.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <698173b487383735e470a28e5cca4f9db22703de.1572024120.git.robin.murphy@arm.com> 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-20191104_101728_179263_6546C397 X-CRM114-Status: GOOD ( 19.03 ) 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: iommu@lists.linux-foundation.org, jcrouse@codeaurora.org, 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+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Fri, Oct 25, 2019 at 07:08:35PM +0100, Robin Murphy wrote: > The nature of the LPAE format means that data->pg_shift is always > redundant with data->bits_per_level, since they represent the size of a > page and the number of PTEs per page respectively, and the size of a PTE > is constant. Thus it works out more efficient to only store the latter, > and derive the former via a trivial addition where necessary. > > Signed-off-by: Robin Murphy > --- > drivers/iommu/io-pgtable-arm.c | 29 +++++++++++++---------------- > 1 file changed, 13 insertions(+), 16 deletions(-) > > diff --git a/drivers/iommu/io-pgtable-arm.c b/drivers/iommu/io-pgtable-arm.c > index 4b1483eb0ccf..15b4927ce36b 100644 > --- a/drivers/iommu/io-pgtable-arm.c > +++ b/drivers/iommu/io-pgtable-arm.c > @@ -36,10 +36,11 @@ > * in a virtual address mapped by the pagetable in d. > */ > #define ARM_LPAE_LVL_SHIFT(l,d) \ > - (((ARM_LPAE_MAX_LEVELS - 1 - (l)) * (d)->bits_per_level) + \ > - (d)->pg_shift) > + (((ARM_LPAE_MAX_LEVELS - (l)) * (d)->bits_per_level) + \ > + ilog2(sizeof(arm_lpae_iopte))) > > -#define ARM_LPAE_GRANULE(d) (1UL << (d)->pg_shift) > +#define ARM_LPAE_GRANULE(d) \ > + (sizeof(arm_lpae_iopte) << (d)->bits_per_level) > #define ARM_LPAE_PGD_SIZE(d) \ > (sizeof(arm_lpae_iopte) << (d)->pgd_bits) > > @@ -55,9 +56,7 @@ > ((1 << ((d)->bits_per_level + ARM_LPAE_PGD_IDX(l,d))) - 1)) > > /* Calculate the block/page mapping size at level l for pagetable in d. */ > -#define ARM_LPAE_BLOCK_SIZE(l,d) \ > - (1ULL << (ilog2(sizeof(arm_lpae_iopte)) + \ > - ((ARM_LPAE_MAX_LEVELS - (l)) * (d)->bits_per_level))) > +#define ARM_LPAE_BLOCK_SIZE(l,d) (1ULL << ARM_LPAE_LVL_SHIFT(l,d)) > > /* Page table bits */ > #define ARM_LPAE_PTE_TYPE_SHIFT 0 > @@ -175,8 +174,7 @@ struct arm_lpae_io_pgtable { > > int pgd_bits; > int start_level; > - unsigned long pg_shift; > - unsigned long bits_per_level; > + int bits_per_level; > > void *pgd; > }; > @@ -206,7 +204,7 @@ static phys_addr_t iopte_to_paddr(arm_lpae_iopte pte, > { > u64 paddr = pte & ARM_LPAE_PTE_ADDR_MASK; > > - if (data->pg_shift < 16) > + if (data->bits_per_level < 13) /* i.e. 64K granule */ nit, but: if (ARM_LPAE_GRANULE(data) < SZ_64K) might be clearer and avoid the need for a comment? (I can make the change locally if you agree) Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel