Wed Apr 24 02:08:03 2024 UTC (39d)
vmem_init(): Ensure that the quantum is a power of 2, and that if private
tags are being used, they are added to the arena before the first span is
added.


(thorpej)
diff -r1.115 -r1.116 src/sys/kern/subr_vmem.c

cvs diff -r1.115 -r1.116 src/sys/kern/subr_vmem.c (expand / switch to context diff)
--- src/sys/kern/subr_vmem.c 2023/12/03 19:34:08 1.115
+++ src/sys/kern/subr_vmem.c 2024/04/24 02:08:03 1.116
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_vmem.c,v 1.115 2023/12/03 19:34:08 thorpej Exp $	*/
+/*	$NetBSD: subr_vmem.c,v 1.116 2024/04/24 02:08:03 thorpej Exp $	*/
 
 /*-
  * Copyright (c)2006,2007,2008,2009 YAMAMOTO Takashi,
@@ -46,7 +46,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.115 2023/12/03 19:34:08 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_vmem.c,v 1.116 2024/04/24 02:08:03 thorpej Exp $");
 
 #if defined(_KERNEL) && defined(_KERNEL_OPT)
 #include "opt_ddb.h"
@@ -971,6 +971,14 @@
 	KASSERT((flags & (VM_SLEEP|VM_NOSLEEP)) != 0);
 	KASSERT((~flags & (VM_SLEEP|VM_NOSLEEP)) != 0);
 	KASSERT(quantum > 0);
+	KASSERT(powerof2(quantum));
+
+	/*
+	 * If private tags are going to be used, they must
+	 * be added to the arena before the first span is
+	 * added.
+	 */
+	KASSERT((flags & VM_PRIVTAGS) == 0 || size == 0);
 
 #if defined(_KERNEL)
 	/* XXX: SMP, we get called early... */