Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp9227090imu; Wed, 5 Dec 2018 00:54:15 -0800 (PST) X-Google-Smtp-Source: AFSGD/Vv3z/HHkOK0s5txutfe6vnrbiXWPhOL1gCNRReKtvv1BRtavgvoSt2X5n+QK1QIDH7Jm2Q X-Received: by 2002:a63:30c8:: with SMTP id w191mr20229942pgw.120.1544000055229; Wed, 05 Dec 2018 00:54:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544000055; cv=none; d=google.com; s=arc-20160816; b=g/udZM8u1ONLYtCpQl9KCS0BrGQwWgPm97jLXYoTYwkP6zyGlb6eFN36maac8EcR2c p+A6dzbuhc0WIwLIGXt2HzDLaGi0nUTWC4EaUPS+toO9zgNEqvj1cPcIiZvXdoBgLSFR 8tM+Q3JwGCkqaCyzK2cnHU+7mMVGqOxmxO9GtZXkvi6+rJ9Lu5np/IYeYdFrf02QvhrZ L4gbhOcBGbIHAkgz7pNiFLKZ/JnACum60PaP7v8ESijL28jUArKS+wQrSUvOX8GNRbe0 zaFyeNtLoKFSxd9tXjjx07SUveICmx/+7tpDtOtE6m7hj6NYjpE3VO1cw2DnxqfK2PYH xulw== 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; bh=TU5S11W+4/P/nvq0gRAs4FWCRJ4P/Vc801qFHvfGOBg=; b=vNinqMBKK4d+brgD8mAxty3sqA9/NPKnOClt0TpjubxC2Sa2DWFEOln9wFz05k8kzM F0I13AW77T64zuzj0omM+9UWSGve2y+YLxpDgi5iHjVXmzj2hQ/RJGOsz2D7sCCZtrEl skdNyIbFpS2Jzf7ozwqg0iAix/yIb5uNrAKCpv1h4KLMylEx9oUWdxPZmmii0LLziTQ8 /zJqs48FmdwoMgWAqWlmRROjC+wIE7TB/eAkhsJ1jSJ3j9CzUKOpqvRik21j5RJT9Z/I ByVlEXKMtW48qPD3HRkZFAR7LVWyCIyyEiJacKihPpTaP+e4bkXyC/iNi/ksUyueq/De 6SXw== 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 t12si19253784plr.311.2018.12.05.00.54.00; Wed, 05 Dec 2018 00:54:15 -0800 (PST) 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 S1727424AbeLEIwL (ORCPT + 99 others); Wed, 5 Dec 2018 03:52:11 -0500 Received: from ex13-edg-ou-002.vmware.com ([208.91.0.190]:46460 "EHLO EX13-EDG-OU-002.vmware.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727332AbeLEIwJ (ORCPT ); Wed, 5 Dec 2018 03:52:09 -0500 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, 5 Dec 2018 00:52:03 -0800 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 DF21441398; Wed, 5 Dec 2018 00:52:04 -0800 (PST) From: Nadav Amit To: Ingo Molnar CC: , , "H. Peter Anvin" , Thomas Gleixner , Borislav Petkov , Andy Lutomirski , Nadav Amit , Dave Hansen , Peter Zijlstra , , , , Nadav Amit , Kees Cook , Dave Hansen Subject: [PATCH v7 04/14] fork: provide a function for copying init_mm Date: Tue, 4 Dec 2018 17:33:58 -0800 Message-ID: <20181205013408.47725-5-namit@vmware.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181205013408.47725-1-namit@vmware.com> References: <20181205013408.47725-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 Tested-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 07cddff89c7b..01d3f5b39363 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1297,13 +1297,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(); @@ -1370,7 +1377,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; @@ -2176,6 +2183,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