From patchwork Wed Jun 18 20:48:15 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Morton X-Patchwork-Id: 4379391 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 6AC199F314 for ; Wed, 18 Jun 2014 20:50:57 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 96DC7201DD for ; Wed, 18 Jun 2014 20:50:56 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C21B2201C8 for ; Wed, 18 Jun 2014 20:50:55 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WxMmf-0005sO-I9; Wed, 18 Jun 2014 20:48:41 +0000 Received: from mail.linuxfoundation.org ([140.211.169.12]) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WxMmd-0005lw-5w for linux-arm-kernel@lists.infradead.org; Wed, 18 Jun 2014 20:48:39 +0000 Received: from akpm3.mtv.corp.google.com (unknown [216.239.45.95]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id DA078A04; Wed, 18 Jun 2014 20:48:16 +0000 (UTC) Date: Wed, 18 Jun 2014 13:48:15 -0700 From: Andrew Morton To: Joonsoo Kim Subject: Re: [PATCH v3 -next 4/9] DMA, CMA: support arbitrary bitmap granularity Message-Id: <20140618134815.69c4d0a5f916846f9857e9ff@linux-foundation.org> In-Reply-To: <1402897251-23639-5-git-send-email-iamjoonsoo.kim@lge.com> References: <1402897251-23639-1-git-send-email-iamjoonsoo.kim@lge.com> <1402897251-23639-5-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: Sylpheed 3.2.0beta5 (GTK+ 2.24.10; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140618_134839_267829_F75A2E44 X-CRM114-Status: GOOD ( 15.27 ) X-Spam-Score: -2.3 (--) Cc: kvm-ppc@vger.kernel.org, Russell King - ARM Linux , kvm@vger.kernel.org, linux-mm@kvack.org, Gleb Natapov , Greg Kroah-Hartman , Alexander Graf , Michal Nazarewicz , linux-kernel@vger.kernel.org, Minchan Kim , Paul Mackerras , "Aneesh Kumar K.V" , Benjamin Herrenschmidt , Paolo Bonzini , Zhang Yanfei , linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, Marek Szyprowski X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Mon, 16 Jun 2014 14:40:46 +0900 Joonsoo Kim wrote: > PPC KVM's CMA area management requires arbitrary bitmap granularity, > since they want to reserve very large memory and manage this region > with bitmap that one bit for several pages to reduce management overheads. > So support arbitrary bitmap granularity for following generalization. > > ... > > --- a/drivers/base/dma-contiguous.c > +++ b/drivers/base/dma-contiguous.c > @@ -38,6 +38,7 @@ struct cma { > unsigned long base_pfn; > unsigned long count; > unsigned long *bitmap; > + unsigned int order_per_bit; /* Order of pages represented by one bit */ > struct mutex lock; > }; > > @@ -157,9 +158,37 @@ void __init dma_contiguous_reserve(phys_addr_t limit) > > static DEFINE_MUTEX(cma_mutex); > > +static unsigned long cma_bitmap_aligned_mask(struct cma *cma, int align_order) > +{ > + return (1 << (align_order >> cma->order_per_bit)) - 1; > +} Might want a "1UL << ..." here. > +static unsigned long cma_bitmap_maxno(struct cma *cma) > +{ > + return cma->count >> cma->order_per_bit; > +} > + > +static unsigned long cma_bitmap_pages_to_bits(struct cma *cma, > + unsigned long pages) > +{ > + return ALIGN(pages, 1 << cma->order_per_bit) >> cma->order_per_bit; > +} Ditto. I'm not really sure what the compiler will do in these cases, but would prefer not to rely on it anyway! --- a/drivers/base/dma-contiguous.c~dma-cma-support-arbitrary-bitmap-granularity-fix +++ a/drivers/base/dma-contiguous.c @@ -160,7 +160,7 @@ static DEFINE_MUTEX(cma_mutex); static unsigned long cma_bitmap_aligned_mask(struct cma *cma, int align_order) { - return (1 << (align_order >> cma->order_per_bit)) - 1; + return (1UL << (align_order >> cma->order_per_bit)) - 1; } static unsigned long cma_bitmap_maxno(struct cma *cma) @@ -171,7 +171,7 @@ static unsigned long cma_bitmap_maxno(st static unsigned long cma_bitmap_pages_to_bits(struct cma *cma, unsigned long pages) { - return ALIGN(pages, 1 << cma->order_per_bit) >> cma->order_per_bit; + return ALIGN(pages, 1UL << cma->order_per_bit) >> cma->order_per_bit; } static void cma_clear_bitmap(struct cma *cma, unsigned long pfn, int count)