title: copy data from linux kernel space to user space
body: <p>I'm adding a kernel function to modify the <code>nice</code> and <code>prio</code> value of Specified pid of process.</p>
  
  <p>Here is the code:</p>
  
  <pre><code>SYSCALL_DEFINE5(mysetnice, pid_t, pid, int, flag, int, nicevalue, void __user *, prio, void __user *, nice)
  {
      if (pid &lt; 0 || (flag != 1 &amp;&amp; flag != 0)) {
          return EFAULT;
      }
      if (nice == NULL || prio == NULL) {
          return EFAULT;
      }
      struct task_struct *p;
      for_each_process(p) {
          if (p-&gt;pid == pid) {
              if (flag == 1) {
                  set_user_nice(p, nicevalue);
                  printk("change nice=%d of pid=%d\n", nicevalue, pid);
              }
              printk("pid:%d,current nice:%d, prio:%d\n",pid,task_nice(p),task_prio(p));
              copy_to_user(prio,(const void*)task_prio(p),sizeof(int));
              copy_to_user(nice,(const void*)task_nice(p),sizeof(int));
              return 0;
          }
      }
      return EFAULT;
  
  }
  </code></pre>
  
  <p>and in user scope, I write a test function like this:</p>
  
  <pre><code>int main()
  {
      int pid = 0;
      int flag = 0;
      int nicevalue = 0;
      int prio = 0;
      int nice = 0;
      int ret;
  
      printf("please input the params: pid, flag, nicevalue\n");
      while(~scanf("%d %d %d", &amp;pid, &amp;flag, &amp;nicevalue))
      {
          ret = syscall(__NR_mysyscall, pid, flag, nicevalue, (void *)&amp;prio, (void *)&amp;nice);
          if (ret != 0)
          {
              printf("syscall error! error code:%d\n", ret);
              return 0;
          }
          printf("pid:%d, flag:%d, nicevalue:%d, prio:%d, nice:%d\n", pid, flag, nicevalue, prio + 100, nice);
      }
  
      return 0;
  }
  </code></pre>
  
  <p>but I found that the I can't get the <code>nice</code> value, and the <code>prio</code> is always <code>100</code>. So how to copy data from kernel scope to user scope?</p>