From nobody Sat Oct 05 07:11:05 2024 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XLGmB1rzJz5Xr71; Sat, 05 Oct 2024 07:11:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XLGm960dDz4N4v; Sat, 5 Oct 2024 07:11:05 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728112265; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LTkCrKykXhNV1qOJIB4+Kc2DE+7P0LJYk4BOs7BNGV4=; b=ZAP75rZpfO5lDFbfPPDF15uPMGv+JcGQ4x/b4GxT0BgUYgSeqKwhrwgOZxatIlehhSDbww hmjKYLieOR+0EtsrpcoloMmt2o5Eq/yjOmUyF4a4I6sHTjOPQQ9JO+O7Lnsp9hxaGDrIYI 3S20b9Ak4BH4NFxBkEgrC5Aw/0shFsYNHVdTg0tushrhJDVfBdkXXx0pTJxOncHStwqcTg hy/dE/5gSG4vwpJjLmKgLM6TL6EVXPaYRj1uT11EB1/3qKP3DNI5SHrguV1VcgaEtXGSkE /tqhbPrumjc7on7wPc6qAGPaKL8+hp0D5NKfxDsWilt7EOndgyzJkYm5vCRw7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1728112265; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=LTkCrKykXhNV1qOJIB4+Kc2DE+7P0LJYk4BOs7BNGV4=; b=SyIlM0diiLMuXoDGl7mSP5XUKhJw/HNPxpnmn9wx8uOGYIZtZl6yYhdDYL2e4ETwSfEb2H qHFkE/YJyFzUcjJYbB5PrFFm9SYAl8dJ/Lq/2qUivAIvuERiVukfcGpANcm7tsRcPn4CUd XQNXZ1j5DlXeCFL+CP8i5hllYf/MTnuXMGbFb1xamLYQc0GTHfkIyyI4AEHRhkYgvRF2Om A3OnODNmliQsVse1T4fVCOcAqPkuEzaAnK/OqwklzqlOyw0Y1pAb9VPk6jv2xbEgPif3XJ KeUxq6OXu3pMFUw7rLf5KVPoV5LjOHl7JrN8oVSklcNsiFlm94pEAI3jQWJ/xQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1728112265; a=rsa-sha256; cv=none; b=EcpVE/GKQ1qxGu0eKAxk72omNhSsK682goIkIfrbiVyNlTwhCd9baPgTZolBWyxwr8R2Wl bPXMPf5z+khlmd/cW8jecgS266gkznjLT7bUkEBdl8ouYIduzs07WYNJRlGkWsSJen0qCC H65/cTNWDQa/uZSvCbp2I6KMkGnFTqk2dhoKI47ONgFJpopFf0PRrh9WNudDXc6wwlyzoV P0t4inF/C9wUyHFSg9m5fDWBdGfyRltk00t7OtdJvD63Va+s1fLD8BFmg4/FYmQf4kVnYD JFqWRKAUtgdpBzRMENERNMKJmvjDk+64RG1dVzpiokXnnerJ81DAHWvixQ5U6w== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XLGm95bCKz17r8; Sat, 5 Oct 2024 07:11:05 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 4957B53p000733; Sat, 5 Oct 2024 07:11:05 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4957B5Pr000730; Sat, 5 Oct 2024 07:11:05 GMT (envelope-from git) Date: Sat, 5 Oct 2024 07:11:05 GMT Message-Id: <202410050711.4957B5Pr000730@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 4cb8ec6c6f81 - stable/14 - vm_map: add vm_map_find_locked(9) List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: 4cb8ec6c6f81243da158def4525f92c6dc7b964b Auto-Submitted: auto-generated The branch stable/14 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=4cb8ec6c6f81243da158def4525f92c6dc7b964b commit 4cb8ec6c6f81243da158def4525f92c6dc7b964b Author: Konstantin Belousov AuthorDate: 2024-09-15 06:29:28 +0000 Commit: Konstantin Belousov CommitDate: 2024-10-05 07:08:54 +0000 vm_map: add vm_map_find_locked(9) (cherry picked from commit 0ecbb28ce351652b3a2dae271eedf1eb3aa65400) --- sys/vm/vm_map.c | 50 +++++++++++++++++++++++++++++++++----------------- sys/vm/vm_map.h | 2 ++ 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 97b96a46e4b2..28cf309f86c3 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -2113,9 +2113,24 @@ vm_map_find_aligned(vm_map_t map, vm_offset_t *addr, vm_size_t length, */ int vm_map_find(vm_map_t map, vm_object_t object, vm_ooffset_t offset, - vm_offset_t *addr, /* IN/OUT */ - vm_size_t length, vm_offset_t max_addr, int find_space, - vm_prot_t prot, vm_prot_t max, int cow) + vm_offset_t *addr, /* IN/OUT */ + vm_size_t length, vm_offset_t max_addr, int find_space, + vm_prot_t prot, vm_prot_t max, int cow) +{ + int rv; + + vm_map_lock(map); + rv = vm_map_find_locked(map, object, offset, addr, length, max_addr, + find_space, prot, max, cow); + vm_map_unlock(map); + return (rv); +} + +int +vm_map_find_locked(vm_map_t map, vm_object_t object, vm_ooffset_t offset, + vm_offset_t *addr, /* IN/OUT */ + vm_size_t length, vm_offset_t max_addr, int find_space, + vm_prot_t prot, vm_prot_t max, int cow) { vm_offset_t alignment, curr_min_addr, min_addr; int gap, pidx, rv, try; @@ -2123,7 +2138,7 @@ vm_map_find(vm_map_t map, vm_object_t object, vm_ooffset_t offset, KASSERT((cow & (MAP_STACK_GROWS_DOWN | MAP_STACK_GROWS_UP)) == 0 || object == NULL, - ("vm_map_find: non-NULL backing object for stack")); + ("non-NULL backing object for stack")); MPASS((cow & MAP_REMAP) == 0 || (find_space == VMFS_NO_SPACE && (cow & (MAP_STACK_GROWS_DOWN | MAP_STACK_GROWS_UP)) == 0)); if (find_space == VMFS_OPTIMAL_SPACE && (object == NULL || @@ -2146,7 +2161,6 @@ vm_map_find(vm_map_t map, vm_object_t object, vm_ooffset_t offset, (map->flags & MAP_ASLR_IGNSTART) != 0) curr_min_addr = min_addr = vm_map_min(map); try = 0; - vm_map_lock(map); if (cluster) { curr_min_addr = map->anon_loc; if (curr_min_addr == 0) @@ -2217,8 +2231,7 @@ again: MPASS(try == 1); goto again; } - rv = KERN_NO_SPACE; - goto done; + return (KERN_NO_SPACE); } } @@ -2232,16 +2245,14 @@ again: try = 0; goto again; } - goto done; + return (rv); } } else if ((cow & MAP_REMAP) != 0) { - if (!vm_map_range_valid(map, *addr, *addr + length)) { - rv = KERN_INVALID_ADDRESS; - goto done; - } + if (!vm_map_range_valid(map, *addr, *addr + length)) + return (KERN_INVALID_ADDRESS); rv = vm_map_delete(map, *addr, *addr + length); if (rv != KERN_SUCCESS) - goto done; + return (rv); } if ((cow & (MAP_STACK_GROWS_DOWN | MAP_STACK_GROWS_UP)) != 0) { rv = vm_map_stack_locked(map, *addr, length, sgrowsiz, prot, @@ -2250,10 +2261,15 @@ again: rv = vm_map_insert(map, object, offset, *addr, *addr + length, prot, max, cow); } - if (rv == KERN_SUCCESS && update_anon) - map->anon_loc = *addr + length; -done: - vm_map_unlock(map); + + /* + * Update the starting address for clustered anonymous memory mappings + * if a starting address was not previously defined or an ASLR restart + * placed an anonymous memory mapping at a lower address. + */ + if (update_anon && rv == KERN_SUCCESS && (map->anon_loc == 0 || + *addr < map->anon_loc)) + map->anon_loc = *addr; return (rv); } diff --git a/sys/vm/vm_map.h b/sys/vm/vm_map.h index c0b3be886505..5d41f892e83d 100644 --- a/sys/vm/vm_map.h +++ b/sys/vm/vm_map.h @@ -475,6 +475,8 @@ boolean_t vm_map_check_protection (vm_map_t, vm_offset_t, vm_offset_t, vm_prot_t int vm_map_delete(vm_map_t, vm_offset_t, vm_offset_t); int vm_map_find(vm_map_t, vm_object_t, vm_ooffset_t, vm_offset_t *, vm_size_t, vm_offset_t, int, vm_prot_t, vm_prot_t, int); +int vm_map_find_locked(vm_map_t, vm_object_t, vm_ooffset_t, vm_offset_t *, + vm_size_t, vm_offset_t, int, vm_prot_t, vm_prot_t, int); int vm_map_find_min(vm_map_t, vm_object_t, vm_ooffset_t, vm_offset_t *, vm_size_t, vm_offset_t, vm_offset_t, int, vm_prot_t, vm_prot_t, int); int vm_map_find_aligned(vm_map_t map, vm_offset_t *addr, vm_size_t length,