diff options
author | Konstantin Khlebnikov <khlebnikov@openvz.org> | 2012-10-08 19:28:54 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-09 03:22:18 -0400 |
commit | e9714acf8c439688884234dcac2bfc38bb607d38 (patch) | |
tree | 2e21c88f855a9f5168a143fa9948141140ff02a2 /kernel | |
parent | 2dd8ad81e31d0d36a5d448329c646ab43eb17788 (diff) |
mm: kill vma flag VM_EXECUTABLE and mm->num_exe_file_vmas
Currently the kernel sets mm->exe_file during sys_execve() and then tracks
number of vmas with VM_EXECUTABLE flag in mm->num_exe_file_vmas, as soon
as this counter drops to zero kernel resets mm->exe_file to NULL. Plus it
resets mm->exe_file at last mmput() when mm->mm_users drops to zero.
VMA with VM_EXECUTABLE flag appears after mapping file with flag
MAP_EXECUTABLE, such vmas can appears only at sys_execve() or after vma
splitting, because sys_mmap ignores this flag. Usually binfmt module sets
mm->exe_file and mmaps executable vmas with this file, they hold
mm->exe_file while task is running.
comment from v2.6.25-6245-g925d1c4 ("procfs task exe symlink"),
where all this stuff was introduced:
> The kernel implements readlink of /proc/pid/exe by getting the file from
> the first executable VMA. Then the path to the file is reconstructed and
> reported as the result.
>
> Because of the VMA walk the code is slightly different on nommu systems.
> This patch avoids separate /proc/pid/exe code on nommu systems. Instead of
> walking the VMAs to find the first executable file-backed VMA we store a
> reference to the exec'd file in the mm_struct.
>
> That reference would prevent the filesystem holding the executable file
> from being unmounted even after unmapping the VMAs. So we track the number
> of VM_EXECUTABLE VMAs and drop the new reference when the last one is
> unmapped. This avoids pinning the mounted filesystem.
exe_file's vma accounting is hooked into every file mmap/unmmap and vma
split/merge just to fix some hypothetical pinning fs from umounting by mm,
which already unmapped all its executable files, but still alive.
Seems like currently nobody depends on this behaviour. We can try to
remove this logic and keep mm->exe_file until final mmput().
mm->exe_file is still protected with mm->mmap_sem, because we want to
change it via new sys_prctl(PR_SET_MM_EXE_FILE). Also via this syscall
task can change its mm->exe_file and unpin mountpoint explicitly.
Signed-off-by: Konstantin Khlebnikov <khlebnikov@openvz.org>
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
Cc: Carsten Otte <cotte@de.ibm.com>
Cc: Chris Metcalf <cmetcalf@tilera.com>
Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Cc: Eric Paris <eparis@redhat.com>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Morris <james.l.morris@oracle.com>
Cc: Jason Baron <jbaron@redhat.com>
Cc: Kentaro Takeda <takedakn@nttdata.co.jp>
Cc: Matt Helsley <matthltc@us.ibm.com>
Cc: Nick Piggin <npiggin@kernel.dk>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Robert Richter <robert.richter@amd.com>
Cc: Suresh Siddha <suresh.b.siddha@intel.com>
Cc: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Cc: Venkatesh Pallipadi <venki@google.com>
Acked-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/fork.c | 21 |
1 files changed, 0 insertions, 21 deletions
diff --git a/kernel/fork.c b/kernel/fork.c index a57a993681ed..ec667f797af3 100644 --- a/kernel/fork.c +++ b/kernel/fork.c | |||
@@ -622,26 +622,6 @@ void mmput(struct mm_struct *mm) | |||
622 | } | 622 | } |
623 | EXPORT_SYMBOL_GPL(mmput); | 623 | EXPORT_SYMBOL_GPL(mmput); |
624 | 624 | ||
625 | /* | ||
626 | * We added or removed a vma mapping the executable. The vmas are only mapped | ||
627 | * during exec and are not mapped with the mmap system call. | ||
628 | * Callers must hold down_write() on the mm's mmap_sem for these | ||
629 | */ | ||
630 | void added_exe_file_vma(struct mm_struct *mm) | ||
631 | { | ||
632 | mm->num_exe_file_vmas++; | ||
633 | } | ||
634 | |||
635 | void removed_exe_file_vma(struct mm_struct *mm) | ||
636 | { | ||
637 | mm->num_exe_file_vmas--; | ||
638 | if ((mm->num_exe_file_vmas == 0) && mm->exe_file) { | ||
639 | fput(mm->exe_file); | ||
640 | mm->exe_file = NULL; | ||
641 | } | ||
642 | |||
643 | } | ||
644 | |||
645 | void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file) | 625 | void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file) |
646 | { | 626 | { |
647 | if (new_exe_file) | 627 | if (new_exe_file) |
@@ -649,7 +629,6 @@ void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file) | |||
649 | if (mm->exe_file) | 629 | if (mm->exe_file) |
650 | fput(mm->exe_file); | 630 | fput(mm->exe_file); |
651 | mm->exe_file = new_exe_file; | 631 | mm->exe_file = new_exe_file; |
652 | mm->num_exe_file_vmas = 0; | ||
653 | } | 632 | } |
654 | 633 | ||
655 | struct file *get_mm_exe_file(struct mm_struct *mm) | 634 | struct file *get_mm_exe_file(struct mm_struct *mm) |