PCM mmap (temporary) fixes for non-coherent architectures
Subsystems (3)
cover PCM mmap (temporary) fixes for non-coherent architectures
Hi,
this is a patchset to fix Oopses from ALSA PCM core with mmap on MIPS and PPC non-coherent architectures. This contains also a clean-up for ARM mmap.
In this patch series, I don't try to port dma_mmap_coherent() to these architectures yet, but just put ugly ifdefs in the ALSA core side. Understand that this is a first step forward to a more cleaner solution, and the purpose right now is just to fix up long-standing Oops. I'll try to push dma_mmap_coherent() patches for the next kernel once again after this gets merged.
Since the changes are minimal, I'd like to put them in ASAP for 2.6.33. Please review and give feedbacks if any problem is found.
Thanks,
Takashi
PATCH 1/5 ALSA: pcm - Use dma_mmap_coherent() if available
Use dma_mmap_coherent() for mmapping the buffers allocated via dma_alloc_coherent() if available. Currently, only ARM has this function, so we do temporarily have an ifdef pcm_native.c. This should be handled better globally in future.
--- sound/core/pcm_native.c | 49 +++++++++++++++++++++++++++++++--------------- 1 files changed, 33 insertions(+), 16 deletions(-)
sound/core/pcm_native.c +33 -16
@@ -26,6 +26,7 @@#include <linux/time.h> #include <linux/pm_qos_params.h> #include <linux/uio.h> +#include <linux/dma-mapping.h> #include <sound/core.h> #include <sound/control.h> #include <sound/info.h>
@@ -3094,23 +3095,42 @@ static int snd_pcm_mmap_data_fault(struct vm_area_struct *area,return 0 ; } -static const struct vm_operations_struct snd_pcm_vm_ops_data = -{ +static const struct vm_operations_struct snd_pcm_vm_ops_data = { + .open = snd_pcm_mmap_data_open, + .close = snd_pcm_mmap_data_close, +}; + +static const struct vm_operations_struct snd_pcm_vm_ops_data_fault = { .open = snd_pcm_mmap_data_open, .close = snd_pcm_mmap_data_close, .fault = snd_pcm_mmap_data_fault, }; +#ifndef ARCH_HAS_DMA_MMAP_COHERENT +/* This should be defined / handled globally! */ +#ifdef CONFIG_ARM +#define ARCH_HAS_DMA_MMAP_COHERENT +#endif +#endif +/* * mmap the DMA buffer on RAM */ static int snd_pcm_default_mmap (struct snd_pcm_substream *substream,struct vm_area_struct *area) { - area->vm_ops = &snd_pcm_vm_ops_data; - area->vm_private_data = substream; area->vm_flags |=VM_RESERVED ; -atomic_inc (&substream->mmap_count); +#ifdef ARCH_HAS_DMA_MMAP_COHERENT +if (!substream->ops->page && + substream->dma_buffer.dev.type ==SNDRV_DMA_TYPE_DEV ) +return dma_mmap_coherent (substream->dma_buffer.dev.dev, + area, + substream->runtime->dma_area, + substream->runtime->dma_addr, + area->vm_end - area->vm_start); +#endif /* ARCH_HAS_DMA_MMAP_COHERENT */ +/* mmap with fault handler */ + area->vm_ops = &snd_pcm_vm_ops_data_fault;return 0 ; }
@@ -3118,12 +3138,6 @@ static int snd_pcm_default_mmap(struct snd_pcm_substream *substream,* mmap the DMA buffer on I/O memory area */ #if SNDRV_PCM_INFO_MMAP_IOMEM -static const struct vm_operations_struct snd_pcm_vm_ops_data_mmio = -{ - .open = snd_pcm_mmap_data_open, - .close = snd_pcm_mmap_data_close, -}; -int snd_pcm_lib_mmap_iomem (struct snd_pcm_substream *substream,struct vm_area_struct *area) {
@@ -3133,8 +3147,6 @@ int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream,#ifdef pgprot_noncached area->vm_page_prot =pgprot_noncached (area->vm_page_prot);#endif - area->vm_ops = &snd_pcm_vm_ops_data_mmio; - area->vm_private_data = substream; area->vm_flags |=VM_IO ; size = area->vm_end - area->vm_start; offset = area->vm_pgoff <<PAGE_SHIFT ;
@@ -3142,7 +3154,6 @@ int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, (substream->runtime->dma_addr + offset) >> PAGE_SHIFT, size, area->vm_page_prot))return -EAGAIN ; -atomic_inc (&substream->mmap_count);return 0 ; }
@@ -3159,6 +3170,7 @@ int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file,long size;unsigned long offset;size_t dma_bytes; +int err;if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) {if (!(area->vm_flags & (VM_WRITE |VM_READ )))
@@ -3183,10 +3195,15 @@ int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file,if (offset > dma_bytes - size)return -EINVAL ; + area->vm_ops = &snd_pcm_vm_ops_data; + area->vm_private_data = substream;if (substream->ops->mmap) -return substream->ops->mmap (substream, area); + err = substream->ops->mmap (substream, area);else -return snd_pcm_default_mmap (substream, area); + err =snd_pcm_default_mmap (substream, area); +if (!err) +atomic_inc (&substream->mmap_count); +return err; }EXPORT_SYMBOL (snd_pcm_mmap_data);
Signature · 1 line
1.6.5.3
PATCH 2/5 ALSA: pcm - define snd_pcm_default_page_ops()
Add a helper (inline) function as the default page ops. Any hacks wrt the page address conversion will be applied in this function.
--- sound/core/pcm_native.c | 20 ++++++++++++-------- 1 files changed, 12 insertions(+), 8 deletions(-)
sound/core/pcm_native.c +12 -8
@@ -3062,6 +3062,13 @@ static int snd_pcm_mmap_control(struct snd_pcm_substream *substream, struct file }#endif /* coherent mmap */ +static inline struct page * +snd_pcm_default_page_ops (struct snd_pcm_substream *substream,unsigned long ofs) +{ +void *vaddr = substream->runtime->dma_area + ofs; +return virt_to_page (vaddr); +} +/* * fault callback for mmapping a RAM page */
@@ -3072,7 +3079,6 @@ static int snd_pcm_mmap_data_fault(struct vm_area_struct *area,struct snd_pcm_runtime *runtime;unsigned long offset;struct page * page; -void *vaddr;size_t dma_bytes;if (substream ==NULL )
@@ -3082,14 +3088,12 @@ static int snd_pcm_mmap_data_fault(struct vm_area_struct *area, dma_bytes =PAGE_ALIGN (runtime->dma_bytes);if (offset > dma_bytes -PAGE_SIZE )return VM_FAULT_SIGBUS ; -if (substream->ops->page) { +if (substream->ops->page) page = substream->ops->page (substream, offset); -if (!page) -return VM_FAULT_SIGBUS ; - }else { - vaddr = runtime->dma_area + offset; - page =virt_to_page (vaddr); - } +else + page =snd_pcm_default_page_ops (substream, offset); +if (!page) +return VM_FAULT_SIGBUS ;get_page (page); vmf->page = page;return 0 ;
Signature · 1 line
1.6.5.3
PATCH 3/5 ALSA: pcm - fix page conversion on non-coherent MIPS arch
The non-coherent MIPS arch doesn't give the correct address by a simple virt_to_page() for pages allocated via dma_alloc_coherent().
Original patch by Wu Zhangjin <[email protected]>. A proper check of the buffer allocation type was added to avoid the wrong conversion.
Note that this doesn't fix perfectly: the pages should be marked with proper pgprot value. This will be done in a future implementation like the conversion to dma_mmap_coherent().
--- sound/core/pcm_native.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
sound/core/pcm_native.c +4 -0
@@ -3066,6 +3066,10 @@ static inline struct page * snd_pcm_default_page_ops(struct snd_pcm_substream *substream, unsigned long ofs) { void *vaddr = substream->runtime->dma_area + ofs; +#if defined(CONFIG_MIPS ) && defined(CONFIG_DMA_NONCOHERENT ) +if (substream->dma_buffer.dev.type ==SNDRV_DMA_TYPE_DEV ) +return virt_to_page (CAC_ADDR (vaddr)); +#endif return virt_to_page (vaddr); }
Signature · 1 line
1.6.5.3
PATCH 4/5 ALSA: pcm - fix page conversion on non-coherent PPC arch
The non-cohernet PPC arch doesn't give the correct address by a simple virt_to_page() for pages allocated via dma_alloc_coherent(). This patch adds a hack to fix the conversion similarly like MIPS.
Note that this doesn't fix perfectly: the pages should be marked with proper pgprot value. This will be done in a future implementation like the conversion to dma_mmap_coherent().
--- sound/core/pcm_native.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
sound/core/pcm_native.c +10 -0
@@ -3070,6 +3070,16 @@ snd_pcm_default_page_ops(struct snd_pcm_substream *substream, unsigned long ofs)if (substream->dma_buffer.dev.type ==SNDRV_DMA_TYPE_DEV )return virt_to_page (CAC_ADDR (vaddr));#endif +#if defined(CONFIG_PPC32 ) && defined(CONFIG_NOT_COHERENT_CACHE ) +if (substream->dma_buffer.dev.type ==SNDRV_DMA_TYPE_DEV ) { +dma_addr_t addr = substream->runtime->dma_addr + ofs; + addr -=get_dma_offset (substream->dma_buffer.dev.dev); +/* assume dma_handle set via pfn_to_phys() in +* mm/dma-noncoherent.c +*/ +return pfn_to_page (dma_handle >>PAGE_SHIFT ); + } +#endif return virt_to_page (vaddr); }
Signature · 1 line
1.6.5.3
PATCH 5/5 ALSA: Remove old DMA-mmap code from arm/devdma.c
The call of dma_mmap_coherent() is done in the PCM core now.
--- sound/arm/Makefile | 2 +- sound/arm/aaci.c | 16 +++------- sound/arm/devdma.c | 80 ---------------------------------------------------- sound/arm/devdma.h | 3 -- 4 files changed, 6 insertions(+), 95 deletions(-) delete mode 100644 sound/arm/devdma.c delete mode 100644 sound/arm/devdma.h
sound/arm/Makefile +1 -1
@@ -3,7 +3,7 @@ # obj-$(CONFIG_SND_ARMAACI) += snd-aaci.o -snd-aaci-objs := aaci.o devdma.o +snd-aaci-objs := aaci.o obj-$(CONFIG_SND_PXA2XX_PCM) += snd-pxa2xx-pcm.o snd-pxa2xx-pcm-objs := pxa2xx-pcm.o
sound/arm/aaci.c +5 -11
@@ -30,7 +30,6 @@#include <sound/pcm_params.h> #include "aaci.h" -#include "devdma.h" #define DRIVER_NAME "aaci-pl041"
@@ -492,7 +491,7 @@ static int aaci_pcm_hw_free(struct snd_pcm_substream *substream)/* * Clear out the DMA and any allocated buffers. */ -devdma_hw_free (NULL , substream); +snd_pcm_lib_free_pages (substream);return 0 ; }
@@ -505,8 +504,8 @@ static int aaci_pcm_hw_params(struct snd_pcm_substream *substream,aaci_pcm_hw_free (substream); - err =devdma_hw_alloc (NULL , substream, -params_buffer_bytes (params)); + err =snd_pcm_lib_malloc_pages (substream, +params_buffer_bytes (params));if (err <0 ) goto out;
@@ -551,11 +550,6 @@ static snd_pcm_uframes_t aaci_pcm_pointer(struct snd_pcm_substream *substream)return bytes_to_frames (runtime, bytes); } -static int aaci_pcm_mmap (struct snd_pcm_substream *substream,struct vm_area_struct *vma) -{ -return devdma_mmap (NULL , substream, vma); -} -/* * Playback specific ALSA stuff
@@ -722,7 +716,6 @@ static struct snd_pcm_ops aaci_playback_ops = { .prepare = aaci_pcm_prepare, .trigger = aaci_pcm_playback_trigger, .pointer = aaci_pcm_pointer, - .mmap = aaci_pcm_mmap, }; static int aaci_pcm_capture_hw_params(struct snd_pcm_substream *substream,
@@ -850,7 +843,6 @@ static struct snd_pcm_ops aaci_capture_ops = { .prepare = aaci_pcm_capture_prepare, .trigger = aaci_pcm_capture_trigger, .pointer = aaci_pcm_pointer, - .mmap = aaci_pcm_mmap, };/*
@@ -1040,6 +1032,8 @@ static int __devinit aaci_init_pcm(struct aaci *aaci)snd_pcm_set_ops (pcm,SNDRV_PCM_STREAM_PLAYBACK , &aaci_playback_ops);snd_pcm_set_ops (pcm,SNDRV_PCM_STREAM_CAPTURE , &aaci_capture_ops); +snd_pcm_lib_preallocate_pages_for_all (pcm,SNDRV_DMA_TYPE_DEV , +NULL ,0 ,64 *104 ); }return ret;
sound/arm/devdma.c deleted +0 -80
80 lines not on this page · raw message
sound/arm/devdma.h deleted +0 -3
@@ -1,3 +0,0 @@ -void devdma_hw_free (struct device *dev,struct snd_pcm_substream *substream); -int devdma_hw_alloc (struct device *dev,struct snd_pcm_substream *substream,size_t size); -int devdma_mmap (struct device *dev,struct snd_pcm_substream *substream,struct vm_area_struct *vma);
Signature · 1 line
1.6.5.3
Re: [PATCH 4/5] ALSA: pcm - fix page conversion on non-coherent PPC arch
In reply to Takashi IwaiSorry, a typo was in this patch. The fixed version is below.
FYI, the patchset is found in sound git tree topic/pcm-dma-fix branch:
git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6.git topic/pcm-dma-fix
thanks,
Takashi
Quoted 1 line
From
bc01f9e365d3afc041ab2c296107728c56410f8fMon Sep 17 00:00:00 2001
From: Takashi Iwai <[email protected]>
Date: Thu, 26 Nov 2009 15:04:24 +0100
Subject: [PATCH] ALSA: pcm - fix page conversion on non-coherent PPC arch
The non-cohernet PPC arch doesn't give the correct address by a simple virt_to_page() for pages allocated via dma_alloc_coherent(). This patch adds a hack to fix the conversion similarly like MIPS.
Note that this doesn't fix perfectly: the pages should be marked with proper pgprot value. This will be done in a future implementation like the conversion to dma_mmap_coherent().
--- sound/core/pcm_native.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)
sound/core/pcm_native.c +10 -0
@@ -3070,6 +3070,16 @@ snd_pcm_default_page_ops(struct snd_pcm_substream *substream, unsigned long ofs)if (substream->dma_buffer.dev.type ==SNDRV_DMA_TYPE_DEV )return virt_to_page (CAC_ADDR (vaddr));#endif +#if defined(CONFIG_PPC32 ) && defined(CONFIG_NOT_COHERENT_CACHE ) +if (substream->dma_buffer.dev.type ==SNDRV_DMA_TYPE_DEV ) { +dma_addr_t addr = substream->runtime->dma_addr + ofs; + addr -=get_dma_offset (substream->dma_buffer.dev.dev); +/* assume dma_handle set via pfn_to_phys() in +* mm/dma-noncoherent.c +*/ +return pfn_to_page (addr >>PAGE_SHIFT ); + } +#endif return virt_to_page (vaddr); }
Signature · 1 line
1.6.5.3
Re: [PATCH 4/5] ALSA: pcm - fix page conversion on non-coherent PPC arch
In reply to Takashi IwaiQuoted 9 lines · Takashi Iwai
The non-cohernet PPC arch doesn't give the correct address by a simple
virt_to_page()for pages allocated viadma_alloc_coherent(). This patch adds a hack to fix the conversion similarly like MIPS.Note that this doesn't fix perfectly: the pages should be marked with proper pgprot value. This will be done in a future implementation like the conversion to
dma_mmap_coherent().Signed-off-by Takashi Iwai <[email protected]>
This will not work with swiotlb, but then, I don't think we have -yet- to deal with a platform that does both swiotlb and isn't DMA coherent :-)
Of course, the conversion to dma_mmap_coherent will makes things better though we really will want to push that function into the dma ops.
So it's hackish but for now its an
Cheers,
Ben.
Quoted 25 lines
--- sound/core/pcm_native.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)sound/core/pcm_native.c +10
-0@@ -3070,6 +3070,16 @@ snd_pcm_default_page_ops(struct snd_pcm_substream *substream, unsigned long ofs)if (substream->dma_buffer.dev.type ==SNDRV_DMA_TYPE_DEV )return virt_to_page (CAC_ADDR (vaddr));#endif +#if defined(CONFIG_PPC32 ) && defined(CONFIG_NOT_COHERENT_CACHE ) +if (substream->dma_buffer.dev.type ==SNDRV_DMA_TYPE_DEV ) { +dma_addr_t addr = substream->runtime->dma_addr + ofs; + addr -=get_dma_offset (substream->dma_buffer.dev.dev); +/* assume dma_handle set via pfn_to_phys() in +* mm/dma-noncoherent.c +*/ +return pfn_to_page (dma_handle >>PAGE_SHIFT ); + } +#endif return virt_to_page (vaddr); }
Re: [PATCH 4/5] ALSA: pcm - fix page conversion on non-coherent PPC arch
In reply to Takashi IwaiQuoted 5 lines · Takashi Iwai
Sorry, a typo was in this patch. The fixed version is below.
FYI, the patchset is found in sound git tree topic/pcm-dma-fix branch:
git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6.gittopic/pcm-dma-fix
Ah, I didn't notice the typo :-) Ack still.
Cheers,
Ben.
Quoted 44 lines
thanks,
Takashi
From
bc01f9e365d3afc041ab2c296107728c56410f8fMon Sep 17 00:00:00 2001
From: Takashi Iwai <[email protected]>
Date: Thu, 26 Nov 2009 15:04:24 +0100
Subject: [PATCH] ALSA: pcm - fix page conversion on non-coherent PPC archThe non-cohernet PPC arch doesn't give the correct address by a simple
virt_to_page()for pages allocated viadma_alloc_coherent(). This patch adds a hack to fix the conversion similarly like MIPS.Note that this doesn't fix perfectly: the pages should be marked with proper pgprot value. This will be done in a future implementation like the conversion to
dma_mmap_coherent().Signed-off-by Takashi Iwai <[email protected]>--- sound/core/pcm_native.c | 10 ++++++++++ 1 files changed, 10 insertions(+), 0 deletions(-)sound/core/pcm_native.c +10
-0@@ -3070,6 +3070,16 @@ snd_pcm_default_page_ops(struct snd_pcm_substream *substream, unsigned long ofs)if (substream->dma_buffer.dev.type ==SNDRV_DMA_TYPE_DEV )return virt_to_page (CAC_ADDR (vaddr));#endif +#if defined(CONFIG_PPC32 ) && defined(CONFIG_NOT_COHERENT_CACHE ) +if (substream->dma_buffer.dev.type ==SNDRV_DMA_TYPE_DEV ) { +dma_addr_t addr = substream->runtime->dma_addr + ofs; + addr -=get_dma_offset (substream->dma_buffer.dev.dev); +/* assume dma_handle set via pfn_to_phys() in +* mm/dma-noncoherent.c +*/ +return pfn_to_page (addr >>PAGE_SHIFT ); + } +#endif return virt_to_page (vaddr); }
Re: [PATCH 3/5] ALSA: pcm - fix page conversion on non-coherent MIPS arch
In reply to Takashi IwaiQuoted 20 lines · Takashi Iwai
The non-coherent MIPS arch doesn't give the correct address by a simple
virt_to_page()for pages allocated viadma_alloc_coherent().Original patch by Wu Zhangjin <[email protected]>. A proper check of the buffer allocation type was added to avoid the wrong conversion.
Note that this doesn't fix perfectly: the pages should be marked with proper pgprot value. This will be done in a future implementation like the conversion to
dma_mmap_coherent().Signed-off-by Takashi Iwai <[email protected]>--- sound/core/pcm_native.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)sound/core/pcm_native.c +0
-0
sound/core/pcm_native.c static inline struct page * · line 3074
Quoted 9 lines
sound/core/pcm_native.c +4
-0@@ -3066,6 +3066,10 @@ static inline struct page * snd_pcm_default_page_ops(struct snd_pcm_substream *substream, unsigned long ofs) { void *vaddr = substream->runtime->dma_area + ofs; +#if defined(CONFIG_MIPS ) && defined(CONFIG_DMA_NONCOHERENT ) +if (substream->dma_buffer.dev.type ==SNDRV_DMA_TYPE_DEV ) +return virt_to_page (CAC_ADDR (vaddr)); +#endif return virt_to_page (vaddr); }
Works well on Loongson family machines, thanks!
Regards,
Wu Zhangjin
Re: [PATCH 3/5] ALSA: pcm - fix page conversion on non-coherent MIPS arch
In reply to Takashi IwaiQuoted 5 lines · Takashi Iwai
The non-coherent MIPS arch doesn't give the correct address by a simple
virt_to_page()for pages allocated viadma_alloc_coherent().Original patch by Wu Zhangjin <[email protected]>. A proper check of the buffer allocation type was added to avoid the wrong conversion.
The origins of this patch go back far further. The oldest patch I could find which is a superset of this was written by Atsushi Nemoto and various incarnations of it have been sumitted to and reject by me a number of times through the years.
Quoted 5 lines
Note that this doesn't fix perfectly: the pages should be marked with proper pgprot value. This will be done in a future implementation like the conversion to
dma_mmap_coherent().Signed-off-by Takashi Iwai <[email protected]>
So while this is ugly I don't think this patch will actually make the the situation worse for any MIPS platform. So with both eyes closed:
Ralf
Re: [PATCH 4/5] ALSA: pcm - fix page conversion on non-coherent PPC arch
In reply to Benjamin HerrenschmidtAt Fri, 27 Nov 2009 07:51:44 +1100,
Quoted 16 lines · Benjamin Herrenschmidt
Quoted 9 lines · Takashi Iwai
The non-cohernet PPC arch doesn't give the correct address by a simple
virt_to_page()for pages allocated viadma_alloc_coherent(). This patch adds a hack to fix the conversion similarly like MIPS.Note that this doesn't fix perfectly: the pages should be marked with proper pgprot value. This will be done in a future implementation like the conversion to
dma_mmap_coherent().Signed-off-by Takashi Iwai <[email protected]>This will not work with swiotlb, but then, I don't think we have -yet- to deal with a platform that does both swiotlb and isn't DMA coherent :-)
Quoted 6 lines
Of course, the conversion to
dma_mmap_coherentwill makes things better though we really will want to push that function into the dma ops.So it's hackish but for now its an
Thanks, I added your ack to the GIT commit.
Takashi
Re: [PATCH 3/5] ALSA: pcm - fix page conversion on non-coherent MIPS arch
In reply to Ralf BaechleAt Fri, 27 Nov 2009 08:46:35 +0000,
Quoted 18 lines · Ralf Baechle
Quoted 5 lines · Takashi Iwai
The non-coherent MIPS arch doesn't give the correct address by a simple
virt_to_page()for pages allocated viadma_alloc_coherent().Original patch by Wu Zhangjin <[email protected]>. A proper check of the buffer allocation type was added to avoid the wrong conversion.
The origins of this patch go back far further. The oldest patch I could find which is a superset of this was written by Atsushi Nemoto and various incarnations of it have been sumitted to and reject by me a number of times through the years.
Quoted 4 lines
Note that this doesn't fix perfectly: the pages should be marked with proper pgprot value. This will be done in a future implementation like the conversion to
dma_mmap_coherent().
Quoted 6 lines
Quoted 1 line
Signed-off-by Takashi Iwai <[email protected]>So while this is ugly I don't think this patch will actually make the the situation worse for any MIPS platform. So with both eyes closed:
Acked-by Ralf Baechle <[email protected]>
I added your ack with the comment about the origins to the GIT commit now.
Thanks for closing your eyes ;) Hopefully this hack can be removed again shortly...
Takashi
Re: [PATCH 3/5] ALSA: pcm - fix page conversion on non-coherent MIPS arch
In reply to Wu ZhangjinAt Fri, 27 Nov 2009 11:52:58 +0800,
Quoted 17 lines · Wu Zhangjin
Quoted 15 lines · Takashi Iwai
The non-coherent MIPS arch doesn't give the correct address by a simple
virt_to_page()for pages allocated viadma_alloc_coherent().Original patch by Wu Zhangjin <[email protected]>. A proper check of the buffer allocation type was added to avoid the wrong conversion.
Note that this doesn't fix perfectly: the pages should be marked with proper pgprot value. This will be done in a future implementation like the conversion to
dma_mmap_coherent().Signed-off-by Takashi Iwai <[email protected]>--- sound/core/pcm_native.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-)
Quoted 16 lines
Quoted 5 lines
sound/core/pcm_native.c +0
-0sound/core/pcm_native.c static inline struct page * · line 3074
Quoted 9 lines
sound/core/pcm_native.c +4
-0@@ -3066,6 +3066,10 @@ static inline struct page * snd_pcm_default_page_ops(struct snd_pcm_substream *substream, unsigned long ofs) { void *vaddr = substream->runtime->dma_area + ofs; +#if defined(CONFIG_MIPS ) && defined(CONFIG_DMA_NONCOHERENT ) +if (substream->dma_buffer.dev.type ==SNDRV_DMA_TYPE_DEV ) +return virt_to_page (CAC_ADDR (vaddr)); +#endif return virt_to_page (vaddr); }Works well on Loongson family machines, thanks!
Thanks for checking!
Takashi
Hi,
I've tried this patch set (with the typo-corrected part 4) on my ASUS WL-500gP v2 MIPSEL via a backport to 2.6.31.9, but all I get is a small blip of the sound I wanted to play, and then the system is fubar (I believe just the same thing as what happened without having this patch applied).
Probably I'm dense and the patch is ARM-only, or my MIPSEL has incorrect cache coherency versus this patch set, or the backport failed due to missing requirements or conflicts.
Attached are two crash logs.
Any ideas?
Would be nice to see this resolved as well, since I now _finally_ have a working consterna^Wconstellation (netconsole, boot, USB host, USB serial) with my patched-up 2.6.31.9 build.
Thanks,
Andreas Mohr
Instruction bus error, epc == 2ab4f178, ra == 80000018
kobject: 'ep_01' (81e8a690): kobject_uevent_env
kobject: 'ep_01' (81e8a690): kobject_uevent_env: filter function caused the event to drop!
kobject: 'ep_01' (81e8a690): kobject_cleanup
kobject: 'ep_01' (81e8a690): calling ktype release
kobject: 'ep_01': free nameEHCI_DIS: hcd 81dd7080 ep 81e09180 qh (null) (#01)
Instruction bus error, epc == 8003475c, ra == 80000018
Oops[#1]:
Cpu 0
$ 0 : 00000000 1000d001 00000000 80000000
$ 4 : 81dad838 806e5e00 00000000 00000000
$ 8 : 00000000 00000000 81040000 81f16000
$12 : 81da0868 80340000 81da0868 0000000a
$16 : 00000000 7fb2dd68 000005b8 81dad838
$20 : 0000000a 81e37ef8 20000000 fffffff6
$24 : 00000000 801874c0
$28 : 81e36000 81e37e40 00000001 80000018
Hi : 00000000
Lo : 00000000
epc : 8003475c wait_consider_task+0x49c/0xe20
Not tainted
ra : 80000018 0x80000018
Status: 1000d003 KERNEL EXL IE
Cause : 00800018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: ipv6 snd_usb_audio arc4 snd_pcm_oss ecb snd_mixer_oss cryptomgr aead snd_pcm pcompress crypto_blkcipher snd_timer crypto_hash snd_page_alloc evdev ftdi_sio crypto_algapi snd_usb_lib snd_rawmidi b43 mac80211 snd_seq_device snd_hwdep usbhid cfg80211 usbserial hid snd input_core soundcore
Process bash (pid: 1447, threadinfo=81e36000, task=81da0838, tls=00000000)
Stack : 8033dab8 80027e24 815bdde4 802b89e0 8033c000 81da0838 00000000 8000ace0
00000000 00000000 80047476 0051f510 81dad838 81da0838 00000000 81da094c
81e37ef8 ffffffff 20000000 fffffff6 00000001 800351b4 00000004 801c7cf8
81f323d8 81db5870 00000000 81da0838 8002d0c4 806e5e08 806e5e08 81da0838
0000000a 00000000 7fb2dd68 00000000 0051f56c 00000000 00440000 00525790
...
Call Trace:
[<8003475c>] wait_consider_task+0x49c/0xe20
[<800351b4>] do_wait+0xd4/0x340
[<800354e0>] sys_wait4+0xc0/0xec
[<800031f0>] stack_done+0x20/0x3cCode: 00431024 14400251 00000000 <ae340000> 16000051 8eb1000c 12200051 8fa30020 0c002bc1
Disabling lock debugging due to kernel taint Instruction bus error, epc == 80004dd8, ra == 80000018 Oops[#2]:
Cpu 0
$ 0 : 00000000 1000d000 00000000 00000000
$ 4 : 7f9765d0 81c0ddd0 00000000 1000d001
$ 8 : 00000000 00000000 00000000 81e36000
$12 : 81c084b0 003d0900 81c084b0 00000000
$16 : 00000004 00000000 81c0ddc0 81c0ddc0
$20 : 7f9765d0 00000000 81c0ddcc 00000000
$24 : 00000000 801874c0
$28 : 81c0c000 81c0dd98 00000001 80000018
Hi : 0000004d
Lo : ab64ed00
epc : 80004dd8 __copy_user+0xd4/0x2bc
Tainted: G D
ra : 80000018 0x80000018
Status: 1000d003 KERNEL EXL IE
Cause : 00800018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: ipv6 snd_usb_audio arc4 snd_pcm_oss ecb snd_mixer_oss cryptomgr aead snd_pcm pcompress crypto_blkcipher snd_timer crypto_hash snd_page_alloc evdev ftdi_sio crypto_algapi snd_usb_lib snd_rawmidi b43 mac80211 snd_seq_device snd_hwdep usbhid cfg80211 usbserial hid snd input_core soundcore
Process init (pid: 1, threadinfo=81c0c000, task=81c08480, tls=00000000)
Stack : 00000000 81c0dda8 81c0df00 80350fb0 81c0ddc0 81c0ddc4 81c0ddc8 81c0ddcc
81c0ddd0 81c0ddd4 00000400 00000000 00000000 00000000 00000000 00000000
00000000 00000000 81f0b000 ffffff9c 81c0dea8 0044a234 7f9769b8 8009b864
00000001 81c0dea8 00000001 81f0b000 ffffff9c 800a2d18 00000003 00000002
00000003 00000003 0000000d 00000000 00000000 00000000 000000c9 00001180
...
Call Trace:
[<80004dd8>] __copy_user+0xd4/0x2bcCode: 8ca80000 24a50004 24c6fffc <ac880000> 1706fffb 24840004 10c00040 00864821 240a0020
Instruction bus error, epc == 80004dd8, ra == 80000018
Oops[#3]:
Cpu 0
$ 0 : 00000000 1000d000 00000000 00000004
$ 4 : 004c7130 81735dd0 00000000 1000d001
$ 8 : 00000080 00000000 00000000 81e36000
$12 : 81d0e868 00000000 81d0e868 00000000
$16 : 00000004 00000001 81735dc0 81735dc0
$20 : 004c7130 004c7360 81735dcc 00000000
$24 : 00000000 80181208
$28 : 81734000 81735d98 004b0000 80000018
Hi : 00000000
Lo : 00000000
epc : 80004dd8 __copy_user+0xd4/0x2bc
Tainted: G D
ra : 80000018 0x80000018
Status: 1000d003 KERNEL EXL IE
Cause : 00800018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: ipv6 snd_usb_audio arc4 snd_pcm_oss ecb snd_mixer_oss cryptomgr aead snd_pcm pcompress crypto_blkcipher snd_timer crypto_hash snd_page_alloc evdev ftdi_sio crypto_algapi snd_usb_lib snd_rawmidi b43 mac80211 snd_seq_device snd_hwdep usbhid cfg80211 usbserial hid snd input_core soundcore
Process sshd (pid: 1445, threadinfo=81734000, task=81d0e838, tls=00000000)
Stack : 0041663c 81735da8 00000000 80200478 81735dc0 81735dc4 81735dc8 81735dcc
81735dd0 81735dd4 00000098 00000000 00000000 00000080 00000000 00000000
00000000 00000000 81735e20 00000001 00000000 00000000 00000040 81735e28
81735e28 fffffdee 81735e20 8009e530 00000000 8173b080 81f731e8 8167d900
00000000 00000000 004bd538 00000090 81cdd360 81ed3160 00000000 00000001
...
Call Trace:
[<80004dd8>] __copy_user+0xd4/0x2bcCode: 8ca80000 24a50004 24c6fffc <ac880000> 1706fffb 24840004 10c00040 00864821 240a0020
Instruction bus error, epc == 80096fa0, ra == 80000018
Oops[#4]:
Cpu 0
$ 0 : 00000000 1000d000 c02e2002 00000002
$ 4 : 00000001 803b5514 00000001 00000001
$ 8 : 80351000 00080000 81040000 81e36000
$12 : 00000000 645fcd00 81da0868 0000000b
$16 : 00000001 81e26138 0044e000 003f0fff
$20 : 0046c000 0126b79f 00000000 00000000
$24 : 00000000 80018ff0
$28 : 81c0c000 81c0db48 fffffffe 80000018
Hi : 00000000
Lo : 00000000
epc : 80096fa0 swap_info_get+0x74/0xfc
Tainted: G D
ra : 80000018 0x80000018
Status: 1000d003 KERNEL EXL IE
Cause : 00800018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: ipv6 snd_usb_audio arc4 snd_pcm_oss ecb snd_mixer_oss cryptomgr aead snd_pcm pcompress crypto_blkcipher snd_timer crypto_hash snd_page_alloc evdev ftdi_sio crypto_algapi snd_usb_lib snd_rawmidi b43 mac80211 snd_seq_device snd_hwdep usbhid cfg80211 usbserial hid snd input_core soundcore
Process init (pid: 1, threadinfo=81c0c000, task=81c08480, tls=00000000)
Stack : fffffffe 800736a0 00000008 81da0870 80350fd0 80099498 81c08614 81024d60
81e26130 0044c000 00002000 81e26138 0044e000 80088a30 8033dab8 80029d78
7f9765d0 00000000 0046bfff 8033d9c0 81e244a0 81e25004 81e25004 0046c000
00000000 00000001 81e0ba9c 81e244a0 8037f840 81e244d4 81c08480 00000000
00000001 00000000 00000001 8008db1c 81c0dbf0 81e2d354 00000000 ffffffff
...
Call Trace:
[<80096fa0>] swap_info_get+0x74/0xfc
[<80099498>] free_swap_and_cache+0x1c/0x218
[<80088a30>] unmap_vmas+0x418/0x63c
[<8008db1c>] exit_mmap+0xb8/0x148
[<8002e3c4>] mmput+0xc0/0x1d8
[<800333e8>] exit_mm+0x260/0x298
[<800357cc>] do_exit+0x1cc/0x688
[<80014658>] nmi_exception_handler+0x0/0x34Code: 00041840 8ca20020 00431021 <94440000> 1480001d 8fbf0014 3c048030 3c05802c 24a5f280
Fixing recursive fault but reboot is needed! Instruction bus error, epc == 80011530, ra == 80000018 Oops[#5]:
Cpu 0
$ 0 : 00000000 1000d001 24020000 80000000
$ 4 : 7fe3fd00 24021017 00000278 81d86be4
$ 8 : 800125cc 80621e80 ffffffff ffffffff
$12 : 00000000 80340000 81d86868 0000000b
$16 : 00000000 00000000 7fe3fcf0 80621f30
$20 : 7fe3fd08 7fe3fd00 81d86be4 00000012
$24 : 00000000 8025e170
$28 : 80620000 80621e10 80621e80 80000018
Hi : 00000000
Lo : 00000000
epc : 80011530 install_sigtramp+0x20/0x54
Tainted: G D
ra : 80000018 0x80000018
Status: 1000d003 KERNEL EXL IE
Cause : 00800018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: ipv6 snd_usb_audio arc4 snd_pcm_oss ecb snd_mixer_oss cryptomgr aead snd_pcm pcompress crypto_blkcipher snd_timer crypto_hash snd_page_alloc evdev ftdi_sio crypto_algapi snd_usb_lib snd_rawmidi b43 mac80211 snd_seq_device snd_hwdep usbhid cfg80211 usbserial hid snd input_core soundcore
Process sshd (pid: 1372, threadinfo=80620000, task=81d86838, tls=00000000)
Stack : 80621f30 80621e98 8059ae20 8061f004 00000009 80621f30 00000012 8001263c
81e82448 81e82448 81c59808 800b212c 80621f30 00000012 80621e80 81d86be4
80621e98 ffffffff 004b352c 00000000 00000004 800116bc 817a5000 80621e80
80621f30 80621ea8 00000010 81e82448 00000000 0040ac18 00000000 00000000
00000000 00000000 00000012 00040002 00000000 000005a5 00000000 0000000b
...
Call Trace:
[<80011530>] install_sigtramp+0x20/0x54
[<8001263c>] setup_frame+0x70/0x110
[<800116bc>] do_notify_resume+0x158/0x428
[<800015f0>] work_notifysig+0xc/0x14Code: afbf001c 00a22821 02008821 <ac850000> 2402000c ac820004 3c038038 8c620038 0040f809
Instruction bus error, epc == 2ac68e50, ra == 80000018 Instruction bus error, epc == 8003475c, ra == 80000018 Oops[#1]:
Cpu 0
$ 0 : 00000000 1000d001 00000000 80000000
$ 4 : 81d4f838 80733c00 00000000 00000000
$ 8 : 00000000 00000000 81040000 81ef2000
$12 : 81312868 80340000 81312868 0000000a
$16 : 00000000 7fd95c08 000005af 81d4f838
$20 : 0000000a 81891ef8 20000000 fffffff6
$24 : 00000000 80018ff0
$28 : 81890000 81891e40 00000001 80000018
Hi : 00000000
Lo : 00000000
epc : 8003475c wait_consider_task+0x49c/0xe20
Not tainted
ra : 80000018 0x80000018
Status: 1000d003 KERNEL EXL IE
Cause : 00800018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: ipv6 arc4 snd_usb_audio ecb snd_pcm_oss cryptomgr snd_mixer_oss aead pcompress snd_pcm crypto_blkcipher crypto_hash snd_timer crypto_algapi snd_page_alloc evdev snd_usb_lib b43 ftdi_sio mac80211 snd_rawmidi snd_seq_device cfg80211 usbhid snd_hwdep usbserial hid snd input_core soundcore
Process bash (pid: 1450, threadinfo=81890000, task=81312838, tls=00000000)
Stack : 8033dab8 80027e24 7fd95c08 802c0000 81db5838 81312838 00000000 8000ace0
00000000 00000000 80047476 0051f510 81d4f838 81312838 00000000 8131294c
81891ef8 ffffffff 20000000 fffffff6 00000001 800351b4 00000004 801c7cf8
81e590b8 81db5870 00000000 81312838 8002d0c4 80733c08 80733c08 81312838
0000000a 00000000 7fd95c08 00000000 0051f56c 00000000 00440000 00525790
...
Call Trace:
[<8003475c>] wait_consider_task+0x49c/0xe20
[<800351b4>] do_wait+0xd4/0x340
[<800354e0>] sys_wait4+0xc0/0xec
[<800031f0>] stack_done+0x20/0x3cCode: 00431024 14400251 00000000 <ae340000> 16000051 8eb1000c 12200051 8fa30020 0c002bc1
Disabling lock debugging due to kernel taint Instruction bus error, epc == 80004dd8, ra == 80000018 Oops[#2]:
Cpu 0
$ 0 : 00000000 1000d000 00000000 00000000
$ 4 : 7fca8450 81c0ddd0 00000000 1000d001
$ 8 : 00000000 00000000 00000000 81890000
$12 : 81c084b0 003d0900 81c084b0 00000000
$16 : 00000004 00000000 81c0ddc0 81c0ddc0
$20 : 7fca8450 00000000 81c0ddcc 00000000
$24 : 00000000 801874c0
$28 : 81c0c000 81c0dd98 00000001 80000018
Hi : 0000013d
Lo : 9812c600
epc : 80004dd8 __copy_user+0xd4/0x2bc
Tainted: G D
ra : 80000018 0x80000018
Status: 1000d003 KERNEL EXL IE
Cause : 00800018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: ipv6 arc4 snd_usb_audio ecb snd_pcm_oss cryptomgr snd_mixer_oss aead pcompress snd_pcm crypto_blkcipher crypto_hash snd_timer crypto_algapi snd_page_alloc evdev snd_usb_lib b43 ftdi_sio mac80211 snd_rawmidi snd_seq_device cfg80211 usbhid snd_hwdep usbserial hid snd input_core soundcore
Process init (pid: 1, threadinfo=81c0c000, task=81c08480, tls=00000000)
Stack : 00000000 81c0dda8 81c0df00 80350fb0 81c0ddc0 81c0ddc4 81c0ddc8 81c0ddcc
81c0ddd0 81c0ddd4 00000400 00000000 00000000 00000000 00000000 00000000
00000000 00000000 81ec3000 ffffff9c 81c0dea8 0044a234 7fca8838 8009b864
00000001 81c0dea8 00000001 81ec3000 ffffff9c 800a2d18 00000003 00000002
00000003 00000003 0000000d 00000000 00000000 00000000 000000cb 00001180
...
Call Trace:
[<80004dd8>] __copy_user+0xd4/0x2bcCode: 8ca80000 24a50004 24c6fffc <ac880000> 1706fffb 24840004 10c00040 00864821 240a0020
Instruction bus error, epc == 80004dd8, ra == 80000018
Oops[#3]:
Cpu 0
$ 0 : 00000000 1000d000 00000000 00000004
$ 4 : 004c7130 81ebbdd0 00000000 1000d001
$ 8 : 00000080 00000000 00000000 81890000
$12 : 81d5c868 00000000 81d5c868 00000000
$16 : 00000004 00000001 81ebbdc0 81ebbdc0
$20 : 004c7130 004c7360 81ebbdcc 00000000
$24 : 00000000 80181208
$28 : 81eba000 81ebbd98 004b0000 80000018
Hi : 00000000
Lo : 00000000
epc : 80004dd8 __copy_user+0xd4/0x2bc
Tainted: G D
ra : 80000018 0x80000018
Status: 1000d003 KERNEL EXL IE
Cause : 00800018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: ipv6 arc4 snd_usb_audio ecb snd_pcm_oss cryptomgr snd_mixer_oss aead pcompress snd_pcm crypto_blkcipher crypto_hash snd_timer crypto_algapi snd_page_alloc evdev snd_usb_lib b43 ftdi_sio mac80211 snd_rawmidi snd_seq_device cfg80211 usbhid snd_hwdep usbserial hid snd input_core soundcore
Process sshd (pid: 1448, threadinfo=81eba000, task=81d5c838, tls=00000000)
Stack : cd09000a 81ebbda8 00000000 00000005 81ebbdc0 81ebbdc4 81ebbdc8 81ebbdcc
81ebbdd0 81ebbdd4 00000098 00000000 00000000 00000080 00000000 00000000
000000e2 81cdd360 81ea39d0 81c4ff20 000000e2 81cdd360 81c4ff20 80251b38
000000e3 80251e78 81ebbe20 8009e530 81cdd080 81c4ff20 81cdd388 80215c18
80000000 81c4ff20 00000042 000000e2 81cdd360 81c4ff20 00000042 801af5f0
...
Call Trace:
[<80004dd8>] __copy_user+0xd4/0x2bcCode: 8ca80000 24a50004 24c6fffc <ac880000> 1706fffb 24840004 10c00040 00864821 240a0020 Kernel panic - not syncing: Attempted to kill init!
At Fri, 1 Jan 2010 20:31:30 +0100,
Quoted 8 lines · Andreas Mohr
Hi,
I've tried this patch set (with the typo-corrected part 4) on my ASUS WL-500gP v2 MIPSEL via a backport to 2.6.31.9, but all I get is a small blip of the sound I wanted to play, and then the system is fubar (I believe just the same thing as what happened without having this patch applied).
As I mentioned in the previous followup, if your device is a USB-audio, the patch doesn't help because it's for devices with buffers using dma_alloc_coherent(). For USB-audio, it uses vmalloc for an intermediate buffer. Maybe this should be changed to dma_*() stuff for such architectures.
Nevertheless, I don't know whether the crash is related with the audio part...
Takashi
At Tue, 12 Jan 2010 08:02:36 +0100,
Quoted 12 lines · I wrote:
At Fri, 1 Jan 2010 20:31:30 +0100,
Quoted 8 lines · Andreas Mohr
Hi,
I've tried this patch set (with the typo-corrected part 4) on my ASUS WL-500gP v2 MIPSEL via a backport to 2.6.31.9, but all I get is a small blip of the sound I wanted to play, and then the system is fubar (I believe just the same thing as what happened without having this patch applied).
Quoted 5 lines
As I mentioned in the previous followup, if your device is a USB-audio, the patch doesn't help because it's for devices with buffers using
dma_alloc_coherent(). For USB-audio, it uses vmalloc for an intermediate buffer. Maybe this should be changed to dma_*() stuff for such architectures.
A quick patch below (totally untested!) might do that.
It's passing the device struct blindly, so not sure whether this would actually work for all dma_alloc_coherent().
Takashi
---
sound/usb/usbaudio.c +21 -1
@@ -734,7 +734,7 @@ static void snd_complete_sync_urb(struct urb *urb) } } - +#ifdef USBAUDIO_VMALLOC_BUFFER /* get the physical page pointer at the given offset */ static struct page *snd_pcm_get_vmalloc_page (struct snd_pcm_substream *subs,unsigned long offset)
@@ -769,6 +769,24 @@ static int snd_pcm_free_vmalloc_buffer(struct snd_pcm_substream *subs) return 0; } +#define preallocate_buffer (chip, pcm, stream)/* NOP */ + +#else +#define snd_pcm_get_vmalloc_page NULL +#define snd_pcm_alloc_vmalloc_buffer snd_pcm_lib_malloc_pages +#define snd_pcm_free_vmalloc_buffer snd_pcm_lib_free_pages + +static int preallocate_buffer (struct snd_usb_audio *chip,struct snd_pcm *pcm, +int stream) +{ +struct snd_pcm_substream *subs = pcm->streams[stream].substream; +if (!subs) +return 0 ; +return snd_pcm_lib_preallocate_pages (subs,SNDRV_DMA_TYPE_DEV , + chip->card->dev, +1024 *64 ,1024 *1024 ); +} +#endif /* * unlink active urbs.
@@ -2328,6 +2346,7 @@ static int add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct aud err =snd_pcm_new_stream (as->pcm, stream,1 );if (err <0 )return err; +preallocate_buffer (chip, as->pcm, stream);init_substream (as, stream, fp);return 0 ; }
@@ -2356,6 +2375,7 @@ static int add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct audelse strcpy (pcm->name,"USB Audio" ); +preallocate_buffer (chip, pcm, stream);init_substream (as, stream, fp);list_add (&as->list, &chip->pcm_list);
Hi,
Quoted 10 lines · Takashi Iwai
At Fri, 1 Jan 2010 20:31:30 +0100,
Quoted 8 lines · Andreas Mohr
Hi,
I've tried this patch set (with the typo-corrected part 4) on my ASUS WL-500gP v2 MIPSEL via a backport to 2.6.31.9, but all I get is a small blip of the sound I wanted to play, and then the system is fubar (I believe just the same thing as what happened without having this patch applied).
Crap, you already managed to beat me to my own reply! ;) (I'll try your patch in the other mail _ASAP_)
Quoted 5 lines
As I mentioned in the previous followup, if your device is a USB-audio, the patch doesn't help because it's for devices with buffers using
dma_alloc_coherent(). For USB-audio, it uses vmalloc for an intermediate buffer. Maybe this should be changed to dma_*() stuff for such architectures.
I've been searching the mailing list postings up and down, but I couldn't deduce anything to that effect from that content (but I'm mailing list-externally - maybe I just really didn't find the correct posting or there was a threading split)
Quoted 2 lines
Nevertheless, I don't know whether the crash is related with the audio part...
Yes, I wasn't fully pointing at the crash being caused by insufficient patches in that area either...
(but I haven't fully investigated these OOPSes yet)
Thanks a lot for your new test patch,
Andreas Mohr
Quoted 9 lines · Takashi Iwai
Quoted 5 lines
As I mentioned in the previous followup, if your device is a USB-audio, the patch doesn't help because it's for devices with buffers using
dma_alloc_coherent(). For USB-audio, it uses vmalloc for an intermediate buffer. Maybe this should be changed to dma_*() stuff for such architectures.A quick patch below (totally untested!) might do that.
It's passing the device struct blindly, so not sure whether this would actually work for alldma_alloc_coherent().
Thanks a lot, tested, but AFAICS there isn't much of a change unfortunately (log below).
Note that the old snd-usb-audio.ko did contain snd_pcm_get_vmalloc_page(), and the new one (put in the correct kernel version dir and depmod -a) doesn't, thus the patch was applied and did make it to the binary side, and it did get loaded correctly upon plugging I think.
Would one also want strace/ltrace output of the userspace side of things? (likely rather useless, except for perhaps nailing that it does crash where we think it crashes or so)
Frankly I'm still pretty much in uninformed shape concerning this mmap pcm buffer issue, would need to take quite a bit more time for research in order to be able to take part in the discussion in a productive way ;)
Thanks,
Andreas Mohr
# cat /usr/local/bin/audio_test.sh #!/bin/sh
# better make sure... sync sleep 1
aplay /usr/local/sounds/attention
[LOCKUP]
$ ../netconsole.sh
kobject: 'ep_01' (81f70090): kobject_add_internal: parent: '2-1.1.1:1.1', set: 'devices'
kobject: 'ep_01' (81f70090): kobject_uevent_env
kobject: 'ep_01' (81f70090): kobject_uevent_env: filter function caused the event to drop!
setting usb interface 1:1
Instruction bus error, epc == 2ab4f178, ra == 80000018
kobject: 'ep_01' (81f70090): kobject_uevent_env
kobject: 'ep_01' (81f70090): kobject_uevent_env: filter function caused the event to drop!
kobject: 'ep_01' (81f70090): kobject_cleanup
kobject: 'ep_01' (81f70090): calling ktype release
kobject: 'ep_01': free name
EHCI_DIS: hcd 81dd7080 ep 81604800 qh (null) (#01)
Instruction bus error, epc == 8003475c, ra == 80000018
Oops[#1]:
Cpu 0
$ 0 : 00000000 1000d001 00000000 80000000
$ 4 : 81d30838 81e57ac0 00000000 00000000
$ 8 : 00000000 00000000 81040000 81ec8000
$12 : 81d37868 80340000 81d37868 0000000a
$16 : 00000000 7fa911e8 00000538 81d30838
$20 : 0000000a 81f0def8 20000000 fffffff6
$24 : 00000000 801874c0
$28 : 81f0c000 81f0de40 00000001 80000018
Hi : 00000000
Lo : 00000000
epc : 8003475c wait_consider_task+0x49c/0xe20
Not tainted
ra : 80000018 0x80000018
Status: 1000d003 KERNEL EXL IE
Cause : 00800018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: snd_usb_audio snd_pcm_oss snd_mixer_oss snd_pcm snd_timer evdev snd_page_alloc snd_usb_lib snd_rawmidi snd_seq_device snd_hwdep usbhid hid snd input_core soundcore ipv6 arc4 ecb cryptomgr aead pcompress crypto_blkcipher crypto_hash crypto_algapi b43 ftdi_sio mac80211 cfg80211 usbserial
Process audio_test.sh (pid: 1333, threadinfo=81f0c000, task=81d37838, tls=00000000)
Stack : 8033dab8 80027e24 81e8488c 802b89e0 8033c000 81d37838 00000000 8000ace0
00000000 00000000 81e57e60 80018238 81d30838 81d37838 00000000 81d3794c
81f0def8 ffffffff 20000000 fffffff6 00000001 800351b4 00000004 801c7cf8
7fa911a8 81db5870 00000000 81d37838 8002d0c4 81e57ac8 81e57ac8 81d37838
00000000 00000000 7fa911e8 00000000 0051f56c 00000000 00440000 00525790
...
Call Trace:
[<8003475c>] wait_consider_task+0x49c/0xe20
[<800351b4>] do_wait+0xd4/0x340
[<800354e0>] sys_wait4+0xc0/0xec
[<800031f0>] stack_done+0x20/0x3c Code: 00431024 14400251 00000000 <ae340000> 16000051 8eb1000c 12200051 8fa30020 0c002bc1
Disabling lock debugging due to kernel taint Instruction bus error, epc == 80004dd8, ra == 80000018 Oops[#2]:
Cpu 0
$ 0 : 00000000 1000d000 00000000 00000000
$ 4 : 7ff0dc60 81c0ddd0 00000000 1000d001
$ 8 : 00000000 00000000 00000000 81f0c000
$12 : 81c084b0 003d0900 81c084b0 00000000
$16 : 00000004 00000000 81c0ddc0 81c0ddc0
$20 : 7ff0dc60 00000000 81c0ddcc 00000000
$24 : 00000000 801874c0
$28 : 81c0c000 81c0dd98 00000001 80000018
Hi : 0000007f
Lo : 3d391e00
epc : 80004dd8 __copy_user+0xd4/0x2bc
Tainted: G D
ra : 80000018 0x80000018
Status: 1000d003 KERNEL EXL IE
Cause : 00800018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: snd_usb_audio snd_pcm_oss snd_mixer_oss snd_pcm snd_timer evdev snd_page_alloc snd_usb_lib snd_rawmidi snd_seq_device snd_hwdep usbhid hid snd input_core soundcore ipv6 arc4 ecb cryptomgr aead pcompress crypto_blkcipher crypto_hash crypto_algapi b43 ftdi_sio mac80211 cfg80211 usbserial
Process init (pid: 1, threadinfo=81c0c000, task=81c08480, tls=00000000)
Stack : 00000000 81c0dda8 81c0df00 80350fb0 81c0ddc0 81c0ddc4 81c0ddc8 81c0ddcc
81c0ddd0 81c0ddd4 00000400 00000000 00000000 00000000 00000000 00000000
00000000 00000000 81f04000 ffffff9c 81c0dea8 0044a234 7ff0e048 8009b864
00000001 81c0dea8 00000001 81f04000 ffffff9c 800a2d18 00000003 00000002
00000003 00000003 0000000d 00000000 00000000 00000000 000000cc 00001180
...
Call Trace:
[<80004dd8>] __copy_user+0xd4/0x2bc Code: 8ca80000 24a50004 24c6fffc <ac880000> 1706fffb 24840004 10c00040 00864821 240a0020
Instruction bus error, epc == 8003475c, ra == 80000018
Oops[#3]:
Cpu 0
$ 0 : 00000000 1000d001 00000000 80000000
$ 4 : 81d37838 80415e00 00000000 00000000
$ 8 : 00000000 00000000 81040000 81f0c000
$12 : 80484868 80340000 80484868 0000000b
$16 : 00000000 7febff60 00000535 81d37838
$20 : 0000000b 81e2bef8 20000000 fffffff6
$24 : 00000000 80018ff0
$28 : 81e2a000 81e2be40 00000001 80000018
Hi : 00000000
Lo : 00000000
epc : 8003475c wait_consider_task+0x49c/0xe20
Tainted: G D
ra : 80000018 0x80000018
Status: 1000d003 KERNEL EXL IE
Cause : 00800018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: snd_usb_audio snd_pcm_oss snd_mixer_oss snd_pcm snd_timer evdev snd_page_alloc snd_usb_lib snd_rawmidi snd_seq_device snd_hwdep usbhid hid snd input_core soundcore ipv6 arc4 ecb cryptomgr aead pcompress crypto_blkcipher crypto_hash crypto_algapi b43 ftdi_sio mac80211 cfg80211 usbserial
Process bash (pid: 1175, threadinfo=81e2a000, task=80484838, tls=00000000)
Stack : 8033dab8 80027e24 81f18390 00002a84 81d37838 80484838 81e57e60 8000ace0
00000000 00000000 80047476 0051f510 81d37838 80484838 00000000 8048494c
81e2bef8 ffffffff 20000000 fffffff6 00000001 800351b4 81e8a1e0 00000008
81e8a0d4 81d37870 00000000 80484838 8002d0c4 80415e08 80415e08 80484838
0000000a 00000000 7febff60 00000000 0051f56c 00000000 00440000 00525790
...
Call Trace:
[<8003475c>] wait_consider_task+0x49c/0xe20
[<800351b4>] do_wait+0xd4/0x340
[<800354e0>] sys_wait4+0xc0/0xec
[<800031f0>] stack_done+0x20/0x3c Code: 00431024 14400251 00000000 <ae340000> 16000051 8eb1000c 12200051 8fa30020 0c002bc1
Instruction bus error, epc == 80096fa0, ra == 80000018
Oops[#4]:
Cpu 0
$ 0 : 00000000 1000d000 c0180002 00000002
$ 4 : 00000001 803b5514 00000001 81e24000
$ 8 : 80351000 00080000 81040000 81e2a000
$12 : 00000000 07de2900 ffffffff 00000000
$16 : 00000001 81e24fa0 2abe8000 003cbf03
$20 : 2abe9000 0119a613 00000000 00000000
$24 : 00000000 80018ff0
$28 : 81c0c000 81c0db48 00000000 80000018
Hi : 00000000
Lo : 00000000
epc : 80096fa0 swap_info_get+0x74/0xfc
Tainted: G D
ra : 80000018 0x80000018
Status: 1000d003 KERNEL EXL IE
Cause : 00800018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: snd_usb_audio snd_pcm_oss snd_mixer_oss snd_pcm snd_timer evdev snd_page_alloc snd_usb_lib snd_rawmidi snd_seq_device snd_hwdep usbhid hid snd input_core soundcore ipv6 arc4 ecb cryptomgr aead pcompress crypto_blkcipher crypto_hash crypto_algapi b43 ftdi_sio mac80211 cfg80211 usbserial
Process init (pid: 1, threadinfo=81c0c000, task=81c08480, tls=00000000)
Stack : ffffffff 800736a0 80002000 80000600 80350fd0 80099498 00002000 81023340
81e24f9c 2abe7000 00002000 81e24fa0 2abe8000 80088a30 81e0da9c 81e1e000
8037f840 81e1e034 2abe8fff 8033d9c0 81e1e000 81e1f2a8 81e1f2a8 2abe9000
00000000 00000001 81e0da9c 81e1e000 8037f840 81e1e034 81c08480 00000000
00000001 00000000 00000001 8008db1c 81c0dbf0 81e26000 00000000 ffffffff
...
Call Trace:
[<80096fa0>] swap_info_get+0x74/0xfc
[<80099498>] free_swap_and_cache+0x1c/0x218
[<80088a30>] unmap_vmas+0x418/0x63c
[<8008db1c>] exit_mmap+0xb8/0x148
[<8002e3c4>] mmput+0xc0/0x1d8
[<800333e8>] exit_mm+0x260/0x298
[<800357cc>] do_exit+0x1cc/0x688
[<80014658>] nmi_exception_handler+0x0/0x34 Code: 00041840 8ca20020 00431021 <94440000> 1480001d 8fbf0014 3c048030 3c05802c 24a5f280
Fixing recursive fault but reboot is needed! Instruction bus error, epc == 80004dd8, ra == 80000018 Oops[#5]:
Cpu 0
$ 0 : 00000000 1000d000 00000000 00000004
$ 4 : 004c2a30 81e3ddd0 00000000 1000d001
$ 8 : 00000080 00000000 00000000 81e2a000
$12 : 81d66868 00000000 81d66868 00000000
$16 : 00000004 00000001 81e3ddc0 81e3ddc0
$20 : 004c2a30 004c7c98 81e3ddcc 00000000
$24 : 00000000 80181208
$28 : 81e3c000 81e3dd98 004b0000 80000018
Hi : 00000000
Lo : 00000000
epc : 80004dd8 __copy_user+0xd4/0x2bc
Tainted: G D
ra : 80000018 0x80000018
Status: 1000d003 KERNEL EXL IE
Cause : 00800018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: snd_usb_audio snd_pcm_oss snd_mixer_oss snd_pcm snd_timer evdev snd_page_alloc snd_usb_lib snd_rawmidi snd_seq_device snd_hwdep usbhid hid snd input_core soundcore ipv6 arc4 ecb cryptomgr aead pcompress crypto_blkcipher crypto_hash crypto_algapi b43 ftdi_sio mac80211 cfg80211 usbserial
Process sshd (pid: 1173, threadinfo=81e3c000, task=81d66838, tls=00000000)
Stack : 0041663c 81e3dda8 00000000 80200478 81e3ddc0 81e3ddc4 81e3ddc8 81e3ddcc
81e3ddd0 81e3ddd4 00000098 00000000 00000000 00000080 00000000 00000000
00000000 00000000 81e3de20 00000001 00000000 00000000 00000040 81e3de28
81e3de28 fffffdee 81e3de20 8009e530 00000000 814a5a20 81f5d8ec 81ed3900
00000000 00000000 004bd538 00000038 81d41900 8017a668 00000000 00000001
...
Call Trace:
[<80004dd8>] __copy_user+0xd4/0x2bcCode: 8ca80000 24a50004 24c6fffc <ac880000> 1706fffb 24840004 10c00040 00864821 240a0020
Instruction bus error, epc == 80011530, ra == 80000018
Oops[#6]:
Cpu 0
$ 0 : 00000000 1000d001 24020000 80000000
$ 4 : 7fb160e0 24021017 00000278 81c6ec2c
$ 8 : 800125cc 8155fe80 ffffffff ffffffff
$12 : 00000000 80340000 81c6e8b0 0000000b
$16 : 00000000 00000000 7fb160d0 8155ff30
$20 : 7fb160e8 7fb160e0 81c6ec2c 00000012
$24 : 00000000 8025e170
$28 : 8155e000 8155fe10 8155fe80 80000018
Hi : 00000000
Lo : 00000000
epc : 80011530 install_sigtramp+0x20/0x54
Tainted: G D
ra : 80000018 0x80000018
Status: 1000d003 KERNEL EXL IE
Cause : 00800018
PrId : 00029029 (Broadcom BCM3302)
Modules linked in: snd_usb_audio snd_pcm_oss snd_mixer_oss snd_pcm snd_timer evdev snd_page_alloc snd_usb_lib snd_rawmidi snd_seq_device snd_hwdep usbhid hid snd input_core soundcore ipv6 arc4 ecb cryptomgr aead pcompress crypto_blkcipher crypto_hash crypto_algapi b43 ftdi_sio mac80211 cfg80211 usbserial
Process sshd (pid: 1100, threadinfo=8155e000, task=81c6e880, tls=00000000)
Stack : 8155ff30 8155fe98 8167f000 8169f004 00000009 8155ff30 00000012 8001263c
81d58b18 81d58b18 81c59808 800b212c 8155ff30 00000012 8155fe80 81c6ec2c
8155fe98 ffffffff 004b352c 00000000 00000004 800116bc 8167f1e0 8155fe80
8155ff30 8155fea8 00000010 81d58b18 00000000 0040ac18 00000000 00000000
00000000 00000000 00000012 00040002 00000000 00000495 00000000 0000000b
...
Call Trace:
[<80011530>] install_sigtramp+0x20/0x54
[<8001263c>] setup_frame+0x70/0x110
[<800116bc>] do_notify_resume+0x158/0x428
[<800015f0>] work_notifysig+0xc/0x14Code: afbf001c 00a22821 02008821 <ac850000> 2402000c ac820004 3c038038 8c620038 0040f809
Instruction bus error, epc == 2ac458ec, ra == 80000018
At Thu, 14 Jan 2010 08:46:38 +0100,
Quoted 8 lines · Andreas Mohr
Quoted 6 lines · Takashi Iwai
Quoted 5 lines
As I mentioned in the previous followup, if your device is a USB-audio, the patch doesn't help because it's for devices with buffers using
dma_alloc_coherent(). For USB-audio, it uses vmalloc for an intermediate buffer. Maybe this should be changed to dma_*() stuff for such architectures.
Quoted 6 lines
Quoted 3 lines
A quick patch below (totally untested!) might do that.
It's passing the device struct blindly, so not sure whether this would actually work for alldma_alloc_coherent().Thanks a lot, tested, but AFAICS there isn't much of a change unfortunately (log below).
Of course, not for the crash. The patch was for improving the sound quality (if any).
Takashi
Quoted 4 lines
A quick patch below (totally untested!) might do that.
It's passing the device struct blindly, so not sure whether this would actually work for alldma_alloc_coherent().
On archs that have dma_ops such as powerpc (but I think x86 too nowadays) you cannot use the USB device for dma_* operations. You need to get up to the host controller device...
It -might- be worth looking at adding code to the USB stack to propagate the parent device dma_ops down to USB devices... hard to tell.
Cheers,
Ben.
Quoted 58 lines
Takashi
---
sound/usb/usbaudio.c +21
-1@@ -734,7 +734,7 @@ static void snd_complete_sync_urb(struct urb *urb) } } - +#ifdef USBAUDIO_VMALLOC_BUFFER /* get the physical page pointer at the given offset */ static struct page *snd_pcm_get_vmalloc_page (struct snd_pcm_substream *subs,unsigned long offset)@@ -769,6 +769,24 @@ static int snd_pcm_free_vmalloc_buffer(struct snd_pcm_substream *subs) return 0; } +#define preallocate_buffer (chip, pcm, stream)/* NOP */ + +#else +#define snd_pcm_get_vmalloc_page NULL +#define snd_pcm_alloc_vmalloc_buffer snd_pcm_lib_malloc_pages +#define snd_pcm_free_vmalloc_buffer snd_pcm_lib_free_pages + +static int preallocate_buffer (struct snd_usb_audio *chip,struct snd_pcm *pcm, +int stream) +{ +struct snd_pcm_substream *subs = pcm->streams[stream].substream; +if (!subs) +return 0 ; +return snd_pcm_lib_preallocate_pages (subs,SNDRV_DMA_TYPE_DEV , + chip->card->dev, +1024 *64 ,1024 *1024 ); +} +#endif /* * unlink active urbs. @@ -2328,6 +2346,7 @@ static int add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct aud err =snd_pcm_new_stream (as->pcm, stream,1 );if (err <0 )return err; +preallocate_buffer (chip, as->pcm, stream);init_substream (as, stream, fp);return 0 ; }@@ -2356,6 +2375,7 @@ static int add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct audelse strcpy (pcm->name,"USB Audio" ); +preallocate_buffer (chip, pcm, stream);init_substream (as, stream, fp);list_add (&as->list, &chip->pcm_list);
At Fri, 15 Jan 2010 14:28:02 +1100,
Quoted 9 lines · Benjamin Herrenschmidt
Quoted 5 lines
A quick patch below (totally untested!) might do that.
It's passing the device struct blindly, so not sure whether this would actually work for alldma_alloc_coherent().On archs that have
dma_opssuch as powerpc (but I think x86 too nowadays) you cannot use the USB device for dma_* operations. You need to get up to the host controller device...
Yep, I don't think this being a proper fix, too.
Quoted 2 lines
It -might- be worth looking at adding code to the USB stack to propagate the parent device
dma_opsdown to USB devices... hard to tell.
Or we may simply need to drop the mmap support on such architectures...
thanks,
Takashi
Quoted 64 lines
Cheers,
Ben.Quoted 58 lines
Takashi
---
sound/usb/usbaudio.c +21
-1@@ -734,7 +734,7 @@ static void snd_complete_sync_urb(struct urb *urb) } } - +#ifdef USBAUDIO_VMALLOC_BUFFER /* get the physical page pointer at the given offset */ static struct page *snd_pcm_get_vmalloc_page (struct snd_pcm_substream *subs,unsigned long offset)@@ -769,6 +769,24 @@ static int snd_pcm_free_vmalloc_buffer(struct snd_pcm_substream *subs) return 0; } +#define preallocate_buffer (chip, pcm, stream)/* NOP */ + +#else +#define snd_pcm_get_vmalloc_page NULL +#define snd_pcm_alloc_vmalloc_buffer snd_pcm_lib_malloc_pages +#define snd_pcm_free_vmalloc_buffer snd_pcm_lib_free_pages + +static int preallocate_buffer (struct snd_usb_audio *chip,struct snd_pcm *pcm, +int stream) +{ +struct snd_pcm_substream *subs = pcm->streams[stream].substream; +if (!subs) +return 0 ; +return snd_pcm_lib_preallocate_pages (subs,SNDRV_DMA_TYPE_DEV , + chip->card->dev, +1024 *64 ,1024 *1024 ); +} +#endif /* * unlink active urbs. @@ -2328,6 +2346,7 @@ static int add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct aud err =snd_pcm_new_stream (as->pcm, stream,1 );if (err <0 )return err; +preallocate_buffer (chip, as->pcm, stream);init_substream (as, stream, fp);return 0 ; }@@ -2356,6 +2375,7 @@ static int add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct audelse strcpy (pcm->name,"USB Audio" ); +preallocate_buffer (chip, pcm, stream);init_substream (as, stream, fp);list_add (&as->list, &chip->pcm_list);
Quoted 7 lines · Takashi Iwai
Quoted 2 lines
It -might- be worth looking at adding code to the USB stack to
propagate
Quoted 1 line
the parent device
dma_opsdown to USB devices... hard to tell.Or we may simply need to drop the mmap support on such architectures...
Nah, that would suck since that includes x86 nowadays :-)
I think you probably need to separate the struct device * used for DMA (it could be default be the same as the "main" struct device tho or it could default to NULL which means no mmap support).
USB could (if not already) provide an accessor to obtain the HC's struct device for such mappings. We'll have to discuss that with Alan Stern I suppose.
The USB Audio or similar drivers could then use that accessors to fill up Alsa's dma_device field to replace the "default".
Cheers,
Ben.
At Fri, 15 Jan 2010 17:50:49 +1100,
Quoted 11 lines · Benjamin Herrenschmidt
Quoted 7 lines · Takashi Iwai
Quoted 2 lines
It -might- be worth looking at adding code to the USB stack to
propagate
Quoted 1 line
the parent device
dma_opsdown to USB devices... hard to tell.Or we may simply need to drop the mmap support on such architectures...
Nah, that would suck since that includes x86 nowadays :-)
Ah, no, I meant about non-coherent architectures that can't use vmalloc pages as the intermediate buffer. Dropping mmap for x86 would be a big regression ;)
Quoted 10 lines
I think you probably need to separate the struct device * used for DMA (it could be default be the same as the "main" struct device tho or it could default to NULL which means no mmap support).
USB could (if not already) provide an accessor to obtain the HC's struct device for such mappings. We'll have to discuss that with Alan Stern I suppose.
The USB Audio or similar drivers could then use that accessors to fill up Alsa's
dma_devicefield to replace the "default".
The situation of usb-audio is, unfortunately, a bit more complex because the driver needs a continuous ring-buffer. The packet data are copied from that intermediate buffer on demand.
This isn't efficient, but the continuous ring-buffer is demanded by the current API design exported as mmap.
thanks,
Takashi