Re: Callback function from kernel module

2012-11-13 Thread Anand Moon
Hi all,
 
You cand find number of example on how to use send_sig_info api.
 
please follow this link : 
http://lxr.linux.no/linux+v3.6.6/kernel/pid_namespace.c#L179
 
 
Regarding this warning

jeshwanth@jeshwanth:~/linux/kernel_user_space/code/signals$ make
make -C /lib/modules/3.0.0-26-generic-pae/build 
M=/home/jeshwanth/linux/kernel_user_space/code/signals modules
make[1]: Entering directory `/usr/src/linux-headers-3.0.0-26-generic-pae'
Building modules, stage 2.
MODPOST 1 modules
WARNING: "find_task_by_vpid" 
[/home/jeshwanth/linux/kernel_user_space/code/signals/signal_kernel.ko] 
undefined!
make[1]: Leaving directory `/usr/src/linux-headers-3.0.0-26-generic-pae'
[1]+  Donegedit signal_kernel.c

install Command:
root@jeshwanth:/home/jeshwanth/linux/kernel_user_space/code/signals# insmod 
signal_kernel.ko 
insmod: error inserting 'signal_kernel.ko': -1 Unknown symbol in module

/proc/kallsyms:

 T find_task_by_pid_ns
 T find_task_by_vpid

 

you need the export these functions so that you can use then in your module.
 
 
-Anand Moon
  


 From: Jeshwanth Kumar N K Jeshu 
To: SaNtosh kuLkarni ; moon.li...@yahoo.com 
Cc: Bernd Petrovitsch ; 
kernelnewbies@kernelnewbies.org 
Sent: Saturday, November 10, 2012 1:47 PM
Subject: Re: Callback function from kernel module
  

Hello Santosh and Anand,

Thanks for the reply and very good suggestions.

As Anand Moon 
suggestedhttp://people.ee.ethz.ch/%7Earkeller/linux/multi/kernel_user_space_howto-3.html
 

link in 
http://lists.kernelnewbies.org/pipermail/kernelnewbies/2012-November/006489.html
 previous thread, 
I read all the kernel to user space communication mechanism ( ExceptUpcall , ll 
read it). As of now for my application,
the signals passing from kernel to user space is enough. I was trying the 
sample code provided in  signals section of above link.

1. In the code he used find_task_by_pid_type, but find_task_by_pid_type not 
available in sched.h. So I have changed it to 
find_task_by_vpid(pid), is this right way ?

2. I tried to install the module but it is not finding the symbol, but the 
symbol is present in /proc/kallsyms.

Anything I am missing while compiling ? as I am getting warning.


Compile:

jeshwanth@jeshwanth:~/linux/kernel_user_space/code/signals$ make
make -C /lib/modules/3.0.0-26-generic-pae/build 
M=/home/jeshwanth/linux/kernel_user_space/code/signals modules
make[1]: Entering directory `/usr/src/linux-headers-3.0.0-26-generic-pae'
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: "find_task_by_vpid" 
[/home/jeshwanth/linux/kernel_user_space/code/signals/signal_kernel.ko] 
undefined!
make[1]: Leaving directory `/usr/src/linux-headers-3.0.0-26-generic-pae'
[1]+  Done    gedit signal_kernel.c

install Command:
root@jeshwanth:/home/jeshwanth/linux/kernel_user_space/code/signals# insmod 
signal_kernel.ko 
insmod: error inserting 'signal_kernel.ko': -1 Unknown symbol in module

/proc/kallsyms:

 T find_task_by_pid_ns
 T find_task_by_vpid

dmesg:
[15012.556740] signal_kernel: Unknown symbol find_task_by_vpid (err 0)

Code:
#include 
#include 
#include 
#include     //siginfo
#include     //rcu_read_lock
#include     //find_task_by_pid_type
#include 
#include 


#define SIG_TEST 44    // we choose 44 as our signal number (real-time signals 
are in the range of 33 to 64)

struct dentry *file;

