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=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 D469DC433ED for ; Tue, 6 Apr 2021 11:57:30 +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 50ADC613B3 for ; Tue, 6 Apr 2021 11:57:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 50ADC613B3 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=QfnBHN9LIiJrvIaXJ1Di2pucGP7DZ5sBxdS0L0A0YhE=; b=V0eK35T7uTt9W7KsC5hWYTqPK G37RpkrFKmfuTZSJprC3pXJUef50pwGEkPh2IMCTAaR5QqoESVmQAbcHFOyeDD4NKsBkVsIwjn56Z Rc1Ol6pUqP9nGdezmRIIQoRjrUU8anYZ82GXAkcACNszuo62+Y33Te12YljVMJ3aMego1lazE1Kvn /nKRxFp/BCL+51EC6EhsT7czJuQbpL/HDmdw6a4GPh8KNtYXZOTA21Th0k2+aqZBQMLsVCS4WqQQb NlQ0yJzwkBQ4oJ2JpTp3KeD2wBSNmCyDwK5jaoiISd0CYa189uvGLYV1QQ/bTSKKtDP2WntSysTDD qebuFEP0Q==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lTkIK-002SZ8-BY; Tue, 06 Apr 2021 11:54:56 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lTkEK-002RXo-Cz for linux-arm-kernel@lists.infradead.org; Tue, 06 Apr 2021 11:51:02 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 868926128A; Tue, 6 Apr 2021 11:50:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617709846; bh=lJ+TjE9jXejKLCTgbSxiyo5N5PBrFMk8ROc2tmk5kbg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TB9kyka9JVkKCYSaaxOBc89WfQJv56gBmLYDOIQyApVo97w8hG2dQLzhovDpYeul7 a4xUd+K9su490FkTHiT5fMbcmsnc3TxK0lvfi37OkmKzt2cd5u9c/vHFs6sduHITmW NGtxuBCmPdQkgY1K+k6h88N/K4uwRjOwP8F20Er8PzEPzcP8QJlksJIQFvFNLVY7vO qAFl2h+M09ymS197wAeLGuHf/soUMgjSKVowaIMIS7NrR0e5Y//oefIi0dCG+9CRDw pOK5DaYYIo4BalQDFjWR/UAwevhDFMs0V3wFd8L5px9MZ/8ILwmKyk/hQg6wvOBDps Mwou4+ZZahylA== Date: Tue, 6 Apr 2021 12:50:41 +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 05/12] iommu: Use bitmap to calculate page size in iommu_pgsize() Message-ID: <20210406115040.GB13747@willie-the-truck> References: <20210405191112.28192-1-isaacm@codeaurora.org> <20210405191112.28192-6-isaacm@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210405191112.28192-6-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_125050_688928_2C41E2A8 X-CRM114-Status: GOOD ( 16.15 ) 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:05PM -0700, Isaac J. Manjarres wrote: > From: Will Deacon > > Avoid the potential for shifting values by amounts greater than the > width of their type by using a bitmap to compute page size in > iommu_pgsize(). > > Signed-off-by: Will Deacon > Signed-off-by: Isaac J. Manjarres > --- > drivers/iommu/iommu.c | 31 ++++++++++++------------------- > 1 file changed, 12 insertions(+), 19 deletions(-) > > diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c > index d0b0a15dba84..9006397b6604 100644 > --- a/drivers/iommu/iommu.c > +++ b/drivers/iommu/iommu.c > @@ -8,6 +8,7 @@ > > #include > #include > +#include > #include > #include > #include > @@ -2360,30 +2361,22 @@ static size_t iommu_pgsize(struct iommu_domain *domain, > unsigned long addr_merge, size_t size) > { > unsigned int pgsize_idx; > + unsigned long pgsizes; > size_t pgsize; > > - /* Max page size that still fits into 'size' */ > - pgsize_idx = __fls(size); > + /* Page sizes supported by the hardware and small enough for @size */ > + pgsizes = domain->pgsize_bitmap & GENMASK_ULL(__fls(size), 0); See my comments on the other thread, but I don't think it's necessary to use the _ULL versions everywhere. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel