Piotr Jaroszyński: Usermode debugging under Linux

Week 7 [ Jul 5 - Jul 11 2010 ]

drivers in userspace

After a lot of reading and trial and error I have managed to come up with a working, but awfully hacky proof of concept:

# ./pcnet32.linuxlibc 
gPXE initialising devices...



gPXE 1.0.1+ -- Open Source Boot Firmware -- http://etherboot.org
Features: HTTP DNS TFTP
DHCP (net0 52:54:00:12:34:58).... ok
http://root.piotrj.org/files/gpxe/1mb. ok

PIO

To make the pci_(read|write)_config_*() work I picked PCIAPI_DIRECT in config/ioapi.h and made all I/O ports available to userspace with iopl(3). That also had a side-effect of making rest of the PIO used by drivers work. The question remains how portable PCIAPI_DIRECT is. Answering that requries more reading. Other approaches are possible here as the PCI config interface is exposed in /sys/ and there is even a lib in pciutils for accessing it.

MMIO

Haven't looked at that yet. A kernel module might be required to mark the pages mmaped to hardware as non-cacheable and non-prefetchable.

DMA

And to make DMA work core/malloc.c uses a mmaped arbitrary (I just tried several ranges until it worked) chunk of /dev/mem. This is ridiculously bad as it can end up corrupting kernel structures, but that's what kvm is for :)

Obviously this has to be changed. Stefan suggested that it might be possible to mlock() the heap (so that it's not swapped away) from core/malloc.c and figure out its physical address via /proc/pagemap. That doesn't guarantee for it to be physically contiguous, but at least we can verify that.

Doing it properly seems to require a kernel module. MMIO might too and I was supposed to look at UIO anyway, so that's on the radar now.


QR Code
QR Code soc:2010:peper:journal:week7 (generated for current page)