9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] vunmap() bug
@ 2011-06-24  1:04 erik quanstrom
  0 siblings, 0 replies; only message in thread
From: erik quanstrom @ 2011-06-24  1:04 UTC (permalink / raw)
  To: 9fans

today i spent a little while chasing a crash that happened after
a driver i'm working on gave up during initialization and decided
to free its vmaps.  it crashed in vunmap.  since this hardware does
some crazy things, it took a while to rule out the hardware.
after all, vunmap can't possibly be broken, right?

as it turns out, there was an off by one error in pdbunmap().
in the case that (va&(4*MB-1)) == 0 and a 4mb pde were used,
the code would stick on the same address and attempt to double-free
the same va.  the code was
	va = (va+4*MB-1) & ~(4*MB-1);
this lead to a panic, since the second time through the va was
not mapped.  the reason for this is that a round-up algorithm
was used, and this is off by one.  i changed the code slightly
to eliminate the rounding in the case of a 4mb mapping.
we're assurred that (va&(4*MB-1)) == 0 in this case. (cf. pdbmap())

- erik

----

static void
pdbunmap(ulong *pdb, ulong va, int size)
{
	ulong vae;
	ulong *table;

	vae = va+size;
	while(va < vae){
		table = &pdb[PDX(va)];
		if(!(*table & PTEVALID)){
			panic("vunmap: not mapped pde");
			/*
			va = (va+4*MB) & ~(4*MB-1);
			continue;
			*/
		}
		if(*table & PTESIZE){
			if(va & 4*MB-1)
				panic("vunmap: misaligned: %#p\n", va);
			*table = 0;
			va += 4*MB;
			continue;
		}
		table = KADDR(PPN(*table));
		if(!(table[PTX(va)] & PTEVALID))
			panic("vunmap: not mapped");
		table[PTX(va)] = 0;
		va += BY2PG;
	}
}



^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2011-06-24  1:04 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-24  1:04 [9fans] vunmap() bug erik quanstrom

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).