static ssize_t write_pid(struct file *file, const char __user *buf,
    size_t count, loff_t *ppos)
{
    char mybuf[10];
    int pid = 0;
    int ret;
    struct siginfo info;
    struct task_struct *t;
    /* read the value from user space */
    if(count > 10)
        return -EINVAL;
    copy_from_user(mybuf, buf, count);
    sscanf(mybuf, "%d", &pid);
    printk("pid = %d\n", pid);

    /* send the signal */
    memset(&info, 0, sizeof(struct siginfo));
    info.si_signo = SIG_TEST;
    info.si_code = SI_QUEUE;    // this is bit of a trickery: SI_QUEUE is 
normally used by sigqueue from user space,
                    // and kernel space should use SI_KERNEL. But if SI_KERNEL 
is used the real_time data 
                    // is not delivered to the user space signal handler 
function. 
    info.si_int = 1234;          //real time signals may have 32 bits of data.

    rcu_read_lock();
    //t = find_task_by_pid_type(PIDTYPE_PID, pid);  //find the task_struct 
associated with this pid
    t = find_task_by_vpid(pid);
    if(t == NULL){
        printk("no such pid\n");
        rcu_read_unlock();
        return -ENODEV;
    }
    rcu_read_unlock();
    ret = send_sig_info(SIG_TEST, &info, t);    //send the signal
    if (ret < 0) {
        printk("err

Re: Callback function from kernel module

2012-11-10 Thread Jeshwanth Kumar N K Jeshu
Hello Santosh and Anand,

Thanks for the reply and very good suggestions.

As Anand Moon 
suggestedhttp://people.ee.ethz.ch/~arkeller/linux/multi/kernel_user_space_howto-3.html

link in 
http://lists.kernelnewbies.org/pipermail/kernelnewbies/2012-November/006489.html
previous thread,

I read all the kernel to user space communication mechanism ( Except
Upcall  
,
ll read it). As of now for my application,

the signals passing from kernel to user space is enough. I was trying
the sample code provided in  signals section of above link.

1. In the code he used *find_task_by_pid_type, *but
*find_task_by_pid_type *not available in sched.h. So I have changed it
to
*find_task_by_vpid(pid)*, is this right way ?

2. I tried to install the module but it is not finding the symbol, but
the symbol is present in */proc/kallsyms.
*
Anything I am missing while compiling ? as I am getting warning.



*Compile:*

jeshwanth@jeshwanth:~/linux/kernel_user_space/code/signals$ make
make -C /lib/modules/3.0.0-26-generic-pae/build
M=/home/jeshwanth/linux/kernel_user_space/code/signals modules
make[1]: Entering directory `/usr/src/linux-headers-3.0.0-26-generic-pae'
  Building modules, stage 2.
  MODPOST 1 modules
*WARNING:* "find_task_by_vpid"
[/home/jeshwanth/linux/kernel_user_space/code/signals/signal_kernel.ko]
undefined!
make[1]: Leaving directory `/usr/src/linux-headers-3.0.0-26-generic-pae'
[1]+  Donegedit signal_kernel.c

*install Command:*
root@jeshwanth:/home/jeshwanth/linux/kernel_user_space/code/signals# insmod
signal_kernel.ko
insmod: error inserting 'signal_kernel.ko': -1 Unknown symbol in module

*/proc/kallsyms:*

 T find_task_by_pid_ns
 T find_task_by_vpid

*dmesg:*
[15012.556740] signal_kernel: Unknown symbol find_task_by_vpid (err 0)

*Code:*
#include 
#include 
#include 
#include //siginfo
#include //rcu_read_lock
#include //find_task_by_pid_type
#include 
#include 


#define SIG_TEST 44// we choose 44 as our signal number (real-time
signals are in the range of 33 to 64)

struct dentry *file;

static ssize_t write_pid(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
char mybuf[10];
int pid = 0;
int ret;
struct siginfo info;
struct task_struct *t;
/* read the value from user space */
if(count > 10)
return -EINVAL;
copy_from_user(mybuf, buf, count);
sscanf(mybuf, "%d", &pid);
printk("pid = %d\n", pid);

/* send the signal */
memset(&info, 0, sizeof(struct siginfo));
info.si_signo = SIG_TEST;
info.si_code = SI_QUEUE;// this is bit of a trickery: SI_QUEUE is
normally used by sigqueue from user space,
// and kernel space should use SI_KERNEL. But if
SI_KERNEL is used the real_time data
// is not delivered to the user space signal handler
function.
info.si_int = 1234;  //real time signals may have 32 bits of
data.

rcu_read_lock();
//t = find_task_by_pid_type(PIDTYPE_PID, pid);  //find the task_struct
associated with this pid
t = find_task_by_vpid(pid);
if(t == NULL){
printk("no such pid\n");
rcu_read_unlock();
return -ENODEV;
}
rcu_read_unlock();
ret = send_sig_info(SIG_TEST, &info, t);//send the signal
if (ret < 0) {
printk("error sending signal\n");
return ret;
}
return count;
}

static const struct file_operations my_fops = {
.write = write_pid,
};

static int __init signalexample_module_init(void)
{
/* we need to know the pid of the user space process
  * -> we use debugfs for this. As soon as a pid is written to
  * this file, a signal is sent to that pid
  */
/* only root can write to this file (no read) */
file = debugfs_create_file("signalconfpid", 0200, NULL, NULL, &my_fops);
return 0;
}
static void __exit signalexample_module_exit(void)
{
debugfs_remove(file);

}

module_init(signalexample_module_init);
module_exit(signalexample_module_exit);
MODULE_LICENSE("GPL");


On Thu, Nov 8, 2012 at 11:33 AM, SaNtosh kuLkarni <
santosh.yesop...@gmail.com> wrote:

> I think you are looking for Upcall Functionality
>
> 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.
>
>
> **
> int call_usermodehelper  (char * *path*, char ** *argv*, char ** *envp*,
> int *wait*);
>
> 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).
>
> Must be called from process context. Returns a negative error code if
> program was not execed successfully, or 0.
>
> **man pages
>
> Regards
>
> Santosh
>
>
>
> On Wed, Nov 7, 2012 at 8:30 PM,

Re: Callback function from kernel module

2012-11-07 Thread SaNtosh kuLkarni
I think you are looking for Upcall Functionality

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.


**
int call_usermodehelper  (char * *path*, char ** *argv*, char ** *envp*,
int *wait*);

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).

