All of lore.kernel.org
 help / color / mirror / Atom feed
From: Robert Hancock <hancockr@shaw.ca>
To: Maitre Bart <maitrebart@excite.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: How to map user space's virtual memory into kernel logical address space
Date: Wed, 28 Nov 2007 18:33:55 -0600	[thread overview]
Message-ID: <474E08F3.6020508@shaw.ca> (raw)
In-Reply-To: <25b1e0c5-c6f4-43e6-a168-7cb701ef9018@e10g2000prf.googlegroups.com>

Maitre Bart wrote:
> A given app is allocating a large amount of memory (~10M) with
> malloc().
> It passes this pointer to the kernel (device driver) via an custom
> ioctl.
> I would like the driver to work on that memory with a pointer (as if
> it was allocated with vmalloc) as well as the user space too (upon
> return of the syscall).
> Is there a way to map a user space's virtual memory range into the
> kernel logical address space?
> 
> As far as I learned from my readings, using the user-space pointer
> directly in kernel space will not work.
> 
> Of course, copy_from_user() is out of question for efficiency
> purposes.
> 
> ioremap() is pretty close to what I wish to do except that it accepts
> a physical address and I don't how to get it from a user space
> pointer. And since a physical address is required, I assume the range
> is considered contiguous, which is not really the case for malloc().
> 
> mmap()/remap_pfn_range() are interesting but I don't know how to get a
> kernel pointer out of them.
> 
> kmap() does the job for a single page (and anyway, I wouldn't know how
> to  feed it with a struct page from the userland pointer).
> 
> get_user_pages() looks promising but it seems I have to call kmap() on
> each page, so it looks like I cannot operate on the buffer with a
> single pointer.
> 
> Does any one know if it is possible? And if so, how can I do it?

10MB is an awfully big mapping to put into kernel virtual memory space. 
I suspect it might be easier to allocate the memory in the kernel and 
map it in from userspace, but then you have the same problem (and 10MB 
is awfully big for vmalloc).

Is there a good reason why you have to be able to do this? There's 
likely a better way.

-- 
Robert Hancock      Saskatoon, SK, Canada
To email, remove "nospam" from hancockr@nospamshaw.ca
Home Page: http://www.roberthancock.com/


           reply	other threads:[~2007-11-29  0:34 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <25b1e0c5-c6f4-43e6-a168-7cb701ef9018@e10g2000prf.googlegroups.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=474E08F3.6020508@shaw.ca \
    --to=hancockr@shaw.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maitrebart@excite.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.