Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 Jan 2008 21:14:05 GMT
From:      Kip Macy <kmacy@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 133595 for review
Message-ID:  <200801182114.m0ILE5N8079792@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=133595

Change 133595 by kmacy@pandemonium:kmacy:xen31 on 2008/01/18 21:13:58

	Set the modified bit when mapping page tables - not doing so was causing us
	to lose the OS resrved bits which in turn confused process page accounting.
	
	Not quite diagnosed by alc, but prompted by him pressing me for why I wasn't 
	setting the modified bit when mapping page table pages. He has my gratitude
	for pushing me on the issue. 

Affected files ...

.. //depot/projects/xen31/sys/i386/xen/pmap.c#23 edit

Differences ...

==== //depot/projects/xen31/sys/i386/xen/pmap.c#23 (text+ko) ====

@@ -332,13 +332,13 @@
 	switch (type) {
 	case SH_PD_SET_VA:
 		xen_queue_pt_update(shadow_pdir_ma,
-				    xpmap_ptom(val & ~(PG_RW|PG_M)));
+				    xpmap_ptom(val & ~(PG_RW)));
 		xen_queue_pt_update(pdir_ma,
 				    xpmap_ptom(val)); 	
 		break;
 	case SH_PD_SET_VA_MA:
 		xen_queue_pt_update(shadow_pdir_ma,
-				    val & ~(PG_RW|PG_M));
+				    val & ~(PG_RW));
 		xen_queue_pt_update(pdir_ma, val); 	
 		break;
 	case SH_PD_SET_VA_CLEAR:
@@ -948,7 +948,7 @@
 		mtx_lock(&PMAP2mutex);
 		newpf = *pde & PG_FRAME;
 		if ((*PMAP2 & PG_FRAME) != newpf) {
-			*PMAP2 = newpf | PG_V | PG_A;
+			*PMAP2 = newpf | PG_V | PG_A | PG_M;
 			pmap_invalidate_page(kernel_pmap, (vm_offset_t)PADDR2);
 		}
 		return (PADDR2 + (i386_btop(va) & (NPTEPG - 1)));
@@ -1005,7 +1005,7 @@
 		KASSERT(curthread->td_pinned > 0, ("curthread not pinned"));
 		newpf = *pde & PG_FRAME;
 		if ((*PMAP1 & PG_FRAME) != newpf) {
-			*PMAP1 = newpf | PG_V | PG_A;
+			*PMAP1 = newpf | PG_V | PG_A | PG_M;
 #ifdef SMP
 			PMAP1cpu = PCPU_GET(cpuid);
 #endif
@@ -1457,7 +1457,7 @@
 		pmap->pm_pdir[PTDPTDI + i] =
 		    xpmap_ptom(VM_PAGE_TO_PHYS(ptdpg[i + NPGPTD])) | PG_V;
 	for (i = KPTDI; i < KPTDI + nkpt; i++)
-		pmap->pm_pdir_shadow[i] = PTD[i] & ~(PG_RW|PG_M|PG_A);
+		pmap->pm_pdir_shadow[i] = PTD[i] & ~(PG_RW);
 	for (i = 0; i < NPGPTD; i++) {
 		pt_entry_t *pd;
 
@@ -2161,8 +2161,16 @@
 	 * why, but I think the most likely explanation is that xen's writable
 	 * page table implementation doesn't respect the unused bits.
 	 */
-	if ((oldpte & PG_MANAGED) || ((oldpte & PG_V) && (va < VM_MAXUSER_ADDRESS))) {
+	if ((oldpte & PG_MANAGED)
+#ifdef PTEBROKEN
+	    || ((oldpte & PG_V) && (va < VM_MAXUSER_ADDRESS))
+#endif
+		) {
 		m = PHYS_TO_VM_PAGE(xpmap_mtop(oldpte) & PG_FRAME);
+
+		if (!(oldpte & PG_MANAGED))
+			printf("va=0x%x is unmanaged :-( pte=0x%llx\n", va, oldpte);
+
 		if (oldpte & PG_M) {
 			KASSERT((oldpte & PG_RW),
 	("pmap_remove_pte: modified page not writable: va: %#x, pte: %#jx",
@@ -2172,11 +2180,9 @@
 		if (oldpte & PG_A)
 			vm_page_flag_set(m, PG_REFERENCED);
 		pmap_remove_entry(pmap, m, va);
-	}
-#ifdef DEBUG
-	else if (va < VM_MAXUSER_ADDRESS) 
-		printf("va=0x%x is unmanaged :-( \n", va);
-#endif	
+	} else if ((va < VM_MAXUSER_ADDRESS) && (oldpte & PG_V))
+		printf("va=0x%x is unmanaged :-( pte=0x%llx\n", va, oldpte);
+
 	return (pmap_unuse_pt(pmap, va, free));
 }
 
@@ -2932,7 +2938,7 @@
 		npdes = size >> PDRSHIFT;
 		for(i = 0; i < npdes; i++) {
 			PD_SET_VA(pmap, ptepindex,
-			    ptepa | PG_U | PG_RW | PG_V | PG_PS, FALSE);
+			    ptepa | PG_U | PG_M | PG_RW | PG_V | PG_PS, FALSE);
 			ptepa += NBPDR;
 			ptepindex += 1;
 		}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200801182114.m0ILE5N8079792>