linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* Re: Question about pte_alloc()
  2000-11-15  7:07 Question about pte_alloc() Shuvabrata Ganguly
@ 2000-11-14 20:51 ` Kanoj Sarcar
  2000-11-15 10:56 ` Stephen C. Tweedie
  1 sibling, 0 replies; 9+ messages in thread
From: Kanoj Sarcar @ 2000-11-14 20:51 UTC (permalink / raw)
  To: Shuvabrata Ganguly; +Cc: linux MM

> 
> hi all,
> 
> it appears from the code that pte_alloc() might block since it allocates
> a page table with GFP_KERNEL if the page table doesnt already exist. i
> need to call pte_alloc() at interrupt time. Basically i want to map some
> kernel memory into user space as soon as the device gives me data. will
> there be any problem if i use another version of pte_alloc() which calls
> with GFP_ATOMIC priority?
> Maybe i am completely lost :-)

Why do you want to run the risk of failing in your allocation at intr
time? 

A cleaner thing to do is to allocate vma/memory/pagetables at driver 
mmap/fcntl time. If you must make the user program fault before your
device will give data (although this synchronization is probably better
done other ways), mark the ptes invalid ... then mark them valid when 
you get the data in your intr routine ... of course, you *might* want 
to flush tlbs on other processors too in that case.

Kanoj

> 
> cheers
> joy
> 
> --
> 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.eu.org/Linux-MM/
> 

--
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.eu.org/Linux-MM/

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

* Question about pte_alloc()
@ 2000-11-15  7:07 Shuvabrata Ganguly
  2000-11-14 20:51 ` Kanoj Sarcar
  2000-11-15 10:56 ` Stephen C. Tweedie
  0 siblings, 2 replies; 9+ messages in thread
From: Shuvabrata Ganguly @ 2000-11-15  7:07 UTC (permalink / raw)
  To: linux MM

hi all,

it appears from the code that pte_alloc() might block since it allocates
a page table with GFP_KERNEL if the page table doesnt already exist. i
need to call pte_alloc() at interrupt time. Basically i want to map some
kernel memory into user space as soon as the device gives me data. will
there be any problem if i use another version of pte_alloc() which calls
with GFP_ATOMIC priority?
Maybe i am completely lost :-)

cheers
joy

--
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.eu.org/Linux-MM/

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

* Re: Question about pte_alloc()
  2000-11-15  7:07 Question about pte_alloc() Shuvabrata Ganguly
  2000-11-14 20:51 ` Kanoj Sarcar
@ 2000-11-15 10:56 ` Stephen C. Tweedie
  2000-11-16  0:04   ` Shuvabrata Ganguly
  1 sibling, 1 reply; 9+ messages in thread
From: Stephen C. Tweedie @ 2000-11-15 10:56 UTC (permalink / raw)
  To: Shuvabrata Ganguly; +Cc: linux MM

Hi,

On Wed, Nov 15, 2000 at 02:07:38AM -0500, Shuvabrata Ganguly wrote:
> 
> it appears from the code that pte_alloc() might block since it allocates
> a page table with GFP_KERNEL if the page table doesnt already exist. i
> need to call pte_alloc() at interrupt time.

You cannot safely play pte games at interrupt time.  You _must_ do
this in the foreground.

 >Basically i want to map some
> kernel memory into user space as soon as the device gives me data.

Why can't you just let the application know that the event has
occurred and then let it mmap the data itself?

Cheers,
 Stephen
--
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.eu.org/Linux-MM/

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

* Re: Question about pte_alloc()
  2000-11-16  0:04   ` Shuvabrata Ganguly
@ 2000-11-15 15:47     ` Stephen C. Tweedie
  2000-11-16 20:32       ` Shuvabrata Ganguly
  0 siblings, 1 reply; 9+ messages in thread
From: Stephen C. Tweedie @ 2000-11-15 15:47 UTC (permalink / raw)
  To: Shuvabrata Ganguly; +Cc: Stephen C. Tweedie, linux MM

Hi,

On Wed, Nov 15, 2000 at 07:04:00PM -0500, Shuvabrata Ganguly wrote:

