From patchwork Tue Oct 15 17:56:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13836809 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 A449DD1D88F for ; Tue, 15 Oct 2024 17:56:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 384EF6B00A1; Tue, 15 Oct 2024 13:56:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 30E016B00A2; Tue, 15 Oct 2024 13:56:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 139846B00A3; Tue, 15 Oct 2024 13:56:34 -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 DFBA16B00A1 for ; Tue, 15 Oct 2024 13:56:33 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id BC17DC07C4 for ; Tue, 15 Oct 2024 17:56:23 +0000 (UTC) X-FDA: 82676591340.18.509B434 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf25.hostedemail.com (Postfix) with ESMTP id DE6D6A0006 for ; Tue, 15 Oct 2024 17:56:24 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=McVIJNPr; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="BqYIDNc/"; spf=pass (imf25.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=1729014917; 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=Yugvb4V1/DaU9YPaXiZJXwYIK8KD9dleMPpB9SJ6Hp8=; b=63sA44sRXi0oupslTyZWVffZ8VJ9906uicQXcOR19Uoe9K+8ZMk9zcJgzKNZGABdCvrBU2 a4X/HAseBOYCEC6JZW6K9D6lWQEnEqUhHjNLAhQou3zAKVVflObgd4yv2sKDuh3IjwW4T9 fBS1gDDveC2Gf+hRVDi450wR7XE3b5E= ARC-Authentication-Results: i=2; imf25.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=McVIJNPr; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="BqYIDNc/"; spf=pass (imf25.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=1729014917; a=rsa-sha256; cv=pass; b=1ylRtDJm2EB+B3eh/Xu3Tl6KueH1QoEUVBggA6tpKkhd63XMXrR/Bm2oIE8fniiKBtxn+t HAECmLDXl32oj1UqpPgkeBN5n/X7RxrnCBSqA6QTIlkeP6qYTJM2gG2kinDPWAaT+LUNr8 9uuwuZX+gYr98NECk1fuPq4vUR83yFI= 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 49FHtdmo011659; Tue, 15 Oct 2024 17:56:24 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=Yugvb4V1/DaU9YPaXiZJXwYIK8KD9dleMPpB9SJ6Hp8=; b= McVIJNPrsacFgsRNFbiZEW5PheaABDt/ncGhNxnG5K5s5rX6xmJ1cPuxqJWKHqpV S6hvTN4XrxlGsZmZEzuUWtuL40H/N/RhK0AJgWJ9+8rm57jega9Cz3qT32rRDiiV qIafudG6Mdh6FYURL1JMZ/8539gYhYVKT4+fdHVdOCk/TrI92j/k637s1rulYW0F AA8hZsnTInR4x9auk+2HmcdL1WaO5pRYkqq7VTp5OjNGx+KcZTUyDqK0x7Hk6hYc Ges66A7KpKJgIJR+Mgyk1VCluTAECzYZrnSEuu4x+BbwTKv2BDrfE4+d0NZTi4bR vBAr8xUE0y6ei/t1laG7kg== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 427gqt1s10-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Oct 2024 17:56:23 +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 49FH4Uno026283; Tue, 15 Oct 2024 17:56:22 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2046.outbound.protection.outlook.com [104.47.70.46]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 427fj7swjg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Oct 2024 17:56:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=E56YhpGPsn/OMck1MrUZlutbg5olQwQc2X6hpMLREi5HDNVRZ5aUxu8fI7rSVbfyp7EAYmXv8qEcLlmzfaVTH0xJKj63bEfODwQa0PYiG8+Bj5izQo/GRc1igN/i4moCrQ3G5CL5metdokADYeBIgOw0+Q05Smkm2RazYjFFTn203M/fJXUNYNmnfz9Am0M40BSdfcwayVsyuIAY9ys5sMbgodFc9Vsjl4mutXqpbwWkOJHfyop13DCK084xsYhEJOD/6xwYPYkqjO23UC+hPI/pmi0sHm6q7SKpKPxMNEiEiUNooUR+S1i90rBmSoNa9py3LSud5Pjl1ZYGTJIQAQ== 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=Yugvb4V1/DaU9YPaXiZJXwYIK8KD9dleMPpB9SJ6Hp8=; b=CkvtTRI/d8Bg4ahTWbkKTFNESQH+AA0T05d9C5poCqX5mzlCZvjMETW5fB95g8CSiNYdS+B6GXx9Pd2jyeFtHh+Atkaep2qJPO+U69bluSWgSg/h8ObbINfAa9o8uSWFOnvGmiCIh/LJC+xscxdYRRhncjq/d8mAlbzCTKEgAOaOauGX7sV3F02hkYcrnGhcXYYof9A8CTuLsdlWMNpBGC1Y/0yVSGyCaAT2cXgHN0o+ZHUYpPtST2PnCaYYZ4Ta1p8fNnweC+tOJRMd8Ufa+boMTujp5uCNIxanGGHMzJJ4jaienVCZ0X9HsC7S5y02nUVs9JI3EG8ztyHf0VOORQ== 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=Yugvb4V1/DaU9YPaXiZJXwYIK8KD9dleMPpB9SJ6Hp8=; b=BqYIDNc/8YlTMBZYwqUPDwylAN7SBkl0dtibxzY44osUDAZSEGKCI/RfPMVNx45zHO3ERDySZeDgZsZNJYjfSDJnUjFWr/HmMFqfcDK8R6AjMyg5RJQ3vOKIMAvHBaqWA4X4XtLlYE+E+EM7PDuu//TSfxdlDe7SMAtOG0c5xFc= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by PH0PR10MB4725.namprd10.prod.outlook.com (2603:10b6:510:3e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Tue, 15 Oct 2024 17:56:19 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%5]) with mapi id 15.20.8048.020; Tue, 15 Oct 2024 17:56:19 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Linus Torvalds , Jann Horn , Liam Howlett , Vlastimil Babka , Jan Kara , Alexander Viro , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH hotfix 6.12 1/2] fork: do not invoke uffd on fork if error occurs Date: Tue, 15 Oct 2024 18:56:05 +0100 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0145.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:188::6) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|PH0PR10MB4725:EE_ X-MS-Office365-Filtering-Correlation-Id: b9d1b6c5-3501-45fb-dae6-08dced42ac4b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: BVPOu6txGovq+WixrfBegcbdDrzOiqvpwlJmK8NYj9tPnNyBMtHHewbBZJRq0CXr0byulKSnvkx4S5k6DljDQQKg/oG95tqlVWxIlBrSzum1PtCc0BxYL9Tu2el4PSDus8VRAlyM9zPnY3ZNesl1qn6ScN46EaJX/Q0EFJ8JhUD26r9wn0mb5yztV0YKMjMI6Z7oPzzc9q/0rKT8+5jrXAmbHE3ACjccS7RTJiHRD3Ny4LEa6UP9Hh/CxXCj0nECfc/C3NvEBbRr6J1DFezeM36JaAgWvoPPmGXhzVRIlNvYLTE1lMguAAPditmfOl3g8mKJuRdBbB5L0bRA5G+6GJVrrLfjn5mKXhq2bfmgUyX9V/GeMl+jOBa6W0u/lR8vFZzgv/gaIFThvbFI0KMvrDDD49vS4iFO/048c/KpGxRh1+/P4uVkVTQAIbxeEWZFEg5yQivI3sR4qm0JitwOcfsxSTJDP6gi+A7WlA5kXn1b8HgXQyYbW8XrdrXU74144C163mLENyal0bzToZ40v65yUjcMaCph7lIeJBiVKn/ZaNPtC2LjuV03474e9Fb1gHnlkfRw8r9j6/7/5vtkHfUR22UqIQIoGlsKDkNFRhhqVQ3Sjz1cUJvqc4E6H/DRKhd1co6SgEIshgM5f3pmLNXU7ZH1q4xPKnsGkKez2UAJ6qTvtST4+K6uZh6WAIkt6mnCSZ04ekLiAeMfWu/8NAJtYXowBU2fUm1IiXhRISGhaCfJtlgLNHSxluMJDcJj8OAsZXygXHYrJtqYJPb1etgwiDVg0+MuVKmnaVNGsUyKYsOkqGsTUfKwKRqDAfqpYbZfYoV3mVx/K4fEukZwyFu5bQZo3HxGPH8aARIF1qOFP0lLF31yT85Dz8yjm8J01chvZFh3L6tsiHrFsec5kFdZeW1ONG2YN5LCm8rFAC6IS8y+mOp3agOdnf2Uer4p1qeQvstaGoysIcsqUc4TSaR6fAY5xdOq5UBJXCc/hP+rHpxsBjAMUsjhrSspCoGr2zAXNz9gDmjUYEsNcl6JMvfIlMChyEKrYwYa0jdSYaqP9mQv+0XUJOawKee9jath7DxxYxOlE8zh3YF7uUSp5K1fXV5T1Q+Y1eHTU4LHhfwLB3ZpBqIR1G/k72qoG6UGmYv+jMxhYI13oI7013fUrIU5D7acnKUy6dr049N/qKfi7bxaQwYu57CZe/aZYEd8gi7hmBOx5YdTZGeIhI1A9/hABJbwo2c6GEubl+oWpD1ftjAfYGAKXYepg8JuJoOxtdmtMLAs6rSmTk4Sb+5Wsw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vSnylwSjTB72bxXkZjOcCuSGQSxThxsQCrjrljQuSSQclVUVt0PxLPwuCaAoownFB5YrThnMTUUdx7Ih5hCYfMgDmYyq38VhvPJzHuxylK9JlQLt5Mol/qV/xCTNt6Uod5Y8VgLP/NyppTPVEXhQHrabGjV6SvDkKPOnmHjzbXI+XA95JOrNV1u7d7xqqGH5jw/lLkNIDVzwOknHFz3AIxdnOWdOxl2O5HEjGUpnBIZl+BiHSlNJFRrctXvHWwKhSibPJ9+6A6y1mRn0MBOObDOFY6b7hirPJCGzACQHha9TsXXCGyBMFNFFhndL+FeCEiuMM95jAReCRUNws95nX6ak4/8orYfgQiB50A2Z91uniRoWpeUjLF7wGM0LdTfAdIKCORy4pHTltuFPAENsVzdZZMc0rGNRIeJjE5Bq8f1k0IlgkuAOnCV7by5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u+SSHqAr+ldPuzcZiphOvy4+97pE6mqNhG+J1f2ac3w1/BNvpRVqX+/l4q+DiMdM/g3ki4mNdgoFPFwerF3tFVEL29SEsO1KPGxWftjQYxrbRpawrg== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: wTm/A/4oc5OPke3Kns/Aq6f4GJ34YgoR1JxzovQvFtSnZkUirENX6bLzgRgug7jEptKcj1ud3hULrPMq3nmb+ZRY+b5bVCIbhey8uN+Vbd7/gxpoktWyKO0fdTdgNRDYmVcZYs4Xt7tyNyORpPQDm6z7K6CXnrzeh8U4QjryBN9dznPnisHg48NcXLaskJguKkJkfYAlmx4sY607rBIT8+gEwSmom3tTjnfA2u7yx1uTpVqFmYqoM0rsFdb2xXxtS32BxpVlsfJaUo0LzzTalFwIy7Lpv7Q6S/5Z/rvnF1Belgi/23qOIU3Lb1R44+G2SJOOvBz8U/xztLtLRnI8cJU6xfV6GF6G7OHrMowR4tb7JdrbJ5BwL8tlyIN0zGXjI83vsznaK7aqkHvzvYQd+zxFkU0rLvjgHbnpOZdGwhrmWB4ScyKYYzH9vLZ5fV1vLyA8MRhsCh4AzpOBMu0a8ubqcuXESbpfH53WRHHt7SmSt08QaDpGA3MsmzGyJJHsMk0lNNDUJQXO3uErSwXmEA7vtFHDntezb5PI18o4ohLHZc0sWd2vuy334goR7rTw99KGAG1BYXWCAOaHbgBv2N/JYnS9EcFl3QY2Tsqu8U8= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9d1b6c5-3501-45fb-dae6-08dced42ac4b X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2024 17:56:19.4674 (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: AtFSLgDYCTz+BGX86lt177g7RaqJJZ1T2n/77IhH9w1eJN+J0IW0lE3u6IeOkm78oGaaUEkFZt6rvLXrPZ53W+6qY3Enyi1yfGtOrnfe/Yw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB4725 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-15_13,2024-10-15_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 adultscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410150122 X-Proofpoint-GUID: HXnmHst5Qkx1XkMSPtEYe8ZUwKq8VBPo X-Proofpoint-ORIG-GUID: HXnmHst5Qkx1XkMSPtEYe8ZUwKq8VBPo X-Rspamd-Server: rspam03 X-Rspam-User: X-Rspamd-Queue-Id: DE6D6A0006 X-Stat-Signature: y9r8eaugt57t5s9xgx1s91cc4uzzgiax X-HE-Tag: 1729014984-313534 X-HE-Meta: U2FsdGVkX1/f4BA1jnyV1lebXKLdma1heSyylsOa3e5OfWtboO6d4gRrdYgdAGKYmHJDC0JdwRvn8M3APVoTzC6rtK7sBxgWLCe+jPzo3xGdeA29VxNBil1aNEeyPG2vl48fIKRZbe1BC4oix0oYV5eYbTOtMDUmuXWkj3ReZnoflaMjk1YnMJQOtSGMe9r8+kDcbkw6Q12wri9bc+kYqUs9U6rslKFT3DzDZt7N4KBh4z0PGmmZgMN3OwE0wkg9kv6CwrbWGAkthFawk4dvLLy6atLpDBvNUcxf2o8g6vX1h6C6tk9w+S/jvGQrpU/91w3c7mwkOCubWsLvNpVypIJ5v6SRU6TG9IPaYkwpZji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ON6ElbOtFcA3ir5UUo3ZjZKPtaX8eCtT7i/2UxpEW9IwchtoHu4+ZfX3smtOBY7FwJtRTp+TnsLoA8ifsYJW9kZkOhX6Ipg6hfEHHj/WEmfV49ypA+kQw== 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: Currently on fork we expose the virtual address space of a process to userland unconditionally if uffd is registered in VMAs, regardless of whether an error arose in the fork. This is performed in dup_userfaultfd_complete() which is invoked unconditionally, and performs two duties - invoking registered handlers for the UFFD_EVENT_FORK event via dup_fctx(), and clearing down userfaultfd_fork_ctx objects established in dup_userfaultfd(). This is problematic, because the virtual address space may not yet be correctly initialised if an error arose. The change in commit d24062914837 ("fork: use __mt_dup() to duplicate maple tree in dup_mmap()") makes this more pertinent as we may be in a state where entries in the maple tree are not yet consistent. We address this by, on fork error, ensuring that we roll back state that we would otherwise expect to clean up through the event being handled by userland and perform the memory freeing duty otherwise performed by dup_userfaultfd_complete(). We do this by implementing a new function, dup_userfaultfd_fail(), which performs the same loop, only decrementing reference counts. Note that we perform mmgrab() on the parent and child mm's, however userfaultfd_ctx_put() will mmdrop() this once the reference count drops to zero, so we will avoid memory leaks correctly here. Reported-by: Jann Horn Fixes: d24062914837 ("fork: use __mt_dup() to duplicate maple tree in dup_mmap()") Reviewed-by: Jann Horn Reviewed-by: Liam R. Howlett Cc: stable@vger.kernel.org Signed-off-by: Lorenzo Stoakes --- fs/userfaultfd.c | 28 ++++++++++++++++++++++++++++ include/linux/userfaultfd_k.h | 5 +++++ kernel/fork.c | 5 ++++- 3 files changed, 37 insertions(+), 1 deletion(-) -- 2.46.2 diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index 68cdd89c97a3..7c0bd0b55f88 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -692,6 +692,34 @@ void dup_userfaultfd_complete(struct list_head *fcs) } } +void dup_userfaultfd_fail(struct list_head *fcs) +{ + struct userfaultfd_fork_ctx *fctx, *n; + + /* + * An error has occurred on fork, we will tear memory down, but have + * allocated memory for fctx's and raised reference counts for both the + * original and child contexts (and on the mm for each as a result). + * + * These would ordinarily be taken care of by a user handling the event, + * but we are no longer doing so, so manually clean up here. + * + * mm tear down will take care of cleaning up VMA contexts. + */ + list_for_each_entry_safe(fctx, n, fcs, list) { + struct userfaultfd_ctx *octx = fctx->orig; + struct userfaultfd_ctx *ctx = fctx->new; + + atomic_dec(&octx->mmap_changing); + VM_BUG_ON(atomic_read(&octx->mmap_changing) < 0); + userfaultfd_ctx_put(octx); + userfaultfd_ctx_put(ctx); + + list_del(&fctx->list); + kfree(fctx); + } +} + void mremap_userfaultfd_prep(struct vm_area_struct *vma, struct vm_userfaultfd_ctx *vm_ctx) { diff --git a/include/linux/userfaultfd_k.h b/include/linux/userfaultfd_k.h index 9fc6ce15c499..cb40f1a1d081 100644 --- a/include/linux/userfaultfd_k.h +++ b/include/linux/userfaultfd_k.h @@ -249,6 +249,7 @@ static inline bool vma_can_userfault(struct vm_area_struct *vma, extern int dup_userfaultfd(struct vm_area_struct *, struct list_head *); extern void dup_userfaultfd_complete(struct list_head *); +void dup_userfaultfd_fail(struct list_head *); extern void mremap_userfaultfd_prep(struct vm_area_struct *, struct vm_userfaultfd_ctx *); @@ -351,6 +352,10 @@ static inline void dup_userfaultfd_complete(struct list_head *l) { } +static inline void dup_userfaultfd_fail(struct list_head *l) +{ +} + static inline void mremap_userfaultfd_prep(struct vm_area_struct *vma, struct vm_userfaultfd_ctx *ctx) { diff --git a/kernel/fork.c b/kernel/fork.c index 89ceb4a68af2..597b477dd491 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -775,7 +775,10 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, mmap_write_unlock(mm); flush_tlb_mm(oldmm); mmap_write_unlock(oldmm); - dup_userfaultfd_complete(&uf); + if (!retval) + dup_userfaultfd_complete(&uf); + else + dup_userfaultfd_fail(&uf); fail_uprobe_end: uprobe_end_dup_mmap(); return retval; From patchwork Tue Oct 15 17:56:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13836810 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 D04BAD1D893 for ; Tue, 15 Oct 2024 17:56:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A4DA6B00A2; Tue, 15 Oct 2024 13:56:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F1CD96B00A3; Tue, 15 Oct 2024 13:56:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CD2366B00A4; Tue, 15 Oct 2024 13:56:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id AC7C96B00A2 for ; Tue, 15 Oct 2024 13:56:34 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D044EA1816 for ; Tue, 15 Oct 2024 17:56:17 +0000 (UTC) X-FDA: 82676591298.10.E010259 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf28.hostedemail.com (Postfix) with ESMTP id 8EF35C0010 for ; Tue, 15 Oct 2024 17:56:23 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=gEo91h5x; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=pUGOMHTL; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf28.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1") ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1729014944; a=rsa-sha256; cv=pass; b=50xEjvC9vhYeZPmrqT79pBmXeAMbZGpms+81OJcY6Dsqrbxteuh9idU9rf3NWoFXylHw7e +JoHqEySjiF9GUJNwJMW/Rf7L8g+Fso5wjwsdLIwqhzoRdUqigg2qtJ87CgAPT7nxi4QFr VfOul5fvFfP3m9eU+qu2rT9WmwRVgOA= ARC-Authentication-Results: i=2; imf28.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=gEo91h5x; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=pUGOMHTL; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf28.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.165.32 as permitted sender) smtp.mailfrom=lorenzo.stoakes@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=1729014944; 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=05Vlkq3Xmq9GA1USXavexmhprJXWFzls7cqapKWzTvM=; b=HpDxMoRubPj8P7V5y07PnNSs3fMxjY71oo2MX0Z6d2940SRXfqNMtNwiJZEwUW1PGdCAPo lvjgku+u3u5YGNG0QuPSWXo+ueYL8Glo3+GG+0m3VJepw0vyca+fvJ1D2vu1ijaEx9qwXz jd9mpwVknZBS4sMe5WhvKNNTXEdLQtg= Received: from pps.filterd (m0246617.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49FHtfub008297; Tue, 15 Oct 2024 17:56:26 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=05Vlkq3Xmq9GA1USXavexmhprJXWFzls7cqapKWzTvM=; b= gEo91h5xsF7SKSEaMc2SaLhtbljG4MvGiKRH9NK+g7Qmz4FxFxPkJNupEY+vU+38 D/oWhCw1pVwGVoCIuZJCq1qymRcYzX6Q8EAof5h9beSCdAoRdQmWgywkd11GlYuu Qa/3ZnhW0bhh2M4aYax3Ld0/ytKid+obidVc1q7AsS3bXwNsuuYXk3904b9Dvn4J KhKJlBuOpx1099I7wg108Bs5+SfhKHvfa6y2yVBR9i8v3Sm591yaWhYNseRIAGXQ tZd7mzf9d6qzSYl6iSUL70yhpJX17vzNIt10SuSR59NS17GTiUiv2Y7Hfi6vAv1G aS6U9cHVS3jsLawTNvoB7w== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 427hnt9vjp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Oct 2024 17:56:25 +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 49FHQMhr026416; Tue, 15 Oct 2024 17:56:25 GMT Received: from nam10-bn7-obe.outbound.protection.outlook.com (mail-bn7nam10lp2048.outbound.protection.outlook.com [104.47.70.48]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 427fj7swmd-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 15 Oct 2024 17:56:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=eIdtnCW4T67xzUSM3jU7NO7nNb52ndpWTU8ZJF8M/OrAxDglB44inl7UuTp/laozKS+Z8L3z32y6gScu1C/thvTJWSkC0O7Cu47rVjpz+9wzqR54ZYEw6QbDT4IpIaEyazmaNrhtNtkBWn1gCXxHMXJZuBZpjHYWx/1t2GF5GlkSRanuEMHW8jl7g77+E1rLLq9za+Rf6OR8BzuJUa2c/6Q6W1RrXYAqSGVKxuSBSznYppIZ2+E0MAMpKMkxd+39/fhiDKmIVdyn7jN3sYULLZezd73L3tew+Jann7gwa/aF+Dcakt5yNLhoz0U5cRm8E2ZDGanOzfC1Zx+oDnjdvQ== 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=05Vlkq3Xmq9GA1USXavexmhprJXWFzls7cqapKWzTvM=; b=lEbH8LYjQ7en4NxxgOAVWQHcktUq81vYmboiQWZ8wVZF6wkEHMB7aweMkLcqY5z6JK7GogG3iOA5lHQ4qFrMD+c23j0a/3D9W8hshpX91qSWnbs09LLNVVfS6Qcybz3ISwxlz1CyBqxp2Kao/DlL4kXDpptSWIfYV6Lfrxomh6pLB3hmrRScfHo0f9e9X+GfD8E/tHMJ7eBnNVM8A5zl22h/N/Oii2LAbjISCQW7YBtXU8nT0q4kLWJkcubJJLDIpxcQjXl8v+05BCOIS7FH6QXpa1iBGAo+HGP2R/gVww3xLmE5ewwBFSU65fqhJd2nZgzNHsleQDtefyZNR9HR0A== 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=05Vlkq3Xmq9GA1USXavexmhprJXWFzls7cqapKWzTvM=; b=pUGOMHTLhGi6nhg6XeCPeDGxi4sq9Gt77+E1MjZGS6vdGeHSRvEKmL+WbwPVFOh4Ro3/jMqx/3wsuoeSVauIth93+Ln4sGJIT4Su/8ST0ZavkfI+GEEUdwpFAr9YYdvAGyXdfFlab89mR/c1Oc+kCLDBXWoze5C5ZNoJahGH+E0= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by PH0PR10MB4725.namprd10.prod.outlook.com (2603:10b6:510:3e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.27; Tue, 15 Oct 2024 17:56:22 +0000 Received: from SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e]) by SJ0PR10MB5613.namprd10.prod.outlook.com ([fe80::4239:cf6f:9caa:940e%5]) with mapi id 15.20.8048.020; Tue, 15 Oct 2024 17:56:22 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Linus Torvalds , Jann Horn , Liam Howlett , Vlastimil Babka , Jan Kara , Alexander Viro , Christian Brauner , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH hotfix 6.12 2/2] fork: only invoke khugepaged, ksm hooks if no error Date: Tue, 15 Oct 2024 18:56:06 +0100 Message-ID: X-Mailer: git-send-email 2.46.2 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0263.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:194::16) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|PH0PR10MB4725:EE_ X-MS-Office365-Filtering-Correlation-Id: 6dd1990e-93a9-480c-dbac-08dced42adea X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|366016|1800799024; X-Microsoft-Antispam-Message-Info: 74hlVoDjMTkUZvvELCNFxuntYqq8CJJSaXRRmuTazWAqJjlgPt+RKuPKLYZ8JfElPFVF6SGegXubFyuGT2AmGtFKd8Msnz/dX4nJCTOq8i7tHguQp45Lq53M0Xx1Gmsxn7REJQIi0AdjRBW4Xzw8DwGJ4BI+uLB4DjVWTTNBDwygGAxp6zEqsmYRCwnsYv0dIsSQVBUCE+MfflofnJNcIJAbFnqNgQST/U4YQPuAWupwCcfB8q12KJA9NGjWfJw6WXCuEZLwO5xGn+tIlSxOimSVCld7jgfTFPTvKDgEpdY9mMxp0k0+E9/lCXd8rIruTPnrkdlfQ4A3Dy6iXp8brNN8hKQ03SwVMXKKuoQwkFybQTeVQKH9UU3uVTk6Sxcgtt783FtC/ik265yMZZ3kfWJnl5wpbh1CZBduVemnYhd6heYU+UENInkWm05CoQhVLFGN2CNimjIXpLbCyYl2M6fhZK3LtHtuMc5P7D36QjJthoPiQ7kcv1qTEztxd9HaFYFJbrwtWzzUXT71owGqmhjwkb+btqdvD+p7owZ5xJeskIWBb4J/Cb2+Wa8g03g10ejzgMoshz+D9EzYBn3VXoGZtvXNo4Q/3GnML2bsR3PdcRKqq6MuYbvl2FbNYf6sZX7O4HYhaf9tftmVETVx3GDJm/0N0WPeg93IBbWkjleLtD5HGRyt5EoSQn7Htv/VWjKZI/BU+d1ICbOK055a4oEBaRnwXvrpgZAe3PDGkTRHrEYEQbww6ezq4R3L3zwcQOvJ1xDYJLh/V9/M0sX386U18qJS/mGvqw2NiQBwohui3GEj4/szRRGRtGqmwRPHU3RZ5pDAxlq7rjITbjeNCe4cKlvfqJR1Ui7JzPu8yKNFPtLUIibjqT9Kqc/N0LmwzPBd1v08mUdR0frfkAAEe0H2+q5kJ005NMKHJi5fl+gYiqZbdit5Qc9nm8YH2c64XYZgv2C9GQsH6ZmbdqvfPqjC0QTWcMiPrFT5+qEKjuQp9I1pOQJWngyrhEMzt+s6jpBBYi/I6WUozOBxI2bYw0VTbCX6kwcw99t6ZDoi6AhrnPqoo+AspmsluDq5nydX+AsKdMxzLAqi2vNJlgZV92zpC7byBURrF3ovV3PIuKaS/dYXTqkRAVjr4O7AgoTk1vbG59Z342XWaFeI6h1zWv7w7A+0+3J/fAKEVceFmKG0bASwY0KXf42/uPC4TNPm5WXaicK/SnDGzGVCGiK3/Xqu7UQ+Lc1rkOQychd+VlXrXfZDPBN/BMU04n4uuY2L7u7MJ7WAZtQaqoRH3dJktQ== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(376014)(7416014)(366016)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ubi33RJAMRLysJ1CZM6QrP08VyggS1Q3iAJaVDiUkujDuNjhE63gsspjNsMKulmt0KTcMCuBCDV3aaMHUvWVyCeA5Q4MVkleDgC0H+AhqqRaRYBeC2Q9qCeQWBGhfkFLDtOwOIqRQbDMeq8hLe9NUh/vZAd/SM+LzPaZpwa2wdVrcgHijRM/7gP0PNTZqMwDvJeRS8PBkuhdsbH77MeTor8/b7eFuF41aP9OwDMXFoZ3YgMwznIUpyUucCkJlViHHdqE4c657mrxioaGohOR+/wkkEqLH2Gq83mx0UlR7MOylzhSkvv2Dmk0BwciPQoGZEImiJnwMJs2mRE1eMJyUy7aV0wgfrnSCC3YOJApwAjk9Ea8NB/YdHWgoGwOjb1NxWXZf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IevWA43vE0Tr4zxwUduijeL/kVkK2ULs+8X5BUwc8nueoMi7mfM46XCJTUEAexM4/aaVzy+JgwztEZ3ExsQ1fdHIDoVGcdU2YcvE4gfe0iGEeeYAyXQm3Ho/B2bw3w8Wn4rOCWhQulnAdCutUJz/SINqGr8DLcqd9zvw== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: IL9ZwwZ6hrUyt0AEHQ2EaADYzeH9IdjWg+HuvKoFryZcU0WytaVOWZBlJzL+U5ZE7zLWWf3qcvxGT4mt7GTuF0Q+Sh0HWtAU1E4dKmjDxMuWlyNmlAubkC6RIhCm7le6jot1YJO+IaEIANuZDq+o3DYCjlVR0jaMRshhM9fyjN1Z83uGkgOLnz5SKAcMKe7j4hRFymufweEBBc3ib4psno00faSmzrKtOa3Hm/TOco+wmZ0EvsiuzvxGwxEjHwXAGrPSzM19HoBnoX9jioOVW1oMjHgMWa/ZmnxaiP1wmYO+c9Pm07TtBLtJY2l914Kxt84f2AutUwoXKidTzDLpfcYolPDDQ1tzOXUiAw6C0VvplTj7gL+q5POS8IuFfDeEWWW2QWbzEs4NfpXXoHKwv3iRFRstjPdkbpsTcirWuO98mkzy0XQLvPqSZFdoOfv8y1oUmHiIbiBUuQlQ3F/0DEpxpKzrMZijt6EaaWdOPAvxJBPoiH+n5vdV/5UPICKmOqtLYNqUP7l09MUuoSaJ00Ig5FalP1iKVqVMRQylcXMmMUqt2JXrjVVUXkPaunAHXQOMbVbOpEz8ER+/ihTL/bMJHqCnkGuI5DUKGCVPI7U= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6dd1990e-93a9-480c-dbac-08dced42adea X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2024 17:56:22.1868 (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: d0TUINwOuHF0I0hViDqI0p4NRynnwAKeGm5XlzQe3PWpU0j1w5IGT4X3NbyNfqbM5mFApQ7nG+npNDgeQxf9jtjL2ohX3urBRPuyNTjlSpo= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR10MB4725 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-15_13,2024-10-15_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 mlxscore=0 malwarescore=0 adultscore=0 bulkscore=0 spamscore=0 mlxlogscore=999 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2409260000 definitions=main-2410150122 X-Proofpoint-ORIG-GUID: vthpnDlnal1iTCXoT8Mmzt3v0eUEehph X-Proofpoint-GUID: vthpnDlnal1iTCXoT8Mmzt3v0eUEehph X-Rspam-User: X-Rspamd-Queue-Id: 8EF35C0010 X-Rspamd-Server: rspam01 X-Stat-Signature: o5t8jcm9rixj9p5jo5zwzzm1gusty98z X-HE-Tag: 1729014983-125472 X-HE-Meta: U2FsdGVkX18h1/xdCrr8Rv7bnHItK++zxhzHu9nq01FI4S0u7tLJp9kEXJI0pJx19PUgjLGG8AvewvvkPMLu47/rZHlJdhPFt/G0Yzh4slyIFkgR1KgIaPNBQzG0GGYyRYRJjDaBmLqkgFiqUCij4Sso4WJv2zlvp+yJzWokvEgSrUPMDzaDIthfUXngfw7WcqcxojTUzX45ticsg4c2vkztzbfN9X6NlSwpy+gM49n6PrJhfBSmljEN6wmBU8D11IqBVXX7OqFDxTVPF9JVcGk60dN8OY98S1UjWsP1ljWt0y6z+v0PIJZnDmyK9zbGz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vFua5wtuIhdiAowbIj8c3hEdE94aNUbGll2aKeoBLay8uvI8BAnIVp6dIkvfnQiwXOWtMXSD5UZvPH1yPa3scG0QaltqTYrmJfQ6E8Qt9nd0I2dGYOrIybpNha3wZoZXkEgk3cby1yTDXwXElYXRO/Bd/2Q== 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: There is no reason to invoke these hooks early against an mm that is in an incomplete state. The change in commit d24062914837 ("fork: use __mt_dup() to duplicate maple tree in dup_mmap()") makes this more pertinent as we may be in a state where entries in the maple tree are not yet consistent. Their placement early in dup_mmap() only appears to have been meaningful for early error checking, and since functionally it'd require a very small allocation to fail (in practice 'too small to fail') that'd only occur in the most dire circumstances, meaning the fork would fail or be OOM'd in any case. Since both khugepaged and KSM tracking are there to provide optimisations to memory performance rather than critical functionality, it doesn't really matter all that much if, under such dire memory pressure, we fail to register an mm with these. As a result, we follow the example of commit d2081b2bf819 ("mm: khugepaged: make khugepaged_enter() void function") and make ksm_fork() a void function also. We only expose the mm to these functions once we are done with them and only if no error occurred in the fork operation. Reported-by: Jann Horn Fixes: d24062914837 ("fork: use __mt_dup() to duplicate maple tree in dup_mmap()") Cc: stable@vger.kernel.org Reviewed-by: Liam R. Howlett Reviewed-by: Vlastimil Babka Reviewed-by: Jann Horn Signed-off-by: Lorenzo Stoakes --- include/linux/ksm.h | 10 ++++------ kernel/fork.c | 7 ++----- 2 files changed, 6 insertions(+), 11 deletions(-) -- 2.46.2 diff --git a/include/linux/ksm.h b/include/linux/ksm.h index 11690dacd986..ec9c05044d4f 100644 --- a/include/linux/ksm.h +++ b/include/linux/ksm.h @@ -54,12 +54,11 @@ static inline long mm_ksm_zero_pages(struct mm_struct *mm) return atomic_long_read(&mm->ksm_zero_pages); } -static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) +static inline void ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) { + /* Adding mm to ksm is best effort on fork. */ if (test_bit(MMF_VM_MERGEABLE, &oldmm->flags)) - return __ksm_enter(mm); - - return 0; + __ksm_enter(mm); } static inline int ksm_execve(struct mm_struct *mm) @@ -107,9 +106,8 @@ static inline int ksm_disable(struct mm_struct *mm) return 0; } -static inline int ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) +static inline void ksm_fork(struct mm_struct *mm, struct mm_struct *oldmm) { - return 0; } static inline int ksm_execve(struct mm_struct *mm) diff --git a/kernel/fork.c b/kernel/fork.c index 597b477dd491..3bf38d260cb3 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -653,11 +653,6 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, mm->exec_vm = oldmm->exec_vm; mm->stack_vm = oldmm->stack_vm; - retval = ksm_fork(mm, oldmm); - if (retval) - goto out; - khugepaged_fork(mm, oldmm); - /* Use __mt_dup() to efficiently build an identical maple tree. */ retval = __mt_dup(&oldmm->mm_mt, &mm->mm_mt, GFP_KERNEL); if (unlikely(retval)) @@ -760,6 +755,8 @@ static __latent_entropy int dup_mmap(struct mm_struct *mm, vma_iter_free(&vmi); if (!retval) { mt_set_in_rcu(vmi.mas.tree); + ksm_fork(mm, oldmm); + khugepaged_fork(mm, oldmm); } else if (mpnt) { /* * The entire maple tree has already been duplicated. If the