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 F1DF7C43603 for ; Tue, 6 Apr 2021 11:51:04 +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 1B535613B7 for ; Tue, 6 Apr 2021 11:51:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1B535613B7 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=k7mcFK2TysJZc7YrUtl8Pin2HhBYgOhgIZ/P5nLeOCw=; b=dIkweKoi4RRI/wkqtmiXGh7EX zYKPM6BvK356SdhtLasvK117msrHdB5DLl1D5teIUGTGmqiVobicnCdrpvswqaYfRRxzUusrdAcjv PzfTgw+ATlxWLxwbPTIFHnUY+gLmp5MfVHg6FKLNClqYdaB6TEcL22JtYpNcANlCGVj89MzOaGisN SUC0Y0k916t7IPOeOnT8E2gONoUkuqLYVYzhm5fJtrfk5kWciJogTJtU6xqbMsQF/eHk9ALRrSniO Z1912hip9pfiGfuxUZL7mI1b1vgsmD2JHexnp01uMKYKH224JUfcWb7t5+G/nniHISRv6E7vw843o iNLZO+sqA==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lTkCl-002R7m-7V; Tue, 06 Apr 2021 11:49:11 +0000 Received: from mail.kernel.org ([198.145.29.99]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lTk4W-002P29-DB for linux-arm-kernel@lists.infradead.org; Tue, 06 Apr 2021 11:40:45 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id 0501661394; Tue, 6 Apr 2021 11:40:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1617709237; bh=D5ja3pEnQKp92DZ8GW4YTR41AKo2SyV0oqDopX8rdNc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OpOMUfXfdimDt7wzdC8WNK7hREUPjfyZIQQndYdn+Tkx33uQpTZoTjFIilbAJXtuN YTCM+YzmPGuDLQcpoGIEKSi9a801j11ipxVpQe5EWFD6JQTS84NvzNQ2IMfvPl6cEg EFR9BPemzAoKAWqVgR0X+ELCXCUVntnTDU/77GXkecVlLLMKbfhs7EMHqTCb6Sj8eO GHS/c1oK6fPX9swF8hhu+nxIF9YJb3z+pJuCrCza0LFRXwL79eMZOxTuSbQF2ZUhM3 xTJ5JNe+qdehkT88kDwtPEzUqBFYiSUqaSRzBN3BRJiDLQio1CVP8noPt6/9O6X8BJ pekY/RBlDs43g== Date: Tue, 6 Apr 2021 12:40:32 +0100 From: Will Deacon To: isaacm@codeaurora.org Cc: iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, Pratik Patel , Robin Murphy , Lu Baolu Subject: Re: [RFC PATCH 3/6] iommu: Use bitmap to calculate page size in iommu_pgsize() Message-ID: <20210406114032.GA13747@willie-the-truck> References: <20210401164738.9513-1-will@kernel.org> <20210401164738.9513-4-will@kernel.org> <7c012a63e8a5ad1856aac08995e6f154@codeaurora.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <7c012a63e8a5ad1856aac08995e6f154@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_124041_135154_B7F3E3E6 X-CRM114-Status: GOOD ( 23.10 ) 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 Thu, Apr 01, 2021 at 06:39:35PM -0700, isaacm@codeaurora.org wrote: > On 2021-04-01 09:47, Will Deacon wrote: > > 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 > > --- > > 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..bcd623862bf9 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(__fls(size), 0); > I've fixed this in the latest RFC for the iommu_map/unmap optimization > patches, > but for the sake of completeness: I think this should be GENMASK_ULL, in > case > __fls(size) >= 32. Hmm, but 'size' is a size_t; which architectures have sizeof(size_t) > sizeof(unsigned long)? > > - /* need to consider alignment requirements ? */ > > - if (likely(addr_merge)) { > > - /* Max page size allowed by address */ > > - unsigned int align_pgsize_idx = __ffs(addr_merge); > > - pgsize_idx = min(pgsize_idx, align_pgsize_idx); > > - } > > - > > - /* build a mask of acceptable page sizes */ > > - pgsize = (1UL << (pgsize_idx + 1)) - 1; > > - > > - /* throw away page sizes not supported by the hardware */ > > - pgsize &= domain->pgsize_bitmap; > > + /* Constrain the page sizes further based on the maximum alignment */ > > + if (likely(addr_merge)) > > + pgsizes &= GENMASK(__ffs(addr_merge), 0); This one looks like more of an issue, though, as addr_merge is a phys_addr_t, which certainly can be 64-bit where unsigned long is 32-bit (e.g. Armv7 + LPAE) Rather than make everything _ULL, please can you just do it where we're actually using the larger types? Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel