aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/ctxfi
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2009-06-02 02:40:51 -0400
committerTakashi Iwai <tiwai@suse.de>2009-06-02 02:40:51 -0400
commit8a4259bf89d23bfd58d87e275ef6da29cea6b3c5 (patch)
treeee96ea01ae32a828f1446f52bd2534783e0c8dfd /sound/pci/ctxfi
parentaae80dc24aeddec4e2b6e182a43491942f8667d3 (diff)
ALSA: ctxfi - Fix Oops at mmapping
Replace a spinlock with a mutex protecting the vm block list at mmap / munmap calls, which caused Oops like below: BUG: sleeping function called from invalid context at mm/slub.c:1599 in_atomic(): 0, irqs_disabled(): 1, pid: 32065, name: xine Pid: 32065, comm: xine Tainted: P 2.6.29.4-75.fc10.x86_64 #1 Call Trace: [<ffffffff81040685>] __might_sleep+0x105/0x10a [<ffffffff810c9fae>] kmem_cache_alloc+0x32/0xe2 [<ffffffffa08e3110>] ct_vm_map+0xfa/0x19e [snd_ctxfi] [<ffffffffa08e1a07>] ct_map_audio_buffer+0x4c/0x76 [snd_ctxfi] [<ffffffffa08e2aa5>] atc_pcm_playback_prepare+0x1d7/0x2a8 [snd_ctxfi] [<ffffffff8105ef3f>] ? up_read+0x9/0xb [<ffffffff81186b61>] ? __up_read+0x7c/0x87 [<ffffffffa08e36a6>] ct_pcm_playback_prepare+0x39/0x60 [snd_ctxfi] [<ffffffffa0886bcb>] snd_pcm_do_prepare+0x16/0x28 [snd_pcm] [<ffffffffa08867c7>] snd_pcm_action_single+0x2d/0x5b [snd_pcm] [<ffffffffa08881f3>] snd_pcm_action_nonatomic+0x52/0x6a [snd_pcm] [<ffffffffa088a723>] snd_pcm_common_ioctl1+0x404/0xc79 [snd_pcm] [<ffffffff810c52c8>] ? alloc_pages_current+0xb9/0xc2 [<ffffffff810c9402>] ? new_slab+0x1a5/0x1cb [<ffffffff810ab9ea>] ? vma_prio_tree_insert+0x23/0xc1 [<ffffffffa088b411>] snd_pcm_playback_ioctl1+0x213/0x230 [snd_pcm] [<ffffffff810b6c20>] ? mmap_region+0x397/0x4c9 [<ffffffffa088bd9b>] snd_pcm_playback_ioctl+0x2e/0x36 [snd_pcm] [<ffffffff810ddc64>] vfs_ioctl+0x2a/0x78 [<ffffffff810de130>] do_vfs_ioctl+0x462/0x4a2 [<ffffffff81029cef>] ? default_spin_lock_flags+0x9/0xe [<ffffffff81374647>] ? trace_hardirqs_off_thunk+0x3a/0x6c [<ffffffff810de1c5>] sys_ioctl+0x55/0x77 [<ffffffff8101133a>] system_call_fastpath+0x16/0x1b Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/ctxfi')
-rw-r--r--sound/pci/ctxfi/ctatc.c11
-rw-r--r--sound/pci/ctxfi/ctatc.h1
-rw-r--r--sound/pci/ctxfi/ctvmem.c14
-rw-r--r--sound/pci/ctxfi/ctvmem.h3
4 files changed, 13 insertions, 16 deletions
diff --git a/sound/pci/ctxfi/ctatc.c b/sound/pci/ctxfi/ctatc.c
index ead104ea1e35..1a4bb357eaef 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, struct ct_atc_pcm *apcm);
119 119
120static int ct_map_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm) 120static int ct_map_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm)
121{ 121{
122 unsigned long flags;
123 struct snd_pcm_runtime *runtime; 122 struct snd_pcm_runtime *runtime;
124 struct ct_vm *vm; 123 struct ct_vm *vm;
125 124
@@ -129,9 +128,7 @@ static int ct_map_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm)
129 runtime = apcm->substream->runtime; 128 runtime = apcm->substream->runtime;
130 vm = atc->vm; 129 vm = atc->vm;
131 130
132 spin_lock_irqsave(&atc->vm_lock, flags);
133 apcm->vm_block = vm->map(vm, runtime->dma_area, runtime->dma_bytes); 131 apcm->vm_block = vm->map(vm, runtime->dma_area, runtime->dma_bytes);
134 spin_unlock_irqrestore(&atc->vm_lock, flags);
135 132
136 if (NULL == apcm->vm_block) 133 if (NULL == apcm->vm_block)
137 return -ENOENT; 134 return -ENOENT;
@@ -141,7 +138,6 @@ static int ct_map_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm)
141 138
142static void ct_unmap_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm) 139static void ct_unmap_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm)
143{ 140{
144 unsigned long flags;
145 struct ct_vm *vm; 141 struct ct_vm *vm;
146 142
147 if (NULL == apcm->vm_block) 143 if (NULL == apcm->vm_block)
@@ -149,9 +145,7 @@ static void ct_unmap_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm)
149 145
150 vm = atc->vm; 146 vm = atc->vm;
151 147
152 spin_lock_irqsave(&atc->vm_lock, flags);
153 vm->unmap(vm, apcm->vm_block); 148 vm->unmap(vm, apcm->vm_block);
154 spin_unlock_irqrestore(&atc->vm_lock, flags);
155 149
156 apcm->vm_block = NULL; 150 apcm->vm_block = NULL;
157} 151}
@@ -161,9 +155,7 @@ static unsigned long atc_get_ptp_phys(struct ct_atc *atc, int index)
161 struct ct_vm *vm; 155 struct ct_vm *vm;
162 void *kvirt_addr; 156 void *kvirt_addr;
163 unsigned long phys_addr; 157 unsigned long phys_addr;
164 unsigned long flags;
165 158
166 spin_lock_irqsave(&atc->vm_lock, flags);
167 vm = atc->vm; 159 vm = atc->vm;
168 kvirt_addr = vm->get_ptp_virt(vm, index); 160 kvirt_addr = vm->get_ptp_virt(vm, index);
169 if (kvirt_addr == NULL) 161 if (kvirt_addr == NULL)
@@ -171,8 +163,6 @@ static unsigned long atc_get_ptp_phys(struct ct_atc *atc, int index)
171 else 163 else
172 phys_addr = virt_to_phys(kvirt_addr); 164 phys_addr = virt_to_phys(kvirt_addr);
173 165
174 spin_unlock_irqrestore(&atc->vm_lock, flags);
175
176 return phys_addr; 166 return phys_addr;
177} 167}
178 168
@@ -1562,7 +1552,6 @@ int ct_atc_create(struct snd_card *card, struct pci_dev *pci,
1562 atc_set_ops(atc); 1552 atc_set_ops(atc);
1563 1553
1564 spin_lock_init(&atc->atc_lock); 1554 spin_lock_init(&atc->atc_lock);
1565 spin_lock_init(&atc->vm_lock);
1566 1555
1567 /* Find card model */ 1556 /* Find card model */
1568 err = atc_identify_card(atc); 1557 err = atc_identify_card(atc);
diff --git a/sound/pci/ctxfi/ctatc.h b/sound/pci/ctxfi/ctatc.h
index 286c993d461a..a7b0ec24cd75 100644
--- a/sound/pci/ctxfi/ctatc.h
+++ b/sound/pci/ctxfi/ctatc.h
@@ -101,7 +101,6 @@ struct ct_atc {
101 unsigned long (*get_ptp_phys)(struct ct_atc *atc, int index); 101 unsigned long (*get_ptp_phys)(struct ct_atc *atc, int index);
102 102
103 spinlock_t atc_lock; 103 spinlock_t atc_lock;
104 spinlock_t vm_lock;
105 104
106 int (*pcm_playback_prepare)(struct ct_atc *atc, 105 int (*pcm_playback_prepare)(struct ct_atc *atc,
107 struct ct_atc_pcm *apcm); 106 struct ct_atc_pcm *apcm);
diff --git a/sound/pci/ctxfi/ctvmem.c b/sound/pci/ctxfi/ctvmem.c
index cecf77e3ee86..363b67e3a9e7 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)
35 struct ct_vm_block *block = NULL, *entry = NULL; 35 struct ct_vm_block *block = NULL, *entry = NULL;
36 struct list_head *pos = NULL; 36 struct list_head *pos = NULL;
37 37
38 mutex_lock(&vm->lock);
38 list_for_each(pos, &vm->unused) { 39 list_for_each(pos, &vm->unused) {
39 entry = list_entry(pos, struct ct_vm_block, list); 40 entry = list_entry(pos, struct ct_vm_block, list);
40 if (entry->size >= size) 41 if (entry->size >= size)
41 break; /* found a block that is big enough */ 42 break; /* found a block that is big enough */
42 } 43 }
43 if (pos == &vm->unused) 44 if (pos == &vm->unused)
44 return NULL; 45 goto out;
45 46
46 if (entry->size == size) { 47 if (entry->size == size) {
47 /* Move the vm node from unused list to used list directly */ 48 /* Move the vm node from unused list to used list directly */
48 list_del(&entry->list); 49 list_del(&entry->list);
49 list_add(&entry->list, &vm->used); 50 list_add(&entry->list, &vm->used);
50 vm->size -= size; 51 vm->size -= size;
51 return entry; 52 block = entry;
53 goto out;
52 } 54 }
53 55
54 block = kzalloc(sizeof(*block), GFP_KERNEL); 56 block = kzalloc(sizeof(*block), GFP_KERNEL);
55 if (NULL == block) 57 if (NULL == block)
56 return NULL; 58 goto out;
57 59
58 block->addr = entry->addr; 60 block->addr = entry->addr;
59 block->size = size; 61 block->size = size;
@@ -62,6 +64,8 @@ get_vm_block(struct ct_vm *vm, unsigned int size)
62 entry->size -= size; 64 entry->size -= size;
63 vm->size -= size; 65 vm->size -= size;
64 66
67 out:
68 mutex_unlock(&vm->lock);
65 return block; 69 return block;
66} 70}
67 71
@@ -70,6 +74,7 @@ static void put_vm_block(struct ct_vm *vm, struct ct_vm_block *block)
70 struct ct_vm_block *entry = NULL, *pre_ent = NULL; 74 struct ct_vm_block *entry = NULL, *pre_ent = NULL;
71 struct list_head *pos = NULL, *pre = NULL; 75 struct list_head *pos = NULL, *pre = NULL;
72 76
77 mutex_lock(&vm->lock);
73 list_del(&block->list); 78 list_del(&block->list);
74 vm->size += block->size; 79 vm->size += block->size;
75 80
@@ -106,6 +111,7 @@ static void put_vm_block(struct ct_vm *vm, struct ct_vm_block *block)
106 pos = pre; 111 pos = pre;
107 pre = pos->prev; 112 pre = pos->prev;
108 } 113 }
114 mutex_unlock(&vm->lock);
109} 115}
110 116
111/* Map host addr (kmalloced/vmalloced) to device logical addr. */ 117/* Map host addr (kmalloced/vmalloced) to device logical addr. */
@@ -191,6 +197,8 @@ int ct_vm_create(struct ct_vm **rvm)
191 if (NULL == vm) 197 if (NULL == vm)
192 return -ENOMEM; 198 return -ENOMEM;
193 199
200 mutex_init(&vm->lock);
201
194 /* Allocate page table pages */ 202 /* Allocate page table pages */
195 for (i = 0; i < CT_PTP_NUM; i++) { 203 for (i = 0; i < CT_PTP_NUM; i++) {
196 vm->ptp[i] = kmalloc(PAGE_SIZE, GFP_KERNEL); 204 vm->ptp[i] = kmalloc(PAGE_SIZE, GFP_KERNEL);
diff --git a/sound/pci/ctxfi/ctvmem.h b/sound/pci/ctxfi/ctvmem.h
index 4eb5bdd5cad4..618952efa5b3 100644
--- a/sound/pci/ctxfi/ctvmem.h
+++ b/sound/pci/ctxfi/ctvmem.h
@@ -20,7 +20,7 @@
20 20
21#define CT_PTP_NUM 1 /* num of device page table pages */ 21#define CT_PTP_NUM 1 /* num of device page table pages */
22 22
23#include <linux/spinlock.h> 23#include <linux/mutex.h>
24#include <linux/list.h> 24#include <linux/list.h>
25 25
26struct ct_vm_block { 26struct ct_vm_block {
@@ -35,6 +35,7 @@ struct ct_vm {
35 unsigned int size; /* Available addr space in bytes */ 35 unsigned int size; /* Available addr space in bytes */
36 struct list_head unused; /* List of unused blocks */ 36 struct list_head unused; /* List of unused blocks */
37 struct list_head used; /* List of used blocks */ 37 struct list_head used; /* List of used blocks */
38 struct mutex lock;
38 39
39 /* Map host addr (kmalloced/vmalloced) to device logical addr. */ 40 /* Map host addr (kmalloced/vmalloced) to device logical addr. */
40 struct ct_vm_block *(*map)(struct ct_vm *, void *host_addr, int size); 41 struct ct_vm_block *(*map)(struct ct_vm *, void *host_addr, int size);