linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* RE: Silly question: How to map a user space page in kernel space?
@ 2003-02-26  4:44 ` Perez-Gonzalez, Inaky
  2003-02-26  5:55   ` Martin J. Bligh
  2003-02-26 12:40   ` Mel Gorman
  0 siblings, 2 replies; 14+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-02-26  4:44 UTC (permalink / raw)
  To: 'Martin J. Bligh', 'linux-mm@kvack.org'

> From: Martin J. Bligh [mailto:mbligh@aracnet.com]
> 
> >> > I have a user space page (I know the 'struct page *' and I did a
> >> > get_page() on it so it doesn't go away to swap) and I need to be able
> >> > to access it with normal pointers (to do a bunch of atomic operations
> >> > on it). I cannot use get_user() and friends, just pointers.
> >> >
> >> > So, the question is, how can I map it into the kernel space in a
> >> > portable manner? Am I missing anything very basic here?
> >>
> >> kmap or kmap_atomic
> >
> > I am trying to use kmap_atomic(), but what is the meaning of the second
> > argument, km_type? I cannot find it anywhere, or at least the difference
> > between KM_USER0 and KM_USER1, which I am guessing are the ones I need.
> 
> Each type is for a different usage, and you need to ensure that two things
> can't reuse the same type at once. As long as interrupts, or whatever
> could
> disturb you can't use what you use, you're OK. Note that you can't hold
> kmap_atomic over a schedule (presumably this means no pre-emption either).

Hmmm, ok, my scenario is this:

System call entry point (these are futex modifications),
kernel/futex.c:futex_wake() and kernel/futex.c:futex_wait(). Both of them
will require to kmap_atomic a page. When they are talking about the same
futex (say three guys come in at the same time, one to unlock, two to lock),
the three of them might end up doing kmap_atomic() over the same page. 

So, are you telling me that for that to work, I have to either:

- each caller uses a different KM_USER<WHATEVER> [kind of clumsy]

- I shall protect the kmap_atomic() region with an spinlock, to serialize
it? [note I have the spinlock already, so it'd be a matter of spinlocking
_before_ kmap_atomic() instead of after - ugly for a quick consistency
check, but can live with it].

I think I still don't really understand what's up with the KM_ flags :]

Thanks,

Inaky Perez-Gonzalez -- Not speaking for Intel -- all opinions are my own
(and my fault)



--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: Silly question: How to map a user space page in kernel space?
  2003-02-26  4:44 ` Silly question: How to map a user space page in kernel space? Perez-Gonzalez, Inaky
@ 2003-02-26  5:55   ` Martin J. Bligh
  2003-02-26  8:33     ` Andrew Morton
  2003-02-26 12:40   ` Mel Gorman
  1 sibling, 1 reply; 14+ messages in thread
From: Martin J. Bligh @ 2003-02-26  5:55 UTC (permalink / raw)
  To: Perez-Gonzalez, Inaky, 'linux-mm@kvack.org'

> Hmmm, ok, my scenario is this:
> 
> System call entry point (these are futex modifications),
> kernel/futex.c:futex_wake() and kernel/futex.c:futex_wait(). Both of them
> will require to kmap_atomic a page. When they are talking about the same
> futex (say three guys come in at the same time, one to unlock, two to
> lock), the three of them might end up doing kmap_atomic() over the same
> page. 
> 
> So, are you telling me that for that to work, I have to either:
> 
> - each caller uses a different KM_USER<WHATEVER> [kind of clumsy]
> 
> - I shall protect the kmap_atomic() region with an spinlock, to serialize
> it? [note I have the spinlock already, so it'd be a matter of spinlocking
> _before_ kmap_atomic() instead of after - ugly for a quick consistency
> check, but can live with it].
> 
> I think I still don't really understand what's up with the KM_ flags :]

Well, there's one kmap_atomic slot per type per cpu. So you should be fine
without spinlocks as long as you can't get pushed off the cpu by anything
you do (eg schedule) ... it's really intended for very short use, like: 

kmap
copy thing
kunmap

But be aware that pagefaulting inside kmap_atomic is bad - you can get
blocked and rescheduled, so touching user pages, etc is dangerous. Either
you do some really funky error handling to pick up the pieces if it goes
wrong, or just use regular kmap - you can always convert over later.

M.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Silly question: How to map a user space page in kernel space?
  2003-02-26  5:55   ` Martin J. Bligh
@ 2003-02-26  8:33     ` Andrew Morton
  2003-02-26 19:03       ` Martin J. Bligh
  0 siblings, 1 reply; 14+ messages in thread
