Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S266810AbUFYRjZ (ORCPT ); Fri, 25 Jun 2004 13:39:25 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S266818AbUFYRjZ (ORCPT ); Fri, 25 Jun 2004 13:39:25 -0400 Received: from cantor.suse.de ([195.135.220.2]:4244 "EHLO Cantor.suse.de") by vger.kernel.org with ESMTP id S266810AbUFYRjV (ORCPT ); Fri, 25 Jun 2004 13:39:21 -0400 Date: Fri, 25 Jun 2004 19:39:19 +0200 Message-ID: From: Takashi Iwai To: Andrea Arcangeli Cc: Andi Kleen , ak@muc.de, tripperda@nvidia.com, discuss@x86-64.org, linux-kernel@vger.kernel.org Subject: Re: [discuss] Re: 32-bit dma allocations on 64-bit platforms In-Reply-To: <20040625173046.GJ30687@dualathlon.random> References: <20040624112900.GE16727@wotan.suse.de> <20040624164258.1a1beea3.ak@suse.de> <20040624152946.GK30687@dualathlon.random> <20040624171620.GN30687@dualathlon.random> <20040624184447.GW30687@dualathlon.random> <20040625173046.GJ30687@dualathlon.random> User-Agent: Wanderlust/2.10.1 (Watching The Wheels) SEMI/1.14.5 (Awara-Onsen) FLIM/1.14.5 (Demachiyanagi) APEL/10.6 MULE XEmacs/21.4 (patch 15) (Security Through Obscurity) (i386-suse-linux) MIME-Version: 1.0 (generated by SEMI 1.14.5 - "Awara-Onsen") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2346 Lines: 76 At Fri, 25 Jun 2004 19:30:46 +0200, Andrea Arcangeli wrote: > > On Fri, Jun 25, 2004 at 05:50:04PM +0200, Takashi Iwai wrote: > > --- linux-2.6.7/arch/i386/kernel/pci-dma.c-dist 2004-06-24 15:56:46.017473544 +0200 > > +++ linux-2.6.7/arch/i386/kernel/pci-dma.c 2004-06-25 17:43:42.509366917 +0200 > > @@ -23,11 +23,22 @@ void *dma_alloc_coherent(struct device * > > if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff)) > > gfp |= GFP_DMA; > > > > + again: > > ret = (void *)__get_free_pages(gfp, get_order(size)); > > > > - if (ret != NULL) { > > + if (ret == NULL) { > > + if (dev && (gfp & GFP_DMA)) { > > + gfp &= ~GFP_DMA; > > I would find cleaner to use __GFP_DMA in the whole file, this is not > about your changes, previous code used GFP_DMA too. The issue is that if > we change GFP_DMA to add a __GFP_HIGH or similar, the above will clear > the other bitflags too. Indeed. > > > + (((unsigned long)*dma_handle + size - 1) & ~(unsigned long)dev->coherent_dma_mask)) { > > + free_pages((unsigned long)ret, get_order(size)); > > + return NULL; > > + } > > I would do the memset and setting of dma_handle after the above check. Yep. The below is the corrected version. Thanks! Takashi --- linux-2.6.7/arch/i386/kernel/pci-dma.c-dist 2004-06-24 15:56:46.017473544 +0200 +++ linux-2.6.7/arch/i386/kernel/pci-dma.c 2004-06-25 19:38:26.334210809 +0200 @@ -21,13 +21,24 @@ void *dma_alloc_coherent(struct device * gfp &= ~(__GFP_DMA | __GFP_HIGHMEM); if (dev == NULL || (dev->coherent_dma_mask < 0xffffffff)) - gfp |= GFP_DMA; + gfp |= __GFP_DMA; + again: ret = (void *)__get_free_pages(gfp, get_order(size)); - if (ret != NULL) { - memset(ret, 0, size); + if (ret == NULL) { + if (dev && (gfp & __GFP_DMA)) { + gfp &= ~__GFP_DMA; + goto again; + } + } else { *dma_handle = virt_to_phys(ret); + if (!(gfp & __GFP_DMA) && + (((unsigned long)*dma_handle + size - 1) & ~(unsigned long)dev->coherent_dma_mask)) { + free_pages((unsigned long)ret, get_order(size)); + return NULL; + } + memset(ret, 0, size); } return ret; } - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/