From patchwork Thu Dec 5 19:07:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 847962 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F16D2EB1F; Thu, 5 Dec 2024 19:08:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=205.220.165.32 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733425693; cv=fail; b=LHyBSCyRVpDS1izNs7IMtt2JlBkYbQ2YYCXQHLnhax9g1815jOXl5sEdymjH3jAlKBl2bM7iXc9GOk24POGf54V3EQj5srYGdo5SvSFgHrmbWFORKFzezxrhrX9XPX1ybuLrWDNxulblMEQLDzvzDHH/tdRQlDclN99dTkBY1x0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1733425693; c=relaxed/simple; bh=aeH3CIjH6ZUoB5EEA5dLaTU4Jr+BqMkuRQI+nCUtfJc=; h=From:To:Cc:Subject:Date:Message-ID:Content-Type:MIME-Version; b=ciTFAL2oT2KL+vUI6g3Dx6Lg+H0cUUfd1Mj+AgbMKO52UPm6g9yKjGxb+Z8FkgKfwuWN66Zd76cAI+FFh8iNSX6h/uVq+7zh32KDeeSwf4DnLtDb6PvrKE0cSChtAPridraGx6pyn/b/O4OI8Kjf+9KIRfAU12zOEqjGCCxKeW0= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com; spf=pass smtp.mailfrom=oracle.com; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b=XnST4onY; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b=MBgoqD7r; arc=fail smtp.client-ip=205.220.165.32 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oracle.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oracle.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=oracle.com header.i=@oracle.com header.b="XnST4onY"; dkim=pass (1024-bit key) header.d=oracle.onmicrosoft.com header.i=@oracle.onmicrosoft.com header.b="MBgoqD7r" Received: from pps.filterd (m0246627.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4B5J7ScE004597; Thu, 5 Dec 2024 19:07:59 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=cc :content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to; s=corp-2023-11-20; bh=Jw7+No8Q8NJt3qg4 bciq81qxw2MOHFfpRoOoPMtFOaQ=; b=XnST4onYCTNeekdbGmTzgvd94m4memY7 /DlrhPkup4oe8pIJsdEqGvF+hENtYgjN5q5IBrB5W+Z3aT4mD7VJD93yLLdGK5ul sopHm99ea2FdP7S5iWPCiRXqh92t5ZQnmxaNQ7FaZyEhLbNM8ImmIiZ1ibdWc/6I 9xHV7ifhoPyT1BH0lBp1IizuzC4ZyudTFKop7I9/bMEjF8+hwY4y+qOgk0AFgCY0 5rFwsT9HeJDR+Rlra/gnrMwPEFPN+lm/gEoHJYhIwwLzhy5TWLF/yIuqfdWlM9+2 aX69NJK8sE2XCaKS3wBmmO+0rIlCyCPCxtVC0ZjU1Kgtw38SPuQ9Rg== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 437sa04015-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 05 Dec 2024 19:07:58 +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 4B5HtuPr011691; Thu, 5 Dec 2024 19:07:56 GMT Received: from nam11-co1-obe.outbound.protection.outlook.com (mail-co1nam11lp2173.outbound.protection.outlook.com [104.47.56.173]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 437s5bat5e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 05 Dec 2024 19:07:56 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=zLA9/byjZ3NppYz7JwR1KYfQJYGMkQdsdIX5prVeRSVukJzPBxlZ7rlXFUzNswmCNtlcswxC9bwRbwZ1F094oGyscoRH/tjlLMHN4bIvth1+a/C7o6aEumdwsCliQKnic92HE/voaPKR86vb+OgrOozYNmWDdzK6RnIjRXnyzdj5Vk4k5lmdtHPgdbOugvhDkQwVHz/Z6x15b1IXsw2P+fRy5zHspJiorDgreWkOuz5IB0W4NDSjezO+Yk+bfk/T44WHhQROGYLrZFuvTqSOuBWbY1qUXAUU7HSCBNWsWkytrGMXOOdOk79yVPYhFNrcf6NI6jTCSpY9XL077ny90w== 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=Jw7+No8Q8NJt3qg4bciq81qxw2MOHFfpRoOoPMtFOaQ=; b=nPJ4wL/bQ8Ta3RXriBSWVaTKqH7RZ0638NtoRBUlfHJMuPUR+rDTP9GEFcxOOHkzNyjhRTNI6qb41AFRuKu5iBGFwP2Ctv2Bhha3kzm0Vi89GgiQIashNNMGtYsvqqtUQfTh6QiICs+VALUhpsD47HWv7FFOrQkhQvmMICdm+iZ6APkCogXTKlv2BA3oZ+ZT7agUGWY82M+IIZ9G8ld+CyP4DiQaWYsEgXO3i153ky4pFLEkKXAyNgA3mvsx1GFBLSGtERuRGtsF9k6xe/8ZAs19lQjUCL8ZzPpGXWhOX0XbnN4kF4ApTDqGQ5IocpMdAzVSfa+z601CQwcJLzuDYg== 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=Jw7+No8Q8NJt3qg4bciq81qxw2MOHFfpRoOoPMtFOaQ=; b=MBgoqD7rlWlcq8hBraUn5g4oBf90RfDynAeiKGrV26UMsPvYrMZFQR0bFQ49KfsY/ddYCs1KTjTSgCruhPqHEw++IJgDg9ioxJ5wo4iyjM3R4Gln6KEYQa3lWcq6F6MSjlsnPdLsQ7Pp7VrkXZbhN76189MxXG+2Q01MV4YXExU= Received: from BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) by PH8PR10MB6624.namprd10.prod.outlook.com (2603:10b6:510:220::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.12; Thu, 5 Dec 2024 19:07:53 +0000 Received: from BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9]) by BYAPR10MB3366.namprd10.prod.outlook.com ([fe80::baf2:dff1:d471:1c9%7]) with mapi id 15.20.8230.010; Thu, 5 Dec 2024 19:07:53 +0000 From: Lorenzo Stoakes To: Andrew Morton Cc: Shuah Khan , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Liam Howlett , Vlastimil Babka , Jann Horn Subject: [PATCH] selftests/mm: add fork CoW guard page test Date: Thu, 5 Dec 2024 19:07:48 +0000 Message-ID: <20241205190748.115656-1-lorenzo.stoakes@oracle.com> X-Mailer: git-send-email 2.47.1 X-ClientProxiedBy: LO2P265CA0448.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:e::28) To BYAPR10MB3366.namprd10.prod.outlook.com (2603:10b6:a03:14f::25) Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BYAPR10MB3366:EE_|PH8PR10MB6624:EE_ X-MS-Office365-Filtering-Correlation-Id: 75295215-0925-4849-4d8a-08dd15601ec5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|1800799024|366016; X-Microsoft-Antispam-Message-Info: kKoRxdyMd4PYgDvmsJfw/c1oWrKe8Aw3NbUrtLpbpXHVypXaWHg5hUVS4L1/4CSKMkXNMYGGDjhui7ki1E6dSmZxpjVgCtzCUCpFkmbLx9KLkRwb6q1UDNFJX5Kg23VcUCFCqRm0lpNzJmssjZ/phgu4tGazJcqOmf8J+RUtGj9kGZt9L3zM8lHeI7mdU0AcORGMz6TLUXQgj0wa+vA4/Cl3mybi47XwIuTiputH8xUemKWbUrdr7wmzOm+c2QxSO6wKFInBGI8frpXgQW1pvm4QryO1rn2ClRU3Q4TQ3UykalYzTFHzhqsvzKjXesAti+264B+ouui7W6iGj4+fbfwEa0TiPiZPFL9RdfbA+wrsRGqwV5tohrzGFBWSWuevTD4v7V7qgSJMC3aqnvXpDYhPRplxe5yHG0B1TeQ4j0p54XFd/xTBs4Ls1UCXC6Rwyop/k7NC9fZTgwevaZRj2EDtNFPmtaN+rYRTDIucXWbNKPYTaWuwQXsx1Lmi/X18+jeVg002VIQb3IHVtpqzXaE8bmP+w6x6EvaUFGsy2RYnYIzbqqIgRroPIQQQnL6obfEhKvhQ7KWetjShJE4ujrs4mTbrbx3BFHgOsZUIGrjhagiqd4TZDIyh70HaJ5LGS39ekVEoUNwv9WjE7Rvb4zSvMb1JNomp3kro4/7qJMxPQMB9fi5eqFczMP9pWWHT4w1Wzyga+d7TWNjmnwjUqU9mhTaL5sIaylmkCRxeXb3dz3y84bfW2+icLycRTWv3NGWbmLk/3BZ0R5Lmr1S7ctogTyS3b5lgDwru99logRYzoEpAczqHRzii0IFVNtf9bcW599UfPfdVYtpGxHvSxR8jMt2akhs5CTXXO0fHY4uFX/kmimfXzlYllINsg0vcXP51kNFmLTrpHg0rw06/RZOU/je5oxxc9RKJZs/sCzr2V2bW8gkD2atOL6TinbpOPse/ng4W+0SzSAnwbCTVIr3fOPczcT3K1YZLmCgMlcwGAxHYv294lhtPG/lGSlsbCTsV6ltF2OIqfuwQ35is9oW7jj5D1b36/fRpJfARXEifNggoDvqQV/y0opauaadS5wOJiDx3kNNq5xa4djLFH+iCvIw5aBVXw+dJcaJYpCPSFUZ+uLACteBYZY2KwR2ycwNVq8jcDyyvFeLYeHi45Sq3w4kk3FxL1BewX+gZ+GOwUIdvyxMFPAt13s3QY3aM5YuEFg2lSEmnkbasJb3F/DYQKL6XoK9uxoGD4G9H4kdNMcIEZM+CyoLNncTA8TliEqHYa0p8nLlJJfQDPg/anjecQsGHcEXKfbj81y+d20mNX4h72zWtkL2iLmYRWkeKCsBimGGW+ctPMXE+nGmpeQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:BYAPR10MB3366.namprd10.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(376014)(1800799024)(366016); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Fc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y8Pe9B4C1CSleDASYLOYXTa5yNLzpdQJKrCrVikJ6ZueT/pqViPtuscQsE/6aFZhMITRGhwLo5eZoP/OnrrVvMD7R6oM7IXVj1sVIAEh5IxiMJtjXsAXe0B+thJ1bs8XDzGivCv5mvk98= X-OriginatorOrg: oracle.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75295215-0925-4849-4d8a-08dd15601ec5 X-MS-Exchange-CrossTenant-AuthSource: BYAPR10MB3366.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Dec 2024 19:07:53.6183 (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: VJ1qhSebHeqdvgLJF9zMKyXusZOsivoBvUQDh8nM5lODy58RHjly+XC2RT31GE88B5lAn6OHyM5kZ3omWygn/Jv7qjG8Zy9FLctC4KM+lzA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR10MB6624 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2024-12-05_14,2024-12-05_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 adultscore=0 mlxscore=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2411120000 definitions=main-2412050141 X-Proofpoint-GUID: amCL09qtX8V8AJ7CAZXc1RSqEfUmPS9g X-Proofpoint-ORIG-GUID: amCL09qtX8V8AJ7CAZXc1RSqEfUmPS9g When we fork anonymous pages, apply a guard page then remove it, the previous CoW mapping is cleared. This might not be obvious to an outside observer without taking some time to think about how the overall process functions, so document that this is the case through a test, which also usefully asserts that the behaviour is as we expect. This is grouped with other, more important, fork tests that ensure that guard pages are correctly propagated on fork. Fix a typo in a nearby comment at the same time. Signed-off-by: Lorenzo Stoakes --- tools/testing/selftests/mm/guard-pages.c | 73 +++++++++++++++++++++++- 1 file changed, 72 insertions(+), 1 deletion(-) -- 2.47.1 diff --git a/tools/testing/selftests/mm/guard-pages.c b/tools/testing/selftests/mm/guard-pages.c index 7cdf815d0d63..d8f8dee9ebbd 100644 --- a/tools/testing/selftests/mm/guard-pages.c +++ b/tools/testing/selftests/mm/guard-pages.c @@ -990,7 +990,7 @@ TEST_F(guard_pages, fork) MAP_ANON | MAP_PRIVATE, -1, 0); ASSERT_NE(ptr, MAP_FAILED); - /* Establish guard apges in the first 5 pages. */ + /* Establish guard pages in the first 5 pages. */ ASSERT_EQ(madvise(ptr, 5 * page_size, MADV_GUARD_INSTALL), 0); pid = fork(); @@ -1029,6 +1029,77 @@ TEST_F(guard_pages, fork) ASSERT_EQ(munmap(ptr, 10 * page_size), 0); } +/* + * Assert expected behaviour after we fork populated ranges of anonymous memory + * and then guard and unguard the range. + */ +TEST_F(guard_pages, fork_cow) +{ + const unsigned long page_size = self->page_size; + char *ptr; + pid_t pid; + int i; + + /* Map 10 pages. */ + ptr = mmap(NULL, 10 * page_size, PROT_READ | PROT_WRITE, + MAP_ANON | MAP_PRIVATE, -1, 0); + ASSERT_NE(ptr, MAP_FAILED); + + /* Populate range. */ + for (i = 0; i < 10 * page_size; i++) { + char chr = 'a' + (i % 26); + + ptr[i] = chr; + } + + pid = fork(); + ASSERT_NE(pid, -1); + if (!pid) { + /* This is the child process now. */ + + /* Ensure the range is as expected. */ + for (i = 0; i < 10 * page_size; i++) { + char expected = 'a' + (i % 26); + char actual = ptr[i]; + + ASSERT_EQ(actual, expected); + } + + /* Establish guard pages across the whole range. */ + ASSERT_EQ(madvise(ptr, 10 * page_size, MADV_GUARD_INSTALL), 0); + /* Remove it. */ + ASSERT_EQ(madvise(ptr, 10 * page_size, MADV_GUARD_REMOVE), 0); + + /* + * By removing the guard pages, the page tables will be + * cleared. Assert that we are looking at the zero page now. + */ + for (i = 0; i < 10 * page_size; i++) { + char actual = ptr[i]; + + ASSERT_EQ(actual, '\0'); + } + + exit(0); + } + + /* Parent process. */ + + /* Parent simply waits on child. */ + waitpid(pid, NULL, 0); + + /* Ensure the range is unchanged in parent anon range. */ + for (i = 0; i < 10 * page_size; i++) { + char expected = 'a' + (i % 26); + char actual = ptr[i]; + + ASSERT_EQ(actual, expected); + } + + /* Cleanup. */ + ASSERT_EQ(munmap(ptr, 10 * page_size), 0); +} + /* * Assert that forking a process with VMAs that do have VM_WIPEONFORK set * behave as expected.