[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: user-defined function call in interrupt handler



On Tue, 05 Aug 2003 10:15:24 +0900, kjw7579 wrote:

> Let me have time to ask some questions about Linux.
> 
> we can access user buffer within interrupt handler (kernel mode) if we
> tocuch segment selectors.
> Like these:
> 		mm_segment_t fs;
> 		fs = get_fs();
> 		set_fs(get_dsc());
> 		call user space function .
> 		.....
>         set_fs(fs);
> 
> My question is:
> Can we execute(call) a function of user space within the interrupt handler?

No. The code might be swapped out to disk.

> reference site http://www.cs.unm.edu/~jotto/linux/linux.html
> 
> Something similar happens with segment selectors when an interrupt takes
> place. But in this case there is no assurance that the handler is executing
> in the context of the interested process. Suppose though that by some bit
> of magic the interrupt handler knows the process's pid and a buffer
> address. Then in the case that the handler needs to write data to the
> buffer we could do something like the following: 
[snip]
> Here, we do a bit of a context switch by finding out the task structure
> associated with the pid (by calling pid2task()and then loading the page
> directory pointer for that task into the CR3 register (the latter is the
> hardware's entry point to a given process's paging structures). Then we can
> use the _fs functions. When we are done we restore the saved context. The
> code for updating CR3 was lifted from the SET_PAGE_DIR macro in
> include/asm. 

This is a bad idea. (Don't believe everything you read on the
Web.) What if the userspace buffer is swapped out? memcpy_tofs will take a
page fault, which is not allowed in interrupt context. See
http://kernelnewbies.org/documents/kdoc/kernel-hacking/routines-copy.html
http://kernelnewbies.org/documents/kdoc/kernel-hacking/deadlock-recipes.html

Wes Felter - wesley@felter.org - http://felter.org/wesley/

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/