⬢ DragonFlyBSD Kernel Audit
DF-5244 / instrument.diff
← back to finding ↓ download raw
--- a/sys/platform/pc64/x86_64/pmap.c
+++ b/sys/platform/pc64/x86_64/pmap.c
@@ -5628,6 +5628,17 @@
 			atomic_add_long(&pt_pv->pv_pmap->pm_stats.wired_count,
 					-1);
 			atomic_clear_long(ptep, pmap->pmap_bits[PG_W_IDX]);
+			/*
+			 * DF-5244 RACE INSTRUMENTATION (temporary, not a fix):
+			 * widen the window between the PG_W clear and the
+			 * frame re-read so a concurrent backing-scan cmpset
+			 * (pmap_remove_all from ftruncate) can land inside it.
+			 */
+			{
+				uint64_t tsc0 = rdtsc();
+				while (rdtsc() - tsc0 < 30000)
+					cpu_ccfence();
+			}
 
 			pa = *ptep & PG_FRAME;
 			m = PHYS_TO_VM_PAGE(pa);