From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 F24C71FC7E8 for ; Wed, 8 Jan 2025 13:37:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736343425; cv=none; b=odnDpFU7bnt5f7gb3ZEIuh5D7UzlgNhSaWhzfllypTm0KV/0Gn2zwgLKhpwCh+c9jQD32LmF3Q3gjw3Ln2MiL5jjqrDgCmOOakNYcWD+ceCtbPYdi0GV+x6JQF7B7ePGdxWaphXvqb+/Jfay6Ro6hbXg2JPmRqj4anNFH+DBE+w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736343425; c=relaxed/simple; bh=bR49NeAcqnBpYnIGt3UxD0ltl98y8XRMc2zqRmIn4Jw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=LuTDDQPpm67k/+Sidjv/IsQ5KJ8Ufca4NLUizb0eSeIovV/y6YnQPldOpIu8hF7Fg7P0C6PW5Z7k4Poo35GwiU/NuFitmpnXS3JTcynHZ4tLb/WrCx/VqJXmYRGhTHQZ9ZMEqfwFgf7/T1feFTwUXqwbAyb0R4sxUrBXFrYKRrc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Z31eqc6O; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Z31eqc6O" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736343423; 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:autocrypt:autocrypt; bh=zsYn+ubCj/k9frOyIineKG0YZObECCsgzLG4WJOG0aI=; b=Z31eqc6OR3m1ICKRnVMxGfShjCFw21mnEfkGSQxXHSBBx7dfeOdI85i+qYdskXyEMdNHhi jg5N6iQqjE2uUgOM/9Y01K5sZkbFblId7eaT7Bcic9t6OCaYCQTE2739Df+Bwynnv6I+TZ rIn6ylCwy47c6pAMNsXce32ldgtinIw= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-523-4NOhDVn8OTS6hi-0906etQ-1; Wed, 08 Jan 2025 08:37:01 -0500 X-MC-Unique: 4NOhDVn8OTS6hi-0906etQ-1 X-Mimecast-MFC-AGG-ID: 4NOhDVn8OTS6hi-0906etQ Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-436248d1240so81193975e9.0 for ; Wed, 08 Jan 2025 05:37:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736343420; x=1736948220; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=zsYn+ubCj/k9frOyIineKG0YZObECCsgzLG4WJOG0aI=; b=WFuWe4wNhpGV2vDntcsPQegsTlOWh0W9zBl41AVSpCZ4WE6oWT3LRuCx3/HmTHViXt LE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.33.1736343420378; Wed, 08 Jan 2025 05:37:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGrSkuA9DL05/QwULjdNVhbRGazffwqTwips2esLt0D2KtCFRWfwckJpNfcFhO/QWP//kZ1mw== X-Received: by 2002:a05:600c:1388:b0:434:f871:1b97 with SMTP id 5b1f17b1804b1-436e26fa594mr21205985e9.33.1736343419988; Wed, 08 Jan 2025 05:36:59 -0800 (PST) Received: from ?IPV6:2003:cb:c70d:3a00:d73c:6a8:ca9f:1df7? (p200300cbc70d3a00d73c06a8ca9f1df7.dip0.t-ipconnect.de. [2003:cb:c70d:3a00:d73c:6a8:ca9f:1df7]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-436e2e21e1esm21180205e9.38.2025.01.08.05.36.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 08 Jan 2025 05:36:58 -0800 (PST) Message-ID: <05edee1e-04f1-4f19-816f-db03c182a201@redhat.com> Date: Wed, 8 Jan 2025 14:36:57 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 1/3] selftests/mm: virtual_address_range: Fix error when CommitLimit < 1GiB To: =?UTF-8?Q?Thomas_Wei=C3=9Fschuh?= , 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 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> <20250108083855-840c688b-003f-423b-8327-2a10a2b27d58@linutronix.de> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/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JI9XQssfrf4Gusdqx8nPEpfOqCtbbwJMATbHyqLt7/oz/5deGuwxgb65pWIzufa N7eop7uh+6bezi+rugUI+w6DABEBAAHCwXwEGAEIACYCGwwWIQQb2cqtc1xMOkYN/MpN3hD3 AP+DWgUCXw7HsgUJEqkpoQAKCRBN3hD3AP+DWrrpD/4qS3dyVRxDcDHIlmguXjC1Q5tZTwNB boaBTPHSy/Nksu0eY7x6HfQJ3xajVH32Ms6t1trDQmPx2iP5+7iDsb7OKAb5eOS8h+BEBDeq 3ecsQDv0fFJOA9ag5O3LLNk+3x3q7e0uo06XMaY7UHS341ozXUUI7wC7iKfoUTv03iO9El5f XpNMx/YrIMduZ2+nd9Di7o5+KIwlb2mAB9sTNHdMrXesX8eBL6T9b+MZJk+mZuPxKNVfEQMQ a5SxUEADIPQTPNvBewdeI80yeOCrN+Zzwy/Mrx9EPeu59Y5vSJOx/z6OUImD/GhX7Xvkt3kq Er5KTrJz3++B6SH9pum9PuoE/k+nntJkNMmQpR4MCBaV/J9gIOPGodDKnjdng+mXliF3Ptu6 3oxc2RCyGzTlxyMwuc2U5Q7KtUNTdDe8T0uE+9b8BLMVQDDfJjqY0VVqSUwImzTDLX9S4g/8 kC4HRcclk8hpyhY2jKGluZO0awwTIMgVEzmTyBphDg/Gx7dZU1Xf8HFuE+UZ5UDHDTnwgv7E th6RC9+WrhDNspZ9fJjKWRbveQgUFCpe1sa77LAw+XFrKmBHXp9ZVIe90RMe2tRL06BGiRZr jPrnvUsUUsjRoRNJjKKA/REq+sAnhkNPPZ/NNMjaZ5b8Tovi8C0tmxiCHaQYqj7G2rgnT0kt WNyWQQ== Organization: Red Hat In-Reply-To: <20250108083855-840c688b-003f-423b-8327-2a10a2b27d58@linutronix.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 08.01.25 09:05, Thomas Weißschuh wrote: > 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 CC stable on tests is ... odd. >>> 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. > Note that with MAP_NORESRVE, most setups we care about will allow mapping as much as you want, but on access OOM will fire. So one could require that /proc/sys/vm/overcommit_memory is setup properly and use MAP_NORESRVE. Reading from anonymous memory will populate the shared zeropage. To mitigate OOM from "too many page tables", one could simply unmap the pieces as they are verified (or MAP_FIXED over them, to free page tables). -- Cheers, David / dhildenb