Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp155490imm; Thu, 30 Aug 2018 10:35:44 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZsYteja0Cm6ruAfcD5XlzVpizCj1iaIl0qxuRSaDBt/uQoXE9rL53+sNsku5IqJsxXv01q X-Received: by 2002:a62:e008:: with SMTP id f8-v6mr11527522pfh.208.1535650544103; Thu, 30 Aug 2018 10:35:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535650544; cv=none; d=google.com; s=arc-20160816; b=pus4Io00XAoi2+4OIL7lAcld0jHqpr3es+t5g5htGuITq44blibjZPxBlHKHVXFc+0 sodVkyUxxWPIlX6KtohYft8VfgX4qoJ8TqksXJ1GClh+aJm8PKVX1dQM3k/+Ow4iwHtV UmdGKwLoP8nUPv3OMpeoYw6CrrKoBMLNNGrB6l0BX9uQ7C0e/8odBDgjsQR9OxwaT3eI N38blTXrysjh9O9DsPwHiIbJbBeFwjAZokIsbkIy5wBuVw7AigRnh/5OYI/k8pkWp+KL kRiz7krtExJ7qqqmVU3qZGuiWYEjV1beciELUUy2VQgI4gQTQPMx15xyNEumPPWH/Ofu LKxw== 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=JNdhhMAnHGqgjkbxdaH5CB2y76HqYXgbvcKQvnH1DDQ=; b=Xn2l6hmmS1OPB1cpcq33w+vkqc25BZeFeihpK7hE6MDXuSPNfFQxCU3yb7NrgopYnv 48YzA9IRsBeSlAumTcgK4llQoZoJD6c36hF/PKFy8wN39UwkdxS0XuVmPr6+ws7He/FS fvIB2U5RA3n07eL4/rXBj5FPgwnu/GO8k09mUrOpTeZ+AhL4jKij6wUlbwz4lJZnc/4E tzrVC+JgQl3ULYHXxJNuS74n0seqYZcg+X5XaqS3KV8Gt945QII0k7vhsQhgWzoetbUl +YJqTrBMvU75y6LFGNmDciDdMI7H3FtcO9RvfHolwLkkxEWZRfhHG6dZ9mMeorizakut rVVw== 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 c3-v6si6797346pld.457.2018.08.30.10.35.29; Thu, 30 Aug 2018 10:35:44 -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 S1727626AbeH3Vh2 (ORCPT + 99 others); Thu, 30 Aug 2018 17:37:28 -0400 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:14372 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726674AbeH3VhU (ORCPT ); Thu, 30 Aug 2018 17:37:20 -0400 Received: from sc9-mailhost2.vmware.com (10.113.161.72) by EX13-EDG-OU-002.vmware.com (10.113.208.156) with Microsoft SMTP Server id 15.0.1156.6; Thu, 30 Aug 2018 10:33:41 -0700 Received: from sc2-haas01-esx0118.eng.vmware.com (sc2-haas01-esx0118.eng.vmware.com [10.172.44.118]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 9D2FEB05DD; Thu, 30 Aug 2018 13:34:06 -0400 (EDT) From: Nadav Amit To: Thomas Gleixner CC: , Ingo Molnar , , Arnd Bergmann , , Dave Hansen , Nadav Amit , Andy Lutomirski , Kees Cook , Peter Zijlstra , Dave Hansen Subject: [PATCH 3/6] fork: provide a function for copying init_mm Date: Thu, 30 Aug 2018 10:32:15 -0700 Message-ID: <20180830173218.238900-4-namit@vmware.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180830173218.238900-1-namit@vmware.com> References: <20180830173218.238900-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: Kees Cook Cc: Peter Zijlstra Cc: Dave Hansen Reviewed-by: Masami Hiramatsu 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