Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 18 Nov 2018 00:11:19 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org
Subject:   svn commit: r340534 - stable/11/lib/libvmmapi
Message-ID:  <201811180011.wAI0BJTk079020@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Sun Nov 18 00:11:19 2018
New Revision: 340534
URL: https://svnweb.freebsd.org/changeset/base/340534

Log:
  MFC 338511: 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.

Modified:
  stable/11/lib/libvmmapi/vmmapi.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/lib/libvmmapi/vmmapi.c
==============================================================================
--- stable/11/lib/libvmmapi/vmmapi.c	Sun Nov 18 00:09:33 2018	(r340533)
+++ stable/11/lib/libvmmapi/vmmapi.c	Sun Nov 18 00:11:19 2018	(r340534)
@@ -360,7 +360,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);
 
@@ -387,8 +387,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);
 
@@ -490,8 +489,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?201811180011.wAI0BJTk079020>