From: Andrew Morton @ 2003-02-26  8:33 UTC (permalink / raw)
  To: Martin J. Bligh; +Cc: inaky.perez-gonzalez, linux-mm

"Martin J. Bligh" <mbligh@aracnet.com> wrote:
>
> But be aware that pagefaulting inside kmap_atomic is bad - you can get
> blocked and rescheduled, so touching user pages, etc is dangerous.

That's true in 2.4.  In 2.5 a copy_foo_user() inside kmap_atomic()
will just return a short copy while remaining atomic.

See mm/filemap.c:filemap_copy_from_user()
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: Silly question: How to map a user space page in kernel space?
  2003-02-26  4:44 ` Silly question: How to map a user space page in kernel space? Perez-Gonzalez, Inaky
  2003-02-26  5:55   ` Martin J. Bligh
@ 2003-02-26 12:40   ` Mel Gorman
  1 sibling, 0 replies; 14+ messages in thread
From: Mel Gorman @ 2003-02-26 12:40 UTC (permalink / raw)
  To: Perez-Gonzalez, Inaky
  Cc: 'Martin J. Bligh', 'linux-mm@kvack.org'

On Tue, 25 Feb 2003, Perez-Gonzalez, Inaky wrote:

> I think I still don't really understand what's up with the KM_ flags :]
>

I'm doing a bit of VM documentation work. I haven't released an update in
a while but I have a chapter on high memory management chapter in my
working version. It covers the various kmap functions, atomic mapping and
an explanation of KM_ flags. I uploaded just that chapter to
http://www.csn.ul.ie/~mel/projects/vm/tmp/ in both PDF (recommended one to
view) and plain text format if you want to take a look. It's against
2.4.20, but I believe it is of relevance to 2.5.x as well

Hope that helps

-- 
Mel Gorman
MSc Student, University of Limerick
http://www.csn.ul.ie/~mel

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Silly question: How to map a user space page in kernel space?
  2003-02-26  8:33     ` Andrew Morton
@ 2003-02-26 19:03       ` Martin J. Bligh
  0 siblings, 0 replies; 14+ messages in thread
From: Martin J. Bligh @ 2003-02-26 19:03 UTC (permalink / raw)
  To: Andrew Morton; +Cc: inaky.perez-gonzalez, linux-mm

>> But be aware that pagefaulting inside kmap_atomic is bad - you can get
>> blocked and rescheduled, so touching user pages, etc is dangerous.
> 
> That's true in 2.4.  In 2.5 a copy_foo_user() inside kmap_atomic()
> will just return a short copy while remaining atomic.
> 
> See mm/filemap.c:filemap_copy_from_user()

Cool - I didn't realise you fixed that up so generically - very nice.

M.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: Silly question: How to map a user space page in kernel space?
@ 2003-02-26 19:04 Perez-Gonzalez, Inaky
  0 siblings, 0 replies; 14+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-02-26 19:04 UTC (permalink / raw)
  To: 'Mel Gorman', Perez-Gonzalez, Inaky; +Cc: 'linux-mm@kvack.org'

> From: Mel Gorman [mailto:mel@csn.ul.ie]
> 
> > Sure it will; your doc was the first pointer I went too [btw,
> > congratulations and thank you, it is really helpful], but, yep, it
> > wasn't there. Checking out the new version right now.
> 
> As I said, this chapter is only in my current working version. I posted it
> up early because I felt it was relevant. The whole document will be
> released again when I finish the swapping chapter.

My mistake, sure you don't want to confuse anybody :]

Inaky Perez-Gonzalez -- Not speaking for Intel -- all opinions are my own
(and my fault)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: Silly question: How to map a user space page in kernel space?
  2003-02-26 18:57 Perez-Gonzalez, Inaky
@ 2003-02-26 19:01 ` Mel Gorman
  0 siblings, 0 replies; 14+ messages in thread
From: Mel Gorman @ 2003-02-26 19:01 UTC (permalink / raw)
  To: Perez-Gonzalez, Inaky; +Cc: 'linux-mm@kvack.org'

On Wed, 26 Feb 2003, Perez-Gonzalez, Inaky wrote:

>
> Sure it will; your doc was the first pointer I went too [btw,
> congratulations and thank you, it is really helpful], but, yep, it wasn't
> there. Checking out the new version right now.
>

As I said, this chapter is only in my current working version. I posted it
up early because I felt it was relevant. The whole document will be
released again when I finish the swapping chapter.