Must be called from process context. Returns a negative error code if
program was not execed successfully, or 0.

**man pages

Regards

Santosh



On Wed, Nov 7, 2012 at 8:30 PM, Bernd Petrovitsch  wrote:

> Hi!
>
> On Sam, 2012-11-03 at 19:14 +0530, Jeshwanth Kumar N K Jeshu wrote:
> [...]
> > Can I call userspace function from kernel module ? Actually I need to
> > process some data in user space for every event occured in kernel module.
>
> The usual way to implement this with a character device. The userspace
> application opens the character device. It then read()s the events from
> it, handles it and write()s results back (if needed).
> The kernel part handles to IRQs, puts that into a buffer where it waits
> for the read() from user space.
>
> You can use netlink sockets for this which may save some code though or
> implement a character device directly.
>
> Kind regards,
> Bernd
> --
> Bernd Petrovitsch  Email : be...@petrovitsch.priv.at
>  LUGA : http://www.luga.at
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>



-- 
*Regards,
Santosh*
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Callback function from kernel module

2012-11-07 Thread Bernd Petrovitsch
Hi!

On Sam, 2012-11-03 at 19:14 +0530, Jeshwanth Kumar N K Jeshu wrote:
[...]
> Can I call userspace function from kernel module ? Actually I need to
> process some data in user space for every event occured in kernel module.

The usual way to implement this with a character device. The userspace
application opens the character device. It then read()s the events from
it, handles it and write()s results back (if needed).
The kernel part handles to IRQs, puts that into a buffer where it waits
for the read() from user space.

You can use netlink sockets for this which may save some code though or
implement a character device directly.

Kind regards,
Bernd
-- 
Bernd Petrovitsch  Email : be...@petrovitsch.priv.at
 LUGA : http://www.luga.at


___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Callback function from kernel module

2012-11-07 Thread anish kumar
On Sat, 2012-11-03 at 21:56 +0530, jeshkumar...@gmail.com wrote:
> hello Mulyadi,
> 
> As per my design, a userspace application shall call some function in
> the application  for each interrupt occur in  particular kernel
> module. So what mechanism shall go ? As subramaniam referred kobject,
> I am going on with it. ( understanding kobject)
Why userspace is bothered about interrupts in the kernel.Something is
inherently wrong in your understanding.
A detailed problem description would help you.
> 
> Sent from my HTC
> Excuse for typo.
> 
> - Reply message -
> From: "Mulyadi Santosa" 
> Date: Sat, Nov 3, 2012 9:42 pm
> Subject: Callback function from kernel module
> To: "Jeshwanth Kumar N K Jeshu" 
> Cc: "kernelnewbies" 
> 
> 
> Hi..
> 
> On Sat, Nov 3, 2012 at 8:44 PM, Jeshwanth Kumar N K Jeshu
>  wrote:
> > Hello All,
> >
> > Can I call userspace function from kernel module ? Actually I need
> to
> > process some data in user space for every event occured in kernel
> module.
> 
> user space function or user space program? for later, IIRC you can use
> usermode_helper...
> 
> 
> -- 
> regards,
> 
> Mulyadi Santosa
> Freelance Linux trainer and consultant
> 
> blog: the-hydra.blogspot.com
> training: mulyaditraining.blogspot.com
> 
> 
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies



___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Callback function from kernel module

2012-11-05 Thread Anand Moon
Hi All, 
Netlink sockets provide simple solution to the problem. 
please refer this link. 
http://people.ee.ethz.ch/~arkeller/linux/multi/kernel_user_space_howto-3.html 
section 3.3 Netlink Sockets explain the IPC mechanism to talk to usersapce from 
the kernel.
 
