Subject: Re: UVM - Kernel & User access question
To: Eric Circlaeys <eric.c@mac.com>
From: Stephan Uphoff <ups@stups.com>
List: tech-kern
Date: 10/20/2003 10:21:35
> > strncpy(pointeur, "toto\0", 5); is a dangerous way to access the 
> > memory.
> > If the buffer is paged out and the swap is bad (disk error) you will 
> > get
> > a kernel panic.
> > Using kcopy/uiomove you can try to copy the memory - and the functions 
> > will
> > just return an error on failure (no kernel panic).
> 
> You say that kcopy will avoid kernel panic if page is out,
> how can I be sure that all the time I can read or write to my pageable 
> kernel memory.
> Because as I understand kcopy will return an error if the page is out 
> but will not force the page to be up and wait for it to copy the data?

Both normal memory access and kcopy will try to page in the memory
if it is paged out - this is not the problem.

However if paging in fails (disk error,...) kcopy will return an error
while strncpy or access through a pointer would cause a kernel panic.

( for i386 take a look at pcb_onfault (PCB_ONFAULT) - an architecture
specific exception mechanisms used for recovering from page faults 
that encountered errors in kcopy/copyin,...)


> What kind of other functions can I use to play with that memory and be 
> sure it is wired at a time for usage?

uvm_fault_wire can be used to wire the pages and you can then use anything
to access the memory and even use it in a an interrupt context.
(uvm_fault_unwire removes the wiring)
Once the page is wired you no longer have to worry about page faults.
However wiring/unwiring is a relative expensive function.

kcopy/copyin/copyout can be used without first wiring the pages because
of their internal exception handling.
( However these functions can not be used from interrupt context)


	Stephan