Bug 161721

Summary: [boot] compiling kernel with KVA_PAGES=512 does not allow system to boot
Product: Base System Reporter: kes-kes
Component: kernAssignee: Alan Cox <alc>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: 1.0-CURRENT   
Hardware: Any   
OS: Any   

Description kes-kes 2011-10-16 19:20:07 UTC
adding option to KERNCONF

options KVA_PAGES=512

does not allow system to boot.


FreeBSD must tune sysctl variables itself. at least to that values that
allow system to boot and WARN user for that tuning!

In other words: changing KVA_PAGES must affect vm.kmem_size and vm.kmem_size_max

Fix: 

You must make additional tuning in /boot/loader.conf:

vm.kmem_size="330M"
vm.kmem_size_max="330M"
vfs.zfs.arc_max="40M"
vfs.zfs.vdev.cache.size="5M"
Comment 1 Mark Linimon freebsd_committer freebsd_triage 2011-10-17 00:01:31 UTC
Responsible Changed
From-To: freebsd-i386->freebsd-bugs

This does not sound i386-specific.
Comment 2 Remko Lodder freebsd_committer freebsd_triage 2011-10-18 19:27:15 UTC
State Changed
From-To: open->closed

If you fiddle with kernel settings you should be aware of what you are 
doing. The KVA pages is a problem that popped up before and is mentioned 
enough. I do not think this is a PR worth, apologies if this offends 
you.
Comment 3 Remko Lodder freebsd_committer freebsd_triage 2011-10-20 20:22:24 UTC
State Changed
From-To: closed->open

Per request of Alan, reopen the ticket and assign it to him. 
Thanks for taking care of this Alan! 


Comment 4 Remko Lodder freebsd_committer freebsd_triage 2011-10-20 20:22:24 UTC
Responsible Changed
From-To: freebsd-bugs->alc

Per request of Alan, reopen the ticket and assign it to him. 
Thanks for taking care of this Alan!
Comment 5 Mark Linimon 2011-10-22 07:57:49 UTC
----- Forwarded message from Alan Cox <alc@rice.edu> -----

Date: Thu, 20 Oct 2011 12:28:14 -0500
From: Alan Cox <alc@rice.edu>
To: Remko Lodder <remko@elvandar.org>
Cc: alc@FreeBSD.org, ÐонÑков Ðвгений <kes-kes@yandex.ru>,
	freebsd-bugs@FreeBSD.org
Subject: Re: kern/161721: [boot] compiling kernel with KVA_PAGES=512 does
	not allow system to boot

Kes,

Your problem report doesn't include any details on the panic that
occurs.  Could you please provide this?

Is this problem occurring with or without the use of PAE?  If I
presume that you are not using PAE, then setting KVA_PAGES to 512
makes the kernel address space 2 GB in size.

Have you ever tried a slightly smaller setting for KVA_PAGES, for
example, 508?

Remko,

I suspect this a bug, specifically, arithmetic overflow is occurring
somewhere because 32-bit arithmetic is being used and the kernel
address space is 2^31 bytes in size.

I would recommend that you reopen this PR, and assign it to me.  While
you can certainly shoot yourself in the foot by messing with low-level
configuration, like KVA_PAGES, in this case, I think we may have a
bug.

Alan

----- End forwarded message -----
Comment 6 Mark Linimon 2011-10-22 07:58:15 UTC
----- Forwarded message from remko@FreeBSD.org -----

Date: Thu, 20 Oct 2011 19:23:03 GMT
From: remko@FreeBSD.org
To: kes-kes@yandex.ru, remko@FreeBSD.org, freebsd-bugs@FreeBSD.org,
	alc@FreeBSD.org
Subject: Re: kern/161721: [boot] compiling kernel with KVA_PAGES=512 does
	not allow system to boot

Synopsis: [boot] compiling kernel with KVA_PAGES=512 does not allow system to boot

