<html><body><div style="color:#000; background-color:#fff; font-family:lucida console, sans-serif;font-size:10pt"><div>Hi all,</div><div> </div><div>You cand find number of example on how to use <strong>send_sig_info</strong> api.</div><div> </div><div>please follow this link : <a href="http://lxr.linux.no/linux+v3.6.6/kernel/pid_namespace.c#L179">http://lxr.linux.no/linux+v3.6.6/kernel/pid_namespace.c#L179</a></div><div> </div><div> </div><div>Regarding this warning</div><div>--------------------------------------------------------------------------------</div><div>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></div><div> </div><div>--------------------------------------------------------------------------------</div><div>you need the export these functions so that you can use then in your module.</div><div> </div><div> </div><div>-Anand Moon</div><div> </div><div style="font-family: lucida console, sans-serif; font-size: 10pt;"> <div style="font-family: times new roman, new york, times, serif; font-size: 12pt;"> <div dir="ltr">
<font size="2" face="Arial"> <div style="margin: 5px 0px; padding: 0px; border: 1px solid rgb(204, 204, 204); height: 0px; line-height: 0; font-size: 0px;" class="hr" contentEditable="false" readonly="true"></div> <b><span style="font-weight: bold;">From:</span></b> Jeshwanth Kumar N K Jeshu <jeshkumar555@gmail.com><br> <b><span style="font-weight: bold;">To:</span></b> SaNtosh kuLkarni <santosh.yesoptus@gmail.com>; moon.linux@yahoo.com <br><b><span style="font-weight: bold;">Cc:</span></b> Bernd Petrovitsch <bernd@petrovitsch.priv.at>; kernelnewbies@kernelnewbies.org <br> <b><span style="font-weight: bold;">Sent:</span></b> Saturday, November 10, 2012 1:47 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: Callback function from kernel module<br> </font> </div> <br>
<div id="yiv1626182373">Hello Santosh and Anand,<br><br>Thanks for the reply and very good suggestions.<br><br>As Anand Moon suggestedhttp://people.ee.ethz.ch/%7Earkeller/linux/multi/kernel_user_space_howto-3.html <br>
<pre>link in http://lists.kernelnewbies.org/pipermail/kernelnewbies/2012-November/006489.html previous thread, <br>
I read all the kernel to user space communication mechanism ( Except<a href="http://people.ee.ethz.ch/~arkeller/linux/multi/kernel_user_space_howto.html#toc7" rel="nofollow" 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="yiv1626182373gmail_quote">On Thu, Nov 8, 2012 at 11:33 AM, SaNtosh kuLkarni <span dir="ltr"><<a href="mailto:santosh.yesoptus@gmail.com" rel="nofollow" target="_blank" ymailto="mailto:santosh.yesoptus@gmail.com">santosh.yesoptus@gmail.com</a>></span> wrote:<br><blockquote style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;" class="yiv1626182373gmail_quote">
<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>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><font face="arial black, sans-serif"><br></font></span></div><div><span><font face="arial black, sans-serif"><br></font></span></div><div><span><font face="arial black, sans-serif">**</font></span></div>
<div><font face="arial black, sans-serif"><span>int </span><span>call_usermodehelper </span><span> (char * </span><i>path</i><span>, char ** </span><i>argv</i><span>, char ** </span><i>envp</i><span>, int </span><i>wait</i><span>);</span><span><br>
</span></font></div><div><span><font face="arial black, sans-serif"><br></font></span></div><div><div><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></div>
<div><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></div><div>
<font face="arial black, sans-serif">**man pages</font></div><div style="font-size: medium;">Regards</div><div style="font-size: medium;">
Santosh</div></div><div><span style="font-size: medium;"><br></span></div><div class="yiv1626182373gmail_extra"><br><br><div class="yiv1626182373gmail_quote"><div><div class="yiv1626182373h5">On Wed, Nov 7, 2012 at 8:30 PM, Bernd Petrovitsch <span dir="ltr"><<a href="mailto:bernd@petrovitsch.priv.at" rel="nofollow" target="_blank" ymailto="mailto:bernd@petrovitsch.priv.at">bernd@petrovitsch.priv.at</a>></span> wrote:<br>
</div></div><blockquote style="margin: 0px 0px 0px 0.8ex; padding-left: 1ex; border-left-color: rgb(204, 204, 204); border-left-width: 1px; border-left-style: solid;" class="yiv1626182373gmail_quote"><div><div class="yiv1626182373h5">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="yiv1626182373h5">--<br>
Bernd Petrovitsch Email : <a href="mailto:bernd@petrovitsch.priv.at" rel="nofollow" target="_blank" ymailto="mailto:bernd@petrovitsch.priv.at">bernd@petrovitsch.priv.at</a><br>
LUGA : <a href="http://www.luga.at/" rel="nofollow" target="_blank">http://www.luga.at/</a><br>
<br>
<br></div></div><div class="yiv1626182373im">
_______________________________________________<br>
Kernelnewbies mailing list<br>
<a href="mailto:Kernelnewbies@kernelnewbies.org" rel="nofollow" target="_blank" ymailto="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" rel="nofollow" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
</div></font></span></blockquote></div><span class="yiv1626182373HOEnZb"><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" rel="nofollow" target="_blank" ymailto="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
<a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" rel="nofollow" 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>
</div><br>_______________________________________________<br>Kernelnewbies mailing list<br><a href="mailto:Kernelnewbies@kernelnewbies.org" ymailto="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><br> </div> </div> </div></body></html>