From nobody Fri Dec 19 02:49:23 2025 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1A12326D4D5; Mon, 28 Apr 2025 15:32:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745854374; cv=fail; b=ihoLELQtBvjKwqzhMeRaHFJp9jizebBi8YR4pO0v4aH9JSp/9RUGOgifcX5aN0BHHwviMYAi9gnRqKSbLmeERutHpTbCRU+UhHujR7rj8iKvptJV54+nAPcMB5Ji5ZVI+n2FaZVvAvCV9SVVCo0XHv15t0QLfyz6uApXWqoix/c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745854374; c=relaxed/simple; bh=9S7EfEXwZR/3uu9ToK4OPavP+aAzm8D40RICC0jDppY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=VW6tUOmhjh0ucHcBzq8zE0ZE06rBacA1ryfVUtRolADrtryOniVUl/7MsAAd1iT7fcYvfjzUaPMHEpfzqdQce/v7wk1ypg7JjcJ6viqloc2g7AFZbfZIxp8zNirIkkGjsty8sJ6JARSvW0KOVakBMLMQ/dd16waOx0HvNxYcW9Y= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=Y9fI+Yhh; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=AfNUANeP; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="Y9fI+Yhh"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="AfNUANeP" Received: from pps.filterd (m0246632.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53SFMuVq010816; Mon, 28 Apr 2025 15:32:37 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=GGjfhe8z8hREZVuk6RU/Sq8CVsI5zVDernyeDHcBGPY=; b= Y9fI+YhhhuwAaz2+bmy/PlhjV49VQ7AiaRFXlgdCpOMTtvfcOM0yyc+9jGY7PfG5 j5cADFo5MDxgVavyOPf5wHrGN8S54lIba25nRQqb1Xk/BEuciCBybP0uXQxIKpBK R8msB1AB2mFx9Vxm3EoqG2bGW8NxBG0uSf3TGeRr9UwFZivYfBBwXl2Eauqgh7fq ZgQxb4Mu5KUcYnxhKvHDjXf07kgOwSA2viyJuctmX++30SNOXpMJw0pzRjpss11L NXiCdXbSBhAnlxrLw39JnxMR6eU5ecRLBhT+zQSvfizMKNkd/dOXoruiK+iRqDlH s0ccdQQzdoBWIIuZE7QrdA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 46abkd85r8-17 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Apr 2025 15:32:37 +0000 (GMT) Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 53SFBUCq025919; Mon, 28 Apr 2025 15:28:27 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam04lp2049.outbound.protection.outlook.com [104.47.74.49]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 468nxetpv2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Apr 2025 15:28:27 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AeGG1+vF4z5b6KiK5UXTyqMdPFlTs4ihSR1ZAOTl6LezJ9aY6wkfHNJSGiMkgU3PjcJEMhOnBwaCcTUOtzMtX4V1pt9ztrheALYOs/papr7jHnxfMKDofGQrD6h9Bc+nLSnm955XqexkP/WI0eVxF3PRhsDicYUMTXmQPJ+md299FPA7mGcxrsdjFVSl1165HzBsMwVca6La+jc2E3kVurztl2opns+kJlFlDVDTxVuqzvgU1WNhfH21ysoI6eQM9FIYyDkHoAgCLsQJ0UZfjRpudqquFTAClWrp+yjwSa5Azwj+yrB57vnooUTz1LwZxtT5fhWFm2ka6ehRQKeRMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=GGjfhe8z8hREZVuk6RU/Sq8CVsI5zVDernyeDHcBGPY=; b=Crn1Ov8mYZt25mT/Y3mC+NZvBJ2t5wqtqwv86b3Rxbu2y+0NHwb3nQSFQum1KDULYOHkgFSGovztdabnX7jluKxyfDUAX2JSo9jAHY1GwWibTUGB907ZSvG/QApWPypH2Wah3MsOztJvwxGHvZf86k4CsLpXsHGeDtiL/VpUXkNxiR7YD1FvgaUsDzf4dZdchU0w/ZvdbS4NjrSmP9ISsi5rDaDtug4aITtYHzR0uRbo7CAdW6AZU6oYJkQYr0o0NB6foXnndssuGPb+mFjGQ7V8OCgh1GW9pvrP3vfPgMll6kNLubo2oTa1sSXVZzBj7JC0ovZOBd2BlisERuoI9w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=GGjfhe8z8hREZVuk6RU/Sq8CVsI5zVDernyeDHcBGPY=; b=AfNUANePvcPA/2mLpkjI2hv/DDS+RWCBT3K6u5WMVAGrLzYd+w9novc8ga7gkherz9667xHi/bT5Ml7XpTfEdtdwVp4L6Gy1DMgbpusfgiYSPHboNO4nXAFi47YpHzxQpsm7CXThovBuyN4vuDvpsWt4ruwIp2xdnuhcObLJ2qU= Received: from DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) by BL3PR10MB6259.namprd10.prod.outlook.com (2603:10b6:208:38e::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8678.33; Mon, 28 Apr 2025 15:28:25 +0000 Received: from DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2]) by DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2%5]) with mapi id 15.20.8678.028; Mon, 28 Apr 2025 15:28:25 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , Pedro Falcato , David Hildenbrand , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Suren Baghdasaryan , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/4] mm: establish mm/vma_exec.c for shared exec/mm VMA functionality Date: Mon, 28 Apr 2025 16:28:14 +0100 Message-ID: <91f2cee8f17d65214a9d83abb7011aa15f1ea690.1745853549.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO4P123CA0394.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18f::21) To DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR10MB8218:EE_|BL3PR10MB6259:EE_ X-MS-Office365-Filtering-Correlation-Id: 823a8d58-802d-4ed5-64ae-08dd86695139 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|366016|1800799024; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?XA4+SibcVt7xy4Y/d/txhKWHncVUrDrN2BSmDwkiAu9AQBQWsoZrQ21Wmaft?= =?us-ascii?Q?yZNIdZI/FiiLJ+H+4O+79ww4suf130+4tWvZqUFGT4qQc6PK8xonSZn8f2iZ?= =?us-ascii?Q?zWYofoCWC8TndUfo/HJzamhZzbx1umlYQ9IIGk2mNJ7BRy7/7qxLjzZqRP2w?= =?us-ascii?Q?uAQzyTJdhQX7hrcdRVvsdo/tubtc8tC5KdPiSIrxXL361mrQ82sWDAeFwPim?= =?us-ascii?Q?T8jbMxGjiPl88/44YQAoU8c5Z3oX2JKz+AkQzdV5sEhwoil98eJOMCE1+Yza?= =?us-ascii?Q?tro8IngTDsyuXQ+fNLwudpqanUKUp4muAv0QQBnrq37Znzkb0oNtDFoCrrkF?= =?us-ascii?Q?RqbCR90ixaoU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HSovxJG/VhEGN?= =?us-ascii?Q?x18apZwVFLecsu8Xma6R5xxTHU4ByjTQFcYz3Y1A6yoDJQ1KMeRWzHswd3OQ?= =?us-ascii?Q?NKtlkYzAt8fpTg3CL3xsnv3/g8NWhVwtfhqYIy6eT4oKdmR+LKVby5tggu3C?= =?us-ascii?Q?MTzVc0Ww0aIsZ8i/LIGaKIJbf91TdERwiZnnSkj+0ojgCAJem8ontZz0babN?= =?us-ascii?Q?fyZtJneQZZ4=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR10MB8218.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?7IlCIf3VXMSmaWjhK0l0zaMxXVy3obqWB7yELieEB63xdml5vkNr8R96jbND?= =?us-ascii?Q?4VwGXprUyvcttYOYyfYAsTFljf7j8Sa9pptUpqeuF5KXPSmNOr4NGwUD2z20?= =?us-ascii?Q?8fs5S3+29xEk8ePt3nIQIppMuMoLLX+kpGN9+6QIJr8Ql9TDf3lHiH2ucpOy?= =?us-ascii?Q?HmQ5bwcp6xaeYSIh7iLunEG0MIyToUUR2w/m97LxPGz+Hdak6Hc6QFrPhkAD?= =?us-ascii?Q?mBZGjMR5ZHMO8qQBNPL+Zf2BE1BPr2DeYznWS8qgtF+64iPSgoZGhKMk8GSj?= =?us-ascii?Q?P7yoyJzsYRixnGim8524UP1467lBoTeJnf/UAqWAdmXlVZUCbB4VqwbsYkdH?= =?us-ascii?Q?loZkx0ZdEJSgcezpSf0NKzV+0LaCgDw9Re9/iCXWOnav/CST8tWvwhzzkJ5C?= =?us-ascii?Q?4BrCwK8OjDchrctMfwSTLL73z0Sjz9uwg6OGBW8UF+ln7KqXNt+PzBYoXTaB?= =?us-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rg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 823a8d58-802d-4ed5-64ae-08dd86695139 X-MS-Exchange-CrossTenant-AuthSource: DM4PR10MB8218.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2025 15:28:25.0876 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: mdlIDhCdnKc/hnVJ8kcKQBxoQuVoRcHB3xkGPZ/dQLvopQxMBK155NQQAowF+O+RbeSjLyI6RWuk9r9BDduXteiIqJdwXzWSFdXynkkm/Mo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL3PR10MB6259 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-04-28_06,2025-04-24_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 suspectscore=0 spamscore=0 adultscore=0 mlxscore=0 malwarescore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2504070000 definitions=main-2504280127 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNDI4MDEyNyBTYWx0ZWRfXwYjtaLch0gU/ I5zBHomgeYu68yyZX5II6fBENH0KFEdgqrNhIg2/eMatpN1tW/S+YRXg5qhJsbgvmAXUvUSdBnE r2uPfw5hCf/fUp1w0l29VKrj2ts8cBjPvJu+a/dcAuFig9YxnQHzvJcPnuuuvBCH6kLzA9uU7Lq EjO3l52q75/dlkQ7bgFkP5ZBOyO1iZUDHUTmAE/HuUNFhwYsO1DN8d74Af3RA5YekGHEHbVR0ZG mZYK3q11qi/EPK0ua0e0yPd1KREykvKA56NXDMKip8Y0Snzi4I5jjA8h/SBXd1yZnVttpegUBV1 jOLWDZI6k/LlZCI85GaeH2tYysIGKt/JQ3CwKO0k1/yW04dNfpFHh7loqH5svKXbinF4vEXBTGe TWdMZkMg X-Proofpoint-ORIG-GUID: 4jv5Tu0DFn-TbH0I7PmMfzvrD4xKIDNf X-Proofpoint-GUID: 4jv5Tu0DFn-TbH0I7PmMfzvrD4xKIDNf Content-Type: text/plain; charset="utf-8" There is functionality that overlaps the exec and memory mapping subsystems. While it properly belongs in mm, it is important that exec maintainers maintain oversight of this functionality correctly. We can establish both goals by adding a new mm/vma_exec.c file which contains these 'glue' functions, and have fs/exec.c import them. As a part of this change, to ensure that proper oversight is achieved, add the file to both the MEMORY MAPPING and EXEC & BINFMT API, ELF sections. scripts/get_maintainer.pl can correctly handle files in multiple entries and this neatly handles the cross-over. Signed-off-by: Lorenzo Stoakes Reviewed-by: David Hildenbrand Reviewed-by: Kees Cook Reviewed-by: Liam R. Howlett Reviewed-by: Pedro Falcato Reviewed-by: Suren Baghdasaryan Reviewed-by: Vlastimil Babka --- MAINTAINERS | 2 + fs/exec.c | 3 ++ include/linux/mm.h | 1 - mm/Makefile | 2 +- mm/mmap.c | 83 ---------------------------- mm/vma.h | 5 ++ mm/vma_exec.c | 92 ++++++++++++++++++++++++++++++++ tools/testing/vma/Makefile | 2 +- tools/testing/vma/vma.c | 1 + tools/testing/vma/vma_internal.h | 40 ++++++++++++++ 10 files changed, 145 insertions(+), 86 deletions(-) create mode 100644 mm/vma_exec.c diff --git a/MAINTAINERS b/MAINTAINERS index f5ee0390cdee..1ee1c22e6e36 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8830,6 +8830,7 @@ F: include/linux/elf.h F: include/uapi/linux/auxvec.h F: include/uapi/linux/binfmts.h F: include/uapi/linux/elf.h +F: mm/vma_exec.c F: tools/testing/selftests/exec/ N: asm/elf.h N: binfmt @@ -15654,6 +15655,7 @@ F: mm/mremap.c F: mm/mseal.c F: mm/vma.c F: mm/vma.h +F: mm/vma_exec.c F: mm/vma_internal.h F: tools/testing/selftests/mm/merge.c F: tools/testing/vma/ diff --git a/fs/exec.c b/fs/exec.c index 8e4ea5f1e64c..477bc3f2e966 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -78,6 +78,9 @@ =20 #include =20 +/* For vma exec functions. */ +#include "../mm/internal.h" + static int bprm_creds_from_file(struct linux_binprm *bprm); =20 int suid_dumpable =3D 0; diff --git a/include/linux/mm.h b/include/linux/mm.h index 21dd110b6655..4fc361df9ad7 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -3223,7 +3223,6 @@ void anon_vma_interval_tree_verify(struct anon_vma_ch= ain *node); extern int __vm_enough_memory(struct mm_struct *mm, long pages, int cap_sy= s_admin); extern int insert_vm_struct(struct mm_struct *, struct vm_area_struct *); extern void exit_mmap(struct mm_struct *); -int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift); bool mmap_read_lock_maybe_expand(struct mm_struct *mm, struct vm_area_stru= ct *vma, unsigned long addr, bool write); =20 diff --git a/mm/Makefile b/mm/Makefile index 9d7e5b5bb694..15a901bb431a 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -37,7 +37,7 @@ mmu-y :=3D nommu.o mmu-$(CONFIG_MMU) :=3D highmem.o memory.o mincore.o \ mlock.o mmap.o mmu_gather.o mprotect.o mremap.o \ msync.o page_vma_mapped.o pagewalk.o \ - pgtable-generic.o rmap.o vmalloc.o vma.o + pgtable-generic.o rmap.o vmalloc.o vma.o vma_exec.o =20 =20 ifdef CONFIG_CROSS_MEMORY_ATTACH diff --git a/mm/mmap.c b/mm/mmap.c index bd210aaf7ebd..1794bf6f4dc0 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1717,89 +1717,6 @@ static int __meminit init_reserve_notifier(void) } subsys_initcall(init_reserve_notifier); =20 -/* - * Relocate a VMA downwards by shift bytes. There cannot be any VMAs betwe= en - * this VMA and its relocated range, which will now reside at [vma->vm_sta= rt - - * shift, vma->vm_end - shift). - * - * This function is almost certainly NOT what you want for anything other = than - * early executable temporary stack relocation. - */ -int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift) -{ - /* - * The process proceeds as follows: - * - * 1) Use shift to calculate the new vma endpoints. - * 2) Extend vma to cover both the old and new ranges. This ensures the - * arguments passed to subsequent functions are consistent. - * 3) Move vma's page tables to the new range. - * 4) Free up any cleared pgd range. - * 5) Shrink the vma to cover only the new range. - */ - - struct mm_struct *mm =3D vma->vm_mm; - unsigned long old_start =3D vma->vm_start; - unsigned long old_end =3D vma->vm_end; - unsigned long length =3D old_end - old_start; - unsigned long new_start =3D old_start - shift; - unsigned long new_end =3D old_end - shift; - VMA_ITERATOR(vmi, mm, new_start); - VMG_STATE(vmg, mm, &vmi, new_start, old_end, 0, vma->vm_pgoff); - struct vm_area_struct *next; - struct mmu_gather tlb; - PAGETABLE_MOVE(pmc, vma, vma, old_start, new_start, length); - - BUG_ON(new_start > new_end); - - /* - * ensure there are no vmas between where we want to go - * and where we are - */ - if (vma !=3D vma_next(&vmi)) - return -EFAULT; - - vma_iter_prev_range(&vmi); - /* - * cover the whole range: [new_start, old_end) - */ - vmg.middle =3D vma; - if (vma_expand(&vmg)) - return -ENOMEM; - - /* - * move the page tables downwards, on failure we rely on - * process cleanup to remove whatever mess we made. - */ - pmc.for_stack =3D true; - if (length !=3D move_page_tables(&pmc)) - return -ENOMEM; - - tlb_gather_mmu(&tlb, mm); - next =3D vma_next(&vmi); - if (new_end > old_start) { - /* - * when the old and new regions overlap clear from new_end. - */ - free_pgd_range(&tlb, new_end, old_end, new_end, - next ? next->vm_start : USER_PGTABLES_CEILING); - } else { - /* - * otherwise, clean from old_start; this is done to not touch - * the address space in [new_end, old_start) some architectures - * have constraints on va-space that make this illegal (IA64) - - * for the others its just a little faster. - */ - free_pgd_range(&tlb, old_start, old_end, new_end, - next ? next->vm_start : USER_PGTABLES_CEILING); - } - tlb_finish_mmu(&tlb); - - vma_prev(&vmi); - /* Shrink the vma to just the new range */ - return vma_shrink(&vmi, vma, new_start, new_end, vma->vm_pgoff); -} - #ifdef CONFIG_MMU /* * Obtain a read lock on mm->mmap_lock, if the specified address is below = the diff --git a/mm/vma.h b/mm/vma.h index 149926e8a6d1..1ce3e18f01b7 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -548,4 +548,9 @@ int expand_downwards(struct vm_area_struct *vma, unsign= ed long address); =20 int __vm_munmap(unsigned long start, size_t len, bool unlock); =20 +/* vma_exec.h */ +#ifdef CONFIG_MMU +int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift); +#endif + #endif /* __MM_VMA_H */ diff --git a/mm/vma_exec.c b/mm/vma_exec.c new file mode 100644 index 000000000000..6736ae37f748 --- /dev/null +++ b/mm/vma_exec.c @@ -0,0 +1,92 @@ +// SPDX-License-Identifier: GPL-2.0-only + +/* + * Functions explicitly implemented for exec functionality which however a= re + * explicitly VMA-only logic. + */ + +#include "vma_internal.h" +#include "vma.h" + +/* + * Relocate a VMA downwards by shift bytes. There cannot be any VMAs betwe= en + * this VMA and its relocated range, which will now reside at [vma->vm_sta= rt - + * shift, vma->vm_end - shift). + * + * This function is almost certainly NOT what you want for anything other = than + * early executable temporary stack relocation. + */ +int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift) +{ + /* + * The process proceeds as follows: + * + * 1) Use shift to calculate the new vma endpoints. + * 2) Extend vma to cover both the old and new ranges. This ensures the + * arguments passed to subsequent functions are consistent. + * 3) Move vma's page tables to the new range. + * 4) Free up any cleared pgd range. + * 5) Shrink the vma to cover only the new range. + */ + + struct mm_struct *mm =3D vma->vm_mm; + unsigned long old_start =3D vma->vm_start; + unsigned long old_end =3D vma->vm_end; + unsigned long length =3D old_end - old_start; + unsigned long new_start =3D old_start - shift; + unsigned long new_end =3D old_end - shift; + VMA_ITERATOR(vmi, mm, new_start); + VMG_STATE(vmg, mm, &vmi, new_start, old_end, 0, vma->vm_pgoff); + struct vm_area_struct *next; + struct mmu_gather tlb; + PAGETABLE_MOVE(pmc, vma, vma, old_start, new_start, length); + + BUG_ON(new_start > new_end); + + /* + * ensure there are no vmas between where we want to go + * and where we are + */ + if (vma !=3D vma_next(&vmi)) + return -EFAULT; + + vma_iter_prev_range(&vmi); + /* + * cover the whole range: [new_start, old_end) + */ + vmg.middle =3D vma; + if (vma_expand(&vmg)) + return -ENOMEM; + + /* + * move the page tables downwards, on failure we rely on + * process cleanup to remove whatever mess we made. + */ + pmc.for_stack =3D true; + if (length !=3D move_page_tables(&pmc)) + return -ENOMEM; + + tlb_gather_mmu(&tlb, mm); + next =3D vma_next(&vmi); + if (new_end > old_start) { + /* + * when the old and new regions overlap clear from new_end. + */ + free_pgd_range(&tlb, new_end, old_end, new_end, + next ? next->vm_start : USER_PGTABLES_CEILING); + } else { + /* + * otherwise, clean from old_start; this is done to not touch + * the address space in [new_end, old_start) some architectures + * have constraints on va-space that make this illegal (IA64) - + * for the others its just a little faster. + */ + free_pgd_range(&tlb, old_start, old_end, new_end, + next ? next->vm_start : USER_PGTABLES_CEILING); + } + tlb_finish_mmu(&tlb); + + vma_prev(&vmi); + /* Shrink the vma to just the new range */ + return vma_shrink(&vmi, vma, new_start, new_end, vma->vm_pgoff); +} diff --git a/tools/testing/vma/Makefile b/tools/testing/vma/Makefile index 860fd2311dcc..624040fcf193 100644 --- a/tools/testing/vma/Makefile +++ b/tools/testing/vma/Makefile @@ -9,7 +9,7 @@ include ../shared/shared.mk OFILES =3D $(SHARED_OFILES) vma.o maple-shim.o TARGETS =3D vma =20 -vma.o: vma.c vma_internal.h ../../../mm/vma.c ../../../mm/vma.h +vma.o: vma.c vma_internal.h ../../../mm/vma.c ../../../mm/vma_exec.c ../..= /../mm/vma.h =20 vma: $(OFILES) $(CC) $(CFLAGS) -o $@ $(OFILES) $(LDLIBS) diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index 7cfd6e31db10..5832ae5d797d 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -28,6 +28,7 @@ unsigned long stack_guard_gap =3D 256UL<mas); @@ -1240,4 +1262,22 @@ static inline int mapping_map_writable(struct addres= s_space *mapping) return 0; } =20 +static inline unsigned long move_page_tables(struct pagetable_move_control= *pmc) +{ + (void)pmc; + + return 0; +} + +static inline void free_pgd_range(struct mmu_gather *tlb, + unsigned long addr, unsigned long end, + unsigned long floor, unsigned long ceiling) +{ + (void)tlb; + (void)addr; + (void)end; + (void)floor; + (void)ceiling; +} + #endif /* __MM_VMA_INTERNAL_H */ --=20 2.49.0 From nobody Fri Dec 19 02:49:23 2025 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D0D532798FF; Mon, 28 Apr 2025 15:33:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745854396; cv=fail; b=C23dQetzFdasoBfTEO59HK2becJjKcYC3OMH3wD2Oy/l/eXz6Wz1xpelHA02VsRlPuaZZVKCc359vw7xcyYNYFYDRNiOH3EqLTKaCiLHxyZVjVU+yESM1pF5rTfWZKpwNb57vwqjZ9UzZ26N1Mlmz98mHk+WQoXNYMkv0CYA3L8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745854396; c=relaxed/simple; bh=5zZ93pf67IRWha3wW7g0O2ncLLGlf1ldLcmKYcxMCaM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=bd/I0GDxLQ35JF2EFzuYNqoNxZ90j2REzK+87C/omvADtt9sY8vdkPz8e7r2laT9Wzk48sk8ohPfqUjaLmM0NAv3gKjWLzlcUhy/C8ONV1dqcSjXhgTmG2Y8qWw48cGLK1MixwtJ3s0JYpAoo59Rn1Nzum9/3w39NpIQWCkWUas= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=i7zEjj97; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=eH4Qhrus; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="i7zEjj97"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="eH4Qhrus" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53SFMw0Y006704; Mon, 28 Apr 2025 15:32:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=vjeiE0w4Ti2Jhwx9gvvWOmUUYlHZR/2vkND0yU76cms=; b= i7zEjj97MJXhW6u+7n/ZvdUVuCd451GBCLlL/kggnyDh4mDCS/be0RP7If0nzzee FS9lb+yu3OXV1Xe/DgK7Bs+wG6rT9gtKCxY1Nb3t9R0E3lcUrIu99ccu5SXSdYA7 ASs1wh84LzeMDHcMJDohOZjg8CTwBjf+ZqhS+dijTLGrg667ZYwe2TJclAs6mVtD DozBeLl18wJU84FolNO1tjnHQxaOcnVVfZyfzA294mB1gpNWy2hY9MPKTFs53xf+ fdZRKaO/iyD2dfB1iNKGMg4H4SE1Utij3bluCf4wWHwptFEjhRFD2yK28D61XaAE qTZNNKXs62tD2XHtyG0KPA== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 46abtf8332-18 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Apr 2025 15:32:55 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 53SE2Ij2007618; Mon, 28 Apr 2025 15:28:39 GMT Received: from sa9pr02cu001.outbound.protection.outlook.com (mail-southcentralusazlp17011029.outbound.protection.outlook.com [40.93.14.29]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 468nx8b3bp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Apr 2025 15:28:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ruTHO5HtdEKvAhFklkBvyp++sVi3Azeb74523C/2vnvqIi+/Ltlvrt0fvCyJqh8y6CLyGI6XnvlRjZjheCuaO29N/PxBlhyCYD7Tic+4GWra60s9/+0fhMQcY9bhGbZ9xQZ00pCR56w5+kENmBQBkUk0kuq5hhqL2QQNaVs2CSwtalmI0OQ6+ooyEHRDjCldQI0D75Dh22MOx9xI5BMypVd9qONi0dsOY9wDkCo2FrDn8D6Wp9QtR7FxuKbYQZZBrhXja9j32vR3cAjOEQaQ6Y48lDZQRTPgmsLLD5VSYL5KJdu07oqJSUlJf1bbkveQo4z1XyRh569qw3LdfykHhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vjeiE0w4Ti2Jhwx9gvvWOmUUYlHZR/2vkND0yU76cms=; b=eSaiVDY/I0qOiJ+5gRmQahujGNItziQ734mokQ497u0PdeoRp4xQup/ZTi+ipUGBYArz6aqlx4zVIVgO/yTeBjRDA0K3Cl3rmGVccUmqozL9YHJIFwvlrZbXvTFHbnqFNgj2nIA31GJSDu48M/vZN7YzxkhzL8Y7WOJFvQIn8eQSNmlR04TVYndaOTE3eA448wpgJxt1X35N+6joG9W1tk1WCuDBKt1Nkr3/1ltY+PNn8CAXaN29dNctBrskRUHEPf12yoZ4fe8/bZmBVZRfNoDDfDhLFYNP68ye9IvidkaDC7o6k3tk+Zlaefb95ZPbWKZ90KzKnWaIfcPoFbH3qQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vjeiE0w4Ti2Jhwx9gvvWOmUUYlHZR/2vkND0yU76cms=; b=eH4QhrusW+YZXkS6wTr2ZVv6CMqiHr9R/M1S/7eVezGtUA1K243rNlfH+fGtSrCzlaxWnOWUXUfKKZh7c5AmJqKD3cdckJpf9jyTrSbLBlJs3NEeePf+VCuRuXjFDeculSoPaDP7QgpYTJs48SdGbk0omp2IVJG6NrfNZaAlLrk= Received: from DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) by DS0PR10MB7223.namprd10.prod.outlook.com (2603:10b6:8:de::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8678.31; Mon, 28 Apr 2025 15:28:27 +0000 Received: from DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2]) by DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2%5]) with mapi id 15.20.8678.028; Mon, 28 Apr 2025 15:28:27 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , Pedro Falcato , David Hildenbrand , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Suren Baghdasaryan , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/4] mm: abstract initial stack setup to mm subsystem Date: Mon, 28 Apr 2025 16:28:15 +0100 Message-ID: <118c950ef7a8dd19ab20a23a68c3603751acd30e.1745853549.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO3P123CA0009.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:ba::14) To DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR10MB8218:EE_|DS0PR10MB7223:EE_ X-MS-Office365-Filtering-Correlation-Id: 03096584-038f-43fb-3d7c-08dd866952d2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?DBsqHAkNFRgv+2UakT6RmAGZtbL+EVb2WfWnvYncJTzbScj7z/vjt1zAh46O?= =?us-ascii?Q?U5oKv2j8CXOq52pJqKgQ87Fy25NkuOw5QJViq1CBWdMKkcPYmgtqCTa1UF6N?= =?us-ascii?Q?CqrxjOxdGvC2I2cU5p7VIf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?Q?K0gCiedmnlfJeyusO3zhzIHyrf/WJCgC40VVn6/Zk27G1HXoYCZffifJ42pj?= =?us-ascii?Q?DNbkQyHANMmCAHUuqXAuNfIulnUj4+CT9N2zjvFI3zNMICpETHRll0nkid9/?= =?us-ascii?Q?LsnoanyycyQCTCruDbt5HkkNi1eT237qbv/aEIT3WFJHTHQnnB0fa/m6JH9N?= =?us-ascii?Q?IODYFeLyzymIFkIwmHiBVb6XHMLgCx1pvOeF9pyfaB6R/KieQA8zrDgNOtRW?= =?us-ascii?Q?VZ/0rS+rz8Vvgi4PcIlxlH2OZX915CdByJC6l4NSg7p9va1DNJX/zlSed+fo?= =?us-ascii?Q?Nw/AikW5hGaLLW0Rfq1k9fXClkduMpeC4QhZqp2HIu4bcbxAgzGv+IXatxvg?= =?us-ascii?Q?7CVR5TXrMYAinrKVDiX3rOJIj2vsd4u0DqahNRyCIc0JNvy/DQ=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR10MB8218.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?32nUhMWnw5aTGG+02ifNI4AkSsTxEKisVZSMkZgZIA+2i6P+S0gnVI4zay2i?= =?us-ascii?Q?/xlMZJw8h4fCuepSzvtRxsmkXpdxT/tenXaFsScOcKvA096R4ETPH34sILJc?= =?us-ascii?Q?w1jbVRvCVCHRvtvqtLZcQkTneGJK/8PlNPU/1v18YD3Kg5Roh7bpvi/P9UL8?= =?us-ascii?Q?QTumCycaNcsJ4S8jCDoP6C+w/RSDnekdqbSfIlyOsF8GM3/KWzPRvcQTsro1?= =?us-ascii?Q?XU1yntNL6/tiUDKs9EEPcsSNgtLItr81DQbrpTkO5bmfRpCj6Oe6kU/Sr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184WCtx8jqCUCRyQQzIEb6vljD9v5KIjqHbFTK5uu3bE?= =?us-ascii?Q?RfpDbkvHz6YZdgtBSXR9FsL0b8gG9Fs50PvQVWiU85TyTS66/cBPB92rP49n?= =?us-ascii?Q?g50V5e9FhR/6D0KMsTvy83O3CjOws2dN2jjCOM8TVRcazndyd/sma+BFx3pf?= =?us-ascii?Q?KufIImRegvjFcepDxFW/Wy/RyJ749xUo+HcHa44SzaRdKnTIvrqnNeZJmAEi?= =?us-ascii?Q?44GK02K9dZGJxkcYz/Z30TRcI7d0iOPRhDuyfgKZC6Az2a2BoZ4Tly6SO9nu?= =?us-ascii?Q?pKzQSseG6/FUymAihhMUTu4nYiPSEUe9AUqGFKYbFItJUVVUmgtya5TmAJ61?= =?us-ascii?Q?tCrEwTSxR7atnt+d1krLchg0pnR86L3gUkr6J0H9UhrBp2N46CE7yqsTH2Ty?= =?us-ascii?Q?eIPR7SEcAK4/V/+sboEdmejGIZxLvD1JZI04PDchKyViBIS+uF6t9lYOS9i1?= =?us-ascii?Q?/Q=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: lb1+mjaiA1uGleO6p2mT3YMgKxUMrwX5I81oaQylzkdTQV6p9FYgd0UgytZwNHSSpHavpEez2TfgX0J5tH8/0RKKBiwYH5u7XBiwhEqIH9IyoNneDgKfop6aV0Vm/lE5mlbRrfRTL4MY+TASMy++q1aMPK/vTC/7Qb/p7RD/TwPugBJ5zRcODA7qrhLrWN4chW7guFsJenLWM+RYWZgVuyI+rbG8wHg9kJyh2scoKDfn+beHLfUj+ibnUC7HAfh5o/gc945OVOrqn9UmbkFGijThjYsQo20uAhS3WNIaJ2pWFVN3oHNF2uYfE6hdBdyD6HmTrk9/atbFm6d4x5s89mdGbQj4ZnuGSssY4cWKAHu4btsi7bykYt89s/40D/kRbr239Oyktff/f2Dzjv9auMxQCNZdYuQtXcd+rxc36vy0mkBh3MD+6Zk4Lxdqd4a2uW+OAIeSgSyIxC7KlXU/RBVjNv1c9XJehuezNhW07acXt2WTtFDiNsewQkHhORwVt13lX5La7/ObaVTOhzBjTUeLB9amsmN+7TXyldDdFLKsVnTzHJ2OOXVqJzpAXe9Q/WZAY9dnS/4L1DFB2Bg0FiO0K00lU2M7KVt0xxhVvPQ= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 03096584-038f-43fb-3d7c-08dd866952d2 X-MS-Exchange-CrossTenant-AuthSource: DM4PR10MB8218.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2025 15:28:27.7500 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 5TaZnu4x72GbLtA++5TRyk4MRVjwEHHMWxueciOkRZRGlElbTjt+P3jpYpCzAkSxt4asryvjV6qxWpkgLga46iATa69dSUzNj+3IXd4kjQQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB7223 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-04-28_06,2025-04-24_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 suspectscore=0 mlxscore=0 malwarescore=0 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2504070000 definitions=main-2504280127 X-Proofpoint-ORIG-GUID: tl38xZGTRQiQ8IvH5KqbvMCAhEbahX-J X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNDI4MDEyNyBTYWx0ZWRfX5FqujDFBNqH6 tF0OkNt9p212xring1WFvIt8CMuPy+H91q0b1THdN+/teXfcaLAABqFzATgFiLaHDePcMAMhMOR lRX9QZthAmUsJNBePfMm1LRmKdeZURhOeFEodjrDxNcEUNImix5z2kZvCm95ZxJchSjtPlk/UHJ q0IhxRPaGDMa6KICxU2zSkvEZxistoAU5kpd1EMAjV0nNmw3tYNtVdaqjfABdvmiH9iKZ4RO1Tl Pitu5nXxnbSLUWN4hFTt2tI73mvDRKzIxxI6jkwKViWKy0WO2kSouDs86AKTt9MsRJq3Gl1ZHfO YSa1zy8tpbM8RQWPxbwqB/1HE8g3acaQd2UXh8YEqFtmeNpcS1DqSrp06w0JGldVsztDv8ZURQP mex1I2ik X-Proofpoint-GUID: tl38xZGTRQiQ8IvH5KqbvMCAhEbahX-J Content-Type: text/plain; charset="utf-8" There are peculiarities within the kernel where what is very clearly mm code is performed elsewhere arbitrarily. This violates separation of concerns and makes it harder to refactor code to make changes to how fundamental initialisation and operation of mm logic is performed. One such case is the creation of the VMA containing the initial stack upon execve()'ing a new process. This is currently performed in __bprm_mm_init() in fs/exec.c. Abstract this operation to create_init_stack_vma(). This allows us to limit use of vma allocation and free code to fork and mm only. We previously did the same for the step at which we relocate the initial stack VMA downwards via relocate_vma_down(), now we move the initial VMA establishment too. Take the opportunity to also move insert_vm_struct() to mm/vma.c as it's no longer needed anywhere outside of mm. Signed-off-by: Lorenzo Stoakes Acked-by: David Hildenbrand Reviewed-by: Suren Baghdasaryan Reviewed-by: Kees Cook Reviewed-by: Liam R. Howlett Reviewed-by: Pedro Falcato Reviewed-by: Vlastimil Babka --- fs/exec.c | 66 +++--------------------------- mm/mmap.c | 42 ------------------- mm/vma.c | 43 ++++++++++++++++++++ mm/vma.h | 4 ++ mm/vma_exec.c | 69 ++++++++++++++++++++++++++++++++ tools/testing/vma/vma_internal.h | 32 +++++++++++++++ 6 files changed, 153 insertions(+), 103 deletions(-) diff --git a/fs/exec.c b/fs/exec.c index 477bc3f2e966..f9bbcf0016a4 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -245,60 +245,6 @@ static void flush_arg_page(struct linux_binprm *bprm, = unsigned long pos, flush_cache_page(bprm->vma, pos, page_to_pfn(page)); } =20 -static int __bprm_mm_init(struct linux_binprm *bprm) -{ - int err; - struct vm_area_struct *vma =3D NULL; - struct mm_struct *mm =3D bprm->mm; - - bprm->vma =3D vma =3D vm_area_alloc(mm); - if (!vma) - return -ENOMEM; - vma_set_anonymous(vma); - - if (mmap_write_lock_killable(mm)) { - err =3D -EINTR; - goto err_free; - } - - /* - * Need to be called with mmap write lock - * held, to avoid race with ksmd. - */ - err =3D ksm_execve(mm); - if (err) - goto err_ksm; - - /* - * Place the stack at the largest stack address the architecture - * supports. Later, we'll move this to an appropriate place. We don't - * use STACK_TOP because that can depend on attributes which aren't - * configured yet. - */ - BUILD_BUG_ON(VM_STACK_FLAGS & VM_STACK_INCOMPLETE_SETUP); - vma->vm_end =3D STACK_TOP_MAX; - vma->vm_start =3D vma->vm_end - PAGE_SIZE; - vm_flags_init(vma, VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SE= TUP); - vma->vm_page_prot =3D vm_get_page_prot(vma->vm_flags); - - err =3D insert_vm_struct(mm, vma); - if (err) - goto err; - - mm->stack_vm =3D mm->total_vm =3D 1; - mmap_write_unlock(mm); - bprm->p =3D vma->vm_end - sizeof(void *); - return 0; -err: - ksm_exit(mm); -err_ksm: - mmap_write_unlock(mm); -err_free: - bprm->vma =3D NULL; - vm_area_free(vma); - return err; -} - static bool valid_arg_len(struct linux_binprm *bprm, long len) { return len <=3D MAX_ARG_STRLEN; @@ -351,12 +297,6 @@ static void flush_arg_page(struct linux_binprm *bprm, = unsigned long pos, { } =20 -static int __bprm_mm_init(struct linux_binprm *bprm) -{ - bprm->p =3D PAGE_SIZE * MAX_ARG_PAGES - sizeof(void *); - return 0; -} - static bool valid_arg_len(struct linux_binprm *bprm, long len) { return len <=3D bprm->p; @@ -385,9 +325,13 @@ static int bprm_mm_init(struct linux_binprm *bprm) bprm->rlim_stack =3D current->signal->rlim[RLIMIT_STACK]; task_unlock(current->group_leader); =20 - err =3D __bprm_mm_init(bprm); +#ifndef CONFIG_MMU + bprm->p =3D PAGE_SIZE * MAX_ARG_PAGES - sizeof(void *); +#else + err =3D create_init_stack_vma(bprm->mm, &bprm->vma, &bprm->p); if (err) goto err; +#endif =20 return 0; =20 diff --git a/mm/mmap.c b/mm/mmap.c index 1794bf6f4dc0..9e09eac0021c 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1321,48 +1321,6 @@ void exit_mmap(struct mm_struct *mm) vm_unacct_memory(nr_accounted); } =20 -/* Insert vm structure into process list sorted by address - * and into the inode's i_mmap tree. If vm_file is non-NULL - * then i_mmap_rwsem is taken here. - */ -int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma) -{ - unsigned long charged =3D vma_pages(vma); - - - if (find_vma_intersection(mm, vma->vm_start, vma->vm_end)) - return -ENOMEM; - - if ((vma->vm_flags & VM_ACCOUNT) && - security_vm_enough_memory_mm(mm, charged)) - return -ENOMEM; - - /* - * The vm_pgoff of a purely anonymous vma should be irrelevant - * until its first write fault, when page's anon_vma and index - * are set. But now set the vm_pgoff it will almost certainly - * end up with (unless mremap moves it elsewhere before that - * first wfault), so /proc/pid/maps tells a consistent story. - * - * By setting it to reflect the virtual start address of the - * vma, merges and splits can happen in a seamless way, just - * using the existing file pgoff checks and manipulations. - * Similarly in do_mmap and in do_brk_flags. - */ - if (vma_is_anonymous(vma)) { - BUG_ON(vma->anon_vma); - vma->vm_pgoff =3D vma->vm_start >> PAGE_SHIFT; - } - - if (vma_link(mm, vma)) { - if (vma->vm_flags & VM_ACCOUNT) - vm_unacct_memory(charged); - return -ENOMEM; - } - - return 0; -} - /* * Return true if the calling process may expand its vm space by the passed * number of pages diff --git a/mm/vma.c b/mm/vma.c index 8a6c5e835759..1f2634b29568 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -3052,3 +3052,46 @@ int __vm_munmap(unsigned long start, size_t len, boo= l unlock) userfaultfd_unmap_complete(mm, &uf); return ret; } + + +/* Insert vm structure into process list sorted by address + * and into the inode's i_mmap tree. If vm_file is non-NULL + * then i_mmap_rwsem is taken here. + */ +int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma) +{ + unsigned long charged =3D vma_pages(vma); + + + if (find_vma_intersection(mm, vma->vm_start, vma->vm_end)) + return -ENOMEM; + + if ((vma->vm_flags & VM_ACCOUNT) && + security_vm_enough_memory_mm(mm, charged)) + return -ENOMEM; + + /* + * The vm_pgoff of a purely anonymous vma should be irrelevant + * until its first write fault, when page's anon_vma and index + * are set. But now set the vm_pgoff it will almost certainly + * end up with (unless mremap moves it elsewhere before that + * first wfault), so /proc/pid/maps tells a consistent story. + * + * By setting it to reflect the virtual start address of the + * vma, merges and splits can happen in a seamless way, just + * using the existing file pgoff checks and manipulations. + * Similarly in do_mmap and in do_brk_flags. + */ + if (vma_is_anonymous(vma)) { + BUG_ON(vma->anon_vma); + vma->vm_pgoff =3D vma->vm_start >> PAGE_SHIFT; + } + + if (vma_link(mm, vma)) { + if (vma->vm_flags & VM_ACCOUNT) + vm_unacct_memory(charged); + return -ENOMEM; + } + + return 0; +} diff --git a/mm/vma.h b/mm/vma.h index 1ce3e18f01b7..94307a2e4ab6 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -548,8 +548,12 @@ int expand_downwards(struct vm_area_struct *vma, unsig= ned long address); =20 int __vm_munmap(unsigned long start, size_t len, bool unlock); =20 +int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma); + /* vma_exec.h */ #ifdef CONFIG_MMU +int create_init_stack_vma(struct mm_struct *mm, struct vm_area_struct **vm= ap, + unsigned long *top_mem_p); int relocate_vma_down(struct vm_area_struct *vma, unsigned long shift); #endif =20 diff --git a/mm/vma_exec.c b/mm/vma_exec.c index 6736ae37f748..2dffb02ed6a2 100644 --- a/mm/vma_exec.c +++ b/mm/vma_exec.c @@ -90,3 +90,72 @@ int relocate_vma_down(struct vm_area_struct *vma, unsign= ed long shift) /* Shrink the vma to just the new range */ return vma_shrink(&vmi, vma, new_start, new_end, vma->vm_pgoff); } + +/* + * Establish the stack VMA in an execve'd process, located temporarily at = the + * maximum stack address provided by the architecture. + * + * We later relocate this downwards in relocate_vma_down(). + * + * This function is almost certainly NOT what you want for anything other = than + * early executable initialisation. + * + * On success, returns 0 and sets *vmap to the stack VMA and *top_mem_p to= the + * maximum addressable location in the stack (that is capable of storing a + * system word of data). + */ +int create_init_stack_vma(struct mm_struct *mm, struct vm_area_struct **vm= ap, + unsigned long *top_mem_p) +{ + int err; + struct vm_area_struct *vma =3D vm_area_alloc(mm); + + if (!vma) + return -ENOMEM; + + vma_set_anonymous(vma); + + if (mmap_write_lock_killable(mm)) { + err =3D -EINTR; + goto err_free; + } + + /* + * Need to be called with mmap write lock + * held, to avoid race with ksmd. + */ + err =3D ksm_execve(mm); + if (err) + goto err_ksm; + + /* + * Place the stack at the largest stack address the architecture + * supports. Later, we'll move this to an appropriate place. We don't + * use STACK_TOP because that can depend on attributes which aren't + * configured yet. + */ + BUILD_BUG_ON(VM_STACK_FLAGS & VM_STACK_INCOMPLETE_SETUP); + vma->vm_end =3D STACK_TOP_MAX; + vma->vm_start =3D vma->vm_end - PAGE_SIZE; + vm_flags_init(vma, VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SE= TUP); + vma->vm_page_prot =3D vm_get_page_prot(vma->vm_flags); + + err =3D insert_vm_struct(mm, vma); + if (err) + goto err; + + mm->stack_vm =3D mm->total_vm =3D 1; + mmap_write_unlock(mm); + *vmap =3D vma; + *top_mem_p =3D vma->vm_end - sizeof(void *); + return 0; + +err: + ksm_exit(mm); +err_ksm: + mmap_write_unlock(mm); +err_free: + *vmap =3D NULL; + vm_area_free(vma); + return err; +} diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_inter= nal.h index 0df19ca0000a..32e990313158 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -56,6 +56,8 @@ extern unsigned long dac_mmap_min_addr; #define VM_PFNMAP 0x00000400 #define VM_LOCKED 0x00002000 #define VM_IO 0x00004000 +#define VM_SEQ_READ 0x00008000 /* App will access data sequentially */ +#define VM_RAND_READ 0x00010000 /* App will not benefit from clustered rea= ds */ #define VM_DONTEXPAND 0x00040000 #define VM_LOCKONFAULT 0x00080000 #define VM_ACCOUNT 0x00100000 @@ -70,6 +72,20 @@ extern unsigned long dac_mmap_min_addr; #define VM_ACCESS_FLAGS (VM_READ | VM_WRITE | VM_EXEC) #define VM_SPECIAL (VM_IO | VM_DONTEXPAND | VM_PFNMAP | VM_MIXEDMAP) =20 +#ifdef CONFIG_STACK_GROWSUP +#define VM_STACK VM_GROWSUP +#define VM_STACK_EARLY VM_GROWSDOWN +#else +#define VM_STACK VM_GROWSDOWN +#define VM_STACK_EARLY 0 +#endif + +#define DEFAULT_MAP_WINDOW ((1UL << 47) - PAGE_SIZE) +#define TASK_SIZE_LOW DEFAULT_MAP_WINDOW +#define TASK_SIZE_MAX DEFAULT_MAP_WINDOW +#define STACK_TOP TASK_SIZE_LOW +#define STACK_TOP_MAX TASK_SIZE_MAX + /* This mask represents all the VMA flag bits used by mlock */ #define VM_LOCKED_MASK (VM_LOCKED | VM_LOCKONFAULT) =20 @@ -82,6 +98,10 @@ extern unsigned long dac_mmap_min_addr; =20 #define VM_STARTGAP_FLAGS (VM_GROWSDOWN | VM_SHADOW_STACK) =20 +#define VM_STACK_DEFAULT_FLAGS VM_DATA_DEFAULT_FLAGS +#define VM_STACK_FLAGS (VM_STACK | VM_STACK_DEFAULT_FLAGS | VM_ACCOUNT) +#define VM_STACK_INCOMPLETE_SETUP (VM_RAND_READ | VM_SEQ_READ | VM_STACK_E= ARLY) + #define RLIMIT_STACK 3 /* max stack size */ #define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ =20 @@ -1280,4 +1300,16 @@ static inline void free_pgd_range(struct mmu_gather = *tlb, (void)ceiling; } =20 +static inline int ksm_execve(struct mm_struct *mm) +{ + (void)mm; + + return 0; +} + +static inline void ksm_exit(struct mm_struct *mm) +{ + (void)mm; +} + #endif /* __MM_VMA_INTERNAL_H */ --=20 2.49.0 From nobody Fri Dec 19 02:49:23 2025 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B409C29D0D; Mon, 28 Apr 2025 15:31:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745854298; cv=fail; b=A1UBUcWjSpvcYokgZ4RiNKXghRP1DVRdWzGfnySTutKIyphG52G1gmxGrJHW7EKVuY2gwBKgO/+vhWPqz76r6eeDm935vw6YO7PqrLbQjuuR6XO+sJRx4+ilCfGb4fsKCp4vZBUkMObuFRaoAt97X5YLUO2g502IJZCJ40oxMs0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745854298; c=relaxed/simple; bh=G9q5fFpZt2w3BQVsbdUq1o5ggLEr3bJ5+C4V8/9veo4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=KesKbmwMF5QLAESwCcDW6pBrJoHPbJy+j1R6B0ERKf89hQkEDjTqORjQpnN95B+UE3VI0wRLEt5YgIwMVvS0bbQ7gQ2hxjREQodWUgbu5cFADwsNuQsNtt82ptXy14P6B7fsDGKBUOOTPUPmDInCNKjDIJlGcTpz9tvH2nDqszk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=PvmJOmON; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=kDqbEvSf; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="PvmJOmON"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="kDqbEvSf" Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53SFMtGv010745; Mon, 28 Apr 2025 15:31:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=qOX46yNSMPDy/eRyQ29rSt/JJQ4uQ8+t+Us6WQo3UR4=; b= PvmJOmONupaKEUMD9jfMm+m1fzS29eooK+/15ld0k34im3hVQLAQOejrPndJTnyB TVwo9wSGTq6DWI7x/kUSAd4+fOBf0Fjxu839I60DwQKjg6iCOZiucQ8e1GnlgfHg e+YghGcZczrZ3nTmq0mqUWa3P3ZWMEGNGzwXjfIxqUy78OFEpojoaa+nghwpOZ1X KXbBuXc+iRntQ9zGl6ompgIZvAUMSmUog5m+kK2fqUYF95pHdPc9n4CLi1Sayxb+ wCmEqQ83A5VYPsqMf333r2Eqed+F0edsXzVlejWq0IoYPLfb5dPRFlB4BcgcV9Ns iNIYi9XkzUdFwJyQgBsJ9A== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 46ac8f818h-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Apr 2025 15:31:21 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 53SE2Ij4007618; Mon, 28 Apr 2025 15:28:42 GMT Received: from sa9pr02cu001.outbound.protection.outlook.com (mail-southcentralusazlp17011029.outbound.protection.outlook.com [40.93.14.29]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 468nx8b3bp-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Apr 2025 15:28:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mqLrh03d4hnAcW0eZVS/hjFqtMXec1QsU0CYcLmhQytEFlIwdwIMogaiRc8iMDogRUo3N6fU0zDhf2AhgFcms71QmMjUKd2G5rm3sIdJCuXz4F986opelOnbDPfHj1BdZEkFSqKO4KzHoqrhF4E7tAD9HTYf1b3qxMSzjd1AZAmRlJcVoHdi47+b7OekmwVSgvMD7p2gAkmBK+dC6Vqyd8NgBNvTBtP7L2Q9nYyhyz9KEoiSGnFAn9eYXTypH2dlzAnTeJWvp04/rZoU1Gu+V2R0aFDJ0cJCt2/dbxzeWS/rCUMxDevAs6Mae226CSSyEsnmJuFFNniBKUN6Ycp2nw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qOX46yNSMPDy/eRyQ29rSt/JJQ4uQ8+t+Us6WQo3UR4=; b=q1zXHOt+PXFUngsB3DFfkFqYIYBcUYLt1rNZvXK3eMxJxg/BUr5jtT14hU/tPrV1DQ9tsgDhaIKR2pgLdSZF+Q4URs7NxKENDwbCMAVsoha6QnMmXhYlriO2gpAJ49AT6A+5BmmEQmXOTip4jbIwNUwP4ywmjeUdBGIBQtw9pX2xXzyjzGeQ/PQ9NYhbcGB7P2YxvsuZpysfIBlTVUcTdJUtjZUHjd0dCCs/7oHzBAm5e5Pu5nnxZZxthnyBMhHKnaEAbdKPsLtnFQ3G1yRMbpCkA2CfNDoaB6zBf/UodNEulzZjnLVLy9PTuheAkumtHAelkMnfjRpA8H6ozYryZQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qOX46yNSMPDy/eRyQ29rSt/JJQ4uQ8+t+Us6WQo3UR4=; b=kDqbEvSf/ZwX47Tx72wUqmcZsU2v/p8prkSUwwxALMZIKXBdhBIaqoSH0UpeZYFrUMSctQIQpm44AigDpVGAsl7+faSc6xyHH68uNEL5Eb5ZRCvQNffnnTG92YuOqC8N+sH7mRUUAcrOjxitNrV3yrV6MscdoMbhvkpZWQU5bCE= Received: from DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) by DS0PR10MB7223.namprd10.prod.outlook.com (2603:10b6:8:de::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8678.31; Mon, 28 Apr 2025 15:28:30 +0000 Received: from DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2]) by DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2%5]) with mapi id 15.20.8678.028; Mon, 28 Apr 2025 15:28:30 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , Pedro Falcato , David Hildenbrand , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Suren Baghdasaryan , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 3/4] mm: move dup_mmap() to mm Date: Mon, 28 Apr 2025 16:28:16 +0100 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO4P123CA0384.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18f::11) To DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR10MB8218:EE_|DS0PR10MB7223:EE_ X-MS-Office365-Filtering-Correlation-Id: acedf857-7abd-4845-4a9a-08dd86695454 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?FzMupjAeH75E1gwO0xdGFhL94WQaSFk7wPMMvgZsChDArvxTb9zIQMAyMCv6?= =?us-ascii?Q?1PYZC7KmorWNcbw8QFu6L47qQqVn+zLk8b5QVXB14+W5ABehQ8+ybqywElQJ?= =?us-ascii?Q?ytb45H8a79U9UIvl2MoEqErA5L3sa1WouXiUgm2hrUdCJdPCjG1Xs9oS7y6/?= =?us-ascii?Q?lAfMIVFU6ywaG95wtgZXVoN0mLu8r0Hc60ev05Rajy5PW7GTmrvpiK5j/aPF?= =?us-ascii?Q?wjt9MuY3XN6nHKJOuESCjfy/SIE/nqqN8smYeVjvQuJ7cdStJPAtesrZMd4A?= =?us-ascii?Q?q+VJxYRMgXj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b1g4?= =?us-ascii?Q?BOZ/aCKFR7uq203ZzrAPRSMNBafmxoRI9nRYg6TCvZIMEOiTVf8+cqFgx/Bt?= =?us-ascii?Q?Gjh5fh316fRp2zB5/qzOgwpbetM/Je4KMSrYqey+l6fjl+c62fzcYqHR6jDw?= =?us-ascii?Q?Dt8WmFZa0+Pm1/MJs64DT8ViLz8f1WPthr/A2wo19Y/DbepFinx5x7KtNIWX?= =?us-ascii?Q?YmFr5Z6xkNgeglQgOjoxDfmmBIr3drPDcQCxRZB4Oz2hPfacCw=3D=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR10MB8218.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?L4g0gQPPJa+W8O4VW7jkEmlk/QCbuaQanbVhTomi1HzAHa0guBfImTjwpZp6?= =?us-ascii?Q?N7N+sf8IkfmffcsU1u1/ZlkLfGn9YyqgzYEjpwJKM0mS1vTy9lgBC6AxxMTE?= =?us-ascii?Q?+5DCOtaqF9pe1N5s3HC/73b/wi04anOLrG1/2NvQKEJRzrChFzTzQk2Qa5En?= =?us-ascii?Q?IrSKlpWmRwpyUGfA2/SvQ6J3zPjHYXGEGHurMDMyeHGKgI0N5tfB2NJ6kakR?= =?us-ascii?Q?xfwYrElQ8wXS2AWMmeI4E5PLScAaTr1OedPnUHhzspdxs4CpB7jGa4Gc4WSM?= =?us-ascii?Q?Wpn83ZtJsA7wd8ZemlUhkYKY+QLav8wrSa6TUU7qan/iVpJTikjeX4+zOBTZ?= =?us-ascii?Q?N5DAFzZ6S0QvOZRxbbLKZrHMIA0cXcoqPmm/MqT/dlayY/Iedm5naP6NV6SY?= =?us-ascii?Q?h+wm9BvBUYQQUw0HnwJFM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UAzS8/CE1Q/V+kzktWn1GC4A= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: acedf857-7abd-4845-4a9a-08dd86695454 X-MS-Exchange-CrossTenant-AuthSource: DM4PR10MB8218.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2025 15:28:30.2772 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: +iJS+dAHGbKLVhiNZ14wWUvClZ4JdugyhULu+0NuhJMPbfR/yzxy6IuNiNyPGrSVSeVrTrV5DumpVe28XzPHRZ7PCtJ7FcFNkXKH3y25VYM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB7223 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-04-28_06,2025-04-24_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 suspectscore=0 mlxscore=0 malwarescore=0 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2504070000 definitions=main-2504280127 X-Proofpoint-GUID: fVCGq3jtu3WSxiluT2AF6nTYElMh9-Og X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNDI4MDEyNyBTYWx0ZWRfX+dSicsMy7XpD XSnAJuiWDIltZ/aic/EgpH8XRV87ukVobvBhQq4NaNYlDmg11MebgGm1UDgTYrJbdxFXlWZYBWB OKSkW/w8iUwYfmuo52kNWgRpl36DdHNXtSYkO4R8tvAHYDZTy/QSfqkrXCBEPOXNlDEaaPrVfr7 DD95owuZvFWlu6RAQuqo603Wv8Q2vHRxpln4G2S43SxDvMGKQLCI5v+kOvMFAe2os9P3V8HuHku NORuy92Iol2aQ5TyAIKYB0fRSFBtq/JyXyI+6X59m7GcYHsPxdU5pNZraEDdvtOfxSDKtkvVLFl dmxCLqVG950BY7N+BH7BPtw5iePs8d9U4TxPRYTyYDIrgb1WaPB+b6hx0qAAN/oZtctzHbQSKqB cMD8n4AY X-Proofpoint-ORIG-GUID: fVCGq3jtu3WSxiluT2AF6nTYElMh9-Og Content-Type: text/plain; charset="utf-8" This is a key step in our being able to abstract and isolate VMA allocation and destruction logic. This function is the last one where vm_area_free() and vm_area_dup() are directly referenced outside of mmap, so having this in mm allows us to isolate these. We do the same for the nommu version which is substantially simpler. We place the declaration for dup_mmap() in mm/internal.h and have kernel/fork.c import this in order to prevent improper use of this functionality elsewhere in the kernel. While we're here, we remove the useless #ifdef CONFIG_MMU check around mmap_read_lock_maybe_expand() in mmap.c, mmap.c is compiled only if CONFIG_MMU is set. Signed-off-by: Lorenzo Stoakes Suggested-by: Pedro Falcato Reviewed-by: Pedro Falcato Reviewed-by: David Hildenbrand Reviewed-by: Kees Cook Reviewed-by: Liam R. Howlett Reviewed-by: Suren Baghdasaryan Reviewed-by: Vlastimil Babka --- kernel/fork.c | 189 ++------------------------------------------------ mm/internal.h | 2 + mm/mmap.c | 181 +++++++++++++++++++++++++++++++++++++++++++++-- mm/nommu.c | 8 +++ 4 files changed, 189 insertions(+), 191 deletions(-) diff --git a/kernel/fork.c b/kernel/fork.c index 168681fc4b25..ac9f9267a473 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -112,6 +112,9 @@ #include #include =20 +/* For dup_mmap(). */ +#include "../mm/internal.h" + #include =20 #define CREATE_TRACE_POINTS @@ -589,7 +592,7 @@ void free_task(struct task_struct *tsk) } EXPORT_SYMBOL(free_task); =20 -static void dup_mm_exe_file(struct mm_struct *mm, struct mm_struct *oldmm) +void dup_mm_exe_file(struct mm_struct *mm, struct mm_struct *oldmm) { struct file *exe_file; =20 @@ -604,183 +607,6 @@ static void dup_mm_exe_file(struct mm_struct *mm, str= uct mm_struct *oldmm) } =20 #ifdef CONFIG_MMU -static __latent_entropy int dup_mmap(struct mm_struct *mm, - struct mm_struct *oldmm) -{ - struct vm_area_struct *mpnt, *tmp; - int retval; - unsigned long charge =3D 0; - LIST_HEAD(uf); - VMA_ITERATOR(vmi, mm, 0); - - if (mmap_write_lock_killable(oldmm)) - return -EINTR; - flush_cache_dup_mm(oldmm); - uprobe_dup_mmap(oldmm, mm); - /* - * Not linked in yet - no deadlock potential: - */ - mmap_write_lock_nested(mm, SINGLE_DEPTH_NESTING); - - /* No ordering required: file already has been exposed. */ - dup_mm_exe_file(mm, oldmm); - - mm->total_vm =3D oldmm->total_vm; - mm->data_vm =3D oldmm->data_vm; - mm->exec_vm =3D oldmm->exec_vm; - mm->stack_vm =3D oldmm->stack_vm; - - /* Use __mt_dup() to efficiently build an identical maple tree. */ - retval =3D __mt_dup(&oldmm->mm_mt, &mm->mm_mt, GFP_KERNEL); - if (unlikely(retval)) - goto out; - - mt_clear_in_rcu(vmi.mas.tree); - for_each_vma(vmi, mpnt) { - struct file *file; - - vma_start_write(mpnt); - if (mpnt->vm_flags & VM_DONTCOPY) { - retval =3D vma_iter_clear_gfp(&vmi, mpnt->vm_start, - mpnt->vm_end, GFP_KERNEL); - if (retval) - goto loop_out; - - vm_stat_account(mm, mpnt->vm_flags, -vma_pages(mpnt)); - continue; - } - charge =3D 0; - /* - * Don't duplicate many vmas if we've been oom-killed (for - * example) - */ - if (fatal_signal_pending(current)) { - retval =3D -EINTR; - goto loop_out; - } - if (mpnt->vm_flags & VM_ACCOUNT) { - unsigned long len =3D vma_pages(mpnt); - - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */ - goto fail_nomem; - charge =3D len; - } - tmp =3D vm_area_dup(mpnt); - if (!tmp) - goto fail_nomem; - - /* track_pfn_copy() will later take care of copying internal state. */ - if (unlikely(tmp->vm_flags & VM_PFNMAP)) - untrack_pfn_clear(tmp); - - retval =3D vma_dup_policy(mpnt, tmp); - if (retval) - goto fail_nomem_policy; - tmp->vm_mm =3D mm; - retval =3D dup_userfaultfd(tmp, &uf); - if (retval) - goto fail_nomem_anon_vma_fork; - if (tmp->vm_flags & VM_WIPEONFORK) { - /* - * VM_WIPEONFORK gets a clean slate in the child. - * Don't prepare anon_vma until fault since we don't - * copy page for current vma. - */ - tmp->anon_vma =3D NULL; - } else if (anon_vma_fork(tmp, mpnt)) - goto fail_nomem_anon_vma_fork; - vm_flags_clear(tmp, VM_LOCKED_MASK); - /* - * Copy/update hugetlb private vma information. - */ - if (is_vm_hugetlb_page(tmp)) - hugetlb_dup_vma_private(tmp); - - /* - * Link the vma into the MT. After using __mt_dup(), memory - * allocation is not necessary here, so it cannot fail. - */ - vma_iter_bulk_store(&vmi, tmp); - - mm->map_count++; - - if (tmp->vm_ops && tmp->vm_ops->open) - tmp->vm_ops->open(tmp); - - file =3D tmp->vm_file; - if (file) { - struct address_space *mapping =3D file->f_mapping; - - get_file(file); - i_mmap_lock_write(mapping); - if (vma_is_shared_maywrite(tmp)) - mapping_allow_writable(mapping); - flush_dcache_mmap_lock(mapping); - /* insert tmp into the share list, just after mpnt */ - vma_interval_tree_insert_after(tmp, mpnt, - &mapping->i_mmap); - flush_dcache_mmap_unlock(mapping); - i_mmap_unlock_write(mapping); - } - - if (!(tmp->vm_flags & VM_WIPEONFORK)) - retval =3D copy_page_range(tmp, mpnt); - - if (retval) { - mpnt =3D vma_next(&vmi); - goto loop_out; - } - } - /* a new mm has just been created */ - retval =3D arch_dup_mmap(oldmm, mm); -loop_out: - vma_iter_free(&vmi); - if (!retval) { - mt_set_in_rcu(vmi.mas.tree); - ksm_fork(mm, oldmm); - khugepaged_fork(mm, oldmm); - } else { - - /* - * The entire maple tree has already been duplicated. If the - * mmap duplication fails, mark the failure point with - * XA_ZERO_ENTRY. In exit_mmap(), if this marker is encountered, - * stop releasing VMAs that have not been duplicated after this - * point. - */ - if (mpnt) { - mas_set_range(&vmi.mas, mpnt->vm_start, mpnt->vm_end - 1); - mas_store(&vmi.mas, XA_ZERO_ENTRY); - /* Avoid OOM iterating a broken tree */ - set_bit(MMF_OOM_SKIP, &mm->flags); - } - /* - * The mm_struct is going to exit, but the locks will be dropped - * first. Set the mm_struct as unstable is advisable as it is - * not fully initialised. - */ - set_bit(MMF_UNSTABLE, &mm->flags); - } -out: - mmap_write_unlock(mm); - flush_tlb_mm(oldmm); - mmap_write_unlock(oldmm); - if (!retval) - dup_userfaultfd_complete(&uf); - else - dup_userfaultfd_fail(&uf); - return retval; - -fail_nomem_anon_vma_fork: - mpol_put(vma_policy(tmp)); -fail_nomem_policy: - vm_area_free(tmp); -fail_nomem: - retval =3D -ENOMEM; - vm_unacct_memory(charge); - goto loop_out; -} - static inline int mm_alloc_pgd(struct mm_struct *mm) { mm->pgd =3D pgd_alloc(mm); @@ -794,13 +620,6 @@ static inline void mm_free_pgd(struct mm_struct *mm) pgd_free(mm, mm->pgd); } #else -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) -{ - mmap_write_lock(oldmm); - dup_mm_exe_file(mm, oldmm); - mmap_write_unlock(oldmm); - return 0; -} #define mm_alloc_pgd(mm) (0) #define mm_free_pgd(mm) #endif /* CONFIG_MMU */ diff --git a/mm/internal.h b/mm/internal.h index 40464f755092..b3e011976f74 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -1631,5 +1631,7 @@ static inline bool reclaim_pt_is_enabled(unsigned lon= g start, unsigned long end, } #endif /* CONFIG_PT_RECLAIM */ =20 +void dup_mm_exe_file(struct mm_struct *mm, struct mm_struct *oldmm); +int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm); =20 #endif /* __MM_INTERNAL_H */ diff --git a/mm/mmap.c b/mm/mmap.c index 9e09eac0021c..5259df031e15 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1675,7 +1675,6 @@ static int __meminit init_reserve_notifier(void) } subsys_initcall(init_reserve_notifier); =20 -#ifdef CONFIG_MMU /* * Obtain a read lock on mm->mmap_lock, if the specified address is below = the * start of the VMA, the intent is to perform a write, and it is a @@ -1719,10 +1718,180 @@ bool mmap_read_lock_maybe_expand(struct mm_struct = *mm, mmap_write_downgrade(mm); return true; } -#else -bool mmap_read_lock_maybe_expand(struct mm_struct *mm, struct vm_area_stru= ct *vma, - unsigned long addr, bool write) + +__latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldm= m) { - return false; + struct vm_area_struct *mpnt, *tmp; + int retval; + unsigned long charge =3D 0; + LIST_HEAD(uf); + VMA_ITERATOR(vmi, mm, 0); + + if (mmap_write_lock_killable(oldmm)) + return -EINTR; + flush_cache_dup_mm(oldmm); + uprobe_dup_mmap(oldmm, mm); + /* + * Not linked in yet - no deadlock potential: + */ + mmap_write_lock_nested(mm, SINGLE_DEPTH_NESTING); + + /* No ordering required: file already has been exposed. */ + dup_mm_exe_file(mm, oldmm); + + mm->total_vm =3D oldmm->total_vm; + mm->data_vm =3D oldmm->data_vm; + mm->exec_vm =3D oldmm->exec_vm; + mm->stack_vm =3D oldmm->stack_vm; + + /* Use __mt_dup() to efficiently build an identical maple tree. */ + retval =3D __mt_dup(&oldmm->mm_mt, &mm->mm_mt, GFP_KERNEL); + if (unlikely(retval)) + goto out; + + mt_clear_in_rcu(vmi.mas.tree); + for_each_vma(vmi, mpnt) { + struct file *file; + + vma_start_write(mpnt); + if (mpnt->vm_flags & VM_DONTCOPY) { + retval =3D vma_iter_clear_gfp(&vmi, mpnt->vm_start, + mpnt->vm_end, GFP_KERNEL); + if (retval) + goto loop_out; + + vm_stat_account(mm, mpnt->vm_flags, -vma_pages(mpnt)); + continue; + } + charge =3D 0; + /* + * Don't duplicate many vmas if we've been oom-killed (for + * example) + */ + if (fatal_signal_pending(current)) { + retval =3D -EINTR; + goto loop_out; + } + if (mpnt->vm_flags & VM_ACCOUNT) { + unsigned long len =3D vma_pages(mpnt); + + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */ + goto fail_nomem; + charge =3D len; + } + + tmp =3D vm_area_dup(mpnt); + if (!tmp) + goto fail_nomem; + + /* track_pfn_copy() will later take care of copying internal state. */ + if (unlikely(tmp->vm_flags & VM_PFNMAP)) + untrack_pfn_clear(tmp); + + retval =3D vma_dup_policy(mpnt, tmp); + if (retval) + goto fail_nomem_policy; + tmp->vm_mm =3D mm; + retval =3D dup_userfaultfd(tmp, &uf); + if (retval) + goto fail_nomem_anon_vma_fork; + if (tmp->vm_flags & VM_WIPEONFORK) { + /* + * VM_WIPEONFORK gets a clean slate in the child. + * Don't prepare anon_vma until fault since we don't + * copy page for current vma. + */ + tmp->anon_vma =3D NULL; + } else if (anon_vma_fork(tmp, mpnt)) + goto fail_nomem_anon_vma_fork; + vm_flags_clear(tmp, VM_LOCKED_MASK); + /* + * Copy/update hugetlb private vma information. + */ + if (is_vm_hugetlb_page(tmp)) + hugetlb_dup_vma_private(tmp); + + /* + * Link the vma into the MT. After using __mt_dup(), memory + * allocation is not necessary here, so it cannot fail. + */ + vma_iter_bulk_store(&vmi, tmp); + + mm->map_count++; + + if (tmp->vm_ops && tmp->vm_ops->open) + tmp->vm_ops->open(tmp); + + file =3D tmp->vm_file; + if (file) { + struct address_space *mapping =3D file->f_mapping; + + get_file(file); + i_mmap_lock_write(mapping); + if (vma_is_shared_maywrite(tmp)) + mapping_allow_writable(mapping); + flush_dcache_mmap_lock(mapping); + /* insert tmp into the share list, just after mpnt */ + vma_interval_tree_insert_after(tmp, mpnt, + &mapping->i_mmap); + flush_dcache_mmap_unlock(mapping); + i_mmap_unlock_write(mapping); + } + + if (!(tmp->vm_flags & VM_WIPEONFORK)) + retval =3D copy_page_range(tmp, mpnt); + + if (retval) { + mpnt =3D vma_next(&vmi); + goto loop_out; + } + } + /* a new mm has just been created */ + retval =3D arch_dup_mmap(oldmm, mm); +loop_out: + vma_iter_free(&vmi); + if (!retval) { + mt_set_in_rcu(vmi.mas.tree); + ksm_fork(mm, oldmm); + khugepaged_fork(mm, oldmm); + } else { + + /* + * The entire maple tree has already been duplicated. If the + * mmap duplication fails, mark the failure point with + * XA_ZERO_ENTRY. In exit_mmap(), if this marker is encountered, + * stop releasing VMAs that have not been duplicated after this + * point. + */ + if (mpnt) { + mas_set_range(&vmi.mas, mpnt->vm_start, mpnt->vm_end - 1); + mas_store(&vmi.mas, XA_ZERO_ENTRY); + /* Avoid OOM iterating a broken tree */ + set_bit(MMF_OOM_SKIP, &mm->flags); + } + /* + * The mm_struct is going to exit, but the locks will be dropped + * first. Set the mm_struct as unstable is advisable as it is + * not fully initialised. + */ + set_bit(MMF_UNSTABLE, &mm->flags); + } +out: + mmap_write_unlock(mm); + flush_tlb_mm(oldmm); + mmap_write_unlock(oldmm); + if (!retval) + dup_userfaultfd_complete(&uf); + else + dup_userfaultfd_fail(&uf); + return retval; + +fail_nomem_anon_vma_fork: + mpol_put(vma_policy(tmp)); +fail_nomem_policy: + vm_area_free(tmp); +fail_nomem: + retval =3D -ENOMEM; + vm_unacct_memory(charge); + goto loop_out; } -#endif diff --git a/mm/nommu.c b/mm/nommu.c index 2b4d304c6445..a142fc258d39 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -1874,3 +1874,11 @@ static int __meminit init_admin_reserve(void) return 0; } subsys_initcall(init_admin_reserve); + +int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm) +{ + mmap_write_lock(oldmm); + dup_mm_exe_file(mm, oldmm); + mmap_write_unlock(oldmm); + return 0; +} --=20 2.49.0 From nobody Fri Dec 19 02:49:23 2025 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4257C170826; Mon, 28 Apr 2025 15:32:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.177.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745854328; cv=fail; b=bksmmMcdm7G2KejEsHX9tYqYSjRpOMvyjjmDMk+IidrWYXTlGazkSpxknCSk7SKIRMbXmjtGrdbfLUf8nqB09CqvPwvqr3qpfly3zeylN8+KhJkLDh5Tpwg31jUZFNKPnLKy+ielHbkcCzk84dkIps+Iq4kWfhbeoV0IhdnwQ8w= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745854328; c=relaxed/simple; bh=HMfAYsOOpS1ptacbrKjNG3535P2IkqLKtXUtXX52Axo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=lbcafjWvrj4CgpVU4IkSC0kJMLaWKXd2fRHLBZHYlgi1HcvkB6FNW29y1niufmJLxvVyPvoLqMa0ADDwG9Vs8uUvhEgJlJyOvG++Uxno17W9HHSvLKCp5bNSuN08eoUZtFjM76xUR5NAfC55wUwAD7o6EY/EBjUIieP/bamElzU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=P9L/+fh4; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=LuGsvJXl; arc=fail smtp.client-ip=205.220.177.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="P9L/+fh4"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="LuGsvJXl" Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 53SFMufc010772; Mon, 28 Apr 2025 15:31:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=6SEpk+QPFmrzZJxC+PZbcE5Tvj9QobanAltJInJEGFw=; b= P9L/+fh4Sph182tLVFNdp6x1S4ChjYo9V+rt3snZ4OQxt8D5xw5MssEQfPok0Tua 0aCR8LfKBmeMOb5pWlNJZt7drRVrqQp+Y/t2/B441w2TmCcs0Z+43/XV6OLWz78O 7KK/xIl0GTAOKwO+yeZ3aaeb2IsFDh5Hn0edeqwa6YaTnyE70ijz5yCbFZHSw69g z6Qm3EaQFkFccghwIvkG3ntv4HsMlJZ0G6pV9vBML9BeqjScRk1AaeMHFl7uHPZ6 EaaxT6lI+ot9/LheZkdUyLgdcksGMW0lUb8pOBnY9fU8ulIzHGUIi1Q1HOEQ3jjW XmEgqe3dsLkHrd7nnyDtsw== Received: from iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta02.appoci.oracle.com [147.154.18.20]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 46ac8f818g-36 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Apr 2025 15:31:52 +0000 (GMT) Received: from pps.filterd (iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 53SE2Ij5007618; Mon, 28 Apr 2025 15:28:47 GMT Received: from sa9pr02cu001.outbound.protection.outlook.com (mail-southcentralusazlp17011029.outbound.protection.outlook.com [40.93.14.29]) by iadpaimrmta02.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 468nx8b3bp-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Apr 2025 15:28:45 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=aDuqCtff/nl1vtydJDBOuOjEHOaIjD7OM+/RmkhuCWBK6oSj05gqzCseATJ9U2/WqntQHlR8hd51o1XZfodo545RKpAYVcdKKXyZRN8+SIBLkfLBs4l/kqID9nWZAE10kizgl6qvgZ/gfZliSrak/WBxrgA7VU4WEQLp2Q3LUJCbhwiyvB6YKLp9dtMYWgiCFNvX6xTkj1qs8cFfKkSb4vT5jH8J3EqOJn6qf/5Jdplsp4bQSJSyWk5fHNuUUyzm+4EcUOsd6zoxG+vr7CYSxzhPvCxL4LyOHJ8AQMOzqZ1AsXEhTH2kkFUT6+ZDkYup3Ny93B5Fwxtf9S/XKMJQzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=6SEpk+QPFmrzZJxC+PZbcE5Tvj9QobanAltJInJEGFw=; b=gqhqt3yxWwQQWyMhK75t6trXS0jBYjFUYzYq9sWxoxIMwtnFReJULB+w4icpZGZbMBH5Z7F++08IX/acrxhQo0mN+3YlJGFrbw/DuNKXwcdEw4sASGfQsL7IGa35+qmPNL61Wc1bN/aZSVtWCO2n+ylr1TPqmGIh3ZTdC04qVuJJBSisMK7l5QB+6M5qFaIm6aXyS/YpL3Oob0866eNZXZCWSsTT6o7t69LahbxqHwLFQvEAeprT4d1XHHb74gN42fhFhPsdjN674fJd2TjSW7Ii25ldIoIbAjej+C8+zpMrMFPZTnbTfNhgbcu6QckEFc+g5BRfg3OBTscBtTBlsQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oracle.com; dmarc=pass action=none header.from=oracle.com; dkim=pass header.d=oracle.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.onmicrosoft.com; s=selector2-oracle-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=6SEpk+QPFmrzZJxC+PZbcE5Tvj9QobanAltJInJEGFw=; b=LuGsvJXlDrcC7NXiAs22SHnKWJ/1fdtffK0YTMmCGxZ3IaPS1C7ph74tZoOX6TNNi7NklJ+rEiUgUJD2FvFHW2bIAVuuCGKJqVF4p4iE/3o1wHHwD2duH9fIU7eoTPTpZuSokP3sEErPabQZkvivm2udfKFARcV6yQ5Ietmjo20= Received: from DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) by DS0PR10MB7223.namprd10.prod.outlook.com (2603:10b6:8:de::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8678.31; Mon, 28 Apr 2025 15:28:32 +0000 Received: from DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2]) by DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2%5]) with mapi id 15.20.8678.028; Mon, 28 Apr 2025 15:28:32 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , Pedro Falcato , David Hildenbrand , Kees Cook , Alexander Viro , Christian Brauner , Jan Kara , Suren Baghdasaryan , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 4/4] mm: perform VMA allocation, freeing, duplication in mm Date: Mon, 28 Apr 2025 16:28:17 +0100 Message-ID: X-Mailer: git-send-email 2.49.0 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO6P123CA0033.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:2fe::6) To DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DM4PR10MB8218:EE_|DS0PR10MB7223:EE_ X-MS-Office365-Filtering-Correlation-Id: 74261ddb-a0a4-47d1-2c7f-08dd866955c8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|376014|366016|7416014; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?6+0xn3YFuERchfDIA7OrYRb8HrbfAmrM+4KVdxTSBrvKUueGrP0OyC0W9DvB?= =?us-ascii?Q?Tea89Yv2ff4K0g00o3mbUO5v/rustqLVxwNjR9KE+p9mneau17zYXKkYdY8/?= =?us-ascii?Q?TCbDWH8654V2iGLrZcoV3WbnW2LdI9oIQ0t1yTZ9LvFaWqd+blimHKiRhwQq?= =?us-ascii?Q?HZhgXS86ivLCAAqcLH8riafNs3y6rXZlQnIoqSCTo0k1bfRH9l8uDiSuKqWC?= =?us-ascii?Q?9Kg7gWbwTp1VpT3ttCrdde86AQfHcPTSYhGJK5NcOqPsjzkrT0lCRV6OdNu+?= =?us-ascii?Q?zDZ7vYoTAtZfxBegciUMuInfppVF2O8LQGCP15M8i7QsWJ3DfVBiuFE8Z5kA?= =?us-ascii?Q?zBjcUUR/AiuuEvvcZ3W4Uel1e2Nx3hGIfRx/mhlIax6V/Dw5YFuawammgsMR?= =?us-ascii?Q?3N3+RmrEPMMJ37D6mnAB/x5ox239/6MyjiInxYxq+uhD5zXEhPVPDfuqYTpB?= =?us-ascii?Q?1Rn45dvQGIHnxaGJGUHn2uVBwcNKPMUMu+stHL6hlfP7kND6Q0mZL29PsUP/?= =?us-ascii?Q?5Y3kiVQGLfsXABDGpalsE5g/GkkTm6Nb/dTHWEBrnIr8JL/gMs+1wQapM+4n?= =?us-ascii?Q?+/NEV88nuyDzwcRt3OTDFVcoGtphpceR3N0H8L6+yVvU/qYTYiOoWsxC+NRm?= =?us-ascii?Q?cTEw9RK/41hFC9VajyvloymmBoEpkG0i9W58P28Peekio0FJHHh3flIFK4r9?= =?us-ascii?Q?YADejKrgLorKVoqFWE1FFLR1xshsRp08V+MjqPQQTwB3hL0r7R/eqXCEnhZ0?= =?us-ascii?Q?tkV88No2T8X58/GwpeWAo7ZldKppRIr1smVX0i1T+so5ozNNX7Uou8Ygmsm1?= =?us-ascii?Q?32J1+7hiVFnZrbPt5z+y0MeeJd4rTHnnN7PAdCxZwXIsVKtIqhfc1q4X1xEW?= =?us-ascii?Q?vSn/GP2bIpwvX1C/Ve0nu7cMKUVVIO8p76pD6JY6k0TJuy0L1Biom/bqcSpj?= =?us-ascii?Q?igCTDfGrmDjMX9Y7LduMRNyC3Tq2NmlzJH2VXwma+pbIg2ABfY60oytLXxLw?= =?us-ascii?Q?w8jGD8/ijrP7MsDFnFdqCPfJq9OmGOKAdaLL8VFjFDgju/FZ+Z+12Jv71bLR?= =?us-ascii?Q?cVxrXdqaaQiQXPE4rsDq7bV3WF4WZK7wIVEoUYdNvOe3sIgzzEgUASAyr06w?= =?us-ascii?Q?GTyDAJlccUZF08hQ0qNDb+a5WyNyCu6lhPVf/ebG5YL+SArkK9ktSQkyvInc?= =?us-ascii?Q?vBT+XGsIo88v/o2+azIXgrhl/siAp2+Gi/coDxTB0u7LjyYIbeQU/LvJgy+z?= =?us-ascii?Q?vWnHyGxbju8vEx/q96H7TRni4r/DBNJjs+yT0l6smiirWBsRo3Wv77410076?= =?us-ascii?Q?3ZKltgUTlRRGiAK0ZdUN8J5w2NxEWT3Yrpnrb+TrOEZTXL7KHFQuV8ntJ5HM?= =?us-ascii?Q?naASWAU/lZkSuEodxwfLtN12voPtoIXnPS4/M7gSPtXXyS33oYwxGLH+UWUz?= =?us-ascii?Q?1awKnvZzGs0=3D?= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR10MB8218.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(376014)(366016)(7416014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Goaf4kux1WCOKBpvI+2YGBuGM48Gx961HFNSYsI6C3J/8EAQtp9ywfLrTyh4?= =?us-ascii?Q?Q3aWg0ccaJQoFrTvRmnCrGJ4QV8NyKnep81PfSjYb11hOcugK14P9bGCSXLT?= =?us-ascii?Q?cYiL7qkbH8rvIiTqRf5nV5m0ZvAhRyzPQvMs84E9pb4PrTjk6LVZ6eJDJ9DD?= =?us-ascii?Q?K12K1+nSUT01oI6Pl5tcXN2uZS+nqT+3c0qK69WtN8kYmJhVdrS6ZI1gGxie?= =?us-ascii?Q?DIMIwYWbJVOJfaYQoWYDKluNhoBEImpeDL7dxCMFfD/M3ENiTWLrPbL/XI0W?= =?us-ascii?Q?aozd9++smptwYp7AHLg3yi4HaTo+EaZMgv9uTt0K9Tu0jaAQwhlRFhx4mCgq?= =?us-ascii?Q?s1pYfCLYp530A1QM6+COuZ8ZCz1oQL6ntoZyF6+HY7u2GjoBu369mhk4A7xv?= =?us-ascii?Q?E3eDMnQG86oZWkM4lJ0UVAKEoYrOZBYQaYUKmOownpvEY8qY8kTu4fMSS2LL?= =?us-ascii?Q?NPcf0F3xAr6ga0uD+zLrqpcO6GlBc4gKy9AIJjJl+2YXjKYm85m6yTa72qRN?= =?us-ascii?Q?78aGAhnZ/uFFWNnqP8UnC1MSKW0yiLqID6fkHLr6YOF/jS1CbTABG9FYZLuu?= =?us-ascii?Q?I0+Mp3GQbjA5sXmEtfIBXAA3ugS2WRqYPAtPVXZQQLxYd3k4wegovgpvvH/f?= =?us-ascii?Q?zCXy6F0FyvWk96vHRrDSFnBO3sUuexmRy+ITcqnufoq+UqYBCycQ9mAgXGUG?= =?us-ascii?Q?uB1dQ0UqXPPyuj9hUFhRRMfHXK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= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: jZTBPQAeiZlklbhX7PB6+VMrk+TiUgdRX6bwJ0+l3Qs7XkSUe4WZ7p4Vwmsl5Dz459Rt8OImB8P89kqs5XA+Y/7G8VfavSuNuM80pCqv+Lc7+73TgL3EHD2MrTf/gePTrQeXcHQjY/Rq+inKNbQvdBSmJaKI4Y1+JfcDExPmnVtQWMZdp8lJpIX0pvs2iUXBWUMr+xY/KqZn1aJ+Gq4vCpGwjQpeln5Y7ZX0CaiS2I8oEyv/pymCTx0bXvs6iXC1VgMClrJDCNnsZcOaWibrn6NtRTilFPM36REZUE647frJal/BulgJDQVKYKx6BJ5+k4T+rN+azQPGIxRRHs/t14ovslLr47J8reWIp6UfOU3Rb8Rvisc6YOxFaNQ63814+5kBocemfHtlVzDVcl/0I0XSEmTQW8bzAhfVibrlNzKPsyIt5A/h48N7WdwiL07lllmFC8/kr3l6fvKNvKub4+G9y6HdpgQojZKdir2jYv3FFitMNTaHSGaoH/yvIew3/NOgC+VBwnx/NKqu1tj9z3n5Lgq2ME4Mehymhu/Xh8Pdbsh7dWDyff7i5ujhaDW0KwxMohS+gYpuHM5tqt27pXVZhwVjz3OqjSYBoIkAdIk= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 74261ddb-a0a4-47d1-2c7f-08dd866955c8 X-MS-Exchange-CrossTenant-AuthSource: DM4PR10MB8218.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Apr 2025 15:28:32.7789 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 4e2c6054-71cb-48f1-bd6c-3a9705aca71b X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 3QwRMai9iEJdzjNr9Mis1kbuDw3UX1NFP5as4RjXSjju9pLgRWCLUw1c4eSofVdrnFAtE+k1pARblTxNprP9GyYHRMc2Rf1QRVObDJtew9U= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR10MB7223 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.0.736,FMLib:17.12.80.40 definitions=2025-04-28_06,2025-04-24_02,2025-02-21_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxlogscore=999 phishscore=0 suspectscore=0 mlxscore=0 malwarescore=0 adultscore=0 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2504070000 definitions=main-2504280127 X-Proofpoint-GUID: ydGmZ4RLdIsurzxpdtlxEYZN7HpngWDp X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNDI4MDEyNyBTYWx0ZWRfX/b3uicFBU9BO Nce5zgaN2xMmdIsEf6qlMI3WwfCcmpGL9OfSh78MarRSqk3+XifPIKRVyCWTSSmkghddO8w4Fo5 k6xfzAF5v8wx4/VJJxUeQo5SN+C22JeA5MejXc7+LMXfD9+T6dsMzjn9Tu48wr2Jy71WVaiIamm do1XIWMWn/8fd1jWSILAl/6o23HxBqX4YkgQfOmHSYL/fbCLcKu/RQ17ISy0C4LoYILtknNJq3b s6FqmNH2zSd9R31OJy5sRQ3amcwDYGOZHtsbrwu/J2FIayyip9DSI8i0XyBn3pzN5oB9dFoxGvw 3AFbQ1WG4LLkRmhTZjx6v1rLKgX1gR2U96dboqmh/cTtuS0R1oB2naZryJN/HKKDtctB57+/vb7 WXCX1YBN X-Proofpoint-ORIG-GUID: ydGmZ4RLdIsurzxpdtlxEYZN7HpngWDp Content-Type: text/plain; charset="utf-8" Right now these are performed in kernel/fork.c which is odd and a violation of separation of concerns, as well as preventing us from integrating this and related logic into userland VMA testing going forward, and perhaps more importantly - enabling us to, in a subsequent commit, make VMA allocation/freeing a purely internal mm operation. There is a fly in the ointment - nommu - mmap.c is not compiled if CONFIG_MMU not set, and neither is vma.c. To square the circle, let's add a new file - vma_init.c. This will be compiled for both CONFIG_MMU and nommu builds, and will also form part of the VMA userland testing. This allows us to de-duplicate code, while maintaining separation of concerns and the ability for us to userland test this logic. Update the VMA userland tests accordingly, additionally adding a detach_free_vma() helper function to correctly detach VMAs before freeing them in test code, as this change was triggering the assert for this. Signed-off-by: Lorenzo Stoakes Reviewed-by: David Hildenbrand Reviewed-by: Kees Cook Reviewed-by: Liam R. Howlett Reviewed-by: Pedro Falcato Reviewed-by: Suren Baghdasaryan Reviewed-by: Vlastimil Babka --- MAINTAINERS | 1 + kernel/fork.c | 88 ------------------- mm/Makefile | 2 +- mm/mmap.c | 3 +- mm/nommu.c | 4 +- mm/vma.h | 7 ++ mm/vma_init.c | 101 ++++++++++++++++++++++ tools/testing/vma/Makefile | 2 +- tools/testing/vma/vma.c | 26 ++++-- tools/testing/vma/vma_internal.h | 143 +++++++++++++++++++++++++------ 10 files changed, 251 insertions(+), 126 deletions(-) create mode 100644 mm/vma_init.c diff --git a/MAINTAINERS b/MAINTAINERS index 1ee1c22e6e36..d274e6802ba5 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15656,6 +15656,7 @@ F: mm/mseal.c F: mm/vma.c F: mm/vma.h F: mm/vma_exec.c +F: mm/vma_init.c F: mm/vma_internal.h F: tools/testing/selftests/mm/merge.c F: tools/testing/vma/ diff --git a/kernel/fork.c b/kernel/fork.c index ac9f9267a473..9e4616dacd82 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -431,88 +431,9 @@ struct kmem_cache *files_cachep; /* SLAB cache for fs_struct structures (tsk->fs) */ struct kmem_cache *fs_cachep; =20 -/* SLAB cache for vm_area_struct structures */ -static struct kmem_cache *vm_area_cachep; - /* SLAB cache for mm_struct structures (tsk->mm) */ static struct kmem_cache *mm_cachep; =20 -struct vm_area_struct *vm_area_alloc(struct mm_struct *mm) -{ - struct vm_area_struct *vma; - - vma =3D kmem_cache_alloc(vm_area_cachep, GFP_KERNEL); - if (!vma) - return NULL; - - vma_init(vma, mm); - - return vma; -} - -static void vm_area_init_from(const struct vm_area_struct *src, - struct vm_area_struct *dest) -{ - dest->vm_mm =3D src->vm_mm; - dest->vm_ops =3D src->vm_ops; - dest->vm_start =3D src->vm_start; - dest->vm_end =3D src->vm_end; - dest->anon_vma =3D src->anon_vma; - dest->vm_pgoff =3D src->vm_pgoff; - dest->vm_file =3D src->vm_file; - dest->vm_private_data =3D src->vm_private_data; - vm_flags_init(dest, src->vm_flags); - memcpy(&dest->vm_page_prot, &src->vm_page_prot, - sizeof(dest->vm_page_prot)); - /* - * src->shared.rb may be modified concurrently when called from - * dup_mmap(), but the clone will reinitialize it. - */ - data_race(memcpy(&dest->shared, &src->shared, sizeof(dest->shared))); - memcpy(&dest->vm_userfaultfd_ctx, &src->vm_userfaultfd_ctx, - sizeof(dest->vm_userfaultfd_ctx)); -#ifdef CONFIG_ANON_VMA_NAME - dest->anon_name =3D src->anon_name; -#endif -#ifdef CONFIG_SWAP - memcpy(&dest->swap_readahead_info, &src->swap_readahead_info, - sizeof(dest->swap_readahead_info)); -#endif -#ifndef CONFIG_MMU - dest->vm_region =3D src->vm_region; -#endif -#ifdef CONFIG_NUMA - dest->vm_policy =3D src->vm_policy; -#endif -} - -struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) -{ - struct vm_area_struct *new =3D kmem_cache_alloc(vm_area_cachep, GFP_KERNE= L); - - if (!new) - return NULL; - - ASSERT_EXCLUSIVE_WRITER(orig->vm_flags); - ASSERT_EXCLUSIVE_WRITER(orig->vm_file); - vm_area_init_from(orig, new); - vma_lock_init(new, true); - INIT_LIST_HEAD(&new->anon_vma_chain); - vma_numab_state_init(new); - dup_anon_vma_name(orig, new); - - return new; -} - -void vm_area_free(struct vm_area_struct *vma) -{ - /* The vma should be detached while being destroyed. */ - vma_assert_detached(vma); - vma_numab_state_free(vma); - free_anon_vma_name(vma); - kmem_cache_free(vm_area_cachep, vma); -} - static void account_kernel_stack(struct task_struct *tsk, int account) { if (IS_ENABLED(CONFIG_VMAP_STACK)) { @@ -3033,11 +2954,6 @@ void __init mm_cache_init(void) =20 void __init proc_caches_init(void) { - struct kmem_cache_args args =3D { - .use_freeptr_offset =3D true, - .freeptr_offset =3D offsetof(struct vm_area_struct, vm_freeptr), - }; - sighand_cachep =3D kmem_cache_create("sighand_cache", sizeof(struct sighand_struct), 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_TYPESAFE_BY_RCU| @@ -3054,10 +2970,6 @@ void __init proc_caches_init(void) sizeof(struct fs_struct), 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_ACCOUNT, NULL); - vm_area_cachep =3D kmem_cache_create("vm_area_struct", - sizeof(struct vm_area_struct), &args, - SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_TYPESAFE_BY_RCU| - SLAB_ACCOUNT); mmap_init(); nsproxy_cache_init(); } diff --git a/mm/Makefile b/mm/Makefile index 15a901bb431a..690ddcf7d9a1 100644 --- a/mm/Makefile +++ b/mm/Makefile @@ -55,7 +55,7 @@ obj-y :=3D filemap.o mempool.o oom_kill.o fadvise.o \ mm_init.o percpu.o slab_common.o \ compaction.o show_mem.o \ interval_tree.o list_lru.o workingset.o \ - debug.o gup.o mmap_lock.o $(mmu-y) + debug.o gup.o mmap_lock.o vma_init.o $(mmu-y) =20 # Give 'page_alloc' its own module-parameter namespace page-alloc-y :=3D page_alloc.o diff --git a/mm/mmap.c b/mm/mmap.c index 5259df031e15..81dd962a1cfc 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1554,7 +1554,7 @@ static const struct ctl_table mmap_table[] =3D { #endif /* CONFIG_SYSCTL */ =20 /* - * initialise the percpu counter for VM + * initialise the percpu counter for VM, initialise VMA state. */ void __init mmap_init(void) { @@ -1565,6 +1565,7 @@ void __init mmap_init(void) #ifdef CONFIG_SYSCTL register_sysctl_init("vm", mmap_table); #endif + vma_state_init(); } =20 /* diff --git a/mm/nommu.c b/mm/nommu.c index a142fc258d39..0bf4849b8204 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -399,7 +399,8 @@ static const struct ctl_table nommu_table[] =3D { }; =20 /* - * initialise the percpu counter for VM and region record slabs + * initialise the percpu counter for VM and region record slabs, initialis= e VMA + * state. */ void __init mmap_init(void) { @@ -409,6 +410,7 @@ void __init mmap_init(void) VM_BUG_ON(ret); vm_region_jar =3D KMEM_CACHE(vm_region, SLAB_PANIC|SLAB_ACCOUNT); register_sysctl_init("vm", nommu_table); + vma_state_init(); } =20 /* diff --git a/mm/vma.h b/mm/vma.h index 94307a2e4ab6..4a1e1768ca46 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -548,8 +548,15 @@ int expand_downwards(struct vm_area_struct *vma, unsig= ned long address); =20 int __vm_munmap(unsigned long start, size_t len, bool unlock); =20 + int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma); =20 +/* vma_init.h, shared between CONFIG_MMU and nommu. */ +void __init vma_state_init(void); +struct vm_area_struct *vm_area_alloc(struct mm_struct *mm); +struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig); +void vm_area_free(struct vm_area_struct *vma); + /* vma_exec.h */ #ifdef CONFIG_MMU int create_init_stack_vma(struct mm_struct *mm, struct vm_area_struct **vm= ap, diff --git a/mm/vma_init.c b/mm/vma_init.c new file mode 100644 index 000000000000..967ca8517986 --- /dev/null +++ b/mm/vma_init.c @@ -0,0 +1,101 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +/* + * Functions for initialisaing, allocating, freeing and duplicating VMAs. = Shared + * between CONFIG_MMU and non-CONFIG_MMU kernel configurations. + */ + +#include "vma_internal.h" +#include "vma.h" + +/* SLAB cache for vm_area_struct structures */ +static struct kmem_cache *vm_area_cachep; + +void __init vma_state_init(void) +{ + struct kmem_cache_args args =3D { + .use_freeptr_offset =3D true, + .freeptr_offset =3D offsetof(struct vm_area_struct, vm_freeptr), + }; + + vm_area_cachep =3D kmem_cache_create("vm_area_struct", + sizeof(struct vm_area_struct), &args, + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_TYPESAFE_BY_RCU| + SLAB_ACCOUNT); +} + +struct vm_area_struct *vm_area_alloc(struct mm_struct *mm) +{ + struct vm_area_struct *vma; + + vma =3D kmem_cache_alloc(vm_area_cachep, GFP_KERNEL); + if (!vma) + return NULL; + + vma_init(vma, mm); + + return vma; +} + +static void vm_area_init_from(const struct vm_area_struct *src, + struct vm_area_struct *dest) +{ + dest->vm_mm =3D src->vm_mm; + dest->vm_ops =3D src->vm_ops; + dest->vm_start =3D src->vm_start; + dest->vm_end =3D src->vm_end; + dest->anon_vma =3D src->anon_vma; + dest->vm_pgoff =3D src->vm_pgoff; + dest->vm_file =3D src->vm_file; + dest->vm_private_data =3D src->vm_private_data; + vm_flags_init(dest, src->vm_flags); + memcpy(&dest->vm_page_prot, &src->vm_page_prot, + sizeof(dest->vm_page_prot)); + /* + * src->shared.rb may be modified concurrently when called from + * dup_mmap(), but the clone will reinitialize it. + */ + data_race(memcpy(&dest->shared, &src->shared, sizeof(dest->shared))); + memcpy(&dest->vm_userfaultfd_ctx, &src->vm_userfaultfd_ctx, + sizeof(dest->vm_userfaultfd_ctx)); +#ifdef CONFIG_ANON_VMA_NAME + dest->anon_name =3D src->anon_name; +#endif +#ifdef CONFIG_SWAP + memcpy(&dest->swap_readahead_info, &src->swap_readahead_info, + sizeof(dest->swap_readahead_info)); +#endif +#ifndef CONFIG_MMU + dest->vm_region =3D src->vm_region; +#endif +#ifdef CONFIG_NUMA + dest->vm_policy =3D src->vm_policy; +#endif +} + +struct vm_area_struct *vm_area_dup(struct vm_area_struct *orig) +{ + struct vm_area_struct *new =3D kmem_cache_alloc(vm_area_cachep, GFP_KERNE= L); + + if (!new) + return NULL; + + ASSERT_EXCLUSIVE_WRITER(orig->vm_flags); + ASSERT_EXCLUSIVE_WRITER(orig->vm_file); + vm_area_init_from(orig, new); + vma_lock_init(new, true); + INIT_LIST_HEAD(&new->anon_vma_chain); + vma_numab_state_init(new); + dup_anon_vma_name(orig, new); + + return new; +} + +void vm_area_free(struct vm_area_struct *vma) +{ + /* The vma should be detached while being destroyed. */ + vma_assert_detached(vma); + vma_numab_state_free(vma); + free_anon_vma_name(vma); + kmem_cache_free(vm_area_cachep, vma); +} diff --git a/tools/testing/vma/Makefile b/tools/testing/vma/Makefile index 624040fcf193..66f3831a668f 100644 --- a/tools/testing/vma/Makefile +++ b/tools/testing/vma/Makefile @@ -9,7 +9,7 @@ include ../shared/shared.mk OFILES =3D $(SHARED_OFILES) vma.o maple-shim.o TARGETS =3D vma =20 -vma.o: vma.c vma_internal.h ../../../mm/vma.c ../../../mm/vma_exec.c ../..= /../mm/vma.h +vma.o: vma.c vma_internal.h ../../../mm/vma.c ../../../mm/vma_init.c ../..= /../mm/vma_exec.c ../../../mm/vma.h =20 vma: $(OFILES) $(CC) $(CFLAGS) -o $@ $(OFILES) $(LDLIBS) diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index 5832ae5d797d..2be7597a2ac2 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -28,6 +28,7 @@ unsigned long stack_guard_gap =3D 256UL<vm_pgoff, 0); ASSERT_EQ(vma->vm_flags, flags); =20 - vm_area_free(vma); + detach_free_vma(vma); mtree_destroy(&mm.mm_mt); =20 return true; @@ -361,7 +368,7 @@ static bool test_simple_modify(void) ASSERT_EQ(vma->vm_end, 0x1000); ASSERT_EQ(vma->vm_pgoff, 0); =20 - vm_area_free(vma); + detach_free_vma(vma); vma_iter_clear(&vmi); =20 vma =3D vma_next(&vmi); @@ -370,7 +377,7 @@ static bool test_simple_modify(void) ASSERT_EQ(vma->vm_end, 0x2000); ASSERT_EQ(vma->vm_pgoff, 1); =20 - vm_area_free(vma); + detach_free_vma(vma); vma_iter_clear(&vmi); =20 vma =3D vma_next(&vmi); @@ -379,7 +386,7 @@ static bool test_simple_modify(void) ASSERT_EQ(vma->vm_end, 0x3000); ASSERT_EQ(vma->vm_pgoff, 2); =20 - vm_area_free(vma); + detach_free_vma(vma); mtree_destroy(&mm.mm_mt); =20 return true; @@ -407,7 +414,7 @@ static bool test_simple_expand(void) ASSERT_EQ(vma->vm_end, 0x3000); ASSERT_EQ(vma->vm_pgoff, 0); =20 - vm_area_free(vma); + detach_free_vma(vma); mtree_destroy(&mm.mm_mt); =20 return true; @@ -428,7 +435,7 @@ static bool test_simple_shrink(void) ASSERT_EQ(vma->vm_end, 0x1000); ASSERT_EQ(vma->vm_pgoff, 0); =20 - vm_area_free(vma); + detach_free_vma(vma); mtree_destroy(&mm.mm_mt); =20 return true; @@ -619,7 +626,7 @@ static bool test_merge_new(void) ASSERT_EQ(vma->vm_pgoff, 0); ASSERT_EQ(vma->anon_vma, &dummy_anon_vma); =20 - vm_area_free(vma); + detach_free_vma(vma); count++; } =20 @@ -1668,6 +1675,7 @@ int main(void) int num_tests =3D 0, num_fail =3D 0; =20 maple_tree_init(); + vma_state_init(); =20 #define TEST(name) \ do { \ diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_inter= nal.h index 32e990313158..198abe66de5a 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -155,6 +155,10 @@ typedef __bitwise unsigned int vm_fault_t; */ #define pr_warn_once pr_err =20 +#define data_race(expr) expr + +#define ASSERT_EXCLUSIVE_WRITER(x) + struct kref { refcount_t refcount; }; @@ -255,6 +259,8 @@ struct file { =20 #define VMA_LOCK_OFFSET 0x40000000 =20 +typedef struct { unsigned long v; } freeptr_t; + struct vm_area_struct { /* The first cache line has the info for VMA tree walking. */ =20 @@ -264,9 +270,7 @@ struct vm_area_struct { unsigned long vm_start; unsigned long vm_end; }; -#ifdef CONFIG_PER_VMA_LOCK - struct rcu_head vm_rcu; /* Used for deferred freeing. */ -#endif + freeptr_t vm_freeptr; /* Pointer used by SLAB_TYPESAFE_BY_RCU */ }; =20 struct mm_struct *vm_mm; /* The address space we belong to. */ @@ -463,6 +467,65 @@ struct pagetable_move_control { .len_in =3D len_, \ } =20 +struct kmem_cache_args { + /** + * @align: The required alignment for the objects. + * + * %0 means no specific alignment is requested. + */ + unsigned int align; + /** + * @useroffset: Usercopy region offset. + * + * %0 is a valid offset, when @usersize is non-%0 + */ + unsigned int useroffset; + /** + * @usersize: Usercopy region size. + * + * %0 means no usercopy region is specified. + */ + unsigned int usersize; + /** + * @freeptr_offset: Custom offset for the free pointer + * in &SLAB_TYPESAFE_BY_RCU caches + * + * By default &SLAB_TYPESAFE_BY_RCU caches place the free pointer + * outside of the object. This might cause the object to grow in size. + * Cache creators that have a reason to avoid this can specify a custom + * free pointer offset in their struct where the free pointer will be + * placed. + * + * Note that placing the free pointer inside the object requires the + * caller to ensure that no fields are invalidated that are required to + * guard against object recycling (See &SLAB_TYPESAFE_BY_RCU for + * details). + * + * Using %0 as a value for @freeptr_offset is valid. If @freeptr_offset + * is specified, %use_freeptr_offset must be set %true. + * + * Note that @ctor currently isn't supported with custom free pointers + * as a @ctor requires an external free pointer. + */ + unsigned int freeptr_offset; + /** + * @use_freeptr_offset: Whether a @freeptr_offset is used. + */ + bool use_freeptr_offset; + /** + * @ctor: A constructor for the objects. + * + * The constructor is invoked for each object in a newly allocated slab + * page. It is the cache user's responsibility to free object in the + * same state as after calling the constructor, or deal appropriately + * with any differences between a freshly constructed and a reallocated + * object. + * + * %NULL means no constructor. + */ + void (*ctor)(void *); +}; + static inline void vma_iter_invalidate(struct vma_iterator *vmi) { mas_pause(&vmi->mas); @@ -547,31 +610,38 @@ static inline void vma_init(struct vm_area_struct *vm= a, struct mm_struct *mm) vma->vm_lock_seq =3D UINT_MAX; } =20 -static inline struct vm_area_struct *vm_area_alloc(struct mm_struct *mm) -{ - struct vm_area_struct *vma =3D calloc(1, sizeof(struct vm_area_struct)); +struct kmem_cache { + const char *name; + size_t object_size; + struct kmem_cache_args *args; +}; =20 - if (!vma) - return NULL; +static inline struct kmem_cache *__kmem_cache_create(const char *name, + size_t object_size, + struct kmem_cache_args *args) +{ + struct kmem_cache *ret =3D malloc(sizeof(struct kmem_cache)); =20 - vma_init(vma, mm); + ret->name =3D name; + ret->object_size =3D object_size; + ret->args =3D args; =20 - return vma; + return ret; } =20 -static inline struct vm_area_struct *vm_area_dup(struct vm_area_struct *or= ig) -{ - struct vm_area_struct *new =3D calloc(1, sizeof(struct vm_area_struct)); +#define kmem_cache_create(__name, __object_size, __args, ...) \ + __kmem_cache_create((__name), (__object_size), (__args)) =20 - if (!new) - return NULL; +static inline void *kmem_cache_alloc(struct kmem_cache *s, gfp_t gfpflags) +{ + (void)gfpflags; =20 - memcpy(new, orig, sizeof(*new)); - refcount_set(&new->vm_refcnt, 0); - new->vm_lock_seq =3D UINT_MAX; - INIT_LIST_HEAD(&new->anon_vma_chain); + return calloc(s->object_size, 1); +} =20 - return new; +static inline void kmem_cache_free(struct kmem_cache *s, void *x) +{ + free(x); } =20 /* @@ -738,11 +808,6 @@ static inline void mpol_put(struct mempolicy *) { } =20 -static inline void vm_area_free(struct vm_area_struct *vma) -{ - free(vma); -} - static inline void lru_add_drain(void) { } @@ -1312,4 +1377,32 @@ static inline void ksm_exit(struct mm_struct *mm) (void)mm; } =20 +static inline void vma_lock_init(struct vm_area_struct *vma, bool reset_re= fcnt) +{ + (void)vma; + (void)reset_refcnt; +} + +static inline void vma_numab_state_init(struct vm_area_struct *vma) +{ + (void)vma; +} + +static inline void vma_numab_state_free(struct vm_area_struct *vma) +{ + (void)vma; +} + +static inline void dup_anon_vma_name(struct vm_area_struct *orig_vma, + struct vm_area_struct *new_vma) +{ + (void)orig_vma; + (void)new_vma; +} + +static inline void free_anon_vma_name(struct vm_area_struct *vma) +{ + (void)vma; +} + #endif /* __MM_VMA_INTERNAL_H */ --=20 2.49.0