Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 2 Dec 2018 13:16:46 +0000 (UTC)
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r341398 - in head/sys: dev/xen/gntdev sys vm
Message-ID:  <201812021316.wB2DGkmC005859@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kib
Date: Sun Dec  2 13:16:46 2018
New Revision: 341398
URL: https://svnweb.freebsd.org/changeset/base/341398

Log:
  Change the vm_ooffset_t type to unsigned.
  
  The type represents byte offset in the vm_object_t data space, which
  does not span negative offsets in FreeBSD VM.  The change matches byte
  offset signess with the unsignedness of the vm_pindex_t which
  represents the type of the page indexes in the objects.
  
  This allows to remove the UOFF_TO_IDX() macro which was used when we
  have to forcibly interpret the type as unsigned anyway.  Also it fixes
  a lot of implicit bugs in the device drivers d_mmap methods.
  
  Reviewed by:	alc, markj (previous version)
  Tested by:	pho
  MFC after:	2 weeks
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/dev/xen/gntdev/gntdev.c
  head/sys/sys/types.h
  head/sys/vm/device_pager.c
  head/sys/vm/sg_pager.c
  head/sys/vm/vm_map.c
  head/sys/vm/vm_object.h

Modified: head/sys/dev/xen/gntdev/gntdev.c
==============================================================================
--- head/sys/dev/xen/gntdev/gntdev.c	Sun Dec  2 12:53:39 2018	(r341397)
+++ head/sys/dev/xen/gntdev/gntdev.c	Sun Dec  2 13:16:46 2018	(r341398)
@@ -814,8 +814,8 @@ gntdev_gmap_pg_fault(vm_object_t object, vm_ooffset_t 
 
 	relative_offset = offset - gmap->file_index;
 
-	pidx = UOFF_TO_IDX(offset);
-	ridx = UOFF_TO_IDX(relative_offset);
+	pidx = OFF_TO_IDX(offset);
+	ridx = OFF_TO_IDX(relative_offset);
 	if (ridx >= gmap->count ||
 	    gmap->grant_map_ops[ridx].status != GNTST_okay)
 		return (VM_PAGER_FAIL);
@@ -1085,7 +1085,7 @@ mmap_gref(struct per_user_data *priv_user, struct gntd
 			break;
 
 		vm_page_insert(gref->page, mem_obj,
-		    UOFF_TO_IDX(gref->file_index));
+		    OFF_TO_IDX(gref->file_index));
 
 		count--;
 	}
@@ -1225,7 +1225,7 @@ gntdev_mmap_single(struct cdev *cdev, vm_ooffset_t *of
 	if (error != 0)
 		return (EINVAL);
 
-	count = UOFF_TO_IDX(size);
+	count = OFF_TO_IDX(size);
 
 	gref_start = gntdev_find_grefs(priv_user, *offset, count);
 	if (gref_start) {

Modified: head/sys/sys/types.h
==============================================================================
--- head/sys/sys/types.h	Sun Dec  2 12:53:39 2018	(r341397)
+++ head/sys/sys/types.h	Sun Dec  2 13:16:46 2018	(r341398)
@@ -261,7 +261,7 @@ typedef	__uint64_t	kvaddr_t;
 typedef	__uint64_t	ksize_t;
 
 typedef	__vm_offset_t	vm_offset_t;
-typedef	__int64_t	vm_ooffset_t;
+typedef	__uint64_t	vm_ooffset_t;
 typedef	__vm_paddr_t	vm_paddr_t;
 typedef	__uint64_t	vm_pindex_t;
 typedef	__vm_size_t	vm_size_t;

Modified: head/sys/vm/device_pager.c
==============================================================================
--- head/sys/vm/device_pager.c	Sun Dec  2 12:53:39 2018	(r341397)
+++ head/sys/vm/device_pager.c	Sun Dec  2 13:16:46 2018	(r341398)
@@ -150,9 +150,9 @@ cdev_pager_allocate(void *handle, enum obj_type tp, st
 	 * of the page size.  Do a check to avoid wrap.
 	 */
 	size = round_page(size);
-	pindex = UOFF_TO_IDX(foff) + UOFF_TO_IDX(size);
-	if (pindex > OBJ_MAX_SIZE || pindex < UOFF_TO_IDX(foff) ||
-	    pindex < UOFF_TO_IDX(size))
+	pindex = OFF_TO_IDX(foff) + OFF_TO_IDX(size);
+	if (pindex > OBJ_MAX_SIZE || pindex < OFF_TO_IDX(foff) ||
+	    pindex < OFF_TO_IDX(size))
 		return (NULL);
 
 	if (ops->cdev_pg_ctor(handle, size, prot, foff, cred, &color) != 0)

Modified: head/sys/vm/sg_pager.c
==============================================================================
--- head/sys/vm/sg_pager.c	Sun Dec  2 12:53:39 2018	(r341397)
+++ head/sys/vm/sg_pager.c	Sun Dec  2 13:16:46 2018	(r341398)
@@ -100,9 +100,9 @@ sg_pager_alloc(void *handle, vm_ooffset_t size, vm_pro
 	 * to map beyond that.
 	 */
 	size = round_page(size);
-	pindex = UOFF_TO_IDX(foff) + UOFF_TO_IDX(size);
-	if (pindex > npages || pindex < UOFF_TO_IDX(foff) ||
-	    pindex < UOFF_TO_IDX(size))
+	pindex = OFF_TO_IDX(foff) + OFF_TO_IDX(size);
+	if (pindex > npages || pindex < OFF_TO_IDX(foff) ||
+	    pindex < OFF_TO_IDX(size))
 		return (NULL);
 
 	/*

Modified: head/sys/vm/vm_map.c
==============================================================================
--- head/sys/vm/vm_map.c	Sun Dec  2 12:53:39 2018	(r341397)
+++ head/sys/vm/vm_map.c	Sun Dec  2 13:16:46 2018	(r341398)
@@ -4213,7 +4213,7 @@ RetryLookupLocked:
 	 * Return the object/offset from this entry.  If the entry was
 	 * copy-on-write or empty, it has been fixed up.
 	 */
-	*pindex = UOFF_TO_IDX((vaddr - entry->start) + entry->offset);
+	*pindex = OFF_TO_IDX((vaddr - entry->start) + entry->offset);
 	*object = entry->object.vm_object;
 
 	*out_prot = prot;
@@ -4294,7 +4294,7 @@ vm_map_lookup_locked(vm_map_t *var_map,		/* IN/OUT */
 	 * Return the object/offset from this entry.  If the entry was
 	 * copy-on-write or empty, it has been fixed up.
 	 */
-	*pindex = UOFF_TO_IDX((vaddr - entry->start) + entry->offset);
+	*pindex = OFF_TO_IDX((vaddr - entry->start) + entry->offset);
 	*object = entry->object.vm_object;
 
 	*out_prot = prot;

Modified: head/sys/vm/vm_object.h
==============================================================================
--- head/sys/vm/vm_object.h	Sun Dec  2 12:53:39 2018	(r341397)
+++ head/sys/vm/vm_object.h	Sun Dec  2 13:16:46 2018	(r341398)
@@ -196,20 +196,13 @@ struct vm_object {
 /*
  * Helpers to perform conversion between vm_object page indexes and offsets.
  * IDX_TO_OFF() converts an index into an offset.
- * OFF_TO_IDX() converts an offset into an index.  Since offsets are signed
- *   by default, the sign propagation in OFF_TO_IDX(), when applied to
- *   negative offsets, is intentional and returns a vm_object page index
- *   that cannot be created by a userspace mapping.
- * UOFF_TO_IDX() treats the offset as an unsigned value and converts it
- *   into an index accordingly.  Use it only when the full range of offset
- *   values are allowed.  Currently, this only applies to device mappings.
+ * OFF_TO_IDX() converts an offset into an index.
  * OBJ_MAX_SIZE specifies the maximum page index corresponding to the
  *   maximum unsigned offset.
  */
 #define	IDX_TO_OFF(idx) (((vm_ooffset_t)(idx)) << PAGE_SHIFT)
 #define	OFF_TO_IDX(off) ((vm_pindex_t)(((vm_ooffset_t)(off)) >> PAGE_SHIFT))
-#define	UOFF_TO_IDX(off) (((vm_pindex_t)(off)) >> PAGE_SHIFT)
-#define	OBJ_MAX_SIZE	(UOFF_TO_IDX(UINT64_MAX) + 1)
+#define	OBJ_MAX_SIZE	(OFF_TO_IDX(UINT64_MAX) + 1)
 
 #ifdef	_KERNEL
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201812021316.wB2DGkmC005859>