> "Stephen C. Tweedie" wrote:
> 
> > On Wed, Nov 15, 2000 at 02:07:38AM -0500, Shuvabrata Ganguly wrote:
> > > it appears from the code that pte_alloc() might block since it allocates
> > > a page table with GFP_KERNEL if the page table doesnt already exist. i
> > > need to call pte_alloc() at interrupt time.
> >
> > You cannot safely play pte games at interrupt time.  You _must_ do
> > this in the foreground.
> 
> why is that ? 

Because the locking mechanisms used to protect ptes on SMP machines
are not interrupt-safe, and because even on uni-processors, we may
perform non-atomic operations on the page tables (such as various
read-modify-write cycles) which will break if an interrupt occurs in
the middle of the cycle and modifies the pte.

> > Why can't you just let the application know that the event has
> > occurred and then let it mmap the data itself?
> 
> Two reasons:-
> i) since kernel memory is unswappable i dont want to allocate a big buffer
> and transfer it to the user when the device has filled it with data. instead
> i want to allocate a page, fill it with data and give it to the user process.
> 
> ii) if i allocate in pages and let the user know that a page of data has
> arrived, it will take a lot of context switches.

I don't buy that.  The user process _has_ to wait if there's no data
ready, surely?  It doesn't matter how you are passing the data around.

> basically i want the kernel to allocate memory on behalf of a process, and
> pass the virtual address of that buffer to the user when it does a read. this
> is somewhat like the "fbuf" scheme.

There are a number of ways you could do that without messiness in the
VM.  You could allocate a small number of pages at once, mmap()
them and use that as a ring buffer to the application.  Basically,
establishing a new kernel buffer mapping from user space IS the mmap()
operation --- why not use mmap for it?  The corresponding munmap when
the application has finished using the data lets the kernel know
exactly when the page can be recycled.

Cheers,
 Stephen
--
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.eu.org/Linux-MM/

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

* Re: Question about pte_alloc()
  2000-11-15 10:56 ` Stephen C. Tweedie
@ 2000-11-16  0:04   ` Shuvabrata Ganguly
  2000-11-15 15:47     ` Stephen C. Tweedie
  0 siblings, 1 reply; 9+ messages in thread
From: Shuvabrata Ganguly @ 2000-11-16  0:04 UTC (permalink / raw)
  To: Stephen C. Tweedie, linux MM

"Stephen C. Tweedie" wrote:

> Hi,
>
> On Wed, Nov 15, 2000 at 02:07:38AM -0500, Shuvabrata Ganguly wrote:
> >
> > it appears from the code that pte_alloc() might block since it allocates
> > a page table with GFP_KERNEL if the page table doesnt already exist. i
> > need to call pte_alloc() at interrupt time.
>
> You cannot safely play pte games at interrupt time.  You _must_ do
> this in the foreground.
>

why is that ? or where can i find code that explains why i cant touch pte
tables at interrupt time ?

>
>  >Basically i want to map some
> > kernel memory into user space as soon as the device gives me data.
>
> Why can't you just let the application know that the event has
> occurred and then let it mmap the data itself?
>

Two reasons:-
i) since kernel memory is unswappable i dont want to allocate a big buffer
and transfer it to the user when the device has filled it with data. instead
i want to allocate a page, fill it with data and give it to the user process.

ii) if i allocate in pages and let the user know that a page of data has
arrived, it will take a lot of context switches.

basically i want the kernel to allocate memory on behalf of a process, and
pass the virtual address of that buffer to the user when it does a read. this
is somewhat like the "fbuf" scheme.
can that be done in the linux kernel at all ?

cheers,
joy



--
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.eu.org/Linux-MM/

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

* Re: Question about pte_alloc()
  2000-11-16 20:32       ` Shuvabrata Ganguly
@ 2000-11-16 14:37         ` Ingo Oeser
  0 siblings, 0 replies; 9+ messages in thread
From: Ingo Oeser @ 2000-11-16 14:37 UTC (permalink / raw)
  To: Shuvabrata Ganguly; +Cc: Stephen C. Tweedie, linux-mm

On Thu, Nov 16, 2000 at 03:32:19PM -0500, Shuvabrata Ganguly wrote:
> i know that. but i dont want to wire the pages. i want the driver to allocate
> pages, fill them up with data and then transfer them to the user, which would
> enable the kernel to swap them  but then i cant touch page tables at interrupt
> time.

Why don't you use an allocator/deliver thread, a ringbuffer and
throw away the overflowing packets, while signalling the sender,
that you are satiated for the moment? The overflowing packets
will be resent later anyway.

If you receive sth., you just put it into the deliver queue and
wake the thread to deliver (==map) it.

BTW: Zero copy might become pointless if you use threads or play
   VM-Tricks.

BTW2: Are you aware of U-Net and VIA?

Regards

Ingo Oeser
-- 
To the systems programmer, users and applications
serve only to provide a test load.
<esc>:x
--
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.eu.org/Linux-MM/

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

* Re: Question about pte_alloc()
  2000-11-15 15:47     ` Stephen C. Tweedie
