From nobody Tue Dec 2 02:43:46 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 AB8F8346786; Tue, 18 Nov 2025 10:19:39 +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=1763461184; cv=fail; b=EKy15YAN+uDqSU0WLBKHD4OHfVTfu8+1OyvhfxfGX27haUE6Sd6G6yhFTMy9n9Qxh9BXNpiD6lk8fO8aeQLiY0db6q0fmnEhrq07sDEB+o2QvOmzdlRFqF0yKYUdAQE09MYfwN7PEObpu/a4/ZN6LWyS1Dv7dPQTMjW7h0uGHUo= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763461184; c=relaxed/simple; bh=s1BHxtfrXV+RS+aoBnX5A82jBkQKQbNb0mVdRCUB4BI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=MycrhM8gHNPaZjaGz7kX2bSpK+n+SEwzpZZJaVB6LMSRaZxVa+hNd7hf+/uagP2utL9cmgmUBJnsPnujnRagmXzgsTUZP12thv7qEgvXO/QMTyt1IRmcIP6HbEuO9LK4zs1Og4GRqlxlPPCzW/AbYPls1H+XArw1QYbTLyanCVg= 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=R4Uh7Yl/; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=c5uuNNgd; 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="R4Uh7Yl/"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="c5uuNNgd" 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 5AI9CaVB024833; Tue, 18 Nov 2025 10:18:39 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-2025-04-25; bh=nrb0nke0MxNQdfATTGM4VlgHv5k6jO1hYqRufDydMVI=; b= R4Uh7Yl/qMBo3O04StjLCuBTl1pqO/l69iJWCaaMTgPTtX9XpRjGmQcnJb0aHsT7 hVGmjv33U6nZISYcXUoH9tH9CgxnrFB/zdlTKy5Pv/HUxn9ZoR9pGdVOg9oiIbir lzp7EqKsxmBObZchFbmtGN+NJVFnzgE04Ay4ymUNpaAErMNHvXVI/uqJF2Hia3qL /hx5m+R5A6EFYDLSONNrD2xbBeOIn3HZ2gGftvlPOvdAL0/jjc60WVy39HCSGeDP p4/HNijZBYOq/7Cgw+PxgrW2D3d64a9w4dAdxAFGEeg1MYRryE4hnMRcD2z65nJ6 7GwsAK9PTsHlDkdXP8cP0g== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejbpvjff-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:38 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5AI8wjfm004268; Tue, 18 Nov 2025 10:18:38 GMT Received: from dm1pr04cu001.outbound.protection.outlook.com (mail-centralusazon11010048.outbound.protection.outlook.com [52.101.61.48]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefy8pp85-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=JLyv9qnvIXctA1330PbBF4TfwQ1BzlROucsZTF6YS1x/8ZTE5GidzVpDmvuhnehsK5D0bTb//w9PnyO3i+UHafmWV2qgjuG5h5uq+fmHZjH5MvIpvr+gHM1FonjNbmbSXj9ZCTuQho+ySWIe1JR1M36ZovUaIeKztvFJB5RGUxAhSCJkeYLi5sOh/Gnw13//Cr1wtWTXVc9heq2ufT0fDdhA7ynlktMQBX3cFS3FKh/TlezKNjsjC69uotCPUnkNGXRRnPbn45ejWW2iEA407PIpMCb3aWjpXN3919bWwIKJ2d7RRXuSnhdPDkChmg+XhBh0G/Agw4izP280o/WFJQ== 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=nrb0nke0MxNQdfATTGM4VlgHv5k6jO1hYqRufDydMVI=; b=qBoPp4GoPZHr0QFotjkhOk2lCyD1prKlyIiSkaDmWjGY9S2UNA1V9TwlCcb78kh9cpeVuiEDPPrpzDLScDUR1thTO+O9ugd+SvNsciHYanRH7Aj8xzRsKgrK11f12YfIiFhPsOEPpsmwL+Q/ckvSeVYosTrsPyqZa+Y0a7aLPwJaecGJoQ9FphpkUN2cAbjWWjCpEegq+/VQ9M3GZ7cStkY11gYRQOPeoHgu6nqNK/Kby7D8Wcgz7NNrkBug2SEwHGG/TuT8bAE3LdIymZaMhW1+k+UPZIPr7qMNWOZJUsCCk3PyAJWjdYTeNk3RRqkjfCSCjj9T1StnaLgUOBvq3Q== 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=nrb0nke0MxNQdfATTGM4VlgHv5k6jO1hYqRufDydMVI=; b=c5uuNNgdKFXjwT88vmJLBFvOrNxe+ok5tUdD6//C68ubqlFkO/wNjk7ib9bvFyGJWeySsb+u98d/DuNaY/Zvyt0+RBi/x2TjHi+Tk08vZ092YD9BTNkBBWwhVmplPS7nZX0pA0O8v/8Tjpt+FfO1HZdwbIbNTZv3Wz4WXptU/GQ= Received: from DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) by IA4PR10MB8756.namprd10.prod.outlook.com (2603:10b6:208:562::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.21; Tue, 18 Nov 2025 10:18:21 +0000 Received: from DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2]) by DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2%7]) with mapi id 15.20.9343.009; Tue, 18 Nov 2025 10:18:21 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Jonathan Corbet , David Hildenbrand , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jann Horn , Pedro Falcato , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Andrei Vagin Subject: [PATCH v4 1/9] mm: introduce VM_MAYBE_GUARD and make visible in /proc/$pid/smaps Date: Tue, 18 Nov 2025 10:17:43 +0000 Message-ID: X-Mailer: git-send-email 2.51.2 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO4P265CA0213.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:33a::11) To BL4PR10MB8229.namprd10.prod.outlook.com (2603:10b6:208:4e6::14) 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_|IA4PR10MB8756:EE_ X-MS-Office365-Filtering-Correlation-Id: 385e1da5-4029-4954-9eb2-08de268bccd6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?5+0w+qOsO0OBMqAJValOs214S5+BkG8wrYOpSvM3fdlkOEODJyJ/PDagTpX+?= =?us-ascii?Q?bsRYvGetWgjptsGeg5vvE543X+YuW3v4f5g8soU1NBY+qf8zb4nrn1CFlQQm?= =?us-ascii?Q?RMgsPFpudfa14y96S2PseTxq0W6kNUy6LbIS+iOHosZtT8VeSdqOoFNU/I5W?= =?us-ascii?Q?+Ah+OnjQ2FpkcB+7KgkBXGu6s0ndX3tJDicQTbrKWm0ku98VnZ9ytHAkDq7Z?= =?us-ascii?Q?okPYA+6WQu/TxjczX57bszs4bfwrFxtLC1+KPA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HBexxNPb4ugCUkueSDRNp/QBgTlFwktUr25V?= =?us-ascii?Q?yvZnbSGv9+GjWMcBulzfHQfKyec4JvBoH/LyV/pgTwi9X25C6D0iVm9TUN1c?= =?us-ascii?Q?WvBYjqtHXSqtKOLS8BHgfoo4PPNhphblorY0rMuwvXFElT2xYdX49S9JqKsM?= =?us-ascii?Q?q2XHJpcolmwr2i7EEK8vmD+1AJLbpOoG3wcMivReR8mdV1Dd3fBW0o/b38W2?= =?us-ascii?Q?SGJyisRoDu+sf7F6pwZB3xOtti+Q+hWimTj78YUdi23ky/JPwnQgwYG0yjvk?= =?us-ascii?Q?Qe2ZN8xNPkTnJW1TZc7mbjZFaK/oAVFJ?= 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)(376014)(7416014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?DTR97mhH/e/s62pv83MQIJgq6X2FpbEw7E+mdqr+6pATQvAh42TVk2f6iNHF?= =?us-ascii?Q?3JRDyF0vQOe6wnRI0eCh5b3wLcL+6sBMdUpmG3xTrqs8zvSuoDcRMPbJbPuR?= =?us-ascii?Q?9hfZKUUl3H5VyM06BpSEzsx6COC/srqo+1YwQuCsVZTISoUX+0/R1lCQVjvA?= =?us-ascii?Q?JZ2lh+nU7YJBrd9TLeujcz2iiLKK4nd6uBygKYxgU/TzEbCNynOjeXBrwHCM?= =?us-ascii?Q?cmdui9JUhr7IVaDnufFnLAVS5hmTqOgNlfVdqyMAsXWz69ffgbgcbDF80EFO?= =?us-ascii?Q?20XvFBnTIRweiDt949QPibp5UfDKSsQqP1i13wBoKrt5NkdYxwIrL6xTWHoF?= =?us-ascii?Q?aBbo2KCNzh55JRYQGZ4o9pF6wsqThA+w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R3jNA+27H3X+9RqhGcYylJSGbK/qYptm4btO/EZ1eD34CYW5b7UynXtK9U5sBXViEaBRkWluQKI0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 385e1da5-4029-4954-9eb2-08de268bccd6 X-MS-Exchange-CrossTenant-AuthSource: BL4PR10MB8229.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2025 10:18:21.6814 (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: 1trfjcDBIjcv0Z3vxEAAKpUy65BXLOz7HEPre9JgITuWPXMByAbh2WbnxXbOSewMD3DA2bD1rVRlDqM3RRehD7egEtDBrKUAqNCVwI3u9nk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA4PR10MB8756 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-17_04,2025-11-13_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 mlxscore=0 bulkscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511180082 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX7+bKCI51wses 6M6xyVjCAj8XgdfnvvtUaWbCsf9ekEwN6Z8ivjV+xC3VOgqFb92x436wBWY7QGr4taxAiQQYwIk 8uHCFWVyivP/5DPG4opnne2GSNlO6xyfq18g4cksW/DdjQFA6dyuFj7ROX/Vi1ESMdfo59w00RJ fBkPziu5ARrVwL0nUtXZdpaOGehvMCp3de1CHd4IhRCKHtvoenbIMZ1uk30LvE8z2PfbXxqyQ1n ywnpeHLK/ZvfFQ4Igd4muEr7FU4GizqhnNhFK3hrrzZAMOCBjpWi1DSEepE3JzO4qISxhTqI9HQ k4dnRPX+cuTBg6TUPq2lUNAPDtSFXRI4+8/5ze03BivCQ4nRMcyquBUrn9gt0pwDFD72fA1hx+q jSdv/iuTgLkO0QJB97T84szhkEgDBQ== X-Proofpoint-ORIG-GUID: peSyNjazSxQuivqXDVtoCRB6D3bF_ZYH X-Proofpoint-GUID: peSyNjazSxQuivqXDVtoCRB6D3bF_ZYH X-Authority-Analysis: v=2.4 cv=a+o9NESF c=1 sm=1 tr=0 ts=691c47ff cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=z/mQ4Ysz8XfWz/Q5cLBRGdckG28=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=xqWC_Br6kY4A:10 a=6UeiqGixMTsA:10 a=GoEa3M9JfhUA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=VwQbUJbxAAAA:8 a=lkmYoepbxJn_IgOSQAYA:9 a=nl4s5V0KI7Kw-pW0DWrs:22 a=pHzHmUro8NiASowvMSCR:22 a=xoEH_sTeL_Rfw54TyV31:22 Content-Type: text/plain; charset="utf-8" Currently, if a user needs to determine if guard regions are present in a range, they have to scan all VMAs (or have knowledge of which ones might have guard regions). Since commit 8e2f2aeb8b48 ("fs/proc/task_mmu: add guard region bit to pagemap") and the related commit a516403787e0 ("fs/proc: extend the PAGEMAP_SCAN ioctl to report guard regions"), users can use either /proc/$pid/pagemap or the PAGEMAP_SCAN functionality to perform this operation at a virtual address level. This is not ideal, and it gives no visibility at a /proc/$pid/smaps level that guard regions exist in ranges. This patch remedies the situation by establishing a new VMA flag, VM_MAYBE_GUARD, to indicate that a VMA may contain guard regions (it is uncertain because we cannot reasonably determine whether a MADV_GUARD_REMOVE call has removed all of the guard regions in a VMA, and additionally VMAs may change across merge/split). We utilise 0x800 for this flag which makes it available to 32-bit architectures also, a flag that was previously used by VM_DENYWRITE, which was removed in commit 8d0920bde5eb ("mm: remove VM_DENYWRITE") and hasn't bee reused yet. We also update the smaps logic and documentation to identify these VMAs. Another major use of this functionality is that we can use it to identify that we ought to copy page tables on fork. We do not actually implement usage of this flag in mm/madvise.c yet as we need to allow some VMA flags to be applied atomically under mmap/VMA read lock in order to avoid the need to acquire a write lock for this purpose. Signed-off-by: Lorenzo Stoakes Reviewed-by: Pedro Falcato Reviewed-by: Vlastimil Babka Acked-by: David Hildenbrand (Red Hat) Reviewed-by: Lance Yang --- Documentation/filesystems/proc.rst | 5 +++-- fs/proc/task_mmu.c | 1 + include/linux/mm.h | 3 +++ include/trace/events/mmflags.h | 1 + mm/memory.c | 4 ++++ tools/testing/vma/vma_internal.h | 1 + 6 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Documentation/filesystems/proc.rst b/Documentation/filesystems= /proc.rst index 0b86a8022fa1..8256e857e2d7 100644 --- a/Documentation/filesystems/proc.rst +++ b/Documentation/filesystems/proc.rst @@ -553,7 +553,7 @@ otherwise. kernel flags associated with the particular virtual memory area in two let= ter encoded manner. The codes are the following: =20 - =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D rd readable wr writeable ex executable @@ -591,7 +591,8 @@ encoded manner. The codes are the following: sl sealed lf lock on fault pages dp always lazily freeable mapping - =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + gu maybe contains guard regions (if not set, definitely doesn't) + =3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 Note that there is no guarantee that every flag and associated mnemonic wi= ll be present in all further kernel releases. Things get changed, the flags m= ay diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index fc35a0543f01..db16ed91c269 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1146,6 +1146,7 @@ static void show_smap_vma_flags(struct seq_file *m, s= truct vm_area_struct *vma) [ilog2(VM_MAYSHARE)] =3D "ms", [ilog2(VM_GROWSDOWN)] =3D "gd", [ilog2(VM_PFNMAP)] =3D "pf", + [ilog2(VM_MAYBE_GUARD)] =3D "gu", [ilog2(VM_LOCKED)] =3D "lo", [ilog2(VM_IO)] =3D "io", [ilog2(VM_SEQ_READ)] =3D "sr", diff --git a/include/linux/mm.h b/include/linux/mm.h index df9f258a017c..36b9418c00fc 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -271,6 +271,8 @@ extern struct rw_semaphore nommu_region_sem; extern unsigned int kobjsize(const void *objp); #endif =20 +#define VM_MAYBE_GUARD_BIT 11 + /* * vm_flags in vm_area_struct, see mm_types.h. * When changing, update also include/trace/events/mmflags.h @@ -296,6 +298,7 @@ extern unsigned int kobjsize(const void *objp); #define VM_UFFD_MISSING 0 #endif /* CONFIG_MMU */ #define VM_PFNMAP 0x00000400 /* Page-ranges managed without "struct page",= just pure PFN */ +#define VM_MAYBE_GUARD BIT(VM_MAYBE_GUARD_BIT) /* The VMA maybe contains g= uard regions. */ #define VM_UFFD_WP 0x00001000 /* wrprotect pages tracking */ =20 #define VM_LOCKED 0x00002000 diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h index aa441f593e9a..a6e5a44c9b42 100644 --- a/include/trace/events/mmflags.h +++ b/include/trace/events/mmflags.h @@ -213,6 +213,7 @@ IF_HAVE_PG_ARCH_3(arch_3) {VM_UFFD_MISSING, "uffd_missing" }, \ IF_HAVE_UFFD_MINOR(VM_UFFD_MINOR, "uffd_minor" ) \ {VM_PFNMAP, "pfnmap" }, \ + {VM_MAYBE_GUARD, "maybe_guard" }, \ {VM_UFFD_WP, "uffd_wp" }, \ {VM_LOCKED, "locked" }, \ {VM_IO, "io" }, \ diff --git a/mm/memory.c b/mm/memory.c index 1a1626bba55a..a520720702f0 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1478,6 +1478,10 @@ vma_needs_copy(struct vm_area_struct *dst_vma, struc= t vm_area_struct *src_vma) if (src_vma->anon_vma) return true; =20 + /* Guard regions have modified page tables that require copying. */ + if (src_vma->vm_flags & VM_MAYBE_GUARD) + return true; + /* * Don't copy ptes where a page fault will fill them correctly. Fork * becomes much lighter when there are big shared or private readonly diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_inter= nal.h index c68d382dac81..46acb4df45de 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -56,6 +56,7 @@ extern unsigned long dac_mmap_min_addr; #define VM_MAYEXEC 0x00000040 #define VM_GROWSDOWN 0x00000100 #define VM_PFNMAP 0x00000400 +#define VM_MAYBE_GUARD 0x00000800 #define VM_LOCKED 0x00002000 #define VM_IO 0x00004000 #define VM_SEQ_READ 0x00008000 /* App will access data sequentially */ --=20 2.51.2 From nobody Tue Dec 2 02:43:46 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 BAE3134320F; Tue, 18 Nov 2025 10:19:27 +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=1763461172; cv=fail; b=WemqXc79aLFMANp/h7kZwiecfdvRmoCSYts3GaUx4/sAxGRO7x2xYeubUOk9gv7EseQWqHsMF2RrcA+yBfW7fhwpgwTg2Gsky6zqqYtGGcwA1Nt5Rb4C7ArIqVxg/TKmK7Xt7LCFTIQbROCtMv2zWIy2X00cxKBXJ8BPFHcHKjQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763461172; c=relaxed/simple; bh=d2FNTytGtZ53VKN9zIBZcTNUa0rj1LNB4pUrzR9/tNM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=UtS2iWszv8pHhEuM4477HltZnW4iEfkDT0F7sWuY2UO0dwsxDeXVMm7pBvDBRJdRwJtcaZE5cRoBT2pnFkltGyTky7eqHa4MF5Ae6NxZ58ROeJcCTuD8gQ8Rwf8TLQlu9v3rPptwk/nwexMZ78Z3fPCZxRRCJsub5zg19omeiwU= 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=TR68TXqj; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=iIwDjg9Z; 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="TR68TXqj"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="iIwDjg9Z" Received: from pps.filterd (m0246630.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AI9CDe1007841; Tue, 18 Nov 2025 10:18:39 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-2025-04-25; bh=qsb5wH3T3F6rhGHk7DsnRdSMIQc4F3lgVOnHE0S143o=; b= TR68TXqjSePgA09QOgx8fQt6rnzp+PujL8NN/HDwzz1FZBrMRjz55bmfzoYB6f9u +8O50Sq5T3nqak/InjK9C1GzzwJDaguXdAuNYfqVXyeJi8oAOw8tiy0MCroPyMf3 5xWRrnVX3xtLsOHq9jtHQ/07cQyQ+Ia+THCxP5bDSUmL8mBxjd0DxMu4iXjE9z67 Gv+L780hJhCjsJbLk4HEVp5/In0xLs+qLtH+9onGb8taDLsug7PtLzEfiZLaGSti TkUXGkXgrA/UDXlAXFnaqjbHmOB+61bmSVRLQnRhTZc9RNNlU2EcehZroWd/svMN of/UjUrK7BRHBZRSvel3vw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejbbvgyw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:39 +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 5AI9NsrV040040; Tue, 18 Nov 2025 10:18:39 GMT Received: from sn4pr0501cu005.outbound.protection.outlook.com (mail-southcentralusazon11011045.outbound.protection.outlook.com [40.93.194.45]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyk8qpj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=bW04fsgsQ4ANdEX00urwnkrGRGfO2AIc5poXEoH8HH0rvZZsBnZdHyuWd//rhh8EF06IZFfkjt7lQSVzgjQJ0ZeL+dd1tomILJPE4gS/HozHnG7rGtY++Zmu7klKjO3N42hmoQU6+wNYs898drkEdSVb6Xcp1n0jDDwuBMMboUafEbRircLz3htFkOrAaR4+NeSLSSrkZYLVawJ1NMNJcJc9tUZfiuVKtiIETcsygyE1yEiDvJ1oJyAOnhcAe0IBdljxEsk2I+nS64QM2vIQrEzkVnYrHLukRc1eN+jdsUJv9bH7BJcczeTtqi5uuqNPJxtt6ciX3wKoe3ZuKyNDPA== 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=qsb5wH3T3F6rhGHk7DsnRdSMIQc4F3lgVOnHE0S143o=; b=uaMfKxjNj2PfgB9ivSpFRZmdgQs+iwzdao4tghqWoGvPWimO/Rek2gHpXw37jihr89qd47l47Kb/cAMgBmjM600pLMKmEvRv+fRE9c6U1OUtoUJRMWwV6PGERrOxHXMvpzzAv/547UcOxsUDsmCkc40HBZYPLZ4a9wg9T5Duz/td58+y8ZLr3Jjpe+/oYhq2uhyY6FpGAtUGiTwQg+VssrcCgOD/HiObRiyrWpwQvewbQRDlSvbUnOEQxayqVouxhBE9GmlidkjDhSvJ8tfXZFNFvtsidaOQCqG2CMf3QvVWze2L8jbXxSsSIy1n6ROqgdfo4F1DTjTRv0AXGdZraw== 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=qsb5wH3T3F6rhGHk7DsnRdSMIQc4F3lgVOnHE0S143o=; b=iIwDjg9Z6WMpVI0UbVrY+QhSoDyf3Dv6f8LYOxMngBwPjOW/2ncjbglKEdp6+i8FySdTdinBkpeBT+UAuNZtddKz/KyvbBoI/PxSFeGeZb7oOlNgr1ASbl56CHctSbjA6Uzfa39InkphaeKyGz2MC/+DOET1hoSCy3vs5NjQ9o0= Received: from DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) by IA4PR10MB8756.namprd10.prod.outlook.com (2603:10b6:208:562::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.21; Tue, 18 Nov 2025 10:18:24 +0000 Received: from DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2]) by DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2%7]) with mapi id 15.20.9343.009; Tue, 18 Nov 2025 10:18:24 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Jonathan Corbet , David Hildenbrand , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jann Horn , Pedro Falcato , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Andrei Vagin Subject: [PATCH v4 2/9] mm: add atomic VMA flags and set VM_MAYBE_GUARD as such Date: Tue, 18 Nov 2025 10:17:44 +0000 Message-ID: <97e57abed09f2663077ed7a36fb8206e243171a9.1763460113.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO3P123CA0019.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:388::15) 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_|IA4PR10MB8756:EE_ X-MS-Office365-Filtering-Correlation-Id: ac50dbc3-5450-40d7-5078-08de268bceb5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?EpzpSwFgRwt/BVHyDh1mvQTIxiJF5MlZH1Q/JOZoYa81Yp57kCjbaGi8C11H?= =?us-ascii?Q?kp7+pQHMoiOTlkGZqGxZzjr/WQ6ywTcc6w5ZrQd5zVnNQDhdGBImoSAcp/t/?= =?us-ascii?Q?9ZGUHUx+lxZ7sIhD4nlsRVnRM5PWJCpPNMkh+G8daqapSZ1J3NJBN5JD3oCv?= =?us-ascii?Q?DgGR2Wvnfkv9a0s/00GGTq/hc2cBUdIOgzZVPm+rrZTrSqvgMm1N/v8eo2BG?= =?us-ascii?Q?IhXbGjByrM7heA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?us-ascii?Q?zPPpNz0vRUhunDn+bEL1r1pXon94g6g518UGVUwad/TEg19DAFci0tT0wkAK?= =?us-ascii?Q?IWU84+GZvLso9IDdDrXDERsLebhyjQjkevi2R4+P1ZBKm2RDaqMjYRoishca?= =?us-ascii?Q?cC9W+4LAtnhV7xZgBKJ41wc50r6wWGvbNRxsxd0V5JLGrSHf/dq4FNRAJ+vb?= =?us-ascii?Q?Rlog/fxC51w5Wa70tcp/Juy2U77rgBmrT44YaBT82Kaf1Xe+VySZyin+U4gM?= =?us-ascii?Q?H6sjRsOsFdNcb34JN7wkiVWjWE+9JTSdOTKDyPEX46hcZGudUb9VOkUTM46U?= =?us-ascii?Q?AyGnPQE5q/yaGOuQnVSLCy1vUWQ7ROYZ?= 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)(376014)(7416014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?1uDnZ3Ghx1qCZZ55fZKLrWHzSToHcR1x2ahRkzMkjcm3vDvdD/HOBfhY3MC7?= =?us-ascii?Q?rVFNThSwP7fjwUMXrC14BH+KRsMUJk0GkAZiZnV7QIps20Fyuf2G7VkZ9TYE?= =?us-ascii?Q?HiwdtJmQ6MR2JYJ64EeRlKpa+D0aGIRlxbB8AAoStc7vIPUyWUywG6wtw3hA?= =?us-ascii?Q?YLHGE2F8mnTPXcf4FUfAGB49/5AShkrA5fDGqs4aWO60vUInfsmAW8dU9S2I?= =?us-ascii?Q?0cfPyacOKiG6lVh9uumX0y4mHOHVcJOBphGNp1WYXVWcmq9EJw/Bj9E4nR6X?= =?us-ascii?Q?wBmv4wP3TQsz8IKDokpSOBEB7H+mNHglpXBpKqDLJcIeCmOCOOvk1Dubm8i0?= =?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Lke9dXXdgiduWMFcGUFwR+aO3EUden2j/yWa?= =?us-ascii?Q?anrA4T1Ymw35zwtoStk82Alocl6DhwS9RtIc4cPuiCOJXpVuqLOGiRnDXPnA?= =?us-ascii?Q?ZbJGtKM8vxHi6NK+TPb76h+2zqsZoWE3eu6mzSoxMr99eqRq5RjTcxU+H6YH?= =?us-ascii?Q?HCD6DeFbHS7cbHfu2/5jG1jGyShMF/K68U+EtyGsn7bF5/2prbVY+q09/ldz?= =?us-ascii?Q?6snBpPVGNM4yv8NtbCfzjjuIrLd5U4K4m2JA3vWUNGlchBdf97inJjrBD7ZN?= =?us-ascii?Q?/Hk55X1xigTdwO8+hYyLsT9mW44RwUCOF/rMqkX9vnvYXSWMka3/n604oFYS?= =?us-ascii?Q?x2q8og9qvwyS1bcl+AsXKiqBA6VL6fXTNy44kEIoWSvRejHnwSXGuvkW8dQp?= =?us-ascii?Q?oA=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: JxNcFjl7Y63m12x4JFagC4xyNjW11umPWXEQOjpau37U/xI+i72/yEfuQWSZs+eyuKb9dUGHud2saQMn7Q8dHiECxoBf29DkDYeZwDZ6gLW1UyRR3UanFIe43QShRZ8Er/gCRN4qm8SJPyDh2IHh8NkCOiKGRz3cVODAg/1X3ndiHoxz+zMg3Gih87IG6NGLf9N/g42APASlkLHKYxp2HmKTeFuo8eJp8aZ8wOLjbWMVlDBGlVMEV/H5lYmdMyulh6L+3GnHuQt97nms8+PHhidzjR/HbZ1nnBwBgQmeijTLmUkED2lDNSK2OgQrMd6jySl+C/eecA5s7PA/aKXbiDgGCFfbvxepONMBihSNrZ+hnZIC7KZ3rhEdHfBYR4mZBGevAfY3V/WsEUhPeDijj8vzGnPPXcYVLfGJRHtTyTFOFgLpf+3qZLrBTyZ/4Zk8pwlSsKp1xAKA9gek7MLdeh3W0RVvJSQaJu0I1UyiOAZOR1mkBjaEM9kaqcOOXN+qr6XCRcr7BIEmoYyqCmq+vCvtIsgr9YIAvWQLW4sZV1FGvj1s4nhVVJdSkxnT9snLwdf09tKNvjtqCYsvZHP25jtm3tWGwQui4tr5gF4RBrg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ac50dbc3-5450-40d7-5078-08de268bceb5 X-MS-Exchange-CrossTenant-AuthSource: DM4PR10MB8218.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2025 10:18:24.4110 (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: kHnue1r6aUOkmwCuymNzrjKhTmfG9jEF3H2Y6PyOhMW2i98ri7c1k2G3wcVmBoo7JR3z7A6TyyvTRFyls6LFeuOZkUVX+CjjySBha/32AV0= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA4PR10MB8756 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-17_04,2025-11-13_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 spamscore=0 adultscore=0 mlxscore=0 mlxlogscore=995 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511180082 X-Proofpoint-GUID: 9YUnt2O-f3duCxjATJFTX7UK9fpbKDuD X-Authority-Analysis: v=2.4 cv=JZyxbEKV c=1 sm=1 tr=0 ts=691c47ff b=1 cx=c_pps a=qoll8+KPOyaMroiJ2sR5sw==:117 a=qoll8+KPOyaMroiJ2sR5sw==:17 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=z/mQ4Ysz8XfWz/Q5cLBRGdckG28=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=xqWC_Br6kY4A:10 a=6UeiqGixMTsA:10 a=GoEa3M9JfhUA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=_GmWhKkRMyt_Xr-G3xIA:9 cc=ntf awl=host:12099 X-Proofpoint-ORIG-GUID: 9YUnt2O-f3duCxjATJFTX7UK9fpbKDuD X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMiBTYWx0ZWRfX529o8I1qLZP9 LPiAc7s3LjlazUGWbPdPf53NJ0A7OdWx/Y/TmeuORVnbjq4Bbs8W3rbNfhPPUUMf/rAG3RDj4DE s6eARfv58NP8UbdyEfrvhah4Ok2M7qwS5Kdn5SUj7UsJEizbpCIrc/x+ZH594oIZMRUPjo+bsev U+7NzbNLTYMXZK/STgKGPwn2iYeMo3alrvsCdrPC0dN/9mdkwfaM0pZ/5Vyznp33PL4+kVUhdQ5 34Fkc29dp0Viyc2+v9the5Xu7aYdSP9kZmH9Go8ALG9Tigoauim1mCI5+LXwZoqhEAR4o+qDzOT n9JHCLHMlzTYUbzlq3o/xPtXQSgabT1umzgegt3hfPaHbrk7VT/IYfm7dmPMFHTBseySMOl30mh 0XIflgRO7GnXSTIVIjOLd+ePbi8sp9SLX7f6LCzxElCHR4f/zzE= Content-Type: text/plain; charset="utf-8" This patch adds the ability to atomically set VMA flags with only the mmap read/VMA read lock held. As this could be hugely problematic for VMA flags in general given that all other accesses are non-atomic and serialised by the mmap/VMA locks, we implement this with a strict allow-list - that is, only designated flags are allowed to do this. We make VM_MAYBE_GUARD one of these flags. Signed-off-by: Lorenzo Stoakes Reviewed-by: Pedro Falcato Reviewed-by: Vlastimil Babka Acked-by: David Hildenbrand (Red Hat) Reviewed-by: Lance Yang --- include/linux/mm.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/include/linux/mm.h b/include/linux/mm.h index 36b9418c00fc..03776aab3837 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -518,6 +518,9 @@ extern unsigned int kobjsize(const void *objp); /* This mask represents all the VMA flag bits used by mlock */ #define VM_LOCKED_MASK (VM_LOCKED | VM_LOCKONFAULT) =20 +/* These flags can be updated atomically via VMA/mmap read lock. */ +#define VM_ATOMIC_SET_ALLOWED VM_MAYBE_GUARD + /* Arch-specific flags to clear when updating VM flags on protection chang= e */ #ifndef VM_ARCH_CLEAR # define VM_ARCH_CLEAR VM_NONE @@ -860,6 +863,47 @@ static inline void vm_flags_mod(struct vm_area_struct = *vma, __vm_flags_mod(vma, set, clear); } =20 +static inline bool __vma_flag_atomic_valid(struct vm_area_struct *vma, + int bit) +{ + const vm_flags_t mask =3D BIT(bit); + + /* Only specific flags are permitted */ + if (WARN_ON_ONCE(!(mask & VM_ATOMIC_SET_ALLOWED))) + return false; + + return true; +} + +/* + * Set VMA flag atomically. Requires only VMA/mmap read lock. Only specific + * valid flags are allowed to do this. + */ +static inline void vma_flag_set_atomic(struct vm_area_struct *vma, int bit) +{ + /* mmap read lock/VMA read lock must be held. */ + if (!rwsem_is_locked(&vma->vm_mm->mmap_lock)) + vma_assert_locked(vma); + + if (__vma_flag_atomic_valid(vma, bit)) + set_bit(bit, &ACCESS_PRIVATE(vma, __vm_flags)); +} + +/* + * Test for VMA flag atomically. Requires no locks. Only specific valid fl= ags + * are allowed to do this. + * + * This is necessarily racey, so callers must ensure that serialisation is + * achieved through some other means, or that races are permissible. + */ +static inline bool vma_flag_test_atomic(struct vm_area_struct *vma, int bi= t) +{ + if (__vma_flag_atomic_valid(vma, bit)) + return test_bit(bit, &vma->vm_flags); + + return false; +} + static inline void vma_set_anonymous(struct vm_area_struct *vma) { vma->vm_ops =3D NULL; --=20 2.51.2 From nobody Tue Dec 2 02:43:46 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 402A43469E6; Tue, 18 Nov 2025 10:19:53 +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=1763461199; cv=fail; b=BtOUg4IxIxzW0kb11vAz7cObME/0B4thK92O0PnJAx0ARs/bOhKefvFABRZAyXw3c2CXemA7xStyD9IHplfKowh/SAXJ+tnB/CypGCmdwICGPIvkhXrSCbAGfdrm8ZoTGzNW6qT+WqrPmX86Hbn0kAyTYBywD/VzvQEt1CmqecU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763461199; c=relaxed/simple; bh=RS6V4xlG7wZJYygEjSqGw5wqQsKkWnk0LWo5GL3GUTs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=TAR93MXGhXS+bxcTuoVUPKuxHy7Y+IYP/kOiI9AN8SRPGCH3huH4LnDzmN8VdxXznxGE5eoalTOkR49SjYxQwe6p/lbkw413ocClK42S+34PJEYvMqkqDtBdE41BpciZFzmhZLAofOxD76oUBx3HHeIcrruUu9JrKE37DnRk/N8= 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=qDJMPh/5; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=G/euT4n8; 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="qDJMPh/5"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="G/euT4n8" 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 5AI9CCMr020871; Tue, 18 Nov 2025 10:18:40 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-2025-04-25; bh=PnAJBcGpQ3U/PYO6jARlBQ9zTAEYuKnTFX5dhMzNpY0=; b= qDJMPh/5IlldnYQuWWPNplxKhT9NR+fuIlCc8MyD/56+XAAj23lImj5fI7WYJupW 6iR/Vx3gIMoCnZcHDyPVPDFw9SeVhtS/GakmcJqSd/cqDHKjIlcb+bBqJMVBf7cN 98yh07gXq3Gwx0iKugY6IDBjzw7B8BrGoRpCmUQAZ1JCKfy4xOmYCVtatHfLYPM7 vbkGJEkeAjcEOAV89uxD9DA+Kmd7MZb6hUGikKPiJpeJzesC1w4xXiENgr+CwMNt /1fmXKNBVo2U40Ma91BjlatgGFB9NPNQC+wKS3DB2qpvRacosTTFN2Xh5npk1du2 7LFVzD+qYO5vhto1rYWJOg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aej8j4j8h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:40 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5AI8wjfn004268; Tue, 18 Nov 2025 10:18:39 GMT Received: from dm1pr04cu001.outbound.protection.outlook.com (mail-centralusazon11010048.outbound.protection.outlook.com [52.101.61.48]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefy8pp85-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LQXvArIEYcxVzk+VYUKlFMtOYalM/okKVNxxH8hKOnczWldzJ3DnbF/CwatBEFYIYxB3GY5qvMSJx7jw40FUC6PYQ9DfK+DY6kHpoNSDR0MGfE8MzxnPi/xzechMxUiS5cZpQLSOg2spANOTl8uWY7GxnKPhYcU6kyoxMRoltECyAVlKpmqgIkJCH7DI732rjEIpUJWaJLTFOXjcsHJ6Ujb67aj3HzTNTI5ioR65FOJ3/qzSpfEPCWoHBCfpOsWZ3YHAnslawFNgr8NLgERF1FHJn4ucvH2c/jtA+YiDxGfUkDAjdobRTHONmy0QzJ8NcCwozpZkOgobmNIvFVdCKQ== 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=PnAJBcGpQ3U/PYO6jARlBQ9zTAEYuKnTFX5dhMzNpY0=; b=MFg9wnIhznPre50MRMV5wfK+W7YFsiB59sZBZdu6wtxeE+WfjiRlyJyc5elRPUXDw1HXmaHPEpFIZBB9dDQauPcTeh7Iu4kw6kNCEY04OW2NmK6WtnVRNXAmCyG+6jnjzDwv9x/RhRJyVpGp9TEJklEclx911EH5L+xuS7SxFpc1/zE9c87oE20MXvhE/3gPryTpCYCWNNHPR8U1zi9/Ct4GqPtjHxCX1K6a8N6aCJOQ3IxKG2Jyh1IPxYJMx2cFootRUOPVXbqCoqyif0jxoCNWnAlTWgF05VLYSDLJCAcVbaw4OhGAbwnBhjWnO2/r72673avhlmmtKNnuGSg0bg== 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=PnAJBcGpQ3U/PYO6jARlBQ9zTAEYuKnTFX5dhMzNpY0=; b=G/euT4n8Lvzyl2J8xoFKw0moti4pA4cl4Vi41G+daTo7fRQLOr9yx4AqhkWn9MqEGM7NLc3EZvRIjBSFh5Eq271TwWwWyNjPTbE/FK2HFp3dd7syDKHRrBEFE499YVHtoKpHc0jC2uUlJrq1KAVzJxyyoedQ4tlnJf6JhgjcJYQ= Received: from DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) by IA4PR10MB8756.namprd10.prod.outlook.com (2603:10b6:208:562::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.21; Tue, 18 Nov 2025 10:18:26 +0000 Received: from DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2]) by DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2%7]) with mapi id 15.20.9343.009; Tue, 18 Nov 2025 10:18:26 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Jonathan Corbet , David Hildenbrand , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jann Horn , Pedro Falcato , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Andrei Vagin Subject: [PATCH v4 3/9] mm: update vma_modify_flags() to handle residual flags, document Date: Tue, 18 Nov 2025 10:17:45 +0000 Message-ID: <23b5b549b0eaefb2922625626e58c2a352f3e93c.1763460113.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO4P265CA0233.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:315::19) 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_|IA4PR10MB8756:EE_ X-MS-Office365-Filtering-Correlation-Id: 2b101520-2a17-4fe5-3b0b-08de268bd01c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?E0lZsFGkWI4T5tNJ9T7sy5c0+tskS72mJ1hTyZ+OOyLbF5nXnS2K7C0jLhtK?= =?us-ascii?Q?tHLqy5O25pL+utcQRlrYII3OL+W4et117XVHMfpJNybuhUaTW/j3bXt9pQG9?= =?us-ascii?Q?RluY+rFEq2psy7fQ4tzE73Th52xcFBp/IC5hxe5t8/+CobAFTHLP4Zqni256?= =?us-ascii?Q?tSpIsHpr9CRkTOsW6l+PkPdzvennfGtwgLlLnNc0AEoIAb5++RkNJmNKQ0pK?= =?us-ascii?Q?WAmh7VCfgz/0OeoA3G7kEcLk+IFsRr7MMIc7IGBYIyVHG5SpgHM9oxr8L2UR?= =?us-ascii?Q?QOZQZzEGCMwaexGZdKUI8FE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?us-ascii?Q?AMeKX9ohbSoK1Kt23khYnmTjAGY4Pq/8RFW86ZNCcem9vPdb6ig7oe0HY4Et?= =?us-ascii?Q?up5t7a5qvFfNX48U0WDx98JGHZlwp33C312JHA3F2bJlhaGQ0mq1UsnqKBfk?= =?us-ascii?Q?ajBAaP9NNpnNXn4zN0P/02FCbrcQYHWZNOwWINszgDP+iT8Hd59TUEnIb6Q+?= =?us-ascii?Q?ditolfwv94V78oLEjNVLtpgrGkH+/1zVkCbxyfwt7cjNG9pPZ/naTEdapUj/?= =?us-ascii?Q?J+3+OhW4/ub0oini6KRui6af1ea1d76J?= 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)(376014)(7416014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?p89VmQDqKVMNX0Ez+4qA9DHPuRNRuO7TwEMH+RAlpqb1AxihN56fY0iXArc2?= =?us-ascii?Q?At/73v0SoQyplk31YOafNPkeByIgYCMdIjDZi4QSnxvHWA/tAmMptoQ3AbFp?= =?us-ascii?Q?nGJbeKeJt0ewTrMsmXmX1F8MsPWrjgAI6tHDkIpvd9BX4ypzC8FP7hbbSFCe?= =?us-ascii?Q?f5E1LFa5zSSDCUhfJRNM9npiZhWxBOPZRXW8UxMBK1b8gqhk6PheItqBXCSf?= =?us-ascii?Q?ZRwezK1PcX/mDIZZrZ9aFyqzRWIqJKCdTeHxFOuXnfXYFj7hLfU5mdiKBnwc?= =?us-ascii?Q?oCmpA9RzJBWqkeO2P9e3RniLZznfHlPNMGt/kxLZfgcNyxMbFHmyzOVbvR5d?= =?us-ascii?Q?cZI2rdRRj6RMAxECQO5y+PHoREAioE7zLy+5reJGMoyT5vaf/UfvsVp00KhD?= =?us-ascii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gEZLHz41Qta//MaIGhSGHRR8jhRvMQYztjKChKc= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2b101520-2a17-4fe5-3b0b-08de268bd01c X-MS-Exchange-CrossTenant-AuthSource: DM4PR10MB8218.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2025 10:18:26.8630 (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: FKuvUby7J0qLyjbVm/+IMu+z9JKDdE/3Drs6V2MptjcPd/vwHfUqvH8DqT9hJEJBLMKNUfZFhsTFbSaplQxZ/a7Xf9rUoQ13SNU/nIvPy94= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA4PR10MB8756 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-17_04,2025-11-13_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 mlxscore=0 bulkscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511180082 X-Proofpoint-ORIG-GUID: LxSxeTHVR9PLh_G3PcVWRbOPrEJBn8-Z X-Proofpoint-GUID: LxSxeTHVR9PLh_G3PcVWRbOPrEJBn8-Z X-Authority-Analysis: v=2.4 cv=I7xohdgg c=1 sm=1 tr=0 ts=691c4800 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=z/mQ4Ysz8XfWz/Q5cLBRGdckG28=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=xqWC_Br6kY4A:10 a=6UeiqGixMTsA:10 a=GoEa3M9JfhUA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=26E9mIcMOp5Dy7kpKFoA:9 a=nl4s5V0KI7Kw-pW0DWrs:22 a=pHzHmUro8NiASowvMSCR:22 a=xoEH_sTeL_Rfw54TyV31:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfXyiBhVJoCZ9aq oYtPSdOYfl3JMSwOQ5Inq904AeHb86NUf71PpgflLRGkXKYMVrD6lcdGA47kpnndoKjwmg4NDBi +NlMTt/nyiC++Hi6ZowPOcXqbOFjbvtuIz3CaqJosundFKJZ9k3GM3IEzC7NsCCtYb6g6V7++Gw TvRaObOVKS730TYJ+/PiVWaB5lXbxSbRJOjR7XortixWXGmoTgKzofHqtu6DNQ7c+KzgdQnpc4m 51BNl1Gs3UvGcyKvxZEQeQhF0X9rmeLWxp43XhGGqh/xjYEKIj6oWxulnnn4JTb04PZr1LT5BEe ZA94AmxS3qW3AgpFyLAZ70SUYBRq6TAs4D25cWUuVwUlqrQtvVtwjtKmE9WxzGgWbltozZ5kATU My9jpPXYQj9J8L5x9LXWCLP/uu+KRg== Content-Type: text/plain; charset="utf-8" The vma_modify_*() family of functions each either perform splits, a merge or no changes at all in preparation for the requested modification to occur. When doing so for a VMA flags change, we currently don't account for any flags which may remain (for instance, VM_SOFTDIRTY) despite the requested change in the case that a merge succeeded. This is made more important by subsequent patches which will introduce the concept of sticky VMA flags which rely on this behaviour. This patch fixes this by passing the VMA flags parameter as a pointer and updating it accordingly on merge and updating callers to accommodate for this. Additionally, while we are here, we add kdocs for each of the vma_modify_*() functions, as the fact that the requested modification is not performed is confusing so it is useful to make this abundantly clear. We also update the VMA userland tests to account for this change. Signed-off-by: Lorenzo Stoakes Reviewed-by: Pedro Falcato Reviewed-by: Vlastimil Babka --- mm/madvise.c | 2 +- mm/mlock.c | 2 +- mm/mprotect.c | 2 +- mm/mseal.c | 9 +-- mm/vma.c | 56 ++++++++-------- mm/vma.h | 140 +++++++++++++++++++++++++++++----------- tools/testing/vma/vma.c | 3 +- 7 files changed, 144 insertions(+), 70 deletions(-) diff --git a/mm/madvise.c b/mm/madvise.c index fb1c86e630b6..0b3280752bfb 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -167,7 +167,7 @@ static int madvise_update_vma(vm_flags_t new_flags, range->start, range->end, anon_name); else vma =3D vma_modify_flags(&vmi, madv_behavior->prev, vma, - range->start, range->end, new_flags); + range->start, range->end, &new_flags); =20 if (IS_ERR(vma)) return PTR_ERR(vma); diff --git a/mm/mlock.c b/mm/mlock.c index bb0776f5ef7c..2f699c3497a5 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -478,7 +478,7 @@ static int mlock_fixup(struct vma_iterator *vmi, struct= vm_area_struct *vma, /* don't set VM_LOCKED or VM_LOCKONFAULT and don't count */ goto out; =20 - vma =3D vma_modify_flags(vmi, *prev, vma, start, end, newflags); + vma =3D vma_modify_flags(vmi, *prev, vma, start, end, &newflags); if (IS_ERR(vma)) { ret =3D PTR_ERR(vma); goto out; diff --git a/mm/mprotect.c b/mm/mprotect.c index ab4e06cd9a69..db93d3bb1a5e 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -756,7 +756,7 @@ mprotect_fixup(struct vma_iterator *vmi, struct mmu_gat= her *tlb, newflags &=3D ~VM_ACCOUNT; } =20 - vma =3D vma_modify_flags(vmi, *pprev, vma, start, end, newflags); + vma =3D vma_modify_flags(vmi, *pprev, vma, start, end, &newflags); if (IS_ERR(vma)) { error =3D PTR_ERR(vma); goto fail; diff --git a/mm/mseal.c b/mm/mseal.c index e5b205562d2e..ae442683c5c0 100644 --- a/mm/mseal.c +++ b/mm/mseal.c @@ -66,12 +66,13 @@ static int mseal_apply(struct mm_struct *mm, prev =3D vma; =20 for_each_vma_range(vmi, vma, end) { - unsigned long curr_end =3D MIN(vma->vm_end, end); + const unsigned long curr_end =3D MIN(vma->vm_end, end); =20 if (!(vma->vm_flags & VM_SEALED)) { - vma =3D vma_modify_flags(&vmi, prev, vma, - curr_start, curr_end, - vma->vm_flags | VM_SEALED); + vm_flags_t vm_flags =3D vma->vm_flags | VM_SEALED; + + vma =3D vma_modify_flags(&vmi, prev, vma, curr_start, + curr_end, &vm_flags); if (IS_ERR(vma)) return PTR_ERR(vma); vm_flags_set(vma, VM_SEALED); diff --git a/mm/vma.c b/mm/vma.c index 0c5e391fe2e2..47469c036a72 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -1638,25 +1638,35 @@ static struct vm_area_struct *vma_modify(struct vma= _merge_struct *vmg) return vma; } =20 -struct vm_area_struct *vma_modify_flags( - struct vma_iterator *vmi, struct vm_area_struct *prev, - struct vm_area_struct *vma, unsigned long start, unsigned long end, - vm_flags_t vm_flags) +struct vm_area_struct *vma_modify_flags(struct vma_iterator *vmi, + struct vm_area_struct *prev, struct vm_area_struct *vma, + unsigned long start, unsigned long end, + vm_flags_t *vm_flags_ptr) { VMG_VMA_STATE(vmg, vmi, prev, vma, start, end); + const vm_flags_t vm_flags =3D *vm_flags_ptr; + struct vm_area_struct *ret; =20 vmg.vm_flags =3D vm_flags; =20 - return vma_modify(&vmg); + ret =3D vma_modify(&vmg); + if (IS_ERR(ret)) + return ret; + + /* + * For a merge to succeed, the flags must match those requested. For + * flags which do not obey typical merge rules (i.e. do not need to + * match), we must let the caller know about them. + */ + if (vmg.state =3D=3D VMA_MERGE_SUCCESS) + *vm_flags_ptr =3D ret->vm_flags; + return ret; } =20 -struct vm_area_struct -*vma_modify_name(struct vma_iterator *vmi, - struct vm_area_struct *prev, - struct vm_area_struct *vma, - unsigned long start, - unsigned long end, - struct anon_vma_name *new_name) +struct vm_area_struct *vma_modify_name(struct vma_iterator *vmi, + struct vm_area_struct *prev, struct vm_area_struct *vma, + unsigned long start, unsigned long end, + struct anon_vma_name *new_name) { VMG_VMA_STATE(vmg, vmi, prev, vma, start, end); =20 @@ -1665,12 +1675,10 @@ struct vm_area_struct return vma_modify(&vmg); } =20 -struct vm_area_struct -*vma_modify_policy(struct vma_iterator *vmi, - struct vm_area_struct *prev, - struct vm_area_struct *vma, - unsigned long start, unsigned long end, - struct mempolicy *new_pol) +struct vm_area_struct *vma_modify_policy(struct vma_iterator *vmi, + struct vm_area_struct *prev, struct vm_area_struct *vma, + unsigned long start, unsigned long end, + struct mempolicy *new_pol) { VMG_VMA_STATE(vmg, vmi, prev, vma, start, end); =20 @@ -1679,14 +1687,10 @@ struct vm_area_struct return vma_modify(&vmg); } =20 -struct vm_area_struct -*vma_modify_flags_uffd(struct vma_iterator *vmi, - struct vm_area_struct *prev, - struct vm_area_struct *vma, - unsigned long start, unsigned long end, - vm_flags_t vm_flags, - struct vm_userfaultfd_ctx new_ctx, - bool give_up_on_oom) +struct vm_area_struct *vma_modify_flags_uffd(struct vma_iterator *vmi, + struct vm_area_struct *prev, struct vm_area_struct *vma, + unsigned long start, unsigned long end, vm_flags_t vm_flags, + struct vm_userfaultfd_ctx new_ctx, bool give_up_on_oom) { VMG_VMA_STATE(vmg, vmi, prev, vma, start, end); =20 diff --git a/mm/vma.h b/mm/vma.h index e912d42c428a..75f1d9c7204b 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -263,47 +263,115 @@ void remove_vma(struct vm_area_struct *vma); void unmap_region(struct ma_state *mas, struct vm_area_struct *vma, struct vm_area_struct *prev, struct vm_area_struct *next); =20 -/* We are about to modify the VMA's flags. */ -__must_check struct vm_area_struct -*vma_modify_flags(struct vma_iterator *vmi, +/** + * vma_modify_flags() - Peform any necessary split/merge in preparation for + * setting VMA flags to *@vm_flags in the range @start to @end contained w= ithin + * @vma. + * @vmi: Valid VMA iterator positioned at @vma. + * @prev: The VMA immediately prior to @vma or NULL if @vma is the first. + * @vma: The VMA containing the range @start to @end to be updated. + * @start: The start of the range to update. May be offset within @vma. + * @end: The exclusive end of the range to update, may be offset within @v= ma. + * @vm_flags_ptr: A pointer to the VMA flags that the @start to @end range= is + * about to be set to. On merge, this will be updated to include any addit= ional + * flags which remain in place. + * + * IMPORTANT: The actual modification being requested here is NOT applied, + * rather the VMA is perhaps split, perhaps merged to accommodate the chan= ge, + * and the caller is expected to perform the actual modification. + * + * In order to account for VMA flags which may persist (e.g. soft-dirty), = the + * @vm_flags_ptr parameter points to the requested flags which are then up= dated + * so the caller, should they overwrite any existing flags, correctly reta= ins + * these. + * + * Returns: A VMA which contains the range @start to @end ready to have its + * flags altered to *@vm_flags. + */ +__must_check struct vm_area_struct *vma_modify_flags(struct vma_iterator *= vmi, + struct vm_area_struct *prev, struct vm_area_struct *vma, + unsigned long start, unsigned long end, + vm_flags_t *vm_flags_ptr); + +/** + * vma_modify_name() - Peform any necessary split/merge in preparation for + * setting anonymous VMA name to @new_name in the range @start to @end con= tained + * within @vma. + * @vmi: Valid VMA iterator positioned at @vma. + * @prev: The VMA immediately prior to @vma or NULL if @vma is the first. + * @vma: The VMA containing the range @start to @end to be updated. + * @start: The start of the range to update. May be offset within @vma. + * @end: The exclusive end of the range to update, may be offset within @v= ma. + * @new_name: The anonymous VMA name that the @start to @end range is abou= t to + * be set to. + * + * IMPORTANT: The actual modification being requested here is NOT applied, + * rather the VMA is perhaps split, perhaps merged to accommodate the chan= ge, + * and the caller is expected to perform the actual modification. + * + * Returns: A VMA which contains the range @start to @end ready to have its + * anonymous VMA name changed to @new_name. + */ +__must_check struct vm_area_struct *vma_modify_name(struct vma_iterator *v= mi, struct vm_area_struct *prev, struct vm_area_struct *vma, unsigned long start, unsigned long end, - vm_flags_t vm_flags); - -/* We are about to modify the VMA's anon_name. */ -__must_check struct vm_area_struct -*vma_modify_name(struct vma_iterator *vmi, - struct vm_area_struct *prev, - struct vm_area_struct *vma, - unsigned long start, - unsigned long end, - struct anon_vma_name *new_name); - -/* We are about to modify the VMA's memory policy. */ -__must_check struct vm_area_struct -*vma_modify_policy(struct vma_iterator *vmi, - struct vm_area_struct *prev, - struct vm_area_struct *vma, + struct anon_vma_name *new_name); + +/** + * vma_modify_policy() - Peform any necessary split/merge in preparation f= or + * setting NUMA policy to @new_pol in the range @start to @end contained + * within @vma. + * @vmi: Valid VMA iterator positioned at @vma. + * @prev: The VMA immediately prior to @vma or NULL if @vma is the first. + * @vma: The VMA containing the range @start to @end to be updated. + * @start: The start of the range to update. May be offset within @vma. + * @end: The exclusive end of the range to update, may be offset within @v= ma. + * @new_pol: The NUMA policy that the @start to @end range is about to be = set + * to. + * + * IMPORTANT: The actual modification being requested here is NOT applied, + * rather the VMA is perhaps split, perhaps merged to accommodate the chan= ge, + * and the caller is expected to perform the actual modification. + * + * Returns: A VMA which contains the range @start to @end ready to have its + * NUMA policy changed to @new_pol. + */ +__must_check struct vm_area_struct *vma_modify_policy(struct vma_iterator = *vmi, + struct vm_area_struct *prev, struct vm_area_struct *vma, unsigned long start, unsigned long end, struct mempolicy *new_pol); =20 -/* We are about to modify the VMA's flags and/or uffd context. */ -__must_check struct vm_area_struct -*vma_modify_flags_uffd(struct vma_iterator *vmi, - struct vm_area_struct *prev, - struct vm_area_struct *vma, - unsigned long start, unsigned long end, - vm_flags_t vm_flags, - struct vm_userfaultfd_ctx new_ctx, - bool give_up_on_oom); - -__must_check struct vm_area_struct -*vma_merge_new_range(struct vma_merge_struct *vmg); - -__must_check struct vm_area_struct -*vma_merge_extend(struct vma_iterator *vmi, - struct vm_area_struct *vma, - unsigned long delta); +/** + * vma_modify_flags_uffd() - Peform any necessary split/merge in preparati= on for + * setting VMA flags to @vm_flags and UFFD context to @new_ctx in the range + * @start to @end contained within @vma. + * @vmi: Valid VMA iterator positioned at @vma. + * @prev: The VMA immediately prior to @vma or NULL if @vma is the first. + * @vma: The VMA containing the range @start to @end to be updated. + * @start: The start of the range to update. May be offset within @vma. + * @end: The exclusive end of the range to update, may be offset within @v= ma. + * @vm_flags: The VMA flags that the @start to @end range is about to be s= et to. + * @new_ctx: The userfaultfd context that the @start to @end range is abou= t to + * be set to. + * @give_up_on_oom: If an out of memory condition occurs on merge, simply = give + * up on it and treat the merge as best-effort. + * + * IMPORTANT: The actual modification being requested here is NOT applied, + * rather the VMA is perhaps split, perhaps merged to accommodate the chan= ge, + * and the caller is expected to perform the actual modification. + * + * Returns: A VMA which contains the range @start to @end ready to have it= s VMA + * flags changed to @vm_flags and its userfaultfd context changed to @new_= ctx. + */ +__must_check struct vm_area_struct *vma_modify_flags_uffd(struct vma_itera= tor *vmi, + struct vm_area_struct *prev, struct vm_area_struct *vma, + unsigned long start, unsigned long end, vm_flags_t vm_flags, + struct vm_userfaultfd_ctx new_ctx, bool give_up_on_oom); + +__must_check struct vm_area_struct *vma_merge_new_range(struct vma_merge_s= truct *vmg); + +__must_check struct vm_area_struct *vma_merge_extend(struct vma_iterator *= vmi, + struct vm_area_struct *vma, unsigned long delta); =20 void unlink_file_vma_batch_init(struct unlink_vma_file_batch *vb); =20 diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index 656e1c75b711..fd37ce3b2628 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -339,6 +339,7 @@ static bool test_simple_modify(void) struct mm_struct mm =3D {}; struct vm_area_struct *init_vma =3D alloc_vma(&mm, 0, 0x3000, 0, vm_flags= ); VMA_ITERATOR(vmi, &mm, 0x1000); + vm_flags_t flags =3D VM_READ | VM_MAYREAD; =20 ASSERT_FALSE(attach_vma(&mm, init_vma)); =20 @@ -347,7 +348,7 @@ static bool test_simple_modify(void) * performs the merge/split only. */ vma =3D vma_modify_flags(&vmi, init_vma, init_vma, - 0x1000, 0x2000, VM_READ | VM_MAYREAD); + 0x1000, 0x2000, &flags); ASSERT_NE(vma, NULL); /* We modify the provided VMA, and on split allocate new VMAs. */ ASSERT_EQ(vma, init_vma); --=20 2.51.2 From nobody Tue Dec 2 02:43:46 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 EB15D33F8B2; Tue, 18 Nov 2025 10:19:35 +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=1763461181; cv=fail; b=XFWmPzq7fudgsG31DqB408fgeH6RDMkZLEqxlZEyBLAFF3uEcfZiz48zns4tO1Ox13ApssKotC0s0izHKmDY+gN9218aro+e+dIOZAOIAfzZg/GLS5SMg3rT9G742wlM9pR7TrwFocJA0m4pyQ1L7vhvOAZyaK8pBONR5+NXCIM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763461181; c=relaxed/simple; bh=geLtrW22BvPJKsPgl4hHg6rdSomU1hs68hzuj7mVgOA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=j4pJWXx8INk0+biNKQBSrdSdkrbOXoDj60k8qWab8A4xKx/enbXIflCskS3Pr70ECiYJ++7sozM1xe1ZjqFRc21whoDNIDyaYDbqijEHZS8zDVQwzs5Zr0CX50yDUqvmPt8NBhviz5K1TPj0Vrhyo9CDapKNRd+asSYI0aY1AWw= 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=iolQeH65; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=rOBd96s8; 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="iolQeH65"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="rOBd96s8" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AI9D0Zv027166; Tue, 18 Nov 2025 10:18:41 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-2025-04-25; bh=dhN0cw2MkNAa5NhIo6p0CINErscRVjVYz/rtyQaDjwI=; b= iolQeH6513Ro4RYNNcMk4dm2ANvWod53QcceD68EtGxe6SgcD8jmV/SlkAc+ePLA 4XJvAW0n8NrhsUvnlo46emKzP140PitvD3Szu7mRoGCTNEacJm94OR+rh+4fb/1S HszqfJ96m5m8gkGptSSprcSsuWMR//PZ8RDt8XRphzGTL2M4SPVNVrsMKw37lcSW uCRjF1ei3OYLqK0zwjMLcrxttWiuasg2lLfaUiJJ6sLJlkJzy0GQAyN/nwa+0wPI d84sw4j1KZodArEXyIiJ6GOw5xTRmZeaDl9P2VqcBDzinNsI/aGK9uxjRKEYXlGT RqQvKOJORygHAh14LkBDig== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejd1cgcp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:41 +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 5AI9NsrW040040; Tue, 18 Nov 2025 10:18:39 GMT Received: from sn4pr0501cu005.outbound.protection.outlook.com (mail-southcentralusazon11011045.outbound.protection.outlook.com [40.93.194.45]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyk8qpj-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:39 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=D4THUG1iLpfvb/me6J/DKHmhR7T69IzE/yPZsjQkGik0EgZqRPUrnObVsU946K06FaFSFJVWcjyBbJGg3TaBnN1QH9FKr8jdgeqmG+V0EYFHvnai9dSDn91Nk8bl0k+r8IHBIOEJASY8Gbkhfn9L2OoXfeSzFBOFMslSI2rRVgwW5lMLa0oiwWvlaUTkcCxgbR98qcEoueezXujPCR4QW+5Qu9ocTRFB3djSbvVXjrBWxlrgC+7UeAcGCej5rzucP5h8GK4Ov2WV0tRTt8fklbupeLHYVNv5fwB06MD4K828f1OyOBGEprFv87Okx37XxWp+FDjsUyCAhJsRovBmGA== 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=dhN0cw2MkNAa5NhIo6p0CINErscRVjVYz/rtyQaDjwI=; b=NsxtbWc/lqEaS/T48+rARPnU4NihezG3ALbyWg/k+KSM81LFlVm7UhrtpJgdjJQ8imRskzfJahTm0eTXgfxVCXx+re9zXzupFjVefUaB6hD5W0XPMCMIr+yk135KcnjShJN5tRzoVD4jBguBk/XeiglPNrdrBjdl0fMJr8PT6TrQekuqILO/J83LzAM6QlJlMlXn4cGwEHKdyZyPTyu7PO2WkTjbJKr1vNDlBQl7yIf3iOK/NUg7t5T9GKx2/SNwfXgqkkSRwMtnqgq+N9daTqkV2U7SrEQr5CrvnIY0VSBkRYW4XnKujO4q9b0bW+RVHlrjIB3OlnZ09OIj5xJ8RA== 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=dhN0cw2MkNAa5NhIo6p0CINErscRVjVYz/rtyQaDjwI=; b=rOBd96s8YXXJpbdcfHFQ+FCxSdi2beXQJPmhgdcUbnRPR/0pnfmOHTDrBMbsPkXoT9wXK9bzxg1SIEF4ZHR2QuyAMFLt/9HR1/FDXqUPAW5bOE1Z8uoFehqE4oHSSZt7olzZF4Ldq1btu2wggDuVyAm/LCKiYcS92WxmQc+16nk= Received: from DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) by IA4PR10MB8756.namprd10.prod.outlook.com (2603:10b6:208:562::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.21; Tue, 18 Nov 2025 10:18:29 +0000 Received: from DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2]) by DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2%7]) with mapi id 15.20.9343.009; Tue, 18 Nov 2025 10:18:29 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Jonathan Corbet , David Hildenbrand , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jann Horn , Pedro Falcato , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Andrei Vagin Subject: [PATCH v4 4/9] mm: implement sticky VMA flags Date: Tue, 18 Nov 2025 10:17:46 +0000 Message-ID: <22ad5269f7669d62afb42ce0c79bad70b994c58d.1763460113.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO3P123CA0032.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:388::8) 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_|IA4PR10MB8756:EE_ X-MS-Office365-Filtering-Correlation-Id: cfde6300-7dd0-4e88-7b36-08de268bd174 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?++gKAVomyLQplW9BZKidDFAz+4Axt/u0JwY5AQUZCflC9N27X9Rw1PLUiZo5?= =?us-ascii?Q?bSb/FzHQCttXKfg+ll4Pc9Hszi+kCq/bdvnuORDFYYTjtOY+E7q9NgATwXIA?= =?us-ascii?Q?Jhp048l44MRMLzZMcYKOSA34X7e3WPCWCIGnPcGAVvLSQiKyNhxWVPom6NkB?= =?us-ascii?Q?s4uaWexCXUX+JGblbI1lc89jpTdxrLRpTIqBUjdwaqPMgKxBwNxt0LCJKmQv?= =?us-ascii?Q?kgviU64R6LmMqm2YWvoqQLthiK/o1dxvsWcHjq7ywZjSBW5fsX91bMXocqBk?= =?us-ascii?Q?VOKRDbylaF7bERnUEO9BRhLgtJz+XI9YsGwCfJmK+9eFCWO1lBWQ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ZGO68wErX24IQxQ2vf4ElECk6foJ/kcIEH3pIJ28t?= =?us-ascii?Q?q0Aapc0To4bHgMpGBXYQf7DulmH3vxhOdynLYCRMN1hpcHH9BYdbAllvv9n+?= =?us-ascii?Q?nkporlYSSEJ+vFtR+UmsGx8tDVze4UakpDR0CgoULa454+QdPBstr3z2i9+R?= =?us-ascii?Q?b9dWyanbV2UYsN/DehQv1ny86JwDJMTI7dkzgaIPPa4Uhhy16Y/vIG1UbE7q?= =?us-ascii?Q?C78PA6scCGK82GVOkNAW3i2kXEtJKEp4?= 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)(376014)(7416014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?5uWJsLKVoC/f7lCkTAxskj2IhlsfkbVUeJDrkvTZ+y3OeEAc6icpv0zcliFN?= =?us-ascii?Q?vLYa21hWLPvxlFSumozHdGIrbSyEE5oQrdOMg30DfUY3p8fyfpXG4vCi2KrO?= =?us-ascii?Q?ZIyYan0LJxS7GTPlDZZAQ0z6NNAOUxaUO33b+as+v63SdA6jaSDzxIOA+Umr?= =?us-ascii?Q?T0yVFyduIHoCB/xlVk6KQLVGmEZZM8tzWO+QyJPHPPEB1V/67HR7l8WIEmiU?= =?us-ascii?Q?EzkKufa2X1C8M5unHbvEg/FRCik2u5HptpoiEgpgYP7/N5cO+OOTxVftOFTx?= =?us-ascii?Q?Pcf2qf6Kg5VT87mgcZlrle67sFQm+9cHtZB+wBjblNLm2XpsuMJRoAuVhXEH?= =?us-ascii?Q?yB3VVCZaTUdmWOfSAnf4IrcULnXY2mbSc0A1g1cA/ssawi9qgmDmDY8Jinac?= =?us-ascii?Q?syeBlXe+edP6Duhs7TXI1v52taTNjnBz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-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: cfde6300-7dd0-4e88-7b36-08de268bd174 X-MS-Exchange-CrossTenant-AuthSource: DM4PR10MB8218.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2025 10:18:29.0177 (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: XzsfRo8KPO7AMnVw9KPKFMd8ePLh8vTfL9lTKErmVFg6e34qVcHvJQp8z6dUSEYuIc6rQyzKDbeRpT+YExqarARRxxasxKA7KXLYR0n2OI4= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA4PR10MB8756 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-17_04,2025-11-13_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 spamscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511180082 X-Proofpoint-GUID: DNFPtyyyJptgHjogJZKm6_LXqzolR-Xe X-Authority-Analysis: v=2.4 cv=Z/jh3XRA c=1 sm=1 tr=0 ts=691c4801 b=1 cx=c_pps a=qoll8+KPOyaMroiJ2sR5sw==:117 a=qoll8+KPOyaMroiJ2sR5sw==:17 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=z/mQ4Ysz8XfWz/Q5cLBRGdckG28=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=xqWC_Br6kY4A:10 a=6UeiqGixMTsA:10 a=GoEa3M9JfhUA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=rpsWnT2a9RKTKGOQHl4A:9 cc=ntf awl=host:12099 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX7cyRBhWNbkwJ vBEXyOYRMMj5bYR4wBGef5q4k8btaT/sphA8OKjIWvNrF+Io/z504VdgPO1bkAit+hDT1arzGA4 /gUb1xODwaU8hE30qs4WBCiBa4pJGC0QcyJtz4y469u2vqfYz3sE7gQb5TUe0O5tmZPvXUDdFUm y9fKbpTNvb1SHBOszjqMo6z/Byad1wb5jZ5Kau9TMMRXQGcY8jSu68bNPqgmwDinZ0qpWkODrWt LyXL9B9uUxmh46cfqoYWJX26rPqyQhUsE5pflxqiE4PZCAeQKPAu/VgX2QY7mJo75UkBt9lsq8o DK8O/AyN0slAE0u77zn+DkPNzc+dKUBeTO5VRfBYYakB/2IX8iG3jlUG/CkdKqmAnUqw/7weghO MILGPOpW41lb3i94lw/vfZmOHff0pmKTJ7vSISxwNjdXN9dhMeg= X-Proofpoint-ORIG-GUID: DNFPtyyyJptgHjogJZKm6_LXqzolR-Xe Content-Type: text/plain; charset="utf-8" It is useful to be able to designate that certain flags are 'sticky', that is, if two VMAs are merged one with a flag of this nature and one without, the merged VMA sets this flag. As a result we ignore these flags for the purposes of determining VMA flag differences between VMAs being considered for merge. This patch therefore updates the VMA merge logic to perform this action, with flags possessing this property being described in the VM_STICKY bitmap. Those flags which ought to be ignored for the purposes of VMA merge are described in the VM_IGNORE_MERGE bitmap, which the VMA merge logic is also updated to use. As part of this change we place VM_SOFTDIRTY in VM_IGNORE_MERGE as it already had this behaviour, alongside VM_STICKY as sticky flags by implication must not disallow merge. Ultimately it seems that we should make VM_SOFTDIRTY a sticky flag in its own right, but this change is out of scope for this series. The only sticky flag designated as such is VM_MAYBE_GUARD, so as a result of this change, once the VMA flag is set upon guard region installation, VMAs with guard ranges will now not have their merge behaviour impacted as a result and can be freely merged with other VMAs without VM_MAYBE_GUARD set. Also update the comments for vma_modify_flags() to directly reference sticky flags now we have established the concept. We also update the VMA userland tests to account for the changes. Signed-off-by: Lorenzo Stoakes Reviewed-by: Pedro Falcato Reviewed-by: Vlastimil Babka Acked-by: David Hildenbrand (Red Hat) --- include/linux/mm.h | 28 ++++++++++++++++++++++++++++ mm/vma.c | 28 +++++++++++++++------------- mm/vma.h | 10 ++++------ tools/testing/vma/vma_internal.h | 28 ++++++++++++++++++++++++++++ 4 files changed, 75 insertions(+), 19 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 03776aab3837..fea113d1d723 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -527,6 +527,34 @@ extern unsigned int kobjsize(const void *objp); #endif #define VM_FLAGS_CLEAR (ARCH_VM_PKEY_FLAGS | VM_ARCH_CLEAR) =20 +/* + * Flags which should be 'sticky' on merge - that is, flags which, when on= e VMA + * possesses it but the other does not, the merged VMA should nonetheless = have + * applied to it: + * + * VM_MAYBE_GUARD - If a VMA may have guard regions in place it implies th= at + * mapped page tables may contain metadata not described = by the + * VMA and thus any merged VMA may also contain this meta= data, + * and thus we must make this flag sticky. + */ +#define VM_STICKY VM_MAYBE_GUARD + +/* + * VMA flags we ignore for the purposes of merge, i.e. one VMA possessing = one + * of these flags and the other not does not preclude a merge. + * + * VM_SOFTDIRTY - Should not prevent from VMA merging, if we match the fla= gs but + * dirty bit -- the caller should mark merged VMA as dirty.= If + * dirty bit won't be excluded from comparison, we increase + * pressure on the memory system forcing the kernel to gene= rate + * new VMAs when old one could be extended instead. + * + * VM_STICKY - When merging VMAs, VMA flags must match, unless they are + * 'sticky'. If any sticky flags exist in either VMA, we si= mply + * set all of them on the merged VMA. + */ +#define VM_IGNORE_MERGE (VM_SOFTDIRTY | VM_STICKY) + /* * mapping from the currently active vm_flags protection bits (the * low four bits) to a page protection mask.. diff --git a/mm/vma.c b/mm/vma.c index 47469c036a72..4e21c988054d 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -89,15 +89,7 @@ static inline bool is_mergeable_vma(struct vma_merge_str= uct *vmg, bool merge_nex =20 if (!mpol_equal(vmg->policy, vma_policy(vma))) return false; - /* - * VM_SOFTDIRTY should not prevent from VMA merging, if we - * match the flags but dirty bit -- the caller should mark - * merged VMA as dirty. If dirty bit won't be excluded from - * comparison, we increase pressure on the memory system forcing - * the kernel to generate new VMAs when old one could be - * extended instead. - */ - if ((vma->vm_flags ^ vmg->vm_flags) & ~VM_SOFTDIRTY) + if ((vma->vm_flags ^ vmg->vm_flags) & ~VM_IGNORE_MERGE) return false; if (vma->vm_file !=3D vmg->file) return false; @@ -808,6 +800,7 @@ static bool can_merge_remove_vma(struct vm_area_struct = *vma) static __must_check struct vm_area_struct *vma_merge_existing_range( struct vma_merge_struct *vmg) { + vm_flags_t sticky_flags =3D vmg->vm_flags & VM_STICKY; struct vm_area_struct *middle =3D vmg->middle; struct vm_area_struct *prev =3D vmg->prev; struct vm_area_struct *next; @@ -900,11 +893,13 @@ static __must_check struct vm_area_struct *vma_merge_= existing_range( if (merge_right) { vma_start_write(next); vmg->target =3D next; + sticky_flags |=3D (next->vm_flags & VM_STICKY); } =20 if (merge_left) { vma_start_write(prev); vmg->target =3D prev; + sticky_flags |=3D (prev->vm_flags & VM_STICKY); } =20 if (merge_both) { @@ -974,6 +969,7 @@ static __must_check struct vm_area_struct *vma_merge_ex= isting_range( if (err || commit_merge(vmg)) goto abort; =20 + vm_flags_set(vmg->target, sticky_flags); khugepaged_enter_vma(vmg->target, vmg->vm_flags); vmg->state =3D VMA_MERGE_SUCCESS; return vmg->target; @@ -1124,6 +1120,10 @@ int vma_expand(struct vma_merge_struct *vmg) bool remove_next =3D false; struct vm_area_struct *target =3D vmg->target; struct vm_area_struct *next =3D vmg->next; + vm_flags_t sticky_flags; + + sticky_flags =3D vmg->vm_flags & VM_STICKY; + sticky_flags |=3D target->vm_flags & VM_STICKY; =20 VM_WARN_ON_VMG(!target, vmg); =20 @@ -1133,6 +1133,7 @@ int vma_expand(struct vma_merge_struct *vmg) if (next && (target !=3D next) && (vmg->end =3D=3D next->vm_end)) { int ret; =20 + sticky_flags |=3D next->vm_flags & VM_STICKY; remove_next =3D true; /* This should already have been checked by this point. */ VM_WARN_ON_VMG(!can_merge_remove_vma(next), vmg); @@ -1159,6 +1160,7 @@ int vma_expand(struct vma_merge_struct *vmg) if (commit_merge(vmg)) goto nomem; =20 + vm_flags_set(target, sticky_flags); return 0; =20 nomem: @@ -1654,9 +1656,9 @@ struct vm_area_struct *vma_modify_flags(struct vma_it= erator *vmi, return ret; =20 /* - * For a merge to succeed, the flags must match those requested. For - * flags which do not obey typical merge rules (i.e. do not need to - * match), we must let the caller know about them. + * For a merge to succeed, the flags must match those + * requested. However, sticky flags may have been retained, so propagate + * them to the caller. */ if (vmg.state =3D=3D VMA_MERGE_SUCCESS) *vm_flags_ptr =3D ret->vm_flags; @@ -1906,7 +1908,7 @@ static int anon_vma_compatible(struct vm_area_struct = *a, struct vm_area_struct * return a->vm_end =3D=3D b->vm_start && mpol_equal(vma_policy(a), vma_policy(b)) && a->vm_file =3D=3D b->vm_file && - !((a->vm_flags ^ b->vm_flags) & ~(VM_ACCESS_FLAGS | VM_SOFTDIRTY)) && + !((a->vm_flags ^ b->vm_flags) & ~(VM_ACCESS_FLAGS | VM_IGNORE_MERGE)) && b->vm_pgoff =3D=3D a->vm_pgoff + ((b->vm_start - a->vm_start) >> PAGE_SH= IFT); } =20 diff --git a/mm/vma.h b/mm/vma.h index 75f1d9c7204b..abada6a64c4e 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -273,17 +273,15 @@ void unmap_region(struct ma_state *mas, struct vm_are= a_struct *vma, * @start: The start of the range to update. May be offset within @vma. * @end: The exclusive end of the range to update, may be offset within @v= ma. * @vm_flags_ptr: A pointer to the VMA flags that the @start to @end range= is - * about to be set to. On merge, this will be updated to include any addit= ional - * flags which remain in place. + * about to be set to. On merge, this will be updated to include sticky fl= ags. * * IMPORTANT: The actual modification being requested here is NOT applied, * rather the VMA is perhaps split, perhaps merged to accommodate the chan= ge, * and the caller is expected to perform the actual modification. * - * In order to account for VMA flags which may persist (e.g. soft-dirty), = the - * @vm_flags_ptr parameter points to the requested flags which are then up= dated - * so the caller, should they overwrite any existing flags, correctly reta= ins - * these. + * In order to account for sticky VMA flags, the @vm_flags_ptr parameter p= oints + * to the requested flags which are then updated so the caller, should they + * overwrite any existing flags, correctly retains these. * * Returns: A VMA which contains the range @start to @end ready to have its * flags altered to *@vm_flags. diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_inter= nal.h index 46acb4df45de..73c2025777e6 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -117,6 +117,34 @@ extern unsigned long dac_mmap_min_addr; #define VM_SEALED VM_NONE #endif =20 +/* + * Flags which should be 'sticky' on merge - that is, flags which, when on= e VMA + * possesses it but the other does not, the merged VMA should nonetheless = have + * applied to it: + * + * VM_MAYBE_GUARD - If a VMA may have guard regions in place it implies th= at + * mapped page tables may contain metadata not described = by the + * VMA and thus any merged VMA may also contain this meta= data, + * and thus we must make this flag sticky. + */ +#define VM_STICKY VM_MAYBE_GUARD + +/* + * VMA flags we ignore for the purposes of merge, i.e. one VMA possessing = one + * of these flags and the other not does not preclude a merge. + * + * VM_SOFTDIRTY - Should not prevent from VMA merging, if we match the fla= gs but + * dirty bit -- the caller should mark merged VMA as dirty.= If + * dirty bit won't be excluded from comparison, we increase + * pressure on the memory system forcing the kernel to gene= rate + * new VMAs when old one could be extended instead. + * + * VM_STICKY - When merging VMAs, VMA flags must match, unless they are + * 'sticky'. If any sticky flags exist in either VMA, we si= mply + * set all of them on the merged VMA. + */ +#define VM_IGNORE_MERGE (VM_SOFTDIRTY | VM_STICKY) + #define FIRST_USER_ADDRESS 0UL #define USER_PGTABLES_CEILING 0UL =20 --=20 2.51.2 From nobody Tue Dec 2 02:43:46 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 29ABB3469EC; Tue, 18 Nov 2025 10:19:41 +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=1763461187; cv=fail; b=X7CbqcWgA5GOpA9kGRhoknjercI1fSXh/5jxa00Ps98DqeCxEQLMGCJP2dJNzxdOTUgUqRUwCzr5qjMtQXQBdUNNFwd7SzWV9RoRvf1NsnBeSyPce7LFe06AR3+ju8Ns1QdgaF7Qi7pOH2D9Vzk4znZ4y5+n2VJGZik/Mpp6imE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763461187; c=relaxed/simple; bh=QnQcnOxovO4S7zCugiGwGLr4Ev8Mi69WxfyWLQnpBOo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=qHCC84zZPUUQ5MBsttgxgV7spNv0DflVZ1a1WUWP3SGVTSgESygn6Tk0FMs6jDxFRWXBAKtw05SEM6DqPdow9qJgXgb4V2uP9SO/n1+GaGCJLXvzECMdlOBTTpAemgPVjA5kW+M1QJCZf2OWw9SBOcQek4wYa7O3iU0lNG5nixY= 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=kSBP5eQQ; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=WCSDnmrQ; 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="kSBP5eQQ"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="WCSDnmrQ" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AI9CcQZ008436; Tue, 18 Nov 2025 10:18:41 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-2025-04-25; bh=8+qMUa249jGesoN0N9VZs8Tj7kmeN3hEi+xQZzoB/bQ=; b= kSBP5eQQH3u91rhHkKQtefyVlL+8qpnFsIT9m0psyfNHi10TuH/NlKzCcrt3GmUm /CnNi6OsCVQWQnHGMSRTya9E6ApPjuD9lzp24zpbxl6xW1y+dRc/4DKaErIW4s49 HrL8lnlymjiZprXDvCY/S4UibGA8L6f2SOibPk3fg/sxffh+O2qV428Zk8nn3yIp 7KZSR9slS1r2D5hI8rQOQJyFESXpVOmEGsk+r8LUyl+l5Zn7JBuXDkD0RxZy2Qc9 F5RvBTpfswQB8YRMN6VKywvVpWtoWTEM1wJDVVw1NnukckAQN7Bb8w2WyWFc8A0+ FrqVqhHcxD+4ZR0xQtN21Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aej964gyv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:40 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5AI8wjfo004268; Tue, 18 Nov 2025 10:18:40 GMT Received: from dm1pr04cu001.outbound.protection.outlook.com (mail-centralusazon11010048.outbound.protection.outlook.com [52.101.61.48]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefy8pp85-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=gTlxx7Pff/wkeQCeM7kDX8EKeR0hBOxEyyspZ3wUm6NSrdiLig88y2GDWd6VQOY/PQu/wKmBWaR4iB5P77Et/0QCIq1p3Ls0+xkrIHcFzm51Odr7YQwAkemP7zfBG63zb/FibVMi/JQ4Yk2GTuVoazJMg1oH4TE7lXSjIybymHpdwfFFV9E2V9w0OQuPNcEDRW43BF8T53UvKwzBl1rMcbhL1II1ayvKLuMenGBfHjWMhIl1MDl88w93W/hcarYwxEvPbHsFkM2MhvAMuo29RkHH0biaIh1V1kMa4lbu9bA9foC1jaeK7UKBuLM7aDu1S2M4QfazCVD5RI0T+Ys3Rg== 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=8+qMUa249jGesoN0N9VZs8Tj7kmeN3hEi+xQZzoB/bQ=; b=I9wmdQqWLZBU1aiDCbpoDZ4Iv0RItRawPo1KdbDWUwzQdCb4RAcig5GxfPgKSMUG13ZM7AZtXYjUFQ2YbJbc7xk34p7k5C8NAQLFCOq2LwURKArIoiwDT3Wkr3/lEaPdq4Aeb+aIxqtgC2/GrUM5kPUVgGHtXOw/si15t7GHVQ/P0YC36828CGEbg7KPVXUJzeHoPL2OdTeHd2saHYb1mivPeANSBW2kUBO7mCZ72EqxfjFMRllGnwHQZl/RQt4pAC49iHf8epiwe3Jsrqo7BCBbGMl9N5/0QP2ctCkKHmyAevZxxhBYtaCMajBaInfyIf3jPEcusVetnGEdYljKdA== 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=8+qMUa249jGesoN0N9VZs8Tj7kmeN3hEi+xQZzoB/bQ=; b=WCSDnmrQiywQlMLw8e29LYcVmUTbpDi276JZAgedqbRVRNVsm+SQXr8aToM/OLgX3yd2m/yXq1hPjxp3fqJoPky50aOQ/hsIejlcAtcMxv8c46MTicJ9Uh/fU6MKqYrcC/bSiOW1Abk6zmvlbIFaZA7KzkxDniaZk4vA8Qk/OkU= Received: from DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) by IA4PR10MB8756.namprd10.prod.outlook.com (2603:10b6:208:562::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.21; Tue, 18 Nov 2025 10:18:31 +0000 Received: from DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2]) by DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2%7]) with mapi id 15.20.9343.009; Tue, 18 Nov 2025 10:18:31 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Jonathan Corbet , David Hildenbrand , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jann Horn , Pedro Falcato , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Andrei Vagin Subject: [PATCH v4 5/9] mm: introduce copy-on-fork VMAs and make VM_MAYBE_GUARD one Date: Tue, 18 Nov 2025 10:17:47 +0000 Message-ID: <5d41b24e7bc622cda0af92b6d558d7f4c0d1bc8c.1763460113.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO2P265CA0275.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a1::23) 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_|IA4PR10MB8756:EE_ X-MS-Office365-Filtering-Correlation-Id: 0625fa5f-e4ee-4cc3-abfc-08de268bd2c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?QQqLpxgn/2ZubEQS7Vyj36G7bbX4glrKyQE3OP0CE280ZMKkDuCaRpEqGBOs?= =?us-ascii?Q?xqzVrPI2bB5W17U5t+ulwP19beG3gjJR0EaTJoNgVqWLdPRgLPkD+riF4VVh?= =?us-ascii?Q?gn86/AEDM7kLLxD6zy/CFaarRBLKgeCRk/9+DUovuYgQvznfKVogIgbp/6OD?= =?us-ascii?Q?t3Tb+dDJw7HjtJi8uw6M68LSLeP6B5nfOj6/xz6k0iNBzautz3qU0ma+hg+O?= =?us-ascii?Q?6stl8rCw3vV7i7o1msvMqOZDK6DIcff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mjKa8mSjIRjx/pxnNazy7iFAtG7D1v9yMuJ+S3TArTBHBewAc?= =?us-ascii?Q?Uow4KL8lFlG2oIP89FhYcuj4O9QEz+p0Ie/6jWEAjdHME/4u7zkkU/ezzSDX?= =?us-ascii?Q?WAeRzL2rFeP9vmsbWbIGAb7rHBAIjfmAwUKIfiPjc/mn742vqEuqQnJgY80G?= =?us-ascii?Q?bOfZ3BKWV9WzanXqSQqL8viowsRt3HuYiWcjEBwtnPeT3h6y5uOnX42kHfPc?= =?us-ascii?Q?bAXLuCcam7apijXBXM0tg3S9GOuXCzI4C+MnaVFmAqSwGA3gZ+1JZ5vtJ8px?= =?us-ascii?Q?iKkoLBaYvrt4+ioDJe5DDoNypmo+/ITp?= 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)(376014)(7416014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?MQcMLru/XakJDb1pfznJUXDvHmGRP2CZlzp4TNEO2x28wp6xLSnWXQZxwGcE?= =?us-ascii?Q?nsRaL1amUAsMO1mawYAeaSiKHv5H4Pw7bFUOa4iheiuU89wKYXod614bUCii?= =?us-ascii?Q?fV2pCAIk1/N884ADS3OZXx8zvbGC9yDwSR9lBhh9x8zk9MjJdaCkgG3hgG8V?= =?us-ascii?Q?5FFEnh4GTLvXQpthFs1AHO8+pIwE8YbtiGb0nLBWmzDt9N3H+cDGaIjzs+jy?= =?us-ascii?Q?VDbKFi8VIIYEo1epAPQe8kz4H6giUYUgeY1CF56RdWC/PxBl+rcnWV3rriei?= =?us-ascii?Q?ql4BFPiO68r+EnjFJ/9fsL3+AIfxUEtzA6QQhQKIB6RKquR2lpQnWS01Hig9?= =?us-ascii?Q?LWXrMSZv5Vjz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dBF5Q0+wVYQ3YiCWWZboo8z2rgoztYXtnuWJ26a0TrTnyIOLbdcDWjMzMDryCWiVO+hRggjPdsS0z4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0625fa5f-e4ee-4cc3-abfc-08de268bd2c5 X-MS-Exchange-CrossTenant-AuthSource: DM4PR10MB8218.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2025 10:18:31.3395 (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: 91JGSxKe19zEyvuqRskn/z60X5qsqKIfguopjw9TsDXL91543I4+gvt1/6UJ6yAjUbouH6JvnpmC1PvmgEdWp8KLjeC0ek0tgM9czr1wwAs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA4PR10MB8756 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-17_04,2025-11-13_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 mlxscore=0 bulkscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511180082 X-Authority-Analysis: v=2.4 cv=DYoaa/tW c=1 sm=1 tr=0 ts=691c4801 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=z/mQ4Ysz8XfWz/Q5cLBRGdckG28=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=xqWC_Br6kY4A:10 a=6UeiqGixMTsA:10 a=GoEa3M9JfhUA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=iU0FZCYCfJC6mG8IRBoA:9 a=nl4s5V0KI7Kw-pW0DWrs:22 a=pHzHmUro8NiASowvMSCR:22 a=xoEH_sTeL_Rfw54TyV31:22 X-Proofpoint-GUID: JitUu5YnEDqhZKiJdEGwpaOWH4F6hwIw X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX0CkLnIhQ0pZw icCMmrsMIQzl4pnT/MNclfgc/FotfRI/ZAy2IHF5U3sdC4a83hODpB0UI4asgBT7trEYuXqBrhe z2PXuIMAHy57QIHE2NN1nD0yKXmnqIgav0XbljORBUL2JGiRK5fUzmD4k9+ITncmHop+i3UTcsx ohCnKZWNeg16Yiy+C/anOLNSeL/lxlERDGDEDeQZ9KrZTBU8qtgzd4zLBj/H3BzGIYdMS5ACJDa B4ZCqedBRZ7AquVhaW9IqVQJ8XoKUaZFbgBS96KW/yUD4bVYC4WzOmj7uJPcpFIRGdMSzAMBeDl DUZIiJJ6s81MMPHO1QLVrLl/p+u0L0EBwwzj/+UmXBbhm1q5vhu6poG8xd0E4pfFoFC4Aj0/ZN1 pqsiAmoD0UK8n+nCM/iBRmMhSszVYw== X-Proofpoint-ORIG-GUID: JitUu5YnEDqhZKiJdEGwpaOWH4F6hwIw Content-Type: text/plain; charset="utf-8" Gather all the VMA flags whose presence implies that page tables must be copied on fork into a single bitmap - VM_COPY_ON_FORK - and use this rather than specifying individual flags in vma_needs_copy(). We also add VM_MAYBE_GUARD to this list, as it being set on a VMA implies that there may be metadata contained in the page tables (that is - guard markers) which would will not and cannot be propagated upon fork. This was already being done manually previously in vma_needs_copy(), but this makes it very explicit, alongside VM_PFNMAP, VM_MIXEDMAP and VM_UFFD_WP all of which imply the same. Note that VM_STICKY flags ought generally to be marked VM_COPY_ON_FORK too - because equally a flag being VM_STICKY indicates that the VMA contains metadat that is not propagated by being faulted in - i.e. that the VMA metadata does not fully describe the VMA alone, and thus we must propagate whatever metadata there is on a fork. However, for maximum flexibility, we do not make this necessarily the case here. Signed-off-by: Lorenzo Stoakes Reviewed-by: Pedro Falcato Reviewed-by: Vlastimil Babka Acked-by: David Hildenbrand (Red Hat) --- include/linux/mm.h | 26 ++++++++++++++++++++++++++ mm/memory.c | 18 ++++-------------- tools/testing/vma/vma_internal.h | 26 ++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 14 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index fea113d1d723..af2904aeb163 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -555,6 +555,32 @@ extern unsigned int kobjsize(const void *objp); */ #define VM_IGNORE_MERGE (VM_SOFTDIRTY | VM_STICKY) =20 +/* + * Flags which should result in page tables being copied on fork. These are + * flags which indicate that the VMA maps page tables which cannot be + * reconsistuted upon page fault, so necessitate page table copying upon + * + * VM_PFNMAP / VM_MIXEDMAP - These contain kernel-mapped data which cannot= be + * reasonably reconstructed on page fault. + * + * VM_UFFD_WP - Encodes metadata about an installed uffd + * write protect handler, which cannot be + * reconstructed on page fault. + * + * We always copy pgtables when dst_vma has uffd= -wp + * enabled even if it's file-backed + * (e.g. shmem). Because when uffd-wp is enabled, + * pgtable contains uffd-wp protection informati= on, + * that's something we can't retrieve from page = cache, + * and skip copying will lose those info. + * + * VM_MAYBE_GUARD - Could contain page guard region markers which + * by design are a property of the page tables + * only and thus cannot be reconstructed on page + * fault. + */ +#define VM_COPY_ON_FORK (VM_PFNMAP | VM_MIXEDMAP | VM_UFFD_WP | VM_MAYBE_G= UARD) + /* * mapping from the currently active vm_flags protection bits (the * low four bits) to a page protection mask.. diff --git a/mm/memory.c b/mm/memory.c index a520720702f0..732414852570 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -1463,25 +1463,15 @@ copy_p4d_range(struct vm_area_struct *dst_vma, stru= ct vm_area_struct *src_vma, static bool vma_needs_copy(struct vm_area_struct *dst_vma, struct vm_area_struct *src_= vma) { + if (src_vma->vm_flags & VM_COPY_ON_FORK) + return true; /* - * Always copy pgtables when dst_vma has uffd-wp enabled even if it's - * file-backed (e.g. shmem). Because when uffd-wp is enabled, pgtable - * contains uffd-wp protection information, that's something we can't - * retrieve from page cache, and skip copying will lose those info. + * The presence of an anon_vma indicates an anonymous VMA has page + * tables which naturally cannot be reconstituted on page fault. */ - if (userfaultfd_wp(dst_vma)) - return true; - - if (src_vma->vm_flags & (VM_PFNMAP | VM_MIXEDMAP)) - return true; - if (src_vma->anon_vma) return true; =20 - /* Guard regions have modified page tables that require copying. */ - if (src_vma->vm_flags & VM_MAYBE_GUARD) - return true; - /* * Don't copy ptes where a page fault will fill them correctly. Fork * becomes much lighter when there are big shared or private readonly diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_inter= nal.h index 73c2025777e6..233819a9e7ee 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -145,6 +145,32 @@ extern unsigned long dac_mmap_min_addr; */ #define VM_IGNORE_MERGE (VM_SOFTDIRTY | VM_STICKY) =20 +/* + * Flags which should result in page tables being copied on fork. These are + * flags which indicate that the VMA maps page tables which cannot be + * reconsistuted upon page fault, so necessitate page table copying upon + * + * VM_PFNMAP / VM_MIXEDMAP - These contain kernel-mapped data which cannot= be + * reasonably reconstructed on page fault. + * + * VM_UFFD_WP - Encodes metadata about an installed uffd + * write protect handler, which cannot be + * reconstructed on page fault. + * + * We always copy pgtables when dst_vma has uffd= -wp + * enabled even if it's file-backed + * (e.g. shmem). Because when uffd-wp is enabled, + * pgtable contains uffd-wp protection informati= on, + * that's something we can't retrieve from page = cache, + * and skip copying will lose those info. + * + * VM_MAYBE_GUARD - Could contain page guard region markers which + * by design are a property of the page tables + * only and thus cannot be reconstructed on page + * fault. + */ +#define VM_COPY_ON_FORK (VM_PFNMAP | VM_MIXEDMAP | VM_UFFD_WP | VM_MAYBE_G= UARD) + #define FIRST_USER_ADDRESS 0UL #define USER_PGTABLES_CEILING 0UL =20 --=20 2.51.2 From nobody Tue Dec 2 02:43:46 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 84EBB344057; Tue, 18 Nov 2025 10:19:36 +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=1763461183; cv=fail; b=V/bVo9CNJRLVytei1xGfDGeRzJ0vrj9rn8Jxp2+Nd3vEeuoXhxBV0nCy9rOhEK5CuC8B+Kuk/QLBPVxcya86RFCWbP+10sWMLdIUqT3iG+gIDW3eSmOuKcVlmRbZZJkNu2REKg91OTJ3etjVcJbeTuLU85p0uRAq92S9vusLEZQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763461183; c=relaxed/simple; bh=er0llcBZGx8WnGYVgZhTRCCxKmQ44DQr13KwH00huUI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=TgGA2Z51yQXB350wz5cVAfqfvl0fFZLSp7VaXvEWBhcfJAVkhu9Xwit1lrPm6e4SulyH+S010yIXWCrDuGDTJH/6/7ila6/3dG7dgAvfCI5sgOftUzgdNyyXXlbaWUmOsY6Z+e2DxSqyQDSw5AQXkvIlxEQzgi3NSBuYdhKicpQ= 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=WD3gnKP4; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=oRY6yfgd; 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="WD3gnKP4"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="oRY6yfgd" Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AI9CiHv026659; Tue, 18 Nov 2025 10:18:42 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-2025-04-25; bh=2Racm7SUJaZEFwX/ZNz2EJODs9wLk4W9UjaEYg9ICkY=; b= WD3gnKP4dWXKftVXh473ofEDtlozJ/F1VxrEQ6531hI6tE7X1udlDrj23864N8vm IW6FCJ+nB2W0CGHdUd76NM2IHx0JkyJHWR6XsSwGBEqaIixQVf0Dzo0SbA85WfL8 +o28aWZrL9EqES2ag5EivzBiPZc21B70QesLeqPwkFugycYU5w7/kRYCnVs4EZ9c eASD9c6sboZludsNajEdTcm8TZUFZ+3X7G4rzrYCxnPLgBlGCje+cf3fS0n0QIOP kmIhox0g2YduONAztYkmJb8PYJITHikdYEEIr5OnEO4aTus0sCIOQSiZcx7IK99a 3agINSYJx0xu9Bgtp3vK+A== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejd1cgcq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:41 +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 5AI9NsrX040040; Tue, 18 Nov 2025 10:18:40 GMT Received: from sn4pr0501cu005.outbound.protection.outlook.com (mail-southcentralusazon11011045.outbound.protection.outlook.com [40.93.194.45]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyk8qpj-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LHrYFDp+FVqWwuuCmSwK+W+to78Y2Z8ytF9MPGIGwzJF9Sk7k8dTzC0Ct4Lf2Bn0OCyFIwIQoBKtMxnESYfagc+FSydHZw+98p/Dnthn6mzNONLKJBSwmKQWAztzKgbPLJJyOz//7b3eh8EMTu1snnaYblAb2DtfyI6T8D8oALxyE7HoZmWmj0wTeg9FxrPTYV7MTTpsUBmCz7G93IDJ/51Pw1UNv1dm6DPoIkMi2HLty+tjRPgevaju6L1svWgvqajE9kaTNuRVOqGL377TjK3mpVIy3IQ04wjP983A5j6vbltewSZfIuv9pAYiJ99RuRl0WbUNAUivfZouJcsUbg== 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=2Racm7SUJaZEFwX/ZNz2EJODs9wLk4W9UjaEYg9ICkY=; b=i/ycdzTBNylGinBPb+EzEXXRHb8t+LVOZox79E5SB0aa0I9gxQbxO7CP3HatC5VlTEA7oHazOrhNGNh75+1lDnsVA3oUzOrrLZr2sB1BlW4qq6wso6hdZWJZ/bicg5D3aewpYODcTcQjfgkAVK7J//gZxSMhsu8ChjhDKIQuQzLx1NFqDXJYiB7crZeYuE28FjO5yd089GcBuekxrFbJ2L3Z06l+WR1Gg3KE4vyCK4U8Xi5zk6RJaFGfx5siMa80yeDGAGXhe5Y4zA3+laCtmcv7lxDtIeNB1t2yfgvrurswqUocif4Lqwl54t2Drr0MUWfijvi6VouaceiC3ygajw== 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=2Racm7SUJaZEFwX/ZNz2EJODs9wLk4W9UjaEYg9ICkY=; b=oRY6yfgdKL+zD8+Jy7/5fsKuwtYkUMLmcGblXnkaroc/FxYLGm/K33W7BSsmtOYMO3XuvJiX/Qb23hOcWaviuaUYX/K/Bi/HQSSVksHKm16lKsv3KcPZkt9GvYKk//HPcvhlvaPBAdl54APvW2lYVTjroGEBDkCMzsYTcjjsa2A= Received: from DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) by IA4PR10MB8756.namprd10.prod.outlook.com (2603:10b6:208:562::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.21; Tue, 18 Nov 2025 10:18:33 +0000 Received: from DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2]) by DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2%7]) with mapi id 15.20.9343.009; Tue, 18 Nov 2025 10:18:33 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Jonathan Corbet , David Hildenbrand , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jann Horn , Pedro Falcato , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Andrei Vagin Subject: [PATCH v4 6/9] mm: set the VM_MAYBE_GUARD flag on guard region install Date: Tue, 18 Nov 2025 10:17:48 +0000 Message-ID: X-Mailer: git-send-email 2.51.2 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO4P123CA0609.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:314::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_|IA4PR10MB8756:EE_ X-MS-Office365-Filtering-Correlation-Id: b27b4857-95c1-4617-23ae-08de268bd42f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?rZr2hzDXr7Vy5k0WWNUVMDKrJ5n+Hm4cpHrJStwwXq533vLVQ7wXCt2xAk83?= =?us-ascii?Q?pUoST5sdjsCl8cms3WIJUJcQSmQ40snIO27t39xBZbgvhB2+8XL/2bPoGVi5?= =?us-ascii?Q?8d6hszzP5Jo2Qxyq9wDzJw2iQZflElzLs5/aqKSgTo1METDkujyoVhDjT72Z?= =?us-ascii?Q?gR5w7pFbvL/HxppzF8Eq4zzV1+pQS77RE+nPMvYa7+M8ZZMzO+t/KWUKlIiq?= =?us-ascii?Q?nwpts9rrMe3RgIFfZCq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7hAAo2DyftzHx8olF96hNY3mIo33MSUCSA6/tg7nQ6oFMWHsyT6NRW3i?= =?us-ascii?Q?opSFFmY8nQBpygocJi7kZKNdtU9ytf5QXCu/8Q/H9iri+7WHwhNzOKjHN2hP?= =?us-ascii?Q?1Prrp0k+RAO4lBwefyXYDQK2Q9zqF0qKz3sG/lOFM4QnHMWvGq0hBOHcIT44?= =?us-ascii?Q?3IiKW5H23bp/W56DfzxNqOeVsPpysL0aKVOALcwZhzuAlLKa9LmPyOkrvfbt?= =?us-ascii?Q?YL860rOvfXATzjnv+CgRVmNLYzVqEnQU3HjA22+sqWxQuq4YMM5c8OONth6C?= =?us-ascii?Q?a4YAswviELqaWY4W+FY8Py9IOWfkRe1x?= 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)(376014)(7416014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?Co4lX67WxGUq+0Sc3IZdrWnzsPbLGEj+4wF7eUVheAAtJscCn41QdFuXgkQZ?= =?us-ascii?Q?/lav1rr7ONle59XrjZeSgswcJejitLO0p7bL4ye02I6VxiVCfIefbvy5EnON?= =?us-ascii?Q?6OwiKg/CCwop0IyQTrIFi2jHOehTd8eA3ugpKg9bQISsQV6atn/JiBzTcN/O?= =?us-ascii?Q?UflE1NXlic4Rvxn44QER/4gg2Vq4iZiR9BjEOQhI8d7ObgxIE4ez3XtxzOJ/?= =?us-ascii?Q?pdpKHaFMVkfCsoiKwV9IMBLfIomqo2czskt/F01ujRTLW3hGb7Z9MgyCzy2x?= =?us-ascii?Q?EF/onMv5A8MU/pZ3vq3V9h+hgcHCd+zeB4oK7HFe+HYSggT9ptecFASgQ+2b?= =?us-ascii?Q?OC+9PNkR5rSfz8r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qaw?= =?us-ascii?Q?WgI//TgaZp1+hPCpY6kkO26xpQFpItZC1SZnlVMndTL4zcsC1nUz9SN6RPLo?= =?us-ascii?Q?2/xv6UHdyDXW0UP4Tb2j5pRdTGUAaHf0WgSC9M+HMdU9UaQdwqv9HXHX6/yY?= =?us-ascii?Q?2CImrGE/gcrNKFY2BgrXKKp1hmGvUbKNcPfH60nLwgx+z2V8PT1Q5P08TIG5?= =?us-ascii?Q?HIEqwQSksepNk7Tup/pXsd3+DwGQ/PsNKH7yusxjGUbIm0zftU3nB6dIylBn?= =?us-ascii?Q?tWKazn/FQ9rKPJRfcrrjouUXHBHbULOXBmuYbymAO/WlSHMoP1PHUlotzQOq?= =?us-ascii?Q?nwD16Us0oywX/gb6s/nWC4ZKUFR14+uscKAQxJ0rY2oDt0erdx4ZiuIAV3GJ?= =?us-ascii?Q?ew=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: hFd0Wm7AQk12FGPrVdgt1XiHrIrQPDNjTZyrHuy5T1dFH13M3MTndGKMhcYUserWJEjjU+dII2K9sJM9uSHx1Yaf6+rKVEsWcGJPFJPdPOx0SSNYjXU67BN5WNANMUNRXJjWf07B9fbN9S4dlLCGHyKqxbCJCBp8pW2iig5SHwiWnPZg5Yhptjai3Qi2YyyTL9eO+cHI+MW/tXZc/g/Om9G0AYRDiPJAzeXtxJHp2Nbeq8O7T99pVE+GMOO4UT5df5eFdEQyxSgLEINtJCOthVO3PywX14agboI7XizpM6sXdTJjIricHHOwRCDQIpkc00ZV8R4sYYwtG1SBbCYrbna0EqOc9lct8/icUUfhE3GyLaSvAY3ZEtDYdyJo1gSp3j7EsThz06qPaqFRvRBi8z6zxC3yTZci911TDGFfHLsyhHklktBhVgZKe89RR4vIdwrCtvQKu1VAKx5TbZKz1EvfF+SnArJS/zhR1x4U5w3hwyGlJD807hIXvjeE+ckVcxXlXnVh9PRfP+cVikfhFZ2Q7+TtE8Fd+1gphaDIbkLeRNqDoVDM54eeB7/6Tf+oiPN9GkB8DEs+5syGaf3fwoLUEefYdBKypnkMnwvgulI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b27b4857-95c1-4617-23ae-08de268bd42f X-MS-Exchange-CrossTenant-AuthSource: DM4PR10MB8218.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2025 10:18:33.6911 (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: 0wiXI+5UyhrZuvxaJ/ytvyNO26RH8rj7NjwnRxv7y9L4RLMzVde1o9A6fAdcJ/PdakOCp0zlPO5nkYm0sZes2QwsFHKrV5SEaYfy5/TZyFA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA4PR10MB8756 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-17_04,2025-11-13_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 spamscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511180082 X-Proofpoint-GUID: Lm-P4E8PjDXnGg7Z3aAAUB1nh89Cns3q X-Authority-Analysis: v=2.4 cv=Z/jh3XRA c=1 sm=1 tr=0 ts=691c4802 b=1 cx=c_pps a=qoll8+KPOyaMroiJ2sR5sw==:117 a=qoll8+KPOyaMroiJ2sR5sw==:17 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=z/mQ4Ysz8XfWz/Q5cLBRGdckG28=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=xqWC_Br6kY4A:10 a=6UeiqGixMTsA:10 a=GoEa3M9JfhUA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=NNagTMxLXCr8bz9WFNoA:9 cc=ntf awl=host:12099 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX20VPG9hxB3O+ WsYSYm9LpvA5V8ONo+DUFpmYwdKkMJa4+QHa+RNat6tv4f7LPMw5jqargnjU+gPGOBOzmlT3Iwa rkEftyfWWgKaCf4+S2XjdKzKxHQM/w2R4+IOScIPXCdQkMW7Kq4vZiSVgwm3Bomv8ifdjHRqBip hs5oFeYOHjpqQXkGdTLx2Bg5g6Ia2mIGFQzYXk1pcc/kGdNA7/SWexVchh15+i3pSdMyUDf1Dae Pq4ayGZlg29gcjv+Qm9pU8tD54/hCPEQo287GVPMxGEecP9ylg/3/f51m+hHNyNtFdbZiEKVzP5 tRzVQEVst2QTHtZYCpOWpBTKDDfI59aGSPIzo67ScP2jyXuzC7yaUn2KUtZEZSsrMlQfBt0Oaeq KcnfBuMoJc8cUtLkO2gXEIhg72zheJWLwnz2dgKtilC/s5DW71Y= X-Proofpoint-ORIG-GUID: Lm-P4E8PjDXnGg7Z3aAAUB1nh89Cns3q Content-Type: text/plain; charset="utf-8" Now we have established the VM_MAYBE_GUARD flag and added the capacity to set it atomically, do so upon MADV_GUARD_INSTALL. The places where this flag is used currently and matter are: * VMA merge - performed under mmap/VMA write lock, therefore excluding racing writes. * /proc/$pid/smaps - can race the write, however this isn't meaningful as the flag write is performed at the point of the guard region being established, and thus an smaps reader can't reasonably expect to avoid races. Due to atomicity, a reader will observe either the flag being set or not. Therefore consistency will be maintained. In all other cases the flag being set is irrelevant and atomicity guarantees other flags will be read correctly. Note that non-atomic updates of unrelated flags do not cause an issue with this flag being set atomically, as writes of other flags are performed under mmap/VMA write lock, and these atomic writes are performed under mmap/VMA read lock, which excludes the write, avoiding RMW races. Note that we do not encounter issues with KCSAN by adjusting this flag atomically, as we are only updating a single bit in the flag bitmap and therefore we do not need to annotate these changes. We intentionally set this flag in advance of actually updating the page tables, to ensure that any racing atomic read of this flag will only return false prior to page tables being updated, to allow for serialisation via page table locks. Note that we set vma->anon_vma for anonymous mappings. This is because the expectation for anonymous mappings is that an anon_vma is established should they possess any page table mappings. This is also consistent with what we were doing prior to this patch (unconditionally setting anon_vma on guard region installation). We also need to update retract_page_tables() to ensure that madvise(..., MADV_COLLAPSE) doesn't incorrectly collapse file-backed ranges contain guard regions. This was previously guarded by anon_vma being set to catch MAP_PRIVATE cases, but the introduction of VM_MAYBE_GUARD necessitates that we check this flag instead. We utilise vma_flag_test_atomic() to do so - we first perform an optimistic check, then after the PTE page table lock is held, we can check again safely, as upon guard marker install the flag is set atomically prior to the page table lock being taken to actually apply it. So if the initial check fails either: * Page table retraction acquires page table lock prior to VM_MAYBE_GUARD being set - guard marker installation will be blocked until page table retraction is complete. OR: * Guard marker installation acquires page table lock after setting VM_MAYBE_GUARD, which raced and didn't pick this up in the initial optimistic check, blocking page table retraction until the guard regions are installed - the second VM_MAYBE_GUARD check will prevent page table retraction. Either way we're safe. We refactor the retraction checks into a single file_backed_vma_is_retractable(), there doesn't seem to be any reason that the checks were separated as before. Note that VM_MAYBE_GUARD being set atomically remains correct as vma_needs_copy() is invoked with the mmap and VMA write locks held, excluding any race with madvise_guard_install(). Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- mm/khugepaged.c | 71 ++++++++++++++++++++++++++++++++----------------- mm/madvise.c | 22 +++++++++------ 2 files changed, 61 insertions(+), 32 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index f6ed1072ed6e..af1c162c9a94 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1710,6 +1710,43 @@ int collapse_pte_mapped_thp(struct mm_struct *mm, un= signed long addr, return result; } =20 +/* Can we retract page tables for this file-backed VMA? */ +static bool file_backed_vma_is_retractable(struct vm_area_struct *vma) +{ + /* + * Check vma->anon_vma to exclude MAP_PRIVATE mappings that + * got written to. These VMAs are likely not worth removing + * page tables from, as PMD-mapping is likely to be split later. + */ + if (READ_ONCE(vma->anon_vma)) + return false; + + /* + * When a vma is registered with uffd-wp, we cannot recycle + * the page table because there may be pte markers installed. + * Other vmas can still have the same file mapped hugely, but + * skip this one: it will always be mapped in small page size + * for uffd-wp registered ranges. + */ + if (userfaultfd_wp(vma)) + return false; + + /* + * If the VMA contains guard regions then we can't collapse it. + * + * This is set atomically on guard marker installation under mmap/VMA + * read lock, and here we may not hold any VMA or mmap lock at all. + * + * This is therefore serialised on the PTE page table lock, which is + * obtained on guard region installation after the flag is set, so this + * check being performed under this lock excludes races. + */ + if (vma_flag_test_atomic(vma, VM_MAYBE_GUARD_BIT)) + return false; + + return true; +} + static void retract_page_tables(struct address_space *mapping, pgoff_t pgo= ff) { struct vm_area_struct *vma; @@ -1724,14 +1761,6 @@ static void retract_page_tables(struct address_space= *mapping, pgoff_t pgoff) spinlock_t *ptl; bool success =3D false; =20 - /* - * Check vma->anon_vma to exclude MAP_PRIVATE mappings that - * got written to. These VMAs are likely not worth removing - * page tables from, as PMD-mapping is likely to be split later. - */ - if (READ_ONCE(vma->anon_vma)) - continue; - addr =3D vma->vm_start + ((pgoff - vma->vm_pgoff) << PAGE_SHIFT); if (addr & ~HPAGE_PMD_MASK || vma->vm_end < addr + HPAGE_PMD_SIZE) @@ -1743,14 +1772,8 @@ static void retract_page_tables(struct address_space= *mapping, pgoff_t pgoff) =20 if (hpage_collapse_test_exit(mm)) continue; - /* - * When a vma is registered with uffd-wp, we cannot recycle - * the page table because there may be pte markers installed. - * Other vmas can still have the same file mapped hugely, but - * skip this one: it will always be mapped in small page size - * for uffd-wp registered ranges. - */ - if (userfaultfd_wp(vma)) + + if (!file_backed_vma_is_retractable(vma)) continue; =20 /* PTEs were notified when unmapped; but now for the PMD? */ @@ -1777,15 +1800,15 @@ static void retract_page_tables(struct address_spac= e *mapping, pgoff_t pgoff) spin_lock_nested(ptl, SINGLE_DEPTH_NESTING); =20 /* - * Huge page lock is still held, so normally the page table - * must remain empty; and we have already skipped anon_vma - * and userfaultfd_wp() vmas. But since the mmap_lock is not - * held, it is still possible for a racing userfaultfd_ioctl() - * to have inserted ptes or markers. Now that we hold ptlock, - * repeating the anon_vma check protects from one category, - * and repeating the userfaultfd_wp() check from another. + * Huge page lock is still held, so normally the page table must + * remain empty; and we have already skipped anon_vma and + * userfaultfd_wp() vmas. But since the mmap_lock is not held, + * it is still possible for a racing userfaultfd_ioctl() or + * madvise() to have inserted ptes or markers. Now that we hold + * ptlock, repeating the retractable checks protects us from + * races against the prior checks. */ - if (likely(!vma->anon_vma && !userfaultfd_wp(vma))) { + if (likely(file_backed_vma_is_retractable(vma))) { pgt_pmd =3D pmdp_collapse_flush(vma, addr, pmd); pmdp_get_lockless_sync(); success =3D true; diff --git a/mm/madvise.c b/mm/madvise.c index 0b3280752bfb..5dbe40be7c65 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1141,15 +1141,21 @@ static long madvise_guard_install(struct madvise_be= havior *madv_behavior) return -EINVAL; =20 /* - * If we install guard markers, then the range is no longer - * empty from a page table perspective and therefore it's - * appropriate to have an anon_vma. - * - * This ensures that on fork, we copy page tables correctly. + * Set atomically under read lock. All pertinent readers will need to + * acquire an mmap/VMA write lock to read it. All remaining readers may + * or may not see the flag set, but we don't care. + */ + vma_flag_set_atomic(vma, VM_MAYBE_GUARD_BIT); + + /* + * If anonymous and we are establishing page tables the VMA ought to + * have an anon_vma associated with it. */ - err =3D anon_vma_prepare(vma); - if (err) - return err; + if (vma_is_anonymous(vma)) { + err =3D anon_vma_prepare(vma); + if (err) + return err; + } =20 /* * Optimistically try to install the guard marker pages first. If any --=20 2.51.2 From nobody Tue Dec 2 02:43:46 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 8D983346E73; Tue, 18 Nov 2025 10:19:46 +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=1763461190; cv=fail; b=MEHRv5w67lgIxWr6nW79E/GisOlmyPE32ltUlISx6D4oQmuOP+k3/FB5SyPpP15+l91QcbwPOG0lHcSEOEGMra4QoPuFDpo2VyxB9/VMmLutxqr4wThEFFus7fqnndvesRTWb0CwIZUselzHTxjKB+F37p4urB+ycqPVhivCjbY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763461190; c=relaxed/simple; bh=PZZFYbI0KbxcHZ7QumRJZ9ERYj2N1E9k4JGKHWdt3mc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=tBXvaJDRUUYtbr94MAlSEZRgANIg1/Of7qkG081qol8fXZ0DWB5gjk5bBgAgWa7q57AL6n+ojpWfDGaGGBOUQqT/jnazYK8v/4v8qx3T+LPJ/TwA2ABy4OKmB6NI3bIt3aG5nfw84SQzuVjzh0qOkJBVniltPiO49N1YPcxA3r4= 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=JjziNcuM; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=UA2pzOC8; 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="JjziNcuM"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="UA2pzOC8" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AI9CYH8008373; Tue, 18 Nov 2025 10:18:42 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-2025-04-25; bh=j0+o73DZcBPC9d5sgCNOLtO+fpCPzD6UIDIHr41PxAg=; b= JjziNcuMquaSo45XqrU3iSaRHFMtKoiu0SNRTi/rEpvlckjgCx21k5vS2enfLAg9 dIviJCKpcQlAfHFKH4exidDujZETbPCTTFNr2/l61p9nHkdNgg4gjViQKbSuJ96F pyBjWuzhJDrPo468doee7yx1wP9pK9ce6t44lUyADUe2EXn351sFubwty87B3pyA 2V4e8YnwW/iF4Dz1XlH7s3yMSGBYPaDjxoQ7L9/jERTQF0L1Jrf/Ow9MPIxr2jd8 gTI8jqQviH3L35mhxNBxwv3Mz15cuFYQ1wqUMkCp2m3bV0uqDgs/7vTluyixy+dp /9yku3PGV1LXRT8Z/PpG/Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aej964gyw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:41 +0000 (GMT) Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5AI8wjfp004268; Tue, 18 Nov 2025 10:18:41 GMT Received: from dm1pr04cu001.outbound.protection.outlook.com (mail-centralusazon11010048.outbound.protection.outlook.com [52.101.61.48]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 4aefy8pp85-5 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=G3+RYaK4mGf6FAW+rPQKTlHanTWJ2GkVfLOyCXyMgkbcnuMUVtunyRwjuhWPUZ0LWAGTBJ7aGZxlTH5GqgfWboVsX9VtaJ0jLq866dza8wLRCiByosrUOJCYhp6mW5k4IvJqPInUthrtslG1QOIvV9A2m02xntcBRw4LZOru7LS/mGwlLCZKdaTqc6coYHmqSU4wbioou7ROPAkDCo/LyA5bBz3jubWPRyyxgvE2Q+THeMb+Xg4QaXedlk6e8LbrN10WtsCPZtoeVIBWzbSbp8J/25UJUGEXoKmfDYfwNYFUPh6XjQ0BLkDlOn+dZp0eIM2f871AhEdCORl3ztjpQQ== 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=j0+o73DZcBPC9d5sgCNOLtO+fpCPzD6UIDIHr41PxAg=; b=NxTFmhjlNeYxd2sPXiavJw8KiksfV2LYMEdl+0XWoxXNq8YiVjidRgsYogQz/0x+nXA6Vsyx8VmZoiw0AedrYF2iaWrl+ljB00+OjK4BYG/6FfDc+LrQMK6M2TYgwHazuLHzt+TWI7ZjnYBj6e0g6ULGTtQdYK90HJi7g4usBwzQjR42f0RvbusvNGotCVjGHE7l9GRrS7rU0SnFJ4LzOqLtU1d9TG71MgOmhl37NznK5/+2N29KBAYgvQOBu1/4PjWvaF/zKT8YEjLAU3o5SvYSvs2A/RRx7CuIRnt7SAFQVwrU1gUu2MDSx3atrdoOuBnuyBcSs5i00RmEUvf23w== 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=j0+o73DZcBPC9d5sgCNOLtO+fpCPzD6UIDIHr41PxAg=; b=UA2pzOC8EVeIhaa/v84/XEE4BUWGXnOyjeKpOlPwLCYlylqMSg8meT522gkny8f4vzUofvHD0UK/3uZBcuL6wRcxw1ZTGy/Y6bdL81TVOu2g11SwoHNIXciYwMOavx83LNhMwxhuaitYUy0Ncg3VzoePiK5ifvW1RKyOG6mLo7k= Received: from DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) by IA4PR10MB8756.namprd10.prod.outlook.com (2603:10b6:208:562::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.21; Tue, 18 Nov 2025 10:18:36 +0000 Received: from DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2]) by DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2%7]) with mapi id 15.20.9343.009; Tue, 18 Nov 2025 10:18:36 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Jonathan Corbet , David Hildenbrand , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jann Horn , Pedro Falcato , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Andrei Vagin Subject: [PATCH v4 7/9] tools/testing/vma: add VMA sticky userland tests Date: Tue, 18 Nov 2025 10:17:49 +0000 Message-ID: <5e2c7244485867befd052f8afc8188be6a4be670.1763460113.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO4P123CA0397.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:189::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_|IA4PR10MB8756:EE_ X-MS-Office365-Filtering-Correlation-Id: ce359fb4-8bd5-4412-e8b1-08de268bd59b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?uNAfdIM9pQjOyWdGL28QRc2JcOlRE4ucwHb5OO/8qpiSOOB1syRQmCUQATtX?= =?us-ascii?Q?ajdTIhxf+lTTwiylVEpKsSWhVxGWcTUnBdnrfuZFO0RwDUULQ8rs0QTDM2XZ?= =?us-ascii?Q?TYi5baJpjuLVqlGB5+ZD6jJtIcmYj4VBOQQXbTy9XqqaEhZCOpNBsrN1+VuJ?= =?us-ascii?Q?lyN+vS5kVSngQaz1llRcfksh4N4dGTlEWLdGqhvSWcp4TS3AYeRUwEdfZXVR?= =?us-ascii?Q?867Ss832GPKRtxg5FntusDkzbI072CXzkVCnO9aEraRHicxj3XwSOwk6fJpO?= =?us-ascii?Q?bcX95RED+pNPeK0cIjFLkubGn9gWRvRlW5Cr1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?Q?nv+e1pPFsrAkyiaVts5773t9qPmzpC8AS1QipcZFox61PG4fDsaxBXwIZvkH?= =?us-ascii?Q?ECBkxcfb3sGej2PqDRXP+Z5Wplwxmli/hp5k3HbTfMD4h4wpUn+u4TLsIXdK?= =?us-ascii?Q?QMk3eYeX52cK6ZzyY1NoM2XVeuRHuvxCSqzbZLva2PSZRfK3wZIw15f2jjP8?= =?us-ascii?Q?2KhjQWtkaQgJqo42WymyBfbxasH/4COYKGc0PYPfB2XtsLHJWqeMWvG1QnS7?= =?us-ascii?Q?329DyMAErcWd9E5zwbXd+HZYo437Yi9i?= 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)(376014)(7416014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?AtD8LIgRwKLsoYlM5/RlQHRa4ErOOVhSXXeCXbGd9YBpMsjbAnZz7tgqSG8F?= =?us-ascii?Q?q2+17BNpa+PFwHbZ58ereKYGhC+bqsGNpZcVkSHJsKtKdIeGQRm9IY3stIbv?= =?us-ascii?Q?zauh2ex/Bc3JnJ05fTnjZSBIvaiey0fqeHfFasB2mlRYSGhkNsspAdX6RQ8s?= =?us-ascii?Q?43ax5+r5+L+BX1YsNSzOHRzAoYtcYHo7c2zEvMKX7mcGyc4XPOTmtLP11rB5?= =?us-ascii?Q?Ho09Jy8ranU/bNCsWGkRIHYCSH5otIiNTZO6HI+1/x7mRVM2WsRy+J/A3lkl?= =?us-ascii?Q?hCgHHUw1WyDB1Jp4NsbovX5a0YTGU+MN3sOOOZyAO7yi7xxNBW7CJrIWHZ7w?= =?us-ascii?Q?Iu/fwSkIIHVSdt6oSvqIvVWCqbCfBLnk0Y/fjI4zsvgNH1WU83IDC829tWXI?= =?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qop9feq1zN4gEaKCcF34n4asy8I9BPRlHBZI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: ce359fb4-8bd5-4412-e8b1-08de268bd59b X-MS-Exchange-CrossTenant-AuthSource: DM4PR10MB8218.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2025 10:18:36.0911 (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: mY1ScsaNE2EmpLARlhtbWcS77l8fxpiXRyKXGQ5LzshS4joIYnPGESG5904R7TP+IRSXDdep51awhfM93q6dEGJh4TCNO2+5kAMmwJXpI7c= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA4PR10MB8756 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-17_04,2025-11-13_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 mlxscore=0 bulkscore=0 phishscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511180082 X-Authority-Analysis: v=2.4 cv=DYoaa/tW c=1 sm=1 tr=0 ts=691c4801 cx=c_pps a=XiAAW1AwiKB2Y8Wsi+sD2Q==:117 a=XiAAW1AwiKB2Y8Wsi+sD2Q==:17 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=z/mQ4Ysz8XfWz/Q5cLBRGdckG28=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=xqWC_Br6kY4A:10 a=6UeiqGixMTsA:10 a=GoEa3M9JfhUA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=5lwAt1zO3iEXF7TzJt4A:9 a=nl4s5V0KI7Kw-pW0DWrs:22 a=pHzHmUro8NiASowvMSCR:22 a=xoEH_sTeL_Rfw54TyV31:22 X-Proofpoint-GUID: 2nbEwgWdyessclDxbNLTSTwMYl5HXMuy X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX8Bsq7nnoejxM Vl13/1FMmrF3bEDbKuxSduBu5K5M7yDbMnocjMdnd9kLk23/zEwymOpseNHLx0fHZDyF+EwOvCR DYLNQzRr2ot98L2UHQEE53yWJiPp7KnpyVqomIwrAvz9XEO0rQQ7BiLbPsyeo7n2bDvONMQZ8X2 JkOQh8YZvyVdLjnEWvbUxBZbjLYFVC3CfQbmGI//k7h5hlPj6eIrG+qQR4DUdbtV4W2hT1R0D4X VRFgLq/X2dbRI7vtICfNE43KhSQ2VQy9aWaiwZ009NNF5APY0HcvWAzO0byK2iJA1r4icirsH5H 375qIReDaDDRBhHa7eEA9MMfKzBiSdFev3FruejqPqamhzlNUZT6AfrsWrnZVHtOBcMtNcy+xBW mDFMHkDf+1DCQwtFLWsqULLg/3/aqQ== X-Proofpoint-ORIG-GUID: 2nbEwgWdyessclDxbNLTSTwMYl5HXMuy Content-Type: text/plain; charset="utf-8" Modify existing merge new/existing userland VMA tests to assert that sticky VMA flags behave as expected. We do so by generating every possible permutation of VMAs being manipulated being sticky/not sticky and asserting that VMA flags with this property retain are retained upon merge. Signed-off-by: Lorenzo Stoakes --- tools/testing/vma/vma.c | 89 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 10 deletions(-) diff --git a/tools/testing/vma/vma.c b/tools/testing/vma/vma.c index fd37ce3b2628..be79ab2ea44b 100644 --- a/tools/testing/vma/vma.c +++ b/tools/testing/vma/vma.c @@ -48,6 +48,8 @@ static struct anon_vma dummy_anon_vma; #define ASSERT_EQ(_val1, _val2) ASSERT_TRUE((_val1) =3D=3D (_val2)) #define ASSERT_NE(_val1, _val2) ASSERT_TRUE((_val1) !=3D (_val2)) =20 +#define IS_SET(_val, _flags) ((_val & _flags) =3D=3D _flags) + static struct task_struct __current; =20 struct task_struct *get_current(void) @@ -442,7 +444,7 @@ static bool test_simple_shrink(void) return true; } =20 -static bool test_merge_new(void) +static bool __test_merge_new(bool is_sticky, bool a_is_sticky, bool b_is_s= ticky, bool c_is_sticky) { vm_flags_t vm_flags =3D VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE; struct mm_struct mm =3D {}; @@ -470,23 +472,32 @@ static bool test_merge_new(void) struct vm_area_struct *vma, *vma_a, *vma_b, *vma_c, *vma_d; bool merged; =20 + if (is_sticky) + vm_flags |=3D VM_STICKY; + /* * 0123456789abc * AA B CC */ vma_a =3D alloc_and_link_vma(&mm, 0, 0x2000, 0, vm_flags); ASSERT_NE(vma_a, NULL); + if (a_is_sticky) + vm_flags_set(vma_a, VM_STICKY); /* We give each VMA a single avc so we can test anon_vma duplication. */ INIT_LIST_HEAD(&vma_a->anon_vma_chain); list_add(&dummy_anon_vma_chain_a.same_vma, &vma_a->anon_vma_chain); =20 vma_b =3D alloc_and_link_vma(&mm, 0x3000, 0x4000, 3, vm_flags); ASSERT_NE(vma_b, NULL); + if (b_is_sticky) + vm_flags_set(vma_b, VM_STICKY); INIT_LIST_HEAD(&vma_b->anon_vma_chain); list_add(&dummy_anon_vma_chain_b.same_vma, &vma_b->anon_vma_chain); =20 vma_c =3D alloc_and_link_vma(&mm, 0xb000, 0xc000, 0xb, vm_flags); ASSERT_NE(vma_c, NULL); + if (c_is_sticky) + vm_flags_set(vma_c, VM_STICKY); INIT_LIST_HEAD(&vma_c->anon_vma_chain); list_add(&dummy_anon_vma_chain_c.same_vma, &vma_c->anon_vma_chain); =20 @@ -521,6 +532,8 @@ static bool test_merge_new(void) ASSERT_EQ(vma->anon_vma, &dummy_anon_vma); ASSERT_TRUE(vma_write_started(vma)); ASSERT_EQ(mm.map_count, 3); + if (is_sticky || a_is_sticky || b_is_sticky) + ASSERT_TRUE(IS_SET(vma->vm_flags, VM_STICKY)); =20 /* * Merge to PREVIOUS VMA. @@ -538,6 +551,8 @@ static bool test_merge_new(void) ASSERT_EQ(vma->anon_vma, &dummy_anon_vma); ASSERT_TRUE(vma_write_started(vma)); ASSERT_EQ(mm.map_count, 3); + if (is_sticky || a_is_sticky) + ASSERT_TRUE(IS_SET(vma->vm_flags, VM_STICKY)); =20 /* * Merge to NEXT VMA. @@ -557,6 +572,8 @@ static bool test_merge_new(void) ASSERT_EQ(vma->anon_vma, &dummy_anon_vma); ASSERT_TRUE(vma_write_started(vma)); ASSERT_EQ(mm.map_count, 3); + if (is_sticky) /* D uses is_sticky. */ + ASSERT_TRUE(IS_SET(vma->vm_flags, VM_STICKY)); =20 /* * Merge BOTH sides. @@ -575,6 +592,8 @@ static bool test_merge_new(void) ASSERT_EQ(vma->anon_vma, &dummy_anon_vma); ASSERT_TRUE(vma_write_started(vma)); ASSERT_EQ(mm.map_count, 2); + if (is_sticky || a_is_sticky) + ASSERT_TRUE(IS_SET(vma->vm_flags, VM_STICKY)); =20 /* * Merge to NEXT VMA. @@ -593,6 +612,8 @@ static bool test_merge_new(void) ASSERT_EQ(vma->anon_vma, &dummy_anon_vma); ASSERT_TRUE(vma_write_started(vma)); ASSERT_EQ(mm.map_count, 2); + if (is_sticky || c_is_sticky) + ASSERT_TRUE(IS_SET(vma->vm_flags, VM_STICKY)); =20 /* * Merge BOTH sides. @@ -610,6 +631,8 @@ static bool test_merge_new(void) ASSERT_EQ(vma->anon_vma, &dummy_anon_vma); ASSERT_TRUE(vma_write_started(vma)); ASSERT_EQ(mm.map_count, 1); + if (is_sticky || a_is_sticky || c_is_sticky) + ASSERT_TRUE(IS_SET(vma->vm_flags, VM_STICKY)); =20 /* * Final state. @@ -638,6 +661,20 @@ static bool test_merge_new(void) return true; } =20 +static bool test_merge_new(void) +{ + int i, j, k, l; + + /* Generate every possible permutation of sticky flags. */ + for (i =3D 0; i < 2; i++) + for (j =3D 0; j < 2; j++) + for (k =3D 0; k < 2; k++) + for (l =3D 0; l < 2; l++) + ASSERT_TRUE(__test_merge_new(i, j, k, l)); + + return true; +} + static bool test_vma_merge_special_flags(void) { vm_flags_t vm_flags =3D VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE; @@ -974,9 +1011,11 @@ static bool test_vma_merge_new_with_close(void) return true; } =20 -static bool test_merge_existing(void) +static bool __test_merge_existing(bool prev_is_sticky, bool middle_is_stic= ky, bool next_is_sticky) { vm_flags_t vm_flags =3D VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE; + vm_flags_t prev_flags =3D vm_flags; + vm_flags_t next_flags =3D vm_flags; struct mm_struct mm =3D {}; VMA_ITERATOR(vmi, &mm, 0); struct vm_area_struct *vma, *vma_prev, *vma_next; @@ -989,6 +1028,13 @@ static bool test_merge_existing(void) }; struct anon_vma_chain avc =3D {}; =20 + if (prev_is_sticky) + prev_flags |=3D VM_STICKY; + if (middle_is_sticky) + vm_flags |=3D VM_STICKY; + if (next_is_sticky) + next_flags |=3D VM_STICKY; + /* * Merge right case - partial span. * @@ -1001,7 +1047,7 @@ static bool test_merge_existing(void) */ vma =3D alloc_and_link_vma(&mm, 0x2000, 0x6000, 2, vm_flags); vma->vm_ops =3D &vm_ops; /* This should have no impact. */ - vma_next =3D alloc_and_link_vma(&mm, 0x6000, 0x9000, 6, vm_flags); + vma_next =3D alloc_and_link_vma(&mm, 0x6000, 0x9000, 6, next_flags); vma_next->vm_ops =3D &vm_ops; /* This should have no impact. */ vmg_set_range_anon_vma(&vmg, 0x3000, 0x6000, 3, vm_flags, &dummy_anon_vma= ); vmg.middle =3D vma; @@ -1019,6 +1065,8 @@ static bool test_merge_existing(void) ASSERT_TRUE(vma_write_started(vma)); ASSERT_TRUE(vma_write_started(vma_next)); ASSERT_EQ(mm.map_count, 2); + if (middle_is_sticky || next_is_sticky) + ASSERT_TRUE(IS_SET(vma_next->vm_flags, VM_STICKY)); =20 /* Clear down and reset. */ ASSERT_EQ(cleanup_mm(&mm, &vmi), 2); @@ -1034,7 +1082,7 @@ static bool test_merge_existing(void) * NNNNNNN */ vma =3D alloc_and_link_vma(&mm, 0x2000, 0x6000, 2, vm_flags); - vma_next =3D alloc_and_link_vma(&mm, 0x6000, 0x9000, 6, vm_flags); + vma_next =3D alloc_and_link_vma(&mm, 0x6000, 0x9000, 6, next_flags); vma_next->vm_ops =3D &vm_ops; /* This should have no impact. */ vmg_set_range_anon_vma(&vmg, 0x2000, 0x6000, 2, vm_flags, &dummy_anon_vma= ); vmg.middle =3D vma; @@ -1047,6 +1095,8 @@ static bool test_merge_existing(void) ASSERT_EQ(vma_next->anon_vma, &dummy_anon_vma); ASSERT_TRUE(vma_write_started(vma_next)); ASSERT_EQ(mm.map_count, 1); + if (middle_is_sticky || next_is_sticky) + ASSERT_TRUE(IS_SET(vma_next->vm_flags, VM_STICKY)); =20 /* Clear down and reset. We should have deleted vma. */ ASSERT_EQ(cleanup_mm(&mm, &vmi), 1); @@ -1061,7 +1111,7 @@ static bool test_merge_existing(void) * 0123456789 * PPPPPPV */ - vma_prev =3D alloc_and_link_vma(&mm, 0, 0x3000, 0, vm_flags); + vma_prev =3D alloc_and_link_vma(&mm, 0, 0x3000, 0, prev_flags); vma_prev->vm_ops =3D &vm_ops; /* This should have no impact. */ vma =3D alloc_and_link_vma(&mm, 0x3000, 0x7000, 3, vm_flags); vma->vm_ops =3D &vm_ops; /* This should have no impact. */ @@ -1081,6 +1131,8 @@ static bool test_merge_existing(void) ASSERT_TRUE(vma_write_started(vma_prev)); ASSERT_TRUE(vma_write_started(vma)); ASSERT_EQ(mm.map_count, 2); + if (prev_is_sticky || middle_is_sticky) + ASSERT_TRUE(IS_SET(vma_prev->vm_flags, VM_STICKY)); =20 /* Clear down and reset. */ ASSERT_EQ(cleanup_mm(&mm, &vmi), 2); @@ -1095,7 +1147,7 @@ static bool test_merge_existing(void) * 0123456789 * PPPPPPP */ - vma_prev =3D alloc_and_link_vma(&mm, 0, 0x3000, 0, vm_flags); + vma_prev =3D alloc_and_link_vma(&mm, 0, 0x3000, 0, prev_flags); vma_prev->vm_ops =3D &vm_ops; /* This should have no impact. */ vma =3D alloc_and_link_vma(&mm, 0x3000, 0x7000, 3, vm_flags); vmg_set_range_anon_vma(&vmg, 0x3000, 0x7000, 3, vm_flags, &dummy_anon_vma= ); @@ -1110,6 +1162,8 @@ static bool test_merge_existing(void) ASSERT_EQ(vma_prev->anon_vma, &dummy_anon_vma); ASSERT_TRUE(vma_write_started(vma_prev)); ASSERT_EQ(mm.map_count, 1); + if (prev_is_sticky || middle_is_sticky) + ASSERT_TRUE(IS_SET(vma_prev->vm_flags, VM_STICKY)); =20 /* Clear down and reset. We should have deleted vma. */ ASSERT_EQ(cleanup_mm(&mm, &vmi), 1); @@ -1124,10 +1178,10 @@ static bool test_merge_existing(void) * 0123456789 * PPPPPPPPPP */ - vma_prev =3D alloc_and_link_vma(&mm, 0, 0x3000, 0, vm_flags); + vma_prev =3D alloc_and_link_vma(&mm, 0, 0x3000, 0, prev_flags); vma_prev->vm_ops =3D &vm_ops; /* This should have no impact. */ vma =3D alloc_and_link_vma(&mm, 0x3000, 0x7000, 3, vm_flags); - vma_next =3D alloc_and_link_vma(&mm, 0x7000, 0x9000, 7, vm_flags); + vma_next =3D alloc_and_link_vma(&mm, 0x7000, 0x9000, 7, next_flags); vmg_set_range_anon_vma(&vmg, 0x3000, 0x7000, 3, vm_flags, &dummy_anon_vma= ); vmg.prev =3D vma_prev; vmg.middle =3D vma; @@ -1140,6 +1194,8 @@ static bool test_merge_existing(void) ASSERT_EQ(vma_prev->anon_vma, &dummy_anon_vma); ASSERT_TRUE(vma_write_started(vma_prev)); ASSERT_EQ(mm.map_count, 1); + if (prev_is_sticky || middle_is_sticky || next_is_sticky) + ASSERT_TRUE(IS_SET(vma_prev->vm_flags, VM_STICKY)); =20 /* Clear down and reset. We should have deleted prev and next. */ ASSERT_EQ(cleanup_mm(&mm, &vmi), 1); @@ -1159,9 +1215,9 @@ static bool test_merge_existing(void) * PPPVVVVVNNN */ =20 - vma_prev =3D alloc_and_link_vma(&mm, 0, 0x3000, 0, vm_flags); + vma_prev =3D alloc_and_link_vma(&mm, 0, 0x3000, 0, prev_flags); vma =3D alloc_and_link_vma(&mm, 0x3000, 0x8000, 3, vm_flags); - vma_next =3D alloc_and_link_vma(&mm, 0x8000, 0xa000, 8, vm_flags); + vma_next =3D alloc_and_link_vma(&mm, 0x8000, 0xa000, 8, next_flags); =20 vmg_set_range(&vmg, 0x4000, 0x5000, 4, vm_flags); vmg.prev =3D vma; @@ -1204,6 +1260,19 @@ static bool test_merge_existing(void) return true; } =20 +static bool test_merge_existing(void) +{ + int i, j, k; + + /* Generate every possible permutation of sticky flags. */ + for (i =3D 0; i < 2; i++) + for (j =3D 0; j < 2; j++) + for (k =3D 0; k < 2; k++) + ASSERT_TRUE(__test_merge_existing(i, j, k)); + + return true; +} + static bool test_anon_vma_non_mergeable(void) { vm_flags_t vm_flags =3D VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE; --=20 2.51.2 From nobody Tue Dec 2 02:43:46 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 8CB6834CFCB; Tue, 18 Nov 2025 10:20:28 +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=1763461233; cv=fail; b=KSrgE0lmCm0JeeTIAsiG6624yqx0OZOL/meosLwsxop6P7cQJ8eAcSJIQHkUyuvpLRvUtkvTIaSvilyJ1/A8JyYGfT64dX5i7nalChVZqOsnYLycAn4OHFjdjEQAt5+wRVBvx2J4UcVh12EAKx+tmhxLRlxeoA44m9OJhbpy0mM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763461233; c=relaxed/simple; bh=Ytdo3mccY4KI7Hzerc/p/bkl53dJecGo78+cqNk8TUY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=EyPlvcP4IZ158zO/BgQJqsxd8gHTp4JjOkG72+0unlLRgpS/Bp9rS3Zd7YBspz3ElkMvemo2b14l8U3PmHi+tUEXSLajZsvFHs37bB0nIoVIqCJeUMyEV8O/4p5ngFpBposTtSyC4UO+DjTHwbnB8bPclTG0Kz2ossDfW/kodcw= 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=rS0kij9b; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=IBkYGurY; 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="rS0kij9b"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="IBkYGurY" Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 5AI9CnqC008908; Tue, 18 Nov 2025 10:18:43 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-2025-04-25; bh=DTZvud34c6Go/B2rzQvutlMJi9tas+bDDXFiWl8H3Q8=; b= rS0kij9bcm5hsGr4NLWv62V+UVmt4GdXcJ7n/jPetpzNPaSdQVTzZd3+96QeQE6k sbrhGe7NyDzvDqwL+UOWUKxJO6L6yQVwsIqTDGy7N0JsgljzHJW+lyjQiq4rIUnX UTazeuAoZQWtZ6tNy+7nUS+hcgZr5jvN+mApdB0MiCjUl1x0HjpAUxRkToFsj+xe Yc9c8zHsyHn6dSqyPwVDMYZUf3YLDEAM9GgAi9KMyLZwKLfMnCVeaQFzam6j/z6n PbxvPi9+opOFwASY4AIlRJ56uS1q+KNWnjxECxZXpZ2kcr6+lQjaN5rpbVom3fQo 3g93sJOmYd5bk1JEo4l/aQ== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aej964gyx-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:42 +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 5AI9NsrY040040; Tue, 18 Nov 2025 10:18:41 GMT Received: from sn4pr0501cu005.outbound.protection.outlook.com (mail-southcentralusazon11011045.outbound.protection.outlook.com [40.93.194.45]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyk8qpj-4 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=vuwEcqBQjqW5FhUdYpufanrPfbi20K9LaopLzGFDXnNXk6jB2sKkhgGsUFS1vLi3ITwC12XhOj5eZu953D/4EyCuz/q/pzcQrwO8FmHaAQnBY5UxP3/oFVqK3vMUVDUpYRnAs47XAB/QgJWzfDezayGSmnrTHMye56eKDASCrpKk4YTP403c+NDjgHHGTCrfGhroNjqr1OLSg4PxW872kWYTeyirfymAIpPZTNqjcJXvXuTusKz9i63yHQ+VgUzYptHmapwJWaWGRiafUQkTUbCMSwDDo4m9787AFAJgu5O7PFz5bwsLS0ymxugViPS/d61CCS4q4m886Cs1L41REQ== 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=DTZvud34c6Go/B2rzQvutlMJi9tas+bDDXFiWl8H3Q8=; b=np8A+EIOYzxjjMFpBujoAYj02mZXaF76gZAcrm/6Wo5g1vY8BcN954+1AdhHvjfguRKY1yJVsqiXxwhXJ89yVEeFLYNH+qRdAQaURxh6g7pV0AC96nbNZasbmQjYKrHwiVnWD9nB2pS2pUn5Qrj4nMcDTNPtTaOcE5YEhdXr4lbI/moGRrlc087kLS0F+8pte8rOClBbETakz/yRrNqAADNHzNgsoQGjINbAc8qrz73fBqKypDCB3rvFDhZHVDm8hegnSvsytmzNfnM8qHtSNb4VHr/fK/YIxFMkru8bh7x1YHjsUaamM4UYEDE2EFToDgdwobl9XUgB5R5/Y2w+cQ== 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=DTZvud34c6Go/B2rzQvutlMJi9tas+bDDXFiWl8H3Q8=; b=IBkYGurYbST4DZHOBT6ot9RkBnE9PNt9+C+3CqtBWjKCGw4Dq+2vADwVD6/w+CO5gLfAS0lAldxV6czOFVgaeUdYbS8WZU5oPFJMJ1Qvf2zJeUfPqJMyN+bdSOcf+lrqUi1QUtbGyBHMa+6eivJvMei+JejqjNPIkB6zhWmkmtU= Received: from DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) by IA4PR10MB8756.namprd10.prod.outlook.com (2603:10b6:208:562::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.21; Tue, 18 Nov 2025 10:18:38 +0000 Received: from DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2]) by DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2%7]) with mapi id 15.20.9343.009; Tue, 18 Nov 2025 10:18:38 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Jonathan Corbet , David Hildenbrand , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jann Horn , Pedro Falcato , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Andrei Vagin Subject: [PATCH v4 8/9] tools/testing/selftests/mm: add MADV_COLLAPSE test case Date: Tue, 18 Nov 2025 10:17:50 +0000 Message-ID: <0748beeb864525b8ddfa51adad7128dd32eb3ac4.1763460113.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO4P123CA0332.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18c::13) To BL4PR10MB8229.namprd10.prod.outlook.com (2603:10b6:208:4e6::14) 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_|IA4PR10MB8756:EE_ X-MS-Office365-Filtering-Correlation-Id: eb6e117e-daa9-4a03-f96e-08de268bd6d9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?hatMU9Py3e9IvJKIWwG1bTzCpEReCpn3g/ZjIXItx4V1yUFLTr6tXmn4NbTt?= =?us-ascii?Q?iP6PDCQf6LgYFmbPHJqXSCFUAQoOjkz3kzaTJKATPtbfWjEwPKDoFdN2Tobu?= =?us-ascii?Q?f0r/rjbmhbjLJLsO4pXyNw2N++T0ri+efVmFdHFQYSGr5HvNS1Td44RohY73?= =?us-ascii?Q?Nw7RCQmHYeB31pZGK976G0t9G5s+PyvEBh/EPR9u/eHWbAjVbK57pQpsgyLR?= =?us-ascii?Q?XV0deoRT5tLSVH4y7GuNGsqrKh2OxtaRWbg7SQgqdZVlrOgKsIHgw/IDeQf9?= =?us-ascii?Q?rJCMaKcpNVIA/cgMhpz3BC5eolEqZvu9r+W/iGZXx/SzISmC0hr3FZ2jZeiZ?= =?us-ascii?Q?9/c5GRHA9pfKXzL36m4S6Kc/RaThR6mGBXHVfS8T0Fha7aA7y/hNz5Gx/rDm?= =?us-ascii?Q?2StUbJWr+Z/e31YXNp50PcePu9of2XEJ+QY9Gqfi6oAofQThPGUX2A2hKpmL?= =?us-ascii?Q?sDpoC9t13neI0Rf5VM4YS2159sO8Do62HtxW39A5w9OhpMeCW/REgJ+pGBC8?= =?us-ascii?Q?KPrr6jPBqBHvx0bl5nmSDudAYmN3sjJPulY/Fb1i9zxSk5JWgXZ99t20duot?= =?us-ascii?Q?jnSqNZpKflYn3Lqlwrjv6tzysRVQ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255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM4PR10MB8218.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?IThwP4h/vmyTNTBALuEExU7vvzY3KF8y0xeCLCIh3VB+c6/YjxVwPbLwSykO?= =?us-ascii?Q?GJ/MnP+GMB7QjZ/bxJb5Z5IrNumZU4+foBAu/CyKzPalIumyJOp6KNdVCfMe?= =?us-ascii?Q?ar0eYcQqqJL2ywBggLsrwaMEAAasVACG6yeKHWSx3Ax3y5a6zKfLKM1G8rbd?= =?us-ascii?Q?jgeta+wO3zCsKVjVOXeDlp/AL7AZKMH7MLtP04s6t3wPHSEhqOFZn5KW6f5C?= =?us-ascii?Q?apWZujYHn2sCu/Vq7yUVaN4TtWu1QsS8GgfGvwFKDm7UsdKbTMdSe8GVi6q9?= =?us-ascii?Q?mBnbP5951t+Y77fPcYM7IQcHqgDpnaIJtxQJIIUO879g2NBaqLVdOvPj0MpN?= =?us-ascii?Q?+Ftbcsq+8Mx+62oxfF+K9L6jDW51vekwZXcDlY7Lrv/APWUTDVVrrxj6nA/U?= =?us-ascii?Q?DHFFi1zm+Z0XHNJ5pUmgcrBimFwElBAvJEKC27X3bn9v6MdyQafJn7BPumUW?= =?us-ascii?Q?hcc4sibb4bFYvIVmwANb8X4BTjRV/hg75DR6kX8bMU8SdeBlQPhbd5qsoYqM?= =?us-ascii?Q?9CKZUNdF7Rer+iwCHUYwry0H+/cGIJ/F3BhNM/V7VLu3dNgeZ3WotJTYPPUh?= =?us-ascii?Q?fg21psQl0G83XjXTBCl1LNFc5I/Phvd2T8gw3BMpFjsH+v5gO9fAWuWQ/yoU?= =?us-ascii?Q?2W12bfvvyXmkfKHftjZdkNS2ttwDxVlQeyDAH8ZvGTb8O77dd3yWnH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J6qxEsgD0U1JXeMIoMxjiEdWsaIjHS?= =?us-ascii?Q?2g=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: ow3KV7dI0XdzDk5J1D5Yhf1/gwa5FiejeE0sPX2B+ZbfizWQOgDWgVw7zO33RK3RYOGbYcjshc2exlqCt/nMj+mXQlgMC4+t9duaqSBG1sTYKcBKls3K7ixAtkM/ahNMrYEbMZ7TWfjM485X3vlbukJharyMjj3PBDUCfwiMsPa26lAHk1aIwa095ihG3HWydAkg16kKqRvFzIuJrRAZcwvB8P+pe8WYI4QBFXcJv6Tm9Cpe0YF7bYzoOsUmm2BeTwypoqbYHj0tIG6C4CxokPiIlH+BZhHd17BD8b9s/Ze6+iAmRg3tA+d/rwjsKl7w03/MKLOENuahL5lGqbCHkUIU9gbhjS6m2VtI1lvYylZN/oMbfHIaxaDSIHbGsFDnCZqUNndRc4Li7+ACY1Qq4gVHZp62wkyoBWN5ki9P1T+mc/BMIJyCydYtsImvmNJ205PPQNt5Ko1QOW+NJiN4uHqVi7R2zlAHOViDV4rx1R62efMSu+dDLdFq0wfG1oOd8OgJ7TJiqREBNEWsby0uNiOctzZcK0rGNAkD2otRruClpPZAIBfXo+iLnvJShyD5xnKPOKqqRSwJAzjdKA7aIqkvHnIQrI20wmiwUa1xeL0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: eb6e117e-daa9-4a03-f96e-08de268bd6d9 X-MS-Exchange-CrossTenant-AuthSource: BL4PR10MB8229.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2025 10:18:38.4466 (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: 8/AXhe9x0XC+4fpL20NwHHCTPrcAwdEddd6o0fvzwJ3DlCr6yK3vZxzI16+7z5JEw8pgkIjXz87JTZUBPMniBYnBChMKfFu2p2/u9QIbpPA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA4PR10MB8756 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-17_04,2025-11-13_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 suspectscore=0 spamscore=0 adultscore=0 mlxscore=0 mlxlogscore=999 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511180082 X-Authority-Analysis: v=2.4 cv=DYoaa/tW c=1 sm=1 tr=0 ts=691c4803 b=1 cx=c_pps a=qoll8+KPOyaMroiJ2sR5sw==:117 a=qoll8+KPOyaMroiJ2sR5sw==:17 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=z/mQ4Ysz8XfWz/Q5cLBRGdckG28=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=xqWC_Br6kY4A:10 a=6UeiqGixMTsA:10 a=GoEa3M9JfhUA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=WR8ShyrngeSRY8Fu9_gA:9 cc=ntf awl=host:12099 X-Proofpoint-GUID: ugPfONMteMM_2N0Zrcw9yUaoJuTwOddB X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfXxSMI79a4Bgob +u1kp2HDDQztAjQZLGjUeoiSsKe0sYD9pAdXNPvtLGvJ4oMMlwH+sYGSajxvuKNmkJyaGifF5Sa 7SHTn2UJC74Rb2j9qX+G6L5raXjBCiN6fq4qpwiebJ/nh1ht30tLtcsBWzRme+XhfP+eoma4y6L ANE0vQQP6TGGnhlsAIwN9eLBADcTvl7lov9RM0E5qESH8tZoEAUTqW4ja+yYMsjCdLYejZsd+Dc B5T75XSdubGB5iNyaEk1BadDbmOa2OuJIKcbRbg83wg9EJUm7As5J4/89vLMfXGYcwu25UKpfFx ookFr363C37l77unU0hq/T0/40l1szPwlmG6JXBwdJmyYN9i1jxODQpfzECVLTweDrwG1vFzwp3 Y4DdLYg/tHR8HCyHJ+yjR3DfyjCv/9OPk4gi8ftIxubKb5IFsZ8= X-Proofpoint-ORIG-GUID: ugPfONMteMM_2N0Zrcw9yUaoJuTwOddB Content-Type: text/plain; charset="utf-8" To ensure the retract_page_tables() logic functions correctly with the introduction of VM_MAYBE_GUARD, add a test to assert that madvise collapse fails when guard regions are established in the collapsed range in all cases. Unfortunately we cannot differentiate between e.g. CONFIG_READ_ONLY_THP_FOR_FS not being set vs. a file-backed VMA having collapse correctly disallowed, so in each instance we will get an assert pass here. We add an additional check to see whether guard regions are preserved across collapse in case of a bug causing the collapse to succeed, which will give us more data to debug with should this occur in future. Signed-off-by: Lorenzo Stoakes --- tools/testing/selftests/mm/guard-regions.c | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/tools/testing/selftests/mm/guard-regions.c b/tools/testing/sel= ftests/mm/guard-regions.c index 8dd81c0a4a5a..c549bcd6160b 100644 --- a/tools/testing/selftests/mm/guard-regions.c +++ b/tools/testing/selftests/mm/guard-regions.c @@ -2138,4 +2138,69 @@ TEST_F(guard_regions, pagemap_scan) ASSERT_EQ(munmap(ptr, 10 * page_size), 0); } =20 +TEST_F(guard_regions, collapse) +{ + const unsigned long page_size =3D self->page_size; + const unsigned long size =3D 2 * HPAGE_SIZE; + const unsigned long num_pages =3D size / page_size; + char *ptr; + int i; + + /* Need file to be correct size for tests for non-anon. */ + if (variant->backing !=3D ANON_BACKED) + ASSERT_EQ(ftruncate(self->fd, size), 0); + + /* + * We must close and re-open local-file backed as read-only for + * CONFIG_READ_ONLY_THP_FOR_FS to work. + */ + if (variant->backing =3D=3D LOCAL_FILE_BACKED) { + ASSERT_EQ(close(self->fd), 0); + + self->fd =3D open(self->path, O_RDONLY); + ASSERT_GE(self->fd, 0); + } + + ptr =3D mmap_(self, variant, NULL, size, PROT_READ, 0, 0); + ASSERT_NE(ptr, MAP_FAILED); + + /* Prevent being faulted-in as huge. */ + ASSERT_EQ(madvise(ptr, size, MADV_NOHUGEPAGE), 0); + /* Fault in. */ + ASSERT_EQ(madvise(ptr, size, MADV_POPULATE_READ), 0); + + /* Install guard regions in ever other page. */ + for (i =3D 0; i < num_pages; i +=3D 2) { + char *ptr_page =3D &ptr[i * page_size]; + + ASSERT_EQ(madvise(ptr_page, page_size, MADV_GUARD_INSTALL), 0); + /* Accesses should now fail. */ + ASSERT_FALSE(try_read_buf(ptr_page)); + } + + /* Allow huge page throughout region. */ + ASSERT_EQ(madvise(ptr, size, MADV_HUGEPAGE), 0); + + /* + * Now collapse the entire region. This should fail in all cases. + * + * The madvise() call will also fail if CONFIG_READ_ONLY_THP_FOR_FS is + * not set for the local file case, but we can't differentiate whether + * this occurred or if the collapse was rightly rejected. + */ + EXPECT_NE(madvise(ptr, size, MADV_COLLAPSE), 0); + + /* + * If we introduce a bug that causes the collapse to succeed, gather + * data on whether guard regions are at least preserved. The test will + * fail at this point in any case. + */ + for (i =3D 0; i < num_pages; i +=3D 2) { + char *ptr_page =3D &ptr[i * page_size]; + + /* Accesses should still fail. */ + ASSERT_FALSE(try_read_buf(ptr_page)); + } +} + TEST_HARNESS_MAIN --=20 2.51.2 From nobody Tue Dec 2 02:43:46 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 2F0C934678B; Tue, 18 Nov 2025 10:19:48 +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=1763461193; cv=fail; b=BANs14Fw8BxjrzUnxG9YfshSrOOpROOQuoJETiMWF0q3UVjScCwzOTDkkgebib6qX2o8a6QRZi/xdj5c5nDzC/8sl9Yvzf3djiVmj+RshPiLhxJ61S3e6DMMHC6bExaJ+aEz1lJZaC1fYZPCPGSTsWhRVGhgKngpCU44Wg5w+Rc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763461193; c=relaxed/simple; bh=Wu/wORsVYHxt58HJ5dVJ4XyhgXPLyurcLJfZRxtmtHs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=qVJgmxeqnDdr2EmQ6iFGYSId4BAgfBPe19Jwh96XAvid+24jeku+t9ocJEJuPI+GuU+wTx561FMxJijdM8Qh+7hOJ1UIEcg+1tGCU+RrFTFFxhC5ryVEqQbQ8//OHYdljwHZPapXd4l09moxNrxNSH2Q0reQ9yyRSQXSs7Ywr4Y= 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=TgO1qsq3; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=XoBIg/1m; 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="TgO1qsq3"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="XoBIg/1m" 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 5AI9CYW1024772; Tue, 18 Nov 2025 10:18:46 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-2025-04-25; bh=6cjn1Gd945CYCHU2XQyGJUGqveqDQQ5FuRAfWVyr9ho=; b= TgO1qsq3WdQqvPkcPVPs1yMXjb2n/kKsAEp9fwZmV3MBpk4EC1JyeJVXli63iqr4 ixD76fh/6ob5SIWPkJTRS/i64bacZRxsCn/NFBT8Y0Ju4t1P2+5SoLlrfZ39gvQv XLbxQLmZOhMhhxk/0LEXnvRSRTmBEqfr459/7JLVRpKLIjLRLln61K8X9HN+ZEBR ld/29XUXoVk57rNMoQ4ZEAv9RUSD/cTOqaCAe413YQUxzEb+qRccp1IvM0WJCRQ3 2hBxS/Y4FyzcCwYUrq75HQeL1qluM7AYN2k6/iYE5keiH5MaYemdq3p0FlXGs2/M zHtAvFF3ew1rEYED62oXGg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 4aejbpvjfr-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:46 +0000 (GMT) Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 5AI81Hmn035898; Tue, 18 Nov 2025 10:18:44 GMT Received: from sn4pr0501cu005.outbound.protection.outlook.com (mail-southcentralusazon11011058.outbound.protection.outlook.com [40.93.194.58]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 4aefyk741w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 18 Nov 2025 10:18:44 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LZOO43CUpQcTQxv6AWqJoJqtc2pV222jgly320AEdCpI6QyuTyj+Hl90RqQzp8OFKU1nbOtPATT1nWKL+c4oDqlFr7ttIOrY7LMNYk9rlFtdsWn8wc/pTairnGQ2tN/veQB+s5OThZA039hSZiFFasOVUv2eqNUQVUBggFhlSRa1oxg82lWpjFe4tutnK86QmwW37XeNe1nkt8+erKcJteonm6OVIS7zn4NbJNX8ON93K82hOPKVPr+8wfxHKBp26lmWQX56bDVtOnGW79aDUGhLCz7x6Yk7XIAUM21/mdF4loHHbgovigRMgF4OR6LOs65AbUNomCM5whFN9XEL6Q== 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=6cjn1Gd945CYCHU2XQyGJUGqveqDQQ5FuRAfWVyr9ho=; b=UyS9Nu7/h4XC/c5nL1xG/oFnTcojPICQBV7JOAyPLiDS/ONQG30nS2oXo8GLExGYB7TrPhIl1VrFoNFV9qmZ6SUNJQl6q0PSAAKiXQKUIt0VM2YncolROLg3gZCFuQToEHrDeeW2EK08Lm+nFVPaBk54RRx3PXwJ5wFlbbqLagECUpE1ngvymezWT38fIFwSzo3LTPvdC+0OPxu+NLwEnWdgfkbWtqHMO8ZrboJwpqS+QUgbM//vtbKouH0PekBvAoDbp25gZLFzDUbTrNK5EEP6vbKVIpyghr3W5VWaO5+2OvMrXZrpiGDiPZq6UKn865jFsVIhpH074aTh4sRMSQ== 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=6cjn1Gd945CYCHU2XQyGJUGqveqDQQ5FuRAfWVyr9ho=; b=XoBIg/1mu1de71NY6NfVAv4q4PIhzqUGXXSg6cONqa/M4ylnYAoK5djF1EiGG1Bh6SJRjhXDnL5UwJrQVqDcECZkFh0wEX9V9jCU2bb0jpwnMH6PpgBU3tWOO0NmECKe4B5BkQ1ccubRDWO/9Zg6oYSitnjIwQKyygZM04TT5DA= Received: from DM4PR10MB8218.namprd10.prod.outlook.com (2603:10b6:8:1cc::16) by IA4PR10MB8756.namprd10.prod.outlook.com (2603:10b6:208:562::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.9320.21; Tue, 18 Nov 2025 10:18:41 +0000 Received: from DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2]) by DM4PR10MB8218.namprd10.prod.outlook.com ([fe80::2650:55cf:2816:5f2%7]) with mapi id 15.20.9343.009; Tue, 18 Nov 2025 10:18:41 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Jonathan Corbet , David Hildenbrand , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Jann Horn , Pedro Falcato , Zi Yan , Baolin Wang , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Andrei Vagin Subject: [PATCH v4 9/9] tools/testing/selftests/mm: add smaps visibility guard region test Date: Tue, 18 Nov 2025 10:17:51 +0000 Message-ID: <059e62b8c67e55e6d849878206a95ea1d7c1e885.1763460113.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.51.2 In-Reply-To: References: Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: LO3P265CA0026.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:387::9) To BL4PR10MB8229.namprd10.prod.outlook.com (2603:10b6:208:4e6::14) 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_|IA4PR10MB8756:EE_ X-MS-Office365-Filtering-Correlation-Id: 81db302a-ad58-4324-86b5-08de268bd87a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|1800799024|366016; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?ft0QFR8U1n6NBEnSzV1JdvJdOPv3PSc4o7tCKIVOFzyfEjJqq2mAO+6s49dI?= =?us-ascii?Q?Q6GfRxOC0BHpozBtOQT0g4TrLu/TswTVJ5WMdl8n+KKttflaYUcIfdougdm3?= =?us-ascii?Q?jhuCzCoMYlybWoDaczwd+l1AMkxNfhuRp8JNX0yvOt8tbP2Syo3PFbKuNeqA?= =?us-ascii?Q?Dq1xW2sasRMRj+rcHTJAaZwVPMNjlLlN8W43G8f/RZIqOucw7nlv80WLe85U?= =?us-ascii?Q?VQprQtRhGPakwHoq6dcYfdGY6hS7EPdZ1oBQmCAPid9XmipLpCUMQQ3B9b2/?= =?us-ascii?Q?gKnyxxnwfAqGEmp7k0pk+gzBDDK7odlDTKhWhbRkVGLzOkPXrtJNBZlQ6r0F?= =?us-ascii?Q?17xm9BXY8m5kqs4C68YGwNsgEubAnP8jGRf2vf1b/7AkNbH9zXiEbJwUFtVI?= =?us-ascii?Q?HmGzObsrZiFRGmLpUM1IO+WJgQR6FWftTXXYU85D1alz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lfXqDYnBabCsuxdglIVH0LnmfdDuG96GjpnJ7zJJdyyU?= =?us-ascii?Q?S5WeEFVNOL9cEz/Lvw5YCZz4o8YrGHyR3Ti2xVBwNMXdu+qyvdGkRQDlObuk?= =?us-ascii?Q?pY8ZKDCPVYL/uAGM2V+l9UlV2+9u3ZA+?= 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)(376014)(7416014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?8Wj4IJxuKp6TBx86wgtJhs8XLTu1dRn+jlcWWy7ZhJZNTZp32rkgrwlX/jEo?= =?us-ascii?Q?zPCmhxmLFmwCXcb5v2YSPUIQRZO/KD8VqlikvDkwNHdCWdXa/2cDZMhbJJV/?= =?us-ascii?Q?wG/iOISjwI9Y4m543/wJDUvnKR0Q66AuQAzKyrjSwqXJ70/SO3oSJ2hsWlnW?= =?us-ascii?Q?JarRfUy3zeMGCbqfvcO4GL40Q+xJsQXnXAzqZWabWZSyg5x0zJLyZnZmcwzD?= =?us-ascii?Q?C2wMsajkv/v+c5l17NWqJVtoT+HJQzRNzNIHVjTRSIeiHAqLqJABonIoog1V?= =?us-ascii?Q?sp8/MR19b0pKtpYGGp6m8B6nm4tSv1Mg4utvGxrZxRgCaF7lguodKURkzHPW?= =?us-ascii?Q?hb8BqKylaN+fg0K4VToT6pLWZCJ4VrliNlPrEBX6v8IQ7Sn1nOQ14voVHZHE?= =?us-ascii?Q?4HaO7yBcoRXsgWk/oey9a++A+pMxVsY+C54hptvCvYMSoe6VfCB/S6LINhID?= =?us-ascii?Q?LJ+9m5NgXFld4H0Y5UCESl0Xrsgz8uHGsM3UGZnkV6vLEjC6WY7Elu5v56a2?= =?us-ascii?Q?EO7lE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BJd?= =?us-ascii?Q?nK5JOC7FNNfKb/PpWu5BZAwiPZWhyJBdxexyJQzWeNzGQknBWER2V/qNvEiz?= =?us-ascii?Q?r/hydX4a99LJRALEy2zL8djTBscL9Dmi0uwVbk+wepZTal+t1cUcsTF5PyYe?= =?us-ascii?Q?BCYf/Jm3OU+553pJIvTB2lo2gDCgBh5FnyTSx9BYwgOfIaxoHMdNzW+6dmKW?= =?us-ascii?Q?Iw=3D=3D?= X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: NH3T18zeZ5HUo7uUrBMhud+qKMie8UsRDc2yGAwZJtkXpvJHXGk9MCW7tgHl0m3EeDa8AD66sKNjyIC+xyCdiLxV1WPFIHhaaHLlfCYpy/WwNrcY+++qydyzdzgo2wqjqLo0WDwZOQudyRToTHwsyrKXOazN5Fu5QNhoGEIAidB58QJ0opaSBW51as7IApvIrx4v5nnJkMwXp/oyptn6yMDlVOdvGAbKgj+5r+cGUh64NOh4moP7m92vOVWnct5BjCRtdeAhcgyguPp3trOv9TcvImmbcs7Bzc4g77l0XHGc+Zv0JFWa/XQoaK8XXIxuZAp4H4nE6f3hysPR3S5hw0bTPJ83mwG/VL/5EJ99NCmR/aXEpy3mcRzBWDrrFeIwwZ+Mrs+wj7kwjewdBswheHLOwj75870slUzWGWYvyUnDJl92BminZoirnh7DoScTIwFPoLMJJHer9VaNDHDiZP1dsONXgIoZrSA6diw4JWxtJc4WSowq6WoEvnCZ9kjUgqmJzKwG16mKBiCdeUl0bDaszyAeDNaB8s3PFonlTOmy96c2giU9DyPxXMCdYrtEvrCg4FvwReEKTNSW3w0Z3W2te6aAMvbR4b3MGjMY4f4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 81db302a-ad58-4324-86b5-08de268bd87a X-MS-Exchange-CrossTenant-AuthSource: BL4PR10MB8229.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Nov 2025 10:18:41.1562 (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: esbvyNyYAM5nX4r4k9rtOz7OPlFAQYZK9Yi3vQLnuPmAH3kKvd+go9dmPSIegybBFj32XLHF4At3Y0ay0Y65hzJMF8ELj8jbmzhXd9buppE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA4PR10MB8756 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1121,Hydra:6.1.9,FMLib:17.12.100.49 definitions=2025-11-17_04,2025-11-13_02,2025-10-01_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 spamscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 mlxscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2510240000 definitions=main-2511180082 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUxMTE1MDAzMSBTYWx0ZWRfX3zbjY7tHSy2m EAodRXTbL22fsXDZ6n5gJrQE+QbEPA/b4wR+K98D3dV5GoiqwAEkTjSu4tazlJ58Tg3aJNI4AoG geLyamwJOUud2SCtW+82xDi7qz54biBCU7Fvosy6ZYXiVAc0FtffWpeGR9F6K9u4ntY4X7plD1K I1d6b8N0igWYGxGRCuCkfTVUF3IVGSlTVEKpuPTvk3fG3eo6yREFqO9exFugHeZ3589wuQjFB5A VY2fL4o5qpHb8x++OCGgGIAbeGB67/T4DKi0oDmJJYGmy1Aw8keBpz7KveC3VniaMc2zZVz9GM7 /eqf6+NFX6rFxUwgM2LBZrubgulSdo25I+9nW2tPbZlsPC6Y0f3ikE9oHjtC0zyEOOWw2mIuDP2 /W5TQQRFbzPA5NnPTpPxG7dFT6QJVszUmZSS6bg7xSYfaJ7+FkY= X-Proofpoint-ORIG-GUID: IL3ihgbvXh7bBNedjvbQN-xRwU7r1vlm X-Proofpoint-GUID: IL3ihgbvXh7bBNedjvbQN-xRwU7r1vlm X-Authority-Analysis: v=2.4 cv=a+o9NESF c=1 sm=1 tr=0 ts=691c4806 b=1 cx=c_pps a=zPCbziy225d3KhSqZt3L1A==:117 a=zPCbziy225d3KhSqZt3L1A==:17 a=6eWqkTHjU83fiwn7nKZWdM+Sl24=:19 a=z/mQ4Ysz8XfWz/Q5cLBRGdckG28=:19 a=lCpzRmAYbLLaTzLvsPZ7Mbvzbb8=:19 a=xqWC_Br6kY4A:10 a=6UeiqGixMTsA:10 a=GoEa3M9JfhUA:10 a=VkNPw1HP01LnGYTKEx00:22 a=yPCof4ZbAAAA:8 a=7oKVWYA_E11v4TV8rOgA:9 cc=ntf awl=host:12098 Content-Type: text/plain; charset="utf-8" Assert that we observe guard regions appearing in /proc/$pid/smaps as expected, and when split/merge is performed too (with expected sticky behaviour). Also add handling for file systems which don't sanely handle mmap() VMA merging so we don't incorrectly encounter a test failure in this situation. Signed-off-by: Lorenzo Stoakes --- tools/testing/selftests/mm/guard-regions.c | 120 +++++++++++++++++++++ tools/testing/selftests/mm/vm_util.c | 5 + tools/testing/selftests/mm/vm_util.h | 1 + 3 files changed, 126 insertions(+) diff --git a/tools/testing/selftests/mm/guard-regions.c b/tools/testing/sel= ftests/mm/guard-regions.c index c549bcd6160b..795bf3f39f44 100644 --- a/tools/testing/selftests/mm/guard-regions.c +++ b/tools/testing/selftests/mm/guard-regions.c @@ -94,6 +94,7 @@ static void *mmap_(FIXTURE_DATA(guard_regions) * self, case ANON_BACKED: flags |=3D MAP_PRIVATE | MAP_ANON; fd =3D -1; + offset =3D 0; break; case SHMEM_BACKED: case LOCAL_FILE_BACKED: @@ -260,6 +261,54 @@ static bool is_buf_eq(char *buf, size_t size, char chr) return true; } =20 +/* + * Some file systems have issues with merging due to changing merge-sensit= ive + * parameters in the .mmap callback, and prior to .mmap_prepare being + * implemented everywhere this will now result in an unexpected failure to + * merge (e.g. - overlayfs). + * + * Perform a simple test to see if the local file system suffers from this= , if + * it does then we can skip test logic that assumes local file system merg= ing is + * sane. + */ +static bool local_fs_has_sane_mmap(FIXTURE_DATA(guard_regions) * self, + const FIXTURE_VARIANT(guard_regions) * variant) +{ + const unsigned long page_size =3D self->page_size; + char *ptr, *ptr2; + struct procmap_fd procmap; + + if (variant->backing !=3D LOCAL_FILE_BACKED) + return true; + + /* Map 10 pages. */ + ptr =3D mmap_(self, variant, NULL, 10 * page_size, PROT_READ | PROT_WRITE= , 0, 0); + if (ptr =3D=3D MAP_FAILED) + return false; + /* Unmap the middle. */ + munmap(&ptr[5 * page_size], page_size); + + /* Map again. */ + ptr2 =3D mmap_(self, variant, &ptr[5 * page_size], page_size, PROT_READ |= PROT_WRITE, + MAP_FIXED, 5 * page_size); + + if (ptr2 =3D=3D MAP_FAILED) + return false; + + /* Now make sure they all merged. */ + if (open_self_procmap(&procmap) !=3D 0) + return false; + if (!find_vma_procmap(&procmap, ptr)) + return false; + if (procmap.query.vma_start !=3D (unsigned long)ptr) + return false; + if (procmap.query.vma_end !=3D (unsigned long)ptr + 10 * page_size) + return false; + close_procmap(&procmap); + + return true; +} + FIXTURE_SETUP(guard_regions) { self->page_size =3D (unsigned long)sysconf(_SC_PAGESIZE); @@ -2203,4 +2252,75 @@ TEST_F(guard_regions, collapse) } } =20 +TEST_F(guard_regions, smaps) +{ + const unsigned long page_size =3D self->page_size; + struct procmap_fd procmap; + char *ptr, *ptr2; + int i; + + /* Map a region. */ + ptr =3D mmap_(self, variant, NULL, 10 * page_size, PROT_READ | PROT_WRITE= , 0, 0); + ASSERT_NE(ptr, MAP_FAILED); + + /* We shouldn't yet see a guard flag. */ + ASSERT_FALSE(check_vmflag_guard(ptr)); + + /* Install a single guard region. */ + ASSERT_EQ(madvise(ptr, page_size, MADV_GUARD_INSTALL), 0); + + /* Now we should see a guard flag. */ + ASSERT_TRUE(check_vmflag_guard(ptr)); + + /* + * Removing the guard region should not change things because we simply + * cannot accurately track whether a given VMA has had all of its guard + * regions removed. + */ + ASSERT_EQ(madvise(ptr, page_size, MADV_GUARD_REMOVE), 0); + ASSERT_TRUE(check_vmflag_guard(ptr)); + + /* Install guard regions throughout. */ + for (i =3D 0; i < 10; i++) { + ASSERT_EQ(madvise(&ptr[i * page_size], page_size, MADV_GUARD_INSTALL), 0= ); + /* We should always see the guard region flag. */ + ASSERT_TRUE(check_vmflag_guard(ptr)); + } + + /* Split into two VMAs. */ + ASSERT_EQ(munmap(&ptr[4 * page_size], page_size), 0); + + /* Both VMAs should have the guard flag set. */ + ASSERT_TRUE(check_vmflag_guard(ptr)); + ASSERT_TRUE(check_vmflag_guard(&ptr[5 * page_size])); + + /* + * If the local file system is unable to merge VMAs due to having + * unusual characteristics, there is no point in asserting merge + * behaviour. + */ + if (!local_fs_has_sane_mmap(self, variant)) { + TH_LOG("local filesystem does not support sane merging skipping merge te= st"); + return; + } + + /* Map a fresh VMA between the two split VMAs. */ + ptr2 =3D mmap_(self, variant, &ptr[4 * page_size], page_size, + PROT_READ | PROT_WRITE, MAP_FIXED, 4 * page_size); + ASSERT_NE(ptr2, MAP_FAILED); + + /* + * Check the procmap to ensure that this VMA merged with the adjacent + * two. The guard region flag is 'sticky' so should not preclude + * merging. + */ + ASSERT_EQ(open_self_procmap(&procmap), 0); + ASSERT_TRUE(find_vma_procmap(&procmap, ptr)); + ASSERT_EQ(procmap.query.vma_start, (unsigned long)ptr); + ASSERT_EQ(procmap.query.vma_end, (unsigned long)ptr + 10 * page_size); + ASSERT_EQ(close_procmap(&procmap), 0); + /* And, of course, this VMA should have the guard flag set. */ + ASSERT_TRUE(check_vmflag_guard(ptr)); +} + TEST_HARNESS_MAIN diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests= /mm/vm_util.c index e33cda301dad..605cb58ea5c3 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -449,6 +449,11 @@ bool check_vmflag_pfnmap(void *addr) return check_vmflag(addr, "pf"); } =20 +bool check_vmflag_guard(void *addr) +{ + return check_vmflag(addr, "gu"); +} + bool softdirty_supported(void) { char *addr; diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests= /mm/vm_util.h index 26c30fdc0241..a8abdf414d46 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -98,6 +98,7 @@ int uffd_register_with_ioctls(int uffd, void *addr, uint6= 4_t len, unsigned long get_free_hugepages(void); bool check_vmflag_io(void *addr); bool check_vmflag_pfnmap(void *addr); +bool check_vmflag_guard(void *addr); int open_procmap(pid_t pid, struct procmap_fd *procmap_out); int query_procmap(struct procmap_fd *procmap); bool find_vma_procmap(struct procmap_fd *procmap, void *address); --=20 2.51.2