State-Changed-From-To: closed->open
State-Changed-By: remko
State-Changed-When: Thu Oct 20 19:22:24 UTC 2011
State-Changed-Why: 
Per request of Alan, reopen the ticket and assign it to him.
Thanks for taking care of this Alan!

----- End forwarded message -----
Comment 7 Mark Linimon 2011-10-22 08:00:00 UTC
----- Forwarded message from ÐонÑков Ðвгений <kes-kes@yandex.ru> -----

Date: Thu, 20 Oct 2011 22:25:59 +0300
From: ÐонÑков Ðвгений <kes-kes@yandex.ru>
To: Alan Cox <alc@rice.edu>
Cc: alc@FreeBSD.org, freebsd-bugs@FreeBSD.org,
	Remko Lodder <remko@elvandar.org>
Subject: Re[2]: kern/161721: [boot] compiling kernel with KVA_PAGES=512 does
	not allow system to boot

   I get system halted on this stage:

   Oct 10 13:52:22 syslogd: kernel boot file is /boot/kernel/kernel
   Oct 10 13:52:22 kernel: Copyright (c) 1992-2011 The FreeBSD Project.
   Oct 10 13:52:22 kernel: Copyright (c) 1979, 1980, 1983, 1986, 1988, 1989, 1991, 1992, 1993, 1994
   Oct 10 13:52:22 kernel: The Regents of the University of California.  All rights reserved.
   Oct 10 13:52:22 kernel: FreeBSD is a registered trademark of The FreeBSD Foundation.
   Oct 10 13:52:22 kernel: FreeBSD 9.0-BETA2 #11: Thu Oct 6 18:02:28 EEST 2011
   Oct 10 13:52:22 kernel: @:/usr/obj/usr/src/sys/KES_KERN_v9 i386

   But as I discover later it was a bug (problem) with KVA_PAGES, I have
   added that option to GENERIC

   and in new installed slice I have no /boot/loader.conf file, so system
   is halt.

   on old slice I have /boot/loader.conf, so I have no problem with
   KVA_PAGES option.

   I know, that FreeBSD automatically reboot if something nasty is
   happen.

   but in this case even no coredumps are present.

   > Is this problem occurring with or without the use of PAE?  If I
   > presume that you are not using PAE, then setting KVA_PAGES to 512
   > makes the kernel address space 2 GB in size.

   > Have you ever tried a slightly smaller setting for KVA_PAGES, for
   > example, 508?

   Ok, I will try 508 and report results.

   --

   S uvazheniem,

    Kon'kov                          [7]mailto:kes-kes@yandex.ru

References

   1. http://www.freebsd.org/cgi/query-pr.cgi?pr=161458
   2. http://www.freebsd.org/cgi/query-pr.cgi?pr=161721
   3. mailto:kes-kes@yandex.ru
   4. mailto:remko@elvandar.org
   5. mailto:remko@FreeBSD.org
   6. http://www.evilcoder.org/
   7. mailto:kes-kes@yandex.ru
_______________________________________________
freebsd-bugs@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "freebsd-bugs-unsubscribe@freebsd.org"


----- End forwarded message -----
Comment 8 kes-kes 2011-12-05 00:30:53 UTC
with KVA_PAGES = 508 it is booted OK
Comment 9 dfilter service freebsd_committer freebsd_triage 2011-12-10 18:42:14 UTC
Author: alc
Date: Sat Dec 10 18:42:00 2011
New Revision: 228398
URL: http://svn.freebsd.org/changeset/base/228398

Log:
  Avoid the possibility of integer overflow in the calculation of
  VM_KMEM_SIZE_MAX.  Specifically, if the user/kernel address space split
  was changed such that the kernel address space was greater than or equal
  to 2 GB, then overflow would occur.
  
  PR:		161721
  MFC after:	3 weeks

Modified:
  head/sys/i386/include/vmparam.h

