Module Name:    src
Committed By:   matt
Date:           Fri May 27 17:17:17 UTC 2011

Modified Files:
        src/sys/uvm [matt-nb5-mips64]: uvm_pglist.c

Log Message:
Fix a bug where limit could be greater avail_end.  Now if that happens, we
just bail.  Use KDASSERTMSG so panics are more informative.


To generate a diff of this commit:
cvs rdiff -u -r1.42.16.7 -r1.42.16.8 src/sys/uvm/uvm_pglist.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/uvm/uvm_pglist.c
diff -u src/sys/uvm/uvm_pglist.c:1.42.16.7 src/sys/uvm/uvm_pglist.c:1.42.16.8
--- src/sys/uvm/uvm_pglist.c:1.42.16.7	Wed May 25 23:58:50 2011
+++ src/sys/uvm/uvm_pglist.c	Fri May 27 17:17:17 2011
@@ -170,6 +170,8 @@
 			second_pass = true;
 			try = roundup2(max(low, ps->avail_start), alignment);
 			limit = min(high, ps->avail_start + ps->start_hint);
+			if (limit >= ps->avail_end)
+				return 0;
 			skip = 0;
 			continue;
 		}
@@ -184,20 +186,28 @@
 			skip = 0;
 			continue;
 		}
-#ifdef DEBUG
+
 		/*
 		 * Make sure this is a managed physical page.
 		 */
+		KDASSERTMSG(vm_physseg_find(try, &cidx) == ps - vm_physmem,
+		    ("%s: %s(%#x, &cidx) (%d) != ps - vm_physmem (%zd)",
+		     __func__, "vm_physseg_find", try,
+		    vm_physseg_find(try, &cidx), ps - vm_physmem));
+
+		KDASSERTMSG(cidx == try - ps->start,
+		    ("%s: cidx (%#x) != try (%#x) - ps->start (%#"PRIxPADDR")",
+		     __func__, cidx, try, ps->start));
+
+		KDASSERTMSG(vm_physseg_find(try + num - 1, &cidx) == ps - vm_physmem,
+		    ("%s: %s(%#x + %#x - 1, &cidx) (%d) != ps - vm_physmem (%zd)",
+		     __func__, "vm_physseg_find", try, num,
+		    vm_physseg_find(try, &cidx), ps - vm_physmem));
+
+		KDASSERTMSG(cidx == try - ps->start + num - 1,
+		    ("%s: cidx (%#x) != try (%#x) - ps->start (%#"PRIxPADDR") + num (%#x) - 1",
+		     __func__, cidx, try, ps->start, num));
 
-		if (vm_physseg_find(try, &cidx) != ps - vm_physmem)
-			panic("pgalloc contig: botch1");
-		if (cidx != try - ps->start)
-			panic("pgalloc contig: botch2");
-		if (vm_physseg_find(try + num - 1, &cidx) != ps - vm_physmem)
-			panic("pgalloc contig: botch3");
-		if (cidx != try - ps->start + num - 1)
-			panic("pgalloc contig: botch4");
-#endif
 		tryidx = try - ps->start;
 		end = tryidx + num;
 
@@ -390,21 +400,31 @@
 	second_pass = false;
 
 	for (;; try++, pg++) {
+		KDASSERTMSG(limit <= ps->avail_end,
+		    ("%s: limit (%#x) > ps->avail_end (%#"PRIxPADDR")",
+		     __func__, limit, ps->avail_end));
+
 		if (try >= limit) {
 			if (ps->start_hint == 0 || second_pass)
 				break;
 			second_pass = true;
 			try = max(low, ps->avail_start) - 1;
 			limit = min(high, ps->avail_start + ps->start_hint);
+			if (limit >= ps->avail_end)
+				break;
 			pg = &ps->pgs[try - ps->start];
 			continue;
 		}
-#ifdef DEBUG
-		if (vm_physseg_find(try, &cidx) != ps - vm_physmem)
-			panic("pgalloc simple: botch1");
-		if (cidx != (try - ps->start))
-			panic("pgalloc simple: botch2");
-#endif
+
+		KDASSERTMSG(vm_physseg_find(try, &cidx) == ps - vm_physmem,
+		    ("%s: %s(%#x, &cidx) (%d) != ps - vm_physmem (%zd)",
+		     __func__, "vm_physseg_find", try,
+		    vm_physseg_find(try, &cidx), ps - vm_physmem));
+
+		KDASSERTMSG(cidx == try - ps->start,
+		    ("%s: cidx (%#x) != try (%#x) - ps->start (%#"PRIxPADDR")",
+		     __func__, cidx, try, ps->start));
+
 		/*
 		 * If this page isn't free, then we need to skip a colors worth
 		 * of pages to get a matching color.  Note that colormask is 1

Reply via email to