Subject: uvm_km_alloc/free from interrupt in netbsd-3
To: None <tech-kern@netbsd.org>
From: Manuel Bouyer <bouyer@antioche.eu.org>
List: tech-kern
Date: 07/28/2006 13:03:59
Hi,
I'm trying to backport the twa driver to netbsd-3, and I'm running in
issues with uvm_km_alloc/free.
First, is it safe to use uvm_km_alloc()/free() on kmem_map from interrupt
context in -current (I guess so because we have a UVM_KMF_NOWAIT flag) ?
Is it safe in netbsd-3, where we can't pass UVM_KMF_NOWAIT to uvm_km_alloc() ?

Here is the code in current:
			s = splvm();
			tr->tr_data = (void *)uvm_km_alloc(kmem_map, 
			    tr->tr_length, 512, UVM_KMF_NOWAIT|UVM_KMF_WIRED);
			splx(s);

I translated this in netbsd-3 to:
			tr->tr_copy_length = tr->tr_length + 511UL;
			s = splvm();
			tr->tr_copy_data = (void *)uvm_km_alloc(kmem_map,
			    tr->tr_copy_length);
			splx(s);
			tr->tr_data = (void *)
				(((u_long)tr->tr_copy_data + 511UL) & ~511UL);

but with this I get random panics apparently due to data corruption after
doing some I/O to the twa. I suspect this is because of this alloc/free
for unaligned requests, because I got panic only when working on the raw
device (e.g. newfs, disklabel, etc ...). Once I get past this I can work
on the mounted filesystem without troubles, but I think requests from
a mounted filesystem are always aligned on 512 bytes.

-- 
Manuel Bouyer, LIP6, Universite Paris VI.           Manuel.Bouyer@lip6.fr
     NetBSD: 26 ans d'experience feront toujours la difference
--