Hello Santosh and Anand,<br><br>Thanks for the reply and very good suggestions.<br><br>As Anand Moon suggested<a href="http://people.ee.ethz.ch/%7Earkeller/linux/multi/kernel_user_space_howto-3.html" target="_blank"> http://people.ee.ethz.ch/~arkeller/linux/multi/kernel_user_space_howto-3.html</a> <br>
<pre>link in <a href="http://lists.kernelnewbies.org/pipermail/kernelnewbies/2012-November/006489.html" target="_blank">http://lists.kernelnewbies.org/pipermail/kernelnewbies/2012-November/006489.html</a> previous thread, <br>
I read all the kernel to user space communication mechanism ( Except<a href="http://people.ee.ethz.ch/%7Earkeller/linux/multi/kernel_user_space_howto.html#toc7" target="_blank"> Upcall </a>, ll read it). As of now for my application,<br>
the signals passing from kernel to user space is enough. I was trying the sample code provided in signals section of above link.<br><br>1. In the code he used <b>find_task_by_pid_type, </b>but <b>find_task_by_pid_type </b>not available in sched.h. So I have changed it to <br>
<b>find_task_by_vpid(pid)</b>, is this right way ?<br><br>2. I tried to install the module but it is not finding the symbol, but the symbol is present in <b>/proc/kallsyms.<br></b><br>Anything I am missing while compiling ? as I am getting warning.<br>
</pre><br><br><b>Compile:</b><br><br>jeshwanth@jeshwanth:~/linux/kernel_user_space/code/signals$ make<br>make -C /lib/modules/3.0.0-26-generic-pae/build M=/home/jeshwanth/linux/kernel_user_space/code/signals modules<br>make[1]: Entering directory `/usr/src/linux-headers-3.0.0-26-generic-pae'<br>
Building modules, stage 2.<br> MODPOST 1 modules<br><b>WARNING:</b> "find_task_by_vpid" [/home/jeshwanth/linux/kernel_user_space/code/signals/signal_kernel.ko] undefined!<br>make[1]: Leaving directory `/usr/src/linux-headers-3.0.0-26-generic-pae'<br>
[1]+ Done gedit signal_kernel.c<br><br>
<b>install Command:</b><br>root@jeshwanth:/home/jeshwanth/linux/kernel_user_space/code/signals# insmod signal_kernel.ko <br>insmod: error inserting 'signal_kernel.ko': -1 Unknown symbol in module<br><br><b>/proc/kallsyms:</b><br>
<br>00000000 T find_task_by_pid_ns<br>00000000 T find_task_by_vpid<br><br><b>dmesg:</b><br>[15012.556740] signal_kernel: Unknown symbol find_task_by_vpid (err 0)<br><br><b>Code:</b><br clear="all">#include <linux/module.h><br>
#include <linux/kernel.h><br>#include <linux/init.h><br>#include <asm/siginfo.h> //siginfo<br>#include <linux/rcupdate.h> //rcu_read_lock<br>#include <linux/sched.h> //find_task_by_pid_type<br>
#include <linux/debugfs.h><br>#include <linux/uaccess.h><br><br><br>#define SIG_TEST 44 // we choose 44 as our signal number (real-time signals are in the range of 33 to 64)<br><br>struct dentry *file;<br>
<br>
static ssize_t write_pid(struct file *file, const char __user *buf,<br> size_t count, loff_t *ppos)<br>{<br> char mybuf[10];<br> int pid = 0;<br> int ret;<br> struct siginfo info;<br>
struct task_struct *t;<br> /* read the value from user space */<br> if(count > 10)<br> return -EINVAL;<br> copy_from_user(mybuf, buf, count);<br> sscanf(mybuf, "%d", &pid);<br> printk("pid = %d\n", pid);<br>
<br> /* send the signal */<br> memset(&info, 0, sizeof(struct siginfo));<br> info.si_signo = SIG_TEST;<br> info.si_code = SI_QUEUE; // this is bit of a trickery: SI_QUEUE is normally used by sigqueue from user space,<br>
// and kernel space should use SI_KERNEL. But if SI_KERNEL is used the real_time data <br> // is not delivered to the user space signal handler function. <br> info.si_int = 1234; //real time signals may have 32 bits of data.<br>
<br> rcu_read_lock();<br> //t = find_task_by_pid_type(PIDTYPE_PID, pid); //find the task_struct associated with this pid<br> t = find_task_by_vpid(pid);<br> if(t == NULL){<br> printk("no such pid\n");<br>
rcu_read_unlock();<br> return -ENODEV;<br> }<br> rcu_read_unlock();<br> ret = send_sig_info(SIG_TEST, &info, t); //send the signal<br> if (ret < 0) {<br> printk("error sending signal\n");<br>
return ret;<br> }<br> return count;<br>}<br><br>static const struct file_operations my_fops = {<br> .write = write_pid,<br>};<br><br>static int __init signalexample_module_init(void)<br>{<br> /* we need to know the pid of the user space process<br>
* -> we use debugfs for this. As soon as a pid is written to <br> * this file, a signal is sent to that pid<br> */<br> /* only root can write to this file (no read) */<br> file = debugfs_create_file("signalconfpid", 0200, NULL, NULL, &my_fops);<br>
return 0;<br>}<br>static void __exit signalexample_module_exit(void)<br>{<br> debugfs_remove(file);<br><br>}<br><br>module_init(signalexample_module_init);<br>module_exit(signalexample_module_exit);<br>MODULE_LICENSE("GPL");<br>
<br><br><div class="gmail_quote">On Thu, Nov 8, 2012 at 11:33 AM, SaNtosh kuLkarni <span dir="ltr"><<a href="mailto:santosh.yesoptus@gmail.com" target="_blank">santosh.yesoptus@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<font face="arial black, sans-serif">I think you are looking for Upcall Functionality</font><div><font face="arial black, sans-serif"><br></font></div><div><font face="arial black, sans-serif"><span style>upcall functionality allows a kernel module to invoke a function in user space. It is possible to start a program in user space, and give it some command line arguments, as well as setting environment variables.</span><br>
</font></div><div><span style><font face="arial black, sans-serif"><br></font></span></div><div><span style><font face="arial black, sans-serif"><br></font></span></div><div><span style><font face="arial black, sans-serif">**</font></span></div>
<div><font face="arial black, sans-serif"><span style>int </span><span style>call_usermodehelper </span><span style> (char * </span><i style>path</i><span style>, char ** </span><i style>argv</i><span style>, char ** </span><i style>envp</i><span style>, int </span><i style>wait</i><span style>);</span><span style><br>
</span></font></div><div><span style><font face="arial black, sans-serif"><br></font></span></div><div><p style><font face="arial black, sans-serif">Runs a user-space application. The application is started asynchronously if wait is not set, and runs as a child of keventd. (ie. it runs with full root capabilities).</font></p>
<p style></p><p style><font face="arial black, sans-serif">Must be called from process context. Returns a negative error code if program was not execed successfully, or 0.</font></p><p style>
<font face="arial black, sans-serif">**man pages</font></p><p style="font-size:medium;font-family:'Times New Roman'">Regards</p><p style="font-size:medium;font-family:'Times New Roman'">
Santosh</p></div><div><span style="font-size:medium;font-family:'Times New Roman'"><br></span></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On Wed, Nov 7, 2012 at 8:30 PM, Bernd Petrovitsch <span dir="ltr"><<a href="mailto:bernd@petrovitsch.priv.at" target="_blank">bernd@petrovitsch.priv.at</a>></span> wrote:<br>
</div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">Hi!<br>
<br>
On Sam, 2012-11-03 at 19:14 +0530, Jeshwanth Kumar N K Jeshu wrote:<br>
[...]<br>
> Can I call userspace function from kernel module ? Actually I need to<br>
> process some data in user space for every event occured in kernel module.<br>
<br>
The usual way to implement this with a character device. The userspace<br>
application opens the character device. It then read()s the events from<br>
it, handles it and write()s results back (if needed).<br>
The kernel part handles to IRQs, puts that into a buffer where it waits<br>
for the read() from user space.<br>
<br>
You can use netlink sockets for this which may save some code though or<br>
implement a character device directly.<br>
<br>
Kind regards,<br>
Bernd<br>
</div></div><span><font color="#888888"><div><div class="h5">--<br>
Bernd Petrovitsch Email : <a href="mailto:bernd@petrovitsch.priv.at" target="_blank">bernd@petrovitsch.priv.at</a><br>
LUGA : <a href="http://www.luga.at" target="_blank">http://www.luga.at</a><br>
<br>
<br></div></div><div class="im">
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org" target="_blank">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</div></font></span></blockquote></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><b style="color:rgb(102,102,204)">Regards,<br>Santosh</b><br><br>
</font></span></div>
<br>_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>Regards<br>Jeshwanth Kumar N K<br>+91-7411483498<br><br>