Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 Oct 2017 14:22:56 +0000 (UTC)
From:      Mark Johnston <markj@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: r325036 - stable/11/sys/vm
Message-ID:  <201710271422.v9REMuTF093617@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: markj
Date: Fri Oct 27 14:22:56 2017
New Revision: 325036
URL: https://svnweb.freebsd.org/changeset/base/325036

Log:
  MFC r324809:
  Free the right address range if kmem_back() fails in memguard_alloc().

Modified:
  stable/11/sys/vm/memguard.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/sys/vm/memguard.c
==============================================================================
--- stable/11/sys/vm/memguard.c	Fri Oct 27 12:37:22 2017	(r325035)
+++ stable/11/sys/vm/memguard.c	Fri Oct 27 14:22:56 2017	(r325036)
@@ -283,7 +283,7 @@ v2sizev(vm_offset_t va)
 void *
 memguard_alloc(unsigned long req_size, int flags)
 {
-	vm_offset_t addr;
+	vm_offset_t addr, origaddr;
 	u_long size_p, size_v;
 	int do_guard, rv;
 
@@ -327,7 +327,7 @@ memguard_alloc(unsigned long req_size, int flags)
 	for (;;) {
 		if (vmem_xalloc(memguard_arena, size_v, 0, 0, 0,
 		    memguard_cursor, VMEM_ADDR_MAX,
-		    M_BESTFIT | M_NOWAIT, &addr) == 0)
+		    M_BESTFIT | M_NOWAIT, &origaddr) == 0)
 			break;
 		/*
 		 * The map has no space.  This may be due to
@@ -342,11 +342,12 @@ memguard_alloc(unsigned long req_size, int flags)
 		memguard_wrap++;
 		memguard_cursor = memguard_base;
 	}
+	addr = origaddr;
 	if (do_guard)
 		addr += PAGE_SIZE;
 	rv = kmem_back(kmem_object, addr, size_p, flags);
 	if (rv != KERN_SUCCESS) {
-		vmem_xfree(memguard_arena, addr, size_v);
+		vmem_xfree(memguard_arena, origaddr, size_v);
 		memguard_fail_pgs++;
 		addr = (vm_offset_t)NULL;
 		goto out;



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