Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Sep 2018 20:29:41 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r338511 - head/lib/libvmmapi
Message-ID:  <201809062029.w86KTfxJ001410@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Thu Sep  6 20:29:40 2018
New Revision: 338511
URL: https://svnweb.freebsd.org/changeset/base/338511

Log:
  bhyve: Use MAP_GUARD when mapping guest memory ranges.
  
  Instead of relying on PROT_NONE mappings with MAP_ANON, use MAP_GUARD
  to reserve address space around guest memory ranges including the
  guard ranges of address space around mappings.
  
  Submitted by:	Shawn Webb
  Reviewed by:	araujo
  Approved by:	re (rgrimes)
  MFC after:	1 month
  Sponsored by:	HardendBSD and G2, Inc
  Differential Revision:	https://reviews.freebsd.org/D16822

Modified:
  head/lib/libvmmapi/vmmapi.c

Modified: head/lib/libvmmapi/vmmapi.c
==============================================================================
--- head/lib/libvmmapi/vmmapi.c	Thu Sep  6 20:02:19 2018	(r338510)
+++ head/lib/libvmmapi/vmmapi.c	Thu Sep  6 20:29:40 2018	(r338511)
@@ -362,7 +362,7 @@ vm_setup_memory(struct vmctx *ctx, size_t memsize, enu
 	size_t objsize, len;
 	vm_paddr_t gpa;
 	char *baseaddr, *ptr;
-	int error, flags;
+	int error;
 
 	assert(vms == VM_MMAP_ALL);
 
@@ -389,8 +389,7 @@ vm_setup_memory(struct vmctx *ctx, size_t memsize, enu
 	 * and the adjoining guard regions.
 	 */
 	len = VM_MMAP_GUARD_SIZE + objsize + VM_MMAP_GUARD_SIZE;
-	flags = MAP_PRIVATE | MAP_ANON | MAP_NOCORE | MAP_ALIGNED_SUPER;
-	ptr = mmap(NULL, len, PROT_NONE, flags, -1, 0);
+	ptr = mmap(NULL, len, PROT_NONE, MAP_GUARD | MAP_ALIGNED_SUPER, -1, 0);
 	if (ptr == MAP_FAILED)
 		return (-1);
 
@@ -492,8 +491,8 @@ vm_create_devmem(struct vmctx *ctx, int segid, const c
 	 * adjoining guard regions.
 	 */
 	len2 = VM_MMAP_GUARD_SIZE + len + VM_MMAP_GUARD_SIZE;
-	flags = MAP_PRIVATE | MAP_ANON | MAP_NOCORE | MAP_ALIGNED_SUPER;
-	base = mmap(NULL, len2, PROT_NONE, flags, -1, 0);
+	base = mmap(NULL, len2, PROT_NONE, MAP_GUARD | MAP_ALIGNED_SUPER, -1,
+	    0);
 	if (base == MAP_FAILED)
 		goto done;
 



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