diff options
Diffstat (limited to 'kernel/exit.c')
-rw-r--r-- | kernel/exit.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/kernel/exit.c b/kernel/exit.c index 40036ac04271..059b38cae384 100644 --- a/kernel/exit.c +++ b/kernel/exit.c | |||
@@ -580,8 +580,6 @@ mm_need_new_owner(struct mm_struct *mm, struct task_struct *p) | |||
580 | * If there are other users of the mm and the owner (us) is exiting | 580 | * If there are other users of the mm and the owner (us) is exiting |
581 | * we need to find a new owner to take on the responsibility. | 581 | * we need to find a new owner to take on the responsibility. |
582 | */ | 582 | */ |
583 | if (!mm) | ||
584 | return 0; | ||
585 | if (atomic_read(&mm->mm_users) <= 1) | 583 | if (atomic_read(&mm->mm_users) <= 1) |
586 | return 0; | 584 | return 0; |
587 | if (mm->owner != p) | 585 | if (mm->owner != p) |
@@ -624,29 +622,38 @@ retry: | |||
624 | } while_each_thread(g, c); | 622 | } while_each_thread(g, c); |
625 | 623 | ||
626 | read_unlock(&tasklist_lock); | 624 | read_unlock(&tasklist_lock); |
625 | /* | ||
626 | * We found no owner yet mm_users > 1: this implies that we are | ||
627 | * most likely racing with swapoff (try_to_unuse()) or /proc or | ||
628 | * ptrace or page migration (get_task_mm()). Mark owner as NULL, | ||
629 | * so that subsystems can understand the callback and take action. | ||
630 | */ | ||
631 | down_write(&mm->mmap_sem); | ||
632 | cgroup_mm_owner_callbacks(mm->owner, NULL); | ||
633 | mm->owner = NULL; | ||
634 | up_write(&mm->mmap_sem); | ||
627 | return; | 635 | return; |
628 | 636 | ||
629 | assign_new_owner: | 637 | assign_new_owner: |
630 | BUG_ON(c == p); | 638 | BUG_ON(c == p); |
631 | get_task_struct(c); | 639 | get_task_struct(c); |
640 | read_unlock(&tasklist_lock); | ||
641 | down_write(&mm->mmap_sem); | ||
632 | /* | 642 | /* |
633 | * The task_lock protects c->mm from changing. | 643 | * The task_lock protects c->mm from changing. |
634 | * We always want mm->owner->mm == mm | 644 | * We always want mm->owner->mm == mm |
635 | */ | 645 | */ |
636 | task_lock(c); | 646 | task_lock(c); |
637 | /* | ||
638 | * Delay read_unlock() till we have the task_lock() | ||
639 | * to ensure that c does not slip away underneath us | ||
640 | */ | ||
641 | read_unlock(&tasklist_lock); | ||
642 | if (c->mm != mm) { | 647 | if (c->mm != mm) { |
643 | task_unlock(c); | 648 | task_unlock(c); |
649 | up_write(&mm->mmap_sem); | ||
644 | put_task_struct(c); | 650 | put_task_struct(c); |
645 | goto retry; | 651 | goto retry; |
646 | } | 652 | } |
647 | cgroup_mm_owner_callbacks(mm->owner, c); | 653 | cgroup_mm_owner_callbacks(mm->owner, c); |
648 | mm->owner = c; | 654 | mm->owner = c; |
649 | task_unlock(c); | 655 | task_unlock(c); |
656 | up_write(&mm->mmap_sem); | ||
650 | put_task_struct(c); | 657 | put_task_struct(c); |
651 | } | 658 | } |
652 | #endif /* CONFIG_MM_OWNER */ | 659 | #endif /* CONFIG_MM_OWNER */ |