From patchwork Fri Sep 27 12:51:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13814267 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EE85CDD1A0 for ; Fri, 27 Sep 2024 12:52:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B5C8E6B00E0; Fri, 27 Sep 2024 08:52:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B41606B00E1; Fri, 27 Sep 2024 08:52:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89B356B00E1; Fri, 27 Sep 2024 08:52:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 662116B00DF for ; Fri, 27 Sep 2024 08:52:14 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0DCBAA0883 for ; Fri, 27 Sep 2024 12:52:14 +0000 (UTC) X-FDA: 82610506188.29.423CE73 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf20.hostedemail.com (Postfix) with ESMTP id ACD621C0012 for ; Fri, 27 Sep 2024 12:52:10 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=LZ3to4+g; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Oj953Xn3; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf20.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727441408; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5j3+3riJngw5WIz7efPctdC6x/cHnhLERvDk6GlnerQ=; b=cGWzM7VkqK/8yzaJ/WjteCv158yB7CQ3HpB8lQrXloHWaQ+owWhrXxMa0tfvK9ZN52Dbga 2i30rUa3mG+mh05UeaqNPq8AUmGlVYTGuxfbkvlmvXCrH/Nx+gFG0JilMxKCwTzNbwBSyt 7HENQWSFICX8suKywk5hG8GtgNDc1Hk= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1727441408; a=rsa-sha256; cv=pass; b=JmAFpxLYqIOwn9CnCV/wsU26R4RNQYlZHi2OpjvrO6+2mW402pfcg6FJJ9RcRl5jqchM1q Ju2cA0KjVon+REmNk+EoXRrj95Q70iHp0D89xgZhUGBTHpZ3vxOKL/yeWq66u60MKB982t 1TQQgFEriKSnkQ1/ydeST4PmT944R/4= ARC-Authentication-Results: i=2; imf20.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=LZ3to4+g; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=Oj953Xn3; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf20.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com Received: from pps.filterd (m0246629.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48R5gdRs016189; Fri, 27 Sep 2024 12:51:40 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=5j3+3riJngw5WIz7efPctdC6x/cHnhLERvDk6GlnerQ=; b= LZ3to4+gQc2ZZJnrNcO2V57W+DR9fSxSpJniFm6isSTwHODN3tJIYtsU/gu7sG/S daKwH0UNFrOW4gX7QloJ2SQZo0P6qMCBEVs/vJZiQQrlDFlGPY/RQ23dkm0SgFCk 0qxEl/D/+ol+UPN+ZVH7Tjd2xCluN/H68WgtxgcaM3kcaFXcMCGGooHtwT2B2+hz 5biN9YcH/tP2J0DZA+2zXK3DO7Q2lDbnSq3VoiVaRuBiF4erBWbnA8auWanwmWTq cnM3+zp4AZOYF9gRXY9FG2/JEeqYuSxyGPMPSgvXCbViwlwIgn3gDNWEggw/A40l XLUXXZErkVSm0FtNtGYctg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41sp1aqejw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Sep 2024 12:51:39 +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 48RBg16V032720; Fri, 27 Sep 2024 12:51:38 GMT Received: from nam11-dm6-obe.outbound.protection.outlook.com (mail-dm6nam11lp2177.outbound.protection.outlook.com [104.47.57.177]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41smkktqm6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Sep 2024 12:51:38 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=HVWXMmvTEn3nu9uyLr74BZtXZllZpkadwc7I2mYpUVRivwY0GclfHcRzwPlTvR4X7ov5+cA6/h3xcOOsz7A1IloDWahy13r263I/pDaxNtcUgj26mxn5n0sMmTladMWd8M/2IIL0Tx1YIey1SEb7pxooHuf5gqR0H/62A/pbMWoYArV2AoWsnKKsAJWw3V0uJ7auOUb0PmzsTdZD+UpxWijMMsLw0YwabOMFdDu1uKnM4x80r2Mm8rzhgDmsZuY3IuL5j88jnH3yOy68vhQmCVUv7dZcAOKUF/3iUNLqwZbBwxgoWl6vgHdglzWJSZmPDrGeQfw1FY1dCayrx/Hrkw== 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=5j3+3riJngw5WIz7efPctdC6x/cHnhLERvDk6GlnerQ=; b=JWOk6A8qxQlioVT1/9dyE4B8/kupnWTVn8tRC+uwyJez4910ezVQf716KPVpMRqhCSqhg6Gq77EECuUlt5Tc6m6rRNPwZrlMqknp7+oFsa6C9lBnzrOWKeYlURK/75czx9gitpZ+FaQcH9dKA2t23TplCwTgvOEMDPeKrJ6spAkg35IfLq2CCHow4SnFlD8ojGnzL3cJF76DWsAd/4FuwgN23+vKKdkpRRyGSl89HP2oBm/2NmQiIBqIwDYmvE9Ay86GE7b9oTzEI+ERB76CWYOamDZsli1VYEzAPYKdlCG0GuGBYVk7cePTaiiwbGnG6z3HqO28oLZZnuDEDXCY/A== 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=5j3+3riJngw5WIz7efPctdC6x/cHnhLERvDk6GlnerQ=; b=Oj953Xn3nkBrCkd4ax2TytO9MZfGdOq/XCpXdkqm1viuNCrxShyH8+fs5cLPq/usJiHptP9wyBVhbtYAMY0V2SphmXho4wrTFdKw0OGhnn4CcLHOVjQZIJK7Tb31oUm3UsmsEHMZUSAFN1f1Xul6VpmRmfGHPKmsjdUt182JBfQ= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by IA0PR10MB6820.namprd10.prod.outlook.com (2603:10b6:208:437::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8026.10; Fri, 27 Sep 2024 12:51:35 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%5]) with mapi id 15.20.8026.009; Fri, 27 Sep 2024 12:51:35 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Suren Baghdasaryan , "Liam R . Howlett" , Matthew Wilcox , Vlastimil Babka , "Paul E . McKenney" , Jann Horn , David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Muchun Song , Richard Henderson , Ivan Kokshaysky , Matt Turner , Thomas Bogendoerfer , "James E . J . Bottomley" , Helge Deller , Chris Zankel , Max Filippov , Arnd Bergmann , linux-alpha@vger.kernel.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linux-arch@vger.kernel.org, Shuah Khan , Christian Brauner , linux-kselftest@vger.kernel.org, Sidhartha Kumar , Vlastimil Babka Subject: [RFC PATCH 3/4] mm: madvise: implement lightweight guard page mechanism Date: Fri, 27 Sep 2024 13:51:13 +0100 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0259.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:194::12) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|IA0PR10MB6820:EE_ X-MS-Office365-Filtering-Correlation-Id: 44dd7404-ecc0-4899-0ba4-08dcdef31e5d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: bbFDIbFgf/fM1TyZd7zjQIzZXKVisAUxr3J9MRR4USjL/+PQ+nurHzT8Gj2rS40bEbyyLTPOk46FpahshGkhl3XaRh7if2SLrg6Yatswy3np67kALLCwWVp2BP4EvMCikZvz1IaxN3SpQozlSc89fEa+tvhDURk9ZMlmWtRWhVl25VSI+7vfRI26ae+dVJxte0T4ka5iWiXa5HGsr1IPJ340NruZbAQXEhXgrVlVycRj4Rs1V+/s9uWyxOh+EdjLfjzgKZ4SmWQTUL9hsWeP1gVovtqjTqGl0ina2hPghRSNoUyqZ2fd8yaq2VO6UtZk3qDLmcwWr+ARPjzSzltVK9XbWsy/E2hWs6qQFAqTAvcoPfkQ3t1LyBQlVPTnWMvok7IcdGP4RTGYa/yr5RkX7shMVhy+dn7Oo+k86LCUEPQhczf7NCeQwZZ4/63o9P9l//kD9WLLCgQls/Oqy86nmIR1/apas9uOpJEx/4NDEAJwLxwNHTwKPn9WhmJjzcgYx4IxRwcQkl34TR5LlkiLkELnEHRBzKZYfDhj+b2jsx9LAUA8HKez8Lz6zouQyW0HqB9A/p06IYzIFcdvQ6SCScYwGZe8q2IpXvTM2R1jDNO121SLqe+p7RhJHmu4fx21xLWZtln/Z9LW9h1oM5eUQ8GTLGSZIOVuWqFMIXx6Wkte8qEISOi1Hfwga+sjtZZp9INs9b7mbvrNrjLwBlenLM3leQJvKDTFxDZ315Cluw82Aj7FkLFORc+zXh2Buaw6g9i1KmT5fd4twIrK42kiQ5Axh5AnFMIE+K0W013b42Micj+fPJV6WDRxJt5W9U0OAa52DBiyTEZWVseNrdOK0LkNbcksy4FQZ9yzXOR+/tLdA0mVxaU9QbZA4mFh7MLFh1fXW9k4hqEzJOlulqqKqE0uwWklRTFKsJytngQiARw7keT42D6ATgI5lk6nHsT0etQOLqWHRzAU013ZcMP4uJ1RFalHpq0bh6Dku8oLUIf4jQqK8V0MzGhk/3X61UkXgIljRMr0NTXzaLsP7oOpuWRo+Oh9XRwb4vyK2GEEXTSoKBGop2546OzcbHvLhnOp8JEZdVM6hIuCB2IHmpHejve1B1nH01qqex3rwHQjHXLaeYoqSrZh22YrGuYk+5TDOgdLVWmdhUdiozSGFXFPpOgfmNVGjdISkN5+5HoTlJHbcsI3A158p7aDdm1reZ/06kc+D52dMFeh/h7V2dos8rqUVzWXQ56NiiemZZoIlv1sxIOsDna/tS/6dvK64ZltcVBybVT6OIDUTYmt2I3LwXBP71zu4+BFYttrW6vDUy7QdYS5nBYfQidtCoqN3G/iDLsIRANNvKRR1+gySCfirA== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RgmrMQHGEGHnZqWyYxaNt3NHn6takjYluE+aDCyKjhb3oONOeSVO1KECWPgGcoDjmAoAeTiqH2LXi2DgpC8UxBVvlq/abCH6qE+PPJlSuXKsBsXUjvxOH+n2JUpwhkDN1MCK90Y3BnAHfm8rU+ckvkFwtOE5kCpyVVtwj5vZ6uS0YBkP1v730LfVBvq8U3N3+QiKxWsUP7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Hop9ylpghkBckRdnEQirffyZiDpKa0brwZ1O8aBLEr0ZipFZMnFePJ9a17JnjOqWYyq13MDHwzTw3aQIVm08p3Mwy6l6KVBS0bEMKyNwVdLIrpnk7evUjgZSP3llNu77p9ysdg/Sr+V8Qho1eyyYbNAiPAGVGRFxDYhRc3GXoJPkia6/ZvxVreo6C7QDVGXQOrKbRcAZIA/6hHX2urjVglptUP43UTk+gvEQ2eb/MEhSSpgzuJip0i0c4//ZxQ8Wqe6pkYWe0eds2Va5VL31f9bQ3MIBPcipm7+83TWldJUinxu2GbuTQ7hZk4PYOHRcB543cF+X0xw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: DA/jRXNy8u/shzw5B9xmjJl+mVobXSRtW7+b3F52Ebef+2DmHYUsfe54v3xNhpjF+Zd+B7H5qtyWs7kznx3KZI4IomBwUXrGZb5t46YJGkMKiCUdHVKfho3y6hIDrBU+1Psn9PNcr9EdRydYXFpzzQNkTBViJUQI6NMCkZTO/42Q0hHW6BD0cvitfJIQvfiqzkL3maQ2UzveAGzeJlbWwXA3+aW78rlAGtlwNmDdMOBXKTN6A52B9f3s3iyDl/IWbKMwS/LL+Jl52+XbQpB2hODIEPUQbv5iTCVll9obsea5eiYWgCSI/ehmJyWDBxBhcEN6UatlQM4K/6XcnNjT0PmS9imUNQdfBZlj5FoMcLzkqEcdxCVN6ewWIIKteD7pLPONCbww3/yuqC5bn+4t+g5XczCMAgE5yzEiRvyynPrpDaqGIQnQIVYl0DfxLsWT7jcnkgCFLMkHPjaB/YHymlunWLO2lGQwo9vVZr83J5iFPmTUO338h6tuNSDAPa7ML/BUCSWqHafhMxYiilafhs7NduZRTYKnnEKHPV5RYbNbwwx9sW+PeJR0WgEMEOLyab21d8xjdnE6uHgw5UX2tpgZgolgs57tEjEg5/nx6w4= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 44dd7404-ecc0-4899-0ba4-08dcdef31e5d X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Sep 2024 12:51:34.9853 (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: 9Kw/51VP4lYgxv8I1CtTQJe9pzRiPvJx08f62Xc9tu6IFHQmSEXdR+kcMzNb3QPVdohXKsRCCqnKpttds+A9PURhq6Dm7VSty1cfKBfpVMM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR10MB6820 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-27_06,2024-09-27_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 suspectscore=0 mlxlogscore=692 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409270092 X-Proofpoint-ORIG-GUID: dsWwBxDP45H2ezrUpQVRpWK4b2LEun2u X-Proofpoint-GUID: dsWwBxDP45H2ezrUpQVRpWK4b2LEun2u X-Stat-Signature: 4t4qf8hhqpqupsjzbfmuayant3w3cgea X-Rspamd-Queue-Id: ACD621C0012 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1727441530-707325 X-HE-Meta: U2FsdGVkX1/YqR5V46RXOM6QgTh27yyzL4apL4wnSsKAPUKuoTenqYNoCUhd+5YKbriB0CtrXRZU8aI4M/Gd7F+9twA01lGXLwI8mcSr4C6KWItfdy+NaN0XX0tz/fpOGRYkFoZIgNn8jds9qsgBYQoKgil9bEU7rct9jCl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P7L4iOq6DJikeKJIWVYp9D5bt2oFHbuVG4XoZdTSE3n16e3D2g6ARgOdSWe/yq6iANNMJsvX8HHKRUxs3LSj37dO1svURzX+gWPOMUgsBDjOHJhLN1iwJX8e+yC34XPL/q0HCu4R+nFO1WqpIeBCjwwZymiVoAUwHry2tIst+OWluhthazZcNq5G0Skb32tiupoGmwscJTdGwG8tJvUoPdsY65Zca/FAnHN30gqB3nBDrcL3KQZRqx1w3cC4zertqdebak/BKj+G8I/wcbLmfEg8dY9/yu0XG/GI0qinhPkammyPQ0JQZ0nXTi4wLJWvsZI1tyxVI3jWJ X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: Implement a new lightweight guard page feature, that is regions of userland virtual memory that, when accessed, cause a fatal signal to arise. Currently users must establish PROT_NONE ranges to achieve this. However this is very costly memory-wise - we need a VMA for each and every one of these regions AND they become unmergeable with surrounding VMAs. In addition repeated mmap() calls require repeated kernel context switches and contention of the mmap lock to install these ranges, potentially also having to unmap memory if installed over existing ranges. The lightweight guard approach eliminates the VMA cost altogether - rather than establishing a PROT_NONE VMA, it operates at the level of page table entries - poisoning PTEs such that accesses to them cause a fault followed by a SIGSGEV signal being raised. This is achieved through the PTE marker mechanism, which a previous commit in this series extended to permit this to be done, installed via the generic page walking logic, also extended by a prior commit for this purpose. These poison ranges are established with MADV_GUARD_POISON, and if the range in which they are installed contain any existing mappings, they will be zapped, i.e. free the range and unmap memory (thus mimicking the behaviour of MADV_DONTNEED in this respect). Any existing poison entries will be left untouched. There is no nesting of poisoned pages. Poisoned ranges are NOT cleared by MADV_DONTNEED, as this would be rather unexpected behaviour, but are cleared on process teardown or unmapping of memory ranges. Ranges can have the poison property removed by MADV_GUARD_UNPOISON - 'remedying' the poisoning. The ranges over which this is applied, should they contain non-poison entries, will be untouched, only poison entries will be cleared. We permit this operation on anonymous memory only, and only VMAs which are non-special, non-huge and not mlock()'d (if we permitted this we'd have to drop locked pages which would be rather counterintuitive). The poisoning of the range must be performed under mmap write lock as we have to install an anon_vma to ensure correct behaviour on fork. Suggested-by: Vlastimil Babka Suggested-by: Jann Horn Suggested-by: David Hildenbrand Signed-off-by: Lorenzo Stoakes --- arch/alpha/include/uapi/asm/mman.h | 3 + arch/mips/include/uapi/asm/mman.h | 3 + arch/parisc/include/uapi/asm/mman.h | 3 + arch/xtensa/include/uapi/asm/mman.h | 3 + include/uapi/asm-generic/mman-common.h | 3 + mm/madvise.c | 158 +++++++++++++++++++++++++ mm/mprotect.c | 3 +- mm/mseal.c | 1 + 8 files changed, 176 insertions(+), 1 deletion(-) diff --git a/arch/alpha/include/uapi/asm/mman.h b/arch/alpha/include/uapi/asm/mman.h index 763929e814e9..71e13f27742d 100644 --- a/arch/alpha/include/uapi/asm/mman.h +++ b/arch/alpha/include/uapi/asm/mman.h @@ -78,6 +78,9 @@ #define MADV_COLLAPSE 25 /* Synchronous hugepage collapse */ +#define MADV_GUARD_POISON 102 /* fatal signal on access to range */ +#define MADV_GUARD_UNPOISON 103 /* revoke guard poisoning */ + /* compatibility flags */ #define MAP_FILE 0 diff --git a/arch/mips/include/uapi/asm/mman.h b/arch/mips/include/uapi/asm/mman.h index 9c48d9a21aa0..1a2222322f77 100644 --- a/arch/mips/include/uapi/asm/mman.h +++ b/arch/mips/include/uapi/asm/mman.h @@ -105,6 +105,9 @@ #define MADV_COLLAPSE 25 /* Synchronous hugepage collapse */ +#define MADV_GUARD_POISON 102 /* fatal signal on access to range */ +#define MADV_GUARD_UNPOISON 103 /* revoke guard poisoning */ + /* compatibility flags */ #define MAP_FILE 0 diff --git a/arch/parisc/include/uapi/asm/mman.h b/arch/parisc/include/uapi/asm/mman.h index 68c44f99bc93..380905522397 100644 --- a/arch/parisc/include/uapi/asm/mman.h +++ b/arch/parisc/include/uapi/asm/mman.h @@ -75,6 +75,9 @@ #define MADV_HWPOISON 100 /* poison a page for testing */ #define MADV_SOFT_OFFLINE 101 /* soft offline page for testing */ +#define MADV_GUARD_POISON 102 /* fatal signal on access to range */ +#define MADV_GUARD_UNPOISON 103 /* revoke guard poisoning */ + /* compatibility flags */ #define MAP_FILE 0 diff --git a/arch/xtensa/include/uapi/asm/mman.h b/arch/xtensa/include/uapi/asm/mman.h index 1ff0c858544f..e8d5affceb28 100644 --- a/arch/xtensa/include/uapi/asm/mman.h +++ b/arch/xtensa/include/uapi/asm/mman.h @@ -113,6 +113,9 @@ #define MADV_COLLAPSE 25 /* Synchronous hugepage collapse */ +#define MADV_GUARD_POISON 102 /* fatal signal on access to range */ +#define MADV_GUARD_UNPOISON 103 /* revoke guard poisoning */ + /* compatibility flags */ #define MAP_FILE 0 diff --git a/include/uapi/asm-generic/mman-common.h b/include/uapi/asm-generic/mman-common.h index 6ce1f1ceb432..5dfd3d442de4 100644 --- a/include/uapi/asm-generic/mman-common.h +++ b/include/uapi/asm-generic/mman-common.h @@ -79,6 +79,9 @@ #define MADV_COLLAPSE 25 /* Synchronous hugepage collapse */ +#define MADV_GUARD_POISON 102 /* fatal signal on access to range */ +#define MADV_GUARD_UNPOISON 103 /* revoke guard poisoning */ + /* compatibility flags */ #define MAP_FILE 0 diff --git a/mm/madvise.c b/mm/madvise.c index e871a72a6c32..7216e10723ae 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -60,6 +60,7 @@ static int madvise_need_mmap_write(int behavior) case MADV_POPULATE_READ: case MADV_POPULATE_WRITE: case MADV_COLLAPSE: + case MADV_GUARD_UNPOISON: /* Only poisoning needs a write lock. */ return 0; default: /* be safe, default to 1. list exceptions explicitly */ @@ -1017,6 +1018,157 @@ static long madvise_remove(struct vm_area_struct *vma, return error; } +static bool is_valid_guard_vma(struct vm_area_struct *vma, bool allow_locked) +{ + vm_flags_t disallowed = VM_SPECIAL | VM_HUGETLB; + + /* + * A user could lock after poisoning but that's fine, as they'd not be + * able to fault in. The issue arises when we try to zap existing locked + * VMAs. We don't want to do that. + */ + if (!allow_locked) + disallowed |= VM_LOCKED; + + if (!vma_is_anonymous(vma)) + return false; + + if ((vma->vm_flags & (VM_MAYWRITE | disallowed)) != VM_MAYWRITE) + return false; + + return true; +} + +static int guard_poison_install_pte(unsigned long addr, unsigned long next, + pte_t *ptep, struct mm_walk *walk) +{ + unsigned long *num_installed = (unsigned long *)walk->private; + + (*num_installed)++; + /* Simply install a PTE marker, this causes segfault on access. */ + *ptep = make_pte_marker(PTE_MARKER_GUARD); + + return 0; +} + +static bool is_guard_pte_marker(pte_t ptent) +{ + return is_pte_marker(ptent) && + is_guard_swp_entry(pte_to_swp_entry(ptent)); +} + +static int guard_poison_pte_entry(pte_t *pte, unsigned long addr, + unsigned long next, struct mm_walk *walk) +{ + pte_t ptent = ptep_get(pte); + + /* + * If not a guard marker, simply abort the operation. We return a value + * > 0 indicating a non-error abort. + */ + return !is_guard_pte_marker(ptent); +} + +static const struct mm_walk_ops guard_poison_walk_ops = { + .install_pte = guard_poison_install_pte, + .pte_entry = guard_poison_pte_entry, + /* We might need to install an anon_vma. */ + .walk_lock = PGWALK_WRLOCK, +}; + +static long madvise_guard_poison(struct vm_area_struct *vma, + struct vm_area_struct **prev, + unsigned long start, unsigned long end) +{ + long err; + bool retried = false; + + *prev = vma; + if (!is_valid_guard_vma(vma, /* allow_locked = */false)) + return -EINVAL; + + /* + * Optimistically try to install the guard poison pages first. If any + * non-guard pages are encountered, give up and zap the range before + * trying again. + */ + while (true) { + unsigned long num_installed = 0; + + /* Returns < 0 on error, == 0 if success, > 0 if zap needed. */ + err = walk_page_range_mm(vma->vm_mm, start, end, + &guard_poison_walk_ops, + &num_installed); + /* + * If we install poison 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. + */ + if (err >= 0 && num_installed > 0) { + int err_anon = anon_vma_prepare(vma); + + if (err_anon) + err = err_anon; + } + + if (err <= 0) + return err; + + if (!retried) + /* + * OK some of the range have non-guard pages mapped, zap + * them. This leaves existing guard pages in place. + */ + zap_page_range_single(vma, start, end - start, NULL); + else + /* + * If we reach here, then there is a racing fault that + * has populated the PTE after we zapped. Give up and + * let the user know to try again. + */ + return -EAGAIN; + + retried = true; + } +} + +static int guard_unpoison_pte_entry(pte_t *pte, unsigned long addr, + unsigned long next, struct mm_walk *walk) +{ + pte_t ptent = ptep_get(pte); + + if (is_guard_pte_marker(ptent)) { + /* Simply clear the PTE marker. */ + pte_clear_not_present_full(walk->mm, addr, pte, true); + update_mmu_cache(walk->vma, addr, pte); + } + + return 0; +} + +static const struct mm_walk_ops guard_unpoison_walk_ops = { + .pte_entry = guard_unpoison_pte_entry, + .walk_lock = PGWALK_RDLOCK, +}; + +static long madvise_guard_unpoison(struct vm_area_struct *vma, + struct vm_area_struct **prev, + unsigned long start, unsigned long end) +{ + *prev = vma; + /* + * We're ok with unpoisoning mlock()'d ranges, as this is a + * non-destructive action. + */ + if (!is_valid_guard_vma(vma, /* allow_locked = */true)) + return -EINVAL; + + return walk_page_range(vma->vm_mm, start, end, + &guard_unpoison_walk_ops, NULL); +} + /* * Apply an madvise behavior to a region of a vma. madvise_update_vma * will handle splitting a vm area into separate areas, each area with its own @@ -1098,6 +1250,10 @@ static int madvise_vma_behavior(struct vm_area_struct *vma, break; case MADV_COLLAPSE: return madvise_collapse(vma, prev, start, end); + case MADV_GUARD_POISON: + return madvise_guard_poison(vma, prev, start, end); + case MADV_GUARD_UNPOISON: + return madvise_guard_unpoison(vma, prev, start, end); } anon_name = anon_vma_name(vma); @@ -1197,6 +1353,8 @@ madvise_behavior_valid(int behavior) case MADV_DODUMP: case MADV_WIPEONFORK: case MADV_KEEPONFORK: + case MADV_GUARD_POISON: + case MADV_GUARD_UNPOISON: #ifdef CONFIG_MEMORY_FAILURE case MADV_SOFT_OFFLINE: case MADV_HWPOISON: diff --git a/mm/mprotect.c b/mm/mprotect.c index 0c5d6d06107d..d0e3ebfadef8 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -236,7 +236,8 @@ static long change_pte_range(struct mmu_gather *tlb, } else if (is_pte_marker_entry(entry)) { /* * Ignore error swap entries unconditionally, - * because any access should sigbus anyway. + * because any access should sigbus/sigsegv + * anyway. */ if (is_poisoned_swp_entry(entry)) continue; diff --git a/mm/mseal.c b/mm/mseal.c index ece977bd21e1..21bf5534bcf5 100644 --- a/mm/mseal.c +++ b/mm/mseal.c @@ -30,6 +30,7 @@ static bool is_madv_discard(int behavior) case MADV_REMOVE: case MADV_DONTFORK: case MADV_WIPEONFORK: + case MADV_GUARD_POISON: return true; }