From: Takashi Iwai Subject: Re: snd-ctxfi Date: Thu, 04 Jun 2009 07:29:44 +0200 Message-ID: References: <4A20A683.9010102@gmail.com> <4A215D56.7080601@gmail.com> <75b66ecd0906011847i7d74d878n8e734fe9e6031e4d@mail.gmail.com> <6d00fe310906032048m35a62a30ua6c23bcf656ea014@mail.gmail.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Return-path: Received: from mx1.suse.de (cantor.suse.de [195.135.220.2]) by alsa0.perex.cz (Postfix) with ESMTP id 910701037F5 for ; Thu, 4 Jun 2009 07:29:45 +0200 (CEST) In-Reply-To: <6d00fe310906032048m35a62a30ua6c23bcf656ea014@mail.gmail.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org To: The Source Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org At Thu, 4 Jun 2009 07:48:47 +0400, The Source wrote: > = > 2009/6/2 Takashi Iwai > = > At Mon, 1 Jun 2009 21:47:02 -0400, > Lee Revell wrote: > > > > On Mon, Jun 1, 2009 at 5:10 AM, Takashi Iwai wrote: > > > Thanks. =A0So, something wrong in the mmap handling. > > > I'll take a look later in this week. > > > > Looks like ct_map_audio_buffer calls ct_vm_map under spinlock; > > ct_vm_map calls get_vm_block which calls kzalloc with GFP_KERNEL. > = > Indeed. =A0Does the patch below fix the problem? > = > thanks, > = > Takashi > = > --- > diff --git a/sound/pci/ctxfi/ctatc.c b/sound/pci/ctxfi/ctatc.c > index ead104e..1a4bb35 100644 > --- a/sound/pci/ctxfi/ctatc.c > +++ b/sound/pci/ctxfi/ctatc.c > @@ -119,7 +119,6 @@ atc_pcm_release_resources(struct ct_atc *atc, str= uct > ct_atc_pcm *apcm); > = > =A0static int ct_map_audio_buffer(struct ct_atc *atc, struct ct_atc_p= cm > *apcm) > =A0{ > - =A0 =A0 =A0 unsigned long flags; > =A0 =A0 =A0 =A0struct snd_pcm_runtime *runtime; > =A0 =A0 =A0 =A0struct ct_vm *vm; > = > @@ -129,9 +128,7 @@ static int ct_map_audio_buffer(struct ct_atc *atc, > struct ct_atc_pcm *apcm) > =A0 =A0 =A0 =A0runtime =3D apcm->substream->runtime; > =A0 =A0 =A0 =A0vm =3D atc->vm; > = > - =A0 =A0 =A0 spin_lock_irqsave(&atc->vm_lock, flags); > =A0 =A0 =A0 =A0apcm->vm_block =3D vm->map(vm, runtime->dma_area, runt= ime-> > dma_bytes); > - =A0 =A0 =A0 spin_unlock_irqrestore(&atc->vm_lock, flags); > = > =A0 =A0 =A0 =A0if (NULL =3D=3D apcm->vm_block) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return -ENOENT; > @@ -141,7 +138,6 @@ static int ct_map_audio_buffer(struct ct_atc *atc, > struct ct_atc_pcm *apcm) > = > =A0static void ct_unmap_audio_buffer(struct ct_atc *atc, struct ct_at= c_pcm > *apcm) > =A0{ > - =A0 =A0 =A0 unsigned long flags; > =A0 =A0 =A0 =A0struct ct_vm *vm; > = > =A0 =A0 =A0 =A0if (NULL =3D=3D apcm->vm_block) > @@ -149,9 +145,7 @@ static void ct_unmap_audio_buffer(struct ct_atc *= atc, > struct ct_atc_pcm *apcm) > = > =A0 =A0 =A0 =A0vm =3D atc->vm; > = > - =A0 =A0 =A0 spin_lock_irqsave(&atc->vm_lock, flags); > =A0 =A0 =A0 =A0vm->unmap(vm, apcm->vm_block); > - =A0 =A0 =A0 spin_unlock_irqrestore(&atc->vm_lock, flags); > = > =A0 =A0 =A0 =A0apcm->vm_block =3D NULL; > =A0} > @@ -161,9 +155,7 @@ static unsigned long atc_get_ptp_phys(struct ct_a= tc > *atc, int index) > =A0 =A0 =A0 =A0struct ct_vm *vm; > =A0 =A0 =A0 =A0void *kvirt_addr; > =A0 =A0 =A0 =A0unsigned long phys_addr; > - =A0 =A0 =A0 unsigned long flags; > = > - =A0 =A0 =A0 spin_lock_irqsave(&atc->vm_lock, flags); > =A0 =A0 =A0 =A0vm =3D atc->vm; > =A0 =A0 =A0 =A0kvirt_addr =3D vm->get_ptp_virt(vm, index); > =A0 =A0 =A0 =A0if (kvirt_addr =3D=3D NULL) > @@ -171,8 +163,6 @@ static unsigned long atc_get_ptp_phys(struct ct_a= tc > *atc, int index) > =A0 =A0 =A0 =A0else > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0phys_addr =3D virt_to_phys(kvirt_addr); > = > - =A0 =A0 =A0 spin_unlock_irqrestore(&atc->vm_lock, flags); > - > =A0 =A0 =A0 =A0return phys_addr; > =A0} > = > @@ -1562,7 +1552,6 @@ int ct_atc_create(struct snd_card *card, struct > pci_dev *pci, > =A0 =A0 =A0 =A0atc_set_ops(atc); > = > =A0 =A0 =A0 =A0spin_lock_init(&atc->atc_lock); > - =A0 =A0 =A0 spin_lock_init(&atc->vm_lock); > = > =A0 =A0 =A0 =A0/* Find card model */ > =A0 =A0 =A0 =A0err =3D atc_identify_card(atc); > diff --git a/sound/pci/ctxfi/ctatc.h b/sound/pci/ctxfi/ctatc.h > index 286c993..a7b0ec2 100644 > --- a/sound/pci/ctxfi/ctatc.h > +++ b/sound/pci/ctxfi/ctatc.h > @@ -101,7 +101,6 @@ struct ct_atc { > =A0 =A0 =A0 =A0unsigned long (*get_ptp_phys)(struct ct_atc *atc, int = index); > = > =A0 =A0 =A0 =A0spinlock_t atc_lock; > - =A0 =A0 =A0 spinlock_t vm_lock; > = > =A0 =A0 =A0 =A0int (*pcm_playback_prepare)(struct ct_atc *atc, > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0struct ct_atc_pcm *apcm); > diff --git a/sound/pci/ctxfi/ctvmem.c b/sound/pci/ctxfi/ctvmem.c > index cecf77e..363b67e 100644 > --- a/sound/pci/ctxfi/ctvmem.c > +++ b/sound/pci/ctxfi/ctvmem.c > @@ -35,25 +35,27 @@ get_vm_block(struct ct_vm *vm, unsigned int size) > =A0 =A0 =A0 =A0struct ct_vm_block *block =3D NULL, *entry =3D NULL; > =A0 =A0 =A0 =A0struct list_head *pos =3D NULL; > = > + =A0 =A0 =A0 mutex_lock(&vm->lock); > =A0 =A0 =A0 =A0list_for_each(pos, &vm->unused) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0entry =3D list_entry(pos, struct ct_vm= _block, list); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0if (entry->size >=3D size) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0break; /* found a bloc= k that is big enough */ > =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0if (pos =3D=3D &vm->unused) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out; > = > =A0 =A0 =A0 =A0if (entry->size =3D=3D size) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0/* Move the vm node from unused list t= o used list directly > */ > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0list_del(&entry->list); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0list_add(&entry->list, &vm->used); > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0vm->size -=3D size; > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 return entry; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 block =3D entry; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out; > =A0 =A0 =A0 =A0} > = > =A0 =A0 =A0 =A0block =3D kzalloc(sizeof(*block), GFP_KERNEL); > =A0 =A0 =A0 =A0if (NULL =3D=3D block) > - =A0 =A0 =A0 =A0 =A0 =A0 =A0 return NULL; > + =A0 =A0 =A0 =A0 =A0 =A0 =A0 goto out; > = > =A0 =A0 =A0 =A0block->addr =3D entry->addr; > =A0 =A0 =A0 =A0block->size =3D size; > @@ -62,6 +64,8 @@ get_vm_block(struct ct_vm *vm, unsigned int size) > =A0 =A0 =A0 =A0entry->size -=3D size; > =A0 =A0 =A0 =A0vm->size -=3D size; > = > + out: > + =A0 =A0 =A0 mutex_unlock(&vm->lock); > =A0 =A0 =A0 =A0return block; > =A0} > = > @@ -70,6 +74,7 @@ static void put_vm_block(struct ct_vm *vm, struct > ct_vm_block *block) > =A0 =A0 =A0 =A0struct ct_vm_block *entry =3D NULL, *pre_ent =3D NULL; > =A0 =A0 =A0 =A0struct list_head *pos =3D NULL, *pre =3D NULL; > = > + =A0 =A0 =A0 mutex_lock(&vm->lock); > =A0 =A0 =A0 =A0list_del(&block->list); > =A0 =A0 =A0 =A0vm->size +=3D block->size; > = > @@ -106,6 +111,7 @@ static void put_vm_block(struct ct_vm *vm, struct > ct_vm_block *block) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pos =3D pre; > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0pre =3D pos->prev; > =A0 =A0 =A0 =A0} > + =A0 =A0 =A0 mutex_unlock(&vm->lock); > =A0} > = > =A0/* Map host addr (kmalloced/vmalloced) to device logical addr. */ > @@ -191,6 +197,8 @@ int ct_vm_create(struct ct_vm **rvm) > =A0 =A0 =A0 =A0if (NULL =3D=3D vm) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return -ENOMEM; > = > + =A0 =A0 =A0 mutex_init(&vm->lock); > + > =A0 =A0 =A0 =A0/* Allocate page table pages */ > =A0 =A0 =A0 =A0for (i =3D 0; i < CT_PTP_NUM; i++) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0vm->ptp[i] =3D kmalloc(PAGE_SIZE, GFP_= KERNEL); > diff --git a/sound/pci/ctxfi/ctvmem.h b/sound/pci/ctxfi/ctvmem.h > index 4eb5bdd..618952e 100644 > --- a/sound/pci/ctxfi/ctvmem.h > +++ b/sound/pci/ctxfi/ctvmem.h > @@ -20,7 +20,7 @@ > = > =A0#define CT_PTP_NUM =A0 =A0 1 =A0 =A0 =A0 /* num of device page tab= le pages */ > = > -#include > +#include > =A0#include > = > =A0struct ct_vm_block { > @@ -35,6 +35,7 @@ struct ct_vm { > =A0 =A0 =A0 =A0unsigned int size; =A0 =A0 =A0 =A0 =A0 =A0 =A0/* Avail= able addr space in bytes */ > =A0 =A0 =A0 =A0struct list_head unused; =A0 =A0 =A0 =A0/* List of unu= sed blocks */ > =A0 =A0 =A0 =A0struct list_head used; =A0 =A0 =A0 =A0 =A0/* List of u= sed blocks */ > + =A0 =A0 =A0 struct mutex lock; > = > =A0 =A0 =A0 =A0/* Map host addr (kmalloced/vmalloced) to device logic= al addr. */ > =A0 =A0 =A0 =A0struct ct_vm_block *(*map)(struct ct_vm *, void *host_= addr, int > size); > = > I tried this patch (actually I downloaded the snapshot yesterday and patch > said it was already applied there), but my system can not boot at all with > this driver. It prints 'starting udev' at that's it. I removed the driver= and > my system is back to normal. Yes, yesterday's version had a severe bug in the core code. It's already fixed, so please use the later one. Note that alsa-driver-snapshot.tar.gz is *always* the latest version, so pick this up instead of the daily snapshots for testing something. thanks, Takashi