-- 
Mel Gorman
MSc Student, University of Limerick
http://www.csn.ul.ie/~mel

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: Silly question: How to map a user space page in kernel space?
@ 2003-02-26 18:57 Perez-Gonzalez, Inaky
  2003-02-26 19:01 ` Mel Gorman
  0 siblings, 1 reply; 14+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-02-26 18:57 UTC (permalink / raw)
  To: 'Mel Gorman'; +Cc: 'linux-mm@kvack.org'

> From: Mel Gorman [mailto:mel@csn.ul.ie]
>
> > I think I still don't really understand what's up with the KM_ flags :]
> >
> 
> I'm doing a bit of VM documentation work. I haven't released an update in
> a while but I have a chapter on high memory management chapter in my
> working version. It covers the various kmap functions, atomic mapping and
> an explanation of KM_ flags. I uploaded just that chapter to
> http://www.csn.ul.ie/~mel/projects/vm/tmp/ in both PDF (recommended one to
> view) and plain text format if you want to take a look. It's against
> 2.4.20, but I believe it is of relevance to 2.5.x as well
> 
> Hope that helps

Sure it will; your doc was the first pointer I went too [btw,
congratulations and thank you, it is really helpful], but, yep, it wasn't
there. Checking out the new version right now.

Inaky Perez-Gonzalez -- Not speaking for Intel -- all opinions are my own
(and my fault)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: Silly question: How to map a user space page in kernel space?
  2003-02-26  4:14   ` Martin J. Bligh
@ 2003-02-26  4:39     ` Robert Love
  0 siblings, 0 replies; 14+ messages in thread
From: Robert Love @ 2003-02-26  4:39 UTC (permalink / raw)
  To: Martin J. Bligh; +Cc: Perez-Gonzalez, Inaky, 'linux-mm@kvack.org'

On Tue, 2003-02-25 at 23:14, Martin J. Bligh wrote:

> Each type is for a different usage, and you need to ensure that two things
> can't reuse the same type at once. As long as interrupts, or whatever could
> disturb you can't use what you use, you're OK. Note that you can't hold
> kmap_atomic over a schedule (presumably this means no pre-emption either).

Indeed, kmap_atomic() disables kernel preemption :)

Which found at least one instance of actually calling schedule() over
kmap_atomic(), due to the atomicity debugging.

	Robert Love

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: Silly question: How to map a user space page in kernel space?
  2003-02-26  3:06 ` Perez-Gonzalez, Inaky
@ 2003-02-26  4:14   ` Martin J. Bligh
  2003-02-26  4:39     ` Robert Love
  0 siblings, 1 reply; 14+ messages in thread
From: Martin J. Bligh @ 2003-02-26  4:14 UTC (permalink / raw)
  To: Perez-Gonzalez, Inaky, 'linux-mm@kvack.org'