@ 2000-11-16 20:32       ` Shuvabrata Ganguly
  2000-11-16 14:37         ` Ingo Oeser
  0 siblings, 1 reply; 9+ messages in thread
From: Shuvabrata Ganguly @ 2000-11-16 20:32 UTC (permalink / raw)
  To: Stephen C. Tweedie, linux MM

"Stephen C. Tweedie" wrote:

> Hi,
>
> On Wed, Nov 15, 2000 at 07:04:00PM -0500, Shuvabrata Ganguly wrote:
>
> > "Stephen C. Tweedie" wrote:
> >
> > > On Wed, Nov 15, 2000 at 02:07:38AM -0500, Shuvabrata Ganguly wrote:
> > > > it appears from the code that pte_alloc() might block since it allocates
> > > > a page table with GFP_KERNEL if the page table doesnt already exist. i
> > > > need to call pte_alloc() at interrupt time.
> > >
> > > You cannot safely play pte games at interrupt time.  You _must_ do
> > > this in the foreground.
> >
> > why is that ?
>
> Because the locking mechanisms used to protect ptes on SMP machines
> are not interrupt-safe, and because even on uni-processors, we may
> perform non-atomic operations on the page tables (such as various
> read-modify-write cycles) which will break if an interrupt occurs in
> the middle of the cycle and modifies the pte.
>

point understood. i got that from the code.

>
> > > Why can't you just let the application know that the event has
> > > occurred and then let it mmap the data itself?
> >
> > Two reasons:-
> > i) since kernel memory is unswappable i dont want to allocate a big buffer
> > and transfer it to the user when the device has filled it with data. instead
> > i want to allocate a page, fill it with data and give it to the user process.
> >
> > ii) if i allocate in pages and let the user know that a page of data has
> > arrived, it will take a lot of context switches.
>
> I don't buy that.  The user process _has_ to wait if there's no data
> ready, surely?

well i did not mention earlier what i am trying to do. i are trying to implement a
zero-copy light-weight protocol for PVM. the PVM task can do computation instead
of waiting for data to arrive. when it needs data it calls read to get the data .
if the data has not arrived yet _then_ it would wait. it would really help if i
could tranfer pages of a msg buffer to the user without the process knowing
....then keep a pointer to that buffer in the rx_queue and pass this pointer to
the process when it calls read.


> It doesn't matter how you are passing the data around.
>
> > basically i want the kernel to allocate memory on behalf of a process, and
> > pass the virtual address of that buffer to the user when it does a read. this
> > is somewhat like the "fbuf" scheme.
>
> There are a number of ways you could do that without messiness in the
> VM.  You could allocate a small number of pages at once, mmap()
> them and use that as a ring buffer to the application.  Basically,
> establishing a new kernel buffer mapping from user space IS the mmap()
> operation --- why not use mmap for it? The corresponding munmap when the
> application has finished using the data lets the kernel know exactly when the
> page can be recycled.

i know that. but i dont want to wire the pages. i want the driver to allocate
pages, fill them up with data and then transfer them to the user, which would
enable the kernel to swap them  but then i cant touch page tables at interrupt
time.

> Cheers,
>  Stephen

--
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.eu.org/Linux-MM/

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

* Re: Question about pte_alloc()
  2000-11-15 15:20 Mark_H_Johnson
