Index: kernel/arch/ppc32/src/mm/tlb.c
===================================================================
--- kernel/arch/ppc32/src/mm/tlb.c	(revision 53634f9294eaa723f35916cf5364f8cd4ab720f8)
+++ kernel/arch/ppc32/src/mm/tlb.c	(revision c19a4169aebe77641429454d4f9abf4c2152888a)
@@ -157,12 +157,22 @@
 	bool found = false;
 	
-	/* Find unused or colliding PTE in PTEG */
+	/* Find colliding PTE in PTEG */
 	for (i = 0; i < 8; i++) {
-		if ((!phte[base + i].v) ||
-		    ((phte[base + i].vsid == vsid)
+		if ((phte[base + i].v)
+		    && (phte[base + i].vsid == vsid)
 		    && (phte[base + i].api == api)
-		    && (phte[base + i].h == 0))) {
+		    && (phte[base + i].h == 0)) {
 			found = true;
 			break;
+		}
+	}
+	
+	if (!found) {
+		/* Find unused PTE in PTEG */
+		for (i = 0; i < 8; i++) {
+			if (!phte[base + i].v) {
+				found = true;
+				break;
+			}
 		}
 	}
@@ -172,14 +182,26 @@
 		uint32_t base2 = (~hash & 0x3ff) << 3;
 		
-		/* Find unused or colliding PTE in PTEG */
+		/* Find colliding PTE in PTEG */
 		for (i = 0; i < 8; i++) {
-			if ((!phte[base2 + i].v) ||
-			    ((phte[base2 + i].vsid == vsid)
+			if ((phte[base2 + i].v)
+			    && (phte[base2 + i].vsid == vsid)
 			    && (phte[base2 + i].api == api)
-			    && (phte[base2 + i].h == 1))) {
+			    && (phte[base2 + i].h == 1)) {
 				found = true;
 				base = base2;
 				h = 1;
 				break;
+			}
+		}
+		
+		if (!found) {
+			/* Find unused PTE in PTEG */
+			for (i = 0; i < 8; i++) {
+				if (!phte[base2 + i].v) {
+					found = true;
+					base = base2;
+					h = 1;
+					break;
+				}
 			}
 		}
@@ -309,12 +331,22 @@
 	bool found = false;
 	
-	/* Find unused or colliding PTE in PTEG */
+	/* Find colliding PTE in PTEG */
 	for (i = 0; i < 8; i++) {
-		if ((!phte_real[base + i].v) ||
-		    ((phte_real[base + i].vsid == vsid)
+		if ((phte_real[base + i].v)
+		    && (phte_real[base + i].vsid == vsid)
 		    && (phte_real[base + i].api == api)
-		    && (phte_real[base + i].h == 0))) {
+		    && (phte_real[base + i].h == 0)) {
 			found = true;
 			break;
+		}
+	}
+	
+	if (!found) {
+		/* Find unused PTE in PTEG */
+		for (i = 0; i < 8; i++) {
+			if (!phte_real[base + i].v) {
+				found = true;
+				break;
+			}
 		}
 	}
@@ -324,14 +356,26 @@
 		uint32_t base2 = (~hash & 0x3ff) << 3;
 		
-		/* Find unused or colliding PTE in PTEG */
+		/* Find colliding PTE in PTEG */
 		for (i = 0; i < 8; i++) {
-			if ((!phte_real[base2 + i].v) ||
-			    ((phte_real[base2 + i].vsid == vsid)
+			if ((phte_real[base2 + i].v)
+			    && (phte_real[base2 + i].vsid == vsid)
 			    && (phte_real[base2 + i].api == api)
-			    && (phte_real[base2 + i].h == 1))) {
+			    && (phte_real[base2 + i].h == 1)) {
 				found = true;
 				base = base2;
 				h = 1;
 				break;
+			}
+		}
+		
+		if (!found) {
+			/* Find unused PTE in PTEG */
+			for (i = 0; i < 8; i++) {
+				if (!phte_real[base2 + i].v) {
+					found = true;
+					base = base2;
+					h = 1;
+					break;
+				}
 			}
 		}
