From patchwork Tue Jan 14 16:06:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13938945 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 344B4E77188 for ; Tue, 14 Jan 2025 16:07:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD1726B0085; Tue, 14 Jan 2025 11:07:13 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id AA8CC6B0088; Tue, 14 Jan 2025 11:07:13 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D3D7280001; Tue, 14 Jan 2025 11:07:13 -0500 (EST) 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 6DC106B0085 for ; Tue, 14 Jan 2025 11:07:13 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 1E28FAF963 for ; Tue, 14 Jan 2025 16:07:13 +0000 (UTC) X-FDA: 83006536746.05.3BC6985 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf16.hostedemail.com (Postfix) with ESMTP id 17C0D18000C for ; Tue, 14 Jan 2025 16:07:10 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b="qIV/Sqi/"; dkim=pass header.d=linutronix.de header.s=2020e header.b=TODIgtjD; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf16.hostedemail.com: domain of t-8ch@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=t-8ch@linutronix.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736870831; a=rsa-sha256; cv=none; b=hlMvQuVaVI4zv6HrqTXimGKZJMSGqhGFRr6CWy2QGCZA0vfOyTizDL97aCS0a3YgPwwrdU YLHxL1Bj0nUVDwuxtPOv13XFCx8KxYrcRiaO8xLechJHoPpKPjIIV54Enq0+OaCbwFJN3C 4eOx46e8Irgm0dPGw/9HYlqX4WkWdSY= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b="qIV/Sqi/"; dkim=pass header.d=linutronix.de header.s=2020e header.b=TODIgtjD; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf16.hostedemail.com: domain of t-8ch@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=t-8ch@linutronix.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736870831; 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=WMw4Pqpozqcj+M46rlKOQ3x4xAheM6IvB7ridCkcbVk=; b=H96k9eVddUdgKJMOOB1uBEGcPQISmE4KIi6BUWyeWdC8mWdzACpkT1t62aUI/bk41e+7nx bzIRMkWnyDqHXYfn7gZaRrftTiYqsYykmiIsvmZu4/UO7CkznHUsZWNJRmuwS1PpbErG77 gfirxvHIqbusAHFiW9GrZ0TuA2GphF4= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736870829; h=from:from: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; bh=WMw4Pqpozqcj+M46rlKOQ3x4xAheM6IvB7ridCkcbVk=; b=qIV/Sqi/Yoks2I8Nqn0d21+mfb/g+17wevTd7eWnB9iPPJgxpq/hvMWR4Cbcrtv3Ad9LKt rpHmgGdMS3mWZSlTBuJIfppw2+TmA0G0hkrFDpuRY0u0rrgAyfhuqS5vNbkM0FfR3Q4Q5k 2OBXZeTyiCU/hzd++lBA+X2QpAVp2fhYJPjpXzNx3JHRKjjoDhZ9rs29ROVEVKzwtF6k+e Yanq0CIZvkDJMrtPKQs0voJpfqzZ3brLHAeaEsr+Wjb/Mef7dzU+WIjQZXrzuS2hR4+HcM WF8mgBXS9+7jYWCODWyklQAvZCyt/2ymxndgYqyMG/hUWGRmV1/US3rFsJqwEA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736870829; h=from:from: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; bh=WMw4Pqpozqcj+M46rlKOQ3x4xAheM6IvB7ridCkcbVk=; b=TODIgtjDbHTyshHRlgReOZN8Eur6i1Ig6fNAmzvJVWuIRBv56dUMgA9GNPCFURWWrKYHmh 1tnnWGa9evG4r7Cg== Date: Tue, 14 Jan 2025 17:06:45 +0100 Subject: [PATCH v4 1/4] selftests/mm: virtual_address_range: mmap() without PROT_WRITE MIME-Version: 1.0 Message-Id: <20250114-virtual_address_range-tests-v4-1-6fd7269934a5@linutronix.de> References: <20250114-virtual_address_range-tests-v4-0-6fd7269934a5@linutronix.de> In-Reply-To: <20250114-virtual_address_range-tests-v4-0-6fd7269934a5@linutronix.de> To: Andrew Morton , Shuah Khan , Dev Jain , Thomas Gleixner , David Hildenbrand , Anshuman Khandual Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1736870827; l=1679; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=CZpuloUjytwkHL2aPWwv10o9ubxrDZ5i+6K2DZNoL+M=; b=GqgQ3xml2Bf4VP4ld+L2fBtKx7TbedcU6otFZT9oJT34c/htO60k0G8UfJ7KMpb3YK+QdSVhb 7XeerjJ2ST8BpBkEE9OUCb9tJz8Maa+jIEBAF1TCFkRLjAjlZP85Dy1 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Stat-Signature: zyamn6iy1s8jtcuenfbb4rubi1rk1gc3 X-Rspam-User: X-Rspamd-Queue-Id: 17C0D18000C X-Rspamd-Server: rspam08 X-HE-Tag: 1736870830-999262 X-HE-Meta: U2FsdGVkX1/QBUlGv3mI9H+mcUKWfGg0YwtmzejjGFljwsLI8BxkOtXNnbINve6vBZ2iXykgaNMaYu2ctJYFzP/QTA1bMMKySizrbwFE3uVDeCjTkkCPDil3/G69EB0iidut1GhkzAH9o8a655SY/+IZ89BQpqEOvd8OgnPyaoVsdlRx+gPmhTc/UPaaWlFkJVrmMBSfZBmMwXivPkmF4sGIDSABSKJYmC/ZGbyulSUnIh2hYrtD3IYmDdi+xv2cm0BNFz7is7dsDzz6QdorIzSvNXFE9HCV5JgR+T4g20RY9z/LFbxls0v21NuCdR5ZCkJpnP9xMMDTDz8ty1rpyxzEA9V3kPmc/4nfvVt0OzXpJVP0ML3ScpSwF4Z28EMONO4TRmtM1dRveaMe3gbFzuQjBqAkhaxLB4eCUJQnMAipyCb28DL5xIBenWFH7uwf57jsLHE+af1DwqDOiqp3Jo51iBEoDuZgsJQ+G8GDFEKbXSLyPmy4LdIujo7eWRCZdEGo6BcwC81yKsQw1njjUyKFY6MAnvpkmz+Jk7udO4DQMAW5nn9I2FEfkZ1/X8upVZmJO65xNScdXFMbrVh1f2GJ4BsDTdZahNp4kzVZiXjLsFZODGPZ7rm1VMKFflueoj4dEhCQ9lHIchmW65Rkc4QUPdQNYDSbbaHXy74vITl04m249fEvG+gP3oOs/VZsohN22gb1tMn6OCSnvHsc6x/GEb65Sy3RBE4ZNToxd86GSMVgWNJ9qmvMMK5eNQoSXOEvd+DGGq5CKl4I5q+m6yEPeZMZcXe0HIy7mn/RiHEo+Xf/OfpMdCIA0PJg4zgZ+dtz9qumKLOcIJojjZehhJ+LbQRpHV9Vd3WHsdhB3zUdd3FnKtDCjBThtv+7peFLk98Tx36aVKbEpjd80epxw8Vas7dCb5mLVmdbrfixQsf2R5Av3YZ5g/QpCXKNuFIe5mL+uljAVmKGx/jSqUL iWDBH6+c zTEfNtn6ok+FFA3GCXtymJ7f1x/S7/BFIVH436bKn9g4qwyMyDVshwMcibrHh+Fn6L1QrBiuHnQQhcyNYZEgwl1/KeP6RV/sgZbIm08viT546pQCEBYU4/lmmyp2p8X/jOi2mc/tvcWmwXHmuTROL7UFqb4B4qpmU1R3cMT3Dn6koISPQFCPOen4NfU0rYxVXOblQ54TkgyedQnhqDSdbImQ6JTnr/EDMEeYXQH9Dnyn5mwnQYOahs5qW2LEELNl6D/s+m8+sRCmgI+hnFv+6jnFTTuTuyA4aOP6dQ1Pufcv32KVdlucxAEKC/XpaF31y/1bdMVrXw4Af8jwoyd5+RGlfIMT24JJs7uhDBqGyZltRbk7Omeq7psdnUXYL8FBZ7Q2jA3qgndrIN9pOK4jRzEkAhWP9fUpqfblufJKLjQeANT2rUfiNDSnFZyb4VGdexelsq838haVqB5bZahEdsFi0nGtPsUTt/bjuZ0NCIDR1r9tiH07J2ifsQtLnEGW9h+sFMQHR7XAeTabsNDpiciI/NQ== 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: When mapping a larger chunk than physical memory is available with PROT_WRITE and overcommit is disabled, the mapping will fail. This will prevent the test from running on systems with less then ~1GiB of memory and triggering an inscrutinable test failure. As the mappings are never written to anyways, the flag can be removed. Fixes: 4e5ce33ceb32 ("selftests/vm: add a test for virtual address range mapping") Signed-off-by: Thomas Weißschuh Acked-by: David Hildenbrand Acked-by: Dev Jain --- tools/testing/selftests/mm/virtual_address_range.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c index 2a2b69e91950a37999f606847c9c8328d79890c2..ea6ccf49ef4c552f26317c2a40b09bca1a677f8f 100644 --- a/tools/testing/selftests/mm/virtual_address_range.c +++ b/tools/testing/selftests/mm/virtual_address_range.c @@ -166,7 +166,7 @@ int main(int argc, char *argv[]) ksft_set_plan(1); for (i = 0; i < NR_CHUNKS_LOW; i++) { - ptr[i] = mmap(NULL, MAP_CHUNK_SIZE, PROT_READ | PROT_WRITE, + ptr[i] = mmap(NULL, MAP_CHUNK_SIZE, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (ptr[i] == MAP_FAILED) { @@ -186,7 +186,7 @@ int main(int argc, char *argv[]) for (i = 0; i < NR_CHUNKS_HIGH; i++) { hint = hint_addr(); - hptr[i] = mmap(hint, MAP_CHUNK_SIZE, PROT_READ | PROT_WRITE, + hptr[i] = mmap(hint, MAP_CHUNK_SIZE, PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); if (hptr[i] == MAP_FAILED) From patchwork Tue Jan 14 16:06:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13938947 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 7B6F4C02185 for ; Tue, 14 Jan 2025 16:07:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4437B280002; Tue, 14 Jan 2025 11:07:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3F1F2280001; Tue, 14 Jan 2025 11:07:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2E0C2280002; Tue, 14 Jan 2025 11:07:14 -0500 (EST) 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 10A62280001 for ; Tue, 14 Jan 2025 11:07:14 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id AE984160B31 for ; Tue, 14 Jan 2025 16:07:13 +0000 (UTC) X-FDA: 83006536746.18.5F2C469 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf25.hostedemail.com (Postfix) with ESMTP id BFE1EA0023 for ; Tue, 14 Jan 2025 16:07:11 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=MbCGZCKp; dkim=pass header.d=linutronix.de header.s=2020e header.b=DZpT+FHa; spf=pass (imf25.hostedemail.com: domain of t-8ch@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=t-8ch@linutronix.de; dmarc=pass (policy=none) header.from=linutronix.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736870832; 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=HHdz6D6xQVTO4bkE6hrOmhg63h4CtMukNog1b9dscsc=; b=soWA3BLcpvbuXz3a4BwtOYBxQffsvWM0zjqf/LyN8nt4hhZES7RKkz7UPZ5JZNULvfyZzK +e0SNbyyupOlduQbLKnn7iKFA9PDwIuW1Ba4EhkLaXCFketM4RbJUcJyPHir0zlDL296YS w1KCIU3Jv2xGmQaSOCbt5x90E01e5J0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736870832; a=rsa-sha256; cv=none; b=0KhqU6NwZeulDTzIqzxDKgmktvVREf39syVhz+pkQ67tALHMimEQdbIoudJTv7DFKtdq4A i2aL3tJnYhfayy96opZdjrmrNHFqNp44R7Hf247Xrg7iMLilArB2wsmi0JasK4QpAJ3w3k 9z9SgPAChG4o01LQnsyuChLCtzE4usk= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=MbCGZCKp; dkim=pass header.d=linutronix.de header.s=2020e header.b=DZpT+FHa; spf=pass (imf25.hostedemail.com: domain of t-8ch@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=t-8ch@linutronix.de; dmarc=pass (policy=none) header.from=linutronix.de From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736870830; h=from:from: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; bh=HHdz6D6xQVTO4bkE6hrOmhg63h4CtMukNog1b9dscsc=; b=MbCGZCKplIQcKN5TErGlMPeR08toq1UH+O+tIlF++i2Erh1tWc+m0yFL5vxQwEjI91VGr5 nEXjaAP22h8s3GzjqTRUPGezJU2lYE8nRTK66/BKA9dJjJFS/tLlQaXq5qX7xzRBe/OsQ5 8ffkqjWJIubzs8nRGKQ8lSH5hzyOLmkgVNEHgUAzU0RRChCdX0y4kPtVwskHkkKV4p6vx+ pyr2paCgjw7yCD+VEME5M42BMvTfzpM8RRfapSav7dHT/SM5tuSAhXzG04Pm3NqWMiv1w7 bTd7k2sWsm0dMHrr1g+1b5ewaeel10i3eP6snHwA9z2jWZTJjpQ6YTGvrra4aA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736870830; h=from:from: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; bh=HHdz6D6xQVTO4bkE6hrOmhg63h4CtMukNog1b9dscsc=; b=DZpT+FHaDSddwumeiTKVkMQotTZFJIFvJnQAW3V+YEbJDHdXS1YkTG6jZzapE/XjkvDueA P8QdLYx03nCk6zCg== Date: Tue, 14 Jan 2025 17:06:46 +0100 Subject: [PATCH v4 2/4] selftests/mm: virtual_address_range: Unmap chunks after validation MIME-Version: 1.0 Message-Id: <20250114-virtual_address_range-tests-v4-2-6fd7269934a5@linutronix.de> References: <20250114-virtual_address_range-tests-v4-0-6fd7269934a5@linutronix.de> In-Reply-To: <20250114-virtual_address_range-tests-v4-0-6fd7269934a5@linutronix.de> To: Andrew Morton , Shuah Khan , Dev Jain , Thomas Gleixner , David Hildenbrand , Anshuman Khandual Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1736870827; l=4005; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=82ZDLn8Ie616VeVZksZ+ubTOfL8+PSxtmk+JZNkNkyo=; b=oPv0Faclo57WmFtlCTOx25wxfWPHxrzmgr+oQuEWlAm5dMTgsvyf6eWeOshX+7AJRPEXs6tq8 xlW9TYQdyCzDR2m8rRreQCxCAWiDTX+sQh/R7IY2xopSEVQPFTGyUIC X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Rspamd-Queue-Id: BFE1EA0023 X-Rspam-User: X-Rspamd-Server: rspam07 X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ZxJCrZy+Cy159LIbPtSl9oBnO+HrsO5citd9KFp6fzE2dz2csw+9vyvFLitl2CTEDJosilz94rPHYYg1ViL4KgCLTnfZuWGzeK4aWkI1IBmommv4aStqVPYkOJ7wi0QKUMfVCJCBIKvFLPE9n1+7dKlFwflxFl3twM6Le0CRytcyCUWOGlLhX34q4Lp4sQiq/+hVFrvKUU1t02RxB0mFL5dzWbLDKjDOn0Bt8BLmdU23j+4zjDITeoOzSilL6R1YceRYA+2lHECOoyzl4qzbyrpxgY8wEJuVsnGOOvBxevhr8SsYZhf3ql+jTNUEUf5hIKi8VKw8jq+eXpzfRyoSRL8YJX1XEch8HLwjangG2maWCxmYz2oe4TJzABURB4Wwfkwwzem3bb4ykO1DatXpdE9524dmwk12wCQJC9PN5BftY1UubAN8cXtMdcE6LxHuMRC1OGM/kJ+58m 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: For each accessed chunk a PTE is created. More than 1GiB of PTEs is used in this way. Remove each PTE after validating a chunk to reduce peak memory usage. It is important to only unmap memory that previously mmap()ed, as unmapping other mappings like the stack, heap or executable mappings will crash the process. The mappings read from /proc/self/maps and the return values from mmap() don't allow a simple correlation due to merging and no guaranteed order. To correlate the pointers and mappings use prctl(PR_SET_VMA_ANON_NAME). While it introduces a test dependency, other alternatives would introduce runtime or development overhead. Fixes: 010409649885 ("selftests/mm: confirm VA exhaustion without reliance on correctness of mmap()") Signed-off-by: Thomas Weißschuh Acked-by: David Hildenbrand --- tools/testing/selftests/mm/config | 1 + tools/testing/selftests/mm/virtual_address_range.c | 33 ++++++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/mm/config b/tools/testing/selftests/mm/config index 4309916f629e36498efb07eb606b2f0c49ee6211..a28baa536332f3fcfb1b83759b5fbb432ae80178 100644 --- a/tools/testing/selftests/mm/config +++ b/tools/testing/selftests/mm/config @@ -7,3 +7,4 @@ CONFIG_TEST_HMM=m CONFIG_GUP_TEST=y CONFIG_TRANSPARENT_HUGEPAGE=y CONFIG_MEM_SOFT_DIRTY=y +CONFIG_ANON_VMA_NAME=y diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c index ea6ccf49ef4c552f26317c2a40b09bca1a677f8f..386e4e46fa65b98af78dee4bb30144eb2b51f528 100644 --- a/tools/testing/selftests/mm/virtual_address_range.c +++ b/tools/testing/selftests/mm/virtual_address_range.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -82,6 +83,24 @@ static void validate_addr(char *ptr, int high_addr) ksft_exit_fail_msg("Bad address %lx\n", addr); } +static void mark_range(char *ptr, size_t size) +{ + if (prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, ptr, size, "virtual_address_range") == -1) { + if (errno == EINVAL) { + /* Depends on CONFIG_ANON_VMA_NAME */ + ksft_test_result_skip("prctl(PR_SET_VMA_ANON_NAME) not supported\n"); + ksft_finished(); + } else { + ksft_exit_fail_perror("prctl(PR_SET_VMA_ANON_NAME) failed\n"); + } + } +} + +static int is_marked_vma(const char *vma_name) +{ + return vma_name && !strcmp(vma_name, "[anon:virtual_address_range]\n"); +} + static int validate_lower_address_hint(void) { char *ptr; @@ -116,12 +135,17 @@ static int validate_complete_va_space(void) prev_end_addr = 0; while (fgets(line, sizeof(line), file)) { + const char *vma_name = NULL; + int vma_name_start = 0; unsigned long hop; - if (sscanf(line, "%lx-%lx %s[rwxp-]", - &start_addr, &end_addr, prot) != 3) + if (sscanf(line, "%lx-%lx %4s %*s %*s %*s %n", + &start_addr, &end_addr, prot, &vma_name_start) != 3) ksft_exit_fail_msg("cannot parse /proc/self/maps\n"); + if (vma_name_start) + vma_name = line + vma_name_start; + /* end of userspace mappings; ignore vsyscall mapping */ if (start_addr & (1UL << 63)) return 0; @@ -149,6 +173,9 @@ static int validate_complete_va_space(void) return 1; lseek(fd, 0, SEEK_SET); + if (is_marked_vma(vma_name)) + munmap((char *)(start_addr + hop), MAP_CHUNK_SIZE); + hop += MAP_CHUNK_SIZE; } } @@ -175,6 +202,7 @@ int main(int argc, char *argv[]) break; } + mark_range(ptr[i], MAP_CHUNK_SIZE); validate_addr(ptr[i], 0); } lchunks = i; @@ -192,6 +220,7 @@ int main(int argc, char *argv[]) if (hptr[i] == MAP_FAILED) break; + mark_range(ptr[i], MAP_CHUNK_SIZE); validate_addr(hptr[i], 1); } hchunks = i; From patchwork Tue Jan 14 16:06:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13938948 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 558ADC02183 for ; Tue, 14 Jan 2025 16:07:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB8CF280003; Tue, 14 Jan 2025 11:07:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D8FB7280001; Tue, 14 Jan 2025 11:07:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BE13F280003; Tue, 14 Jan 2025 11:07:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 961B0280001 for ; Tue, 14 Jan 2025 11:07:14 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 54F1A1409AC for ; Tue, 14 Jan 2025 16:07:14 +0000 (UTC) X-FDA: 83006536788.03.22AB1A6 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf15.hostedemail.com (Postfix) with ESMTP id 4B6C8A0020 for ; Tue, 14 Jan 2025 16:07:12 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b="TYd+3SM/"; dkim=pass header.d=linutronix.de header.s=2020e header.b=TN14Vn5s; spf=pass (imf15.hostedemail.com: domain of t-8ch@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=t-8ch@linutronix.de; dmarc=pass (policy=none) header.from=linutronix.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736870832; 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=jc6lPJWBXfz2WyOhO1yRIjUxMkwiFWRg7L1C1Eo7ZW8=; b=yvqRz0SIfRguB8AZA7Aonrc8KBmU0BiNefvy+4hWCf0stoCZTTZyqkyydpkTAK5lJnpTal BEypIHJCagkpb8dkqSnUq5SEzT0GhmlJ8mGDRUdVxhYCf24+E4ES91KgyrH2CxrNleeKZu Cxx4UjDHe1RAPvt3Si5iGmRqOor5900= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b="TYd+3SM/"; dkim=pass header.d=linutronix.de header.s=2020e header.b=TN14Vn5s; spf=pass (imf15.hostedemail.com: domain of t-8ch@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=t-8ch@linutronix.de; dmarc=pass (policy=none) header.from=linutronix.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736870832; a=rsa-sha256; cv=none; b=G0OEDaq0WtTxNpbPXUSzrEhteHECp3PxD/iwmjnoOOf3R8NNz/xa41FspwNGemdVBQae26 zfPiZ6YTEAkHQkhItn0utqXPG218EgOCUYPtMHChhK5QH1SrH0qQe439S3P588PiS+KTqd 5HsN0B3PEPkJiDuvxvYWgovzCw4IPcU= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736870831; h=from:from: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; bh=jc6lPJWBXfz2WyOhO1yRIjUxMkwiFWRg7L1C1Eo7ZW8=; b=TYd+3SM/Zzv8AeGJDtkHtFw5Zc07ZYkaqucBnYDTJBEwsbwaWlXHvqvHWkDlu72h3Z6Wd1 TmTfIV0GaDhM/tD898JAabg9DEIa43vvV8rhJfw4ELBS27eASXQVxqVX7R5qvadW1uZ3SJ 7ClAvHdSkHaoJYIiNYtUJL8a2ifV/z52TGJyCJx+gFdqPZUIy20DhrWGVzN58UuoTMRhF6 aCS4pVMfvt1vT7yD1Y1F6+MtAEQmRktdAuc1vpPaerfqKk890qiemIJa7domNDepp1pdvU A8IafqZZmYsoTwklNjujlNr9NLKnGF8LOKGgvr9OZZJi+8rGx/R2VCR7vvxq3Q== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736870831; h=from:from: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; bh=jc6lPJWBXfz2WyOhO1yRIjUxMkwiFWRg7L1C1Eo7ZW8=; b=TN14Vn5silJWC6WJq8XDyL63P8p11yF1750ISYCYPkpibeDxk2BH0U6KeJuuQECo7vLBzn x7BU9R0ToQjc6rAg== Date: Tue, 14 Jan 2025 17:06:47 +0100 Subject: [PATCH v4 3/4] selftests/mm: vm_util: Split up /proc/self/smaps parsing MIME-Version: 1.0 Message-Id: <20250114-virtual_address_range-tests-v4-3-6fd7269934a5@linutronix.de> References: <20250114-virtual_address_range-tests-v4-0-6fd7269934a5@linutronix.de> In-Reply-To: <20250114-virtual_address_range-tests-v4-0-6fd7269934a5@linutronix.de> To: Andrew Morton , Shuah Khan , Dev Jain , Thomas Gleixner , David Hildenbrand , Anshuman Khandual Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Developer-Signature: v=1; a=ed25519-sha256; t=1736870827; l=2915; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=gR157o96GOD5Fi5AXkbUAbIHuV8f9whd7ZV2AeOIVu8=; b=w4OIeFsyazqsWCb42afv7zGrsXsPmDhiUXiU0G/0S+jHi5uqcgpHGFHrnJlu+GKmwp+XkwCiX TMob5JaYSQdDteTjGBmt3vMUIt6mJRqhvM03Tv7+D6ZfV2KKG4mQuPX X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Rspamd-Queue-Id: 4B6C8A0020 X-Stat-Signature: q64usgtcjopdb63f85fwuce3ps89ydgj X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1736870832-290620 X-HE-Meta: U2FsdGVkX191X9nHYcYEvBnE0ncPBCraomungHbUWsFsc83Ey0q/vSZDFZiTDEXnNzq/cMOVDioOtP32LaNh1WZCln80OCsmdsLFTgzWVR+XkuX0PxDFlnoE+xToRnr1LM365jX9rDrBh2xTGV3xnpPs7e5jw00AeyshRaLA93MJq43T2mJNm/DnY8LZxrMa9ax3RBXZoaVLSVegXNR22j7oCMAYEpAYIX9WpTJ4KTctDMhU01XL/5eUxRHQVoFoejVIjcufvF7dS2c+BX4XZ9oZy/7Y5zPuoPs31WejlGoPg/5IAULdTQx5O2zVl1Jtm2rGaVVyz7dELemE/aTx2jq+TVxVZR+o7sInXtFzn8gO6abTK7ainWK2EJhtAtOZFb9LphXm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cz0jDlucMAGGmDPRQW5vgwlwULc3GN7lt++W1zbs7JvTTXbq5KikRBV/ago6j+RVPyURP 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: Upcoming changes want to reuse the /proc/self/smaps parsing logic to parse the VmFlags field. As that works differently from the currently parsed HugePage counters, split up the logic so common functionality can be shared. While reworking this code, also use the correct sscanf placeholder for the "uint64_t thp" variable. Signed-off-by: Thomas Weißschuh Acked-by: David Hildenbrand --- tools/testing/selftests/mm/vm_util.c | 42 +++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index d8d0cf04bb57fd22bd7748fffec6a23c3103e35c..a450ab353f8e710a6bfce347bc3a7309920c70f5 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -193,13 +194,11 @@ unsigned long rss_anon(void) return rss_anon; } -bool __check_huge(void *addr, char *pattern, int nr_hpages, - uint64_t hpage_size) +char *__get_smap_entry(void *addr, const char *pattern, char *buf, size_t len) { - uint64_t thp = -1; int ret; FILE *fp; - char buffer[MAX_LINE_LENGTH]; + char *entry = NULL; char addr_pattern[MAX_LINE_LENGTH]; ret = snprintf(addr_pattern, MAX_LINE_LENGTH, "%08lx-", @@ -211,23 +210,40 @@ bool __check_huge(void *addr, char *pattern, int nr_hpages, if (!fp) ksft_exit_fail_msg("%s: Failed to open file %s\n", __func__, SMAP_FILE_PATH); - if (!check_for_pattern(fp, addr_pattern, buffer, sizeof(buffer))) + if (!check_for_pattern(fp, addr_pattern, buf, len)) goto err_out; - /* - * Fetch the pattern in the same block and check the number of - * hugepages. - */ - if (!check_for_pattern(fp, pattern, buffer, sizeof(buffer))) + /* Fetch the pattern in the same block */ + if (!check_for_pattern(fp, pattern, buf, len)) goto err_out; - snprintf(addr_pattern, MAX_LINE_LENGTH, "%s%%9ld kB", pattern); + /* Trim trailing newline */ + entry = strchr(buf, '\n'); + if (entry) + *entry = '\0'; - if (sscanf(buffer, addr_pattern, &thp) != 1) - ksft_exit_fail_msg("Reading smap error\n"); + entry = buf + strlen(pattern); err_out: fclose(fp); + return entry; +} + +bool __check_huge(void *addr, char *pattern, int nr_hpages, + uint64_t hpage_size) +{ + char buffer[MAX_LINE_LENGTH]; + uint64_t thp = -1; + char *entry; + + entry = __get_smap_entry(addr, pattern, buffer, sizeof(buffer)); + if (!entry) + goto err_out; + + if (sscanf(entry, "%9" SCNu64 " kB", &thp) != 1) + ksft_exit_fail_msg("Reading smap error\n"); + +err_out: return thp == (nr_hpages * (hpage_size >> 10)); } From patchwork Tue Jan 14 16:06:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= X-Patchwork-Id: 13938949 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 7D66EC02183 for ; Tue, 14 Jan 2025 16:07:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6B2D3280004; Tue, 14 Jan 2025 11:07:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 63CB1280001; Tue, 14 Jan 2025 11:07:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4B6C2280004; Tue, 14 Jan 2025 11:07:15 -0500 (EST) 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 2C07E280001 for ; Tue, 14 Jan 2025 11:07:15 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id DE39EAFA60 for ; Tue, 14 Jan 2025 16:07:14 +0000 (UTC) X-FDA: 83006536788.18.CA72D90 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf22.hostedemail.com (Postfix) with ESMTP id F22E7C0012 for ; Tue, 14 Jan 2025 16:07:12 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=cnFtEm18; dkim=pass header.d=linutronix.de header.s=2020e header.b=KnaL0Bqp; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf22.hostedemail.com: domain of t-8ch@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=t-8ch@linutronix.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736870833; a=rsa-sha256; cv=none; b=s41cQTFo28E01XELdAVvq+KstX7TgfAYtqWc0rJgnPcte1u1OfDsoxYOZJI7O9PhbD2QB6 tOVrwYlRDKYqL4swlcsMt1KsyVkcVjMAGgbpNE7+cRze0SdAh03vbiloYimlYRdCIxl0eU kT0RGoxQEH6Mr9U8O+EBxvqF3HfeM7s= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=cnFtEm18; dkim=pass header.d=linutronix.de header.s=2020e header.b=KnaL0Bqp; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf22.hostedemail.com: domain of t-8ch@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=t-8ch@linutronix.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736870833; 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=8RpmujbkErM0AyBS/jsicWpVLkLAFbMaYP9rwEqJEd4=; b=RN2QLwQHqsKYNE1ZxiISrQwtJ/dVBOPy6yk+lbo3CD/CkxkwI4ipdr5BsYmOQbGSIJ48kz oun1Y/ZdAT28pM3L1z22EnuCwjpfrtaZTQEl4oUwd9DvflfHgBhPWWiTMvDKQtLJ45vL+S lUjF447aX0oPpT57B/xiWeEyhDlUoqM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736870831; h=from:from: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; bh=8RpmujbkErM0AyBS/jsicWpVLkLAFbMaYP9rwEqJEd4=; b=cnFtEm18MbrSTZZNuEaTkbh1BCcJt6ODsBTtckfbbeBTuMwWvfgoDH3wreQrDdYd1I0hw8 97ExHGFWJLfiU6XcyeJtpAwoC0Qz1BIovPU4xCrc8zfK7umEq2FCW1b9xv3S92UJChPxeI tKtUWD1C7mvfBy86MAPmtENlpMqANSi8EfbAps+ZDGu9SEPH548AoatKNvljt7zOw90zTk oTEyluL2uULENRWrH4iVCaTTYUj05nGT4qftjRCQp0nC+/v0mveb4TPDoLF3HpAt3N8xVE QXHaHQqJ10QuHj+hBWYkwwD9Srq37GiphfOKHOOYwuSSW0V8RyGLEC17HbnREA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736870831; h=from:from: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; bh=8RpmujbkErM0AyBS/jsicWpVLkLAFbMaYP9rwEqJEd4=; b=KnaL0Bqp9VgUi6gfGyMii2Jd+8VSJEQIwpet4OdI32Z/16BYWMCnsNmSsVtWJTtQZh+xOC Zg4dYFNssdyZ38Ag== Date: Tue, 14 Jan 2025 17:06:48 +0100 Subject: [PATCH v4 4/4] selftests/mm: virtual_address_range: Avoid reading from VM_IO mappings MIME-Version: 1.0 Message-Id: <20250114-virtual_address_range-tests-v4-4-6fd7269934a5@linutronix.de> References: <20250114-virtual_address_range-tests-v4-0-6fd7269934a5@linutronix.de> In-Reply-To: <20250114-virtual_address_range-tests-v4-0-6fd7269934a5@linutronix.de> To: Andrew Morton , Shuah Khan , Dev Jain , Thomas Gleixner , David Hildenbrand , Anshuman Khandual Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , kernel test robot X-Developer-Signature: v=1; a=ed25519-sha256; t=1736870827; l=4152; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=dH3RzX1kWHmc070i/rqPW6ADGmajD2eJb8ZOtqkz4DI=; b=xQ+14+XJAZIgmtLRSLuvQ0RJRXCT1ZR5pG5JrfZEm4tjhZLiKT2rLZ0+9AZVNI24R/g7D4PPN oQPBYszSdrkDyMlNo2pPeLn+tt9sG8qIS0glZuGpfXKUlxWf9D0u92u X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: F22E7C0012 X-Stat-Signature: rdxkspgamzgwzjs4awxup1ydquz4fiaq X-HE-Tag: 1736870832-804041 X-HE-Meta: U2FsdGVkX1/1Q+y7G+5nBwLXfCBg0ylbA6pjyVYqDdsZUZvhWkn0OxsH5U/HGhaK/Bo07xeQzGapYewHopoDvSdy4p5zWJOLgKPUchyf7t6L0vfXTSTWfWkMlCKjEoTQZe2iGICEE6kEVnoLOOPN71IB6oAyiskCm5Q8dFbR2aQJNDmUR7iC2slKVkYR0cghURCOWihvKfT+UwQsfl9tuvhQ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5sLtBw3+WCsEWHnwUlZ4oYUmJp/2kLxtp1LagTZWFwWUgbmiH3a8nFVirqg2nSLCDv1f0XfZcQ/HUWXoI0EbeUf8CsB5nYeiXueQMludU9cnF3HTM39R794nOrh6pUxNmoqzf04y+2KTUccKK6hW1fsjEcZrb35kuZHlCmzGla92I1Rbq2Irv8bJDwrQ/UvbQNTpQ2+3DkJ5yTMU= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The virtual_address_range selftest reads from the start of each mapping listed in /proc/self/maps. However not all mappings are valid to be arbitrarily accessed. For example the vvar data used for virtual clocks on x86 [vvar_vclock] can only be accessed if 1) the kernel configuration enables virtual clocks and 2) the hypervisor provided the data for it. Only the VDSO itself has the necessary information to know this. Since commit e93d2521b27f ("x86/vdso: Split virtual clock pages into dedicated mapping") the virtual clock data was split out into its own mapping, leading to EFAULT from read() during the validation. Check for the VM_IO flag as a proxy. It is present for the VVAR mappings and MMIO ranges can be dangerous to access arbitrarily. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202412271148.2656e485-lkp@intel.com Fixes: e93d2521b27f ("x86/vdso: Split virtual clock pages into dedicated mapping") Fixes: 010409649885 ("selftests/mm: confirm VA exhaustion without reliance on correctness of mmap()") Suggested-by: David Hildenbrand Link: https://lore.kernel.org/lkml/e97c2a5d-c815-4936-a767-ac42a3220a90@redhat.com/ Signed-off-by: Thomas Weißschuh Acked-by: David Hildenbrand --- I left out the comment about the requirement for check_vmflag_io() to be called with the start address of a mapping. It's the same for the check_huge_*() functions and there it's not documented either. Also there is only a single, correct user and any misuse will instantly result in visible breakage. --- tools/testing/selftests/mm/virtual_address_range.c | 4 ++++ tools/testing/selftests/mm/vm_util.c | 24 ++++++++++++++++++++++ tools/testing/selftests/mm/vm_util.h | 1 + 3 files changed, 29 insertions(+) diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c index 386e4e46fa65b98af78dee4bb30144eb2b51f528..b380e102b22f0a44654ab046f257e8c35e8d90e9 100644 --- a/tools/testing/selftests/mm/virtual_address_range.c +++ b/tools/testing/selftests/mm/virtual_address_range.c @@ -15,6 +15,7 @@ #include #include +#include "vm_util.h" #include "../kselftest.h" /* @@ -159,6 +160,9 @@ static int validate_complete_va_space(void) if (prot[0] != 'r') continue; + if (check_vmflag_io((void *)start_addr)) + continue; + /* * Confirm whether MAP_CHUNK_SIZE chunk can be found or not. * If write succeeds, no need to check MAP_CHUNK_SIZE - 1 diff --git a/tools/testing/selftests/mm/vm_util.c b/tools/testing/selftests/mm/vm_util.c index a450ab353f8e710a6bfce347bc3a7309920c70f5..8bd2c5e59bc73bdfa617d4b11b448da84e2a3daf 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -400,3 +400,27 @@ unsigned long get_free_hugepages(void) fclose(f); return fhp; } + +bool check_vmflag_io(void *addr) +{ + char buffer[MAX_LINE_LENGTH]; + const char *flags; + size_t flaglen; + + flags = __get_smap_entry(addr, "VmFlags:", buffer, sizeof(buffer)); + if (!flags) + ksft_exit_fail_msg("%s: No VmFlags for %p\n", __func__, addr); + + while (true) { + flags += strspn(flags, " "); + + flaglen = strcspn(flags, " "); + if (!flaglen) + return false; + + if (flaglen == strlen("io") && !memcmp(flags, "io", flaglen)) + return true; + + flags += flaglen; + } +} diff --git a/tools/testing/selftests/mm/vm_util.h b/tools/testing/selftests/mm/vm_util.h index 2eaed82099255e09ffd38ad9714994397f304685..b60ac68a9dc8893895f49946b258260f7a82218a 100644 --- a/tools/testing/selftests/mm/vm_util.h +++ b/tools/testing/selftests/mm/vm_util.h @@ -53,6 +53,7 @@ int uffd_unregister(int uffd, void *addr, uint64_t len); int uffd_register_with_ioctls(int uffd, void *addr, uint64_t len, bool miss, bool wp, bool minor, uint64_t *ioctls); unsigned long get_free_hugepages(void); +bool check_vmflag_io(void *addr); /* * On ppc64 this will only work with radix 2M hugepage size