From patchwork Tue Jan 7 15:14: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: 855845 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 34AD91F239C; Tue, 7 Jan 2025 15:14:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736262900; cv=none; b=XzhJ3/ypkNV/80e98shoASDzaO6BHt0S1kgfw7iHlXFgW/U6nO4R6IKGjEYxd51tzTGXvI7+YZphMrvw9kdBF9Yxmtx0M2IyTMlMakBsoS7qeglVKaV9varOat1pFObnjCsOb2pzBN1Y/vPQ3cw7Z2Dm44JnTJwlh42cILyrplw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736262900; c=relaxed/simple; bh=pkeSpzoPWHY8BsliSFSfbcQRoHvGqOoQKWjNi/5v8ic=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=m/CKF42VP7LyFyk6sfYZ+LzSGFmqOw842TSOA6ECOm3NKo4QwIej8N81psELJe7yulsP1fmDT2OUdOiO+9vZBoNyktcnBfm7w+3HTuHIIsi6pUaAk7MOHGDdvMo41pxtJPetqqrg39+0chGC/k7cDNaEnv1+y+873z9WlrYwxy8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=xEDYdNyQ; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=gvC+B3rW; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="xEDYdNyQ"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="gvC+B3rW" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736262894; 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=8MKnoaEM2eqbdSEIwek8NUSxcpZg/joWFCsMXcOwV8g=; b=xEDYdNyQFc4yS3PKefVEYJImsRrGchl4NLvK5u9X9qhOqvFW0G8VLPI78Rjead8YUOib7I Cp8hXOE3hKfi3pGrlSwNvoMarO0cVNB/hlBoNDcidAlhPn8zfBVPZMEumYRVKnJG6v7r69 /sbhJ9/tTdWWjHy1D9E9Z67acXtbk0Vkpa6xtZwN35JQF/OTHRjXiLsszzHJrESKwQFzPA q+diYTEMhS26YnqaIgw+K0ZgP+4dbsJ68AuO0J5YuIfuwT7Qw6M6ifzRdko4FroLMVxl0n vGVrRQt5L8ZAA1neAL/nD3gHTMdNEWDFagGE5zt1sgYCSdOluSJtGwYEODQd4g== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736262894; 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=8MKnoaEM2eqbdSEIwek8NUSxcpZg/joWFCsMXcOwV8g=; b=gvC+B3rWXyc/qxMwaqaSZObNNe1xvWwv3/CKHVVFYl2ybnP1xfbZCjm2f7hlL4ynU0ItoI bCMQv5vsaVEyHVBw== Date: Tue, 07 Jan 2025 16:14:45 +0100 Subject: [PATCH 1/3] selftests/mm: virtual_address_range: Fix error when CommitLimit < 1GiB Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250107-virtual_address_range-tests-v1-1-3834a2fb47fe@linutronix.de> References: <20250107-virtual_address_range-tests-v1-0-3834a2fb47fe@linutronix.de> In-Reply-To: <20250107-virtual_address_range-tests-v1-0-3834a2fb47fe@linutronix.de> To: Andrew Morton , Shuah Khan , Dev Jain , Thomas Gleixner Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , stable@vger.kernel.org X-Developer-Signature: v=1; a=ed25519-sha256; t=1736262892; l=1691; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=pkeSpzoPWHY8BsliSFSfbcQRoHvGqOoQKWjNi/5v8ic=; b=Q7U4tGUxDzcEKeBChx8jtgkcq7Wge8kBvCoqMUZT2oi/Qti7jPY0onQ2kqHsunfb2jqdfU1hz sAu/mvAzojZDkvqBTlCrLkZo2WWSwciE2YoG/u+CTP/BwDRiXqX58/F X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= If not enough physical memory is available the kernel may fail mmap(); see __vm_enough_memory() and vm_commit_limit(). In that case the logic in validate_complete_va_space() does not make sense and will even incorrectly fail. Instead skip the test if no mmap() succeeded. Fixes: 010409649885 ("selftests/mm: confirm VA exhaustion without reliance on correctness of mmap()") Cc: stable@vger.kernel.org Signed-off-by: Thomas Weißschuh --- The logic in __vm_enough_memory() seems weird. It describes itself as "Check that a process has enough memory to allocate a new virtual mapping", however it never checks the current memory usage of the process. So it only disallows large mappings. But many small mappings taking the same amount of memory are allowed; and then even automatically merged into one big mapping. --- tools/testing/selftests/mm/virtual_address_range.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c index 2a2b69e91950a37999f606847c9c8328d79890c2..d7bf8094d8bcd4bc96e2db4dc3fcb41968def859 100644 --- a/tools/testing/selftests/mm/virtual_address_range.c +++ b/tools/testing/selftests/mm/virtual_address_range.c @@ -178,6 +178,12 @@ int main(int argc, char *argv[]) validate_addr(ptr[i], 0); } lchunks = i; + + if (!lchunks) { + ksft_test_result_skip("Not enough memory for a single chunk\n"); + ksft_finished(); + } + hptr = (char **) calloc(NR_CHUNKS_HIGH, sizeof(char *)); if (hptr == NULL) { ksft_test_result_skip("Memory constraint not fulfilled\n"); From patchwork Tue Jan 7 15:14: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: 855573 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9C6541F2C51; Tue, 7 Jan 2025 15:14:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736262901; cv=none; b=dAZYu0LAVLyvS1G7PuY0WI1ehOdr8aSjBxEXAP2Bs9+qgEvMAcFs23U1yAihSvO6nLqiT/vOBfNFxu3YJMQ7YTs7Ffp4OmvRXtePTfbDRuDAVwcTeasa6v8SrLFTaGDugIolnMCl4K5uNoVb0RvYCI+2e71xyWPRVN1CiKkBcD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736262901; c=relaxed/simple; bh=JV1EmwhzZN8rbAZfsKr/X1cMrrhDBFJbY8LiCwcvoc8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=cPeZlUyMNNtHFLzAUujNZa78wfCrz8vushfj+eqY4ANQeZ0VjEZKDiNc+0c9WoG3WfCc3XCWl/HCCkMRJKXK9jjGdgFESokjdJuTrRmZ60dISAe2pC0+nLO27a0UQg+UxUfYecGPcLFqO6aapgqtXAP7aGRaV36h1YsS2XIyUas= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=a9oDTS+H; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=MlKdOtsV; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="a9oDTS+H"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="MlKdOtsV" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736262895; 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=xr/B0xvK7sGkfKbzNUSoXapb4RwCqM0VBcWsRspXohE=; b=a9oDTS+H17gco4eQ8kGhsCqsv9PlMnDDDlrs5LYGf2TxvF6Hc5SBP64YFNV0nppAvZUusn M/G7DF0KH/LcmAEI1xWxZL+QNzgVlBsgjstoBDXG+O5kcLjbzcxJ73XRFUfad5bU/BSlXo A7Y1TLhJxAJJJUB1Cu+ZmF8o4HPSLIsSPIGcqtN8vDA3eYzeCZSbOkqrbjlbcq4O2qsS/n 7bsoJ93HjH1DQiw0HcpeuRycJzpZhiOC/HLEyk8byYgd9q0UkBKXyK2nM17peGau2Mh0ah 0BAgqvWbeo6MZ37fDRAIoWa1XTY/LDxATu4Oigy2pzOK7TSbTD+y5AJX8XyKGw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736262895; 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=xr/B0xvK7sGkfKbzNUSoXapb4RwCqM0VBcWsRspXohE=; b=MlKdOtsVGTXjDdT5TITCXHSRGRiOVe9EHCVyyPc/IRYFURbCmmQ3GfZsh8mk9woFCpH0+G JprG5Ns6Ac7MHGDQ== Date: Tue, 07 Jan 2025 16:14:46 +0100 Subject: [PATCH 2/3] selftests/mm: virtual_address_range: Avoid reading VVAR mappings Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250107-virtual_address_range-tests-v1-2-3834a2fb47fe@linutronix.de> References: <20250107-virtual_address_range-tests-v1-0-3834a2fb47fe@linutronix.de> In-Reply-To: <20250107-virtual_address_range-tests-v1-0-3834a2fb47fe@linutronix.de> To: Andrew Morton , Shuah Khan , Dev Jain , Thomas Gleixner Cc: linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, =?utf-8?q?Thomas_Wei=C3=9Fschuh?= , stable@vger.kernel.org, kernel test robot X-Developer-Signature: v=1; a=ed25519-sha256; t=1736262892; l=2470; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=JV1EmwhzZN8rbAZfsKr/X1cMrrhDBFJbY8LiCwcvoc8=; b=UWmnjc1iTVSO0yiJVv6/4RPN2Sb/xWnNUD78AugJktpFzXZZymMS0+1ZQxMl27beVnu+e+YDZ 8Nc8ASPkmPSCTTatBfxeZhgcl4WR/ohvWgXLmHZ4bc0wTeHWOo89/b8 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= 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 can only be accessed if 1) the kernel configuration enables virtual clocks and 2) the hypervisor provided the data for it, which can only determined by the VDSO code itself. Since commit e93d2521b27f ("x86/vdso: Split virtual clock pages into dedicated mapping") the virtual clock data was split out into its own mapping, triggering faulting accesses by virtual_address_range. Skip the various vvar mappings in virtual_address_range to avoid errors. Fixes: e93d2521b27f ("x86/vdso: Split virtual clock pages into dedicated mapping") Fixes: 010409649885 ("selftests/mm: confirm VA exhaustion without reliance on correctness of mmap()") Cc: stable@vger.kernel.org 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 | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c index d7bf8094d8bcd4bc96e2db4dc3fcb41968def859..484f82c7b7c871f82a7d9ec6d6c649f2ab1eb0cd 100644 --- a/tools/testing/selftests/mm/virtual_address_range.c +++ b/tools/testing/selftests/mm/virtual_address_range.c @@ -116,10 +116,11 @@ static int validate_complete_va_space(void) prev_end_addr = 0; while (fgets(line, sizeof(line), file)) { + int path_offset = 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, &path_offset) != 3) ksft_exit_fail_msg("cannot parse /proc/self/maps\n"); /* end of userspace mappings; ignore vsyscall mapping */ @@ -135,6 +136,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 (path_offset && !strncmp(line + path_offset, "[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 From patchwork Tue Jan 7 15:14: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: 855844 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E03FD1F2395; Tue, 7 Jan 2025 15:14:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736262900; cv=none; b=RrWTe6puIlW59Gs82spdC8XVKy6krtstsrs9bQJsVYmgMNrbvQTyVjJLAGbWTyRg3w8/u4e8VwzlCQzdsUos+gGZsf5j13uG9xtb80tFVQcvQndtLV6wPNSQtvM4xwgvf6MBLpfLw8ICNRx3o+uJsxgAx2bJVgBEhbrprboCCUY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736262900; c=relaxed/simple; bh=MeslUuRpp6snP8kaY60rYzKdJKBjCd/nlz8O3AupkXI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=gnt7lJsTa40FdtS/XwyROxgICBT9KJBWTwPkvYHNatpN1VQicvSb/19BOkvbIM5qGBTwFvFeAqwxv/57TwBn6v2ktVobQbgnxZguwdfpfLfeLD2HVUV9/H8c0uXZJHIhxWppXA39vTpU6kWlMUqLw+Qd/8RcukbYlPQodSaKZ30= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=UiQRK0pO; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=Kfi/QA9H; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="UiQRK0pO"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Kfi/QA9H" From: =?utf-8?q?Thomas_Wei=C3=9Fschuh?= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736262896; 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=tydfE0F+64UOWjWNZaYZ/G6V8qY6qkkoQjYUo5kzM8U=; b=UiQRK0pOMnBJssXVy82Zjf1x4fX0s6WRl+VbZBBCpTDHc/y/KzVxCjU8wCZTMEqfWR3CTC GkwWkidrZdh7otQx6AY4tbdd6bGm1RZhEbTUM455gxI/uYzwItJNYnFGMpl+iAyeNm4x0N Wf+kMoOtKaMN9PFgMyPViFjRTqO3unAmJZx0hlO5vAJX2AAdzO1Egbwa2I1uVQpWuHt+VE Oc23zoruxrccDh8+ZMtLsUonylVw+yjkbOejLe3JSC+J9ZdlMXcpEDIWPcSGsbovpafcU/ xE1656kYniX8lstBNsSSBpui7QJdkqSgGHt5rDDBa8w9mVSaES7WlLw/n8FHeA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736262896; 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=tydfE0F+64UOWjWNZaYZ/G6V8qY6qkkoQjYUo5kzM8U=; b=Kfi/QA9HsvdZ4syxi4iEtnoRj7YoGxTHEfXpJeTF/g6P+zPt8wSKZ8n1LlDIE+CmZardgk JjIVXg8097Oa12Ag== Date: Tue, 07 Jan 2025 16:14:47 +0100 Subject: [PATCH 3/3] selftests/mm: virtual_address_range: Dump to /dev/null Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250107-virtual_address_range-tests-v1-3-3834a2fb47fe@linutronix.de> References: <20250107-virtual_address_range-tests-v1-0-3834a2fb47fe@linutronix.de> In-Reply-To: <20250107-virtual_address_range-tests-v1-0-3834a2fb47fe@linutronix.de> To: Andrew Morton , Shuah Khan , Dev Jain , Thomas Gleixner 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=1736262892; l=2277; i=thomas.weissschuh@linutronix.de; s=20240209; h=from:subject:message-id; bh=MeslUuRpp6snP8kaY60rYzKdJKBjCd/nlz8O3AupkXI=; b=NgTUKSqcuckegdTFYfiFIOnS20yzvT8cJRDvGk4KpA/YgWzMR5+yLFIoBtpKsziXFS/XXkBns TiPuiJvnbd+C2YlaXpIPif/pnn6JvFsSRrw925v6Gp3yFUsERRJgQl7 X-Developer-Key: i=thomas.weissschuh@linutronix.de; a=ed25519; pk=pfvxvpFUDJV2h2nY0FidLUml22uGLSjByFbM6aqQQws= During the execution of validate_complete_va_space() a lot of memory is on the VM subsystem. When running on a low memory subsystem an OOM may be triggered, when writing to the dump file as the filesystem may also require memory. On my test system with 1100MiB physical memory: Tasks state (memory values in pages): [ pid ] uid tgid total_vm rss rss_anon rss_file rss_shmem pgtables_bytes swapents oom_score_adj name [ 57] 0 57 34359215953 695 256 0 439 1064390656 0 0 virtual_address Out of memory: Killed process 57 (virtual_address) total-vm:137436863812kB, anon-rss:1024kB, file-rss:0kB, shmem-rss:1756kB, UID:0 pgtables:1039444kB oom_score_adj:0 fault_in_iov_iter_readable+0x4a/0xd0 generic_perform_write+0x9c/0x280 shmem_file_write_iter+0x86/0x90 vfs_write+0x29c/0x480 ksys_write+0x6c/0xe0 do_syscall_64+0x9e/0x1a0 entry_SYSCALL_64_after_hwframe+0x77/0x7f Write the dumped data into /dev/null instead which does not require additional memory during write(), making the code simpler as a side-effect. Signed-off-by: Thomas Weißschuh --- tools/testing/selftests/mm/virtual_address_range.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/mm/virtual_address_range.c b/tools/testing/selftests/mm/virtual_address_range.c index 484f82c7b7c871f82a7d9ec6d6c649f2ab1eb0cd..4042fd878acd702d23da2c3293292de33bd48143 100644 --- a/tools/testing/selftests/mm/virtual_address_range.c +++ b/tools/testing/selftests/mm/virtual_address_range.c @@ -103,10 +103,9 @@ static int validate_complete_va_space(void) FILE *file; int fd; - fd = open("va_dump", O_CREAT | O_WRONLY, 0600); - unlink("va_dump"); + fd = open("/dev/null", O_WRONLY); if (fd < 0) { - ksft_test_result_skip("cannot create or open dump file\n"); + ksft_test_result_skip("cannot create or open /dev/null\n"); ksft_finished(); } @@ -152,7 +151,6 @@ static int validate_complete_va_space(void) while (start_addr + hop < end_addr) { if (write(fd, (void *)(start_addr + hop), 1) != 1) return 1; - lseek(fd, 0, SEEK_SET); hop += MAP_CHUNK_SIZE; }