diff options
author | Andi Kleen <ak@suse.de> | 2005-12-13 01:17:09 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2005-12-13 01:31:16 -0500 |
commit | bf5421c309bb89e5106452bc840983b1b4754d61 (patch) | |
tree | dd1b97332a053197175b13a3fe7d62e568c6f3f1 /arch/i386/mm/ioremap.c | |
parent | 5e9ef02ec00c70840661d174dc2f4862db471bb6 (diff) |
[PATCH] i386/x86-64: Don't call change_page_attr with a spinlock held
It's illegal because it can sleep.
Use a two step lookup scheme instead. First look up the vm_struct, then
change the direct mapping, then finally unmap it. That's ok because nobody
can change the particular virtual address range as long as the vm_struct is
still in the global list.
Also added some LinuxDoc documentation to iounmap.
Signed-off-by: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'arch/i386/mm/ioremap.c')
-rw-r--r-- | arch/i386/mm/ioremap.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/arch/i386/mm/ioremap.c b/arch/i386/mm/ioremap.c index 5d09de8d1c6b..8498b5ac3955 100644 --- a/arch/i386/mm/ioremap.c +++ b/arch/i386/mm/ioremap.c | |||
@@ -223,9 +223,15 @@ void __iomem *ioremap_nocache (unsigned long phys_addr, unsigned long size) | |||
223 | } | 223 | } |
224 | EXPORT_SYMBOL(ioremap_nocache); | 224 | EXPORT_SYMBOL(ioremap_nocache); |
225 | 225 | ||
226 | /** | ||
227 | * iounmap - Free a IO remapping | ||
228 | * @addr: virtual address from ioremap_* | ||
229 | * | ||
230 | * Caller must ensure there is only one unmapping for the same pointer. | ||
231 | */ | ||
226 | void iounmap(volatile void __iomem *addr) | 232 | void iounmap(volatile void __iomem *addr) |
227 | { | 233 | { |
228 | struct vm_struct *p; | 234 | struct vm_struct *p, *o; |
229 | 235 | ||
230 | if ((void __force *)addr <= high_memory) | 236 | if ((void __force *)addr <= high_memory) |
231 | return; | 237 | return; |
@@ -239,22 +245,37 @@ void iounmap(volatile void __iomem *addr) | |||
239 | addr < phys_to_virt(ISA_END_ADDRESS)) | 245 | addr < phys_to_virt(ISA_END_ADDRESS)) |
240 | return; | 246 | return; |
241 | 247 | ||
242 | write_lock(&vmlist_lock); | 248 | addr = (volatile void *)(PAGE_MASK & (unsigned long __force)addr); |
243 | p = __remove_vm_area((void *)(PAGE_MASK & (unsigned long __force)addr)); | 249 | |
244 | if (!p) { | 250 | /* Use the vm area unlocked, assuming the caller |
245 | printk(KERN_WARNING "iounmap: bad address %p\n", addr); | 251 | ensures there isn't another iounmap for the same address |
252 | in parallel. Reuse of the virtual address is prevented by | ||
253 | leaving it in the global lists until we're done with it. | ||
254 | cpa takes care of the direct mappings. */ | ||
255 | read_lock(&vmlist_lock); | ||
256 | for (p = vmlist; p; p = p->next) { | ||
257 | if (p->addr == addr) | ||
258 | break; | ||
259 | } | ||
260 | read_unlock(&vmlist_lock); | ||
261 | |||
262 | if (!p) { | ||
263 | printk("iounmap: bad address %p\n", addr); | ||
246 | dump_stack(); | 264 | dump_stack(); |
247 | goto out_unlock; | 265 | return; |
248 | } | 266 | } |
249 | 267 | ||
268 | /* Reset the direct mapping. Can block */ | ||
250 | if ((p->flags >> 20) && p->phys_addr < virt_to_phys(high_memory) - 1) { | 269 | if ((p->flags >> 20) && p->phys_addr < virt_to_phys(high_memory) - 1) { |
251 | change_page_attr(virt_to_page(__va(p->phys_addr)), | 270 | change_page_attr(virt_to_page(__va(p->phys_addr)), |
252 | p->size >> PAGE_SHIFT, | 271 | p->size >> PAGE_SHIFT, |
253 | PAGE_KERNEL); | 272 | PAGE_KERNEL); |
254 | global_flush_tlb(); | 273 | global_flush_tlb(); |
255 | } | 274 | } |
256 | out_unlock: | 275 | |
257 | write_unlock(&vmlist_lock); | 276 | /* Finally remove it */ |
277 | o = remove_vm_area((void *)addr); | ||
278 | BUG_ON(p != o || o == NULL); | ||
258 | kfree(p); | 279 | kfree(p); |
259 | } | 280 | } |
260 | EXPORT_SYMBOL(iounmap); | 281 | EXPORT_SYMBOL(iounmap); |