-Anand Moon


 From: "jeshkumar...@gmail.com" 
To: Mulyadi Santosa  
Cc: kernelnewbies  
Sent: Saturday, November 3, 2012 9:56 PM
Subject: Re: Callback function from kernel module
  

hello Mulyadi,

As per my design, a userspace application shall call some function in the 
application  for each interrupt occur in  particular kernel module. So what 
mechanism shall go ? As subramaniam referred kobject, I am going on with it. ( 
understanding kobject)

Sent from my HTC
Excuse for typo.

- Reply message -
From: "Mulyadi Santosa" 
Date: Sat, Nov 3, 2012 9:42 pm
Subject: Callback function from kernel module
To: "Jeshwanth Kumar N K Jeshu" 
Cc: "kernelnewbies" 


Hi..

On Sat, Nov 3, 2012 at 8:44 PM, Jeshwanth Kumar N K Jeshu
 wrote:
> Hello All,
>
> Can I call userspace function from kernel module ? Actually I need to
> process some data in user space for every event occured in kernel module.

user space function or user space program? for later, IIRC you can use
usermode_helper...


-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com



___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Callback function from kernel module

2012-11-03 Thread jeshkumar...@gmail.com
hello Mulyadi,

As per my design, a userspace application shall call some function in the 
application  for each interrupt occur in  particular kernel module. So what 
mechanism shall go ? As subramaniam referred kobject, I am going on with it. ( 
understanding kobject)

Sent from my HTC
Excuse for typo.

- Reply message -
From: "Mulyadi Santosa" 
Date: Sat, Nov 3, 2012 9:42 pm
Subject: Callback function from kernel module
To: "Jeshwanth Kumar N K Jeshu" 
Cc: "kernelnewbies" 


Hi..

On Sat, Nov 3, 2012 at 8:44 PM, Jeshwanth Kumar N K Jeshu
 wrote:
> Hello All,
>
> Can I call userspace function from kernel module ? Actually I need to
> process some data in user space for every event occured in kernel module.

user space function or user space program? for later, IIRC you can use
usermode_helper...


-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Callback function from kernel module

2012-11-03 Thread Mulyadi Santosa
Hi..

On Sat, Nov 3, 2012 at 8:44 PM, Jeshwanth Kumar N K Jeshu
 wrote:
> Hello All,
>
> Can I call userspace function from kernel module ? Actually I need to
> process some data in user space for every event occured in kernel module.

user space function or user space program? for later, IIRC you can use
usermode_helper...


-- 
regards,

Mulyadi Santosa
Freelance Linux trainer and consultant

blog: the-hydra.blogspot.com
training: mulyaditraining.blogspot.com

___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Callback function from kernel module

2012-11-03 Thread Jeshwanth Kumar N K Jeshu
THanks Subramaniam ,

Get back to you once understand KObject :)


On Sat, Nov 3, 2012 at 7:25 PM, Subramaniam Appadodharana <
c.a.subraman...@gmail.com> wrote:

> You can use kobject_uevent()
>
> http://www.mjmwired.net/kernel/Documentation/kobject.txt#169
>
> Also check out the kobject example under samples folder.
>
> BR
> Subbu
>
> On Sat, Nov 3, 2012 at 8:44 AM, Jeshwanth Kumar N K Jeshu <
> jeshkumar...@gmail.com> wrote:
>
>> Hello All,
>>
>> Can I call userspace function from kernel module ? Actually I need to
>> process some data in user space for every event occured in kernel module.
>>
>> --
>> Regards
>> Jeshwanth Kumar N K
>> +91-7411483498
>>
>>
>> ___
>> Kernelnewbies mailing list
>> Kernelnewbies@kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>>
>


-- 
Regards
Jeshwanth Kumar N K
+91-7411483498
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies


Re: Callback function from kernel module

2012-11-03 Thread Subramaniam Appadodharana
You can use kobject_uevent()

http://www.mjmwired.net/kernel/Documentation/kobject.txt#169

Also check out the kobject example under samples folder.

BR
Subbu

On Sat, Nov 3, 2012 at 8:44 AM, Jeshwanth Kumar N K Jeshu <
jeshkumar...@gmail.com> wrote:

> Hello All,
>
> Can I call userspace function from kernel module ? Actually I need to
> process some data in user space for every event occured in kernel module.
>
> --
> Regards
> Jeshwanth Kumar N K
> +91-7411483498
>
>
> ___
> Kernelnewbies mailing list
> Kernelnewbies@kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
___
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies