Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 3 Sep 2019 20:33:39 +0000 (UTC)
From:      Kyle Evans <kevans@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r351796 - head/sys/kern
Message-ID:  <201909032033.x83KXdWv001094@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kevans
Date: Tue Sep  3 20:33:38 2019
New Revision: 351796
URL: https://svnweb.freebsd.org/changeset/base/351796

Log:
  posixshm: start counting writeable mappings
  
  r351650 switched posixshm to using OBJT_SWAP for shm_object
  
  r351795 added support to the swap_pager for tracking writeable mappings
  
  Take advantage of this and start tracking writeable mappings; fd sealing
  will use this to reject a seal on writing with EBUSY if any such mapping
  exist.
  
  Reviewed by:	kib, markj
  Differential Revision:	https://reviews.freebsd.org/D21456

Modified:
  head/sys/kern/uipc_shm.c

Modified: head/sys/kern/uipc_shm.c
==============================================================================
--- head/sys/kern/uipc_shm.c	Tue Sep  3 20:31:48 2019	(r351795)
+++ head/sys/kern/uipc_shm.c	Tue Sep  3 20:33:38 2019	(r351796)
@@ -895,6 +895,7 @@ shm_mmap(struct file *fp, vm_map_t map, vm_offset_t *a
 	struct shmfd *shmfd;
 	vm_prot_t maxprot;
 	int error;
+	bool writecnt;
 
 	shmfd = fp->f_data;
 	maxprot = VM_PROT_NONE;
@@ -905,10 +906,10 @@ shm_mmap(struct file *fp, vm_map_t map, vm_offset_t *a
 	if ((fp->f_flag & FWRITE) != 0)
 		maxprot |= VM_PROT_WRITE;
 
+	writecnt = (flags & MAP_SHARED) != 0 && (prot & VM_PROT_WRITE) != 0;
+
 	/* Don't permit shared writable mappings on read-only descriptors. */
-	if ((flags & MAP_SHARED) != 0 &&
-	    (maxprot & VM_PROT_WRITE) == 0 &&
-	    (prot & VM_PROT_WRITE) != 0)
+	if (writecnt && (maxprot & VM_PROT_WRITE) == 0)
 		return (EACCES);
 	maxprot &= cap_maxprot;
 
@@ -931,10 +932,16 @@ shm_mmap(struct file *fp, vm_map_t map, vm_offset_t *a
 	mtx_unlock(&shm_timestamp_lock);
 	vm_object_reference(shmfd->shm_object);
 
+	if (writecnt)
+		vm_pager_update_writecount(shmfd->shm_object, 0, objsize);
 	error = vm_mmap_object(map, addr, objsize, prot, maxprot, flags,
-	    shmfd->shm_object, foff, FALSE, td);
-	if (error != 0)
+	    shmfd->shm_object, foff, writecnt, td);
+	if (error != 0) {
+		if (writecnt)
+			vm_pager_release_writecount(shmfd->shm_object, 0,
+			    objsize);
 		vm_object_deallocate(shmfd->shm_object);
+	}
 	return (error);
 }
 



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