From patchwork Mon Sep 23 16:03:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13809814 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 CB909CF9C74 for ; Mon, 23 Sep 2024 16:04:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 767E36B0095; Mon, 23 Sep 2024 12:04:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F12F6B0096; Mon, 23 Sep 2024 12:04:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4A66F6B0098; Mon, 23 Sep 2024 12:04:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 0E9066B0095 for ; Mon, 23 Sep 2024 12:04:22 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id BD637AC4BB for ; Mon, 23 Sep 2024 16:04:21 +0000 (UTC) X-FDA: 82596475122.30.5F2C4E8 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf14.hostedemail.com (Postfix) with ESMTP id 6DA39100012 for ; Mon, 23 Sep 2024 16:04:18 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=ReigIwKm; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=RSyriIYL; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf14.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.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=1727107423; a=rsa-sha256; cv=pass; b=HTr5LqymK+6nqK8QRD5cbOHcLGn5yOvqmPyszPCWLRQt+ID0Ufc3Ga2p9dPz5xlN2M8qbP 2PGsTSZIw84ZsNQJLHoNxDjQNP60qaXz4DO/4vGvGgVz4QPsUixI8FiDd7yMareQkjMHkf V5wSZb8LRQS1hp/FAH6hKMat6JqXl8k= ARC-Authentication-Results: i=2; imf14.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=ReigIwKm; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b=RSyriIYL; dmarc=pass (policy=reject) header.from=oracle.com; spf=pass (imf14.hostedemail.com: domain of lorenzo.stoakes@oracle.com designates 205.220.177.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=1727107423; 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=W0q67exA6YdXcrL3YepDeU7tz8LTl7V+/D0PXUIJ5u8=; b=wsoLEIw9F27tzZLZ9FgkgR5nv1szAHuEWBBsYLJ3q+yXQJJhk5AZFJU1rGi9FJuM+gEYHZ QKsYeU/+iTTyvjGWdoOO8vhr0XtXQhvhZ32cF2u96CKmFGfJT/nKc0xrroI0VprekRoAAj 2bt+ylaa+B7EEd3m63LoV1iXlfbvEys= 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 48NFtX9P021774; Mon, 23 Sep 2024 16:04:12 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=W0q67exA6YdXcrL3YepDeU7tz8LTl7V+/D0PXUIJ5u8=; b= ReigIwKmhPvAbU0nnhXVgzhmro2B0LyTxZotEdG/Y+9tql2Tflk9JaJ+H0dKptFc T6jcbPARjoQV1aYMnr24nQMrGTnw8qPgr7lGgZCGYMhTtZhPARhh2nRhX3Twmbcd I99cbvhD+vucbDsUYm7Pe9RPhFjzViav1wtZNYjY/5XVjwiwlR8KMeDCSLGhUDr3 t62IAn8wQtsMqMI5doFUpN1fOmlvd3CGE5eMMzLVzAZ82kSWdfwDK17hkKu97UM5 gv/812aXLcCddf2yTs0Xu+P1Oqt6lYIOmAUgv/sWp4Q6bXvzJpApeDg6hyTTm5io jTpGV1n+G30M0H6Dll6FDw== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41smx32q47-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:04:12 +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 48NFUeje000461; Mon, 23 Sep 2024 16:04:11 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2045.outbound.protection.outlook.com [104.47.55.45]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 41smk7qpkr-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:04:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=ma8ulFKpyY0yVSUFJ992rFc5eKV1ahTQt7dFZV+F+gObsGQuAHk7u4hglXH8WMvdQ5yZXwA3XVqLhGh6fwRDEfsU3vT6ewOOLeOno++MW4Kd3yZytYKjNrh9y5x+qTDh7g5vMPdFxFjVoyR3IOdeHbpOoyhzKFkN5rXF2llHWUWatlRrrvIG6LMYuxeYine1WN13hgsLklidjWUPvsA60ZTZuM54hFY7+D2d2r+x4fxuJWTlOPep6szBUfN6t1CfotRvb0ZDscRswMlDOv3N3f8DbHgOi0Gg9BtafiyDUYTU/DaS9vYtZz4vVk8RWBswHF2xtlZ2Y25NWSlvDcqOyQ== 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=W0q67exA6YdXcrL3YepDeU7tz8LTl7V+/D0PXUIJ5u8=; b=ykEYuvLxKA3QFXC8J+LzZoKDENhVaGH7+DX/v4qnccQCQ5EktBqhKMBUSz9PZlYMIB9rofHQMCBzsP/vFd/93mkdf9J3I9l3/YZI3iAD2hxc2mj2w4BNnnTIPaHmfz3Mj+SiW7xjUBQu8ZsN7daLOivdrmWDQIhS7IjqbmFOAp9VmbknPucujN1fju8BIEfko5Ak4shH/JYxmvJF0NhmzV9kIiCOh9W3xfU21c8JRVt3quRkbz93AbfXtHfCG69iyeArj0t+m4kJZkbe05JuVah6TyemoXbO+fztVdodwAUzukiWwyktNpbjzgILpJX6WvM7ATbYMN1u2F6kgLawCg== 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=W0q67exA6YdXcrL3YepDeU7tz8LTl7V+/D0PXUIJ5u8=; b=RSyriIYLVO6A0lwpiijVMPpi5ucG3TW32ozKIM9Nq/raEGTkhekW6dwU4G6PljGO/c2grOWbjpHhjsuGYbSbA4h2eYvZ5KrS9+ZRYoybxeN9lt2waSXcY6GxD+/8/lsd29/kFTz5l56Dpy0FWqJRxNscc2hZQ7lrUpoLDzESxXE= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by DM4PR10MB6744.namprd10.prod.outlook.com (2603:10b6:8:10c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.13; Mon, 23 Sep 2024 16:04:08 +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; Mon, 23 Sep 2024 16:04:08 +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 Subject: [PATCH 1/2] mm/madvise: introduce PR_MADV_SELF flag to process_madvise() Date: Mon, 23 Sep 2024 17:03:56 +0100 Message-ID: <077be0d59cb1047870a84c87c62e7b027af1c75d.1727106751.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: X-ClientProxiedBy: LO2P265CA0495.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:13a::20) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|DM4PR10MB6744:EE_ X-MS-Office365-Filtering-Correlation-Id: f3c438b7-86c0-43c2-d0ea-08dcdbe95a11 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|10070799003|1800799024|376014; X-Microsoft-Antispam-Message-Info: I/lgZUYvPLkX21hO9tXjo5dGnd649UQu0DiC8DvVqeb34PURpX6uZDpdRcRfcSvSwSOWddGv18f30uMXsCS57i5FLLGJVOAk9Wm5Dg2lzsifT/kFZjmprFZfZXremJybjDUKYt8ihHJJOZkqTg3XvdfgIc/H8bqRtjUZZlxEkeYDx29Eqfc9H7wYAw0z6vKxqjOXglBMr1s4S7v8GtCqakR/wsFlBR+d5AnocS7JGt8P1UfvQMquQbk5EuA+FtrQESEmvNMuU60HQaLKqoiS94QCe2KqgkM7Vn/BQJnce4kRSCoXcgF1y3wg6Fc1RI07A7n2nxPLTDW6R55fugcezQJ38yHEehcFhfij47FkL6iFJ8GXjtRc5vkCtkICqxY7Ef5cPkHQpBx6N3NHo0jd9UmKH7XNtfyx63Ua/6HbX6ScUWM50eHqi6AmY8JAnu2rbzFCxv3BKz7Ki5F8rPyKyc83MLdQblWSiJhPVKvcjewGg+cUL1gd+NSz3y0qntg13EpwkChi8okdZ89rYxoBLH4lZ7DuTeXEQ+lp/SKZAM/bO12Wz+AsABXuBxtspbEQNlMCwAdwQTD4EaQ5tyKHOTAQ1i+EhfxifkdwGCAy/erKn1yJp0tiBhWEEMvTmMufgwf/MvojCgh0EBx4tu5gQngGONUpEJkroGqSkgLjDXonzthhHM5vWscS2rSJ3AIKwANmrShpAaQnPlY8XK2QtxoMm7ZpZvGWPaK1M1xas26JeVwkUw6Gv3125NdB7O35kXzHqbSATM6QsrEwF9Vhkx+5GxGnyVQWz+HrDqwMMzZjFUVTW0QCfWPeOiI+cIPDlD9NO4AzvlAbMTnVAaji34LN3+uAsCd3CFZG954zmZygUvstA3WmlltvS5qKc4aHY1MRV0K6/Q1TpQ0jfTRNmCjXit60GlNN92TMJBIdyk/C7nwA3+5a1OXRa8mHHYVqyfrG07YkTdaj768OJenpkI0errobkkTwbr+VvnFZ9O2mZxGMKwlcSdOidqdd59NVZqWl1g4kacpk6uohyLvluK0JbF15/7ja8rXfLKictS9SmajXNvBJcmXY4V+9RQHjYySijIyHNjph8sVKTSWPSvDlVziaWT+tQ8hLdjDjeCHZdVQ3tfpiZXfi7RRBCfHrX/T6L/T5VgPUrdS3xV8Dka35+km7zx5Cx46+c9qDpVSxVlDct7r2NMApiacPRlJnLe4zFT0bWtEEwR65spXzAdGe5n00CY2J/+I21Z4x4fx1/m6azQ54wxaT1Sjuu7YgXY5muGJg7jrbFgbn3Mn/EqWx5iZVIkG1CNg2nnBS56CL6IcxbGGAddvUeVNpVJqTS3vcltMUvZqB902ujY/18g== 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)(366016)(10070799003)(1800799024)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ELe0cC/VvYJzuHeb280kcJBxR9LxJa0/XuLYAyraZ8UdS1Iq6+izpSvtM2A/hpbd1AULIcUO9x9/fvSr7nVKbGFuzSdQFyqpzN2Hbhc5V0q4Xjp6ZTWebnxDLpQUVdOOwGoD1436Zmkk/1P+lnb5gBKIaFJ3wUShfXsee4Dej70VheAOfBy71sQjNfDkWRaK6UKzrHLGriYqPub7VBYVB0Zn1O1bWD6JrCcc2hmQav2lpljRB8JKt73Vt76+fMAzzuyweuMjQb9MZ8NkA2P038lTgtCaVc6Ksix610aEYs7Kz+2mIwqSr98eV+ifeQXrYZ9XByOulrUaoO2p9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BjsVYLkumW94R8HMldQux+7d12D5EbyIH/l6cRyzwPWx1YoIPFP5YikP32FhC5UhdtBAbGMjDofkzjCmPGVIRoTftBtpOjfGCApZpXtpnl+7PxRyYGGxhqIy2CZkBtgWzVPdHK9B0/nwJ3wAVt56wiIb3Zudgy8CtteUX4cqJ3rkluEZP72n+Q185f3o+YgVVCoi1QmDDndqYKPZoGBrkFFUBlfbFlQhrtbBT/7nW6WkooUg1ckL84EpV9uqywPQ== X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: Q9SWoSQjloUIaay1zLP9PXXNbHfyYX57sUQc4uhmZOMigTpn0TT6qoUtH5zypjtLpPxa1Y7Llm7cRnW2k/12rrdxjNne1fOK6AxKf9Eh+vD+kC/3MftVHCblsEzUbtgnAckImrND6U/V4UdxnqZ+hK3r9rvr+QIFa2wriQzJ2r7H4KpiHIsKeAwKNh5iQO17L8hn7F992kiffTkNS/6lIdMf+m/MaD/XuGnkHz+QQiZjXF8z6bxLyQxbVedJo5bmv30HHBvAu7C9klnwVV0rWp9wqRgvZrhEqXugw1Sl+eq2zaKzg5Iwrt4wvF2C/rwANvNaj4DDd5y4ZiInQK4/yPSCIoqkcW+yXco4OMzgov5rBVQcPvIQmu7N7XSUoV6InBaoUkXSoKQWOXlE1zy2q1wqMC0J58T5bdBFmSy0we01a1hpV3I4AAb0PDvANlcfiodmsr4tcUkdOmJekXxC8VPnWhhlxWd0dYoFSaki1+mShPcb4eu3vpaZ5SdQzEO857AXph9kPnRUoapjg4gt79RxsIDm5rd6vVw7V5QaKgiZhwxYV0X8uyHV5Neo4jO+Hs09dP5K0P+7qL/UOqVfh3YpxLUH+ApSwjLfmt066d0= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: f3c438b7-86c0-43c2-d0ea-08dcdbe95a11 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2024 16:04:06.5729 (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: hCMFRWTBx1WJlx8kreCh4bLMfOcDaHIzRnJDnjRe/h0MfZhvQ3EsA+6b+MSr2YoobYNdPo2oq2pMOBZqYRbJZX49oM3fhl40N/sDFEgcqSQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB6744 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-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 bulkscore=0 phishscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409230120 X-Proofpoint-ORIG-GUID: Cfg6OGNxv8c_XJD9P9l8cUjYFLk5aDDd X-Proofpoint-GUID: Cfg6OGNxv8c_XJD9P9l8cUjYFLk5aDDd X-Rspam-User: X-Rspamd-Queue-Id: 6DA39100012 X-Rspamd-Server: rspam01 X-Stat-Signature: khx4nmt1bqubn17xxdp9ysobh3kt4r9m X-HE-Tag: 1727107458-171587 X-HE-Meta: U2FsdGVkX19B7+GTDbBrM8ho8cl7wgUCYA/A7o9o6VUgtylwcMLDZI+AxfJcR1vmH4FxfFmmluV7JQlWm0iSx9dXQemSEqnkaYkvQp5Ml+HcLmIE4NXFuanmURr+8cBCr3t0kzN+D4ryUXdZE2nxazpmQzK5+goGedvTiSwcVUsCXMQRYKTOxhoGuFFeZuKnvlDFX529qzrz6Vi27R/RdYIEKHzLDjetjA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VEFXcU7O4QDe4eV9MqjMLpY3qLIpvNFbFqt7kSS1Wp2Supdv2EgzZmlEOMufpF2YDh7L4yPk4PrKpTS7P9cwqcLCsYKvVBGSapPvZwV3o+rOzGwf1rwGgWgE9qQuBuYCjZWmpG/wA8p4k6ta/Bt5k0O+JItluFykE7NuvDOZfkQLWc+/CGpgkXGugRTCW0dlzeveKXpUJeZUT3/Ih7F0aGt7dUi05Lm/8T5pMjQKDwtnu4GTdRUNSzM03Epyz3vk3g== 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 --- include/uapi/asm-generic/mman-common.h | 2 + mm/madvise.c | 58 +++++++++++++++++++------- 2 files changed, 44 insertions(+), 16 deletions(-) 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..549b36d1463c 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,13 +1520,26 @@ 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)) { + /* + * 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_task; } @@ -1518,24 +1553,15 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec, /* * 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 Mon Sep 23 16:03:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13809815 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 56CE5CF9C72 for ; Mon, 23 Sep 2024 16:04:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E45556B0099; Mon, 23 Sep 2024 12:04:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF76E6B009A; Mon, 23 Sep 2024 12:04:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD4876B009B; Mon, 23 Sep 2024 12:04:27 -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 9684D6B0099 for ; Mon, 23 Sep 2024 12:04:27 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 4CCA2121351 for ; Mon, 23 Sep 2024 16:04:27 +0000 (UTC) X-FDA: 82596475374.13.6AE5FC3 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by imf03.hostedemail.com (Postfix) with ESMTP id D6D652003C for ; Mon, 23 Sep 2024 16:04:23 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Z3z5Ci3Q; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="KcZEe/6x"; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf03.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=1727107377; a=rsa-sha256; cv=pass; b=BSe/vxzA236pv9PRs9yvKI1PMEo7957wqbDtw4zdjt2VmEXQps3pGhbuGho7+jskLpOc+X JR6mLp6FwRgpg1UJNTQJ0+SxSW68PiP4V8CdqgydNheUVZFBLSovkrdHt+leHe1mZ1jZ8i DxleNDbGEIGKto9b5DHUsXUTCMcx9x8= ARC-Authentication-Results: i=2; imf03.hostedemail.com; dkim=pass header.d=oracle.com header.s=corp-2023-11-20 header.b=Z3z5Ci3Q; dkim=pass header.d=oracle.onmicrosoft.com header.s=selector2-oracle-onmicrosoft-com header.b="KcZEe/6x"; dmarc=pass (policy=reject) header.from=oracle.com; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf03.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=1727107377; 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=R3jsKPvSaTFQunubOiBK+AHqYbNo9cBbFoAOn0lGGjWEa1nussjitJ8FiSmvz7pNg5TnJr E7EEwW8RVZ4I6NJEhrDVo7F0ZsNnKDa5nICSgB9D1HmvXOzChu1Iuvl/2lXkXTYp9tD/7i JaTqMCZqr2tHuDlydAf7SJO7jvqJJJ8= 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 48NFtXhk021790; Mon, 23 Sep 2024 16:04:13 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= Z3z5Ci3QvDcARDcbBc84JiKwInr3Yk+/L3MXiNq23BH9MpEzYu+QMtNRrC/YOOIY JM5w3gyCsl3c8+Pjw7ywvbdZzeN2TBJ5aR8ji4pJZlF+UZD2rD/GY2Bc9Ag07RRs cBldrfKK2O7nqvw2CxAHrRGckp0nwJsz+2xPkCpiLmeATzrDs1lnLHSVGcVGXWuu pWF5eZH95sO5kKx7+pwibKmfuTQQKxez9GHOfzXd9sUmL9ClEq4oZMebrq86GvZT RRPZkvw+Y+AIwp7YkqH0DOyJn6Kq9zHHViZIUY3roCMWRrtMRkupATIvTvn6boNz 4YwdaSju1Ywhnrs+OweU6Q== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 41smx32q4a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:04:12 +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 48NFUejg000461; Mon, 23 Sep 2024 16:04:12 GMT Received: from nam10-mw2-obe.outbound.protection.outlook.com (mail-mw2nam10lp2045.outbound.protection.outlook.com [104.47.55.45]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 41smk7qpkr-3 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 23 Sep 2024 16:04:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Jf6P48mGil8mw3zglHadaQ1SAh5Jh9AA5hDtunb7tdnjjOG1eqvgWHJu3aSHBRjOzXNlSdjVBzgRNKCc3nNRU7HS3J4dypsYiccYHOf1Ynzf7VGIGv3Ffd/ZTUZYm7W4LFo3SU4jPpsopXm3Spn7Rfq6jjh2zleE87qwQJ4w2xCEc+uaK+jEGjYvqh+Qd2rmnok7xElKySrKBa1n3iJN/PwsbdmruUPDl6apd7AW11jqGCY6Nk7qctYU35h/bvbfUCytMGEpziAcO+jH3f0pZACYWfaXuVGQL2Mx6H3D6Vhhcx3L5+/SiUVe3Jbmcjv7CytINbxUhvaWqn9d/nFojg== 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=qI6JmJ1vlW0LrW5BmmZ5V1jwyQVxyn5YvT5ROBOn9wRMZvN0uJNwS8dX70H0mspLUaIQ8H0NT35juD0jHpBDabpT2/d1CqesruOu3BWGzo896IhGFsPAMamonrdJli7PuKLqGQUfml7wIH9UW8yxllP92kz7JdA+HQmaMJETqz7xm4zY1LKTljzdTbqaN8FBHKXeCRkBqGsxUinHXW2uCtFaOJA7SuDnvjRFJ0K1h0oiSYH/jmnHrveOWhQ0Fgqh397HA3DuiHlu3V7He51KtT6IeEeH4yLbAph1TwVIzHD/XuzzFSpWd1IBX3enwcsAMZoVD61OY9iXCiBA6fWbmw== 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=KcZEe/6xW9qVLI0n35boO+mUXxmipQY+cGMnj5pr7dFjkq2p6meSz8IzkDmFE6X91T05rQgdI5AVlPcgliQ9S/Uj2lGFGA3DTH7S4lEm5JhRqzRn2uIFboqR5ObB2x+i3BthFTElUVLH7ODjQbsHo+XdTz7QesaEtZGU1KmUgrA= Received: from SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) by DM4PR10MB6744.namprd10.prod.outlook.com (2603:10b6:8:10c::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8005.13; Mon, 23 Sep 2024 16:04:09 +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; Mon, 23 Sep 2024 16:04:09 +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 Subject: [PATCH 2/2] selftests/mm: add test for process_madvise PR_MADV_SELF flag use Date: Mon, 23 Sep 2024 17:03:57 +0100 Message-ID: <07d65076cb1632a67043b70bbcec8e450d5b8fb7.1727106751.git.lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: References: X-ClientProxiedBy: LO4P123CA0640.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:296::21) To SJ0PR10MB5613.namprd10.prod.outlook.com (2603:10b6:a03:3d0::5) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ0PR10MB5613:EE_|DM4PR10MB6744:EE_ X-MS-Office365-Filtering-Correlation-Id: 5d73c895-864a-45b0-79e8-08dcdbe95bc6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|10070799003|1800799024|376014; X-Microsoft-Antispam-Message-Info: irAcSunEduZxK15oui3zM+XZAjh4tFJjZgRXp1y5skI8uIiIayvkbycAdsdGUxLoS1e9xIC4H01ioGSF7DIxxYv4D3MHzAVv1rJ+QvOYQwP2jHNJd/AkpkWtvB2m5yDnfGABboCgJLugWGv1+CCKZK/Cm/1wxEg8eYRm5I12ZxWdDA2+oB33SmrY1vEwWFYKQl+32hj5A8d0EoH3gjAVfil/Kc9YxNTdMbWr1F+PSmOo3ZYGjYnvnJn8mcClzFX15q9ZUf4efrFp9w5SkBI9tMZbh2i+cMP4kKvPEBl5qLSdN5BC6SYhCba4mQj4u5nJSLjQcMO3MLR857EXovff/9Mexa6KJVMr/kxIEjUDe9iKWlraGHVLru17ub6JZeg7yxy0SRkMYrCMP4VjvJvMlw8bTflU2ebugiITGlTzhbSVFqdE6JGk+9+JH+rxZawhy4IVGe6QCAkXWeUJjP5Mq6EteFJB3XTYGQTVs1/Va5AqrL/f7wMZSz4uOzHqhUNoz06558b2YMlOqK89J91OD7oZ2aHeat3nCvmDQc7L+arjagDlobvD9JK15tlw2XjOWChV/+u+YyLcep+RVu0iLFT1ig5Mr/6s7B5HJp44uJw0oEcX06RMPsJcD3sCVf3zunKQmDD95jWNmVjeEHnPHgirB/Wk2Mfs7OYWUZkdL8kwV1irdvGrUkJA70neKgXcSVukuxQa89coSK3vAaUh+W3v8+dMQ6geauqhsq+VN+uJpdG8WzMjXOzbFnU0SeA1L+6nW6B+CKBEHBBv246fjzpfkWt76f8cSrMTGxgmDuDiT79mfrdoznS0b8f206/NBzCRG3toCyYpiCjttXh4ORdIqjMvMfvDosgpghPRS/O81l52r4t9a5cdbTvAnVXw/vAF2Z/lc5eBV8hKvaFya/W6jJYI0yUa7oanCYG9wCrweLNcjU5gFiSjVzirzYRW8EeMUNtykWCqMEEBR0OEyZjvD1GSe+r9izYL+hjCiu+t7dzInnLyu9WlB5D1TavtKEcHWm89spJ6uSaLKfQKtOTLI0KRHPb2GoOSiZp3vx7SpAFR2rh7EDkK92M9bvWmTGmEQ+KfvCE4A+23vGSROSm8Tipf0lALIGW5jLnK7rQ07yuvLEWBdWUIAd9F63Mkz17Z3+bquPecdvg/6k/PT2bELDfQoc9p20tpvU+sWWMIQjoa+IVJu/V4//Ir4hadPZMxw1iASHYkQ2mHbI4V+q3fHxIYVpPznbAK9kqSu/V5f8CyMP95x8ueBU2cjLQlkxgKbD/YkmX5sFe8q59YzKAkugQllBSpXyYJpKGsJCv8NFlNOrSc7RLR1FRwrnhjVt5biL3XsmqInIm5+IAzTg== 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)(366016)(10070799003)(1800799024)(376014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam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IALKfPXkN3gbU/4LO5+vEk11OKzmuD3bgdjVexayEKlgEZYHYyamx5SPCZXOcTqcAj80HKXi18uzFO3XZoKQXbLI5x9mpNLcXggp+U6BuaMcp5anD+8jb8bAuA5WP7gEd0sdo/8Vx7BL3aD+foC6yv7xUReEokVTKGFnh82gJaBIZvOn3YRg/usBJ7q3cOWxdYWGMxitZtf2ZolK88j9qt+fu/LTyX+ulvJNSrlZK57+tJ+W7UEDN05hy3ddMoIXNQZTdI= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5d73c895-864a-45b0-79e8-08dcdbe95bc6 X-MS-Exchange-CrossTenant-AuthSource: SJ0PR10MB5613.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Sep 2024 16:04:09.4260 (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: 7oOrepPtiEsAShj2znTUld/aMb/SuKyTg6ulVbeq4uPv1h0fHco+ASi+Tur3H5beodgs/ENXZ7ntbW9ZBiKMYUzAvHyOph67tf1XDiT35aw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR10MB6744 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-23_12,2024-09-23_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 bulkscore=0 phishscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2408220000 definitions=main-2409230120 X-Proofpoint-ORIG-GUID: rrPXbEMX6V55EjXN4jVsHtEw7xKEkHpX X-Proofpoint-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1z8V3+c2Plfy20FBjs2wmD20/ipIwgcCROeLcflaB0TvVKmGpAdK7Hwbx232sRHxAnmcE9z Oet4ZE1g u8wRd6JmV27y1Yz++A710bILJEXs4ZQBuvSNOtZsEhXzsytGgrFNCqQWue4e5YNVpRthlKjE12krRTNREniM0Y2681E3LIZctosZnire1rC7TDO3Ln1Di+clqdtXhZlAL2S2r1oMCeLWpJxR0qqPD6QOV5OFKgU2wNkShXqf2xAJqmWYO5JPkWnWL1mkQKn1Z+b3aVaDNHRaI5DxksdCT+MyeEE1MHJKYTVbcbbZKYmRSUXUxUaHmcPfrVsYfwVQxe6nXrxDxGh2AgEcwngnnjnKneBoDFPXCuIGy2Yf67yOqwl+BxCcUxekeCrFqcdd4H7PRTXQDF2ikYARNodjx6K5AtBozhZNr1XnwyNpSBkGQLg/qOQA3fJQA7h4VY4r3OT/pua1LYTda9UMWfjC7KEHxWShJvr2ziUDsCwBbb2Yo1nghgS0QtJYhgBd0MF73+UsMXo2KTsAxhBnBAsEJtjtm/FRW12GkZPJuWBW38KXywhaY5yoNkuNpc3bft2o3em7qc0IshHHupuXfKtaDDrAHBfmnj+fCf2XsgAgj2p6EMcdzcgL5WczE2Q== 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