From patchwork Mon Jan 13 13:15:35 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: 13937332 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 035ADE7719F for ; Mon, 13 Jan 2025 13:17:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 874246B009E; Mon, 13 Jan 2025 08:17:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7CAE66B009F; Mon, 13 Jan 2025 08:17:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64DC06B00A0; Mon, 13 Jan 2025 08:17:15 -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 456B36B009D for ; Mon, 13 Jan 2025 08:17:15 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id F1F66160213 for ; Mon, 13 Jan 2025 13:17:14 +0000 (UTC) X-FDA: 83002479588.22.5CCBE72 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf11.hostedemail.com (Postfix) with ESMTP id 1705540010 for ; Mon, 13 Jan 2025 13:17:12 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=fGH5LhPL; dkim=pass header.d=linutronix.de header.s=2020e header.b="Wh/rLWoy"; spf=pass (imf11.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=1736774233; 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=nXUVqotOwksrgtObQJbhIdeITzwigDuITzq7I8OaDiY=; b=rtWWN72s4xSzgCepRzEI7aFVRXr7rZejrP94iKDvZ7Y1Pb6ZVyAwwQ/bHrmu7XnMCnsCZ4 L4yBP6zZ2mATkF3+TEfBXlaS5obiyZ3lFTm8xu3UpI/ec0ygnQmHCnrirPyZJty3Qeossl uOvD/8aB78zKDTx5KHaSCN2/50N5Hv8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736774233; a=rsa-sha256; cv=none; b=QL6BuAYOytdK/r9RMWzexru2WWlJIGnmFxV2i6+XowMZpqhkrHxZqPt/4L5vw63FNiO9Hw FEpylIwHfIl45VEYRkwWeq24EIGmXKkI6GFXbYbYoKnS3b9XKh8lTVuciK6xl/EEM9Q/qu Gc/a1fjFZ458qP266qYoRCsd8qRutxw= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=fGH5LhPL; dkim=pass header.d=linutronix.de header.s=2020e header.b="Wh/rLWoy"; spf=pass (imf11.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=1736774231; 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=nXUVqotOwksrgtObQJbhIdeITzwigDuITzq7I8OaDiY=; b=fGH5LhPLbxJ0Iq+16N4pLYnNpVcIgofwYRD98RxBnRtYphMiJYKJuxlo1Hrg5uSOnvUeTM 9TrylLx4K+iB3rfsM6cE4LDqeiAoBytxVU1DjS0n1z9WvGj9+n/HWJCRj73IssfsyQMV4Q x0VHxyDz5DyQoZs5jWQWWylXpeWmvIC4HCPtiJyZWLId4kr0CoIJJszHLddy64W53jnCF8 ilcGOuSn82g147LQS7zKjULC+bOYyJBm7RpscqMhvE7rM79v3WQ6HPI/G1eiIAsUoLX9kq Us3T2QpUeTpkg11IRKLQOQ5k//TTyt6RdD+PoHXq7WmfvEKFCCjqM16A7aKq3g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736774231; 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=nXUVqotOwksrgtObQJbhIdeITzwigDuITzq7I8OaDiY=; b=Wh/rLWoySnbsESvYzcaLXyIcCBn9BBgs0DqghRiOoH2KXlfHzzAVZWYpATDDTQBV9Tf4xW DONDrWrWceEu0SAg== Date: Mon, 13 Jan 2025 14:15:35 +0100 Subject: [PATCH v3 1/4] selftests/mm: virtual_address_range: mmap() without PROT_WRITE MIME-Version: 1.0 Message-Id: <20250113-virtual_address_range-tests-v3-1-f4a8e6b7feed@linutronix.de> References: <20250113-virtual_address_range-tests-v3-0-f4a8e6b7feed@linutronix.de> In-Reply-To: <20250113-virtual_address_range-tests-v3-0-f4a8e6b7feed@linutronix.de> To: Andrew Morton , Shuah Khan , Dev Jain , Thomas Gleixner , David Hildenbrand 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=1736774229; l=1698; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=cUBEfQwiMoC+IN0PqoM+iEVxivVSJV0lgRrH9DVIFOs=; b=XD9wdAETA3CT+EKMf87OQ9yWUi7VjDLtiEEwegZyI5XtmEZYGy8kMRXOBy4T1pXRpbRFmtcRp tHC2yAZ4j+XDY3smjIklkGtqgVOg08vf//ARADirDthzh7UIJGJiRx6 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Rspamd-Queue-Id: 1705540010 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: n7auyc8bij53w6h8nfxk4uqrwrj6eiuc X-HE-Tag: 1736774232-613072 X-HE-Meta: U2FsdGVkX18v6AaGlYOujup+GW5fo1nUceOODGsAcTy9HYu39dpfzI2ZnkeZKTvFeVY6C8ERdK/ivzfSRcRywXFKNca/WdogrOVu+FpQljjc2ut2IDAubcpNazwr0+CM6qH+hj33xlRpeMZqkFFshmqKN67YAbXiw/QfPN67leDRNfeqURAAQFRiBz+QuBhGPLLZwNU8+DnCMrukVvCW+ZqupiJpp1gNYQeeaBlYhE2/5SxV1/bsrCjvP/e6bPI/wpdN305plhcmcvqRxo8Bh3thjYhmDACc/YEE0uBqK/xuXoHUFyz8mXJfgjLu+7Va0cRZOYnB+3oEETEjNwrdac9dB3SjZHtMbD3JMSqg6hLz7UIqc1y1IDrZkqYLFw1YeE1lb222C1U/8VJQjmEr9GBYxY03DjOSAShfWRR+8GVJOgWN67TX3iJUhq70Z6xTi5i0qP4+BgWVvmnsmTwzlTdb1vqbCrVLTVwovLc06WeI4XxWN8nmxaUQPGT8bfEalg3H+V2Us1gThVjP2qnVy3pv+DO2ngfCRXxqsoN1Lj6KZEO7ebv9l1oqJln/w8Hw3qP22OKBBjO9wyT9gnh0q+igYm7BfEokhPI0fwqXT51AMUGICVPpOx3K8GNvUOGE7tHPuzFQGv58RVE5sHLAP4ZlvKM8CqxYr9Icye515INScPoG57xapu0NDOMU2G4WVqjvhs+iMaVIOWnAoS1AeASJG3jeiEOtV9uozyAievekUj9Bar23/bs6ULpEGZp226coIAudR8BJDbWspraF9RPULetbvbxcG/6joi9lI4I0SZWuITCtuKF8ibDcxlfKZloDMA8bCHOp7wxp0B4Oxu5888Sx7FKsLS3MYPjsMSyaUbcKDcypHFzqkp2TVc2RsSxSXFlbV/bXpeJKsqOiNNlc5EZCEeoCk//jmvdjjPdErITLJFRWNTyXC5ZolWzbWZHdhNwJeMKvHi9VzOY ru6mUVCw yX7fvyI/Lff+SCMg2fjiJsxvltMbvmG4ZmX3Dms7llHNxkkbJM7WQoMEFXgD/7FvoqI9/PdN0O1nWA9FSbtKuiXwwpLX0q4ZEiCbsSKhpVyZYeNZf0qr0pJu8A7I4CGQSfDAFOHz9ysGRqwgJ+nZM4MY7OUBPSuI2VODQfZmOTUVsJqRT1j2pHUCO2kQyeGHQ4JkBJm6RF2zCVZbs5Y6JZTbKOsGrpIOBz1MKSGCJcpoaOwscFcyLYkmEVxk4KHSZkY1fFeKUJJmccY2EqVR7KnrA47UjKfuApnobp15KkI4s/hsec6s4J/Xpc0c+2lVjRI+dyu773DXetp7O+lfNrF2NgInQQaiAY6YjTzGNFgfu8QKYaliqQlFCIRLaC/CQSNKmuVSEm7rpV6qFo2XFdd6KDI8sTGjg1iHNEYssNReLnQF5gZ2/pmoJzaNtnS6CQWcq/f8O6nTtbXzUvn8TvRTv77ELt8m68DcZv8PCy/tLO9CRgdXOgYEpcwYDiYL4KGTMtVJl5wpgaiqMnX66e9sadw== 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: 010409649885 ("selftests/mm: confirm VA exhaustion without reliance on correctness of mmap()") 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 Mon Jan 13 13:15:36 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: 13937334 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 88B17C02180 for ; Mon, 13 Jan 2025 13:17:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED5566B009F; Mon, 13 Jan 2025 08:17:15 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E59846B00A2; Mon, 13 Jan 2025 08:17:15 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BBF6F6B00A1; Mon, 13 Jan 2025 08:17:15 -0500 (EST) 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 7E6BA6B00A0 for ; Mon, 13 Jan 2025 08:17:15 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2DD9D120265 for ; Mon, 13 Jan 2025 13:17:15 +0000 (UTC) X-FDA: 83002479630.24.385AD9F Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf25.hostedemail.com (Postfix) with ESMTP id 484E2A000F for ; Mon, 13 Jan 2025 13:17:13 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=1CBuV9LM; dkim=pass header.d=linutronix.de header.s=2020e header.b=4mvRayE0; dmarc=pass (policy=none) header.from=linutronix.de; 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 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736774233; a=rsa-sha256; cv=none; b=uqTun2l8GJ5gI6F1Dg0zUghgm2Q/oUnuObHb1QSes5HIMWW6d97BBd+3oGP5f7zwv9kZqn +z67uLFw1F2aKiUaMU2ia2ByHd9b3W8yvtxnVxP9Iuv5EnreIRNDJPRmZDlNWMY3m1k+Ru kU9arkfzEqqQ05cUVq4pTHIa/6i9eLA= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=1CBuV9LM; dkim=pass header.d=linutronix.de header.s=2020e header.b=4mvRayE0; dmarc=pass (policy=none) header.from=linutronix.de; 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736774233; 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=BB2O49jg7bdHh5I8SFkvOSGpR/2gpeyIP8hG/oWKnuA=; b=nhA0qwBYcXFK52kmYDN2471BmKuM4sDgwvslC3sdjxakiuiKYEhWyfBAsd8KfuePuAEgHj Jv2wuhML0/pb0CcUBTqLX9+o094Bm4APtkkP+hwApsJw0waLv2BxuYra4sWf9ShkdJ06a+ gPusrnUlP50bGoQko7eyOT+IjccpENs= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736774232; 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=BB2O49jg7bdHh5I8SFkvOSGpR/2gpeyIP8hG/oWKnuA=; b=1CBuV9LMXAMrlJ9IflbNljk0JXuo2zd1MPzCAD9297JXLmLapQgdndJiXwT9Vw1dv1uKvA 3kICr8J0Qe1Tq4VBT8i+HBZMz24xJjspAfUAPBBG8Hlg6ueJV0YyCI5RFnaBAG1OgXxsKq YapIM26nzRMoFgxDh73szQ+M2S2EEJ9gRWRIypMbuhzp1HP1p9qlmWMp6i2uZcRUHN+ABj exBQpNpNN6nUzy3zt3I1iNRjVKI3GKVsYRj43hvJtSVDXSxH5aF/yxKFFF0pU/tduSeWpL jAqd4m77yFE9yk/NJfqGzFRd/38BDctkg8gkUVC/8WmJLzSILbZAxQcBcL6GVA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736774232; 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=BB2O49jg7bdHh5I8SFkvOSGpR/2gpeyIP8hG/oWKnuA=; b=4mvRayE0CAw8tX3kK9BfIK84n94lkVUmzadM8HdJlJ0M9Ts30Nn0HAT/7T/QT7TYsJ4nq9 3oA4maHReyzVsBAA== Date: Mon, 13 Jan 2025 14:15:36 +0100 Subject: [PATCH v3 2/4] selftests/mm: virtual_address_range: Unmap chunks after validation MIME-Version: 1.0 Message-Id: <20250113-virtual_address_range-tests-v3-2-f4a8e6b7feed@linutronix.de> References: <20250113-virtual_address_range-tests-v3-0-f4a8e6b7feed@linutronix.de> In-Reply-To: <20250113-virtual_address_range-tests-v3-0-f4a8e6b7feed@linutronix.de> To: Andrew Morton , Shuah Khan , Dev Jain , Thomas Gleixner , David Hildenbrand 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=1736774229; l=3957; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=+J+pIjUkTrbA4CGXJ2S1U5YIbW5DfoH8SKBNfbwggwk=; b=uq6vmORxXVZbLi6UjqFMoF/YkYKRm8KQxCroQXGFlQap/Mqol+by324sYz153F6iNnwjZ6KOL VMaXve+XTJRDEdc0V6gkAQOwLRX6E/dWtAUFFJK3OOzNeRGN9Dg8+3q X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 484E2A000F X-Stat-Signature: 3eimobbstbm6t4jq8cjix8iomgonyz58 X-Rspam-User: X-HE-Tag: 1736774233-941500 X-HE-Meta: U2FsdGVkX184kR+3mwh7Pne7aiuQ/yloUOXgYfzra37/9KBYibNH2EYfzej7PBX+W1ek/3ygCgdkkfgdGpdnihtJm5PyIfFOZR/h7Mzc4bl2uRQxfOu6o4pH20CGJIqzkhoXcFa/gTRWnFjVyul8swz8re+ANBKvnzeIlYf0utbfctQnJdenIn8f7EnY2kHBqD79ZuK7E9IKbxhsBS5OEpuiaLYQ9dKxijmNmUaGNeIDsKIyzIJaVa6qHkaFdPYXkd3v9pXafVD1JwEn7jFaVVLLZzZ+2QpcuIpyzTca0QW4fmsm2NcYFlQ7KxhLeDHnkUs9cty11n9n//qUuEliqwIgUwQCyF+Pb0U6vPAXk8H6OjOnFtNTMpbkecqXVWJpHgR17x3Y5EZctKcceHEMdyMvbeCj4Appy2rs+qJNS24kCpCAAbpS00Cmu8EidesCnlysxS5ch/TBw7+mR46bDZrK9H6AE3x60r8/A7Zglj8N2731aEUGEp4ANx9taFYTTC/yZafhJnhPnMhJU0xLUzxfXR8+aZNAEX0JrlD+qLbTQgrbvlDoN9UW5TOYyOd60k4+eG+xm8sJ9jm5rJvtZFpdsRjiiBlx9+05wAXkSfTfL9d1X2lolXjG8Z+xLR+IwCEILQryZgqQRGf+At0vG8NPuoi4HSt/RPNzvKsD5NfMMMiri8hvLyVpH1Y6/m/TqMwepnda9349CwvhEWwBSVBgc5Xl+3M0uEOEPmVRp/BC9HHMyBprDGf8YZCuxgmKiE0St4/Zqh2coDpCIihE3c/gQel/A06WvGt4tavDqUKeub31barFghZBW+V/18ghjH3v2oG8nE7jUvCxpKyxyLA3MdEmomgyVN9b6UNceHUaIqHMMd9XTkJQvuJaz5Hh8SeUEUZ2qc4LEHW436/Cq9SFKZfXqNLRRGvobyc7QbG0uHUSeBJjbrFtjdaR+L/GxXkhHs2yqy5ocrUbho2 O8X5tczo pAqnEEe5Edt+AvyS3nnz1sMEEz0dnJAWnYarpj/1iwcKeMsYtceR9CZMYHJz3dcHkL5+OE/qu3SBqzreR3WY4RNgqAxfZz4bRLbjaPtYyZ+12DULHWMbE/9WTmobp30d52Az2xMMgcyQgT6DmudBnNjnqfgHUI8xyepryxujY7d/20WHadzVx+iuwC2Dz0xe8rZBApb32N58fu3npeTH2hpNzKILyhMiWLbhJAWrmcAWXa+gPLOBpg8c5kVUF47UuE4jC5XnE2gWhWkV22a94rjmoUL1WcoYgN8936al0EftUQ3CXUZ9QzSojU+vzuy4HAzqTPtkKZnbNMKXCan/IP1jPMlMXxKIJG964Xlucl/2KE9KPlVAXZBV4lHJkuJx5GYJC+ds3VNkfddqqvgfGEBueUdTJoh+l5o26M3a6BaiulNvBLyzkooZhDeI86KWsTxtJ 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 Mon Jan 13 13:15:37 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: 13937336 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 7B3FBE7719F for ; Mon, 13 Jan 2025 13:17:24 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 18ABC6B00A0; Mon, 13 Jan 2025 08:17:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 04E116B00A2; Mon, 13 Jan 2025 08:17:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0DF16B00A1; Mon, 13 Jan 2025 08:17:16 -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 9647C6B00A0 for ; Mon, 13 Jan 2025 08:17:16 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 4B57DADB60 for ; Mon, 13 Jan 2025 13:17:16 +0000 (UTC) X-FDA: 83002479672.07.9B9E03C Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf05.hostedemail.com (Postfix) with ESMTP id 60F4E10000A for ; Mon, 13 Jan 2025 13:17:14 +0000 (UTC) Authentication-Results: imf05.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=JC9KfFs9; dkim=pass header.d=linutronix.de header.s=2020e header.b=akBV3Alj; spf=pass (imf05.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=1736774234; a=rsa-sha256; cv=none; b=mVZkiU7HKDi/C94tMFRjjClFzMq6AgXkYcN6rGONQMUgKnQ3yZHef6kMpH2VTBGdqz42DH zHAOuzsL6gdk7+Hwb3f6Jc04jZId5YyhDSpC8fx4aqHUJubr3+N/yNrxAWzS9kcFWPZ6kn NphLS6tg/jXaLyWarSBtD1fBIkbrOiU= ARC-Authentication-Results: i=1; imf05.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=JC9KfFs9; dkim=pass header.d=linutronix.de header.s=2020e header.b=akBV3Alj; spf=pass (imf05.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=1736774234; 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=/blv4n22o4xwWzbzoYSZD2Qy5uJLVnQWfTrkFwx7l5I=; b=J5y5vNa3Au+gjYzK9x5Y9rzHzLSQjF+bF5QHYLAY6akd+mUA4uJQiZvfUeuITfOvebZJFR JeNzNOSNpWn+m2fl6qkksqljGWqhepUcVSn31zsdE/mTxHGHJTz5/Iedl8BTGBnhu2JdR5 rYwjtybHg+GrIlX2tsPeyKfmxTEJ8HM= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736774232; 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=/blv4n22o4xwWzbzoYSZD2Qy5uJLVnQWfTrkFwx7l5I=; b=JC9KfFs9JRXBreQf5tTCEIA1Ao/60W8ETgVULszb5IjAOS4XhzBsmguV0z4dqb+hhlDY31 ygcP4IHPscYdJkrpg4+LBOops94w8k6dI0FAJbVjF3w8M6KpOKt0DEyLu134egeSa7C2Df JHtRsIGBWHFvVUc0PKV5eTwoMgtldEQd/QqgoGI5SorvLXZbOKkyz7mLm7n+VsYBEKV9O5 84IN+p2CW6y1mKNX/bIXA/oKP9wWIIXVt+vJt6RCTA93NqX3a7jktamava233cQXNmtIyy AbXRuaVGSoytzsRu/kbfim8TpJLI06qRngTzJaXqf6nt+aa0NjzfB3AAkafHxg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736774232; 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=/blv4n22o4xwWzbzoYSZD2Qy5uJLVnQWfTrkFwx7l5I=; b=akBV3AljlG0D1RueAA+llky0t1bUlT/ReAoBYz+3tA96RoxFhJdo/Ej4ttqRYBFASO9Vom JOqtMbCEWhwUxsCw== Date: Mon, 13 Jan 2025 14:15:37 +0100 Subject: [PATCH v3 3/4] selftests/mm: vm_util: Split up /proc/self/smaps parsing MIME-Version: 1.0 Message-Id: <20250113-virtual_address_range-tests-v3-3-f4a8e6b7feed@linutronix.de> References: <20250113-virtual_address_range-tests-v3-0-f4a8e6b7feed@linutronix.de> In-Reply-To: <20250113-virtual_address_range-tests-v3-0-f4a8e6b7feed@linutronix.de> To: Andrew Morton , Shuah Khan , Dev Jain , Thomas Gleixner , David Hildenbrand 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=1736774229; l=2860; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=6BHmjOZjGkeOAxEqViu35ESnPzRfjS5CZ+5Ol52x1DA=; b=kpnruwzlgMo/dc08nb/9iPLsVW71YnBKUlSIi/oNgq/lXX5w4hmH5bzGI8CKBfFvq82kX/ZME L/MltRi86xRCLZc6e+9DcqmU/KPMVlsaDy6rFzqC8ID23MLQyvGI34P X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Rspamd-Queue-Id: 60F4E10000A X-Stat-Signature: u3x3homyhd8mu4roq66k3ygpbha7w71q X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1736774234-496595 X-HE-Meta: U2FsdGVkX19pE4AVL6xu1pol0G6RjuuIr0obT3sE2rp2XhhychzeegzZfdmRiHvyXDaoV5fJDAkQUukNJznrAYT4sz/vtdCbS73AL2sJZdBIQ4i69jOo2SNwzvN5KKB6tAYI/0gn3aRdnOmigs2sPCieybey4DfnbWXCsNz/5kfuj8IdNC8fQMyJjSQ+aXbZMiiVJp1J+izb8La8DB0UNSNjvirKIt5ZQZhqCyvIEZ04YKNWU4RTpxV0f1pgnIG+zvOFGo+WTKaqlXqi9kFHp5bmeKJaMNbp6t2S6vW42XkgQZ16puEHLZnBMnFQI/3E0lK8L7G5dyRD2DTGUtmS/Kk7FV+/U9TSRsScp81fvFVAc78448lme7ktRn0Qj7fg7pQPHCt1LR0QZ0yXMwAFFjIB+WZNw+UGtm7sahCdmPS5O1ozZohgxhyUVr6Ymq7h0ZNW95eBc2T1hXphJ+lvgEh8Z0VNz80PAGA6i967OGu8iTffc6aILQkisPp1FJOphma6yYy7P1K0PfrBXH/uzLuKqY1evfUC44VNCYdS60XoFk3yRxRLqlOU1P6LrQrq6b9We4KvWan+KAL0tyRy1M1Vn9cd55DPZYPqfBWDmAay/7gzeO7ZPbjUkOYtnVtfTwfTKaca82cM6onqiEpU3H5DOD1NN3Wxvms23qpw+7cKTfY4/tqZlklShEMW0BJtJEjBSDGDplxDH5Wmf8/TYpSqH2Eh/zh2dakkX5oeOQH2MV6dtG8voB01jqt5L60BSL3Sw7vy7FX9YRnn6qnO1eLzIhaf0ugDpbgA0yf0mtXsr6Odkg3gVH/hNknctt/RRtnWTSOv8D/XMaHc3MY1dgmO/j2wgi6g8hFR2egsNMWuUdtWhpM+rQ+sg4DMDS9pMA7enaIDaUydrp8vn5bEE/Tgdnjm8Jw3p2Riv7iNV5PVeoMa7NV1mFeyQRiIaMN9HVQmRRz9ajsoMN9zL4i DSZMWPQm g2Wq4S6NluZV4KNpY+uwhB8M/V4UvCMia3liMxiL4LLK6QP1+/mW2CFVh2L2Vtu64nM3Icgg+STlSXDfctcFP6axCUSnEU/IgzE61sDtbYLISSjHzP95zL8LWh9sa0ZTVBncG5/12DM8VbLIzyjp5OEXc+byxIEwJL/5oGYE0bFPKMU3YskIaxMTw8wNguyR7hwAVRG9gYE3rfa4dq0QJY6SjwyibQ1GmhCip56731KFrwRacziEB/0xvv7V9CeclD8fEaB8sc38htEdyzNU0kYTS6DcozHk5iLQ+ZP55/wnIkc/Jolxp0w2fmNByZLcX20IHHY0WAcFCYln4MXN3zfwQGM7ZNJjN5Twi9yfbRlKR76jNJdTpJI38Qe8hWkLwsen/vGXgC1qlqzoVmL/khb/gbS2NwIKEMiY9vlECOqRrvEuzWATAk9snPPBMJ6NZ9ARk 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..8468a19d6acca10c7e9228c03a935cdeb2402b5d 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; 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 Mon Jan 13 13:15:38 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: 13937335 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 D4B56C02183 for ; Mon, 13 Jan 2025 13:17:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C10A76B00A4; Mon, 13 Jan 2025 08:17:16 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B247D6B00A3; Mon, 13 Jan 2025 08:17:16 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 927986B00A2; Mon, 13 Jan 2025 08:17:16 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 7199B6B00A0 for ; Mon, 13 Jan 2025 08:17:16 -0500 (EST) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 29A8A140259 for ; Mon, 13 Jan 2025 13:17:16 +0000 (UTC) X-FDA: 83002479672.26.E70001A Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf01.hostedemail.com (Postfix) with ESMTP id 3A0F340016 for ; Mon, 13 Jan 2025 13:17:14 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=tOd1+oYb; dkim=pass header.d=linutronix.de header.s=2020e header.b=4WUy0BVW; spf=pass (imf01.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=1736774234; 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=UqkR3Vf3Utpm6qqhuJmf9/1TcUxTIh5FO0zgNY2iBlQ=; b=UF8bX5lJf38MViQA6q4KahwKfXdmgvuN9rF9jm5POFSyFlmRgsMoCMBq8l+gt7xzRE4EtU uOJJyth8ORQ8+v3R9bXnAPBWfl6/79ISG1LvDMffvpALfBmNYPoax+MzGXTGxuuwCT+Oet vsmU4Eup7LKMgbAulo3BYKUY3xf+b0o= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736774234; a=rsa-sha256; cv=none; b=IfzBp1+PN2NFWrIaBMAXYFUaNFC9iFjlvxOGkyEXXafFtvn9SC68KuLBep0un5K+paRhjE hemuK2XwFGPTCpifvtL8lAHD6t1vBrAJI9+CZo+1T1N8Bw42SYk6DKGrfYo4C+MZPEDesz rdqMEr2Q9XtOC5C1wlqIlnBJ5ojgcU8= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=tOd1+oYb; dkim=pass header.d=linutronix.de header.s=2020e header.b=4WUy0BVW; spf=pass (imf01.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=1736774233; 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=UqkR3Vf3Utpm6qqhuJmf9/1TcUxTIh5FO0zgNY2iBlQ=; b=tOd1+oYbaw93xI5qiPtbOLngwYfXVaCDgpIb0F1rOhjs9p2VWQsgJU8vJnllZX7z5BAL/S lNcAVwjI7RNiLWH69IWcGQGISkmh0cJeeFdJohCBn9Ev0akqMBoTZsEtKugqXkaIUQIMbA Y0JLN/xKfRZLpa+XIz6yt+0rv8gmuwgXoIDcv2bwgljVfOM5lxDsD35nCnCXzHdqay88Bw wsMrnqYQGPhArtr8ejOSDsRhii0cx8/jEyFDE06fZo8gIcL8oH8dZtffl41RDRAHPI8xbE RsP1TvFYfLiGegojESCE2ZOvE+xxuo8PhYvnxcvx/D61mjmfyrrYjPiCVD4Ayw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736774233; 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=UqkR3Vf3Utpm6qqhuJmf9/1TcUxTIh5FO0zgNY2iBlQ=; b=4WUy0BVWvBSBOdixeQzZNV2YvPplN6D1GIvqp47n45grd+/sld7MFBsaL5fjWk6wiukVtK PJw7pr58sz4JilAQ== Date: Mon, 13 Jan 2025 14:15:38 +0100 Subject: [PATCH v3 4/4] selftests/mm: virtual_address_range: Avoid reading from VM_IO mappings MIME-Version: 1.0 Message-Id: <20250113-virtual_address_range-tests-v3-4-f4a8e6b7feed@linutronix.de> References: <20250113-virtual_address_range-tests-v3-0-f4a8e6b7feed@linutronix.de> In-Reply-To: <20250113-virtual_address_range-tests-v3-0-f4a8e6b7feed@linutronix.de> To: Andrew Morton , Shuah Khan , Dev Jain , Thomas Gleixner , David Hildenbrand 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=1736774229; l=3934; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=4PwI9Ccn5M7eMxfUmG8BWAwz4GRkkm02QUveGYfCnxc=; b=xbBux7r8n6o18h59gp/9UfYQ+pHgD0rP3QBiHdmTwKMk9vdZ/SHtmSYtgzFGZcQ52GrBGiPKZ YYGMIiM1TpWA/PGh6exbFX6/gcaT+cXJ6QBX0kjNQWFo+32arGd47fF X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Rspamd-Queue-Id: 3A0F340016 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: fofhs1murbytwt8gksy7ord4qdjnixku X-HE-Tag: 1736774233-174436 X-HE-Meta: U2FsdGVkX191Ef+yX7XXZz0rsQPckVKl24eg1kUNCD6/ffT+aGFN5JBomnEAPZ+ovUD5wjIhh9wwun5XBTu4JKqAUjzkEYhP2csIHWCA42RL7TRFub4+DBdoQRJd9rE00BZfY5a4obeaWDryCY41cMWn18P4ELe3ZcsPxReqG4UWtfzRcXj+PEW5OFc3oSUMSJakZZlDbtJ5/8aIaXcCnDyUW7H+xjfbhMTlMImWsOIgHr2GwONNQSwi4gkmVG+dJdMZgSeKMRKBR6ynUqS7O9ZvbFRxv4DqSiIOvM5z5cJsj6OueRS+38ra8+gGsUwnbs91PuX4w674+AJmTmo3xjbXAFNLUU7DWq7CYayjdJPnWrCJV6GHKQGrfOuGzFipz8TnVzFm/1/c1zeR2DFTOdsrgScyg5dW13SmCRp5UtXwkzfSoSHcfmkKfMV9LRGm9nS7LFlBKfOQ03FlGvLtc0Tc3Z51KEB1upmclh2S2agitfz/Y5maVmKp/jtJgfAQmAjIOkCL4g3C857FEbxIYqBDcQaFmbyJ9fxQDyowRmSlrhmdoA+zmXeHJzLyB3gaM9MF8nVU4KkeGtonKDbkb2QH7igp9Ehfh2/fGzMatVqmM+XJ+/c6P30LsZEmiW6BBJGLLSVLAlhWVXqnbLmmRZoRe1ri0MOKxx3vEQzYA6MPo6JYWntrw5cPNcGSc4vq2Rq9zr/KkQMWqar83xBR4vLBHEZJxfCwCxf2BkKswCLbaelKhkTigrAyGKUvxiWoQrFqWzsxXoG6hcAgs0ht3PyL0P9rsF6iP2e5/HtV1u0obsTwGoHV/2aDu3UAwfTFEI1Tvs2h/jxtivBuG01XrePZSwtLzohQE/Wnnz+eqZyLvXKQruPEtx4uTnE9FB4xfUUsrt/k2iMmowpsrJv0flCqKudRh5RKYVYG3J4DhhHRrj2IT0L8z0BJVKvODTJJXWWLCYs6+qMdzBqxzOe cSx8WHCg 16qCy1pWTL8gYL3Jb7AtJrEpUcp1Uq5/2q6TzCFYdeF6CBfgwpbq5NB3bXGnmae0BDRt3qUZjNVUDZhkO1DKesfQ2cUF8rftb7n4XS1qcKMXth/z+3mCeAM1sPSJTy5wt7umqX96ihu1HaMOpyV4XRIHP3iam4h/Pcph+XYG++K616/uqG10nuhmdO4Eb+32kKqzM9rBiNd9xpqgPC0i0cga62bUdoyMz+9mmGOnkSDEqX4MDr5xStY/5dDTMNqjhkfmTzPQcIJJ516QpArxF5gusSFU7nHSmv4LxSmF721y29AnnObmLv0pu5zL0IC5PLAOBYzzumFlfNf0KP9Ndzuq3TUR8TSbJiJyQoMSrBYnH7csbH0IRZ+FQeJZUYSqU0A5q9t4ZGNGYvUGCGNb3pNvi5eeiIIiztRr1GVW/bt5Qyn1IoH13eoVA3RETZsrN6Kei309Z+tG9X48wsX5OTUclRjnRuoqHxPjAJSkeUvDLSdg6JRzoxEGdNYCLum93rIZ38jB70kW8d2c= 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 Revert "selftests/mm: virtual_address_range: Avoid reading VVAR mappings" This reverts commit 05cc5d292ac4238684b59922aecf59c932edefa0. --- tools/testing/selftests/mm/virtual_address_range.c | 4 ++++ tools/testing/selftests/mm/vm_util.c | 21 +++++++++++++++++++++ tools/testing/selftests/mm/vm_util.h | 1 + 3 files changed, 26 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 8468a19d6acca10c7e9228c03a935cdeb2402b5d..161fe03b07af78244efc669a36155ad603fa6f7d 100644 --- a/tools/testing/selftests/mm/vm_util.c +++ b/tools/testing/selftests/mm/vm_util.c @@ -400,3 +400,24 @@ unsigned long get_free_hugepages(void) fclose(f); return fhp; } + +bool check_vmflag_io(void *addr) +{ + char *saveptr, *flag, *strtok_arg; + char buffer[MAX_LINE_LENGTH]; + + strtok_arg = __get_smap_entry(addr, "VmFlags:", buffer, sizeof(buffer)); + if (!strtok_arg) + ksft_exit_fail_msg("%s: No VmFlags for %p\n", __func__, addr); + + while (true) { + flag = strtok_r(strtok_arg, " ", &saveptr); + if (!flag) + break; + if (strcmp(flag, "io") == 0) + return true; + strtok_arg = NULL; + } + + return false; +} 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