@ 2000-11-15 15:34 ` Stephen C. Tweedie
  0 siblings, 0 replies; 9+ messages in thread
From: Stephen C. Tweedie @ 2000-11-15 15:34 UTC (permalink / raw)
  To: Mark_H_Johnson
  Cc: Stephen C. Tweedie, linux MM, owner-linux-mm, Shuvabrata Ganguly

Hi,

On Wed, Nov 15, 2000 at 09:20:52AM -0600, Mark_H_Johnson@Raytheon.com wrote:
> 
> Could you please clarify what is meant by...
>   "You cannot safely play pte games at interrupt time.  You _must_
> do this in the foreground."
> We are concerned because it may block adoption of Linux for one of our
> current applications.

...

>  - Can we do this kind of manipulation with the page tables if we modified
> the Linux trap handlers?

Trap handlers are completely different.  Page faults already vector
through the trap handlers, and the kernel is quite happy about
performing blocking IO or pte modifications in that context.  You
shouldn't have a problem as long as you observe the kernel's VM and
page table locking rules.

Cheers,
 Stephen
--
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.eu.org/Linux-MM/

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

* Re: Question about pte_alloc()
@ 2000-11-15 15:20 Mark_H_Johnson
  2000-11-15 15:34 ` Stephen C. Tweedie
  0 siblings, 1 reply; 9+ messages in thread
From: Mark_H_Johnson @ 2000-11-15 15:20 UTC (permalink / raw)
  To: Stephen C. Tweedie; +Cc: linux MM, owner-linux-mm, Shuvabrata Ganguly

Could you please clarify what is meant by...
  "You cannot safely play pte games at interrupt time.  You _must_
do this in the foreground."
We are concerned because it may block adoption of Linux for one of our
current applications.

We are looking at rehosting a computer emulation to Linux. Our current bare
machine solution uses protection settings in the page table to trap
operations we are interested in. The sequence of steps we currently use is
something like...
 [0] pages protected & an auxiliary table indicates which routine to call
when each page is accessed
 [1] application is started and runs normally
 [2] the application accesses a protected page - trap generated
 [3] trap handler captures the address being manipulated
 [4] trap handler modifies context so the instruction can succeed
 [5] the instruction is single stepped
 [6] the designated routine is called w/ the address being manipulated
 [7] it does its simulation (perhaps of an interface card) and returns
 [8] the context is restored & execution resumes with the next instruction
This sequence allows our emulation to capture all reads and writes to the
simulated devices. We simulate the operation of those devices (functional,
timing, etc.). We also have a restriction that we can't change the binary
code of the software that is running [it allows patches & performs checksum
for consistency]. We need some method to do this (or something similar).
 - Can we do this kind of manipulation with the page tables if we modified
the Linux trap handlers?
 - Are there "better" ways of doing this?

Thanks.

--Mark H Johnson
  <mailto:Mark_H_Johnson@raytheon.com>


                                                                                                                     
                    "Stephen C.                                                                                      
                    Tweedie"              To:     Shuvabrata Ganguly <sganguly@cse.iitkgp.ernet.in>                  
                    <sct@redhat.co        cc:     linux MM <linux-mm@kvack.org>                                      
                    m>                    Subject:     Re: Question about pte_alloc()                                
                    Sent by:                                                                                         
                    owner-linux-mm                                                                                   
                    @kvack.org                                                                                       
                                                                                                                     
                                                                                                                     
                    11/15/00 04:56                                                                                   
                    AM                                                                                               
                                                                                                                     
                                                                                                                     



Hi,

On Wed, Nov 15, 2000 at 02:07:38AM -0500, Shuvabrata Ganguly wrote:
>
> it appears from the code that pte_alloc() might block since it allocates
> a page table with GFP_KERNEL if the page table doesnt already exist. i
> need to call pte_alloc() at interrupt time.

You cannot safely play pte games at interrupt time.  You _must_ do
this in the foreground.

 >Basically i want to map some
> kernel memory into user space as soon as the device gives me data.

Why can't you just let the application know that the event has
occurred and then let it mmap the data itself?

Cheers,
 Stephen
--
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.eu.org/Linux-MM/




--
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.eu.org/Linux-MM/

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

end of thread, other threads:[~2000-11-16 20:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-11-15  7:07 Question about pte_alloc() Shuvabrata Ganguly
2000-11-14 20:51 ` Kanoj Sarcar
2000-11-15 10:56 ` Stephen C. Tweedie
2000-11-16  0:04   ` Shuvabrata Ganguly
2000-11-15 15:47     ` Stephen C. Tweedie
2000-11-16 20:32       ` Shuvabrata Ganguly
2000-11-16 14:37         ` Ingo Oeser
2000-11-15 15:20 Mark_H_Johnson
2000-11-15 15:34 ` Stephen C. Tweedie

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