From: Takashi Iwai Subject: Re: bad page when freeing preallocated pages Date: Thu, 27 Apr 2006 13:10:56 +0200 Message-ID: References: <444F2FA6.7010305@atmel.com> <4450622C.80802@norway.atmel.com> <4450A4AF.1000501@norway.atmel.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Return-path: In-Reply-To: <4450A4AF.1000501@norway.atmel.com> Sender: alsa-devel-admin@lists.sourceforge.net Errors-To: alsa-devel-admin@lists.sourceforge.net List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , List-Archive: To: Hans-Christian Egtvedt Cc: alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org At Thu, 27 Apr 2006 13:02:07 +0200, Hans-Christian Egtvedt wrote: > > Takashi Iwai wrote: > > At Thu, 27 Apr 2006 08:18:20 +0200, > > Hans-Christian Egtvedt wrote: > >> Takashi Iwai wrote: > >>> At Wed, 26 Apr 2006 10:30:30 +0200, > >>> Hans-Christian Egtvedt wrote: > > > > >> The interessting part is that if I preallocate a small area (4kB), then > >> the bad pages go away on rmmod. It could maybe be that we have some > >> undiscovered bug in dma_alloc_coherent() or dma_free_coherent(), but we > >> use there function calls in other drivers, so i doubt it (but keeping > >> the option open;) ). > > > > Ah, that enlighted me. > > > > According to your first post, snd_pcm_preallocate_pages*() is called > > like below: > > > > snd_pcm_lib_preallocate_pages_for_all(chip->pcm, > > SNDRV_DMA_TYPE_DEV, > > snd_dma_continuous_data(GFP_KERNEL), > > 64 * 1024, 64 * 1024); > > > > The third argument is wrong in this case. You have to pass struct > > device pointer there instead of snd_dma_continuous_data(). > > I tried that, but the result is the same. I have stored the platform > device in chip->pdev and passed this to preallocation of pages: > > snd_pcm_lib_preallocate_pages_for_all(chip->pcm, SNDRV_DMA_TYPE_DEV, > &chip->pdev->dev, 64 * 1024, 64 * 1024); > > I've looked into the library and it all seems to be correct in the > deeper layers. > > Thank you for you feedback. Any tips or hints to where start debugging > would be greatly appreciated. Removing snd_pcm_lib_preallocate_pages_for_all() might be a tentative option. Instead of snd_pcm_lib_malloc_pages() and *_free_pages(), call dma_alloc_coherent() and dma_free_coherent() in hw_params and hw_free PCM callbacks. Return -ENOMEM if the alloc fails. One thing to care in this case is that hw_params callback can be called multiple times at each open. You should check the buffer size at each time, and re-allocate if a buffer was already allocated but the size changed. Another possile buggy point is the mmap support in pcm_native.c. It uses virt_to_page() in nopage vma op, and it's known that this doesn't work on some architectures. Try to not to set SNDRV_PCM_INFO_MMAP bit in snd_pcm_hardware.info bitflags to avoid mmap. Takashi ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642