svn commit: r343017 - head/sys/kern

Konstantin Belousov kib at FreeBSD.org
Mon Jan 14 07:31:20 UTC 2019


Author: kib
Date: Mon Jan 14 07:31:19 2019
New Revision: 343017
URL: https://svnweb.freebsd.org/changeset/base/343017

Log:
  Handle overflow in calculating max kmem size.
  
  vm_kmem_size is u_long, and it might be not capable of holding page
  count times PAGE_SIZE, even when scaled down by VM_KMEM_SIZE_SCALE.  As
  bde reported, 12G PAE config ends up with zero for kmem size.
  
  Explicitly check for overflow and clamp kmem size at vm_kmem_size_max.
  If we end up at zero size because VM_KMEM_SIZE_MAX is not defined,
  panic with clear explanation rather then failing in a way which is
  hard to relate.
  
  Reported by:	bde, pho
  Tested by:	pho
  Reviewed by:	markj
  Sponsored by:	The FreeBSD Foundation
  MFC after:	1 week
  Differential revision:	https://reviews.freebsd.org/D18767

Modified:
  head/sys/kern/kern_malloc.c

Modified: head/sys/kern/kern_malloc.c
==============================================================================
--- head/sys/kern/kern_malloc.c	Mon Jan 14 07:25:44 2019	(r343016)
+++ head/sys/kern/kern_malloc.c	Mon Jan 14 07:31:19 2019	(r343017)
@@ -920,13 +920,16 @@ kmeminit(void)
 	 * variable:
 	 */
 	if (vm_kmem_size == 0) {
-		vm_kmem_size = (mem_size / vm_kmem_size_scale) * PAGE_SIZE;
-
+		vm_kmem_size = mem_size / vm_kmem_size_scale;
+		vm_kmem_size = vm_kmem_size * PAGE_SIZE < vm_kmem_size ?
+		    vm_kmem_size_max : vm_kmem_size * PAGE_SIZE;
 		if (vm_kmem_size_min > 0 && vm_kmem_size < vm_kmem_size_min)
 			vm_kmem_size = vm_kmem_size_min;
 		if (vm_kmem_size_max > 0 && vm_kmem_size >= vm_kmem_size_max)
 			vm_kmem_size = vm_kmem_size_max;
 	}
+	if (vm_kmem_size == 0)
+		panic("Tune VM_KMEM_SIZE_* for the platform");
 
 	/*
 	 * The amount of KVA space that is preallocated to the


More information about the svn-src-all mailing list