Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp344960imm; Wed, 29 Aug 2018 01:15:52 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZVuiqdVygLeN4mqoSndtPciszIFFkft3VLq6ceWxINdvnqbdTdgO9E0n+uL8Y+safy/QEl X-Received: by 2002:a17:902:163:: with SMTP id 90-v6mr4916746plb.322.1535530552457; Wed, 29 Aug 2018 01:15:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535530552; cv=none; d=google.com; s=arc-20160816; b=zlFzcwHOGJ6z0JAfEl8cv1JYFDSQERZer9FiAVHXWvsJspyw2+3+p1eVgTod3Gtd6W 7TXce5RbILyl0WSZef6DTS+oOA+2NugmrR1zyvsvO0JRevm9iKP6GFs6MMKZMgOFgZ0Z HvvMwNcQUF2rtf6oQVpJ4kGYhlqFNY6lf+0B2KZR9o+9ImU+HtMHNS8kpyWI6oSzVE1C nyv/5p9YcxF3Z2jlcfksecl5Df+nyc69Pvy+934fwJ+3E1Oy6Z849cOpHiiPMvUvdFbo rWME1omNjeayzcC1dgI96GhR9jXodmXoFa/G8vFtw6PzfwbL37I5sTOElleyDUEnEyy5 49fg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=wvopoBeOIyl3M/41o7Q2/AguywjSa8PyK6IOGmkhqIU=; b=RAaj/qamwXaeneyulAHWGuy2tHLQUEkajtib2nRNgHSf/6IQkxNs9yTRmB1RKi7X29 OkBGQ9jxAm+kN9+oT9VXrPUCq/gLaQOCvhKpEVZ7z8HzQGcCM04IjyLChp/VHzI07RRp B7wvFSU8a2BuWXz0MD5BPEm4Nghuo7jbe9jh6FQu4jhExsYPFO/bLVnqK8wOg5MiSB8q 9qvl/QxLo7InunumI6UUl057On7SNGr38eO8SNUPCUG06V7EbacgXMkdGKGINXGgPu0s mv+BBNLpYQiNKed7hoT5847SylfIJqs/DBXZKeouyJ3wXOfEhlg4g8yRQYygo3aO3uMw tvnA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l7-v6si929730pgi.261.2018.08.29.01.15.37; Wed, 29 Aug 2018 01:15:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727973AbeH2MJI (ORCPT + 99 others); Wed, 29 Aug 2018 08:09:08 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:26867 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727819AbeH2MJH (ORCPT ); Wed, 29 Aug 2018 08:09:07 -0400 Received: from sc9-mailhost3.vmware.com (10.113.161.73) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Wed, 29 Aug 2018 01:13:02 -0700 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 33C3D40DF6; Wed, 29 Aug 2018 01:13:26 -0700 (PDT) From: Nadav Amit To: Thomas Gleixner CC: , Ingo Molnar , , Arnd Bergmann , , Nadav Amit , Andy Lutomirski , Masami Hiramatsu , Kees Cook , Peter Zijlstra Subject: [RFC PATCH 3/6] fork: provide a function for copying init_mm Date: Wed, 29 Aug 2018 01:11:44 -0700 Message-ID: <20180829081147.184610-4-namit@vmware.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180829081147.184610-1-namit@vmware.com> References: <20180829081147.184610-1-namit@vmware.com> MIME-Version: 1.0 Content-Type: text/plain Received-SPF: None (EX13-EDG-OU-002.vmware.com: namit@vmware.com does not designate permitted sender hosts) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Provide a function for copying init_mm. This function will be later used for setting a temporary mm. Cc: Andy Lutomirski Cc: Masami Hiramatsu Cc: Kees Cook Cc: Peter Zijlstra Signed-off-by: Nadav Amit --- include/linux/sched/task.h | 1 + kernel/fork.c | 24 ++++++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/include/linux/sched/task.h b/include/linux/sched/task.h index 108ede99e533..ac0a675678f5 100644 --- a/include/linux/sched/task.h +++ b/include/linux/sched/task.h @@ -74,6 +74,7 @@ extern void exit_itimers(struct signal_struct *); extern long _do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *, unsigned long); extern long do_fork(unsigned long, unsigned long, unsigned long, int __user *, int __user *); struct task_struct *fork_idle(int); +struct mm_struct *copy_init_mm(void); extern pid_t kernel_thread(int (*fn)(void *), void *arg, unsigned long flags); extern long kernel_wait4(pid_t, int __user *, int, struct rusage *); diff --git a/kernel/fork.c b/kernel/fork.c index d896e9ca38b0..a1c637b903c1 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1254,13 +1254,20 @@ void mm_release(struct task_struct *tsk, struct mm_struct *mm) complete_vfork_done(tsk); } -/* - * Allocate a new mm structure and copy contents from the - * mm structure of the passed in task structure. +/** + * dup_mm() - duplicates an existing mm structure + * @tsk: the task_struct with which the new mm will be associated. + * @oldmm: the mm to duplicate. + * + * Allocates a new mm structure and copy contents from the provided + * @oldmm structure. + * + * Return: the duplicated mm or NULL on failure. */ -static struct mm_struct *dup_mm(struct task_struct *tsk) +static struct mm_struct *dup_mm(struct task_struct *tsk, + struct mm_struct *oldmm) { - struct mm_struct *mm, *oldmm = current->mm; + struct mm_struct *mm; int err; mm = allocate_mm(); @@ -1327,7 +1334,7 @@ static int copy_mm(unsigned long clone_flags, struct task_struct *tsk) } retval = -ENOMEM; - mm = dup_mm(tsk); + mm = dup_mm(tsk, current->mm); if (!mm) goto fail_nomem; @@ -2127,6 +2134,11 @@ struct task_struct *fork_idle(int cpu) return task; } +struct mm_struct *copy_init_mm(void) +{ + return dup_mm(NULL, &init_mm); +} + /* * Ok, this is the main fork-routine. * -- 2.17.1