From patchwork Tue Sep 24 11:16: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: 13810792 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 1B88CCF9C6F for ; Tue, 24 Sep 2024 11:17:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6A69C6B0083; Tue, 24 Sep 2024 07:17:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 662AA6B0088; Tue, 24 Sep 2024 07:17:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 480946B0085; Tue, 24 Sep 2024 07:17:23 -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 218736B0082 for ; Tue, 24 Sep 2024 07:17:23 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 9F4D91208E6 for ; Tue, 24 Sep 2024 11:17:22 +0000 (UTC) X-FDA: 82599380724.03.D1D26F5 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by imf07.hostedemail.com (Postfix) with ESMTP id 425DB40003 for ; Tue, 24 Sep 2024 11:17:19 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=bfdyvir4; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=dShjQ8ZN; 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=1727176578; a=rsa-sha256; cv=pass; b=x2Mpt4zGJb1rdVgC1uOLEUiZNQ4ink6ZS22YKW4YHucakN6fOjaEdMbRHFJ/xpqU0o2TuK CSjUJ86c3rcJRN4vubRG6FxY65qu0ifoXhrGyMPspAAScOJzLo1RyJHd/hX/gWynLNW7uw 3xxcFeHTuSaOBW2SxOfpEEGPN7WNjFg= ARC-Authentication-Results: i=2; imf07.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=bfdyvir4; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=dShjQ8ZN; 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=1727176578; 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=3yvYy5mInhuS6TXooJbJBSUzDgPnmQzXOcR1ccPdQcY=; b=8bhxUxAsiOYf4RaW+tjK2znvUk0beWinpWjj7sTumIUkwPhHk7xnCiiuDtS/u4T/oZMhVr dkxqv9byc1sq9K3DsxZKsIOK4R9gRBu1bDx/Y/MYcnavyF3+IymqQNVEn8Cmu5p/TSpU1c Dkdj2mXW3jSVvD8Vnvo4zSnbvie1aQo= 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 48O1N3c9024933; Tue, 24 Sep 2024 11:16:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=3yvYy5mInhuS6TXooJbJBSUzDgPnmQzXOcR1ccPdQcY=; b= bfdyvir4/u6L3YaFzHStKCC7BuSw2vfU/JdbqMFhrF6ypVfrRYX4vK9Dd65dx0B+ CCv7dIuzmIOI5E5bzngOcHkwuBDU9FVI1XSHYjyAoSXv+G9W8KsvWlqs2plZ+yQI X5Hp57y+KhBLseHWkxijrBGfzaCaRdUlVwsKAJxQwy73oIjHxNsUC8amL6xG0cPj TsyyrmGmgvbrqyj6RNuQMmOGLh3rDcUYwnA52h3VoLgw6IrNsWCyoHyizxUO4/ZI iAWDm1ylboUo+UyuT+dkdsoWmSy0yWFbykp5RQWn8j3l4QsF8XnOlkmCM4JFkWJq XD0YGrpvNRzykpmeU8yP5g== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41sppu740k-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 Sep 2024 11:16:43 +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 48OAp6NB028296; Tue, 24 Sep 2024 11:16:41 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2170.outbound.protection.outlook.com [104.47.59.170]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41smkfb9sg-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 Sep 2024 11:16:41 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=MyOXdGyrNmg/rf0C4WCG2M71u2LE0LRJJtPwbmefapCO82I4ljtx/Si6r3wcU5MTnWvI+UtgP0U0UwxA03T56NLGywWjFsiRgHc8iAPXcv5ty2qrLldTWSW74LNFY+FPm8aLo/qZlvz7sG7NVtk4zfk4Oh45nzUCFpgc4mwlQsY+Bp+Yvzxdlz4L73iQOdu81muM6gvnRX0DOY8DSVvkFIVCqLo8TBJZTOK2g8ZtPKrESKHSm351bdSgXdI9MJhKB8No/8qNB7BEq1hPDPvIxZ4OTJPWgxCFRxFQmU1bit9qhx+VT01TSs3aaY64uEaWUd7gJAs4r7orJLLrWpoQIg== 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=3yvYy5mInhuS6TXooJbJBSUzDgPnmQzXOcR1ccPdQcY=; b=Nl9NL2cXL9o3JDjkGVrxMPAiImLhWwUGEZdOT9nsBGnMhO4IZrwPTuRvcirfB0L5Un+5efniZWteK1yA3IJpGePuV41BSimkMlGi4XX5biAx+cWUEX98Lm7nwHUNLx58htHuNzwEpK+ITBE8zcDdh9JmewHnrQA/8ASyHC3mm+Bi8QqYobfzw1FobEaJi8iltv8FYgpJdv4chkN69Hvvx74N0Yb8GyU3q2HS//BcgA8wmQ1ZIM6zabbqFOB8K/nuifythUnVXt9swFu5AvC2Y/TW/pGJCdJcIC9ime0DuCto01ZlW7JaljRLsGnT24ozEJk8zXC/9n4QZOor1Kj90g== 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=3yvYy5mInhuS6TXooJbJBSUzDgPnmQzXOcR1ccPdQcY=; b=dShjQ8ZNmI6+aEiaj1TPmwvakHAwmZdgMfC/em06+3c7yYshok72OuJn5ttGNWTE048i9G2Og3SJwB9Mxv2hNK+uEEQrEW9cQxyyBVCO9Oga97knfGUtPQ7513maXMnEVRHKOs4TdUItQQu48CjlHZR1JtU6WdiGTwNFiKK2Xvc= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by MW5PR10MB5850.namprd10.prod.outlook.com (2603:10b6:303:190::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.10; Tue, 24 Sep 2024 11:16:36 +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.8005.010; Tue, 24 Sep 2024 11:16:36 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Vlastimil Babka , "Liam R . Howlett" , Suren Baghdasaryan , Arnd Bergmann , Shakeel Butt , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Minchan Kim , Richard Henderson , Ivan Kokshaysky , Matt Turner , linux-alpha@vger.kernel.org, Thomas Bogendoerfer , linux-mips@vger.kernel.org, "James E . J . Bottomley" , Helge Deller , linux-parisc@vger.kernel.org, Chris Zankel , Max Filippov Subject: [PATCH v2 1/2] mm/madvise: introduce PR_MADV_SELF flag to process_madvise() Date: Tue, 24 Sep 2024 12:16:27 +0100 Message-ID: <1ecf2692b3bcdd693ad61d510ce0437abb43a1bd.1727176176.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0432.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18b::23) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|MW5PR10MB5850:EE_ X-MS-Office365-Filtering-Correlation-Id: c8d86591-e58b-4f0e-163c-08dcdc8a5a79 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: Fu8aq+QXlQpdcuDwElAqmG5F+3DtsF5OUnhoFtiSiKYprOFY9DxSYiuU7SFgVw9O9djEhHAgb9k7XV8q8OBy6xNjW+VX8nmYfjdYTin7eiL/wbe/FtKP3UUssbRPS+M57b0vaWJLKkbZZfEm2EVz3h0+SSjP6ShiB4dkaEafZ44Zz/3srxLpEGAbaI3OAzTTUK1gmcZsX/DI5FPIhaTNN0H4QPcolXYc/e9nbahZpCiz5OrmPO6wVm9lShtTAJ42vQ7jdcI9BG8HPJ4WKPVmyeWGsYvkAPIWspTIwyyj78LiQbWznrYxN7BWcF8TR66pgiIcpKmg1lbq/47VmnPZzhAC9Vzm5Q1VQyDR3XH5qndP/mqZCADUUkdgeRWSlE2VWJvxmfWLgmVMTk72Zu3P2ES68FDe0myfvUVKdQV9Sk1MW6kjb/GGko+b1HSByQPJvHzFSkLy62OI2KGNeizFQNtPWcp0IK1jHC9g9ywdvr4o7TvzadSrURMtle8Aveawp4W7MpOtPkiXfsmUDoi83fud64opYonOspCwQ8XXC6iC7IabVMUEbcMu9oz4Cd1SgYjmcxTWqnyR0P5KyGv5NH2kAA/3ZL87GvrA0+WFA4b6esjA2OnCs1tJVohMtpRSifSR4r6LMDlofUxl1GiHefkb0IUfM/rhfDyvqwC5zTas+Gh8n9lC3OkLleaSur+ql7UFaCVsUfxR+sGi9bmvDpCVt0LcGJHkVoAft7nj+7752E9TmXgNJcz6iT38zzeU8MYY/607VfspXQ317F4GJveYzbo+AnjSIPIw5IuPlbv3yyfNOZMWFT2AC0DrA0hEK57a06poHjglXM3l2epOP8NSYvCmp6PSEL9vGpKMMGjqd6IVi4C/xHnMWh1OMiXJOky0ShPLEVt9B7VJS6YBgIRKQGpdbTQqDp5W9SxZOVGArhf7qsq2yv2iZEBazk63k7MzlMGCxxj2PATmjpLnR76EGRkV5WikdV+8s/eiQdJXBJUOyKBlrpW+If3umicy9Q7Z92kRetUUulco7sTGb0k8qYRAIGdp8++cGnnLn4EufoWmxq3Jzhgja2qTskSQwo/ysaKlUaJMOE/ydmeumEMJFQdj6nVA8HiM3sYuYwjT/w1MnaVuWOT5Pcjm2s0/vc8yAEo8zxWmtW1GGsnf+pBU0KbKAN3IJZqUedTQK0C3cmGJp8BTyt0b7v/OrW1uNhniZyW1C9+mtYAtQnAbgpJ6o8CD+loIcRiZ+QvLjRpsRYCtalYYIyNtf/Y4PKeQ4ZfoFfOPWc1HqHragngM3g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: G8NY7Z6/cMqKaOZ9UZ2gn1d7zTrWnY9rkY5ge2pKXhnPUjvBGiLzBBbO/le0henJC8zDRD76dhD+lbetABYSfI/BXA1mOi7qX9FCxS0s1Wu9nlWyhfBTy21qYh+kPcVQif4bLDlAn85gY59Sb6gE3cwzp4MmST1/Xq2+P7SEBSCohxKMiswN4doBkQb/ML0o7UDpZ0pN3gMLnU3fctnQgSIhlMGD8YwkZu6+nsg6OQlkRzj/+pChpqZI+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qgXraOsDyc7hFzT8CIDsxuMsDpe5Lp3ItBah4c22BvsEt5doTPNqrSRGntyX/TLHAti1lwasV+OoYsqH/+nXO8iclKUScR17judwwaN9qkLJ2EEu6SRPOdDLVa9RhSUtbhPqyMFHlN8UNjN10eZ+ZCxnoLuox8O0WUe7Lgtt33q2e7A8CmhRcWd44qFDgNaewfsSyvKeXiQ+CPahcB8bdBWql6HOjJCc8HdHD0KIBnmAWxnDAZwQKHB5IbqDR7QbNaHaZBblx7YUebLZcpObAz7jayzOdDZIdz8lZotstgVA== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: z3jlcsVz+mAmuFV2AzOQS62JMm1CyED0y4TyB6eQr+jj02XFjy6HYfgj38yjg2qfdM2pyFNoQPwX2+zQQ6oc7VOjAA4CwNXCbPnQXP6G7U5vgKJNbWjsRy1TVVZEzMu00eSla1YN9sjFYaFIF5+KhHQwEnuhcrzLhgMpaDI6VXlzUPLTsJohoJu5LFb5Yr3RuQ1EXbV/s6R4YletdWXGAz86vry57j8WL/1rlsrgOjEFfFxIANJDqCQFTaYJQyjVY34J6IgIx4w1kR0RABB6lwcug3tDfk0cqOk5cE5R2FARs42GNroee/GMcZb2XEP6mUYZjlFnhdK69XW8KmF3H0ScKB3b/cfZdBi1AcAgw1kYwC9YsjefZbD9+fK6esQboZy88UWuuuTwDZiWqgcn6SBAPn9P99XTD3OULPhLZexl8ExjfkuuI7o2HaQr4RiAPpqBXImkPA+jp3awJJIIUodtpGwNwXl88FEYXj7laDAXwHvGwpEF7xKVEFGS65LddRAE0eBkrBlCuZ3Rv2rjZ2k9WEGghRjt6iK3oeLivpStOIlkJ3uJedpWu10OYWo3AxWrRtARTnQUpR8t6nCAdQ5U9/eGSqGpBimqYDgK0+E= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: c8d86591-e58b-4f0e-163c-08dcdc8a5a79 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Sep 2024 11:16:36.3580 (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: jV2eoJWlNR92bBOBfRfMS/NTY8F1mwq+r63PfSErC9oi8IYSawSEeposya+4Sr97P5ux212qyvr8p4thPKW5w/9LvvFK2QHaev4d8Hg6UYk= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR10MB5850 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-24_02,2024-09-24_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409240079 X-Proofpoint-GUID: 12EY5B6d7nliO3BmNw1VYUuRGwTtFB2p X-Proofpoint-ORIG-GUID: 12EY5B6d7nliO3BmNw1VYUuRGwTtFB2p X-Stat-Signature: y1qe45t7nyrp93zkg8mqhtzfihttykry X-Rspamd-Queue-Id: 425DB40003 X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1727176639-123798 X-HE-Meta: U2FsdGVkX1+SSj092JZLYJBfCP6sopm3/0KY6HvlTaVs6z4BWD5B3Ru6MHI2BM+vaGE0h92tO5bTVXODbMUbYQj/d4elEa8TumOnqeSoEV31l1QLhwDTEHf5JS0zMQNqbyvcKzpnYNHET+N5cPBWgE1n8Ls7Zvwc830CG7Zshn7FJ6u9ZIdgiuYy7XzJLo5BjNFzj1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Vj1E6aCBNFuWR6717czuPD+4/KH9OE5F2TDDT9PbcgldYvLeD+p0A4xVhLBJKTbUCm8BAgT3taOZN4CUMGdELoKh6evRBxnXJ9rF7Skajmwi1A3/K1sQk9avVVPcap6iw1juX8KBLYO66EvobgSU0EZFPvAGCncwLJIBwClCqY7d6Ds57NohV3NpRwBfYjcAgqRfE7nIr9qZFF7T0S3hklfNO2JKODk9twO696IDrcMczSIlx1iBsa99G7fU9RujEfUraKdSbmVgPE3k4xfSS4S83QeZQN/ 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: process_madvise() was conceived as a useful means for performing a vector of madvise() operations on a remote process's address space. However it's useful to be able to do so on the current process also. It is currently rather clunky to do this (requiring a pidfd to be opened for the current process) and introduces unnecessary overhead in incrementing reference counts for the task and mm. Avoid all of this by providing a PR_MADV_SELF flag, which causes process_madvise() to simply ignore the pidfd parameter and instead apply the operation to the current process. Since we are operating on our own process, no restrictions need be applied on behaviors we can perform, so do not limit these in that case. Also extend the case of a user specifying the current process via pidfd to not be restricted on behaviors which can be performed. Signed-off-by: Lorenzo Stoakes --- arch/alpha/include/uapi/asm/mman.h | 2 + arch/mips/include/uapi/asm/mman.h | 2 + arch/parisc/include/uapi/asm/mman.h | 2 + arch/xtensa/include/uapi/asm/mman.h | 2 + include/uapi/asm-generic/mman-common.h | 2 + mm/madvise.c | 66 ++++++++++++++++++-------- 6 files changed, 56 insertions(+), 20 deletions(-) diff --git a/arch/alpha/include/uapi/asm/mman.h b/arch/alpha/include/uapi/asm/mman.h index 763929e814e9..0148e6de35ab 100644 --- a/arch/alpha/include/uapi/asm/mman.h +++ b/arch/alpha/include/uapi/asm/mman.h @@ -86,4 +86,6 @@ #define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\ PKEY_DISABLE_WRITE) +#define PR_MADV_SELF (1<<0) /* process_madvise() flag - apply to self */ + #endif /* __ALPHA_MMAN_H__ */ diff --git a/arch/mips/include/uapi/asm/mman.h b/arch/mips/include/uapi/asm/mman.h index 9c48d9a21aa0..acb4c3bc92b2 100644 --- a/arch/mips/include/uapi/asm/mman.h +++ b/arch/mips/include/uapi/asm/mman.h @@ -113,4 +113,6 @@ #define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\ PKEY_DISABLE_WRITE) +#define PR_MADV_SELF (1<<0) /* process_madvise() flag - apply to self */ + #endif /* _ASM_MMAN_H */ diff --git a/arch/parisc/include/uapi/asm/mman.h b/arch/parisc/include/uapi/asm/mman.h index 68c44f99bc93..0f839b2cad13 100644 --- a/arch/parisc/include/uapi/asm/mman.h +++ b/arch/parisc/include/uapi/asm/mman.h @@ -83,4 +83,6 @@ #define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\ PKEY_DISABLE_WRITE) +#define PR_MADV_SELF (1<<0) /* process_madvise() flag - apply to self */ + #endif /* __PARISC_MMAN_H__ */ diff --git a/arch/xtensa/include/uapi/asm/mman.h b/arch/xtensa/include/uapi/asm/mman.h index 1ff0c858544f..37dd27d09251 100644 --- a/arch/xtensa/include/uapi/asm/mman.h +++ b/arch/xtensa/include/uapi/asm/mman.h @@ -121,4 +121,6 @@ #define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\ PKEY_DISABLE_WRITE) +#define PR_MADV_SELF (1<<0) /* process_madvise() flag - apply to self */ + #endif /* _XTENSA_MMAN_H */ diff --git a/include/uapi/asm-generic/mman-common.h b/include/uapi/asm-generic/mman-common.h index 6ce1f1ceb432..8f59f23dee09 100644 --- a/include/uapi/asm-generic/mman-common.h +++ b/include/uapi/asm-generic/mman-common.h @@ -87,4 +87,6 @@ #define PKEY_ACCESS_MASK (PKEY_DISABLE_ACCESS |\ PKEY_DISABLE_WRITE) +#define PR_MADV_SELF (1<<0) /* process_madvise() flag - apply to self */ + #endif /* __ASM_GENERIC_MMAN_COMMON_H */ diff --git a/mm/madvise.c b/mm/madvise.c index ff139e57cca2..49d12f98b677 100644 --- a/mm/madvise.c +++ b/mm/madvise.c @@ -1208,7 +1208,8 @@ madvise_behavior_valid(int behavior) } } -static bool process_madvise_behavior_valid(int behavior) +/* Can we invoke process_madvise() on a remote mm for the specified behavior? */ +static bool process_madvise_remote_valid(int behavior) { switch (behavior) { case MADV_COLD: @@ -1477,6 +1478,28 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior) return do_madvise(current->mm, start, len_in, behavior); } +/* Perform an madvise operation over a vector of addresses and lengths. */ +static ssize_t vector_madvise(struct mm_struct *mm, struct iov_iter *iter, + int behavior) +{ + ssize_t ret = 0; + size_t total_len; + + total_len = iov_iter_count(iter); + + while (iov_iter_count(iter)) { + ret = do_madvise(mm, (unsigned long)iter_iov_addr(iter), + iter_iov_len(iter), behavior); + if (ret < 0) + break; + iov_iter_advance(iter, iter_iov_len(iter)); + } + + ret = (total_len - iov_iter_count(iter)) ? : ret; + + return ret; +} + SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, size_t, vlen, int, behavior, unsigned int, flags) { @@ -1486,10 +1509,9 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, struct iov_iter iter; struct task_struct *task; struct mm_struct *mm; - size_t total_len; unsigned int f_flags; - if (flags != 0) { + if (flags & ~PR_MADV_SELF) { ret = -EINVAL; goto out; } @@ -1498,17 +1520,21 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, if (ret < 0) goto out; + /* + * Perform an madvise operation on the current process. No restrictions + * need be applied, nor do we need to pin the task or mm_struct. + */ + if (flags & PR_MADV_SELF) { + ret = vector_madvise(current->mm, &iter, behavior); + goto free_iov; + } + task = pidfd_get_task(pidfd, &f_flags); if (IS_ERR(task)) { ret = PTR_ERR(task); goto free_iov; } - if (!process_madvise_behavior_valid(behavior)) { - ret = -EINVAL; - goto release_task; - } - /* Require PTRACE_MODE_READ to avoid leaking ASLR metadata. */ mm = mm_access(task, PTRACE_MODE_READ_FSCREDS); if (IS_ERR_OR_NULL(mm)) { @@ -1516,26 +1542,26 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, goto release_task; } + /* + * We need only perform this check if we are attempting to manipulate a + * remote process's address space. + */ + if (mm != current->mm && !process_madvise_remote_valid(behavior)) { + ret = -EINVAL; + goto release_mm; + } + /* * Require CAP_SYS_NICE for influencing process performance. Note that - * only non-destructive hints are currently supported. + * only non-destructive hints are currently supported for remote + * processes. */ if (mm != current->mm && !capable(CAP_SYS_NICE)) { ret = -EPERM; goto release_mm; } - total_len = iov_iter_count(&iter); - - while (iov_iter_count(&iter)) { - ret = do_madvise(mm, (unsigned long)iter_iov_addr(&iter), - iter_iov_len(&iter), behavior); - if (ret < 0) - break; - iov_iter_advance(&iter, iter_iov_len(&iter)); - } - - ret = (total_len - iov_iter_count(&iter)) ? : ret; + ret = vector_madvise(mm, &iter, behavior); release_mm: mmput(mm); From patchwork Tue Sep 24 11:16: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: 13810793 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 58F47CF9C6B for ; Tue, 24 Sep 2024 11:17:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B12B86B0082; Tue, 24 Sep 2024 07:17:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AC2356B0085; Tue, 24 Sep 2024 07:17:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 880236B0089; Tue, 24 Sep 2024 07:17:23 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 545B26B0082 for ; Tue, 24 Sep 2024 07:17:23 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 015F616105C for ; Tue, 24 Sep 2024 11:17:22 +0000 (UTC) X-FDA: 82599380766.29.9A2AD6F Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf09.hostedemail.com (Postfix) with ESMTP id A724F140003 for ; Tue, 24 Sep 2024 11:17:18 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=PF5o1KOh; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="kOz/tUou"; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf09.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=1727176624; a=rsa-sha256; cv=pass; b=kaNkLJBhHURyC9zBfMKvGc/YTbE8y3ATwrux3MNjcBriRVt94xd30M2pcp8YO7asU8XJEi dTaH6k5UGUtUq66MGSqwAO1IHFUDuOU0wSYnEG3zbwJnaC1TCJXMyFa1W++ohLIphWSn/P hnUsfvNikuTWpjXis8DaX1ic9vqF4Yc= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=PF5o1KOh; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="kOz/tUou"; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf09.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=1727176624; 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=xZeDwn2PWu8UYuFKltEJq/RpzlHL3GN0BRBf7w2ydCY=; b=LmaC2a69B68mHfjvTtf8FXRpQrYPEPdCFxLNYiFzP12esW5qlCu3GBHWjOmk8QHXm/SpU8 4lT0eMsbqiXnx/BKAW3fiyYwno3uFmpKusMjc2ubJiFnXLRaSbWbdtetxLdqf33VT6fBPB +1iu3LwwIiYgCkZHSSpl8iEgZ8qjh1o= Received: from pps.filterd (m0333520.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48O1MXVN008712; Tue, 24 Sep 2024 11:16:43 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :content-transfer-encoding:content-type:mime-version; s= corp-2023-11-20; bh=xZeDwn2PWu8UYuFKltEJq/RpzlHL3GN0BRBf7w2ydCY=; b= PF5o1KOhcjuZf5tPvXh0jVH+uO297kpbXVx97IVFqu9W362VAr0xgAtXTjwJMnH4 dEamfyEry8Mkq0hcK4QCIPwGe4rMSZ3W8vT+D0NtIqPbEICoZHebqRwAXEYqfymm O25ynheEKETt9VQACt+Kv31gIitOPvOPKWRYDXH91ZfmJqB0Dz556mc2SalPQdEc s0clx5Y29gUKr5GYHoN8prKCS4orLkO3sHoolStWYF/TJ/e/hQb56OEx+c4AOJRi CO1MO7xJ95wuylGiOmQRSqBqU/KsNgZhOXHcpauZBCM/leep3+5ghHhNwci5AS+1 rXB9WQ6dJlwMsirxTANXWQ== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41sp6ccpqq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 Sep 2024 11:16:43 +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 48OAp6NC028296; Tue, 24 Sep 2024 11:16:42 GMT Received: from nam12-dm6-obe.outbound.protection.outlook.com (mail-dm6nam12lp2170.outbound.protection.outlook.com [104.47.59.170]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 41smkfb9sg-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 24 Sep 2024 11:16:42 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=lvhzeSdy474z9W6MdngidAX9tXDx2LNtU+phJkhWyOsPr9gK2ykxOMuSXXQexm0/R0fcC5fOB0reryI03VszMlIDNbm1FjDNly9yt7RD3Cz4q+eNzHMU+xxgzxPqL5yw6F8G0oiOi8m1hIsWc0hquSL8CMBM2zoQWDuWbvlMUi7n79TmRXvjNYLrE8Ok3e6vaUAz658l00p54BNJc5MOk/h7iBPq2quYJrbZ+mmXSkQ32QD1D2VS9O2mW1iAD/Q0a1acalQWk1s/v8yLIlNm/o9SZ40xnIkFgdiu76IGQwwPPzk2pgbVKGpz+fLen8yExSrQoCcMyBienSsWCSgk0Q== 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=xZeDwn2PWu8UYuFKltEJq/RpzlHL3GN0BRBf7w2ydCY=; b=jxibOukJEtID1IxjhqmOx6QESRW44ADbx0gk2S0JSz2wnJV9X35TwbpPO0BKwNb6PiAicd/A7+KFkeNGVgxZcGStQSjF9pJVuYQrY6e+5eJM5ucMqIQibuRoRGSkCqMfW7PtPr43FYvhASFHhYFblPbghzffcfG5Fhdm/rg49+P1phTTdH9Hn3IpNRWEzKmEneTZMGEuGt2q7db29svnEcMS0Q+bByEVwalbs7BQRTSxo96OrksJt8+N/LiIfLczDtTzKCs1zyeUWP6uCi5yI5qOWvqOEhAqzAYIvEAqwHwP4w47Y55KhdRXAEB9FB5KIwqAwQW9NcWcREpR3dYY+g== 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=xZeDwn2PWu8UYuFKltEJq/RpzlHL3GN0BRBf7w2ydCY=; b=kOz/tUouTNsLbg7ykpvhnyAnJ7yZDac5hyTIYOW1PxD11AwTalLI+PgNZxlCqr/Ub8uQZGlRXNnOgKyQG7Qvmi7INhiiqQAEkI443EgylolEY6WGTUXmEakBc00Rg4M0SdwgTGWBNZ1Dr1PeB2M1D6HOQV0YUP1FIuQss4+QJbQ= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by MW5PR10MB5850.namprd10.prod.outlook.com (2603:10b6:303:190::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.10; Tue, 24 Sep 2024 11:16:39 +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.8005.010; Tue, 24 Sep 2024 11:16:39 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Vlastimil Babka , "Liam R . Howlett" , Suren Baghdasaryan , Arnd Bergmann , Shakeel Butt , linux-api@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Minchan Kim , Richard Henderson , Ivan Kokshaysky , Matt Turner , linux-alpha@vger.kernel.org, Thomas Bogendoerfer , linux-mips@vger.kernel.org, "James E . J . Bottomley" , Helge Deller , linux-parisc@vger.kernel.org, Chris Zankel , Max Filippov Subject: [PATCH v2 2/2] selftests/mm: add test for process_madvise PR_MADV_SELF flag use Date: Tue, 24 Sep 2024 12:16:28 +0100 Message-ID: X-Mailer: git-send-email 2.46.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0171.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18a::14) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|MW5PR10MB5850:EE_ X-MS-Office365-Filtering-Correlation-Id: e146c437-b395-4b50-ca45-08dcdc8a5c1e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: AliNnVuXUqQcL97T2Ed0TUGzGxMRXSR5OCD2oTPGZfTCjk5yWBFCUhWqwH7PbejHymdQJmvMvAVgP/sKSXxMOWE2So3k5vf9ujviJT/LRJvsqds5T5fEQrxZ+WEiv1f8RArrL4wyPR3lXsgRBV5IBoxNArHy3Ri4fkPwI6qk+uzl79jGaDofa0w2J/zSDlaJxTcIs7gSKnmu0hOwth8vsyxM9td3Wwa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R8bRZBg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ0PR10MB5613.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(7416014)(376014)(1800799024)(366016);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: O1ttHJIfeFgOdX43/ecMmexcIReA1KDZyHKrzr84/lbI3mn1rWTOMkRgF6xiYtMIGS7PtuOLYnUYqVkOodcKPF9TP84+6eiYUzSjiK6nfCg8ovtBUifNFv0EA4YMhVU1bC2fbvow+dtrf35sN4dnYLNa6lt45T6LSPUXj31I20R8l8nCIF+oWn/KUjqQpD8sgO8FLRjsFiLK46ZNplKJb4SEnec9UBB3MSX+FUn7sJtg0ypag2d6fTXZscFef5Ks3smAQAhyjmiZFkhb0KQOhTQ+eoXTv+eWaW5jxIn4dR9XHZEgqF39W0T/naseyKTtSi8SS8ozYOv5oTMGPCX1JI5sk8aHqp27NVHkXVkSjA4FlcL6IdVPzhS5HOAYp+wDC3FUIUquan3u2NrAkdBqLtq2MCgeWbjqSIDrWkmutw6W/l6+aYbivrsDhSoQlqRYDC2238dT6+p/ACY+YWQpmn6ZaqC3uNunWNRnfla04lsBDbl/yZQqi2zxPDSsnASlubqaA15VGpjpbmKYgpEftMtU2XtSyZ7Uiy5Oz7+uBYbC58JDwJRch60g6k3RzkheaQgfRvSVD6q1r0WdV8qdXLZDjxAHsRqSs+vGeaZXgnYIEv5x8/m//W26E25rrkUMAYGPC49hjbUdK/jW2+LeFA2m7wtH3opEpD6WUci4Rp1/isGMh2QX8X//abatM8q19Ww1GS4DudoEqIjcV7Bu2wn5x2Umy9J0rDe/NR7QZmqYnXa0xuB5pfoGL35EcHUjAb10WFjyGfypQv0RO8WU3JxpLKL2xMK7tZNKX+0OEynaxe0FkhIJEeVbqKnp6E7LmE8suEV4z2xrAW+msqlMRpAYW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xTJ7FDAJ7isPNVSTjsPJAhg1wsqfdp4QNzPaKf5Zun++0PNFJLDNi3GCs/XYPPZHFKOS8mPfGKoS0e2PqNsBWnUSCeI4j8VcLXp0lLdAxgqOpMTxDzYF5X6BQ35B9tHT7Jp9x3WGoXkbqNlSct5k9VHSIyNWeqq7+WEhAW9LDXOc54fH/Eoyi+3fI/7+N0rTL7osTSz3qWZ8axHqU4frlfqI/Luc0wtEuxUC3XNFxf384Mza+1f0hwQCcVLgyKvv+siBHtaSYTM6Ud0a25Vzbd7mSjuTiAD58QtzJCm+ky1Mfe0DYjKh3yATW7fYmxlo0G/PR9Q6Woad7u6tclo14SPGqP0mq8vqt98WZzNMPnhU1WtAf0m6AL1tS30vcMs= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: e146c437-b395-4b50-ca45-08dcdc8a5c1e X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Sep 2024 11:16:38.9684 (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: fXd0jQzMydvDM476wm0LbQZBCVhX2ik9IdbSWikJmA0SN9o7VjambW/5THuIpi5NbrFVw257KoX8JCdYA2L2sHttk4FRviLGB6SoJd5/vVU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW5PR10MB5850 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-24_02,2024-09-24_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 spamscore=0 phishscore=0 suspectscore=0 mlxlogscore=999 malwarescore=0 adultscore=0 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409240079 X-Proofpoint-GUID: jnqVMxIf9PCCXo1dKuq8xVfg6GIXm__7 X-Proofpoint-ORIG-GUID: jnqVMxIf9PCCXo1dKuq8xVfg6GIXm__7 X-Rspam-User: X-Stat-Signature: wzpuc3edid4uutztx55m94uwutqtww1m X-Rspamd-Queue-Id: A724F140003 X-Rspamd-Server: rspam02 X-HE-Tag: 1727176638-385639 X-HE-Meta: U2FsdGVkX18liipwXCHQaOmZihzOk7YUbt2FbqjStvY+ScCWR68ewfC9cKQnA0dhuJ/+chjqg3dsObSr7ca7OLT6/YGMM3esa5Que9C6y7IOgxQnMpuKdVVX2OCUiFDZqBZmF1lJSNOX0lHJR1Tu2bkGzmTIrQ98R398I+6/Fk+GOuvZ53y8+9WU8Izsi4Wk8eCWNWOpnr6qiNCbDeZeGitbCIrUqjD2lqAifee9ATzo5O9shs4mfvdzPLFd1MnbeevifOe2LqHuvtBbH7B6TcpDLu4WZ205riaPr+cyUq+tyDw8P73oZgjEZ1ExPrqnrljYWf/HhXVjDsllpMkSbg5mQx/Q3tTaeMFF4vxicPZrsKayDfASaEHfzOq0tPEQCQZGdCOqUwxpQu/TGq08DeFkCXeTEZapISwreViJivimMeC60z5MEcqM8U/Ts3c3frHQhfrkgGbyayXWEMhLp3q/YjreoqpA9867HRKUqFrL/lgm2rfa8TaL4MvtarOvmai24acj35TP23oxu3nTBnXSikdQzECYvWkjZyEMtYv8wI+SLGjQ3onPZwB/Tu27tkhz3NFO1/W0Q2HrV9/r5VAMcMTFYDfrWLs1zPQ+feLjmGs+86rv1jcHxkjNYXsP+WKUfVgixjKsksSw1La1+05S1s39RSSnpvzLD+1jtrhrIx8tBcxtbLDMPRu5BJqi5p0YH8WextHvz8esGABQWbbiZ7/Rwt+2Ca6S3v0z1Ycd137YNEru9utprWkKNWgFR87yZKHbxBDmtz+r1CFMIlC0mPIZ42qlRFI3mzCUYe9flIrbJ+2dholwEQLbQ1XxA+IHv+0j7oOcOh1eVSxPQ5jEwyR6b/fC1zdZNwNOLw5hWITfMpGCVVOaK9p0wGcgX0nCT5KcDWJg/Q4zl8BiIHx5/ovoPNen5Q3j9NAry+2R1U1jxvwNwlnN9qkWeEf9XtpjVfHb1yW5UaOtL4c 0OeVqNgn YFrOJsRZJDNwc3tdrTpXfe18qLnzTaGpXQumidwj3z/Ft602jb7pgFdMvH7SJBZfre6Iu8sBYju1pE65P1O3BJ5s+8FLrLlby3E0WdY2xqHsmI5mrQ0Gn8ci7PhiPQfnN4+5TdEd2FUvyDVaul80rmDmqYKQSdzhxaG34CTxzZ7JERMUekWXfoN4ARda6jAd4qoNOCaKNKq88k6dSlKG/Lh0cIa4C7EQPALg2PWdRQOH0rh4vDGTA9R92t8zLJ6Q+0ltTVpTzYzeOg66bqagxZq8dP9Nh34v0XVLjOjCshBeRVobjfpkoca+IESNQloXcCqB0h2+d/nBU+lp33qOpzFY0pe7ZH2sQjVNobMPI+bFoOjQAVcumeDLgZMks/mimzndWQ0uZJxY3bo52pQqAedNfGhrBy4IvPJBCwjg5zBfni6ogcj3ft23zEMr8+n06CmSpQN3UlEDblfAs8coXzBnkbYgsF6Dba+QU/lg0ho+kHuXIPbI0kczj3Nmep1cIXB9I+9BRbcPMBs5MuOvl7L49AbiHO7H3VxMk2M2w7tHcjQvtd6ljLV5USnZHK1hqG/ac 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 a new process_madvise() selftest, and add a test for the newly introduced PR_MADV_SELF flag. Assert that we can perform a vector operation of an operation that would not be permitted on a remote mm (MADV_DONTNEED in this instance) on ones in our own mm and that the operation is correctly peformed. Signed-off-by: Lorenzo Stoakes --- tools/testing/selftests/mm/.gitignore | 1 + tools/testing/selftests/mm/Makefile | 1 + tools/testing/selftests/mm/process_madvise.c | 115 +++++++++++++++++++ 3 files changed, 117 insertions(+) create mode 100644 tools/testing/selftests/mm/process_madvise.c diff --git a/tools/testing/selftests/mm/.gitignore b/tools/testing/selftests/mm/.gitignore index da030b43e43b..a875376601b7 100644 --- a/tools/testing/selftests/mm/.gitignore +++ b/tools/testing/selftests/mm/.gitignore @@ -51,3 +51,4 @@ hugetlb_madv_vs_map mseal_test seal_elf droppable +process_madvise diff --git a/tools/testing/selftests/mm/Makefile b/tools/testing/selftests/mm/Makefile index 02e1204971b0..7503ec177cd2 100644 --- a/tools/testing/selftests/mm/Makefile +++ b/tools/testing/selftests/mm/Makefile @@ -79,6 +79,7 @@ TEST_GEN_FILES += hugetlb_fault_after_madv TEST_GEN_FILES += hugetlb_madv_vs_map TEST_GEN_FILES += hugetlb_dio TEST_GEN_FILES += droppable +TEST_GEN_FILES += process_madvise ifneq ($(ARCH),arm64) TEST_GEN_FILES += soft-dirty diff --git a/tools/testing/selftests/mm/process_madvise.c b/tools/testing/selftests/mm/process_madvise.c new file mode 100644 index 000000000000..7a29b77d837d --- /dev/null +++ b/tools/testing/selftests/mm/process_madvise.c @@ -0,0 +1,115 @@ +// SPDX-License-Identifier: GPL-2.0-or-later + +#define _GNU_SOURCE +#include "../kselftest_harness.h" +#include +#include +#include +#include +#include + +/* May not be available in host system yet. */ +#ifndef PR_MADV_SELF +#define PR_MADV_SELF (1<<0) +#endif + +FIXTURE(process_madvise) +{ + unsigned long page_size; +}; + +FIXTURE_SETUP(process_madvise) +{ + self->page_size = (unsigned long)sysconf(_SC_PAGESIZE); +}; + +FIXTURE_TEARDOWN(process_madvise) +{ +} + +static void populate_range(char *ptr, size_t len) +{ + memset(ptr, 'x', len); +} + +static bool is_range_zeroed(char *ptr, size_t len) +{ + size_t i; + + for (i = 0; i < len; i++) { + if (ptr[i] != '\0') + return false; + } + + return true; +} + +TEST_F(process_madvise, pr_madv_self) +{ + const unsigned long page_size = self->page_size; + struct iovec vec[3]; + char *ptr_region, *ptr, *ptr2, *ptr3; + + /* Establish a region in which to place VMAs. */ + ptr_region = mmap(NULL, 100 * page_size, PROT_NONE, + MAP_PRIVATE | MAP_ANON, -1, 0); + ASSERT_NE(ptr_region, MAP_FAILED); + + /* Place a 5 page mapping offset by one page into the region. */ + ptr = mmap(&ptr_region[page_size], 5 * page_size, + PROT_READ | PROT_WRITE, + MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0); + ASSERT_NE(ptr, MAP_FAILED); + populate_range(ptr, 5 * page_size); + vec[0].iov_base = ptr; + vec[0].iov_len = 5 * page_size; + /* Free the PROT_NONE region before this region. */ + ASSERT_EQ(munmap(ptr_region, page_size), 0); + + /* Place a 10 page mapping in the middle of the region. */ + ptr2 = mmap(&ptr_region[50 * page_size], 10 * page_size, + PROT_READ | PROT_WRITE, + MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0); + ASSERT_NE(ptr2, MAP_FAILED); + populate_range(ptr2, 10 * page_size); + vec[1].iov_base = ptr2; + vec[1].iov_len = 10 * page_size; + /* Free the PROT_NONE region before this region. */ + ASSERT_EQ(munmap(&ptr_region[6 * page_size], 44 * page_size), 0); + + /* Place a 3 page mapping at the end of the region, offset by 1. */ + ptr3 = mmap(&ptr_region[96 * page_size], 3 * page_size, + PROT_READ | PROT_WRITE, + MAP_FIXED | MAP_ANON | MAP_PRIVATE, -1, 0); + ASSERT_NE(ptr3, MAP_FAILED); + populate_range(ptr3, 3 * page_size); + vec[2].iov_base = ptr3; + vec[2].iov_len = 3 * page_size; + /* Free the PROT_NONE region before this region. */ + ASSERT_EQ(munmap(&ptr_region[60 * page_size], 36 * page_size), 0); + /* Free the PROT_NONE region after this region. */ + ASSERT_EQ(munmap(&ptr_region[99 * page_size], page_size), 0); + + /* + * OK now we should have three distinct regions of memory. Zap + * them with MADV_DONTNEED. This should clear the populated ranges and + * we can then assert on them being zeroed. + * + * The function returns the number of bytes advised, so assert this is + * equal to the total size of the three regions. + */ + ASSERT_EQ(process_madvise(0, vec, 3, MADV_DONTNEED, PR_MADV_SELF), + (5 + 10 + 3) * page_size); + + /* Make sure these ranges are now zeroed. */ + ASSERT_TRUE(is_range_zeroed(ptr, 5 * page_size)); + ASSERT_TRUE(is_range_zeroed(ptr2, 10 * page_size)); + ASSERT_TRUE(is_range_zeroed(ptr2, 3 * page_size)); + + /* Cleanup. */ + ASSERT_EQ(munmap(ptr, 5 * page_size), 0); + ASSERT_EQ(munmap(ptr2, 10 * page_size), 0); + ASSERT_EQ(munmap(ptr3, 3 * page_size), 0); +} + +TEST_HARNESS_MAIN