Modified: head/sys/i386/include/vmparam.h
==============================================================================
--- head/sys/i386/include/vmparam.h	Sat Dec 10 18:35:26 2011	(r228397)
+++ head/sys/i386/include/vmparam.h	Sat Dec 10 18:42:00 2011	(r228398)
@@ -186,11 +186,12 @@
 #endif
 
 /*
- * Ceiling on amount of kmem_map kva space.
+ * Ceiling on the amount of kmem_map KVA space: 40% of the entire KVA space
+ * rounded to the nearest multiple of the superpage size.
  */
 #ifndef VM_KMEM_SIZE_MAX
-#define	VM_KMEM_SIZE_MAX	((VM_MAX_KERNEL_ADDRESS - \
-    VM_MIN_KERNEL_ADDRESS) * 2 / 5)
+#define	VM_KMEM_SIZE_MAX	(((((VM_MAX_KERNEL_ADDRESS - \
+    VM_MIN_KERNEL_ADDRESS) >> (PDRSHIFT - 2)) + 5) / 10) << PDRSHIFT)
 #endif
 
 /* initial pagein size of beginning of executable file */
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 10 Alan Cox freebsd_committer freebsd_triage 2011-12-10 18:44:45 UTC
State Changed
From-To: open->patched

A fix has been applied to HEAD.
Comment 11 dfilter service freebsd_committer freebsd_triage 2012-01-21 08:26:56 UTC
Author: alc
Date: Sat Jan 21 08:26:41 2012
New Revision: 230421
URL: http://svn.freebsd.org/changeset/base/230421

Log:
  MFC r228398
    Avoid the possibility of integer overflow in the calculation of
    VM_KMEM_SIZE_MAX.  Specifically, if the user/kernel address space split
    was changed such that the kernel address space was greater than or equal
    to 2 GB, then overflow would occur.
  
  PR:		161721

Modified:
  stable/9/sys/i386/include/vmparam.h
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/amd64/include/xen/   (props changed)
  stable/9/sys/boot/   (props changed)
  stable/9/sys/boot/i386/efi/   (props changed)
  stable/9/sys/boot/ia64/efi/   (props changed)
  stable/9/sys/boot/ia64/ski/   (props changed)
  stable/9/sys/boot/powerpc/boot1.chrp/   (props changed)
  stable/9/sys/boot/powerpc/ofw/   (props changed)
  stable/9/sys/cddl/contrib/opensolaris/   (props changed)
  stable/9/sys/conf/   (props changed)
  stable/9/sys/contrib/dev/acpica/   (props changed)
  stable/9/sys/contrib/octeon-sdk/   (props changed)
  stable/9/sys/contrib/pf/   (props changed)
  stable/9/sys/contrib/x86emu/   (props changed)

Modified: stable/9/sys/i386/include/vmparam.h
==============================================================================
--- stable/9/sys/i386/include/vmparam.h	Sat Jan 21 07:57:27 2012	(r230420)
+++ stable/9/sys/i386/include/vmparam.h	Sat Jan 21 08:26:41 2012	(r230421)
@@ -186,11 +186,12 @@
 #endif
 
 /*
- * Ceiling on amount of kmem_map kva space.
+ * Ceiling on the amount of kmem_map KVA space: 40% of the entire KVA space
+ * rounded to the nearest multiple of the superpage size.
  */
 #ifndef VM_KMEM_SIZE_MAX
-#define	VM_KMEM_SIZE_MAX	((VM_MAX_KERNEL_ADDRESS - \
-    VM_MIN_KERNEL_ADDRESS) * 2 / 5)
+#define	VM_KMEM_SIZE_MAX	(((((VM_MAX_KERNEL_ADDRESS - \
+    VM_MIN_KERNEL_ADDRESS) >> (PDRSHIFT - 2)) + 5) / 10) << PDRSHIFT)
 #endif
 
 /* initial pagein size of beginning of executable file */
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
Comment 12 Alan Cox freebsd_committer freebsd_triage 2012-01-21 08:27:39 UTC
State Changed
From-To: patched->closed

All affected branches have been fixed.