From patchwork Wed Oct 23 20:38:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13847893 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 BE474CFA46A for ; Wed, 23 Oct 2024 20:39:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 568ED6B00A6; Wed, 23 Oct 2024 16:39:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 518D66B00A7; Wed, 23 Oct 2024 16:39:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 345636B00A8; Wed, 23 Oct 2024 16:39:03 -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 0E6076B00A6 for ; Wed, 23 Oct 2024 16:39:03 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id B4B59C0E82 for ; Wed, 23 Oct 2024 20:38:43 +0000 (UTC) X-FDA: 82706030190.20.1A32BD5 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf07.hostedemail.com (Postfix) with ESMTP id E91C44001F for ; Wed, 23 Oct 2024 20:38:34 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=mDLV1RSF; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=ncxS35y3; spf=pass (imf07.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=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729715862; 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=GoV/SXOqaoQJF6Y962A0upUaI4C5tg8OVEAFdKWNTU8=; b=avNxHLGEzZIpDfN9dmDrZU+8umYEa1YzvopON7rhOwadTfCPqGuas2sxvhKUMUZIl9S57K mz8NI1nKIcqZaXMO9xCLrlu/QnqEBhaPGeDtWdj+MZphNjBNxxwnk0WLVRZ9mNLBdxBAvR Jb8OiAfOblNPMohxuSp6B1DSx2zNMPc= ARC-Authentication-Results: i=2; imf07.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=mDLV1RSF; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=ncxS35y3; spf=pass (imf07.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=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729715862; a=rsa-sha256; cv=pass; b=exuktpY0uEB0W9Lwhpw8DyR+KwnKOtZkGllZHv4mbHZSuNv0j/NAaKbi/83tYDSgOL5nzb x50fm0Ggi3JynRPUyCQIOY5epTkjQaNqy21fvdloWaBPDcs/wUGsgodNnao1iEAryNDu1D CxZcmFYQfNCP3WzAgOZDbPq6QS+JC5Q= 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 49NKcaVB026722; Wed, 23 Oct 2024 20:38:56 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=GoV/SXOqaoQJF6Y962A0upUaI4C5tg8OVEAFdKWNTU8=; b= mDLV1RSFcwAqq0lHdBl8LBxAJeqYvj+hjmbIEIjxiO5cOb211FyG7zHA6X09W4pJ Mt545YKd0HNS0zAGdbMbXjdT4J3Fu1esPtrJ5Qj6x0k8elW8SOhbr14cQ9/GxZge XNh8wg1zxG6SQ4b+A2CSFkykoPIPt2F2HsEBAwXhJ4Sb0NXP26os4lME1p9EOXJ+ rb/4gUuewS7J4b4JTOy47NFyYpknKiKM8lFKQ31WgrfvjrXDSQr7hzVHKmPknlYH mLmazHk4b5rNSERD7d0191yyb+amxVztPBHJzpuQmTEQmsGJG9AJbDoE3PI/3gSX 802bH8QnpdP6PEgHUBonXw== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c55v14fv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:38:56 +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 49NJ8ndL027496; Wed, 23 Oct 2024 20:38:55 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2042.outbound.protection.outlook.com [104.47.55.42]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42emh3bjwp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:38:55 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=L6YR/W7+tVMaZTrxwZKJRP09virM6kTQGbGO32O5li79bMi44RQtiQm9Hy1Vlbo3sC84nThclgr+dqnm/kwCwhID/5pehiV03+AhCzrQgWadtI+KuL5RoSvaW3cH7RBiyYqzKX45Y8s2Rys0R+pOLjikb23PAtS5P6XMKr2gvnu5vsCsL9TRsOsGGVppR2S6HMszTcPVT3rDao+r/1anu8H5ceNXmk6HePnzFw8cZr6GMGUTkx+UOoTJ+be1ecf69XxO+oP887w/32EdWDlvjhntrga7ou5C6fMu/8xBT8srnyKLpFACfyMAvSqvagfsbSRkqs79f5J4BeV/pXvsag== 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=GoV/SXOqaoQJF6Y962A0upUaI4C5tg8OVEAFdKWNTU8=; b=S56PHo9kk3XqtuW1igiW/eFZxNGCihVFzpiTJjiN1ti0gz19Ieuju2SGaLMWbGqRYcPnygJ74zMhlGxMkOOttiLSZmwFfZLjDlwSI8Qbc+q6yxBvYXJq4iskM2akhHNjqGG6DyOgpY9+qOYNfAonCCjxtDKLPGdPblXmkZ8OFUVETxkhUqts8pGAyMwfum2PdFX0sBCv8tuxZ8FMPNHA5+3HJeNZtgkI4Rdjfw8pN7AwCQPXZa6gWrL5ITecFNv7Kf7kH033mGOe4U07j4k4OkpSJojDVPjI52c5UESeAor6Ev0PGKW4/yPDIpcIda6r+fawzHsLzvcPrPpdEy5hSA== 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=GoV/SXOqaoQJF6Y962A0upUaI4C5tg8OVEAFdKWNTU8=; b=ncxS35y32JBpihG9WaLuv0ymC4l/nkwVtj32Sy81dL1WWA+44B+ijyfNSbWYGeQ8vxiTztK6O5DtWveO2BY9XJ0ig16QwUkQcxASAmLk+T2vbeVpmTC0eUVw/9L4Dv1AfZa/samrcY7nzeCSomr9rTbGniulTgChqHnNwllqLyI= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by SJ0PR10MB5833.namprd10.prod.outlook.com (2603:10b6:a03:3ed::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.17; Wed, 23 Oct 2024 20:38:52 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8069.024; Wed, 23 Oct 2024 20:38:52 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu Subject: [PATCH hotfix 6.12 v2 1/8] mm: avoid unsafe VMA hook invocation when error arises on mmap hook Date: Wed, 23 Oct 2024 21:38:26 +0100 Message-ID: <69f3c04df1ece2b7d402a29451ec19290ff429a4.1729715266.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P302CA0012.GBRP302.PROD.OUTLOOK.COM (2603:10a6:600:2c2::19) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|SJ0PR10MB5833:EE_ X-MS-Office365-Filtering-Correlation-Id: 4b27283d-c3df-483f-f08e-08dcf3a2b479 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|10070799003; X-Microsoft-Antispam-Message-Info: 5FMzz/agnPPgTvbwQPjJjvoTCLL02RKS9WTSlDJDr++1bRblfAge84g4xg3rWuSoDBs+FHgo9lfJ52CM1COyc+V87TT2OrBns/WPDE75Ylh4KOZ+fmq44DqtyoacgSxJxd23G1khMTnUGl7cyU7jVBQzqBUVZn6n87ykncRYm1O7MmCjxH2pbsLxPrSoscAUWpe+HilBQy9Y2DjNHZ4U/hPnaw1VVBfcsdltPZ9KoBqbZHtv1XzJA/v5SipeUeSSlMwZVD6GnK1fobd34xsbYy7T8rFzaeBWSzDi77PdSiIImo/hXj6o+cNr4a61WzfgEMNGh7b2K+w5zb3tmqfCwzv7JdZckSlG6LGhdvztzu0hs78OAu0BjUgKQrAyO6fOMvcXp7+RtGRtE3Wf6BpXJlu04OR0jrNs/6LtQ1ynLI2Au+aeVFGrhQ39h4aP6UYLRVD/+pyOacifjDEcSBVgmDs8v0lYUJDTibuu6a9X2itlgzS3yLPSHkS+k3oTb2FBJXlUzjUULuYltTRDMTBmHXPpINlwBkIxGaH8Crtke1NhKddL5WBq01M4FYafAB+1ktayJcPsJpnsIyD9Ms3C0Zjfihn9ch+ooG3gxxu6T1OoCtl/lI1lMrhDn9sl3AepFIa5IwAGArdnLOuQpzW9osp7ZZROeJ8vBEAPBFf7VBCDHn+b/8gIuq1FsZYND2dquhEKtEBYWFslk4VjgbjLOt0OFoI7Zry2vVdqvEvo2xkq4wpW9A/C9wv+wEEU+B8g9hp9p4Me7j99ac35GAcico9VswOiTwS4eDtgs4AYDqSwkTsjWd/bVCGrbp4Mo9EbQ3t3KDDbivbz04/3XQ3o7OOKlqzmQzHJAFCUVwRgKAzjJ1htDyLg4WDn3v2Jcm6QE8e2+/FZ5+SjfhcAJT9mw+BqEr9w3MNAQM/7/mcorkMaXnb6pXCogwJ4qtQj/p3u1TWMdpSJQ2czE0jRKoV5JzWlVxK+vn2qnu52l5ZPLn3uuawoYKTSDQoeUqGtNQXk18qKiG+MgxrsXf4QoIsRJw2Vvfjzc1mct4+LtYD0jj5DZ9lnpSbsHH5b5KP8UxT3wkg+8U0SPE/hYsFjFzKU+8HeXz5efNanqKSb7ZXXyrhxE6fH7k9ueYS4/QCsHQfyY2s+Pr7Trix1qX5casA2lyX3LTIyHpmnbc55l8iYzNWe7MGjFfP4Djs8w7tztHhigHkH0bcORD4PY+bITZljWT0elkTZZFU/E5xR2lrBaHdhxX2ee9EGdqyrRwSX2e8aaegY0uQCYW89Rm8JlFfTIFFL9XFBn/qghXg+UYK0YTQVYv6f6+T8ceK4nZQWz8LG X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(10070799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZMQ1Gvd6zCBXXxtzXig2Frz3zU9AKhAbnEhHOfc2H/iZ95Uuze+EX2IX8lz2Nb1OL+uS19rMEA/Uq6+PW9dXTCs+NE88HBUSjrw902xMBYtaB9bwGnmDdL1V6JxFAPMV7b+nlwtm0peRdxj1Ir9OxGSaOJRgf/9Brie2F1JLswFc9IWgtnzYJfDDFTD1Jz47+uAbSgit5OSPA4C6mi6qGVq1pj7wRkdpSShlEc0QytggG0E1IcFITZa96kSvibGN0UbmbjF7WPw+s4zsV464L4vQnco17NzMcYOla8dTQrjJMp7nLt4SWbOJpfJEugpgI5rKaDxOr9NsSD6uxJ869/LZXDkQLgoV6AOABKN72iiEydxzBPeXCG5lVF5as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Hli3kvAwchk2v6X6MFNN2Bp8kE7CThF4ikisqR70I1IHa3oGIvuLGuklQo/8+lmL4DdDzk03uPmWlvCFZj4582nOaQ9uxeOg/9v8tK5MCsiH+Isn95/Vep/giMOQ+Rg3lXYdt5MT+wCmDN+VmccrMmb6kaSiWY8B+xiGwa4PK92rLIL0orvVj2pm1G9wzAvHefOIk5Zfxt42TO22oOQbVO6tQ6yIpW40UJvNvvFRU0rg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Aou/9qqGc0ReEn9gOXVADm31mcSjK85tauEwTvkT6x1Ywv/Z7ZJDn2espdSmNpbwhSJccawy6Krvc1ChCOm9/nnUj5+zrKpPakhEEq+5zpcy5lczvudacdzi80GPab1i+oaXrdaf8z6vYDRgMLwvPGfr8S/XTLSiJ6L60iXc203q9uRC8KSda6/92dSHYD1+/dD+Dj2rExUfxY0CG8HDZhDiR72bWpdsyY1AD343G73ssKqYtJKMuzaiLgttvt1INNS1o5KMX8R55ZAk5xTCYlz1yMkBhfUpkUEKMCEVGCZ1jXE4X1RtcA/mNX1zIzb9M1o4w80pJHr4OLIkEi74q5t4q64SwlPKo5WiTAFwW8ZXxaMPKYCfFfw7aj3Z3AwSICHkG3Jap5u+F3wqyogzA07JA3J6bDLjY6tw24ngd/vb13Of+okoqA44wsolyMMIBQskLMxYFNvjkJWZG2v4DxazNX81UVw1sgDWIa2C/497GhORFamrsYTN2QSqflahJ4chbltjrpmJANmkKnYxwZ2vktbAI1FC42I46yRVYnTuUM8RV7Gqh+sL+HrtEpP5r7V8t1wvNKLhJjw1q0X9x+JSTOSPVYaKq7q6ZTYeW68= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4b27283d-c3df-483f-f08e-08dcf3a2b479 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2024 20:38:52.0661 (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: uIA4w2DI3F9qNt+lZNffz4TVxRCEz6XXtN+4FM2FuiLKuMOCANnJNIjZkypxE5ydWJNPlVmlzcxOrxhc218pXulGWx6P86cmPVK1aFB/8DU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5833 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-23_16,2024-10-23_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 malwarescore=0 adultscore=0 mlxscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410230132 X-Proofpoint-GUID: 9UzNX2otY6yG9b7VdoE1gg2T7uVYINpX X-Proofpoint-ORIG-GUID: 9UzNX2otY6yG9b7VdoE1gg2T7uVYINpX X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: E91C44001F X-Stat-Signature: 77bepkowxgww4a8isjaiarojjkzpowib X-HE-Tag: 1729715914-807604 X-HE-Meta: U2FsdGVkX1/aPwlUfz6JUz1lBYsQSRB/48VF7GTxPUmom9/fkhOqFLqbou8IR6sGHrX9LE4KJkN84+sWddsZJmsTnjFabxqjRk0tdtTcMc23/xwrqnHxJOZdJA0R8/3pCJNvR6iu/wBqdazs8HGmc6PlCAbif2D9cvXJ008FEFcD/hcK51Py/vufQgdszmGz/SkAAksyVQ+W0qXa0eJIIermL2B+C1KPdIVVf/ArNLOkx77IMJTPwcAOVB7d8f3LMlcywGo9VMXcIrf57m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zMjZ7p6dvc9Ry0K7d3rvW0U9JLvovqckaCpihy7ec02EsZdy0oF7hpbozTe6xanfb+SgRnBfMW57hynl7i7oXGRonLoBwFyxke4jilHqqg5yAmPXeLxuMzl89OGaDK2y0wpEFSbA0Y3EPBygDN8KAUxL4vw0RIPlesiPYFs7aT9L+B26+Z00kG94h63uAsWa1crEX2yN7+Pz180D 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: After an attempted mmap() fails, we are no longer in a situation where we can safely interact with VMA hooks. This is currently not enforced, meaning that we need complicated handling to ensure we do not incorrectly call these hooks. We can avoid the whole issue by treating the VMA as suspect the moment that the file->f_ops->mmap() function reports an error by replacing whatever VMA operations were installed with a dummy empty set of VMA operations. We do so through a new helper function internal to mm - mmap_file() - which is both more logically named than the existing call_mmap() function and correctly isolates handling of the vm_op reassignment to mm. All the existing invocations of call_mmap() outside of mm are ultimately nested within the call_mmap() from mm, which we now replace. It is therefore safe to leave call_mmap() in place as a convenience function (and to avoid churn). The invokers are: ovl_file_operations -> mmap -> ovl_mmap() -> backing_file_mmap() coda_file_operations -> mmap -> coda_file_mmap() shm_file_operations -> shm_mmap() shm_file_operations_huge -> shm_mmap() dma_buf_fops -> dma_buf_mmap_internal -> i915_dmabuf_ops -> i915_gem_dmabuf_mmap() None of these callers interact with vm_ops or mappings in a problematic way on error, quickly exiting out. Reported-by: Jann Horn Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Cc: stable Reviewed-by: Liam R. Howlett Reviewed-by: Vlastimil Babka Reviewed-by: Jann Horn Signed-off-by: Lorenzo Stoakes --- mm/internal.h | 27 +++++++++++++++++++++++++++ mm/mmap.c | 6 +++--- mm/nommu.c | 4 ++-- 3 files changed, 32 insertions(+), 5 deletions(-) -- 2.47.0 diff --git a/mm/internal.h b/mm/internal.h index 508f7802dd2b..af032e76dfd4 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -108,6 +108,33 @@ static inline void *folio_raw_mapping(const struct folio *folio) return (void *)(mapping & ~PAGE_MAPPING_FLAGS); } +/* + * This is a file-backed mapping, and is about to be memory mapped - invoke its + * mmap hook and safely handle error conditions. On error, VMA hooks will be + * mutated. + * + * @file: File which backs the mapping. + * @vma: VMA which we are mapping. + * + * Returns: 0 if success, error otherwise. + */ +static inline int mmap_file(struct file *file, struct vm_area_struct *vma) +{ + int err = call_mmap(file, vma); + + if (likely(!err)) + return 0; + + /* + * OK, we tried to call the file hook for mmap(), but an error + * arose. The mapping is in an inconsistent state and we most not invoke + * any further hooks on it. + */ + vma->vm_ops = &vma_dummy_vm_ops; + + return err; +} + #ifdef CONFIG_MMU /* Flags for folio_pte_batch(). */ diff --git a/mm/mmap.c b/mm/mmap.c index 1ba0878bbc30..10f4ccaf491b 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1425,7 +1425,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, /* * clear PTEs while the vma is still in the tree so that rmap * cannot race with the freeing later in the truncate scenario. - * This is also needed for call_mmap(), which is why vm_ops + * This is also needed for mmap_file(), which is why vm_ops * close function is called. */ vms_clean_up_area(&vms, &mas_detach); @@ -1450,7 +1450,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, if (file) { vma->vm_file = get_file(file); - error = call_mmap(file, vma); + error = mmap_file(file, vma); if (error) goto unmap_and_free_vma; @@ -1473,7 +1473,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma_iter_config(&vmi, addr, end); /* - * If vm_flags changed after call_mmap(), we should try merge + * If vm_flags changed after mmap_file(), we should try merge * vma again as we may succeed this time. */ if (unlikely(vm_flags != vma->vm_flags && vmg.prev)) { diff --git a/mm/nommu.c b/mm/nommu.c index 385b0c15add8..f9ccc02458ec 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -885,7 +885,7 @@ static int do_mmap_shared_file(struct vm_area_struct *vma) { int ret; - ret = call_mmap(vma->vm_file, vma); + ret = mmap_file(vma->vm_file, vma); if (ret == 0) { vma->vm_region->vm_top = vma->vm_region->vm_end; return 0; @@ -918,7 +918,7 @@ static int do_mmap_private(struct vm_area_struct *vma, * happy. */ if (capabilities & NOMMU_MAP_DIRECT) { - ret = call_mmap(vma->vm_file, vma); + ret = mmap_file(vma->vm_file, vma); /* shouldn't return success if we're not sharing */ if (WARN_ON_ONCE(!is_nommu_shared_mapping(vma->vm_flags))) ret = -ENOSYS; From patchwork Wed Oct 23 20:38:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13847894 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 2B327CFA46A for ; Wed, 23 Oct 2024 20:39:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B35D66B00A9; Wed, 23 Oct 2024 16:39:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AE6316B00AA; Wed, 23 Oct 2024 16:39:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8E9CA6B00AB; Wed, 23 Oct 2024 16:39:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 692CF6B00A9 for ; Wed, 23 Oct 2024 16:39:06 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5BE0240EAF for ; Wed, 23 Oct 2024 20:38:56 +0000 (UTC) X-FDA: 82706030988.24.19F5644 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf24.hostedemail.com (Postfix) with ESMTP id 0C3F3180011 for ; Wed, 23 Oct 2024 20:38:59 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Ab7rGpCW; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=geJxMFBR; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf24.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729715818; a=rsa-sha256; cv=pass; b=AMXzeEEF+nwg6jl7g3tnbFK3qNkUJIY6gJef6U9vQDym0s4g1IPkV1Qbc5RL9WusDVffc4 zrZkTuNau3RPB0NsofvYujRNpa+uVIgOv46k3iLB3TeS6lYcVDwtR6U9ZNwKT1zXFiXBnb QErW3mkglcradNDRuBiSIPDB6evQdLA= ARC-Authentication-Results: i=2; imf24.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Ab7rGpCW; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=geJxMFBR; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf24.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729715818; 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=isYXjEUHVJpnaUR/SKlmRO3SkZ58UHRLRDJ+bIB+HNg=; b=ATTpXZDquqMjYfNgAPWkju8pOqHd/DfFhRWfOdmZVo0zd+GmMWnCJw7FimLmiiD/rXha06 YbIi7zeJ0IFlC3kIMLhcbO4kWr5w9z8G24m2583ZY3QK0fUhzRpl5CqaI340MkB1o0nc18 UOXK+RgGNhT3VaWg+2ci75TsD5EkdNQ= Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49NKcZKS025393; Wed, 23 Oct 2024 20:39:00 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=isYXjEUHVJpnaUR/SKlmRO3SkZ58UHRLRDJ+bIB+HNg=; b= Ab7rGpCWlni6wz5UCHnIpmQGIT2Lc5L7WvQBXZhlk22Bk2Gb0ib5YhY557RbXpTU muZuPIJr64Bwnq+eN9bFHci6b9ZM3/FWVGj5UbgljPoH69ePxhATc7ZLP6+OxkvY j2XlUJ1y8JWy2qfxi4UnwRpfIibGkRsDuEj9wNIqz0dgvwzQf8SlbnbrP3FtHRWc aMPtTKnZ0LUBaDecWzn+ENwO+QkLFetXQTsp90eC+p09pKxRF7amLNS1Z1BwQi/O jD45y8n6kq5yxH8UYJMkP/RVS4M0f3rBoYR5Kozg/F+cGzRm7+yQnXcLASSfW6g4 2y2tkXK+PaenWgsvebublA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c57qh5ct-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:39:00 +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 49NJUVje039523; Wed, 23 Oct 2024 20:39:00 GMT Received: from nam04-mw2-obe.outbound.protection.outlook.com (mail-mw2nam04lp2170.outbound.protection.outlook.com [104.47.73.170]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42emhbj44w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:38:59 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=q2bBUG09nj28x37rNkTfmaziMfGAxuLy0e+ffwaG6sv7WIfxqhH1HkpsfsqHhksRf3iej3mjAzi35d6aanOr2ojSY+kqU2IivzwyaU7pNE3pV1UyKbNutLF9qMCBGisG1cSuZGKg44HlkGy02VSUr9BAD1zS61+DA9l/Dob8hZgrkgTjClvpgwHiYV1K8vWgGQx0HVVszrve8giSvO7Ae6Dc0oJkpfaoXLaa1YoWAL3GXmxUJLYbiEOJQYkXGIxMdN67n0cb5cKzd+WyezjD8ca01ibZRffRjh9rHAFPPdVkbiiQ1tKavgXzrJHdIOLnLI+zJpoUQ2A4yVmqlVMWgA== 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=isYXjEUHVJpnaUR/SKlmRO3SkZ58UHRLRDJ+bIB+HNg=; b=l+/IrsnWzOSAvwLGlhBR32DHcceENHoFnfo1jKIXlZ4c+kwDRe+4WoDtDElOz+3EXwTXIMaNSWTT9tRbOR9wn4Q3yAk1kvyUNb3h1ufvJVz85mrdegkV6uwMq0oEhlMoQMlNrTLpo08imDma6sgub3mApOj2frpTIRwCrJ3O1ByapN4URWt0FoaZAMbQQ7wsi37KQd8U+/uJuI2ByRRzHeMeNP7WLDhDGkHTmPzFRyLm9imFlYc19HQDJWPsPz5B1Jg+tghraKQT+LwHDUegmJe0+13lDoh37t8/4BDwghimuO/ElRiqZaJEZvwLhHa683yJDSiB+GU/fOspuEiOaw== 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=isYXjEUHVJpnaUR/SKlmRO3SkZ58UHRLRDJ+bIB+HNg=; b=geJxMFBRfc2bgwob1tvBUEdI29x02RnKDAJj4nQOntFb5m7StU+yWM7TygScCfl72nwXGv6ftGYKouwij/cWpdl8CdrtNJ43Aj9SNtyygUwC/xPcylMnY123pYJwUEdqF/+vT6HZFvg0mjHE6U3f2TltfZfpC1Qo2EuYgEfJImU= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by SJ0PR10MB5833.namprd10.prod.outlook.com (2603:10b6:a03:3ed::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.17; Wed, 23 Oct 2024 20:38:57 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8069.024; Wed, 23 Oct 2024 20:38:57 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu Subject: [PATCH hotfix 6.12 v2 2/8] mm: unconditionally close VMAs on error Date: Wed, 23 Oct 2024 21:38:27 +0100 Message-ID: <72a81a6fb997508db644313a5fdf4d239f620da6.1729715266.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0028.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:151::15) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|SJ0PR10MB5833:EE_ X-MS-Office365-Filtering-Correlation-Id: 35cb7490-a50d-4333-26c7-08dcf3a2b767 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|10070799003; X-Microsoft-Antispam-Message-Info: YAEl1lPPiYImrNxjt+zyAmv1NiHnF0PHzrzNgteahTq6cb54YpKIdepOsTG1ioI38ltRS3mULSbid+9iHoIAheTMF6G7eLojlWct0NsI3xx3AF+YDoG72xT6WiJU+SPLZ63yRLCJYFSV/J44BmAiVqdxnRr986bEs4sY0xFk04Axj0pFIFtFSmDAMX19kwb4pRdf4fyB4tOF8U/CG7ORem4acEMNySD5yN4M2OvTScRb7NdK4kxnROBvrKlV01A5vnJk14Py3l72WvXlEk2JYHCE3wrNTPM9B3gTahWyNTEi+S1n3SY28fDGoso4ReTf6qccZXq63dn6lP6W4gv/+sY+beMFqxucLmfs0AFnRNow6z2VXfpXtAe4NAbk5g7Y2R4lJqASP8FWbmofezH7E/cFAq2YubMTZP7/iKrB9FGZYUEbK2cfS2QHnvixKZjCN/lDwtFhoI8ZXpa38QQNyT1Z5s54sZS5JPYbjyB8v3UuwvIUbbF+eZxUqe4eIZYlk+8JGgdzaAnkY+ZVspnjBVgEv7SRAPrngLczPukcIbmQrx9ynOhPyTYiUf5FGQKrtW2C6KU+Es1EQgZKisaEGCpSHc5abFtJO/APf/VI5qJJDOqLh2vJxGAjf5Gr5oW0tGqGSu6lBJQNuGn89wN8mogAaKcTGDOiHTR5VmEO03txBnbRhvvsXWHRQKtsMXtWmqb365IRK8tDynqOUzCU2Pj3+7UrPB0rW2wD2vJAoEUFywBU1a8Uo7kWmMpwZeAILCJ2gWJ2600scQdSGRC51fFQ+O0z5bcnP3GcD8JWsDyS4NWd3rJkspd1PNoFOErFITGA7e7TzPg5AMIdgu8skAq2IfY1VlDy+ZQ+STXZ9YMdtTlBimzW2Ll6WX9oJVmteCCBNa1QzVs+baCqEWB2xw9BxWt1vRIyrM0qKeNzmIKsZRDSl7D4EdAQZDvPIiQOFJhixCkh9iwuwaYg7u18Z9NS3OYi7qMxBuknBap+XqoLShCWvZjBlsX8hNP2c0AAJF372VoJ1FJyxdhPQYUhmN24rHA1pqFPt47wboEITMw3zcO9GEkt4+NgGFeWxVF79ORCUgGx1oQgmusOukhGC1Jj4sm+SuLePlwNaIJF/WTHlQqLWXGK1IJM4RGfGTfN99U6vw8M2tYIZV032tkq1GpjjXHhU1CkZSzDaKUBPLvu8LCh/6zzKWQTlwZORSDRM95EH6v26a+5sQUZjPfgcLoi8qu40nfoJi0b9DkZDEaY+trIdOof7IAL+szQob2Hfr0iZNkm7fgaq65cNhPtSb6pE1tFfvmyaR1JJhm9YUW9mIiLM+STKi/Zwoulc0Z7 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(10070799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Sm/bshCd9g8cr+jL+Ur/LwBauj31IbvNij81H1GV4X1pSM5O9yOtm3KMO20BjJzeCaVnreUbc+l9Hq+zs4IpeLXwk0b6XwGrP3vruyAHwpUj+7bkPKo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Y9zHUcuH1oeGol1y9xXixusWgf9ZshSMbSU8LHYmRsXF73SK0pXgBJwQCGFFT7PTnfcdep7dj4oqvp7w2bHkyjA= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 35cb7490-a50d-4333-26c7-08dcf3a2b767 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2024 20:38:56.9640 (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: k6RfI3Q4fRgYXsv8RSxSb5/u/rKfOdXBd6jEGTI/n8lLoPG1k85wTWEXzwaO5y+TRdvL4iOlrQRXcB4AV+qPWEPaf+UHneqDzrGY7h43fnY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5833 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-23_16,2024-10-23_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 phishscore=0 suspectscore=0 bulkscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410230132 X-Proofpoint-ORIG-GUID: 9god8jj7Mp6doCKpcF5T5EvsObyK1tZs X-Proofpoint-GUID: 9god8jj7Mp6doCKpcF5T5EvsObyK1tZs X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 0C3F3180011 X-Stat-Signature: unphqojocfazxrake63i3oieajs6cipc X-Rspam-User: X-HE-Tag: 1729715939-645933 X-HE-Meta: U2FsdGVkX1/qEsZgYDaTL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x7K92I3NkbqKTOdnCkj903qMAmS68FCAxkepjw/rLHjmZ8OQ2AEdF94Rbv7bFYGfJaxsWNxQeoH2Tq2+wYCiIgXEGgnsXvV9Y/OKFiJNK+97C4+2HBH7P+EiwVn5GW+DawErR+SQvKbgb2ODuy/pKjTC4gH2ykqEqfQxgPJyohCnGO9/TxQGucim0mS4EZxkmid9dILy8LG2eAT8N/cS5EZexYSLGiz3EXGkPjSi70Io0gF4jWEAM1f/FLrfPM8iS2gCNJIQsDpDjfS2dQ17nhS2D+O6Xg0YPwMHfhXaG/1FvZHhwLF71phID78+ZrGLK++Y1XSLeQdqSl5IoaIVf4sVYNAuXY0EaMeMxj+y8aDVtoY9zTiAv9Jq3xxD94uzzZ4EYT3kYd2JiQHkyGtbKYjlXlxzJOUi7XGJdUJ1vKcryiRdpIGkK1vt3HpTFBhvmLSqKmryhU5IZEi6S8NNgcB 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: Incorrect invocation of VMA callbacks when the VMA is no longer in a consistent state is bug prone and risky to perform. With regards to the important vm_ops->close() callback We have gone to great lengths to try to track whether or not we ought to close VMAs. Rather than doing so and risking making a mistake somewhere, instead unconditionally close and reset vma->vm_ops to an empty dummy operations set with a NULL .close operator. We introduce a new function to do so - vma_close() - and simplify existing vms logic which tracked whether we needed to close or not. This simplifies the logic, avoids incorrect double-calling of the .close() callback and allows us to update error paths to simply call vma_close() unconditionally - making VMA closure idempotent. Reported-by: Jann Horn Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Cc: stable Reviewed-by: Vlastimil Babka Reviewed-by: Liam R. Howlett Reviewed-by: Jann Horn Signed-off-by: Lorenzo Stoakes --- mm/internal.h | 18 ++++++++++++++++++ mm/mmap.c | 5 ++--- mm/nommu.c | 3 +-- mm/vma.c | 14 +++++--------- mm/vma.h | 4 +--- 5 files changed, 27 insertions(+), 17 deletions(-) -- 2.47.0 diff --git a/mm/internal.h b/mm/internal.h index af032e76dfd4..0c4bf09bf788 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -135,6 +135,24 @@ static inline int mmap_file(struct file *file, struct vm_area_struct *vma) return err; } +/* + * If the VMA has a close hook then close it, and since closing it might leave + * it in an inconsistent state which makes the use of any hooks suspect, clear + * them down by installing dummy empty hooks. + */ +static inline void vma_close(struct vm_area_struct *vma) +{ + if (vma->vm_ops && vma->vm_ops->close) { + vma->vm_ops->close(vma); + + /* + * The mapping is in an inconsistent state, and no further hooks + * may be invoked upon it. + */ + vma->vm_ops = &vma_dummy_vm_ops; + } +} + #ifdef CONFIG_MMU /* Flags for folio_pte_batch(). */ diff --git a/mm/mmap.c b/mm/mmap.c index 10f4ccaf491b..d55c58e99a54 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1576,8 +1576,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, return addr; close_and_free_vma: - if (file && !vms.closed_vm_ops && vma->vm_ops && vma->vm_ops->close) - vma->vm_ops->close(vma); + vma_close(vma); if (file || vma->vm_file) { unmap_and_free_vma: @@ -1937,7 +1936,7 @@ void exit_mmap(struct mm_struct *mm) do { if (vma->vm_flags & VM_ACCOUNT) nr_accounted += vma_pages(vma); - remove_vma(vma, /* unreachable = */ true, /* closed = */ false); + remove_vma(vma, /* unreachable = */ true); count++; cond_resched(); vma = vma_next(&vmi); diff --git a/mm/nommu.c b/mm/nommu.c index f9ccc02458ec..635d028d647b 100644 --- a/mm/nommu.c +++ b/mm/nommu.c @@ -589,8 +589,7 @@ static int delete_vma_from_mm(struct vm_area_struct *vma) */ static void delete_vma(struct mm_struct *mm, struct vm_area_struct *vma) { - if (vma->vm_ops && vma->vm_ops->close) - vma->vm_ops->close(vma); + vma_close(vma); if (vma->vm_file) fput(vma->vm_file); put_nommu_region(vma->vm_region); diff --git a/mm/vma.c b/mm/vma.c index 3c5a80876725..bb7cfa2dc282 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -323,11 +323,10 @@ static bool can_vma_merge_right(struct vma_merge_struct *vmg, /* * Close a vm structure and free it. */ -void remove_vma(struct vm_area_struct *vma, bool unreachable, bool closed) +void remove_vma(struct vm_area_struct *vma, bool unreachable) { might_sleep(); - if (!closed && vma->vm_ops && vma->vm_ops->close) - vma->vm_ops->close(vma); + vma_close(vma); if (vma->vm_file) fput(vma->vm_file); mpol_put(vma_policy(vma)); @@ -1115,9 +1114,7 @@ void vms_clean_up_area(struct vma_munmap_struct *vms, vms_clear_ptes(vms, mas_detach, true); mas_set(mas_detach, 0); mas_for_each(mas_detach, vma, ULONG_MAX) - if (vma->vm_ops && vma->vm_ops->close) - vma->vm_ops->close(vma); - vms->closed_vm_ops = true; + vma_close(vma); } /* @@ -1160,7 +1157,7 @@ void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, /* Remove and clean up vmas */ mas_set(mas_detach, 0); mas_for_each(mas_detach, vma, ULONG_MAX) - remove_vma(vma, /* = */ false, vms->closed_vm_ops); + remove_vma(vma, /* unreachable = */ false); vm_unacct_memory(vms->nr_accounted); validate_mm(mm); @@ -1684,8 +1681,7 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap, return new_vma; out_vma_link: - if (new_vma->vm_ops && new_vma->vm_ops->close) - new_vma->vm_ops->close(new_vma); + vma_close(new_vma); if (new_vma->vm_file) fput(new_vma->vm_file); diff --git a/mm/vma.h b/mm/vma.h index 55457cb68200..75558b5e9c8c 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -42,7 +42,6 @@ struct vma_munmap_struct { int vma_count; /* Number of vmas that will be removed */ bool unlock; /* Unlock after the munmap */ bool clear_ptes; /* If there are outstanding PTE to be cleared */ - bool closed_vm_ops; /* call_mmap() was encountered, so vmas may be closed */ /* 1 byte hole */ unsigned long nr_pages; /* Number of pages being removed */ unsigned long locked_vm; /* Number of locked pages */ @@ -198,7 +197,6 @@ static inline void init_vma_munmap(struct vma_munmap_struct *vms, vms->unmap_start = FIRST_USER_ADDRESS; vms->unmap_end = USER_PGTABLES_CEILING; vms->clear_ptes = false; - vms->closed_vm_ops = false; } #endif @@ -269,7 +267,7 @@ int do_vmi_munmap(struct vma_iterator *vmi, struct mm_struct *mm, unsigned long start, size_t len, struct list_head *uf, bool unlock); -void remove_vma(struct vm_area_struct *vma, bool unreachable, bool closed); +void remove_vma(struct vm_area_struct *vma, bool unreachable); void unmap_region(struct ma_state *mas, struct vm_area_struct *vma, struct vm_area_struct *prev, struct vm_area_struct *next); From patchwork Wed Oct 23 20:38:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13847895 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 D3FF8CFA46A for ; Wed, 23 Oct 2024 20:39:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5BA0B6B00AB; Wed, 23 Oct 2024 16:39:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5672B6B00AC; Wed, 23 Oct 2024 16:39:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 392D16B00AD; Wed, 23 Oct 2024 16:39:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 13E646B00AB for ; Wed, 23 Oct 2024 16:39:11 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 8127D1C687B for ; Wed, 23 Oct 2024 20:38:50 +0000 (UTC) X-FDA: 82706030820.03.83BD241 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf01.hostedemail.com (Postfix) with ESMTP id 60E5E40022 for ; Wed, 23 Oct 2024 20:38:53 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="g/Noy20H"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="P7GtL/xO"; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf01.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=1729715796; 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=0rDE1LjjLhK0evyvP5sZKz477C4Wubbi+LdXiNbsMzY=; b=iFVv5AqsQZnvSKYGwl+HNJfdxefjMrshtEeprj9Q7/RhaXNcFPnUKB8FeEA4Z+c1OCNeli qnh3nZ9/Wuqpe/kk39ZkFjUAMr3bHrJbzbxsw+MVz6TdM2DCmCvvNnYPzcObnRVceKo+Iy O+HKSEXxIfGqEag8iPLpUDpWF0jlpDk= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729715796; a=rsa-sha256; cv=pass; b=cDeByD+oL5swRq/mnKksfmNCPYf8CTf2InTC/4qKtHLJM59QrUvEau8IAFNrpuc7rcVCQT /J959lgB75rsmNzu7PfOwkRedjbAd9xXGbQkHqFNRx5jeFYnm9zmD4Y6a/VGov2VSBh8ds nXvqrl0iZg6BtIga5govZlijwKFmdZs= ARC-Authentication-Results: i=2; imf01.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b="g/Noy20H"; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="P7GtL/xO"; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf01.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 (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49NKd40K032473; Wed, 23 Oct 2024 20:39:04 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=0rDE1LjjLhK0evyvP5sZKz477C4Wubbi+LdXiNbsMzY=; b= g/Noy20HV5Dd8HzkCO2gi2P98GR09+Nti773nFRj0swO5hRJEEkl0SICGDuR1yjN x/usyNE+3+l+7NEcGAyW3WTxUYkbTxRyxxKngGPVWWB3l5hgvon9PjQRID0MjbUo xSHT1qcTGY8BfiIwYe7s3AfeF4XfJji1qydmljWleGKqNrpyn9bMte0I1JY5Idyj Dr1Oo0TikhDPax6Wvf8V03xJ1Nf+pBxczlKyn/51oE3gdMlJYUew/Y0J/pdKvc+H 2H2WCXUyTJf3r43N43a8h9C7lGxdgK/osAd0diCn/I3AfAktW2LxUBuHT++5TDiY wnbw26zHdUfUfYMxoPCxYg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c53us4cs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:39:04 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49NJk0V1025440; Wed, 23 Oct 2024 20:39:03 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam04lp2045.outbound.protection.outlook.com [104.47.74.45]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42emha1aka-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:39:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ukZhib82aRZmQFL9/FpnX8fp81MEqcz9CbalGwf7886y12xhvVJvcpSHdUed1wD9ciTeCtRIZqNWb1vhxpVEDzZqCZBuwEYNU1/+5gvXXwJWSGeztD+nrDqkC6kjhWmp2JpuqDpciKDv/ZZjNY3z7l4UThhJF42xreW4qik19ewin18LRVqle6xY95CtJc3Zo6vCmzWSGlPPWMCM5qrfiM2GrTdfqyEuATs94sceLFvZOGeqHfPfRFkHX6pQtGGoiVfANsVzQ2y2AgWtlMhkaTFPpolKOobK7GuhNouZBtMrhEtbO8+ALQDB1b4xeMDBSmwxJzR1//p3KpSfJokBlQ== 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=0rDE1LjjLhK0evyvP5sZKz477C4Wubbi+LdXiNbsMzY=; b=o1Ae8zZ0NQ/8Z49B3jS29y0ofG6GPNoy8MH6dFi+pIW8PwByde3ZdEq9qLymOJnMcu9t8aXEA3oLtJHXQY3G29pXNKsufZEnl6QmJgOOu81c/S2BI6BMyb9MQnSagsCqShCYJKH5Ifv9CdyRHQooDY+9MlbjTm23Qzwmi9fRZIMMv1h0e7SyA+nIka+E3Tt2YgwvMHgvSmDQ/1/c76jTQV/Jgq22rU6u6CXGleTAu4wfPrbsUi76l72/T2DoHnvdedR1nK/d2vy/gNuyZ/yPVPY8apxtzO6KGY/C0MvIGisHm4MsCFlYPvqRAqrxAQtjXwV5+hbv+Cs8VbmKJmJdqg== 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=0rDE1LjjLhK0evyvP5sZKz477C4Wubbi+LdXiNbsMzY=; b=P7GtL/xOOyVCLqxowaVBS/nPBC2Fm5xAwRfacJaMVA60zd3mnd2DPFRomMh0QyN1sz7HwaMegoOuWjpcHaZPp+UR7fChpbHuSWyQ15MZodZUjA8Xxn9nMXlMk1Bvj8999hQRGgS/OP1+zyjaHao8JyOeoUXAWK77LSPolCws73s= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by SJ0PR10MB5833.namprd10.prod.outlook.com (2603:10b6:a03:3ed::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.17; Wed, 23 Oct 2024 20:39:00 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8069.024; Wed, 23 Oct 2024 20:39:00 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu Subject: [PATCH hotfix 6.12 v2 3/8] mm: refactor map_deny_write_exec() Date: Wed, 23 Oct 2024 21:38:28 +0100 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO0P265CA0006.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:355::17) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|SJ0PR10MB5833:EE_ X-MS-Office365-Filtering-Correlation-Id: b00151d5-ffde-4ec8-a869-08dcf3a2b989 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|10070799003; X-Microsoft-Antispam-Message-Info: 3KII73MuJfN9qT1zp5XFQbPmvQVTagMFSElgtq9NteCNqzfw1sA/KE4MpILEWNo3DMdYQL6t1xfu4W4GJCWTp6pDWuaLG7OBOw/yIiQJSuzrT0LV+QjB1k78s80bjeJ9awBfmgmg6XdAd/5xiw0ah/IwB2wUgj7Kjz0P//MmyCO9JtQJ5Xj7N9tJjrwK5CmEIDfPOF5ZEOvbTvvP1wwNa3IMhXDy4XxRRyudlSey0idNxx+t5e9l0A4juf4ewwzezC3PNYGpLStP5jGvWoglXgBd+Nld/Gz+8ZYv0Kli1yXmPdJi5aCPv6nQNOgH7+fcLqpuBaYb6kThdVAmlBMabJxZTTXEiYz9gKWW8eMnpDY7Okn2VZK6V7791JdAz8PJnTaPUzHvQOks5rRmKg/iy/5Nie/8cw4kO0wsnSyp+tiiUVpiPMygQ6VwyyCFt3tDLjKq5vK6ALY9wx9/v691ZxsS/X5O5kPXV/reaPNs4drsZqnNfbL4adPlMGc2zE01Hjjo6vM1pEQYorMY6Glb27uON3sdSvIGm41Q0/K9358qp+4nXmllyharE6JF/SmTXsZGaWsP0DLky7FJyLjvu5vw9XWkuJjAlBgRrPgRCzbFB3ykzskl1lotGwFf4BF7P/kHSnyU1piiLa45GGYn1lHHNDa2qjF/NEugmjZ3Yt7igWSUazqn7oD3IFze6IsOY+u5gjE22f4UQeMnRDQ7s1OaGId8nTaJYAz2nbspv4FZFy8U9+6Ku+utI+LWp5KSIwCPk3U4nyQ+tXkT6d3hG4pLL7boixPGzE7yRj+4aAwdCjPpoaWpfwt1f/Jznv6v8KDp47N08lDZyBgOynEutU0iufm0NKhUByriF40OGpCAtIQVbOkpsseINT7DYnKB/wedASLsbLhqhypholQ8BxpaB7cHFWymubXDFWizLFZBJblHsj9XaNS+0PWZLY3BkLoV/Hppbay5U5LoSunAyPYX3tOu+MPoQuHetktVDsbTi6u93c7z6CU01STi190n/9+8uTYeAe/WM6Z9fBA5Gg9+84zsmApLkXqgguZ2YYtrdXK0nhHj4x4PgRX8ZkyRyy5Oh9h+Twcy0OQKutkP6QnhBnaxHFzgtMH0OVRAcoD/1JsH1SpB1MMayQLtnxB+j/UT/32UKAiZxmvEzUMUFpOjYWZ+QkdJWA0xmTu1VofNqoWCStiSva4jk5reu9ZiWBJQV48hVg1lzxnDRPVg0EXq5Pc+wiUxx5RTIUC0q/FioSGELkW3qYOZ828pWSwTuBB6etQa8mxcLNsUA3v1OYwbq0PgjTxwFuyNo5rooZ2SEExvLyzawxlGRllHhJKZ X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(10070799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Zdr+XzLVmwsicy+us10ugEYhiO8in6ZhBsuapSYtVC4/6QEKzFCbBG9maceT4qfs+oHXHAgiISlqUJS6KRpbCA40tAbAqqJ4dHiDPzV0/BaAKn+mLRmi6XC4y7YIqPdX15AvI1bBGc+hqBio5ZgBV7+naY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UEkDXcYZM5IWPq2bnlH3SRY0QUXPXP8fSoapX06PVrI2BTNi10NjxuXDvTin/R8OHm0Rc/1NfMSZb6RGyg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b00151d5-ffde-4ec8-a869-08dcf3a2b989 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2024 20:39:00.3846 (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: xF6uWvu602bfRFdFB2BKx9MRQ/tLrwtBFrcx+TWAECQqV7oYMd3ivopAVSPiBSRYFiA3dmfQjp+BSnowM5Q2MbPF7/Ol3kBD3ii2InxYBRQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5833 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-23_16,2024-10-23_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 adultscore=0 suspectscore=0 mlxscore=0 bulkscore=0 mlxlogscore=927 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410230132 X-Proofpoint-GUID: zAz0mEDJK1N6tTkXJSG4x5pi-wPazSyK X-Proofpoint-ORIG-GUID: zAz0mEDJK1N6tTkXJSG4x5pi-wPazSyK X-Rspamd-Queue-Id: 60E5E40022 X-Stat-Signature: cuy6scs3yk5s7jgnfbii1ytoss1r6qgz X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1729715933-275159 X-HE-Meta: U2FsdGVkX1/ZIIN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ygyP0qR2Q/VRENXpfz8jPrnGukU0xMX6THyr7Bk5lpXmiHuigtB3PGxsqLG4R0lTBKUyFAfGC73jGLdQtMGLIRF87XNBWN3CvEsvXsR8nRhtiQ0CHhyZ1c30Caxh/3Qc4b5L37CmBKBCcfQlpPWvkyiVG0/OD/pJ+fU58kFpbXYje4/AGkGIZpar1XAcHEqEk99crbsnnFCqKTQwOe8GCurRfvQmZVpIhHVvQ7weC41uw422E7ltZyOrJJgQ5vE0wH9AANQfqKAEFXRqWxa2/wcjuGwU60/cm+qpLh4YMw2Du7I1bIRoLhVBQIIRTOVf6+DQ923m2PxVqM+3lMn6GI268ocUUTFv3rUzE2kUHsCvf3Tu/FalWZBLA372Y/dJhT0f7KlwbsS6kzuCrAqNwVCcaglmvTriIYE2MN817SirLXGYBqVfFaiaBHO2Id646I15Q/wRuY3e4nadjV4AxzNs5B2AR/HwtWK/0wTs6EeI3pB6dqDjwUDtx02g6jL9qRL+eg= 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: Refactor the map_deny_write_exec() to not unnecessarily require a VMA parameter but rather to accept VMA flags parameters, which allows us to use this function early in mmap_region() in a subsequent commit. While we're here, we refactor the function to be more readable and add some additional documentation. Reported-by: Jann Horn Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Cc: stable Reviewed-by: Liam R. Howlett Reviewed-by: Vlastimil Babka Reviewed-by: Jann Horn Signed-off-by: Lorenzo Stoakes --- include/linux/mman.h | 21 ++++++++++++++++++--- mm/mmap.c | 2 +- mm/mprotect.c | 2 +- mm/vma.h | 2 +- 4 files changed, 21 insertions(+), 6 deletions(-) -- 2.47.0 diff --git a/include/linux/mman.h b/include/linux/mman.h index bcb201ab7a41..8ddca62d6460 100644 --- a/include/linux/mman.h +++ b/include/linux/mman.h @@ -188,16 +188,31 @@ static inline bool arch_memory_deny_write_exec_supported(void) * * d) mmap(PROT_READ | PROT_EXEC) * mmap(PROT_READ | PROT_EXEC | PROT_BTI) + * + * This is only applicable if the user has set the Memory-Deny-Write-Execute + * (MDWE) protection mask for the current process. + * + * @old specifies the VMA flags the VMA originally possessed, and @new the ones + * we propose to set. + * + * Return: false if proposed change is OK, true if not ok and should be denied. */ -static inline bool map_deny_write_exec(struct vm_area_struct *vma, unsigned long vm_flags) +static inline bool map_deny_write_exec(unsigned long old, unsigned long new) { + /* If MDWE is disabled, we have nothing to deny. */ if (!test_bit(MMF_HAS_MDWE, ¤t->mm->flags)) return false; - if ((vm_flags & VM_EXEC) && (vm_flags & VM_WRITE)) + /* If the new VMA is not executable, we have nothing to deny. */ + if (!(new & VM_EXEC)) + return false; + + /* Under MDWE we do not accept newly writably executable VMAs... */ + if (new & VM_WRITE) return true; - if (!(vma->vm_flags & VM_EXEC) && (vm_flags & VM_EXEC)) + /* ...nor previously non-executable VMAs becoming executable. */ + if (!(old & VM_EXEC)) return true; return false; diff --git a/mm/mmap.c b/mm/mmap.c index d55c58e99a54..66edf0ebba94 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1508,7 +1508,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma_set_anonymous(vma); } - if (map_deny_write_exec(vma, vma->vm_flags)) { + if (map_deny_write_exec(vma->vm_flags, vma->vm_flags)) { error = -EACCES; goto close_and_free_vma; } diff --git a/mm/mprotect.c b/mm/mprotect.c index 0c5d6d06107d..6f450af3252e 100644 --- a/mm/mprotect.c +++ b/mm/mprotect.c @@ -810,7 +810,7 @@ static int do_mprotect_pkey(unsigned long start, size_t len, break; } - if (map_deny_write_exec(vma, newflags)) { + if (map_deny_write_exec(vma->vm_flags, newflags)) { error = -EACCES; break; } diff --git a/mm/vma.h b/mm/vma.h index 75558b5e9c8c..d58068c0ff2e 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -42,7 +42,7 @@ struct vma_munmap_struct { int vma_count; /* Number of vmas that will be removed */ bool unlock; /* Unlock after the munmap */ bool clear_ptes; /* If there are outstanding PTE to be cleared */ - /* 1 byte hole */ + /* 2 byte hole */ unsigned long nr_pages; /* Number of pages being removed */ unsigned long locked_vm; /* Number of locked pages */ unsigned long nr_accounted; /* Number of VM_ACCOUNT pages */ From patchwork Wed Oct 23 20:38:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13847896 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 073A8CFA469 for ; Wed, 23 Oct 2024 20:39:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8EBA66B00A4; Wed, 23 Oct 2024 16:39:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 89BDB6B00AD; Wed, 23 Oct 2024 16:39:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 652586B00AE; Wed, 23 Oct 2024 16:39: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 3E4476B00A4 for ; Wed, 23 Oct 2024 16:39:14 -0400 (EDT) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 426A940E9E for ; Wed, 23 Oct 2024 20:39:04 +0000 (UTC) X-FDA: 82706031240.21.FA65050 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf24.hostedemail.com (Postfix) with ESMTP id EBBA318000E for ; Wed, 23 Oct 2024 20:39:07 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=jAeG5v8X; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=eePXmu1B; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf24.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729715912; a=rsa-sha256; cv=pass; b=RYsSAb8YnnKUso89qDrqjxgfBYWqULfsNI0oDDqdQPi4WsF2bKtBBM17HZxRJnHRXBI5pd zFWZE+LwNmUOYDCcnBDTM80KTNch+9CP9qoh+y57zOh5/PqaUqQeKpTycaC1GvAAk0PiwA n6QiK+pxYzaQhBmori4aLTu7v1zpX9A= ARC-Authentication-Results: i=2; imf24.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=jAeG5v8X; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=eePXmu1B; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf24.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729715912; 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=TGZw0tx4qXQwwlFjxRJyFwIfVly//uJpCzOdUNUOgFU=; b=tO1qRlJfyqpUr+9ukGKuU5He99hzov10z+H6CWxzGxv2dTbGg7VBaM8lgazqtC+rpmHgcH gdACi/70nwhEzAH2XTB+ddy3iKtwhwh8JMK8GlZMsnvhftIz4Z9ZWBTOJmx58e1KK0SQva GhfShLgeqWa8EC/xqmwfp8nBF8PkmTE= 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 49NKcXg3010429; Wed, 23 Oct 2024 20:39:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=TGZw0tx4qXQwwlFjxRJyFwIfVly//uJpCzOdUNUOgFU=; b= jAeG5v8XZLqcJ45zSJSyjzuBEPD/zPWzaPdMFHokfimcdg2Cli0eksS7I1c/xQv5 zz6NAKc3+tIEWaZyd28lH8sszfJHwAxbMNw9bj7VO5LfZZ1iPzNyuCgbci4TG57x NpWENmG2G7ibjaRTbFErF101o6Yh2P01ZPy29oEkzJjv8gUkY1k/4hBnokE1cTzh +htXd0fKNjF1acn8JGkEEaY/tKLa+yeuGWQ36+PNbVGYnfX38qg18bAzUmVH4ex/ VM4+VRlj81evpJZMIIy6fIFPRoLYxT5BsG5dZciqUK95X6me9rWqrv0BWi71K7hA 3t77Z3lMn5hD/HT5tIHVbw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42cqv3g8w4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:39:08 +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 49NKIAZm031093; Wed, 23 Oct 2024 20:39:07 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2049.outbound.protection.outlook.com [104.47.70.49]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42emh219dg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:39:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=M09eoLqT9dIRokBOCZ8VH8KjBuyNg++ZuzTbXkkCixxzcoEKNhCKFo1kUBF856WaFNdmP+CnKkBMQKKkWhKKKNwQOyGspdqCryE0C7X5V+3Jf77Nk3VYdhQq9pLaymyAG785MIkVL8FYddPq5JgY5qKQBkoMcgx7mr2xE4no7pGBNTTiN6X8aEzMbVfbTqyCBbNQvNcry/sUJciPrl5XLpUI7W1yuMMgLBSvSfQ4zRwPaWwjvbr9DIay1kCOmXLoyw4rSXaccWAyPNDY5sDtJOrnL/IqG10w6TPR8X6vxAA7eDDUycAs6unjo12cjBV6QdjX3LZfI32GrvPfKejKxg== 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=TGZw0tx4qXQwwlFjxRJyFwIfVly//uJpCzOdUNUOgFU=; b=xtdBNCZHiE4K1za8MuGHwyxtVUqQkkByV0iCZGS+4VasDJK/YkIwI/IGx8Qq7RVIaYJ1U1izGVyicYhKtxv866L0+Hgd+GYlM72h921CHstCEnzU4C6j1x/sXoZL5D2LlIcAApBd/B17FYApT4fpiB9Uza2LcJethXt42c8Vmc/Fs0ZWeBTZewSpQ8fu0x/xElpWTRd2abQ6b80PGNs5NShHArZd75I3UM2E1CUTHp2NZJnTvteFwEoYrHs6WMRGGO6kSN130Ja+sWF0Mt8xfVS2e0rpvBdcyfzlJXquD3IiIiprEoSwBhVqgGNKWPnRXSJw9hUZy5PW4Q31YgNCxw== 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=TGZw0tx4qXQwwlFjxRJyFwIfVly//uJpCzOdUNUOgFU=; b=eePXmu1BUWNfaqKR/QeDV67sr+b8MgN7zjRwU+TOvEDcTXF4b6EUZhqcwF+XSW3Yz3xdP7eMk4C98ZMvyUeorCQvTjdOWXkjW64EvTaDsjGs4lnmzZDc/epOg5vRrkEv3M4UF83IRCGMYKzjY4OwhLnxkkg1mjCaAiYIjROuWFw= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by SJ0PR10MB5833.namprd10.prod.outlook.com (2603:10b6:a03:3ed::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.17; Wed, 23 Oct 2024 20:39:04 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8069.024; Wed, 23 Oct 2024 20:39:04 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu Subject: [PATCH hotfix 6.12 v2 4/8] mm: resolve faulty mmap_region() error path behaviour Date: Wed, 23 Oct 2024 21:38:29 +0100 Message-ID: <6e8deda970b982e1e8ffd876e3cef342c292fbb5.1729715266.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0264.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8a::36) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|SJ0PR10MB5833:EE_ X-MS-Office365-Filtering-Correlation-Id: 6c0c3067-c6e4-4580-1dca-08dcf3a2bbcd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|10070799003; X-Microsoft-Antispam-Message-Info: ezwjPU10Hy8v9RBw6meAkObqWSYxnJqvMbDdLpNfouFhlGfV1wYr0Fx/ONJTL5GvGVfEwmwB0rmI5yA1vNBQz/Fsde1o0W/2IgOhU270478pxlMqV0924tiwaqygyTf2BGVb6Dvuk2cPrprYiuB2YuLB1MhVkfNjoQAQlToWZfVgKXSlXwwDLor2kpmqCWHfLVSyzvUbDuSAxsxR4K3Q9MjLWxgW6T43e9P7PBBbeywEn994fQ9yKrL6HtnYIBg4Qchua3bR+OgaNA8akh7qPvVUar6s1yCEaGGRQDE+bwhztmw3EyDbCuXdJJwnpmAOeBSaWOcxTIMontab2S3omGKv2X0wc5wtpwDQUG3N03vxfGb3FecQR5FD4mkfNxA+p5q2rWLHhf9Szluu57VJf2WE2UpGkbjyjKh7wKtZQ0I4rajEqNnB1a/i5mcl/f46qLeXdn0ucwziPhuZawqiNYMNLMwY6Wn2JU5nGtTQorzoEexPuTrs4Wsm/hEC9IjpJppvjrKUtCCSpQWsYYEtIEfAttdRNJYetfEfWZBeB49T5vsHvNP/bub5u5bKJ/9ourlBKg7xI6y7+SPcA+Krt66pCnrYcPwnh94ZFoEe7KZkUH9rYjUs+9xs/sT/0l/OoO8X8UHN49AwlNuZT7KDRLz+XKfM6yo1BcsGUjDCCb7TQDK8b0mftINlFUR9Lo/CfKzXIYS9SYhGwow7XBm9ajVV6PiEuZdIbww9ZdFr9kfg67N3vkhqyFDdriXY9KVwqbMfso/hYWzmgvtkv4i04LKlKI4M5iGAZZvk0oU/CQS1F5LNQckCe13yZo6VpiAPgJPdIuEdlK2pQShTevEjcppMExok2yT7W0taVR9UE8uLrZcFKYiVO7N6C8o2SrWtWbSRl9ESndSXVChCqxaQFpbNTi2Rvr9J5SG8wJ/2ZKtJx45S1EQ26vVzqr31SJ9Kz/XVkm1z6cYS+CRDk/B2k9b2HrCpDM6y2qVhvJ70N00y29zyvr9C2lNwICAE665HuepvGZY5DYHhTp/zHl1mtvhLOlR1L+nzz3V8a1JeOk58Qi2+ddL/Hgdpnplk8z2qYKkwDLa6bCm6Zt4z6As3YVNOkWU4rTlpZh5g25Ua1NXyq1zFx+kUIZ+KD5MVtpOATQq2jsXxoZ/dLyB3DE6r2i6UBc9rmk3C4ekS2HEFtLZ+l/iep7FwDwJRveOwBDCVgP148Ap2g5hrXHQ4iGpVnsbegYC5d/5o0iohhFz66DQgz3SVsuM2J+snOy2Uc8e5UPPJ82an8YHm36GRtXCa4085ZqZJlhnTaS2CfbJmB8MkjKcHC5afEuj/yM3gkTbW X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(10070799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hmCLnWVgMs20n9QGLaLm+loQlmuWwQt8YP8ZbFYsGzXA5weWX9GNI72jSNVcdxVNfgvFz1ejAHdMYulAVtHmSUTc+rWEWyk1lW2gy8Xcwefk3f/ulK5WHot6ImM3qE06J7azJZ+Xf/ovgHeMwndnzhfnnv9sFN4oxa7+ltSLq8+poRZC6xwwxUgT3xcbCQ7ZqKYY+5rFxI/xn/+g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9P5SpnCULUKLKUojOp6AWSseDMg1q84dXGz1VplcTp18UXigd8lAlBEDoX1BOfktCKF8pv4131KLMda5ZcAIAiVeo543syuGzhCy619qiwAg8PeUENIKRZnXAyfnEyxrfn2HGsT/TCCfJ+z0ve+qGH4KnPVtnkSOge1KHdgzX24SVzAaVvz8nTWT5ilf+KWxMRbAFdzZY7Cec4DLeQDNK6DpNhYqeVCdhSqGKj4AROKLeT2wkOnt/+r4dhRWzshCpC3T+MQw8REFGZqRNPsNQT9xiHJRNJrcoF1gp+2sPjcfV9rQCi/xwIgz1w+7QL7G1vtOhy6ioaPOgbA28JnrmaYJRmw5a6WC4+VA0uqj7kgKweKoBMEwU+Xh1ErI59oiAQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: tEbNw632Zv6KGAYJHvI9GjavZn3Cb5f6XLBHw1s5zcEx/MW96BLH8n6JoLk+QFrmLhr8x5ugvQ4pzMU1GUyZlbrU1AsreSguZfQOFEnaqO3TCXgKw2CC+IVZqZdVT8nvjeBJ26g8+5b9Mu5ncqXpgQt1PewNRWGhujYhDCo8KMxzAcgHRmyvef4G5XftqCbNP0VwLUtYvV3analAENl4eaM41pXQyiX8ekuvoXKNg/H/f7pm4AH3puejseZnGIzMLaYjvaAXakg5uZ/YMAK2YybS9jG54TWQXnW64AmKY9YOlQZ62h16ggJggI1BVoA+MrwgvPi7/N4QrZoDi7AoEL8c63LQdvZIEK+gOCf+nGiPajse3lKVxhWKX6pWARwc67QpawGVJTrSPhlyBEB9ejiU5Rei+1PDUwMfs/LNbDVtz46Dv4NoRAkwuztebSNxn9He0IMZSBqAawcVFottF7nB5sHjYSa3XYDFQlrC+vALqQ9+2FxGRGnT25UYSOBGTsSlW1bnczczpeWx0YzCwbjFzlZl7S67xeaJJvbuRmVySsyO7KoI+GKK3RmNJEO+hJLBoszthfJXCF4EyXv3Am9jGaX+PU4H0WPyle05f5k= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6c0c3067-c6e4-4580-1dca-08dcf3a2bbcd X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2024 20:39:04.1804 (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: PB5FehlCXSNSyjAf6hA96DYkmPRwniofeSwsGqvT4t3mOjD/l2idYRyhSggNvZAfdaOHFMsYi+eKOzDnl8ZCBqr8X96QchsDfxUd7iBF25Q= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5833 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-23_16,2024-10-23_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 mlxscore=0 spamscore=0 bulkscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410230132 X-Proofpoint-ORIG-GUID: cJ4ZA9dO-MjJLmDSTGZ47qRkGazPDiZv X-Proofpoint-GUID: cJ4ZA9dO-MjJLmDSTGZ47qRkGazPDiZv X-Rspam-User: X-Stat-Signature: em1gnn7qpy6nzuqqneyock3b3igxbytp X-Rspamd-Queue-Id: EBBA318000E X-Rspamd-Server: rspam02 X-HE-Tag: 1729715947-588101 X-HE-Meta: U2FsdGVkX1+GpWINHKlUQN+VGpxh3bOdddLd+r7UfceLLRDOkizfgzq/GPNH/4rE0KP+zzXI8AdpQFRasvZ+nMugQAzAPt3NKlcZ1sD3oj9vY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dfQa72K7syz1a42sAiNcxphloKKeLXQURoguO15DLe2EzcfeNu65jdyB82iQYTNsiqbpaq2+lTLrgF0mkEWBpAEyOOvmQeljyklCoXntQc2ohrxr5MTtrxGZfs+WD+CMsUHrTcsT+ugAuKaYsyR6ZHQFP3eQh2yKXjJ56BnQAPPxqpy3H+jbTUROpWe+rwXhxixVH79peH/B01LTYLcq1ETERtItdsGPDB3C1RPbVemVerUYlDXVkZ+YtuNozGLwHbGyvuMrXJt72vtnvwwiBfOa9OAYsRlUR6biAfAMIftwgrixpssvZ0BYEYHHbyDC/aH33kQoLTOdcshxJwXA0W4+dNrGhb5MlX3SnX/6LgJqDKZmr1my/ZmdpGCWJ0d7TTEqAsXVhdgd2dRs+JOTCfB7XH4D6E9ut7CEzUk= 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: The mmap_region() function is somewhat terrifying, with spaghetti-like control flow and numerous means by which issues can arise and incomplete state, memory leaks and other unpleasantness can occur. A large amount of the complexity arises from trying to handle errors late in the process of mapping a VMA, which forms the basis of recently observed issues with resource leaks and observable inconsistent state. Taking advantage of previous patches in this series we move a number of checks earlier in the code, simplifying things by moving the core of the logic into a static internal function __mmap_region(). Doing this allows us to perform a number of checks up front before we do any real work, and allows us to unwind the writable unmap check unconditionally as required and to perform a CONFIG_DEBUG_VM_MAPLE_TREE validation unconditionally also. We move a number of things here: 1. We preallocate memory for the iterator before we call the file-backed memory hook, allowing us to exit early and avoid having to perform complicated and error-prone close/free logic. We carefully free iterator state on both success and error paths. 2. The enclosing mmap_region() function handles the mapping_map_writable() logic early. Previously the logic had the mapping_map_writable() at the point of mapping a newly allocated file-backed VMA, and a matching mapping_unmap_writable() on success and error paths. We now do this unconditionally if this is a file-backed, shared writable mapping. If a driver changes the flags to eliminate VM_MAYWRITE, however doing so does not invalidate the seal check we just performed, and we in any case always decrement the counter in the wrapper. We perform a debug assert to ensure a driver does not attempt to do the opposite. 3. We also move arch_validate_flags() up into the mmap_region() function. This is only relevant on arm64 and sparc64, and the check is only meaningful for SPARC with ADI enabled. We explicitly add a warning for this arch if a driver invalidates this check, though the code ought eventually to be fixed to eliminate the need for this. With all of these measures in place, we no longer need to explicitly close the VMA on error paths, as we place all checks which might fail prior to a call to any driver mmap hook. This eliminates an entire class of errors, makes the code easier to reason about and more robust. Reported-by: Jann Horn Fixes: deb0f6562884 ("mm/mmap: undo ->mmap() when arch_validate_flags() fails") Cc: stable Reviewed-by: Liam R. Howlett Reviewed-by: Vlastimil Babka Signed-off-by: Lorenzo Stoakes Signed-off-by: Lorenzo Stoakes Tested-by: Mark Brown Signed-off-by: Lorenzo Stoakes Acked-by: Vlastimil Babka Tested-by: Mark Brown --- mm/mmap.c | 119 +++++++++++++++++++++++++++++------------------------- 1 file changed, 65 insertions(+), 54 deletions(-) -- 2.47.0 diff --git a/mm/mmap.c b/mm/mmap.c index 66edf0ebba94..e686d57ed9f7 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -1361,20 +1361,18 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, return do_vmi_munmap(&vmi, mm, start, len, uf, false); } -unsigned long mmap_region(struct file *file, unsigned long addr, +static unsigned long __mmap_region(struct file *file, unsigned long addr, unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, struct list_head *uf) { struct mm_struct *mm = current->mm; struct vm_area_struct *vma = NULL; pgoff_t pglen = PHYS_PFN(len); - struct vm_area_struct *merge; unsigned long charged = 0; struct vma_munmap_struct vms; struct ma_state mas_detach; struct maple_tree mt_detach; unsigned long end = addr + len; - bool writable_file_mapping = false; int error; VMA_ITERATOR(vmi, mm, addr); VMG_STATE(vmg, mm, &vmi, addr, end, vm_flags, pgoff); @@ -1448,28 +1446,26 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vm_flags_init(vma, vm_flags); vma->vm_page_prot = vm_get_page_prot(vm_flags); + if (vma_iter_prealloc(&vmi, vma)) { + error = -ENOMEM; + goto free_vma; + } + if (file) { vma->vm_file = get_file(file); error = mmap_file(file, vma); if (error) - goto unmap_and_free_vma; - - if (vma_is_shared_maywrite(vma)) { - error = mapping_map_writable(file->f_mapping); - if (error) - goto close_and_free_vma; - - writable_file_mapping = true; - } + goto unmap_and_free_file_vma; + /* Drivers cannot alter the address of the VMA. */ + WARN_ON_ONCE(addr != vma->vm_start); /* - * Expansion is handled above, merging is handled below. - * Drivers should not alter the address of the VMA. + * Drivers should not permit writability when previously it was + * disallowed. */ - if (WARN_ON((addr != vma->vm_start))) { - error = -EINVAL; - goto close_and_free_vma; - } + VM_WARN_ON_ONCE(vm_flags != vma->vm_flags && + !(vm_flags & VM_MAYWRITE) && + (vma->vm_flags & VM_MAYWRITE)); vma_iter_config(&vmi, addr, end); /* @@ -1477,6 +1473,8 @@ unsigned long mmap_region(struct file *file, unsigned long addr, * vma again as we may succeed this time. */ if (unlikely(vm_flags != vma->vm_flags && vmg.prev)) { + struct vm_area_struct *merge; + vmg.flags = vma->vm_flags; /* If this fails, state is reset ready for a reattempt. */ merge = vma_merge_new_range(&vmg); @@ -1494,7 +1492,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma = merge; /* Update vm_flags to pick up the change. */ vm_flags = vma->vm_flags; - goto unmap_writable; + goto file_expanded; } vma_iter_config(&vmi, addr, end); } @@ -1503,26 +1501,15 @@ unsigned long mmap_region(struct file *file, unsigned long addr, } else if (vm_flags & VM_SHARED) { error = shmem_zero_setup(vma); if (error) - goto free_vma; + goto free_iter_vma; } else { vma_set_anonymous(vma); } - if (map_deny_write_exec(vma->vm_flags, vma->vm_flags)) { - error = -EACCES; - goto close_and_free_vma; - } - - /* Allow architectures to sanity-check the vm_flags */ - if (!arch_validate_flags(vma->vm_flags)) { - error = -EINVAL; - goto close_and_free_vma; - } - - if (vma_iter_prealloc(&vmi, vma)) { - error = -ENOMEM; - goto close_and_free_vma; - } +#ifdef CONFIG_SPARC64 + /* TODO: Fix SPARC ADI! */ + WARN_ON_ONCE(!arch_validate_flags(vm_flags)); +#endif /* Lock the VMA since it is modified after insertion into VMA tree */ vma_start_write(vma); @@ -1536,10 +1523,7 @@ unsigned long mmap_region(struct file *file, unsigned long addr, */ khugepaged_enter_vma(vma, vma->vm_flags); - /* Once vma denies write, undo our temporary denial count */ -unmap_writable: - if (writable_file_mapping) - mapping_unmap_writable(file->f_mapping); +file_expanded: file = vma->vm_file; ksm_add_vma(vma); expanded: @@ -1572,23 +1556,17 @@ unsigned long mmap_region(struct file *file, unsigned long addr, vma_set_page_prot(vma); - validate_mm(mm); return addr; -close_and_free_vma: - vma_close(vma); - - if (file || vma->vm_file) { -unmap_and_free_vma: - fput(vma->vm_file); - vma->vm_file = NULL; +unmap_and_free_file_vma: + fput(vma->vm_file); + vma->vm_file = NULL; - vma_iter_set(&vmi, vma->vm_end); - /* Undo any partial mapping done by a device driver. */ - unmap_region(&vmi.mas, vma, vmg.prev, vmg.next); - } - if (writable_file_mapping) - mapping_unmap_writable(file->f_mapping); + vma_iter_set(&vmi, vma->vm_end); + /* Undo any partial mapping done by a device driver. */ + unmap_region(&vmi.mas, vma, vmg.prev, vmg.next); +free_iter_vma: + vma_iter_free(&vmi); free_vma: vm_area_free(vma); unacct_error: @@ -1598,10 +1576,43 @@ unsigned long mmap_region(struct file *file, unsigned long addr, abort_munmap: vms_abort_munmap_vmas(&vms, &mas_detach); gather_failed: - validate_mm(mm); return error; } +unsigned long mmap_region(struct file *file, unsigned long addr, + unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, + struct list_head *uf) +{ + unsigned long ret; + bool writable_file_mapping = false; + + /* Check to see if MDWE is applicable. */ + if (map_deny_write_exec(vm_flags, vm_flags)) + return -EACCES; + + /* Allow architectures to sanity-check the vm_flags. */ + if (!arch_validate_flags(vm_flags)) + return -EINVAL; + + /* Map writable and ensure this isn't a sealed memfd. */ + if (file && is_shared_maywrite(vm_flags)) { + int error = mapping_map_writable(file->f_mapping); + + if (error) + return error; + writable_file_mapping = true; + } + + ret = __mmap_region(file, addr, len, vm_flags, pgoff, uf); + + /* Clear our write mapping regardless of error. */ + if (writable_file_mapping) + mapping_unmap_writable(file->f_mapping); + + validate_mm(current->mm); + return ret; +} + static int __vm_munmap(unsigned long start, size_t len, bool unlock) { int ret; From patchwork Wed Oct 23 20:38:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13847897 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 E12FFCFA46B for ; Wed, 23 Oct 2024 20:39:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 237CB6B00AE; Wed, 23 Oct 2024 16:39:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1995B6B00AF; Wed, 23 Oct 2024 16:39:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E44FA6B00B0; Wed, 23 Oct 2024 16:39:15 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id B1D836B00AE for ; Wed, 23 Oct 2024 16:39:15 -0400 (EDT) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id CB31C140EF2 for ; Wed, 23 Oct 2024 20:38:56 +0000 (UTC) X-FDA: 82706031366.24.1A183F7 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf29.hostedemail.com (Postfix) with ESMTP id 877A3120005 for ; Wed, 23 Oct 2024 20:38:48 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=hAFSTcir; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=0DZ0wkn6; spf=pass (imf29.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729715875; 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=WP57i7v+tW2ioFRTEIKKj1mu6dNHF0V1UcxvMSTIrXU=; b=Nxpyf1rRMIehmkbZ3k9BhYJsminlNOmpqmshhSIzSUQ21SX23Qigu7w4nYL+cG2ktU7vp9 99h3RAk+SquXBQ8uEA4/qr844qbbqAUhlhn9pgwKVhXSeXLHE/f79EH9Jwt9KxYrTuvXwZ QdoW2h0P5U6n8V2EvklPCcqLyTEx0Hc= ARC-Authentication-Results: i=2; imf29.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=hAFSTcir; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=0DZ0wkn6; spf=pass (imf29.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729715875; a=rsa-sha256; cv=pass; b=KGA8PhP4hNFOx6NINUP6cGk3CjBXnsf95OgOE0B3dJ/xB632MLiULZWuzU/Zb3y/jw+qnI GWUhIaRs66oK1qIGfS3EGt3kSkWQ5qyHvGd8NxdgrGkdb96CDwFz/2DfcOCHr1uf4QqvDv 6En9SgqOXxRKCQYkJiE+IEG2r0E6j18= 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 49NKcTV1010295; Wed, 23 Oct 2024 20:39:10 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=WP57i7v+tW2ioFRTEIKKj1mu6dNHF0V1UcxvMSTIrXU=; b= hAFSTcir4XzhAtoaNGmWtT4iaKFWY5VrW4VhiHZ84g/5KhGDqOQUxBg1EK4Y/UeD 551e/XoDioC6vlHfoQtGhVE41c1srMLwIdowU2Szhe0/f5YX3aNKScdQ3SHXJruN /ey33TbtHz2fEdg52vNUd2b3BuW5O/3H+ErH+kUd/+APP38ccEh9zIZIE0kps2tI aXKYkLA13dDGaqE0GSu0YLSMLSgsmP4OV0cTyFpYxY2aBz/kJ9K/GI5y1u2MEmT2 SJ1YE9LF0pJixfsYDuBZcm8XPH9mBUQXi90P+szGDuYti6hXNe9OZ0BD+CNK2rXY erSDFhHKS1QIHmrf7uFlhA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42cqv3g8w5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:39:10 +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 49NJEEmp027438; Wed, 23 Oct 2024 20:39:09 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2045.outbound.protection.outlook.com [104.47.58.45]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42emh3bk7q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:39:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=naBVmz/G/DX+Vz902PvbV1U+beSEKgfmGYxZs3mESRePJsVIBAV1nopw3Ncwc+NNav6I0H5CkZcu8FnUw3EiftMKkv4Wm1RTHtXDeSFFYAl/Eu4e4Sp/SqrPIQW6jQUEs7/XrGVBSMkPtOOWII5rlonS791Rp5TIGoU7Iv0X30czkCFZcv6bhT9TK7ZMLqJ1RVD/365Q1Mv5rgET3COR6EFA+arXEkbrOcvA2t294kQ8rk6ueEilgxjdYGsaJfBxjNTG6h96ZL+hFZcNPA7C3T5B8+U/xZmRfrFXk2yA1n5YrGBfKPcO1Wk16NnxHsj2a/BbCIjA+Azgj0hcMIa/Nw== 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=WP57i7v+tW2ioFRTEIKKj1mu6dNHF0V1UcxvMSTIrXU=; b=cZnHEw/ZjEdN/5c8o98g3+K0LIRzZf4Z1T8UnBHePNEs9jxWgNwU4qIvYYerjswG00D6HJgPBt/TM4ibdArJTTgCTxc9iNPPP1csOYuOtQ+ICm4IBE0cho4b490nZQ5R3tMImecQiYdr26UbMWJMZ0QKYs4FI2YAGYpkKk4AdMJoGwolTngZBojJQRnTnP49P9U9e2zF18JHMyi93UVcyVH0mnYFX0TC62X0doL/G4W40D7QxlAKuz+OglOlJhJw4Cblcw8Qdj/a1oJvAax9xwMqNDIWMhWrxahtPRfqn/u22O+j72wDWf8NR7tQmJofvSRRn+w/3+MNcM0a4/5WxQ== 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=WP57i7v+tW2ioFRTEIKKj1mu6dNHF0V1UcxvMSTIrXU=; b=0DZ0wkn6jxXqp0MDI9dIyUXvpnC8ssyevmYVAkJJOU5tW5x7fXYFW54X9RmiL6TCYmo0Ej9BaYJtbjpQUSFHLBU9T1UJbCr3oyVHn5r0wQfGlQ3FNa1UK2Op/jPOhHDVHJQ9Go9zoLkQC/e68Uw3IbgBS98SnS1RSpnZCE/THJk= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by SJ0PR10MB5833.namprd10.prod.outlook.com (2603:10b6:a03:3ed::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.17; Wed, 23 Oct 2024 20:39:07 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8069.024; Wed, 23 Oct 2024 20:39:07 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu Subject: [PATCH v2 5/8] tools: testing: add additional vma_internal.h stubs Date: Wed, 23 Oct 2024 21:38:30 +0100 Message-ID: <4eddd714a8d6dfb052032dfda5aa28d9f4bd134a.1729715266.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO0P265CA0011.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:355::19) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|SJ0PR10MB5833:EE_ X-MS-Office365-Filtering-Correlation-Id: e7539a0c-afad-49dd-a908-08dcf3a2bd80 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|10070799003; X-Microsoft-Antispam-Message-Info: j5OZBnSH9TEJb/SI+ZMzI4ApzF/7cYxZWsbkqOh5Ey3MxSUiRZCf7HT5vab/VrdhpcG7eH3X5xTLZQxK06D2AIyqm60V/jLgmAdoiZHdQoFnrB/gtMWZR0tQ6SF88DJNNqzY5ZEQ8LJLTpLLVF0LkFdJLcy+Mw6cjCwsQqnEP9L3MsxilVuVuDHrUQSmOEDyC7d2kE8SVt11cH8sA8EG/VLTMCuXECiAQov1sRyEY5zcsK50Jb+n69CPybDgXQspCDzu6uaj7W+T9ryV/T0PaB9thZe/TaQ3bItA12hrpcK4xYYGoDZwTqnS25LRsU+xQ/yVr7INAdC94RW1ACtzZESxDSq4EP9mUwVzM+kHpYrILrNn+6G6yX273g2z2LRKyElQDgVqV32yojQB9W+aWRgAv6cniiaM98upLo+bYtAjnl38ip4rXCYznwnRVLUJCgkOntComVXH2gLSTZSBE8VEVp7v7UUaxVYCum0ho6zQS7z3RQgpJvGtzmHf7bkdLeh2FxyONFlZ3wICkKhoIZVeKjrHWEHQIXaApwQ7TROezZxfMN78xJBIJ/47cSutVtgkGB9gIX4inIL1l+YMWvqlEIW0ns+4rzD1ba61lDgrub2/kUpiDnmo8yEMxx0DWFT4WLrDIyFj8td5GHp7PMtJb1pteByVPzb5AxogVkc+OkDse1uMkfuD3I3MovbJVOaSUImc0PkcP6kMQkXx/bgtsS6fyeol4bVaLUW3BZgmeR9CGl9vg2GsdLqZyFtKAGWZU6w55EA5YdsMqU3CJagzIxSZCFWImaRrBSXwN1WgZplwVa7y3gxuVHwJRa7dFPrZviESGKZjWDSQUbMh5DU4w01bjg6UMIXBxMNsSLVTiBQw6C1A4sPeOdKKJUNB6qDQonS44Od/aMvXbCfQaOLVORmAfPwPmYqJ1pCViwAq+E7CYyeo+dAmR+Iz5uj3v3THbys0TCD6/A2X0snhgyfIq98asgBixMZliVyZBa1tpgKd2LW9JIP1JgmTfpevb4/NFhbxtJEZ9MCsBrqpweIoOG5hk9AWKEuWFxb9YcoVGAsiMtNRU7buAwsITgYZzqLDetVsmk/x3HjUKlSt4a0dHS93aCrRnNPSwqgVNo6yZJqFSoEW29/ARHIbEGdi0YJizkOZDGxspLLAAJOEXnvpRO+g8b4E2/Aw13NXTZ5vLkWj5VJZtwEKr2Ax9AiT1T9Dx4OPRsT5rncsr8OhqagPl8zPUWrFTPRfquAAZGns6u8Qd83P+zNg4txVPEvmzBTpyS8YhaHrfrKLDS6KpGofync/OiDJDCnhybgp0Q4= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(10070799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: m9BI3ITDfDXmGd2Fk8MP08qk8v7pYbir3BFFH/BUMakbTwBv229isnJ3RgdIGEcqZIM0Nf9BIocM1mlDt6gyGpcukkwGspuefGQD9reDeqCaz0Hk1s02NVYIRfjEfmhQF7NE8Q+BemvSsjZZffeLfK6U7PlwiGeCaU0vCSfsDhArA81N2qlUhHTEeOstbceild51mShInKrPD/FMr0RY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l7WHKxKBHKISY= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e7539a0c-afad-49dd-a908-08dcf3a2bd80 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2024 20:39:07.1473 (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: ImhGGEXLaUoogCJwlHqfecr6wyRW0PbNhX+89ZQN69en0LH9bAqZTiDC6kOTFuGxgF5zhMM97NeipCraKRRkurD8rY+Los0VEoj3KWEUoHk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5833 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-23_16,2024-10-23_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 malwarescore=0 adultscore=0 mlxscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410230132 X-Proofpoint-ORIG-GUID: MrrK6r_56xooXujw_gIF9lXeizzJIn5J X-Proofpoint-GUID: MrrK6r_56xooXujw_gIF9lXeizzJIn5J X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: 877A3120005 X-Stat-Signature: ueh18sczdmd5f7son5q345smjscrscag X-HE-Tag: 1729715928-356381 X-HE-Meta: U2FsdGVkX18q6IwkLdLwh1hWx592m5pVOQbiuejrD2EIXjel+QL17i3+fEqN59r+q2cAYh7NiCoyVHjKUBY2bMZQx551aws94nPGuQe5jlpr0RnYQU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kyrCDN+NTVVeV2QjiJTDvDE/9fZc4RFWukLXImjXuRiTQDFMxyfT0r6VoKaAmVfyJUOEIhSSCPc0InCWRcdxR9Y2PnrVA+lC9HrA7N4AtmC+EwsbhcUvFUQYRnjaoqtORg05RA6jJLXBtStcgn9XESBR4N0h4AabzKhfoxUYY4so6DHmQcWhF+QQpbN8AwmWzxTj7Pw4Acv6ejwPHhv4B/rnHEvlBCZdQeJlwDBk9qSgnlu1J3/CoqFQb4NyrlU/wS8bV4GKENBO4WTzbB82sZjhx5zRv4b14Rr+/AZEToPhT7xHxgDTU+fMNzyIO1jmqyIGq3aEHrvsqXItqoXaYzXad5EtSTBEcUsCYbB/fwkqtbGfvwlYw1RJ9ISuZVRu30CMTCk1aQYyom9Ri/u 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: Add some additional vma_internal.h stubs in preparation for __mmap_region() being moved to mm/vma.c. Without these the move would result in the tests no longer compiling. Signed-off-by: Lorenzo Stoakes --- tools/testing/vma/vma_internal.h | 115 ++++++++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 1 deletion(-) -- 2.47.0 diff --git a/tools/testing/vma/vma_internal.h b/tools/testing/vma/vma_internal.h index c5b9da034511..77eba27365a2 100644 --- a/tools/testing/vma/vma_internal.h +++ b/tools/testing/vma/vma_internal.h @@ -44,7 +44,9 @@ #define VM_LOCKED 0x00002000 #define VM_IO 0x00004000 #define VM_DONTEXPAND 0x00040000 +#define VM_LOCKONFAULT 0x00080000 #define VM_ACCOUNT 0x00100000 +#define VM_NORESERVE 0x00200000 #define VM_MIXEDMAP 0x10000000 #define VM_STACK VM_GROWSDOWN #define VM_SHADOW_STACK VM_NONE @@ -53,6 +55,14 @@ #define VM_ACCESS_FLAGS (VM_READ | VM_WRITE | VM_EXEC) #define VM_SPECIAL (VM_IO | VM_DONTEXPAND | VM_PFNMAP | VM_MIXEDMAP) +/* This mask represents all the VMA flag bits used by mlock */ +#define VM_LOCKED_MASK (VM_LOCKED | VM_LOCKONFAULT) + +#ifdef CONFIG_64BIT +/* VM is sealed, in vm_flags */ +#define VM_SEALED _BITUL(63) +#endif + #define FIRST_USER_ADDRESS 0UL #define USER_PGTABLES_CEILING 0UL @@ -698,8 +708,9 @@ static inline void tlb_finish_mmu(struct mmu_gather *) { } -static inline void get_file(struct file *) +static inline struct file *get_file(struct file *f) { + return f; } static inline int vma_dup_policy(struct vm_area_struct *, struct vm_area_struct *) @@ -920,4 +931,106 @@ static inline bool signal_pending(void *) return false; } +static inline bool is_file_hugepages(struct file *) +{ + return false; +} + +static inline int security_vm_enough_memory_mm(struct mm_struct *, long) +{ + return true; +} + +static inline bool may_expand_vm(struct mm_struct *, vm_flags_t, unsigned long) +{ + return true; +} + +static inline void vm_flags_init(struct vm_area_struct *vma, + vm_flags_t flags) +{ + vma->__vm_flags = flags; +} + +static inline void vm_flags_set(struct vm_area_struct *vma, + vm_flags_t flags) +{ + vma_start_write(vma); + vma->__vm_flags |= flags; +} + +static inline void vm_flags_clear(struct vm_area_struct *vma, + vm_flags_t flags) +{ + vma_start_write(vma); + vma->__vm_flags &= ~flags; +} + +static inline int call_mmap(struct file *, struct vm_area_struct *) +{ + return 0; +} + +static inline int shmem_zero_setup(struct vm_area_struct *) +{ + return 0; +} + +static inline void vma_set_anonymous(struct vm_area_struct *vma) +{ + vma->vm_ops = NULL; +} + +static inline void ksm_add_vma(struct vm_area_struct *) +{ +} + +static inline void perf_event_mmap(struct vm_area_struct *) +{ +} + +static inline bool vma_is_dax(struct vm_area_struct *) +{ + return false; +} + +static inline struct vm_area_struct *get_gate_vma(struct mm_struct *) +{ + return NULL; +} + +bool vma_wants_writenotify(struct vm_area_struct *vma, pgprot_t vm_page_prot); + +/* Update vma->vm_page_prot to reflect vma->vm_flags. */ +static inline void vma_set_page_prot(struct vm_area_struct *vma) +{ + unsigned long vm_flags = vma->vm_flags; + pgprot_t vm_page_prot; + + /* testing: we inline vm_pgprot_modify() to avoid clash with vma.h. */ + vm_page_prot = pgprot_modify(vma->vm_page_prot, vm_get_page_prot(vm_flags)); + + if (vma_wants_writenotify(vma, vm_page_prot)) { + vm_flags &= ~VM_SHARED; + /* testing: we inline vm_pgprot_modify() to avoid clash with vma.h. */ + vm_page_prot = pgprot_modify(vm_page_prot, vm_get_page_prot(vm_flags)); + } + /* remove_protection_ptes reads vma->vm_page_prot without mmap_lock */ + WRITE_ONCE(vma->vm_page_prot, vm_page_prot); +} + +static inline bool arch_validate_flags(unsigned long) +{ + return true; +} + +static inline void vma_close(struct vm_area_struct *) +{ +} + +static inline int mmap_file(struct file *, struct vm_area_struct *) +{ + return 0; +} + #endif /* __MM_VMA_INTERNAL_H */ From patchwork Wed Oct 23 20:38:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13847898 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 0EECCCFA46A for ; Wed, 23 Oct 2024 20:39:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9883B6B00B1; Wed, 23 Oct 2024 16:39:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 938076B00B3; Wed, 23 Oct 2024 16:39:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6779A6B00B2; Wed, 23 Oct 2024 16:39:20 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 24A0F6B00B0 for ; Wed, 23 Oct 2024 16:39:20 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 83513C0E7D for ; Wed, 23 Oct 2024 20:39:00 +0000 (UTC) X-FDA: 82706031618.15.8D6B063 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf30.hostedemail.com (Postfix) with ESMTP id DA7E18001C for ; Wed, 23 Oct 2024 20:38:42 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=EW2lFWf4; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="uUan/e/v"; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf30.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729715832; a=rsa-sha256; cv=pass; b=GLISJE900lABzlGfbVOIpp03IhsxDygipVQbego3s/RxUZhDvrQZ/yynZj4JwGTUQoLwXH y5XurCttWY945AMxtAJBlRbSsLeGStnqF1bpVp+ZC/k/tD6ovu+a8eol2jBpsKk8arhFgN 3VFHIoLYOl8uwuv1GOlyyyjvjCfTISA= ARC-Authentication-Results: i=2; imf30.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=EW2lFWf4; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="uUan/e/v"; arc=pass ("microsoft.com:s=arcselector10001:i=1"); dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf30.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729715832; 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=UJegJK5P09zD1reHH/LUQnoUje3wTD/Wt9CcED7Sn9Q=; b=0SSvcupfe0CSQgfODROYuAdWPG5oyN+Z154rNNVx6P6T3+/6JrI475iY483RMMVrKSBzZE XMo+tvz21IMtvn+ls2RLFd/kk8fi1sB/R17Rdfgr8nKUdArK3epiAk+SV0A4W4gogiYvIm QOMsFIRYpqYHhzYthb1cWIhW+tm9FcA= 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 49NKcahE005402; Wed, 23 Oct 2024 20:39:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=UJegJK5P09zD1reHH/LUQnoUje3wTD/Wt9CcED7Sn9Q=; b= EW2lFWf4vrwwN+wbHNdicCoop7reb+TshGdFiP+NOdmgweQ4WaE2R3J5YxAZkPC2 YrdAJFgZ5BcCAmgt872/idZvNSLzuTlTiW943vHXAK8xNSJCJuF4BfFwcr4fUut8 cwf3ugpfLzR/OCjCFpoeHidUTavT50J0WHtlPVEFTC9mAYrQECEeCZfHsDD/7iFQ wkuma2gMtaKKKKmNd28B7oWIGQugFWreEUK6ttfteERkqm92kji0svUr3njp4zie J3YtjDM1n0QkMBPWHgXbnwYUmMWcovwn6LmKzd6lrXVT6WSbkQsUOMQfOtEeRxOt ti/3uxgHEyOBnujGjnxLcw== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42ckkr0e4b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:39:13 +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 49NJMpf1039579; Wed, 23 Oct 2024 20:39:13 GMT Received: from nam04-bn8-obe.outbound.protection.outlook.com (mail-bn8nam04lp2045.outbound.protection.outlook.com [104.47.74.45]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42emhbj4dt-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:39:13 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=LVvBTp5U49Slfa4B4lOXOjKxhoXckoPfmcjdJj/9pXZ7xp8P/3v5W5OuM1HpFQslonNGbxT+cRYpTv6CCMXU29Phl6WBEUtPFgmHrYLmpwB/rFJbenXHNSl3G8A1djbdWiJu3iO5bO6it3exjizhDOmJ7dVpjBj47co3ioW1dMoL1WK3B86dxDrU7tVq0yC6dEmHtJrtMI9TloV4LTCLTcgPfFowqZTc8S5+9pDfJIsG9uq7dshvrzcdkrh+RhvgjGrEl2Wpq+OqFcTSJcFnE0c2PEL+HNUIwkE55zr7UjO3RNVs4+Z3RM+3xRe1HI2MDZ72z83eQ1KZPBMvsJfFLA== 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=UJegJK5P09zD1reHH/LUQnoUje3wTD/Wt9CcED7Sn9Q=; b=Aol7WYtd/+FXTyUuuo5f84wA1CtItML9tRjIKCDLpG2dHib3PaK5rzqTajTBg2Yy1+h8GD9Ki1+W4Wh/c9LQON+52eeTaGiqV825O59UMnAXPU6GAKt+w+TaLZX+24/z9QbD1Fo6oD3qSRa5vG+3N0t1ir3qO7iBp7s4OB8Yf/1q5wFbDR/J++L0KRRswNkSWQ7F5/QXciQ9q990dsLJJDaXBJWbRfVRhhYypVbt8aqUiH7Kz7Qfhua0PrQRrIjN9akZ5uVCRR6lRNiFlt1EcdfNFqmZdqInednSbr/My4N9O0q9C4vAQI35OIQByTi/z590imRO6bDZRCx6oZCHIQ== 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=UJegJK5P09zD1reHH/LUQnoUje3wTD/Wt9CcED7Sn9Q=; b=uUan/e/vq83MDUXwp+vQnpf6O8SxMr/DyF/vCwrdIIkQ6gGWJhXQuM1LD+zk9LBQd6tuYj7AREL3DfZ6loAgfZFYPPxsYxkReiuwGVCMVgUqVsxPDN3HFlVGJB+2CSy8NTwrc11j/d03Dth1pzTEZiW3n5XlqaCDiycehO5InnY= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by SJ0PR10MB5833.namprd10.prod.outlook.com (2603:10b6:a03:3ed::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.17; Wed, 23 Oct 2024 20:39:10 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8069.024; Wed, 23 Oct 2024 20:39:10 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu Subject: [PATCH v2 6/8] mm: isolate mmap internal logic to mm/vma.c Date: Wed, 23 Oct 2024 21:38:31 +0100 Message-ID: <67d9ba63e203452431c7ee7802d3988bd1258ab6.1729715266.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P265CA0178.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:311::9) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|SJ0PR10MB5833:EE_ X-MS-Office365-Filtering-Correlation-Id: 8809d1e3-4e40-4a9a-409b-08dcf3a2bfa3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|10070799003; X-Microsoft-Antispam-Message-Info: 0JAkxuIxstkFo81uIE4+QA9VSAX9uPTibYEip5676E1B6vJTXMwstWEHaauKBQvFaEiMTYFhzDc98w8qq4wWzMTKW43DwfFTR03jHXZWSoZOzCg3OqbiTtCdWhbjmd4szs3Hcc7ZxqFu3OTlPMV9+g09oLugt5m4ewWBSCuexiDYknec1JFbGTAV5bbCAUdaYwl38v8xY7YvWP6RCXEn4PEOEpbsgaaaoZggDOOIr9hqLxOz8BaI3QQmfExKAuK8AQE58KCANpei2SVZv5iBbmWlhvImhqzFw6KIjn5efczEjxbM5kBmSaoBKCIc6f0oowDrNT8lDx2+PX42s3F2k00xTS457+szpFNnxMksSa1HFDil7jCVe3AmcR0MN7V6QXr81RYoNcej+JAgZydk/f9ajfOzCrYYbd2pu2/C8SR6kk4PmNuBtsJVrHboc2Mu1w7VeSZwiPssmGk7cXrgnH0gl1aU9iV/6yzyzjtZRydd/tBYuHHv+LHf4JCMqGGf6bmVnEUies0VuC99ESk1vqAgLajFlpuJ+vtb6mePq+9Xm2kcfR/BGw/EhcF/DjEQmqJl+tzuABfpgL22EnA9PTVZjJ6lpD60/MGsKyOU45oLB7gaDJ1+VyUCKo8oYsDmmoT5duyHqiOlXlEMt0I1e6OcsaeTq6q8iEg8VZNZnZ/o4Sir+JcjF87rqwsGPBnGvNwOBSGN9PcqlOlhsFh0Ynm5XiGreD8qN66+SLGpWnf7DbQxjCi2hYiuayHaNDFzN4rOQkGcNCsT6ZyMim5KAZiqfa9bioEd982UGqnEjiQTYDcbYorrt4s27ldQf3Z6mHOTBH0AwPLZZKEvePM1sLSBmCsYkbwKmReF6Nf+Z7I5N0SE82Y9qJDVg9lRSAbU7SezNGYMhneu8AhQz+CFISYoh/efg0sUGKDY5w/TL7O8y2RL9zfUJtUBJfqGkPTJGp36MQwyqP10AlSBGgmOB3S/vbf4cWmj6hY0zjVLekQ98iwPOn9iKzmDnD8W4D2KxFXGmOSZFZv5vmGw+G1+xHGQa1BoymKWLLSry/3Lt6mmHAfPGX22uhFnncZZwKrCqbY6aJl9YhzUpVsDBW/jb78sMZeyjscJahpt5zkSClysQZqbNhgap8mutU5fxT1u4ncYDgy/Ix1hVhgMGzuZPEaMmpuqvr/1d/S3ADJNQwpMtxk+E7Nq8ExXcyURzjJD3zsM0csBkbXFZNiwnwj8YiTbL8KEQMh5Rw/r5PUWHFJIRujxBHh6RDcWVsXYyiNN0MluPRMkw1f9pFwOCKFiaJMBBRko5YJ9vw+BUmOe26dfRszJhvygkV6xpnsEVwLM X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(10070799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1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vBOISeyQGQkFAwkxj6kOABmyJpx2edB8mDVRR/Morbob4S+9gfycvGyToMq0ByvB4bi57IuX4wBZoPw2SAgiWHgdTb6yyOL3IIn1NzH0zVQFhKd60EoLxiq7R8O0mBL7osIz3uhXJQNcdB2wHfFp/D6Fkjz8uXdoAkTxP/fbX8kDO1hiY2lz34sZgwmFoy5EznmyVuaNLlppc6BBr9WAVtBrpDOFOHL1vB3p8XuvCc/p/i5uJrcXhTcWb/c= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8809d1e3-4e40-4a9a-409b-08dcf3a2bfa3 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2024 20:39:10.7486 (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: /Icfi16DXD6lROd2jR6UWGONfDQNg5CXv+9cF2DSbu1wtGGk3NmxwXPRRhB7rwH1BKIlkO4ER6hgoo/NqFiWtkTjzFjdBVQbxk5oxx3KSCI= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5833 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-23_16,2024-10-23_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 mlxscore=0 phishscore=0 suspectscore=0 bulkscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410230132 X-Proofpoint-GUID: NdrEEQCvf8Dfy0wg6hR1z00SdQhSvRPk X-Proofpoint-ORIG-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H378L9JvtMYJtzlJZURFisou0hP6AVJ5J9dzwEGEkkU0wk7WrsgvtCLvyA caplBb8O nbO312IgNI2S07z1j4uprPdwrlX76Sb7D1RGhZcisoHWW5EG/vjSjHDTbfcFhOlMq4PFmSaQu/G6J83AX6iYnHsnM3XBFv0hpfI6gJLCyKArNrpC6hvA57fTGbcQB2IqxjV6DZTr4DA5TfEjuYyLsgHO7FZt0MNZ9Z4xy448j+Ds1neP0VQ3WfdMio1j1Er+ohqGYtsgx3tF3O7a46ywXPAJjgkcJfgcfRcfb/Wu/0D8+CupLMQ+e58BEX6bCi2M68sxK9uwWcvtiqbZaZcbT1A8iTo4Af5zQtXOmopMm9nDPO8A5lEj8PQkJfUhCtGYkm8Z8jdv/yNm9kKVi5AcZsBJAIkR9qUl8KLR2amqGV8BRCjNYUQs0b96gN4/NZ5ghxOssxhNLFBa2jEF6wT9kbSwpmhq807CwLblj3JI3IqPDiitT62oOU4X3JzQawF1gPOFEkd9+5wo/WIg2B4BE6r+X3o/aO6nBeLmBy/NAALXP/iPZYK/XfivNn1vMMA/PYLcLTyhs+k1AzEI= 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: In previous commits we effected improvements to the mmap() logic in mmap_region() and its newly introduced internal implementation function __mmap_region(). However as these changes are intended to be backported, we kept the delta as small as is possible and made as few changes as possible to the newly introduced mm/vma.* files. Take the opportunity to move this logic to mm/vma.c which not only isolates it, but also makes it available for later userland testing which can help us catch such logic errors far earlier. Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- mm/mmap.c | 234 --------------------------------- mm/vma.c | 323 +++++++++++++++++++++++++++++++++++++++++++++- mm/vma.h | 97 +------------- mm/vma_internal.h | 5 + 4 files changed, 329 insertions(+), 330 deletions(-) diff --git a/mm/mmap.c b/mm/mmap.c index e686d57ed9f7..0affd1a0687f 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -577,22 +577,6 @@ SYSCALL_DEFINE1(old_mmap, struct mmap_arg_struct __user *, arg) } #endif /* __ARCH_WANT_SYS_OLD_MMAP */ -/* - * We account for memory if it's a private writeable mapping, - * not hugepages and VM_NORESERVE wasn't set. - */ -static inline bool accountable_mapping(struct file *file, vm_flags_t vm_flags) -{ - /* - * hugetlb has its own accounting separate from the core VM - * VM_HUGETLB may not be set yet so we cannot check for that flag. - */ - if (file && is_file_hugepages(file)) - return false; - - return (vm_flags & (VM_NORESERVE | VM_SHARED | VM_WRITE)) == VM_WRITE; -} - /** * unmapped_area() - Find an area between the low_limit and the high_limit with * the correct alignment and offset, all from @info. Note: current->mm is used @@ -1361,224 +1345,6 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len, return do_vmi_munmap(&vmi, mm, start, len, uf, false); } -static unsigned long __mmap_region(struct file *file, unsigned long addr, - unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, - struct list_head *uf) -{ - struct mm_struct *mm = current->mm; - struct vm_area_struct *vma = NULL; - pgoff_t pglen = PHYS_PFN(len); - unsigned long charged = 0; - struct vma_munmap_struct vms; - struct ma_state mas_detach; - struct maple_tree mt_detach; - unsigned long end = addr + len; - int error; - VMA_ITERATOR(vmi, mm, addr); - VMG_STATE(vmg, mm, &vmi, addr, end, vm_flags, pgoff); - - vmg.file = file; - /* Find the first overlapping VMA */ - vma = vma_find(&vmi, end); - init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock = */ false); - if (vma) { - mt_init_flags(&mt_detach, vmi.mas.tree->ma_flags & MT_FLAGS_LOCK_MASK); - mt_on_stack(mt_detach); - mas_init(&mas_detach, &mt_detach, /* addr = */ 0); - /* Prepare to unmap any existing mapping in the area */ - error = vms_gather_munmap_vmas(&vms, &mas_detach); - if (error) - goto gather_failed; - - vmg.next = vms.next; - vmg.prev = vms.prev; - vma = NULL; - } else { - vmg.next = vma_iter_next_rewind(&vmi, &vmg.prev); - } - - /* Check against address space limit. */ - if (!may_expand_vm(mm, vm_flags, pglen - vms.nr_pages)) { - error = -ENOMEM; - goto abort_munmap; - } - - /* - * Private writable mapping: check memory availability - */ - if (accountable_mapping(file, vm_flags)) { - charged = pglen; - charged -= vms.nr_accounted; - if (charged) { - error = security_vm_enough_memory_mm(mm, charged); - if (error) - goto abort_munmap; - } - - vms.nr_accounted = 0; - vm_flags |= VM_ACCOUNT; - vmg.flags = vm_flags; - } - - /* - * clear PTEs while the vma is still in the tree so that rmap - * cannot race with the freeing later in the truncate scenario. - * This is also needed for mmap_file(), which is why vm_ops - * close function is called. - */ - vms_clean_up_area(&vms, &mas_detach); - vma = vma_merge_new_range(&vmg); - if (vma) - goto expanded; - /* - * Determine the object being mapped and call the appropriate - * specific mapper. the address has already been validated, but - * not unmapped, but the maps are removed from the list. - */ - vma = vm_area_alloc(mm); - if (!vma) { - error = -ENOMEM; - goto unacct_error; - } - - vma_iter_config(&vmi, addr, end); - vma_set_range(vma, addr, end, pgoff); - vm_flags_init(vma, vm_flags); - vma->vm_page_prot = vm_get_page_prot(vm_flags); - - if (vma_iter_prealloc(&vmi, vma)) { - error = -ENOMEM; - goto free_vma; - } - - if (file) { - vma->vm_file = get_file(file); - error = mmap_file(file, vma); - if (error) - goto unmap_and_free_file_vma; - - /* Drivers cannot alter the address of the VMA. */ - WARN_ON_ONCE(addr != vma->vm_start); - /* - * Drivers should not permit writability when previously it was - * disallowed. - */ - VM_WARN_ON_ONCE(vm_flags != vma->vm_flags && - !(vm_flags & VM_MAYWRITE) && - (vma->vm_flags & VM_MAYWRITE)); - - vma_iter_config(&vmi, addr, end); - /* - * If vm_flags changed after mmap_file(), we should try merge - * vma again as we may succeed this time. - */ - if (unlikely(vm_flags != vma->vm_flags && vmg.prev)) { - struct vm_area_struct *merge; - - vmg.flags = vma->vm_flags; - /* If this fails, state is reset ready for a reattempt. */ - merge = vma_merge_new_range(&vmg); - - if (merge) { - /* - * ->mmap() can change vma->vm_file and fput - * the original file. So fput the vma->vm_file - * here or we would add an extra fput for file - * and cause general protection fault - * ultimately. - */ - fput(vma->vm_file); - vm_area_free(vma); - vma = merge; - /* Update vm_flags to pick up the change. */ - vm_flags = vma->vm_flags; - goto file_expanded; - } - vma_iter_config(&vmi, addr, end); - } - - vm_flags = vma->vm_flags; - } else if (vm_flags & VM_SHARED) { - error = shmem_zero_setup(vma); - if (error) - goto free_iter_vma; - } else { - vma_set_anonymous(vma); - } - -#ifdef CONFIG_SPARC64 - /* TODO: Fix SPARC ADI! */ - WARN_ON_ONCE(!arch_validate_flags(vm_flags)); -#endif - - /* Lock the VMA since it is modified after insertion into VMA tree */ - vma_start_write(vma); - vma_iter_store(&vmi, vma); - mm->map_count++; - vma_link_file(vma); - - /* - * vma_merge_new_range() calls khugepaged_enter_vma() too, the below - * call covers the non-merge case. - */ - khugepaged_enter_vma(vma, vma->vm_flags); - -file_expanded: - file = vma->vm_file; - ksm_add_vma(vma); -expanded: - perf_event_mmap(vma); - - /* Unmap any existing mapping in the area */ - vms_complete_munmap_vmas(&vms, &mas_detach); - - vm_stat_account(mm, vm_flags, pglen); - if (vm_flags & VM_LOCKED) { - if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) || - is_vm_hugetlb_page(vma) || - vma == get_gate_vma(current->mm)) - vm_flags_clear(vma, VM_LOCKED_MASK); - else - mm->locked_vm += pglen; - } - - if (file) - uprobe_mmap(vma); - - /* - * New (or expanded) vma always get soft dirty status. - * Otherwise user-space soft-dirty page tracker won't - * be able to distinguish situation when vma area unmapped, - * then new mapped in-place (which must be aimed as - * a completely new data area). - */ - vm_flags_set(vma, VM_SOFTDIRTY); - - vma_set_page_prot(vma); - - return addr; - -unmap_and_free_file_vma: - fput(vma->vm_file); - vma->vm_file = NULL; - - vma_iter_set(&vmi, vma->vm_end); - /* Undo any partial mapping done by a device driver. */ - unmap_region(&vmi.mas, vma, vmg.prev, vmg.next); -free_iter_vma: - vma_iter_free(&vmi); -free_vma: - vm_area_free(vma); -unacct_error: - if (charged) - vm_unacct_memory(charged); - -abort_munmap: - vms_abort_munmap_vmas(&vms, &mas_detach); -gather_failed: - return error; -} - unsigned long mmap_region(struct file *file, unsigned long addr, unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, struct list_head *uf) diff --git a/mm/vma.c b/mm/vma.c index bb7cfa2dc282..0a2965be582d 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -1103,7 +1103,7 @@ static inline void vms_clear_ptes(struct vma_munmap_struct *vms, vms->clear_ptes = false; } -void vms_clean_up_area(struct vma_munmap_struct *vms, +static void vms_clean_up_area(struct vma_munmap_struct *vms, struct ma_state *mas_detach) { struct vm_area_struct *vma; @@ -1126,7 +1126,7 @@ void vms_clean_up_area(struct vma_munmap_struct *vms, * used for the munmap() and may downgrade the lock - if requested. Everything * needed to be done once the vma maple tree is updated. */ -void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, +static void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, struct ma_state *mas_detach) { struct vm_area_struct *vma; @@ -1167,6 +1167,23 @@ void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, __mt_destroy(mas_detach->tree); } +/* + * reattach_vmas() - Undo any munmap work and free resources + * @mas_detach: The maple state with the detached maple tree + * + * Reattach any detached vmas and free up the maple tree used to track the vmas. + */ +static void reattach_vmas(struct ma_state *mas_detach) +{ + struct vm_area_struct *vma; + + mas_set(mas_detach, 0); + mas_for_each(mas_detach, vma, ULONG_MAX) + vma_mark_detached(vma, false); + + __mt_destroy(mas_detach->tree); +} + /* * vms_gather_munmap_vmas() - Put all VMAs within a range into a maple tree * for removal at a later date. Handles splitting first and last if necessary @@ -1177,7 +1194,7 @@ void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, * * Return: 0 on success, error otherwise */ -int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, +static int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, struct ma_state *mas_detach) { struct vm_area_struct *next = NULL; @@ -1315,6 +1332,39 @@ int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, return error; } +/* + * init_vma_munmap() - Initializer wrapper for vma_munmap_struct + * @vms: The vma munmap struct + * @vmi: The vma iterator + * @vma: The first vm_area_struct to munmap + * @start: The aligned start address to munmap + * @end: The aligned end address to munmap + * @uf: The userfaultfd list_head + * @unlock: Unlock after the operation. Only unlocked on success + */ +static void init_vma_munmap(struct vma_munmap_struct *vms, + struct vma_iterator *vmi, struct vm_area_struct *vma, + unsigned long start, unsigned long end, struct list_head *uf, + bool unlock) +{ + vms->vmi = vmi; + vms->vma = vma; + if (vma) { + vms->start = start; + vms->end = end; + } else { + vms->start = vms->end = 0; + } + vms->unlock = unlock; + vms->uf = uf; + vms->vma_count = 0; + vms->nr_pages = vms->locked_vm = vms->nr_accounted = 0; + vms->exec_vm = vms->stack_vm = vms->data_vm = 0; + vms->unmap_start = FIRST_USER_ADDRESS; + vms->unmap_end = USER_PGTABLES_CEILING; + vms->clear_ptes = false; +} + /* * do_vmi_align_munmap() - munmap the aligned region from @start to @end. * @vmi: The vma iterator @@ -2069,3 +2119,270 @@ void mm_drop_all_locks(struct mm_struct *mm) mutex_unlock(&mm_all_locks_mutex); } + +/* + * We account for memory if it's a private writeable mapping, + * not hugepages and VM_NORESERVE wasn't set. + */ +static bool accountable_mapping(struct file *file, vm_flags_t vm_flags) +{ + /* + * hugetlb has its own accounting separate from the core VM + * VM_HUGETLB may not be set yet so we cannot check for that flag. + */ + if (file && is_file_hugepages(file)) + return false; + + return (vm_flags & (VM_NORESERVE | VM_SHARED | VM_WRITE)) == VM_WRITE; +} + +/* + * vms_abort_munmap_vmas() - Undo as much as possible from an aborted munmap() + * operation. + * @vms: The vma unmap structure + * @mas_detach: The maple state with the detached maple tree + * + * Reattach any detached vmas, free up the maple tree used to track the vmas. + * If that's not possible because the ptes are cleared (and vm_ops->closed() may + * have been called), then a NULL is written over the vmas and the vmas are + * removed (munmap() completed). + */ +static void vms_abort_munmap_vmas(struct vma_munmap_struct *vms, + struct ma_state *mas_detach) +{ + struct ma_state *mas = &vms->vmi->mas; + + if (!vms->nr_pages) + return; + + if (vms->clear_ptes) + return reattach_vmas(mas_detach); + + /* + * Aborting cannot just call the vm_ops open() because they are often + * not symmetrical and state data has been lost. Resort to the old + * failure method of leaving a gap where the MAP_FIXED mapping failed. + */ + mas_set_range(mas, vms->start, vms->end - 1); + mas_store_gfp(mas, NULL, GFP_KERNEL|__GFP_NOFAIL); + /* Clean up the insertion of the unfortunate gap */ + vms_complete_munmap_vmas(vms, mas_detach); +} + +unsigned long __mmap_region(struct file *file, unsigned long addr, + unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, + struct list_head *uf) +{ + struct mm_struct *mm = current->mm; + struct vm_area_struct *vma = NULL; + pgoff_t pglen = PHYS_PFN(len); + unsigned long charged = 0; + struct vma_munmap_struct vms; + struct ma_state mas_detach; + struct maple_tree mt_detach; + unsigned long end = addr + len; + int error; + VMA_ITERATOR(vmi, mm, addr); + VMG_STATE(vmg, mm, &vmi, addr, end, vm_flags, pgoff); + + vmg.file = file; + /* Find the first overlapping VMA */ + vma = vma_find(&vmi, end); + init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock = */ false); + if (vma) { + mt_init_flags(&mt_detach, vmi.mas.tree->ma_flags & MT_FLAGS_LOCK_MASK); + mt_on_stack(mt_detach); + mas_init(&mas_detach, &mt_detach, /* addr = */ 0); + /* Prepare to unmap any existing mapping in the area */ + error = vms_gather_munmap_vmas(&vms, &mas_detach); + if (error) + goto gather_failed; + + vmg.next = vms.next; + vmg.prev = vms.prev; + vma = NULL; + } else { + vmg.next = vma_iter_next_rewind(&vmi, &vmg.prev); + } + + /* Check against address space limit. */ + if (!may_expand_vm(mm, vm_flags, pglen - vms.nr_pages)) { + error = -ENOMEM; + goto abort_munmap; + } + + /* + * Private writable mapping: check memory availability + */ + if (accountable_mapping(file, vm_flags)) { + charged = pglen; + charged -= vms.nr_accounted; + if (charged) { + error = security_vm_enough_memory_mm(mm, charged); + if (error) + goto abort_munmap; + } + + vms.nr_accounted = 0; + vm_flags |= VM_ACCOUNT; + vmg.flags = vm_flags; + } + + /* + * clear PTEs while the vma is still in the tree so that rmap + * cannot race with the freeing later in the truncate scenario. + * This is also needed for mmap_file(), which is why vm_ops + * close function is called. + */ + vms_clean_up_area(&vms, &mas_detach); + vma = vma_merge_new_range(&vmg); + if (vma) + goto expanded; + /* + * Determine the object being mapped and call the appropriate + * specific mapper. the address has already been validated, but + * not unmapped, but the maps are removed from the list. + */ + vma = vm_area_alloc(mm); + if (!vma) { + error = -ENOMEM; + goto unacct_error; + } + + vma_iter_config(&vmi, addr, end); + vma_set_range(vma, addr, end, pgoff); + vm_flags_init(vma, vm_flags); + vma->vm_page_prot = vm_get_page_prot(vm_flags); + + if (vma_iter_prealloc(&vmi, vma)) { + error = -ENOMEM; + goto free_vma; + } + + if (file) { + vma->vm_file = get_file(file); + error = mmap_file(file, vma); + if (error) + goto unmap_and_free_file_vma; + + /* Drivers cannot alter the address of the VMA. */ + WARN_ON_ONCE(addr != vma->vm_start); + /* + * Drivers should not permit writability when previously it was + * disallowed. + */ + VM_WARN_ON_ONCE(vm_flags != vma->vm_flags && + !(vm_flags & VM_MAYWRITE) && + (vma->vm_flags & VM_MAYWRITE)); + + vma_iter_config(&vmi, addr, end); + /* + * If vm_flags changed after mmap_file(), we should try merge + * vma again as we may succeed this time. + */ + if (unlikely(vm_flags != vma->vm_flags && vmg.prev)) { + struct vm_area_struct *merge; + + vmg.flags = vma->vm_flags; + /* If this fails, state is reset ready for a reattempt. */ + merge = vma_merge_new_range(&vmg); + + if (merge) { + /* + * ->mmap() can change vma->vm_file and fput + * the original file. So fput the vma->vm_file + * here or we would add an extra fput for file + * and cause general protection fault + * ultimately. + */ + fput(vma->vm_file); + vm_area_free(vma); + vma = merge; + /* Update vm_flags to pick up the change. */ + vm_flags = vma->vm_flags; + goto file_expanded; + } + vma_iter_config(&vmi, addr, end); + } + + vm_flags = vma->vm_flags; + } else if (vm_flags & VM_SHARED) { + error = shmem_zero_setup(vma); + if (error) + goto free_iter_vma; + } else { + vma_set_anonymous(vma); + } + +#ifdef CONFIG_SPARC64 + /* TODO: Fix SPARC ADI! */ + WARN_ON_ONCE(!arch_validate_flags(vm_flags)); +#endif + + /* Lock the VMA since it is modified after insertion into VMA tree */ + vma_start_write(vma); + vma_iter_store(&vmi, vma); + mm->map_count++; + vma_link_file(vma); + + /* + * vma_merge_new_range() calls khugepaged_enter_vma() too, the below + * call covers the non-merge case. + */ + khugepaged_enter_vma(vma, vma->vm_flags); + +file_expanded: + file = vma->vm_file; + ksm_add_vma(vma); +expanded: + perf_event_mmap(vma); + + /* Unmap any existing mapping in the area */ + vms_complete_munmap_vmas(&vms, &mas_detach); + + vm_stat_account(mm, vm_flags, pglen); + if (vm_flags & VM_LOCKED) { + if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) || + is_vm_hugetlb_page(vma) || + vma == get_gate_vma(current->mm)) + vm_flags_clear(vma, VM_LOCKED_MASK); + else + mm->locked_vm += pglen; + } + + if (file) + uprobe_mmap(vma); + + /* + * New (or expanded) vma always get soft dirty status. + * Otherwise user-space soft-dirty page tracker won't + * be able to distinguish situation when vma area unmapped, + * then new mapped in-place (which must be aimed as + * a completely new data area). + */ + vm_flags_set(vma, VM_SOFTDIRTY); + + vma_set_page_prot(vma); + + return addr; + +unmap_and_free_file_vma: + fput(vma->vm_file); + vma->vm_file = NULL; + + vma_iter_set(&vmi, vma->vm_end); + /* Undo any partial mapping done by a device driver. */ + unmap_region(&vmi.mas, vma, vmg.prev, vmg.next); +free_iter_vma: + vma_iter_free(&vmi); +free_vma: + vm_area_free(vma); +unacct_error: + if (charged) + vm_unacct_memory(charged); + +abort_munmap: + vms_abort_munmap_vmas(&vms, &mas_detach); +gather_failed: + return error; +} diff --git a/mm/vma.h b/mm/vma.h index d58068c0ff2e..388d34748674 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -165,99 +165,6 @@ static inline int vma_iter_store_gfp(struct vma_iterator *vmi, return 0; } -#ifdef CONFIG_MMU -/* - * init_vma_munmap() - Initializer wrapper for vma_munmap_struct - * @vms: The vma munmap struct - * @vmi: The vma iterator - * @vma: The first vm_area_struct to munmap - * @start: The aligned start address to munmap - * @end: The aligned end address to munmap - * @uf: The userfaultfd list_head - * @unlock: Unlock after the operation. Only unlocked on success - */ -static inline void init_vma_munmap(struct vma_munmap_struct *vms, - struct vma_iterator *vmi, struct vm_area_struct *vma, - unsigned long start, unsigned long end, struct list_head *uf, - bool unlock) -{ - vms->vmi = vmi; - vms->vma = vma; - if (vma) { - vms->start = start; - vms->end = end; - } else { - vms->start = vms->end = 0; - } - vms->unlock = unlock; - vms->uf = uf; - vms->vma_count = 0; - vms->nr_pages = vms->locked_vm = vms->nr_accounted = 0; - vms->exec_vm = vms->stack_vm = vms->data_vm = 0; - vms->unmap_start = FIRST_USER_ADDRESS; - vms->unmap_end = USER_PGTABLES_CEILING; - vms->clear_ptes = false; -} -#endif - -int vms_gather_munmap_vmas(struct vma_munmap_struct *vms, - struct ma_state *mas_detach); - -void vms_complete_munmap_vmas(struct vma_munmap_struct *vms, - struct ma_state *mas_detach); - -void vms_clean_up_area(struct vma_munmap_struct *vms, - struct ma_state *mas_detach); - -/* - * reattach_vmas() - Undo any munmap work and free resources - * @mas_detach: The maple state with the detached maple tree - * - * Reattach any detached vmas and free up the maple tree used to track the vmas. - */ -static inline void reattach_vmas(struct ma_state *mas_detach) -{ - struct vm_area_struct *vma; - - mas_set(mas_detach, 0); - mas_for_each(mas_detach, vma, ULONG_MAX) - vma_mark_detached(vma, false); - - __mt_destroy(mas_detach->tree); -} - -/* - * vms_abort_munmap_vmas() - Undo as much as possible from an aborted munmap() - * operation. - * @vms: The vma unmap structure - * @mas_detach: The maple state with the detached maple tree - * - * Reattach any detached vmas, free up the maple tree used to track the vmas. - * If that's not possible because the ptes are cleared (and vm_ops->closed() may - * have been called), then a NULL is written over the vmas and the vmas are - * removed (munmap() completed). - */ -static inline void vms_abort_munmap_vmas(struct vma_munmap_struct *vms, - struct ma_state *mas_detach) -{ - struct ma_state *mas = &vms->vmi->mas; - if (!vms->nr_pages) - return; - - if (vms->clear_ptes) - return reattach_vmas(mas_detach); - - /* - * Aborting cannot just call the vm_ops open() because they are often - * not symmetrical and state data has been lost. Resort to the old - * failure method of leaving a gap where the MAP_FIXED mapping failed. - */ - mas_set_range(mas, vms->start, vms->end - 1); - mas_store_gfp(mas, NULL, GFP_KERNEL|__GFP_NOFAIL); - /* Clean up the insertion of the unfortunate gap */ - vms_complete_munmap_vmas(vms, mas_detach); -} - int do_vmi_align_munmap(struct vma_iterator *vmi, struct vm_area_struct *vma, struct mm_struct *mm, unsigned long start, @@ -336,6 +243,10 @@ bool vma_wants_writenotify(struct vm_area_struct *vma, pgprot_t vm_page_prot); int mm_take_all_locks(struct mm_struct *mm); void mm_drop_all_locks(struct mm_struct *mm); +unsigned long __mmap_region(struct file *file, unsigned long addr, + unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, + struct list_head *uf); + static inline bool vma_wants_manual_pte_write_upgrade(struct vm_area_struct *vma) { /* diff --git a/mm/vma_internal.h b/mm/vma_internal.h index b930ab12a587..fc5f172a36bd 100644 --- a/mm/vma_internal.h +++ b/mm/vma_internal.h @@ -17,8 +17,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -32,11 +34,14 @@ #include #include #include +#include #include #include #include #include #include +#include +#include #include #include #include From patchwork Wed Oct 23 20:38:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13847899 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 29054CFA46A for ; Wed, 23 Oct 2024 20:39:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B37616B00B3; Wed, 23 Oct 2024 16:39:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ABF236B00B5; Wed, 23 Oct 2024 16:39:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 89C646B00B4; Wed, 23 Oct 2024 16:39:24 -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 657D46B00B2 for ; Wed, 23 Oct 2024 16:39:24 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CA18280E54 for ; Wed, 23 Oct 2024 20:39:08 +0000 (UTC) X-FDA: 82706031702.10.E769E83 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf15.hostedemail.com (Postfix) with ESMTP id B4B15A002D for ; Wed, 23 Oct 2024 20:39:02 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=P7wUYVpc; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=aSeU5KxM; spf=pass (imf15.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729715757; 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=vHCZVUqc1OUCr81cPgBjdxfmyaJ7aPEXNpHoog10F9s=; b=mc39VWt8pi5IfpD6PH46/xJoxNVy4oV2mYlb7bi+K7fQMk6nQf4hZGuChoLlW65X4sad52 72uOxwCheDSv0ViCU4Gx3YfL7s7Uqb1L9TmQKVJ+Ukcq19jKfLMqN1kEz0YED1DBqyVECj 6QADx0euN8ww9Qrop2qh7lxB3dxYJLk= ARC-Authentication-Results: i=2; imf15.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=P7wUYVpc; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=aSeU5KxM; spf=pass (imf15.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729715757; a=rsa-sha256; cv=pass; b=PjHN7MrbpvbH7jPJKOguHEbmNMQd5VbABcYKf22XK1l710xWefgH2e6Ecwwg/U3XuA8vKR QDO90CgHCnX5UKxoMtAqo5V16O9HT0F04O7kfxX8DDxxTgYmJqN4bqj0yO8PO4nWVynH3m Jp+J0FCQd32D2hsO687KdG71t6dWmMk= Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49NKcSvA025102; Wed, 23 Oct 2024 20:39:18 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=vHCZVUqc1OUCr81cPgBjdxfmyaJ7aPEXNpHoog10F9s=; b= P7wUYVpc+GNTuQiiEwHeiZn8qnZCiF9c5Rdl6vecgUhjY3TVMG6iaNfJSZ2F38VH BOUKXAB0to8774cVS8k9joaKAIfwpjj6SddEOfHggRe4+Ic8+Q4Ut3Z4/LgVNVuM Vh69eDdFE+tb1H+NNn+luE1i+hajunk6rIYWwCWxq/qLpIvP1y8bql5g3LGGOdGu 018vIggzJeRBejDN2YsIqUkD3T3pLZ/D5FlwoAmwqlbX78ZJQKXRDw9G67dXfZNp 1vD5UTdNYZXVOjsS56WvBmFghf1MikvDLw3mxBXFkwxCeVNm5JdF5lKKxggY8EhU WURzoezomfsyIMVWkCUotg== Received: from phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta02.appoci.oracle.com [147.154.114.232]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42c57qh5dh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:39:18 +0000 (GMT) Received: from pps.filterd (phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (8.18.1.2/8.18.1.2) with ESMTP id 49NJKtmU025386; Wed, 23 Oct 2024 20:39:17 GMT Received: from nam10-dm6-obe.outbound.protection.outlook.com (mail-dm6nam10lp2047.outbound.protection.outlook.com [104.47.58.47]) by phxpaimrmta02.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 42emha1at9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:39:17 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=s/7paXTJIYpvUJ5CQ15I+7Th0MbvZOBUmJsnqS7NwHsTZ5O04KlnQpiwg9Le/jLKSkf+1L2PzLkEWUlWumahE1PDVT9/m+lUiQO5o2jYEKh9zSAOsmcIAn8SYcVVyweD49FZFZ9Bn56o/kZhAlO6iO+Qaxr719j9TzsN1eIc3QNXMuL09qTyCAoNJ3/L8uW+RLRXd+1x4Tv4I3Ury41Me+tAZK50DXhJ//XTRmUFaMC11LCUM8bMHdeMmtD0UFfyiTyLUNx5Zc9Saudt9VTS5m1/wbC1wJ8UoQWIw6xkJHskmVTLL54bn3cT72WmtMnOV2AFnHiGX5pUmmjru8ZU2w== 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=vHCZVUqc1OUCr81cPgBjdxfmyaJ7aPEXNpHoog10F9s=; b=l9jukNyjFBl1AmFBMijPCTXSIuY5q6ik3ugsGeTKOjGwFlvWpHhsFNbqH+FhtS/W+7fGTUmIvus2Jg7Wa2hTpf/hghBII7dDxw1TanUWjGd0vYO0bLZY5qcNKeA8ig3S/TUbWFDmfulzxp4R7edFb8/Fdtj//H4IQr6SY4/tkP8MkdpZGPH28Fx3Mtd5O7G9Xz8siJrjgbhImb5sNU5A6rTpt5n2G/bGLvbXidnlAY+STUkSQ4k/OGFPW9b+Sk7/Rq3kcxpFxvkIFpJrdUDw2ESuvP8eMBUvYKPAcAgaH7p3Qxc7dZIuBESQEOG8dPtbBEPouu0VIfnS3WONMwcASg== 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=vHCZVUqc1OUCr81cPgBjdxfmyaJ7aPEXNpHoog10F9s=; b=aSeU5KxM0qsk1TDAtN7elBVri98OSH1SbhHkLz9hq9U3baGvQ9SkQDBKqMMYDXpwMSUS7Mggm5rplnWPBuRQcVYDJexaJRPAkO8EZ/qHzZknycNwl1XrDL5AOTNUsl0vjLCuIxfL6lXweEVhUQiKrmAN14RZetcCYBslRmdUXIQ= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by SJ0PR10MB5833.namprd10.prod.outlook.com (2603:10b6:a03:3ed::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.17; Wed, 23 Oct 2024 20:39:14 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8069.024; Wed, 23 Oct 2024 20:39:14 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu Subject: [PATCH v2 7/8] mm: refactor __mmap_region() Date: Wed, 23 Oct 2024 21:38:32 +0100 Message-ID: <0b1da31b49d47ccb930d36f509d50d04c0422b73.1729715266.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0017.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:150::22) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|SJ0PR10MB5833:EE_ X-MS-Office365-Filtering-Correlation-Id: 32a31267-82d1-455a-9d55-08dcf3a2c1e7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|10070799003; X-Microsoft-Antispam-Message-Info: uARFujKRRbAN7Duma0lB6AwYvt3jkfbmkkAQthcqAyALiSE9ubD+ELRYoxwhjKWerQyQtn6zcbYVTjFKac+AE50lRUrkF/URsb8jYyEc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b+XHZ2eziVvgFRF/4zH6G9To35PzEA3IfPCdesEwwdbGIU/VFBGr1jJVyefrOrzfhBZ9M8d85USb5r4dTTC80sOFezwN86g3k3Xz5OsZp7rW5k212tKKfeQKGPnDh3Asfq0kRjpE2RYbIwvvgGYIYIBo1GRfXGNQ6QKod X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BYAPR10MB3366.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(10070799003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ru2HcCFNLNwVzbo3C81gm8DttFacSl48iTH7TkBQD2VvvETvDbrdOtm8jbK2G3aStzj6sDoSzUXm+cZ37iax7za0hiMYTq7kmfJ5h8yCnwFhdvLUXaCffLBfTK7fgDZ29etazyiEThkJeRLAGuyz6Ziizjp3QPkmrzTn3g1hk+KBD8OhUcZ85S5vzg1HhZnt/4sfzdDiHguXgrrdZSrP2KgudBD1xn/uXrbzUqPXDAo45NJkvnhjNAyBb3+0U1ZQ5y6pHswwm9UUPISoUX73y5osno0o00chBReEQyFwaFYlGuGteV/SLOktWEqxVWJo00ONK6zmOyjRSKrS0fw8nhzmSDA/e7MyE5Q/nFAGQ8kjkHND4XTG2QQTlpNCV/rRpJu3//vsFXi8lrP7+YFHvCdRFNzHzyqo98yAge6VBFrw4nvmZDChyvnj9ASD5uC5vcKyHLMlIzug0WgBF3PoAgahsT5FZUbBfcSkD2kNq5pywdp971OqfHuCCE/fACC7ZpWuhlab0RxNkw7X0L8rKmpJ2MqWmML/wSCp9rYhLcO9W3/GQ0eqOgxv4h02Mr3ZjuMcuGF7i/f4o4DMfx7EGQpg/9t5PKQxADTVLuMx7BSSgQjrkdvNPCbeK2h/vzaJQKhOTKdBJdSLPtgoWemo7ytC2Gv/MrjJbK1JqVYTfzoB1FHnHZM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g07Mqq4QM0M1jkIzKR+e1hPWxsnIAMx35O4Yd/ozGYQCOqkcoiU6+YgJ9aZzcah3EpYIpkSJ+GR4vYrfoZHOk/kqgagzapozNNuDeDf1nnLDWYOZ1eGmecsVpsG63Vrla9wrNWEWajji4xOZuWICvCqq0q04u2dN4uweHaI6PBCNNCK9lW31OQKjWH2oF02LMIwSbDxAfzgZawqbB5ccLc+Rkfs2rUjJi7bit8UFi434cl0EhCXV3u1BaPeb9/kJ87qJLVpkXgUqQtSEHck4pLlmLIcRTWYx4HzLdKHCuuPmLMClMMgeVi/tDeg26Zwe/SWsy9KH/sC9HR1IGIqSGo73+NJYKDAAzd+Slw31hfEYd9nxtezUy/LCINvEIG6S5LsLav44SuN0S7ZllD4D1paMVUlNz4pj83/lV5+DDQQswfDG5DtuLnpgJsbbRzbVlr8+xbMthnu7oYbGPHW7jBU8JB9BqceLUB5STc2KsGiXyAqm+bUOH9+HJJrxyhTCURvXkIDYWPFR1ApqRiuZi3D00n3SxwmgnyzAnv1uns9uJ1FjykNrBiH0osesFQfmkqAgeURCysgVn55jPjwfEfWHDALFxomg= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 32a31267-82d1-455a-9d55-08dcf3a2c1e7 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2024 20:39:14.4229 (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: iMDX2IZYFu4d5iSGMtEyJYMFVSGDRUqKKt6b5qlYTdC87p6eBqOagXmrqDXQknb4h9W273BhoJEAV3zk6n+FYYX3mQjxVmzbYQS++7rwRdA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SJ0PR10MB5833 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-23_16,2024-10-23_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 malwarescore=0 spamscore=0 adultscore=0 suspectscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410230132 X-Proofpoint-ORIG-GUID: CBlrgsLu13UUVspl6ZZk8r7P3AeOqAD4 X-Proofpoint-GUID: CBlrgsLu13UUVspl6ZZk8r7P3AeOqAD4 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: B4B15A002D X-Stat-Signature: xq1y61hoaxw79q4wi8hjdhh3zen9i4a6 X-Rspam-User: X-HE-Tag: 1729715942-3724 X-HE-Meta: U2FsdGVkX1/nidb3BcdUpJB9QZh2TMb+B0ZHPoXBHMbVpjWyy3+R97qXDApjpM/SZSHyOdS6eWC2FnAPKuQnAPJh/QXJmYLFnq9pcunQSxTzLvinBz5amXMUgy1WgaeqoR2wolp8UWZq1KPdbMue7bYPaD2JZ9hLStCQKVTuSClHXDEriPz2ykHqk1UMIETEkyVj5sLGY3GjEzO7SD9JQbRiX6MFlsqCAzR2cjePt0/NIKrhNDJVPDUWoUoU56GEtpSvpXSRZjxk9dVpiFQ4PVvLxwu64p2LKpZJGhBEvG5ISFxsWCz/qFhne6V4cG9UEXHuncqFVbWm1GVXfW8H2WdU1JiYCcPonK7wWqemBxStFl7BN/Ot69EucvzVmoYMYfXSCrEKAtIDQexB/KR+8jOGpAA0ShEf+AbYUQ/qCqe9rt65yeeOZ42YJZ1xcm4UJQoEmphjAFFNwKN23WiUIf8/sPZwIElCKUwRB81+No3/bLT9XnV/PAxcwCMzACmTUm8oLhdKXSjrqmbZsjpRj+1rl49SldAVhdgsJ5Iu6M32gfEUmPpXkG4T4ByKU2vPuDQJbi40+QGjN6Cb0JL8ZNtP8Yo9sRfrnq7ppDdhG8gRvxkKh4jaE+asJBAo1zz4fc/XwIwW+aQ1P0LgbohtewZ3dj6Qen9EhR81na+EErz2YxAGJ+WVsOe+FBXRFL+bNQd9Lp8pRw2F9djZYi6SJt/mSzo4eev4jQj/99rFqr0Krrbj/bdFgQ+Wyn07dcC1dl4VbcvSxoBDp688M1M6KirO63sFsLqImhr15wCqNaHvP8Xf/gYMuVeVoM9I5qvjyfatA4kUR9MN8F11UFvGfbfmAzawmG8GH4pn19bajpWheDCAVqdOROwqnBsTdsSmKG1wrj5XB+95HGOBgMvf8rNs5oXsMr1UO+8KpLtmetbyJyrS/eQmjDjS8uGqJKbgpToCrfHf77lvUVf7u9Q sUqpApfF 7/vlgjpXhT6cozigs7sL3obQf/hWKU2DnU6O6zvytuniNEZng1wg7bwxdej08xzjx5h4rpxkp0WQj7aTOKYzX9KAZtkl2TsRCNtUTR1qwsSyMPtzun1c5nDqIfOr9z0phLJl4Y0VFeRXqUAvgtUpyPkMTTwgsFtbthdLznrbidn75aRM4Xh/0xx2HfEAeQvXEeMdlvRtDvOc/zIDXE8sJrHejVW2rIOiOxTlTkpoYi1qoUS0lW+GQA1APiPuXYi+piQyMmDr7yppjNCxtFMbmhU5AVsm0yPCy2Y0nY1MlvOsg3zx/9yUNTBxOxRRe54+FQSTWjo7wTbHcNB3Sp5jdTQ9lOv1/gkynj+NXOo0Vg379NDGK7uGQNCEZNhvvZpyetH9yD/JoD+b4B8A4kONTkAeprm/CikaLwUhUxdQd7fM4lbmTLXfYLlRX6N+pOtRA02HpCTjcWKMF88exjfOI+kmBFZBjaO5Utj6y9uUx+S2N1pBmanN5GC6RwSa9wIzig0mCMtxc/5YqC2ezs9S/rNKu44K8wwE8zZOF6YVKy7aGp1qKbDxWeoiJww== 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: We have seen bugs and resource leaks arise from the complexity of the __mmap_region() function. This, and the generally deeply fragile error handling logic and complexity which makes understanding the function difficult make it highly desirable to refactor it into something readable. Achieve this by separating the function into smaller logical parts which are easier to understand and follow, and which importantly very significantly simplify the error handling. Note that we now call vms_abort_munmap_vmas() in more error paths than we used to, however in cases where no abort need occur, vms->nr_pages will be equal to zero and we simply exit this function without doing more than we would have done previously. Importantly, the invocation of the driver mmap hook via mmap_file() now has very simple and obvious handling (this was previously the most problematic part of the mmap() operation). Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- mm/vma.c | 401 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 261 insertions(+), 140 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 0a2965be582d..065f5e1f65be 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -7,6 +7,40 @@ #include "vma_internal.h" #include "vma.h" +struct mmap_state { + struct mm_struct *mm; + struct vma_iterator *vmi; + + unsigned long addr; + unsigned long end; + pgoff_t pgoff; + unsigned long pglen; + unsigned long flags; + struct file *file; + + unsigned long charged; + + struct vm_area_struct *prev; + struct vm_area_struct *next; + + /* Unmapping state. */ + struct vma_munmap_struct vms; + struct ma_state mas_detach; + struct maple_tree mt_detach; +}; + +#define MMAP_STATE(name, mm_, vmi_, addr_, len_, pgoff_, flags_, file_) \ + struct mmap_state name = { \ + .mm = mm_, \ + .vmi = vmi_, \ + .addr = addr_, \ + .end = addr + len, \ + .pgoff = pgoff_, \ + .pglen = PHYS_PFN(len_), \ + .flags = flags_, \ + .file = file_, \ + } + static inline bool is_mergeable_vma(struct vma_merge_struct *vmg, bool merge_next) { struct vm_area_struct *vma = merge_next ? vmg->next : vmg->prev; @@ -2169,188 +2203,259 @@ static void vms_abort_munmap_vmas(struct vma_munmap_struct *vms, vms_complete_munmap_vmas(vms, mas_detach); } -unsigned long __mmap_region(struct file *file, unsigned long addr, - unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, - struct list_head *uf) +/* + * __mmap_prepare() - Prepare to gather any overlapping VMAs that need to be + * unmapped once the map operation is completed, check limits, account mapping + * and clean up any pre-existing VMAs. + * + * @map: Mapping state. + * @vmg: VMA merge state. + * @uf: Userfaultfd context list. + * + * Returns: 0 on success, error code otherwise. + */ +static int __mmap_prepare(struct mmap_state *map, struct vma_merge_struct *vmg, + struct list_head *uf) { - struct mm_struct *mm = current->mm; - struct vm_area_struct *vma = NULL; - pgoff_t pglen = PHYS_PFN(len); - unsigned long charged = 0; - struct vma_munmap_struct vms; - struct ma_state mas_detach; - struct maple_tree mt_detach; - unsigned long end = addr + len; int error; - VMA_ITERATOR(vmi, mm, addr); - VMG_STATE(vmg, mm, &vmi, addr, end, vm_flags, pgoff); - - vmg.file = file; - /* Find the first overlapping VMA */ - vma = vma_find(&vmi, end); - init_vma_munmap(&vms, &vmi, vma, addr, end, uf, /* unlock = */ false); - if (vma) { - mt_init_flags(&mt_detach, vmi.mas.tree->ma_flags & MT_FLAGS_LOCK_MASK); - mt_on_stack(mt_detach); - mas_init(&mas_detach, &mt_detach, /* addr = */ 0); + struct vma_iterator *vmi = map->vmi; + struct vma_munmap_struct *vms = &map->vms; + + /* Find the first overlapping VMA and initialise unmap state. */ + vms->vma = vma_find(vmi, map->end); + init_vma_munmap(vms, vmi, vms->vma, map->addr, map->end, uf, + /* unlock = */ false); + + /* OK, we have overlapping VMAs - prepare to unmap them. */ + if (vms->vma) { + mt_init_flags(&map->mt_detach, + vmi->mas.tree->ma_flags & MT_FLAGS_LOCK_MASK); + mt_on_stack(map->mt_detach); + mas_init(&map->mas_detach, &map->mt_detach, /* addr = */ 0); /* Prepare to unmap any existing mapping in the area */ - error = vms_gather_munmap_vmas(&vms, &mas_detach); - if (error) - goto gather_failed; + error = vms_gather_munmap_vmas(vms, &map->mas_detach); + if (error) { + /* On error VMAs will already have been reattached. */ + vms->nr_pages = 0; + return error; + } - vmg.next = vms.next; - vmg.prev = vms.prev; - vma = NULL; + map->next = vms->next; + map->prev = vms->prev; } else { - vmg.next = vma_iter_next_rewind(&vmi, &vmg.prev); + map->next = vma_iter_next_rewind(vmi, &map->prev); } + /* Set up vmg for merge attempt. */ + vmg->file = map->file; + vmg->prev = map->prev; + vmg->next = map->next; + /* Check against address space limit. */ - if (!may_expand_vm(mm, vm_flags, pglen - vms.nr_pages)) { - error = -ENOMEM; - goto abort_munmap; - } + if (!may_expand_vm(map->mm, map->flags, map->pglen - vms->nr_pages)) + return -ENOMEM; - /* - * Private writable mapping: check memory availability - */ - if (accountable_mapping(file, vm_flags)) { - charged = pglen; - charged -= vms.nr_accounted; - if (charged) { - error = security_vm_enough_memory_mm(mm, charged); + /* Private writable mapping: check memory availability. */ + if (accountable_mapping(map->file, map->flags)) { + map->charged = map->pglen; + map->charged -= vms->nr_accounted; + if (map->charged) { + error = security_vm_enough_memory_mm(map->mm, map->charged); if (error) - goto abort_munmap; + return error; } - vms.nr_accounted = 0; - vm_flags |= VM_ACCOUNT; - vmg.flags = vm_flags; + vms->nr_accounted = 0; + map->flags |= VM_ACCOUNT; } /* - * clear PTEs while the vma is still in the tree so that rmap + * Clear PTEs while the vma is still in the tree so that rmap * cannot race with the freeing later in the truncate scenario. * This is also needed for mmap_file(), which is why vm_ops * close function is called. */ - vms_clean_up_area(&vms, &mas_detach); - vma = vma_merge_new_range(&vmg); - if (vma) - goto expanded; + vms_clean_up_area(vms, &map->mas_detach); + + return 0; +} + +static int __mmap_new_file_vma(struct mmap_state *map, + struct vma_merge_struct *vmg, + struct vm_area_struct **vmap, bool *mergedp) +{ + struct vma_iterator *vmi = map->vmi; + struct vm_area_struct *vma = *vmap; + int error; + + vma->vm_file = get_file(map->file); + error = mmap_file(vma->vm_file, vma); + if (error) { + fput(vma->vm_file); + vma->vm_file = NULL; + + vma_iter_set(vmi, vma->vm_end); + /* Undo any partial mapping done by a device driver. */ + unmap_region(&vmi->mas, vma, map->prev, map->next); + + return error; + } + + /* Drivers cannot alter the address of the VMA. */ + WARN_ON_ONCE(map->addr != vma->vm_start); + /* + * Drivers should not permit writability when previously it was + * disallowed. + */ + VM_WARN_ON_ONCE(map->flags != vma->vm_flags && + !(map->flags & VM_MAYWRITE) && + (vma->vm_flags & VM_MAYWRITE)); + + vma_iter_config(vmi, map->addr, map->end); + /* + * If flags changed after mmap_file(), we should try merge + * vma again as we may succeed this time. + */ + if (unlikely(map->flags != vma->vm_flags && map->prev)) { + struct vm_area_struct *merge; + + vmg->flags = vma->vm_flags; + /* If this fails, state is reset ready for a reattempt. */ + merge = vma_merge_new_range(vmg); + + if (merge) { + /* + * ->mmap() can change vma->vm_file and fput + * the original file. So fput the vma->vm_file + * here or we would add an extra fput for file + * and cause general protection fault + * ultimately. + */ + fput(vma->vm_file); + vm_area_free(vma); + vma = merge; + *mergedp = true; + } else { + vma_iter_config(vmi, map->addr, map->end); + } + } + + map->flags = vma->vm_flags; + *vmap = vma; + return 0; +} + +/* + * __mmap_new_vma() - Allocate a new VMA for the region, as merging was not + * possible. + * + * An exception to this is if the mapping is file-backed, and the underlying + * driver changes the VMA flags, permitting a subsequent merge of the VMA, in + * which case the returned VMA is one that was merged on a second attempt. + * + * @map: Mapping state. + * @vmg: VMA merge state. + * @vmap: Output pointer for the new VMA. + * + * Returns: Zero on success, or an error. + */ +static int __mmap_new_vma(struct mmap_state *map, struct vma_merge_struct *vmg, + struct vm_area_struct **vmap) +{ + struct vma_iterator *vmi = map->vmi; + int error = 0; + bool merged = false; + struct vm_area_struct *vma; + /* * Determine the object being mapped and call the appropriate * specific mapper. the address has already been validated, but * not unmapped, but the maps are removed from the list. */ - vma = vm_area_alloc(mm); - if (!vma) { - error = -ENOMEM; - goto unacct_error; - } + vma = vm_area_alloc(map->mm); + if (!vma) + return -ENOMEM; - vma_iter_config(&vmi, addr, end); - vma_set_range(vma, addr, end, pgoff); - vm_flags_init(vma, vm_flags); - vma->vm_page_prot = vm_get_page_prot(vm_flags); + vma_iter_config(vmi, map->addr, map->end); + vma_set_range(vma, map->addr, map->end, map->pgoff); + vm_flags_init(vma, map->flags); + vma->vm_page_prot = vm_get_page_prot(map->flags); - if (vma_iter_prealloc(&vmi, vma)) { + if (vma_iter_prealloc(vmi, vma)) { error = -ENOMEM; goto free_vma; } - if (file) { - vma->vm_file = get_file(file); - error = mmap_file(file, vma); - if (error) - goto unmap_and_free_file_vma; - - /* Drivers cannot alter the address of the VMA. */ - WARN_ON_ONCE(addr != vma->vm_start); - /* - * Drivers should not permit writability when previously it was - * disallowed. - */ - VM_WARN_ON_ONCE(vm_flags != vma->vm_flags && - !(vm_flags & VM_MAYWRITE) && - (vma->vm_flags & VM_MAYWRITE)); - - vma_iter_config(&vmi, addr, end); - /* - * If vm_flags changed after mmap_file(), we should try merge - * vma again as we may succeed this time. - */ - if (unlikely(vm_flags != vma->vm_flags && vmg.prev)) { - struct vm_area_struct *merge; - - vmg.flags = vma->vm_flags; - /* If this fails, state is reset ready for a reattempt. */ - merge = vma_merge_new_range(&vmg); - - if (merge) { - /* - * ->mmap() can change vma->vm_file and fput - * the original file. So fput the vma->vm_file - * here or we would add an extra fput for file - * and cause general protection fault - * ultimately. - */ - fput(vma->vm_file); - vm_area_free(vma); - vma = merge; - /* Update vm_flags to pick up the change. */ - vm_flags = vma->vm_flags; - goto file_expanded; - } - vma_iter_config(&vmi, addr, end); - } - - vm_flags = vma->vm_flags; - } else if (vm_flags & VM_SHARED) { + if (map->file) + error = __mmap_new_file_vma(map, vmg, &vma, &merged); + else if (map->flags & VM_SHARED) error = shmem_zero_setup(vma); - if (error) - goto free_iter_vma; - } else { + else vma_set_anonymous(vma); - } + + if (error) + goto free_iter_vma; + + if (merged) + goto file_expanded; #ifdef CONFIG_SPARC64 /* TODO: Fix SPARC ADI! */ - WARN_ON_ONCE(!arch_validate_flags(vm_flags)); + WARN_ON_ONCE(!arch_validate_flags(map->flags)); #endif /* Lock the VMA since it is modified after insertion into VMA tree */ vma_start_write(vma); - vma_iter_store(&vmi, vma); - mm->map_count++; + vma_iter_store(vmi, vma); + map->mm->map_count++; vma_link_file(vma); /* * vma_merge_new_range() calls khugepaged_enter_vma() too, the below * call covers the non-merge case. */ - khugepaged_enter_vma(vma, vma->vm_flags); + khugepaged_enter_vma(vma, map->flags); file_expanded: - file = vma->vm_file; ksm_add_vma(vma); -expanded: + *vmap = vma; + return 0; + +free_iter_vma: + vma_iter_free(vmi); +free_vma: + vm_area_free(vma); + return error; +} + +/* + * __mmap_complete() - Unmap any VMAs we overlap, account memory mapping + * statistics, handle locking and finalise the VMA. + * + * @map: Mapping state. + * @vma: Merged or newly allocated VMA for the mmap()'d region. + */ +static void __mmap_complete(struct mmap_state *map, struct vm_area_struct *vma) +{ + struct mm_struct *mm = map->mm; + unsigned long vm_flags = vma->vm_flags; + perf_event_mmap(vma); - /* Unmap any existing mapping in the area */ - vms_complete_munmap_vmas(&vms, &mas_detach); + /* Unmap any existing mapping in the area. */ + vms_complete_munmap_vmas(&map->vms, &map->mas_detach); - vm_stat_account(mm, vm_flags, pglen); + vm_stat_account(mm, vma->vm_flags, map->pglen); if (vm_flags & VM_LOCKED) { if ((vm_flags & VM_SPECIAL) || vma_is_dax(vma) || is_vm_hugetlb_page(vma) || - vma == get_gate_vma(current->mm)) + vma == get_gate_vma(mm)) vm_flags_clear(vma, VM_LOCKED_MASK); else - mm->locked_vm += pglen; + mm->locked_vm += map->pglen; } - if (file) + if (vma->vm_file) uprobe_mmap(vma); /* @@ -2363,26 +2468,42 @@ unsigned long __mmap_region(struct file *file, unsigned long addr, vm_flags_set(vma, VM_SOFTDIRTY); vma_set_page_prot(vma); +} - return addr; +unsigned long __mmap_region(struct file *file, unsigned long addr, + unsigned long len, vm_flags_t vm_flags, unsigned long pgoff, + struct list_head *uf) +{ + struct mm_struct *mm = current->mm; + struct vm_area_struct *vma; + int error; + VMA_ITERATOR(vmi, mm, addr); + VMG_STATE(vmg, mm, &vmi, addr, addr + len, vm_flags, pgoff); + MMAP_STATE(map, mm, &vmi, addr, len, pgoff, vm_flags, file); -unmap_and_free_file_vma: - fput(vma->vm_file); - vma->vm_file = NULL; + error = __mmap_prepare(&map, &vmg, uf); + if (error) + goto abort_munmap; - vma_iter_set(&vmi, vma->vm_end); - /* Undo any partial mapping done by a device driver. */ - unmap_region(&vmi.mas, vma, vmg.prev, vmg.next); -free_iter_vma: - vma_iter_free(&vmi); -free_vma: - vm_area_free(vma); -unacct_error: - if (charged) - vm_unacct_memory(charged); + /* Attempt to merge with adjacent VMAs... */ + vmg.flags = map.flags; + vma = vma_merge_new_range(&vmg); + if (!vma) { + /* ...but if we can't, allocate a new VMA. */ + error = __mmap_new_vma(&map, &vmg, &vma); + if (error) + goto unacct_error; + } + + __mmap_complete(&map, vma); + return addr; + + /* Accounting was done by __mmap_prepare(). */ +unacct_error: + if (map.charged) + vm_unacct_memory(map.charged); abort_munmap: - vms_abort_munmap_vmas(&vms, &mas_detach); -gather_failed: + vms_abort_munmap_vmas(&map.vms, &map.mas_detach); return error; } From patchwork Wed Oct 23 20:38:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13847900 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 D46F7CFA46A for ; Wed, 23 Oct 2024 20:39:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 67A606B00B5; Wed, 23 Oct 2024 16:39:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 62AEC6B00B6; Wed, 23 Oct 2024 16:39:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 40A386B00B7; Wed, 23 Oct 2024 16:39:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 122A46B00B5 for ; Wed, 23 Oct 2024 16:39:28 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 32FFB140ED6 for ; Wed, 23 Oct 2024 20:39:09 +0000 (UTC) X-FDA: 82706031744.06.E0A7265 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf19.hostedemail.com (Postfix) with ESMTP id 8D50B1A001D for ; Wed, 23 Oct 2024 20:39:02 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=KNSMlhMS; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=GFqBd5jp; spf=pass (imf19.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729715887; a=rsa-sha256; cv=pass; b=C2VwhLrVMSOeLb2OwR/Ve7J2ljxA4bI6/6NEALLv66TaXDVm74FqkON8W4s+gl++imlgFv QbWls2XHRmub1sJIa23esfNo5ZaAgMP1q4WbDFvj2DcPPpSIVWcuCfmOmyZi0f80Uh1J/V xNq/U+Nsors0hL+/OjaLDiDviaRZt8M= ARC-Authentication-Results: i=2; imf19.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=KNSMlhMS; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=GFqBd5jp; spf=pass (imf19.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1729715887; 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=GwbeFR97uKuCzPgrgBwD5NPAUJTeqMBP0i3dribbKhQ=; b=A7YmMChksH1zCBD7YnKUdG6Svb3uV91MIKm37htlZHd0XB4qvgI0dHN36LhFZ4ahwVlDNV 891egEE1njqLIyVh3sw22ooUm1ecasjiSLDi8BC3z+0eeon6JK9P4n1a6ezQkjIBCA98yH Zw5c2hlMfEjH5IUTU+quEfGmdWdMdxc= 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 49NKcaOe010483; Wed, 23 Oct 2024 20:39:22 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s= corp-2023-11-20; bh=GwbeFR97uKuCzPgrgBwD5NPAUJTeqMBP0i3dribbKhQ=; b= KNSMlhMSEWAYRqXQBGhaC/RZY5VJ9JQ5PdotPIm4QDqnrk0Wr6cE13dPhNGH7GYl QhfBh953PDn1TJjkheoNQNhBqRIaOJGUERv+UOZ7JXwzeVawAI4ODpVaVgBlxueU +Kwp3D1k45FbAYdYMkL3uyfq0Li7TYVJRgura9o2BpjMIXd0BitvQQK68+dTTJ+S 0Q07fphzlBQoGyxw1i+GjWh9LAyTwKNzPZKWhk+iTRaGEQNdyjSvdSw/Evvmr/6B r0Xj3slVU3gGSfCPNqY5PcxQp2nJ+FzZznqjq5EUICRbeZg7lHEiiYAwTTZ3PImD XzK//tegIRHxzYDJSOR0HA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 42cqv3g8wg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:39:22 +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 49NJJHjq027526; Wed, 23 Oct 2024 20:39:21 GMT Received: from nam12-mw2-obe.outbound.protection.outlook.com (mail-mw2nam12lp2046.outbound.protection.outlook.com [104.47.66.46]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 42emh3bkfu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 23 Oct 2024 20:39:21 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=whSU4dnrtKXW4Rz5+pNN4L6xbV7w81YPF49v9gWPI4TqCMCXeYQpnH+ZT48Fu4TJI7HfG594cd/XQnaMxRwhdq9r974MfXuSTCHJbGJCVcjgNs0aibb1+FOKLVIoGUa54Pp9QJp3bJ//OxL/MfvhAziO+gCKDbK6vfVyGUlf2RmonmGHWq99WB1Z+jCPGrB8vV+gOKxnK6CygnDQH4tUB7HwxQ0A1TMKoxQljfBRptI+xtnf+wwRZYi3uVjVvG/Evg8xyOdrW9OUy1sYtXERFREEUWNvzJF0u3MgDE9KzILm+GFugFYyHDzp7SOlm+I0eQ6facjQeyM2TR4idz9XRQ== 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=GwbeFR97uKuCzPgrgBwD5NPAUJTeqMBP0i3dribbKhQ=; b=qUk8ZtarKbE7li9ykmqO8A6C0WWZZb1OodbTRlpYapon0MS+np31RXqnLm6oMVX+aKwTt8g8NmOMs+edMESbqEoqco+dtmlxFa6hSTpDkd7lKFhbWgScqcLjmWeFjxhHlAyCpfZM4WWL80xKame91af1JKcyUvBreTISe3h/dcgZwLh6DBEpWFb04NjgYFNmD9u8goyiA36HoIaWFpYeouMvK4VwLzxZsHvHuDk0xDEWWxPP15E2BL41N5GQSY+eVlXK4ff2caYI8NbOgk97dJTwqZKBqOnoYHbkgTv57r3juNQ9IrQjg+H3EMzBit0bY4RvVmHK+TFey1yiDZE98w== 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=GwbeFR97uKuCzPgrgBwD5NPAUJTeqMBP0i3dribbKhQ=; b=GFqBd5jpj9muymT+SWrnW+fj8ApLyGzO2JEvYT0O2zxJP1n2rQHk7aw1jiJWY8/F6oGqdzn7/Jo2XOsDqu0S+qTyMsBtkN5+RWhTHFZIUDiK7Id0m1rXtlVO9aEkkDjT/H+g4s4u+4yqrugLh9jdL7yFXx9aWmbbKsmJ+dvrwZU= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by PH8PR10MB6338.namprd10.prod.outlook.com (2603:10b6:510:1cd::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.20; Wed, 23 Oct 2024 20:39:18 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%6]) with mapi id 15.20.8069.024; Wed, 23 Oct 2024 20:39:18 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: "Liam R . Howlett" , Vlastimil Babka , Jann Horn , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Linus Torvalds , Peter Xu Subject: [PATCH v2 8/8] mm: defer second attempt at merge on mmap() Date: Wed, 23 Oct 2024 21:38:33 +0100 Message-ID: X-Mailer: git-send-email 2.47.0 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0269.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a1::17) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|PH8PR10MB6338:EE_ X-MS-Office365-Filtering-Correlation-Id: c715a4b6-e8fd-4d7a-d582-08dcf3a2c438 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|10070799003|366016; X-Microsoft-Antispam-Message-Info: uYFLPUMO3sryJ9098QEuykuHJR3SNKI7C8dbadX4jtZRmPQSEHBRNkViU2uH+xfI0jh92l29jdtP/8sPeSWva0AdMKhlu1cshrwqBY6vDtUy3FSsjVWbidP0fIx+syhjPfVRPwyUHZZK0L8usmIw9PKv3TlHV4ULPGh7UqmhSOB2eENiZ6HhqYV3ttwZnuNr5i9B84OkjVuxSCcZQm1u5jjSqvNAjIK6ZO0g6uxfVAfFXdqQRbGXQJohvYMuqwBKDHsy6QGJoT2Dgy27A6Zfp7HQOlpktsPVzZKUdMn0qtEEOWYIGAlQXEyN+oJ+jD8kS0ThiQw16MiJ2IFl4TDDZFIUbCdzu0IHCrVLR6dk2/3YxdmbaH6xJ9sjabgfwIctEy1mn7lfOXnpk/m85RRz9lwrK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xq7N806RzhHJfJ2ju0Yof1pKpHn6eZKqrKSkEkO4eubLNU4mwm2/zW9jmnuz07z6SzRggyPrSE9ruCdrwAPn5AJxgo7rSzYZ9v5VrfjQ6yd+D1prsEUIBQRSWNUMavkh1jgvGbhC+C20jBYlDfqxGkG7ZF3q5C9rzCWcRuBrzxXbRbQwWqrElwmMLbnlitJitLLfqF72I3YPhL5NYRIVw6aXAe5a6YmeJLoa5TmSP9h9zG18NDp/GMi3zqlOUS5KY8IbbyrLBxAF7SXv2IMJW7cCQcXa/1kFaev+Tx1PCKFUTFJBqBI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c715a4b6-e8fd-4d7a-d582-08dcf3a2c438 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Oct 2024 20:39:18.4376 (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: BYrbbkG9MvNzsE2Cb/JXOvn1JSwB+cUlAVQgFNseqOxZCJdpLohFtbAsuvU1qLONmnNQwVRjE1q+4wbIkBlALtZeXFs63VbBcimZeAwQcYc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR10MB6338 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-23_16,2024-10-23_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=0 phishscore=0 malwarescore=0 adultscore=0 mlxscore=0 mlxlogscore=999 spamscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410230132 X-Proofpoint-ORIG-GUID: YzzipgxMoHitkMQ4xa8d9FIDOn6-IItv X-Proofpoint-GUID: YzzipgxMoHitkMQ4xa8d9FIDOn6-IItv X-Stat-Signature: d7rpyq5ihza4bmqi54586pg81xa4gmwx X-Rspamd-Queue-Id: 8D50B1A001D X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1729715942-542837 X-HE-Meta: U2FsdGVkX1931JmbrmW5T9HVHP2qBqvvCyatUm+BjYQBRNX91OuWpnSgBQ3zBWpPMA85yN1Zi/i9MbVDP9hh0l81Enu03AmUsoUwV8BpHWXNhowUR+3DqYLtFOMO1pwhV6dS8zynvzzh3qiCO4486GGuAT3oLOJ3gvuwDZ35qNUJTAuXuf53ONNtXw+reFE3k8VuKsXykOJFR1U1qqGGXS/w/I4MTUmSgOZNj/9xtKFgFCRdFTrgpIBuTxBW/B1JCWLMB+zHMwYkTnesZU0K4HtCjiS2tdW2tyQTrgacUAmiZU48Zt1rsijzp9fHWEkSnJ7p6wkMr7FFwnpMOHXeClRLpGAL1buk9FOHo/nQ6LVCH/vDYvhvIKgUTlLJeXk3B4yTRVAoGSPYy50BREuXRByITrFcw/CgcmW96cfVDfMxZ2OLqlqgB33JOdFkfUFp8Sft2fSbxflGG+TB52IjH7fuEKMKYQ8gCN8Dzo0xXhQ3yAx5likpDXGLtMKdBCMso/lnwZIYEBLiOAY96SwfZZeguzgK5Ex4aFLsCdGmtkzvBmsdCiUghYRJk4wEpUhN9+qJCqq0nqNRjk+qV5DI1rMw9Aj0h6iGKlV7gK2PXP7DF0yydWvXqRzc3hnL1A3D5xLEdOwSamn85gx2VevbwO3CbPSrGqAhedez/3XFjdrOu/CMUEZsGInfS02obApghJENkW3EQNMpEuBXhRAa762p4kg9fChlaziQ6NspY2yXzLtXNQB9IP8J4gcOUmRQiqohDzblPD1Tg0K892DNeQl051MHWsclcznUEzflRVLYPLdLp+LqHvYAoZ3GB/Ti2EuNx3GVzPXb1B6D9jrb9hHC2Iss2oXizUCFxJvqahDE8ezr4i9f8Efg3+clhM9rnaJm25BaFezeji7/M853CPYyomTrHKUWYl0uJiULEqfI9UptElcCOUgah65hqlAbYFiCiK5/42oiJ9ibWrh 55saOior YOxs2Va2v7MPHgBom5TERPjrmMyTClrkF8POxnrNOx0xd4EYZFoY21Axiqk0dsHfHkaoRD4AONynph6GQBrnObbS9hRsKK+L2MSiYjZ1YkQYeRMfVOIgPM6tVF41H8E20B5/bCfsPLg+9z58y7/xoigzF5MQVP7HmnWk8b5j+B2G/4ZSTo3uzvmgmYAVsJr0Dh8ZUWDcJRVMUtMqFq3JWhkBKjsaQJbqFqBu8FilbipBuyKdXPvelL+EMcjnLRH4LEH4gUWhUtDk/L6CgrAVGQaFD95HXzRnZiPEw80nkol7CoV9Hvi5YwHWIKMJZg42P0XSo4do+si7NUUVjAOr2T3H+VGCP4D0GcSVfWeqcJfJGgqFn7PRFgKDMQYMWqQ2Gq1odJ5V72/MlRL/QS9oMlFTeZVvE0naCRd7Tv3b5wBXorWtn98ppBcbL+6GInwL7pHT81m1y7XZzf3u+5/0/HwUH0ylCn5ApLNZdKu1YExW7iL39quANaAjbaSs/X7iQOAidkpS6Lu2DirE= 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: Rather than trying to merge again when ostensibly allocating a new VMA, instead defer until the VMA is added and attempt to merge the existing range. This way we have no complicated unwinding logic midway through the process of mapping the VMA. In addition this removes limitations on the VMA not being able to be the first in the virtual memory address space which was previously implicitly required. It also performs this merge after the final flag adjustments are performed, something that was not done previously and thus might have prevented possibly valid merges in the past. In theory, for this very same reason, we should unconditionally attempt merge here, however this is likely to have a performance impact so it is better to avoid this given the unlikely outcome of a merge. The vmg state will already have been reset by the first attempt at a merge so we only need to reset the iterator, set the vma and flags and try again. Signed-off-by: Lorenzo Stoakes Reviewed-by: Vlastimil Babka --- mm/vma.c | 75 ++++++++++++++++++++------------------------------------ 1 file changed, 26 insertions(+), 49 deletions(-) diff --git a/mm/vma.c b/mm/vma.c index 065f5e1f65be..c493ecebf394 100644 --- a/mm/vma.c +++ b/mm/vma.c @@ -19,6 +19,7 @@ struct mmap_state { struct file *file; unsigned long charged; + bool retry_merge; struct vm_area_struct *prev; struct vm_area_struct *next; @@ -2280,9 +2281,9 @@ static int __mmap_prepare(struct mmap_state *map, struct vma_merge_struct *vmg, return 0; } + static int __mmap_new_file_vma(struct mmap_state *map, - struct vma_merge_struct *vmg, - struct vm_area_struct **vmap, bool *mergedp) + struct vm_area_struct **vmap) { struct vma_iterator *vmi = map->vmi; struct vm_area_struct *vma = *vmap; @@ -2311,37 +2312,11 @@ static int __mmap_new_file_vma(struct mmap_state *map, !(map->flags & VM_MAYWRITE) && (vma->vm_flags & VM_MAYWRITE)); - vma_iter_config(vmi, map->addr, map->end); - /* - * If flags changed after mmap_file(), we should try merge - * vma again as we may succeed this time. - */ - if (unlikely(map->flags != vma->vm_flags && map->prev)) { - struct vm_area_struct *merge; - - vmg->flags = vma->vm_flags; - /* If this fails, state is reset ready for a reattempt. */ - merge = vma_merge_new_range(vmg); - - if (merge) { - /* - * ->mmap() can change vma->vm_file and fput - * the original file. So fput the vma->vm_file - * here or we would add an extra fput for file - * and cause general protection fault - * ultimately. - */ - fput(vma->vm_file); - vm_area_free(vma); - vma = merge; - *mergedp = true; - } else { - vma_iter_config(vmi, map->addr, map->end); - } - } + /* If the flags change (and are mergeable), let's retry later. */ + map->retry_merge = vma->vm_flags != map->flags && !(vma->vm_flags & VM_SPECIAL); + vma_iter_config(vmi, map->addr, map->end); map->flags = vma->vm_flags; - *vmap = vma; return 0; } @@ -2349,22 +2324,15 @@ static int __mmap_new_file_vma(struct mmap_state *map, * __mmap_new_vma() - Allocate a new VMA for the region, as merging was not * possible. * - * An exception to this is if the mapping is file-backed, and the underlying - * driver changes the VMA flags, permitting a subsequent merge of the VMA, in - * which case the returned VMA is one that was merged on a second attempt. - * * @map: Mapping state. - * @vmg: VMA merge state. * @vmap: Output pointer for the new VMA. * * Returns: Zero on success, or an error. */ -static int __mmap_new_vma(struct mmap_state *map, struct vma_merge_struct *vmg, - struct vm_area_struct **vmap) +static int __mmap_new_vma(struct mmap_state *map, struct vm_area_struct **vmap) { struct vma_iterator *vmi = map->vmi; int error = 0; - bool merged = false; struct vm_area_struct *vma; /* @@ -2387,7 +2355,7 @@ static int __mmap_new_vma(struct mmap_state *map, struct vma_merge_struct *vmg, } if (map->file) - error = __mmap_new_file_vma(map, vmg, &vma, &merged); + error = __mmap_new_file_vma(map, &vma); else if (map->flags & VM_SHARED) error = shmem_zero_setup(vma); else @@ -2396,9 +2364,6 @@ static int __mmap_new_vma(struct mmap_state *map, struct vma_merge_struct *vmg, if (error) goto free_iter_vma; - if (merged) - goto file_expanded; - #ifdef CONFIG_SPARC64 /* TODO: Fix SPARC ADI! */ WARN_ON_ONCE(!arch_validate_flags(map->flags)); @@ -2415,8 +2380,6 @@ static int __mmap_new_vma(struct mmap_state *map, struct vma_merge_struct *vmg, * call covers the non-merge case. */ khugepaged_enter_vma(vma, map->flags); - -file_expanded: ksm_add_vma(vma); *vmap = vma; return 0; @@ -2430,13 +2393,17 @@ static int __mmap_new_vma(struct mmap_state *map, struct vma_merge_struct *vmg, /* * __mmap_complete() - Unmap any VMAs we overlap, account memory mapping - * statistics, handle locking and finalise the VMA. + * statistics, handle locking and finalise the VMA, + * attempt a final merge if required. * * @map: Mapping state. * @vma: Merged or newly allocated VMA for the mmap()'d region. + * @vmg: VMA merge state. */ -static void __mmap_complete(struct mmap_state *map, struct vm_area_struct *vma) +static void __mmap_complete(struct mmap_state *map, struct vm_area_struct *vma, + struct vma_merge_struct *vmg) { + struct mm_struct *mm = map->mm; unsigned long vm_flags = vma->vm_flags; @@ -2468,6 +2435,16 @@ static void __mmap_complete(struct mmap_state *map, struct vm_area_struct *vma) vm_flags_set(vma, VM_SOFTDIRTY); vma_set_page_prot(vma); + + /* OK VMA flags changed in __mmap_new_vma(), try a merge again. */ + if (map->retry_merge) { + vma_iter_config(map->vmi, map->addr, map->end); + vmg->vma = vma; + vmg->flags = map->flags; + vmg->next = NULL; /* Must be set by merge logic. */ + + vma_merge_existing_range(vmg); + } } unsigned long __mmap_region(struct file *file, unsigned long addr, @@ -2490,12 +2467,12 @@ unsigned long __mmap_region(struct file *file, unsigned long addr, vma = vma_merge_new_range(&vmg); if (!vma) { /* ...but if we can't, allocate a new VMA. */ - error = __mmap_new_vma(&map, &vmg, &vma); + error = __mmap_new_vma(&map, &vma); if (error) goto unacct_error; } - __mmap_complete(&map, vma); + __mmap_complete(&map, vma, &vmg); return addr;