Index | Thread | Search

From:
Dave Voutila <dv@sisu.io>
Subject:
zap uvm_share
To:
tech@openbsd.org
Date:
Wed, 21 May 2025 11:25:49 -0400

Download raw body.

Thread
  • Dave Voutila:

    zap uvm_share

Now that I've landed my vmm(4) changes to use UVM aobjs, there are no
consumers of uvm_share(). IIRC this was written specifically for vmm(4)
to be able to share map entries from a vmm-managed address space (UVM
vmspace) and userland process's address space (i.e. vmd(8)).

Had I included this in my vmm diff, it would have been net-negative ;)

ok?


diffstat refs/heads/master refs/heads/uvm-share
 M  sys/uvm/uvm_extern.h  |  0+    2-
 M  sys/uvm/uvm_map.c     |  0+  102-

2 files changed, 0 insertions(+), 104 deletions(-)

diff refs/heads/master refs/heads/uvm-share
commit - 1363fb03696276e9d6bf45c745eb6f898b4e85c7
commit + 45c377d4c19f731d8755ac51fbd065c99dd09c17
blob - 6e6de1bf2059e5295aab3efb8ca639777c9f9acc
blob + ba7e6bb0a22640c30b6ec262f75d2905ca60d10e
--- sys/uvm/uvm_extern.h
+++ sys/uvm/uvm_extern.h
@@ -403,8 +403,6 @@ struct vmspace		*uvmspace_fork(struct process *);
 void			uvmspace_addref(struct vmspace *);
 void			uvmspace_free(struct vmspace *);
 struct vmspace		*uvmspace_share(struct process *);
-int			uvm_share(vm_map_t, vaddr_t, vm_prot_t,
-			    vm_map_t, vaddr_t, vsize_t);
 int			uvm_sysctl(int *, u_int, void *, size_t *,
 			    void *, size_t, struct proc *);
 struct vm_page		*uvm_pagealloc(struct uvm_object *,
blob - 4666b57f5b9b6d8fd70a181d7d39349938ab59d7
blob + acc8af86dce0edb3bbc1508c10a37f7e3599e172
--- sys/uvm/uvm_map.c
+++ sys/uvm/uvm_map.c
@@ -3422,108 +3422,6 @@ uvmspace_free(struct vmspace *vm)
 }

 /*
- * uvm_share: Map the address range [srcaddr, srcaddr + sz) in
- * srcmap to the address range [dstaddr, dstaddr + sz) in
- * dstmap.
- *
- * The whole address range in srcmap must be backed by an object
- * (no holes).
- *
- * If successful, the address ranges share memory and the destination
- * address range uses the protection flags in prot.
- *
- * This routine assumes that sz is a multiple of PAGE_SIZE and
- * that dstaddr and srcaddr are page-aligned.
- */
-int
-uvm_share(struct vm_map *dstmap, vaddr_t dstaddr, vm_prot_t prot,
-    struct vm_map *srcmap, vaddr_t srcaddr, vsize_t sz)
-{
-	int ret = 0;
-	vaddr_t unmap_end;
-	vaddr_t dstva;
-	vsize_t s_off, len, n = sz, remain;
-	struct vm_map_entry *first = NULL, *last = NULL;
-	struct vm_map_entry *src_entry, *psrc_entry = NULL;
-	struct uvm_map_deadq dead;
-
-	if (srcaddr >= srcmap->max_offset || sz > srcmap->max_offset - srcaddr)
-		return EINVAL;
-
-	TAILQ_INIT(&dead);
-	vm_map_lock(dstmap);
-	vm_map_lock_read(srcmap);
-
-	if (!uvm_map_isavail(dstmap, NULL, &first, &last, dstaddr, sz)) {
-		ret = ENOMEM;
-		goto exit_unlock;
-	}
-	if (!uvm_map_lookup_entry(srcmap, srcaddr, &src_entry)) {
-		ret = EINVAL;
-		goto exit_unlock;
-	}
-
-	dstva = dstaddr;
-	unmap_end = dstaddr;
-	for (; src_entry != NULL;
-	    psrc_entry = src_entry,
-	    src_entry = RBT_NEXT(uvm_map_addr, src_entry)) {
-		/* hole in address space, bail out */
-		if (psrc_entry != NULL && psrc_entry->end != src_entry->start)
-			break;
-		if (src_entry->start >= srcaddr + sz)
-			break;
-
-		if (UVM_ET_ISSUBMAP(src_entry))
-			panic("uvm_share: encountered a submap (illegal)");
-		if (!UVM_ET_ISCOPYONWRITE(src_entry) &&
-		    UVM_ET_ISNEEDSCOPY(src_entry))
-			panic("uvm_share: non-copy_on_write map entries "
-			    "marked needs_copy (illegal)");
-
-		/*
-		 * srcaddr > map entry start? means we are in the middle of a
-		 * map, so we calculate the offset to use in the source map.
-		 */
-		if (srcaddr > src_entry->start)
-			s_off = srcaddr - src_entry->start;
-		else if (srcaddr == src_entry->start)
-			s_off = 0;
-		else
-			panic("uvm_share: map entry start > srcaddr");
-
-		remain = src_entry->end - src_entry->start - s_off;
-
-		/* Determine how many bytes to share in this pass */
-		if (n < remain)
-			len = n;
-		else
-			len = remain;
-
-		if (uvm_mapent_share(dstmap, dstva, len, s_off, prot, prot,
-		    srcmap, src_entry, &dead) == NULL)
-			break;
-
-		n -= len;
-		dstva += len;
-		srcaddr += len;
-		unmap_end = dstva + len;
-		if (n == 0)
-			goto exit_unlock;
-	}
-
-	ret = EINVAL;
-	uvm_unmap_remove(dstmap, dstaddr, unmap_end, &dead, FALSE, TRUE, FALSE);
-
-exit_unlock:
-	vm_map_unlock_read(srcmap);
-	vm_map_unlock(dstmap);
-	uvm_unmap_detach(&dead, 0);
-
-	return ret;
-}
-
-/*
  * Clone map entry into other map.
  *
  * Mapping will be placed at dstaddr, for the same length.