>> > I have a user space page (I know the 'struct page *' and I did a
>> > get_page() on it so it doesn't go away to swap) and I need to be able
>> > to access it with normal pointers (to do a bunch of atomic operations
>> > on it). I cannot use get_user() and friends, just pointers.
>> > 
>> > So, the question is, how can I map it into the kernel space in a
>> > portable manner? Am I missing anything very basic here?
>> 
>> kmap or kmap_atomic
> 
> I am trying to use kmap_atomic(), but what is the meaning of the second
> argument, km_type? I cannot find it anywhere, or at least the difference
> between KM_USER0 and KM_USER1, which I am guessing are the ones I need.

Each type is for a different usage, and you need to ensure that two things
can't reuse the same type at once. As long as interrupts, or whatever could
disturb you can't use what you use, you're OK. Note that you can't hold
kmap_atomic over a schedule (presumably this means no pre-emption either).
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: Silly question: How to map a user space page in kernel space?
@ 2003-02-26  3:06 ` Perez-Gonzalez, Inaky
  2003-02-26  4:14   ` Martin J. Bligh
  0 siblings, 1 reply; 14+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-02-26  3:06 UTC (permalink / raw)
  To: 'Martin J. Bligh', 'linux-mm@kvack.org'

> Martin J. Bligh wrote:
>
> > Inaky Perez-Gonzalez wrote:
> >
> > I have a user space page (I know the 'struct page *' and I did a
> > get_page() on it so it doesn't go away to swap) and I need to be able to
> > access it with normal pointers (to do a bunch of atomic operations on
> > it). I cannot use get_user() and friends, just pointers.
> >
> > So, the question is, how can I map it into the kernel space in a
> > portable manner? Am I missing anything very basic here?
> 
> kmap or kmap_atomic

I am trying to use kmap_atomic(), but what is the meaning of the second
argument, km_type? I cannot find it anywhere, or at least the difference
between KM_USER0 and KM_USER1, which I am guessing are the ones I need.

Inaky Perez-Gonzalez--Not speaking for Intel--opinions are my own (and my
fault)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* RE: Silly question: How to map a user space page in kernel space?
@ 2003-02-21 22:49 Perez-Gonzalez, Inaky
  0 siblings, 0 replies; 14+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-02-21 22:49 UTC (permalink / raw)
  To: 'Martin J. Bligh',
	Perez-Gonzalez, Inaky, 'linux-mm@kvack.org'

> Martin J. Bligh wrote:
>
> > So, the question is, how can I map it into the kernel space in a
> portable
> > manner? Am I missing anything very basic here?
> 
> kmap or kmap_atomic

Thanks Martin, you are the man :)

Inaky Perez-Gonzalez --- Not speaking for Intel -- all opinions are my own
(and my fault)

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: Silly question: How to map a user space page in kernel space?
  2003-02-21 22:06 ` Perez-Gonzalez, Inaky
@ 2003-02-21 22:22   ` Martin J. Bligh
  0 siblings, 0 replies; 14+ messages in thread
From: Martin J. Bligh @ 2003-02-21 22:22 UTC (permalink / raw)
  To: Perez-Gonzalez, Inaky, 'linux-mm@kvack.org'

> Got a naive question I cannot find the answer for: 
> 
> I have a user space page (I know the 'struct page *' and I did a
> get_page() on it so it doesn't go away to swap) and I need to be able to
> access it with normal pointers (to do a bunch of atomic operations on
> it). I cannot use get_user() and friends, just pointers.
> 
> So, the question is, how can I map it into the kernel space in a portable
> manner? Am I missing anything very basic here?
> 
> Thanks in advance :)
> 
> PS: I suspect remap_page_range() is going to be involved, but I cannot see
> how.

kmap or kmap_atomic

M.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Silly question: How to map a user space page in kernel space?
@ 2003-02-21 22:06 ` Perez-Gonzalez, Inaky
  2003-02-21 22:22   ` Martin J. Bligh
  0 siblings, 1 reply; 14+ messages in thread
From: Perez-Gonzalez, Inaky @ 2003-02-21 22:06 UTC (permalink / raw)
  To: 'linux-mm@kvack.org'

Hi All

Got a naive question I cannot find the answer for: 

I have a user space page (I know the 'struct page *' and I did a get_page()
on it so it doesn't go away to swap) and I need to be able to access it with
normal pointers (to do a bunch of atomic operations on it). I cannot use
get_user() and friends, just pointers.

So, the question is, how can I map it into the kernel space in a portable
manner? Am I missing anything very basic here?

Thanks in advance :)

PS: I suspect remap_page_range() is going to be involved, but I cannot see
how.

Inaky Perez-Gonzalez --- Not speaking for Intel -- all opinions are my own
(and my fault)
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"aart@kvack.org">aart@kvack.org</a>

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2003-02-26 19:04 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <A46BBDB345A7D5118EC90002A5072C780A7D57E6@orsmsx116.jf.intel.com >
2003-02-26  4:44 ` Silly question: How to map a user space page in kernel space? Perez-Gonzalez, Inaky
2003-02-26  5:55   ` Martin J. Bligh
2003-02-26  8:33     ` Andrew Morton
2003-02-26 19:03       ` Martin J. Bligh
2003-02-26 12:40   ` Mel Gorman
2003-02-26 19:04 Perez-Gonzalez, Inaky
  -- strict thread matches above, loose matches on Subject: below --
2003-02-26 18:57 Perez-Gonzalez, Inaky
2003-02-26 19:01 ` Mel Gorman
     [not found] <A46BBDB345A7D5118EC90002A5072C780A7D57BB@orsmsx116.jf.intel.com >
2003-02-26  3:06 ` Perez-Gonzalez, Inaky
2003-02-26  4:14   ` Martin J. Bligh
2003-02-26  4:39     ` Robert Love
2003-02-21 22:49 Perez-Gonzalez, Inaky
     [not found] <A46BBDB345A7D5118EC90002A5072C780A7D5194@orsmsx116.jf.intel.com >
2003-02-21 22:06 ` Perez-Gonzalez, Inaky
2003-02-21 22:22   ` Martin J. Bligh

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox