History

mm/vmalloc: Fix unlock order in s_stop()

When multiple locks are acquired, they should be released in reverse order. For s_start() and s_stop() in mm/vmalloc.c, that is not the case. s_start: mutex_lock(&vmap_purge_lock); spin_lock(&vmap_area_lock); s_stop : mutex_unlock(&vmap_purge_lock); spin_unlock(&vmap_area_lock); This unlock sequence, though allowed, is not optimal. If a waiter is present, mutex_unlock() will need to go through the slowpath of waking up the waiter with preemption disabled. Fix that by releasing the spinlock first before the mutex.

Waiman Long committed 5 years ago

Commit 0a7dd4e1 parent e924d461 file · +2 −2Browse files

Unified · Split

mm/vmalloc.c+2−2
@@ -3465,11 +3465,11 @@ static void *s_next(struct seq_file *m, void *p, loff_t *pos) · 3464 unmodified lines
34653465 }
34663466
34673467 static void s_stop(struct seq_file *m, void *p)
3468− __releases(&vmap_purge_lock)
34693468 __releases(&vmap_area_lock)
3469+ __releases(&vmap_purge_lock)
34703470 {
3471− mutex_unlock(&vmap_purge_lock);
34723471 spin_unlock(&vmap_area_lock);
3472+ mutex_unlock(&vmap_purge_lock);
34733473 }
34743474
34753475 static void show_numa_info(struct seq_file *m, struct vm_struct *v)