From patchwork Fri Jan 10 13:05:50 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: 13934560 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 30B16E77188 for ; Fri, 10 Jan 2025 13:06:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AAA4C6B009E; Fri, 10 Jan 2025 08:06:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A58FD6B00A0; Fri, 10 Jan 2025 08:06:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8D0D36B00A7; Fri, 10 Jan 2025 08:06:19 -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 70A066B009E for ; Fri, 10 Jan 2025 08:06:19 -0500 (EST) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 1E468160A4B for ; Fri, 10 Jan 2025 13:06:19 +0000 (UTC) X-FDA: 82991565678.15.B420F72 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf15.hostedemail.com (Postfix) with ESMTP id 28B31A000F for ; Fri, 10 Jan 2025 13:06:16 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=kA+S8SXB; dkim=pass header.d=linutronix.de header.s=2020e header.b=5KZkRKHk; 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=1736514377; 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=rvleoViXEKAiJTVXtrq0/ICXhKzDLpaWFsIO95ioPJE=; b=nDcXMRUtrI0pCOT6buNolZAzDmqICHU9XSjUseGNEVw09IAVBheJLHt1tEXUu1juvtWLcW Cjy4nyW8026eNPJyOpJhSKiy08u3n6qv0iMPZZGhp/PBxnM2NJ2VW8fHjleLuHwY3nPbH5 gEg8xY8ZDnW467Uj5HtvbpHR7Ci2Cc0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=kA+S8SXB; dkim=pass header.d=linutronix.de header.s=2020e header.b=5KZkRKHk; 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=1736514377; a=rsa-sha256; cv=none; b=aS25VPzyQNlHcye0IlfSPMhwneMW8g5eGdb6FWUcObyBDpDrR00OeoRNdKmtHqkgwCASho i/4v4MDbZWu7yCnnnBw6IKQi022f9SWoIed74S+tFwUyrFWy0DPo9CROyjHj3LOi2sYkMa CPunNeGV5Bio4W0CopRm+y6UrtiXiNw= From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736514375; 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=rvleoViXEKAiJTVXtrq0/ICXhKzDLpaWFsIO95ioPJE=; b=kA+S8SXBPARb8/LLqo0nfKGrPw7rdKWdDmGS2CbReD3UmVTIQQskSvD3RaWBL93kyST6L9 PsHFEZqYEro6lVdcsTGBAw2OEuWu6/NQixUPXpAxkpeQOj0Gj1sS7Qmps6jUqISOAOPscj J4JDbtS7rOZZV9TurTDXICTLNe6BWu5xsr4cmjNppwduyJDK/ief8slr8ViWYefVI5crLN 8OltyuL8hhe48ezTMJra2ESijyzKBCc14D8GstA+D5PU3hMtbQGu18gh/Hpi6IldVe7ZgK XHuDv3nt/6TFjUHpbRZ8PP1Hoqrek4EY71BUqqybuaVVD2/t9vdau5pjUO1mgg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736514375; 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=rvleoViXEKAiJTVXtrq0/ICXhKzDLpaWFsIO95ioPJE=; b=5KZkRKHkwyWQDbmLNGda8RdT9cAqgyA7/oTQynMbpe46hd4sDQU1p09idFSqW8ElHooX/B Gw4DHIjstVF/o6CQ== Date: Fri, 10 Jan 2025 14:05:50 +0100 Subject: [PATCH v2 1/3] selftests/mm: virtual_address_range: mmap() without PROT_WRITE MIME-Version: 1.0 Message-Id: <20250110-virtual_address_range-tests-v2-1-262a2bf3c3d0@linutronix.de> References: <20250110-virtual_address_range-tests-v2-0-262a2bf3c3d0@linutronix.de> In-Reply-To: <20250110-virtual_address_range-tests-v2-0-262a2bf3c3d0@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=1736514373; l=1736; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=6Y4AYnLMO6bZ4JZYH4ZHiDJ17RsT8q+tecRlw111Dgw=; b=x/1Tr/J0h4P+MXP4+Hne/MFcUXBC2su4aDXFajOeQYUQnctX6GGFfB8m0I5tB3Rhc4XdY+xHO VpnjsHoiQtVDIsaAjowbqM8fe55VK5GfURLdBwupuLvfHlnMEtMxNGB X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 28B31A000F X-Rspam-User: X-Stat-Signature: wixutbu1m7qgu4we5ppm5xqxzxtd5jta X-HE-Tag: 1736514376-124931 X-HE-Meta: U2FsdGVkX1/Q8ID8WOTQEGtZ18A10IGfCs0Sodjy7xxK5bBSV25IckUmbzzS1ti/C16hXR3MaZoK1gDHFLekFfoNGmjO0G+ZgbDyZOhlG1Yz6CwuZo6zV6HQ+B77SlFowBrdo81nwSrpyooSw6CDo/L0pA0yqBaE2+/78Oq50QvnnSoMTemTIVwVlsNErc8UcA1/g/fdI5fu3DACmpYecAKyJcHbcPysFAkY9Q/gUnwHPagpQK2G3/vzmG737afTDSgTeT8NAj0OF4IVa1ZFYlOVpgXCN+CW9LwPBq2fd89irKJg5rGqM3zyQs8NeqbM6ShdQpPBW0yD3sGbWsKAabxz89ouJkB1KF1KkGLFebJ1ecnCNaOUonqGXebPQ+nwg+Ro9n8XxLpHsQd1ynPi+TkGBdjFk7874XMvAkwqXMLZLLPFfcmksl9mj/idByd7Fdbxy7U5xZkYzV7A3LHcL3LsEBlg1ITJohDMcdAtALM4kZzpyfdriMft/sf/FwCzHXb3g5//28BPIbjld+NdvWqKTgnKuwBrjqYdC/xBpGxMsgTNAy+5l3rVza2DOEVtIwSFqETONXP7CumxnY4DR7gunJD94FQeIErEOloae3iqKnGS4lC4NoAF+XE0Gd/oq7z4mt6YXwSSjdAD7m45XhvAfJHg1E+0lRQyqjlj3FCS8DDma9UC0vgzk+xy2vzYUkqh1Hl+7LgBJ7OH/kz8UkjFZO79Q3QQNhHsfXhffzeCutH+jkXd7rzG00qiwf0w856MgT6JZnqTu7VNqNLfI1YHgk02mWVxmq4WkiuB56b+jbv8/66TAMk0djoSqFDhlLQqGeNGOXZ06ZAcYAJmkfkeSd8UDbL/61W7KbkF92HtQZh1rxxcXJQVoLdXfd0iAtOaGy2BulUd4rhbIO3etHXGbL8tLQI5WrC9TWeQTZgZgGBXiEbbve8ToCRiarHe1UIoAH3X8SQ4LrjCRNI UtbZBPn/ 4Z7AM5h6gA0XNwUCrXKaX5cySfwi/pP+DGJrHqxCn176HneIMZ0Jmt6lMd651nw40mZZrq1zGQYETuJhjb/YSI6wNsZkUmTbK7O/R1msZwvWbnCjLvpzgRAJHTYbVOozt04+ma+W+xebG+9hPe6xwIpvrdFdNN3HpHGaj+ZIC6MKhbW1LVv9t1m+1bpAksu2mRi9EajVbgE0I2jn+NBLj2ORHRYLu2ZP6MI/yNEzrFGXUbbGhkXvrKTfJGpk75A8k0kkiW4OhKtjhZfCkJghGLJkw0Jt9xqAOEdZrrnZ4pfMs1/rvSbL/Hf7+cq7RoxLoaWLt0MLnQsGdPHKNyuV+sJO8HX6LZ/Cl0V0I9DZi3dw5HT2RSm3EM9YRBb1/fSLfSyJdGHu5wN16XgjQ+7RuLx1g7YLyrgTNGdZM1OFvB0OiQ5SoIuu4/8KYhyTuMaZF6cPa 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 --- I went with dropping PROT_WRITE instead of adding MAP_NORESERVE as this works even in the face of OVERCOMMIT_NEVER. --- 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 Fri Jan 10 13:05:51 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: 13934562 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 EB9B0E77188 for ; Fri, 10 Jan 2025 13:06:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6FF8F6B00A7; Fri, 10 Jan 2025 08:06:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6D54B6B00AB; Fri, 10 Jan 2025 08:06:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3059B6B00A7; Fri, 10 Jan 2025 08:06:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0176F6B00A0 for ; Fri, 10 Jan 2025 08:06:19 -0500 (EST) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id A3A481C794A for ; Fri, 10 Jan 2025 13:06:19 +0000 (UTC) X-FDA: 82991565678.05.E763507 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf04.hostedemail.com (Postfix) with ESMTP id C6EAE4001F for ; Fri, 10 Jan 2025 13:06:17 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=vflGQwKo; dkim=pass header.d=linutronix.de header.s=2020e header.b=xv1l3BxM; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf04.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=1736514378; 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=FfSwcoper7Dt8IbJd6SAJbSWE7t+Dn+VNNOEgXwNNto=; b=aUU+WUE8/B+j7dru0YdlRvwd8xOlVK3uFPVe7aZ9HBIGwyGSAeBuQwZDpN+vpnxQnwRB0Q K2+zEEWl9y3ERk9bsTF6pVOryNF4aABQg2ZhwJ/ANnAs7XUx6ab2ePCXnKq3rRYVYd78E1 BUHk3hFVrbze3YrqPD54EfR8+yi5now= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736514378; a=rsa-sha256; cv=none; b=RjLgLxN3suw2mjn850Rvtt1+hoNTFRxUdOw/JUzkQ1T1GFrM9wGvTy7AdPpertmYIEkpAt bGIJNX5PSQSd3Xm+4hLFwMtm7Ain+RYzgavkdi183WD1bClqz2ekOfnbz9DvnEzaoJ/NsW cMvY9VqyR+WclmCxPZktNoaiiKdTJOA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=vflGQwKo; dkim=pass header.d=linutronix.de header.s=2020e header.b=xv1l3BxM; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf04.hostedemail.com: domain of t-8ch@linutronix.de designates 193.142.43.55 as permitted sender) smtp.mailfrom=t-8ch@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=1736514375; 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=FfSwcoper7Dt8IbJd6SAJbSWE7t+Dn+VNNOEgXwNNto=; b=vflGQwKokksy9wndTuq2JDp+6s69Q4PSQE8lsJVo/7ytgk1kgyOqo2DNj7xUlianGmIxpM dwtU55pWT9kh/QtQ3bPk2y9YrAyJzjFYnlTrQEieNrCbY7DOnCStBvTuAaf4GwVKd7HRwG JmHRaoF0AGj8YJbtKHGI2Lxh4rUA9xu82Lwu3yu6mDmzlRx3voVagjPpMSuxK/nH88OYC3 NJsTYU3D2P8oehUd23xQ1N1id1VFGhEDBWcnuCHMxLZGt8DK7csgf/dA/QK+IO89+FOaSW crR4UkvEa3TOGQIinakJzlWKpLeOm290nKcGAKzRvvy0rL+5Ghkskz5gOE82cw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736514375; 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=FfSwcoper7Dt8IbJd6SAJbSWE7t+Dn+VNNOEgXwNNto=; b=xv1l3BxMw4fVDw1Q7ltYhO+FHNtq+hmY6thNOPkVzJOhJW55YkcR0nToy/OQXE3yrsADa+ oCwAHbkGm0wmjkAA== Date: Fri, 10 Jan 2025 14:05:51 +0100 Subject: [PATCH v2 2/3] selftests/mm: virtual_address_range: Unmap chunks after validation MIME-Version: 1.0 Message-Id: <20250110-virtual_address_range-tests-v2-2-262a2bf3c3d0@linutronix.de> References: <20250110-virtual_address_range-tests-v2-0-262a2bf3c3d0@linutronix.de> In-Reply-To: <20250110-virtual_address_range-tests-v2-0-262a2bf3c3d0@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=1736514373; l=3739; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=oH2aay2q7fFXdPQqT97Za+YuSgFw9tqAjxqs/EP1Kzk=; b=mS86EYLMAXqOl7y/cnaZgsSNJY87tS1Z/rkrO57qBRkaq02XGrGaGId/wVKSlYBOv1mWsF16C J0pGqBlWmmJDP2C0qPH9D6og59+leY8TwHdjXT7pyuGMpY13DOhWck2 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Stat-Signature: hqbs1zyd35wcau7tocibch8rug59t34s X-Rspamd-Queue-Id: C6EAE4001F X-Rspam-User: X-Rspamd-Server: rspam01 X-HE-Tag: 1736514377-957989 X-HE-Meta: U2FsdGVkX1+oq0Qm7BstXayb5dCmo2YfBJrmg///A7P6KkVs1JPr+qqpYvHUeI2mdmdWRGHmgVt3WpA6l8ZsUI6bHQaVLz8FnGCHebcLLlawGmA8G4pDe4YYn543WJo/RKmXjb8oiWwK7InmzNQDVoY1xVWKUJ/alsjs3rsXQyDcl/gYUAe7bJt1e6TR46uj/agnVugAA7ZAOOlNPWZa0tIUX7PgUqnpNg7kHkanW5tvoR7NH4p8q7plI6ZeD3tmF9Q5TrrPj6ZlELcNjAF8hQSJt1UqpN2sSf3i8R46ucY6/7Af1NXRK61qr9XGzjxQYkCICb+b0dTzojKHcppdaDgeiw3rVl/4DXX+Q+8AM1RcALTE0pIdNAMcUZy9zzILIMTmel8psymTSXYKin5XLkeQWrGUMqfh6vKR1yBlsKzYJGajqZL6zIpg4D/3gJr9137pAYbpMVcnfRZw9Jnnb+M0cwKS2J9jRFAL2Iv00F+0KoeJa45anu7G3NybVOnmX5y3ywfxJ8Hii5Q2Xa7YfeNzQ/Z/q7XL3vjgZaPlxnQN7ykt2VMrguOR+1fdZ0maASIdxxBoR3f5bdST45rAU7TQ8JYEAipb/AS0uRLCqgMAILvdSFdgV1e2JF5AyNJdCjPQbvS2JDeY2PiC8BfPn1D3DqkKNzsLJ4I+JYoo+CJEMuzBGgKp3P9hQsbEaHj/2ZwOjA6C+xtbjSJj6vISPx17GmxmPMTMgG7nCH3ND62wGdOl9WCBMjrh/JtB+kJUkeQHimLh0QivMVWbk7wKeOSn9BTf388dxgCNHomHaBtdk12PKCOof9VmyuqOGQyFia55azpRjkU1jdffOpdLRAhNu9K8cP1KG1kvfx/I9lib92jzEe3JmhT96WDwBfmLuuQGuDRcC/OX/JebQfQzfaNQ1SBlwggCVE+HURomiBJmJbrPGIUkB3iuBjQK+Yhjs5XBh8dvl+xw6M8u2OT AsuL2Rcx 3vV/vhjkCmg0nYMxnon9akKKlQ8TSVkNKdwne/xHGlGtUeormJh2iugRWeVMUMRdlycbkXBVLe9QkE/XxfWhvwfN3fSNh748OdW4eHtfNCl2nTl8Hty/rk1VlRWo1bbXyUaIxSWPeQtJMEiV8ZAKJnb7I2EkgJuObx5SWrtHKwktSg1P0VOU68V2ZqxQRZnQvXJdRxRuJuVw6cSx3piNSF8kOmIGD6dBaI8/bx0GXmDFrWLJQC1JMwQmbbu4UQcAwxZJvH1MUL0q/iue8owQsYwQJOZrlHRttWH7XUIM3Rx9Jueckh/g4IOKP9aDR2JlN1FW81q1YbAMfQam+WFO9q9y2KjVP9hdxs50i9jxl4WE2dmOaxk3unc0aeX5Uj/64rQRhGAgLeP7Y4s/b46wCxfHWMtKTCYovb7ETGzsphj5xMGNsKVSXkxLOycIMQmpJXPwu 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 --- tools/testing/selftests/mm/config | 1 + tools/testing/selftests/mm/virtual_address_range.c | 26 ++++++++++++++++++++-- 2 files changed, 25 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..4fc1c21a5e218eaec4d059b75c31a21dd4e8a215 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,17 @@ static void validate_addr(char *ptr, int high_addr) ksft_exit_fail_msg("Bad address %lx\n", addr); } +static void mark_addr(char *ptr) +{ + if (prctl(PR_SET_VMA, PR_SET_VMA_ANON_NAME, ptr, MAP_CHUNK_SIZE, "virtual_address_range")) + ksft_exit_fail_msg("prctl(PR_SET_VMA_ANON_NAME) failed: %s\n", strerror(errno)); +} + +static int is_marked_addr(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 +128,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 +166,9 @@ static int validate_complete_va_space(void) return 1; lseek(fd, 0, SEEK_SET); + if (is_marked_addr(vma_name)) + munmap((char *)(start_addr + hop), MAP_CHUNK_SIZE); + hop += MAP_CHUNK_SIZE; } } @@ -175,6 +195,7 @@ int main(int argc, char *argv[]) break; } + mark_addr(ptr[i]); validate_addr(ptr[i], 0); } lchunks = i; @@ -192,6 +213,7 @@ int main(int argc, char *argv[]) if (hptr[i] == MAP_FAILED) break; + mark_addr(ptr[i]); validate_addr(hptr[i], 1); } hchunks = i; From patchwork Fri Jan 10 13:05:52 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: 13934561 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 EE1C3E77188 for ; Fri, 10 Jan 2025 13:06:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 307F76B00AC; Fri, 10 Jan 2025 08:06:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 21B586B00AB; Fri, 10 Jan 2025 08:06:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EC50B6B00A8; Fri, 10 Jan 2025 08:06:19 -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 CDDDD6B00A0 for ; Fri, 10 Jan 2025 08:06:19 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 5F97544A23 for ; Fri, 10 Jan 2025 13:06:19 +0000 (UTC) X-FDA: 82991565678.04.AF68D9F Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf26.hostedemail.com (Postfix) with ESMTP id 7B1EA14000E for ; Fri, 10 Jan 2025 13:06:17 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=cgMVMM0X; dkim=pass header.d=linutronix.de header.s=2020e header.b=vnqKOQqc; spf=pass (imf26.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=1736514377; 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=7/HpKeU3nB17qCbgw45LzfDStDcTMTxJdySqt4LT06I=; b=dmwM+Q4sHZXG/hkDQPRlm4wrWBtCe0c0jo7yE5l6QSYIx5rV37W/LTZpZUy+3svynT3ZvV xdZFnG12P8bI08NNJYtSXJNP/Qc9b1qc6CTSbrkYIKjD6MXLIVonXHjdNlkKl9FxfOtofE k8hQooHPvZ4hTWf4fO4EEvF3MpNQKsY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736514377; a=rsa-sha256; cv=none; b=kfuHLc1+TbiePuS2+OCBSBiYYYG8OF+74KjYOc4shlULHKLma3X93Spcj1YJKN6k6l/jMg EvxwK3lcrqp8xQ9/C5eFwwYsvFBXxi7ir/jySy29Mzk/HB1ErQhWc5FKIXA1NJn2b1806K MBu5tnl5F5wz39EWl72gm0B9m1QW250= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b=cgMVMM0X; dkim=pass header.d=linutronix.de header.s=2020e header.b=vnqKOQqc; spf=pass (imf26.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=1736514376; 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=7/HpKeU3nB17qCbgw45LzfDStDcTMTxJdySqt4LT06I=; b=cgMVMM0XMvPpgk7LQVls0/NjZqULU4tlyO7mR7tS+j2wRjYSlSDJj1NU5zpG7j3eU2jJG0 RFR31a/9lS28uHmr5fDEca2yBUHlNtFks2HYxvKM9igXsAHf6VSe8gonN3qjICvqN6jeGv xqos6rZYmqHPdEixvDMfQdTPfVrFKQVEweEvgBMcnCOWHBzuI4IvcXz8ilknht6CFNqYbz rLVx5bNwFeFRmrti2Rkzn0CANvENJNbfUGCNDj4uAG3PEQd7rrtqgn7qx0kKr3OlcNGsKm 8l2FXpnZyu5HLbFzfwPIGMNVChguSF/0q2e65AzVHOYHrfL7CVpcZ4EstcnZsA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736514376; 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=7/HpKeU3nB17qCbgw45LzfDStDcTMTxJdySqt4LT06I=; b=vnqKOQqcnyThrY7uwgt10ODiZAJvUV1j7RK4XfnLpFpnSDHBblD4BPTaFhJM6d71HmumZy r3TkoT027CrLHjDg== Date: Fri, 10 Jan 2025 14:05:52 +0100 Subject: [PATCH v2 3/3] selftests/mm: virtual_address_range: Avoid reading VVAR mappings MIME-Version: 1.0 Message-Id: <20250110-virtual_address_range-tests-v2-3-262a2bf3c3d0@linutronix.de> References: <20250110-virtual_address_range-tests-v2-0-262a2bf3c3d0@linutronix.de> In-Reply-To: <20250110-virtual_address_range-tests-v2-0-262a2bf3c3d0@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=1736514373; l=1931; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=bdSDA3kxsRphOJAe1hxQQ4SiKiKcoohRKkjKfuCnFKc=; b=gKZeKPISRJ9eyZV3iQPMGCo8+Fm6utfH+O07hIoYZsNN5ZCKnoVoHyndhFCIolHxljj1aIu4l qp0SJjbKI5LBX7Q3yIWHuSlRgoFOxhE/K020QA06NXrxEPE/bZTtSOY X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 7B1EA14000E X-Stat-Signature: qim1ner71ppkc5m9uz6n34u4yw1xz7fw X-Rspam-User: X-HE-Tag: 1736514377-786503 X-HE-Meta: U2FsdGVkX18Pn7b1uCxvZ4ev4jwRY/9vJuwFo+PEImMU2qtceepcnsxP5AkWmN86oWQuRQtPMB+FbFPNHXPf59vAuAnG4gjeMzdI9nVGuKwhtQ8UbM4J9Zki7BknmiG4lxVSeH3Fxt/sBrwN/+S1NcwKzwfAJzNCgi3eFDDkDqHD0HYIbd+6Y2OTfscdtiwsGROqAWB7W795msSItpmsgN3572Cypk6Lb/vw0yYe12rWMfuECplV6MTYQ3WQA0uXlGcoCmp2itYeajA2GAOOOjR9nHZ4mV1z6Jl8A5a7fGn+NTjkALoH6o9141K95j6wWZ7kq7vITp7JCUvegHjiAFvNO8MutYLIPhFsnMhRsgwKPRJpMyuDCGJB5u4sQuYNcA2nhv1Y707f4egphxD4kp4hXounNGtgU+tS0fa7NmQY7UDAknx/KTp6nkpqVU7zPgkKaBG1bWQFz++P7zMuBP2CE8adFrcmV2xRhW6d656Vm0s7vYUKERiFLPVijye8hhJFeRn2XA6EFIk8bnuhWxWpwPbuNlcm5y/iA7oAWk1wCGjyW96QccI2vce7UGXIqieECel6h+xedQgXs1KBtUIFagtpvz3Hlv71carHeoEk/oMyxoOvmUag51UFAT+jx2oP8Ff02lJ6mhMEtVaWiUxotMaNEicK3vXe9Y7YJGMdSPEKZ49/xvWv9DIThO0sTfpZtB6Lph3R9n/q8dRsdkTZ78enGvYYL2mpSIMjibl4m4FrUcQyDHD4/QmMT+K81EKQ+N/fUAFa/LEqzXsLz70hBHdgNpbBTFrGGGzMQ+GlLOuP/XcSwJg+7zHJ3G49yhKyLlfQDx6AGe5GRcAxjkrmQk6v8hjftnIRhgFkOU90kn7tkYxBfHcJ41dtZiax3ksMhsr9z1tjqbTlgVuveF3Afm37h4bXyUCS+8uDvyg/rM7owhvJdNtB8l/SAb/4kvm3F6UWuFayN5XD1Ol noH6pNAE sRwFkeY0K5GRbWfaCIP+TVf37tdPUVMBFyM+X6KmfkJBCtgv4woT4lQ1LdAKhukPJhTjkS/RmkytVxog78dpduIo0/ndWQJz1rZDs74A6lFHQWcqAhYHt7VLekeoSnO3MISu7CPTWN7IqJ0p0817PBdo0fjzXHlpGlqU8UN4vLMZGYNbPbSYxnMj7MmNQSkzK5uvGvIFrWhrIw71ztq7IKNQv10Vi7nPxyM4ELrXxb8sec66YCCNmR2KUWH1AhGUIP89w7q5SUpPOx6zJ9/GqgBE3MnewgB5TAVKgW80Mg79aNg0MnIBiqz68ln+RUpKU9Pe+e8H3cSASkXNJAEzWaG83y4na/Vul8n9PSU1cChPRlXqmQy9G3YSj001EoCYCGjtRe/d37AnKpwLdT6jqs6i3HYbj1cgfshuvY1sSEONyGfLRpkGSRKWz0WQs/2nTJeGAzw3/PBl1Qkh3H+ggKSXgJp4+t6ak373whG2ImO+HL9l9ChNcD8/4Vw== 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. Skip the various vvar mappings in virtual_address_range to avoid the issue. Fixes: e93d2521b27f ("x86/vdso: Split virtual clock pages into dedicated mapping") Fixes: 010409649885 ("selftests/mm: confirm VA exhaustion without reliance on correctness of mmap()") Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-lkp/202412271148.2656e485-lkp@intel.com Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/mm/virtual_address_range.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c index 4fc1c21a5e218eaec4d059b75c31a21dd4e8a215..993990aba56fc986c42084ffa91973558aa07e87 100644 --- a/tools/testing/selftests/mm/virtual_address_range.c +++ b/tools/testing/selftests/mm/virtual_address_range.c @@ -152,6 +152,10 @@ static int validate_complete_va_space(void) if (prot[0] != 'r') continue; + /* Only the VDSO can know if a VVAR mapping is really readable */ + if (vma_name && !strncmp(vma_name, "[vvar", 5)) + continue; + /* * Confirm whether MAP_CHUNK_SIZE chunk can be found or not. * If write succeeds, no need to check MAP_CHUNK_SIZE - 1