From nobody Fri Aug 25 01:08:29 2023 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 4RX1zd49Vsz4qZmF; Fri, 25 Aug 2023 01:08:29 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RX1zd3HRVz4SDQ; Fri, 25 Aug 2023 01:08:29 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692925709; 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=LtKlWOJUzn1sdfatOtGPY/G2PZNk7QmKr3Sv5Zq6w5g=; b=LiOhxnkwEjeEbLtM+EGwKAzKwhFToFO2UJkd/BUbkFWVp/8cpqeg2aYvJufdcpx6wqTq5O oTqSZqZK6vjr4uqsvy8/k31DHv67RYRvzow2lSAPuKtugtTs6vlMPKpVS/bTkyCNK74zns kdWrbqjKGJU/0N74Bss7c9xAfwTSZyehmOGlUrxOxyznPLYWCwSTQV6qo6iNyRaLqWAWPY nc6qpONoBBuRqU/6IqdliiWuRvHBxxTfGVoll2S2Jy93xyKpm64TFt6SnOoS/EZ0Csb3nO SbC6nB7LQ3tyyCDnvtBv290SO74cMpc7XB3OwGgua44EJ3LWY+WMSDoPvC6lxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1692925709; 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=LtKlWOJUzn1sdfatOtGPY/G2PZNk7QmKr3Sv5Zq6w5g=; b=llGg79FcJ8w9i2IwTMkQfceetUEfHsHrn2zCfLQdI1FXvcP630/Hc5NoTM02vIAAKPiIG7 USb/+76i9yzyzVexO4JSUk697+YiIhGKmp9vx/rekvyHUnR2zYXcJV5m2lwaKUAigmjz6E Pbxw2u6c1hrY8GXEQrYcJRxHTP+t5yxgdiaQ/cUBSf+7oIKxdRV8m+n6KQQlHH7q1iffnM Jd0MV47EayAhvtKztX1d8B293Sbh9XAp+LYJtho6yvQMFZJ14OqmXM/gobEBf5Herh5E4Q /E0FD6QhhEuNdznSEb06YSCjRQSyM0jcUvhzFFb89DyGfB0hOZz4Gwt4wkeD/g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1692925709; a=rsa-sha256; cv=none; b=HaBokUx1B9OWxMxAfDQmg1DQhTtgED25pHHqh0VPfo98wfKKtepSEuZ9+Z2IYQ4b6+U7eE sIDTYvF4bG9JocD0ZTgDl04iTTrjiGfDUu7AXJidbHUjS1m+8CnLW3tITAIqmwV6K+LHke R0XsSewYo72zP2IkdZ04KWZyRMXAsxkTScbTvFxqKfd6Delwu69Hu44oVMwZ3Yys41MYX+ ePFfwI3sr0a6fFJZe3RcRMt0c1Ko5XQ1m6rlSMDBdVWr5/8o9h8pCi1TzkdDnjUQoL2F8c teVksBF6Gdcz4Ke5NB0fDwVVd5Hjuz8jkIdRxZaH5OMoGaDP8bmavR0BKcH/qA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4RX1zd2NGfzplH; Fri, 25 Aug 2023 01:08:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 37P18T6J058135; Fri, 25 Aug 2023 01:08:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 37P18ToO058132; Fri, 25 Aug 2023 01:08:29 GMT (envelope-from git) Date: Fri, 25 Aug 2023 01:08:29 GMT Message-Id: <202308250108.37P18ToO058132@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: 820ff1974625 - stable/13 - Add vm_map_insert1(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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: 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/13 X-Git-Reftype: branch X-Git-Commit: 820ff197462530b169fcc40283a45d18f41b2dfc Auto-Submitted: auto-generated The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=820ff197462530b169fcc40283a45d18f41b2dfc commit 820ff197462530b169fcc40283a45d18f41b2dfc Author: Konstantin Belousov AuthorDate: 2023-07-19 16:44:18 +0000 Commit: Konstantin Belousov CommitDate: 2023-08-25 01:06:43 +0000 Add vm_map_insert1(9) (cherry picked from commit ba41b0de3ef2b29c5c1155c7550785ed4b491bd8) --- sys/vm/vm_map.c | 75 +++++++++++++++++++++++++++++++++++++++------------------ sys/vm/vm_map.h | 2 +- 2 files changed, 52 insertions(+), 25 deletions(-) diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 1f111448a49d..27360f70e1e1 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -1599,19 +1599,16 @@ vm_map_lookup_entry( } /* - * vm_map_insert: - * - * Inserts the given VM object into the target map at the - * specified address range. - * - * Requires that the map be locked, and leaves it so. - * - * If object is non-NULL, ref count must be bumped by caller - * prior to making call to account for the new entry. + * vm_map_insert1() is identical to vm_map_insert() except that it + * returns the newly inserted map entry in '*res'. In case the new + * entry is coalesced with a neighbor or an existing entry was + * resized, that entry is returned. In any case, the returned entry + * covers the specified address range. */ -int -vm_map_insert(vm_map_t map, vm_object_t object, vm_ooffset_t offset, - vm_offset_t start, vm_offset_t end, vm_prot_t prot, vm_prot_t max, int cow) +static int +vm_map_insert1(vm_map_t map, vm_object_t object, vm_ooffset_t offset, + vm_offset_t start, vm_offset_t end, vm_prot_t prot, vm_prot_t max, int cow, + vm_map_entry_t *res) { vm_map_entry_t new_entry, next_entry, prev_entry; struct ucred *cred; @@ -1758,7 +1755,8 @@ charged: map->size += end - prev_entry->end; vm_map_entry_resize(map, prev_entry, end - prev_entry->end); - vm_map_try_merge_entries(map, prev_entry, next_entry); + *res = vm_map_try_merge_entries(map, prev_entry, + next_entry); return (KERN_SUCCESS); } @@ -1819,7 +1817,7 @@ charged: * other cases, which are less common. */ vm_map_try_merge_entries(map, prev_entry, new_entry); - vm_map_try_merge_entries(map, new_entry, next_entry); + *res = vm_map_try_merge_entries(map, new_entry, next_entry); if ((cow & (MAP_PREFAULT | MAP_PREFAULT_PARTIAL)) != 0) { vm_map_pmap_enter(map, start, prot, object, OFF_TO_IDX(offset), @@ -1829,6 +1827,27 @@ charged: return (KERN_SUCCESS); } +/* + * vm_map_insert: + * + * Inserts the given VM object into the target map at the + * specified address range. + * + * Requires that the map be locked, and leaves it so. + * + * If object is non-NULL, ref count must be bumped by caller + * prior to making call to account for the new entry. + */ +int +vm_map_insert(vm_map_t map, vm_object_t object, vm_ooffset_t offset, + vm_offset_t start, vm_offset_t end, vm_prot_t prot, vm_prot_t max, int cow) +{ + vm_map_entry_t res; + + return (vm_map_insert1(map, object, offset, start, end, prot, max, + cow, &res)); +} + /* * vm_map_findspace: * @@ -2312,13 +2331,14 @@ vm_map_merged_neighbor_dispose(vm_map_t map, vm_map_entry_t entry) /* * vm_map_try_merge_entries: * - * Compare the given map entry to its predecessor, and merge its precessor - * into it if possible. The entry remains valid, and may be extended. - * The predecessor may be deleted. + * Compare two map entries that represent consecutive ranges. If + * the entries can be merged, expand the range of the second to + * cover the range of the first and delete the first. Then return + * the map entry that includes the first range. * * The map must be locked. */ -void +vm_map_entry_t vm_map_try_merge_entries(vm_map_t map, vm_map_entry_t prev_entry, vm_map_entry_t entry) { @@ -2328,7 +2348,9 @@ vm_map_try_merge_entries(vm_map_t map, vm_map_entry_t prev_entry, vm_map_mergeable_neighbors(prev_entry, entry)) { vm_map_entry_unlink(map, prev_entry, UNLINK_MERGE_NEXT); vm_map_merged_neighbor_dispose(map, prev_entry); + return (entry); } + return (prev_entry); } /* @@ -4548,10 +4570,10 @@ vm_map_stack_locked(vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize, gap_bot = top; gap_top = addrbos + max_ssize; } - rv = vm_map_insert(map, NULL, 0, bot, top, prot, max, cow); + rv = vm_map_insert1(map, NULL, 0, bot, top, prot, max, cow, + &new_entry); if (rv != KERN_SUCCESS) return (rv); - new_entry = vm_map_entry_succ(prev_entry); KASSERT(new_entry->end == top || new_entry->start == bot, ("Bad entry start/end for new stack entry")); KASSERT((orient & MAP_STACK_GROWS_DOWN) == 0 || @@ -4562,10 +4584,17 @@ vm_map_stack_locked(vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize, ("new entry lacks MAP_ENTRY_GROWS_UP")); if (gap_bot == gap_top) return (KERN_SUCCESS); - rv = vm_map_insert(map, NULL, 0, gap_bot, gap_top, VM_PROT_NONE, + rv = vm_map_insert1(map, NULL, 0, gap_bot, gap_top, VM_PROT_NONE, VM_PROT_NONE, MAP_CREATE_GUARD | (orient == MAP_STACK_GROWS_DOWN ? - MAP_CREATE_STACK_GAP_DN : MAP_CREATE_STACK_GAP_UP)); + MAP_CREATE_STACK_GAP_DN : MAP_CREATE_STACK_GAP_UP), &gap_entry); if (rv == KERN_SUCCESS) { + KASSERT((gap_entry->eflags & MAP_ENTRY_GUARD) != 0, + ("entry %p not gap %#x", gap_entry, gap_entry->eflags)); + KASSERT((gap_entry->eflags & (MAP_ENTRY_STACK_GAP_DN | + MAP_ENTRY_STACK_GAP_UP)) != 0, + ("entry %p not stack gap %#x", gap_entry, + gap_entry->eflags)); + /* * Gap can never successfully handle a fault, so * read-ahead logic is never used for it. Re-use @@ -4575,8 +4604,6 @@ vm_map_stack_locked(vm_map_t map, vm_offset_t addrbos, vm_size_t max_ssize, * store the original stack protections in the * object offset. */ - gap_entry = orient == MAP_STACK_GROWS_DOWN ? - vm_map_entry_pred(new_entry) : vm_map_entry_succ(new_entry); gap_entry->next_read = sgp; gap_entry->offset = prot; } else { diff --git a/sys/vm/vm_map.h b/sys/vm/vm_map.h index 85d622ee1bb6..8adfcaf57cb3 100644 --- a/sys/vm/vm_map.h +++ b/sys/vm/vm_map.h @@ -522,7 +522,7 @@ vm_map_entry_succ(vm_map_entry_t entry) int vm_map_protect(vm_map_t map, vm_offset_t start, vm_offset_t end, vm_prot_t new_prot, vm_prot_t new_maxprot, int flags); int vm_map_remove (vm_map_t, vm_offset_t, vm_offset_t); -void vm_map_try_merge_entries(vm_map_t map, vm_map_entry_t prev, +vm_map_entry_t vm_map_try_merge_entries(vm_map_t map, vm_map_entry_t prev, vm_map_entry_t entry); void vm_map_startup (void); int vm_map_submap (vm_map_t, vm_offset_t, vm_offset_t, vm_map_t);