From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752567AbbCNWjz (ORCPT ); Sat, 14 Mar 2015 18:39:55 -0400 Received: from smtp2.provo.novell.com ([137.65.250.81]:60831 "EHLO smtp2.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751059AbbCNWjt (ORCPT ); Sat, 14 Mar 2015 18:39:49 -0400 From: Davidlohr Bueso To: akpm@linux-foundation.org Cc: viro@zeniv.linux.org.uk, gorcunov@openvz.org, oleg@redhat.com, koct9i@gmail.com, dave@stgolabs.net, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Davidlohr Bueso Subject: [PATCH 2/4] mm: introduce struct exe_file Date: Sat, 14 Mar 2015 15:39:24 -0700 Message-Id: <1426372766-3029-3-git-send-email-dave@stgolabs.net> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1426372766-3029-1-git-send-email-dave@stgolabs.net> References: <1426372766-3029-1-git-send-email-dave@stgolabs.net> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch isolates exe_file handling into its own data structure, tiding up the mm_struct bits (which must remain there as we provide prctl thread interfaces to change it). Note that none of the interfaces have changed, users will continue dealing with the actual backing struct file, but internally we isolate things, serialization remaining the same. Signed-off-by: Davidlohr Bueso Cc: Alexander Viro Cc: Cyrill Gorcunov Cc: Oleg Nesterov CC: Konstantin Khlebnikov --- include/linux/mm_types.h | 8 ++++++-- kernel/fork.c | 27 ++++++++++++++------------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h index 5951baf..1fc994e 100644 --- a/include/linux/mm_types.h +++ b/include/linux/mm_types.h @@ -326,6 +326,11 @@ struct core_state { struct completion startup; }; +struct exe_file { + rwlock_t lock; + struct file *file; +}; + enum { MM_FILEPAGES, MM_ANONPAGES, @@ -429,8 +434,7 @@ struct mm_struct { #endif /* store ref to file /proc//exe symlink points to */ - rwlock_t exe_file_lock; - struct file *exe_file; + struct exe_file exe_file; #ifdef CONFIG_MMU_NOTIFIER struct mmu_notifier_mm *mmu_notifier_mm; #endif diff --git a/kernel/fork.c b/kernel/fork.c index a573b18..aa0332b 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -566,7 +566,7 @@ static struct mm_struct *mm_init(struct mm_struct *mm, struct task_struct *p) mm_init_owner(mm, p); mmu_notifier_mm_init(mm); clear_tlb_flush_pending(mm); - rwlock_init(&mm->exe_file_lock); + rwlock_init(&mm->exe_file.lock); #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && !USE_SPLIT_PMD_PTLOCKS mm->pmd_huge_pte = NULL; #endif @@ -679,45 +679,46 @@ void set_mm_exe_file_locked(struct mm_struct *mm, struct file *new_exe_file) { if (new_exe_file) get_file(new_exe_file); - if (mm->exe_file) - fput(mm->exe_file); + if (mm->exe_file.file) + fput(mm->exe_file.file); - write_lock(&mm->exe_file_lock); - mm->exe_file = new_exe_file; - write_unlock(&mm->exe_file_lock); + write_lock(&mm->exe_file.lock); + mm->exe_file.file = new_exe_file; + write_unlock(&mm->exe_file.lock); } void set_mm_exe_file(struct mm_struct *mm, struct file *new_exe_file) { if (new_exe_file) get_file(new_exe_file); - if (mm->exe_file) - fput(mm->exe_file); + if (mm->exe_file.file) + fput(mm->exe_file.file); - mm->exe_file = new_exe_file; + mm->exe_file.file = new_exe_file; } struct file *get_mm_exe_file(struct mm_struct *mm) { struct file *exe_file; - read_lock(&mm->exe_file_lock); - exe_file = mm->exe_file; + read_lock(&mm->exe_file.lock); + exe_file = mm->exe_file.file; if (exe_file) get_file(exe_file); - read_unlock(&mm->exe_file_lock); + read_unlock(&mm->exe_file.lock); return exe_file; } EXPORT_SYMBOL(get_mm_exe_file); + static void dup_mm_exe_file(struct mm_struct *oldmm, struct mm_struct *newmm) { /* * It's safe to write the exe_file without the * exe_file_lock as we are just setting up the new task. */ - newmm->exe_file = get_mm_exe_file(oldmm); + newmm->exe_file.file = get_mm_exe_file(oldmm); } /** -- 2.1.4