Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Sep 2006 16:44:26 -0400
From:      John Baldwin <jhb@freebsd.org>
To:        LI Xin <delphij@delphij.net>
Cc:        freebsd-arch@freebsd.org
Subject:   Re: How to map a page with userland program?
Message-ID:  <200609151644.27040.jhb@freebsd.org>
In-Reply-To: <450AE7FE.5000905@delphij.net>
References:  <450AB80B.1050100@delphij.net> <200609151251.16371.jhb@freebsd.org> <450AE7FE.5000905@delphij.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Friday 15 September 2006 13:50, LI Xin wrote:
> John Baldwin wrote:
> > On Friday 15 September 2006 11:21, LI Xin wrote:
> >> John Baldwin wrote:
> >>> On Friday 15 September 2006 10:26, LI Xin wrote:
> >>>> Dear folks,
> >>>>
> >>>> Is there a continent and MI way to map a kernel page into userland 
> >>>> address space under the same virtual address?  It seems that this can be 
> >>>> implemented through some routines in MD part of pmap, but is it possible 
> >>>> to use higher level VM routines to do the job?
> >>> Not to the same userland virtual address.  Why do you need the same
> >>> virtual address anyway?  If it's for pointers use offsets relative to
> >>> the start of the page instead.
> >> That would make it easier to implement some sort of VSYSCALL, which is 
> >> in fact executed in userland.  Or, is there any better way? :-)
> > 
> > If you want to stick code in the page, make the code PIC, the same as is done 
> > for shared libraries.  Alternatively, if you wanted to be very, very evil and 
> > can have the page read-only once it is initialized, flip the user/supervisor 
> > bit in the kernel PTE for that page such that it is treated as a user page 
> > rather than a kernel page (even though it's in KVA), and then userland 
> > processes can access that page via it's kernel VA.  Making the code PIC would 
> > probably be better though.
> 
> I see...  So, what if I want to make some data available to userland? 
> Is flipping the user/supervisor bit the only way?

Well, it's a quicker hack than the much more complicated way.  Otherwise,
you have to make sure everyone agrees on the same address.  Hmm, I suppose
actually you could just use a simple dummy device driver that creates a
/dev/foo and mmap it using MMAP_FIXED with your chosen userland virtual
address.  Then in your driver you just need to malloc a page and use
vtophys() to get a phys_addr to hand back in your d_mmap() routine.

-- 
John Baldwin



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200609151644.27040.jhb>