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