title: Shared Memory between User Space and Kernel Threads
body: <p>I am developing a kernel application which involves kthreads. I create an array of structure and allocate memory using malloc in user-space. Then I call a system call (which I implemented) and pass the address of array to kernel-space. In the handler of system-call I create I create 2 kthreads which will monitor the array. kthread can change some value and user-space threads can also change some values. The idea is to use the array as a shared memory. But some when I access the memory in kernel space (using copy_from_user) the data are somehow changed. I can verify that the address are same when it was assigned and in kernel. But when using copy_from_user it is giving various values like garbage values.</p>
  
  <p>Also is the following statement ok?</p>
  
  <pre><code>int kthread_run_function(void* data){
      struct entry tmp;
      copy_from_user(&amp;tmp, data, sizeof(struct entry));
  }
  </code></pre>