From mboxrd@z Thu Jan 1 00:00:00 1970 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 D0F88E77199 for ; Wed, 8 Jan 2025 08:05:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 32C156B00AD; Wed, 8 Jan 2025 03:05:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2DC196B00AF; Wed, 8 Jan 2025 03:05:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1CB0B6B00B1; Wed, 8 Jan 2025 03:05:54 -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 F0C1C6B00AD for ; Wed, 8 Jan 2025 03:05:53 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id AA83B1A1021 for ; Wed, 8 Jan 2025 08:05:53 +0000 (UTC) X-FDA: 82983550986.06.46E6418 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by imf20.hostedemail.com (Postfix) with ESMTP id D57F81C0010 for ; Wed, 8 Jan 2025 08:05:51 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b="ln3Ko/U9"; dkim=pass header.d=linutronix.de header.s=2020e header.b=HsNNeh3R; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf20.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=1736323552; a=rsa-sha256; cv=none; b=hD4eyOi4ZwuVunG7+b4XCOFgxLJY9n0eH+Nqp0DS7uh/z/Fgr89OG4HDqxqIKvh6K9Ye9A ErpSsEZTqowvpFHYXaLYIyEX53RajlSR69Ha4obSJlJDCq28W9WriQNEB65+PkKw4E7cCH 4BjEiEp/0ZWD0s5Z1F9JynXG/gn0l8E= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=linutronix.de header.s=2020 header.b="ln3Ko/U9"; dkim=pass header.d=linutronix.de header.s=2020e header.b=HsNNeh3R; dmarc=pass (policy=none) header.from=linutronix.de; spf=pass (imf20.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=1736323552; 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=qJmg0rlYDsu9eOC/BK9/42GtYToiXcNh3fOPiQsHx28=; b=kY3OmOmXud37M0/hgWHXIwYnccqy7+xt/JBOUD1nwcwZwQyLYmqXdHlMIu+i+cXDaSgdBO GpIvK8RRNOZr7MGk0rxB4KoWpiXyM0dtLAZ4NJJJwN54MkWo5LzBVMtlU03sQFBlvrwwAM YXrXSE7mF7r7PdbA1kVjCxko4dPF0Yg= Date: Wed, 8 Jan 2025 09:05:48 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1736323549; 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=qJmg0rlYDsu9eOC/BK9/42GtYToiXcNh3fOPiQsHx28=; b=ln3Ko/U9q5IFu3FTm0+YzBkPfHxxpock+ZTNMzitMYQtFkBRw2JpSECshDnLIfF/rN00Op fSQBOOJ3EYl3Sdwxi0WOWxF5hepkHR6hgNjrPm4g7c+LHI5pHJwxRV+caev0kBNQYZkxhA y3GWzSBW4DxJ03ywD1mAJN0H05Wc/JmEh0/62pa40wWCDBFb7l+4w9volysE35CZbpwb7S IUGlYW3zmXUMhjAC8mSliphBfcTtVkObUjv9J/bqeX44dAtILZMR+F6abM+WN65eI1iPk0 3D4lRGPUmrzx0V+E/VogYIy7WY4zfei3T5DVaWy3xx5LrhFmVkbNQeL7mF9Vow== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1736323549; 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=qJmg0rlYDsu9eOC/BK9/42GtYToiXcNh3fOPiQsHx28=; b=HsNNeh3RFpXd9rSUKsJHzCMMKUHXeFrMxlbNDm6s6+G9tA68kvlcLaXQnjcObvgWD/s1Be 10Eqm24ER82AgcBA== From: Thomas =?utf-8?Q?Wei=C3=9Fschuh?= To: Dev Jain Cc: Andrew Morton , Shuah Khan , Thomas Gleixner , linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Ryan Roberts , David Hildenbrand Subject: Re: [PATCH 1/3] selftests/mm: virtual_address_range: Fix error when CommitLimit < 1GiB Message-ID: <20250108083855-840c688b-003f-423b-8327-2a10a2b27d58@linutronix.de> References: <20250107-virtual_address_range-tests-v1-0-3834a2fb47fe@linutronix.de> <20250107-virtual_address_range-tests-v1-1-3834a2fb47fe@linutronix.de> <5811cf74-d333-4653-ab64-0e981eda7745@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <5811cf74-d333-4653-ab64-0e981eda7745@arm.com> X-Stat-Signature: x973f3rtt5etzy7sh83nakaqdgiess13 X-Rspam-User: X-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gs9PhFHdtTrZkUWLiNU4hMUlnoX0o4qTdiXM9RbWLV/u26b6I7Fhfkb8LfxySXW/ed2ejPOMHWReQSIZkjffmBBXn4ydC9KNLIcy74YdPgHD8bCnA3ATqWhFMjW/74n5GyLrYccSkxaMgSj/jIusU70ZBbMGWGT0oOn+upy/Q30ad8+GKUOM4yoPz/Lg/QwE0VtEKGkk5sFR1FY1z3RsAgpxbX9iJerQgTVgXgRup+p130r5yBDDE11FDMRyJNT0SxkimU+8mVdHGjvXec5JhJXHMNiR53GoEVWqENHu6WhspGqaA059MLQnO04Ks1PQjQbWR4DvUNKOE5am36jLotulvzYXey1xo8ON6hCIsR5tJYT6lh4O0W24HtjklmKVPA4ta3hcHH53JOhnkjVsy5Srn2kWAg75gVB/Hg9vQ50qxm1SIKoKA3CVcId5LN2pJKtmlaRJITo2wvlCug 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: On Wed, Jan 08, 2025 at 11:46:19AM +0530, Dev Jain wrote: > > On 07/01/25 8:44 pm, Thomas Weißschuh wrote: > > 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"); > > > > I do not know about __vm_enough_memory(), but I am going by your description: > You say that the kernel may fail mmap() when enough physical memory is not > there, but it may happen that we have already done 100 mmap()'s, and then > the kernel fails mmap(), so if (!lchunks) won't be able to handle this case. > Basically, lchunks == 0 is not a complete indicator of kernel failing mmap(). __vm_enough_memory() only checks the size of each single mmap() on its own. It does not actually check the current memory or address space usage of the process. This seems a bit weird, as indicated in my after-the-fold explanation. > The basic assumption of the test is that any process should be able to exhaust > its virtual address space, and running the test under memory pressure and the > kernel violating this behaviour defeats the point of the test I think? The assumption is correct, as soon as one mapping succeeds the others will also succeed, until the actual address space is exhausted. Looking at it again, __vm_enough_memory() is only called for writable mappings, so it would be possible to use only readable mappings in the test. The test will still fail with OOM, as the many PTEs need more than 1GiB of physical memory anyways, but at least that produces a usable error message. However I'm not sure if this would violate other test assumptions.