tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Implement mmap for PUD

On Sat, 10 Sep 2011, Masao Uebayashi wrote:

> On Sat, Sep 10, 2011 at 7:24 PM, Roger Pau Monné
> <> wrote:

> > PUD is a framework present in NetBSD that allows to implement
> > character and block devices in userspace. I'm trying to implement a
> > blktap [1] driver purely in userspace, and the mmap operation is
> > needed (and it would also be beneficial for PUD to have the full set
> > of operations implemented, for future uses). The implementation of
> > blktap driver using fuse was discused in the port-xen mailing list,
> > but the blktap driver needs a set of specific operations over
> > character and block devices.
> >
> > My main concern is if it is possible to pass memory form a userspace
> > program to another trough the kernel (that is mainly what my mmap
> > implementation tries to accomplish). I trough that I could accomplish
> It is called pipe(2), isn't it?

Did you forget a smiley there?  No it isn't, that's page loaning.

I don't think the device mmap() infrastructure will work for you.  As I 
said before, it's designed to hand out unmanaged device physical memory 
and you're working with managed memory.  While you may be able to cobble 
together something that appears functional, it will probably not properly 
manage VM reference counts and eventually go belly up.  Keep in mind the 
way device mmap is not done during the mmap() call.  Instead nothing 
happens until there's a page fault, which is when the driver's mmap() 
routine is called to do the v->p mapping and insert it into the pmap().

I think you may need to create a new uvm object to hold the pages you want 
to share and attach it to the vmspaces of both the server process handing 
out the pages and the ... err ... client(?) process trying to do the mmap.
fork() does this as well as mmap() of a file and sysv_shm.  I think the 
set of operations in sysv_shm is the best bet since it's the closest to 
what you want to do.  

You will probably need to find some way to intercept the mmap() syscall 
and have it do something unique for the PUD device, maybe by fiddling with 
vnode OP vectors.  I don't know, but I don't think this will be 


Home | Main Index | Thread Index | Old Index